Commit 1de5774d authored by Robert Maynard's avatar Robert Maynard Committed by Kitware Robot

Merge topic 'just_infer_execution_signature'

cf2d62fb Remove unneeded ExecutionSignatures
c3f0060c ExecutionSignatures are now optional for simple worklets
1b08521f Merge branch 'upstream-taotuple'
c6d30956 taotuple 2019-10-08 (0d1e4dfd)
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: Kenneth Moreland's avatarKenneth Moreland <kmorel@sandia.gov>
Merge-request: !1882
parents c68919fc cf2d62fb
ExecutionSignatures are now optional for simple worklets
If a worklet doesn't explicitly state an `ExecutionSignature`, VTK-m
assumes the worklet has no return value, and each `ControlSignature`
argument is passed to the worklet in the same order.
For example if we had this worklet:
```cxx
struct DotProduct : public vtkm::worklet::WorkletMapField
{
using ControlSignature = void(FieldIn, FieldIn, FieldOut);
using ExecutionSignature = void(_1, _2, _3);
template <typename T, vtkm::IdComponent Size>
VTKM_EXEC void operator()(const vtkm::Vec<T, Size>& v1,
const vtkm::Vec<T, Size>& v2,
T& outValue) const
{
outValue = vtkm::Dot(v1, v2);
}
};
```
It can be simplified to be:
```cxx
struct DotProduct : public vtkm::worklet::WorkletMapField
{
using ControlSignature = void(FieldIn, FieldIn, FieldOut);
template <typename T, vtkm::IdComponent Size>
VTKM_EXEC void operator()(const vtkm::Vec<T, Size>& v1,
const vtkm::Vec<T, Size>& v2,
T& outValue) const
{
outValue = vtkm::Dot(v1, v2);
}
};
......@@ -29,7 +29,6 @@ namespace worklet
struct HelloWorklet : public vtkm::worklet::WorkletMapField
{
using ControlSignature = void(FieldIn inVector, FieldOut outMagnitude);
using ExecutionSignature = void(_1, _2);
VTKM_EXEC void operator()(const vtkm::Vec3f& inVector, vtkm::FloatDefault& outMagnitude) const
{
......
......@@ -15,7 +15,6 @@ namespace
struct ComputeReverseMapping : public vtkm::worklet::WorkletMapField
{
using ControlSignature = void(FieldIn cellIndex, WholeArrayOut cellIds);
using ExecutionSignature = void(_1, _2);
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename PortalType>
......
......@@ -43,11 +43,13 @@ namespace vtkmstd
using simple_tuple::get;
using simple_tuple::make_tuple;
using simple_tuple::tuple;
using simple_tuple::tuple_element;
using simple_tuple::tuple_size;
#else
using tao::get;
using tao::make_tuple;
using tao::tuple;
using tao::tuple_element;
using tao::tuple_size;
#endif
......
......@@ -23,7 +23,6 @@ class CrossProduct : public vtkm::worklet::WorkletMapField
{
public:
using ControlSignature = void(FieldIn, FieldIn, FieldOut);
using ExecutionSignature = void(_1, _2, _3);
template <typename T>
VTKM_EXEC void operator()(const vtkm::Vec<T, 3>& vec1,
......
......@@ -23,7 +23,6 @@ class DotProduct : public vtkm::worklet::WorkletMapField
{
public:
using ControlSignature = void(FieldIn, FieldIn, FieldOut);
using ExecutionSignature = void(_1, _2, _3);
template <typename T, vtkm::IdComponent Size>
VTKM_EXEC void operator()(const vtkm::Vec<T, Size>& v1,
......
......@@ -23,7 +23,6 @@ class Magnitude : public vtkm::worklet::WorkletMapField
{
public:
using ControlSignature = void(FieldIn, FieldOut);
using ExecutionSignature = void(_1, _2);
template <typename T, typename T2>
VTKM_EXEC void operator()(const T& inValue, T2& outValue) const
......
......@@ -23,7 +23,6 @@ class Normal : public vtkm::worklet::WorkletMapField
{
public:
using ControlSignature = void(FieldIn, FieldOut);
using ExecutionSignature = void(_1, _2);
template <typename T, typename T2>
VTKM_EXEC void operator()(const T& inValue, T2& outValue) const
......@@ -36,7 +35,6 @@ class Normalize : public vtkm::worklet::WorkletMapField
{
public:
using ControlSignature = void(FieldInOut);
using ExecutionSignature = void(_1);
template <typename T>
VTKM_EXEC void operator()(T& value) const
......
......@@ -27,7 +27,6 @@ public:
struct DistributeCellData : public vtkm::worklet::WorkletMapField
{
using ControlSignature = void(FieldIn inIndices, FieldOut outIndices);
using ExecutionSignature = void(_1, _2);
using ScatterType = vtkm::worklet::ScatterCounting;
......
......@@ -29,8 +29,6 @@ struct DivergenceTypes
struct Divergence : public vtkm::worklet::WorkletMapField
{
using ControlSignature = void(FieldIn input, FieldOut output);
using ExecutionSignature = void(_1, _2);
using InputDomain = _1;
template <typename InputType, typename OutputType>
VTKM_EXEC void operator()(const InputType& input, OutputType& divergence) const
......
......@@ -28,8 +28,6 @@ struct QCriterionTypes
struct QCriterion : public vtkm::worklet::WorkletMapField
{
using ControlSignature = void(FieldIn input, FieldOut output);
using ExecutionSignature = void(_1, _2);
using InputDomain = _1;
template <typename InputType, typename OutputType>
VTKM_EXEC void operator()(const InputType& input, OutputType& qcriterion) const
......
......@@ -31,9 +31,6 @@ struct Transpose3x3 : vtkm::worklet::WorkletMapField
{
using ControlSignature = void(FieldInOut field);
using ExecutionSignature = void(_1);
using InputDomain = _1;
template <typename FieldInVecType>
VTKM_EXEC void operator()(FieldInVecType& field) const
{
......
......@@ -29,8 +29,6 @@ struct VorticityTypes
struct Vorticity : public vtkm::worklet::WorkletMapField
{
using ControlSignature = void(FieldIn input, FieldOut output);
using ExecutionSignature = void(_1, _2);
using InputDomain = _1;
template <typename InputType, typename OutputType>
VTKM_EXEC void operator()(const InputType& input, OutputType& vorticity) const
......
......@@ -12,6 +12,7 @@ set(headers
DecayHelpers.h
DispatcherBase.h
MaskBase.h
Placeholders.h
ScatterBase.h
TriangulateTables.h
WorkletBase.h
......
......@@ -489,8 +489,12 @@ private:
protected:
using ControlInterface =
vtkm::internal::FunctionInterface<typename WorkletType::ControlSignature>;
using ExecutionInterface =
vtkm::internal::FunctionInterface<typename WorkletType::ExecutionSignature>;
// We go through the GetExecSig as that generates a default ExecutionSignature
// if one doesn't exist on the worklet
using ExecutionSignature =
typename vtkm::placeholders::GetExecSig<WorkletType>::ExecutionSignature;
using ExecutionInterface = vtkm::internal::FunctionInterface<ExecutionSignature>;
static constexpr vtkm::IdComponent NUM_INVOKE_PARAMS = ControlInterface::ARITY;
......
//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#ifndef vtk_m_worklet_internal_Placeholders_h
#define vtk_m_worklet_internal_Placeholders_h
#include <vtkmtaotuple/include/Tuple.h>
#include <vtkmtaotuple/include/tao/seq/make_integer_sequence.hpp>
#include <type_traits>
#include <vtkm/exec/arg/BasicArg.h>
namespace vtkm
{
namespace placeholders
{
//============================================================================
template <int ControlSignatureIndex>
struct Arg : vtkm::exec::arg::BasicArg<ControlSignatureIndex>
{
};
//============================================================================
/**
* Type that computes the number of parameters to the given function signature
*/
template <typename>
struct FunctionSigArity;
template <typename R, typename... ArgTypes>
struct FunctionSigArity<R(ArgTypes...)>
{
static constexpr std::size_t value = sizeof...(ArgTypes);
};
//============================================================================
template <int... Args>
auto DefaultSigGenerator(tao::seq::integer_sequence<int, 0, Args...>) -> void (*)(Arg<Args>...);
/**
* Given a desired length will generate the default/assumed ExecutionSignature.
*
* So if you want the ExecutionSignature for a function that has 2 parameters this
* would generate a `type` that is comparable to the user writing:
*
* using ExecutionSignature = void(_1, _2);
*
*/
template <int Length>
struct DefaultExecSig
{
using seq = tao::seq::make_integer_sequence<int, Length + 1>;
using type = typename std::remove_pointer<decltype(DefaultSigGenerator(seq{}))>::type;
};
template <>
struct DefaultExecSig<1>
{
using type = void(Arg<1>);
};
template <>
struct DefaultExecSig<2>
{
using type = void(Arg<1>, Arg<2>);
};
template <>
struct DefaultExecSig<3>
{
using type = void(Arg<1>, Arg<2>, Arg<3>);
};
template <>
struct DefaultExecSig<4>
{
using type = void(Arg<1>, Arg<2>, Arg<3>, Arg<4>);
};
//============================================================================
/**
* Given a worklet this will produce a typedef `ExecutionSignature` that is
* the ExecutionSignature of the worklet, even if the worklet itself doesn't
* have said typedef.
*
* Logic this class uses:
*
* 1. If the `WorkletType` has a typedef named `ExecutionSignature` use that
* 2. If no typedef exists, generate one!
* - Presume the Worklet has a `void` return type, and each ControlSignature
* argument is passed to the worklet in the same listed order.
* - Generate this assumed `ExecutionSignature` by using `DefaultExecSig`
*
*/
template <typename WorkletType>
struct GetExecSig
{
template <typename U, typename S = decltype(std::declval<typename U::ExecutionSignature>())>
static vtkmstd::tuple<std::true_type, typename U::ExecutionSignature> get_exec_sig(int);
template <typename U>
static vtkmstd::tuple<std::false_type, std::false_type> get_exec_sig(...);
using cont_sig = typename WorkletType::ControlSignature;
using cont_sig_info = vtkm::placeholders::FunctionSigArity<cont_sig>;
using result = decltype(get_exec_sig<WorkletType>(0));
using has_explicit_exec_sig = typename vtkmstd::tuple_element<0, result>::type;
using ExecutionSignature = typename std::conditional<
has_explicit_exec_sig::value,
typename vtkmstd::tuple_element<1, result>::type,
typename vtkm::placeholders::DefaultExecSig<cont_sig_info::value>::type>::type;
};
}
}
#endif
......@@ -40,18 +40,10 @@
#include <vtkm/worklet/MaskNone.h>
#include <vtkm/worklet/ScatterIdentity.h>
#include <vtkm/worklet/internal/Placeholders.h>
namespace vtkm
{
namespace placeholders
{
template <int ControlSignatureIndex>
struct Arg : vtkm::exec::arg::BasicArg<ControlSignatureIndex>
{
};
}
namespace worklet
{
namespace internal
......
......@@ -65,7 +65,6 @@ public:
ZFPDims = PaddedDims / 4;
}
using ControlSignature = void(FieldIn, WholeArrayOut, WholeArrayIn bitstream);
using ExecutionSignature = void(_1, _2, _3);
template <typename InputScalarPortal, typename BitstreamPortal>
VTKM_EXEC void operator()(const vtkm::Id blockIdx,
......
......@@ -77,7 +77,6 @@ public:
ZFPDims[1] = PaddedDims[1] / 4;
}
using ControlSignature = void(FieldIn, WholeArrayOut, WholeArrayIn bitstream);
using ExecutionSignature = void(_1, _2, _3);
template <typename InputScalarPortal, typename BitstreamPortal>
VTKM_EXEC void operator()(const vtkm::Id blockIdx,
......
......@@ -85,7 +85,6 @@ public:
ZFPDims[2] = PaddedDims[2] / 4;
}
using ControlSignature = void(FieldIn, WholeArrayOut, WholeArrayIn bitstream);
using ExecutionSignature = void(_1, _2, _3);
template <typename InputScalarPortal, typename BitstreamPortal>
VTKM_EXEC void operator()(const vtkm::Id blockIdx,
......
......@@ -71,7 +71,6 @@ public:
ZFPDims = PaddedDims / 4;
}
using ControlSignature = void(FieldIn, WholeArrayIn, AtomicArrayInOut bitstream);
using ExecutionSignature = void(_1, _2, _3);
template <class InputScalarPortal, typename BitstreamPortal>
VTKM_EXEC void operator()(const vtkm::Id blockIdx,
......
......@@ -84,7 +84,6 @@ public:
ZFPDims[1] = PaddedDims[1] / 4;
}
using ControlSignature = void(FieldIn, WholeArrayIn, AtomicArrayInOut bitstream);
using ExecutionSignature = void(_1, _2, _3);
template <class InputScalarPortal, typename BitstreamPortal>
VTKM_EXEC void operator()(const vtkm::Id blockIdx,
......
......@@ -103,7 +103,6 @@ public:
ZFPDims[2] = PaddedDims[2] / 4;
}
using ControlSignature = void(FieldIn, WholeArrayIn, AtomicArrayInOut bitstream);
using ExecutionSignature = void(_1, _2, _3);
template <typename InputScalarPortal, typename BitstreamPortal>
VTKM_EXEC void operator()(const vtkm::Id blockIdx,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment