Merge topic 'allow_for_easier_scheduling_range_overloads'

36161b42c Renamed to SchedulingRange to follow VTK-m naming convention
40c0c0fef Allow for easier overloads of scheduling_range

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !1952
This commit is contained in:
Robert Maynard 2020-01-29 20:18:51 +00:00 committed by Kitware Robot
commit 124fb23c50
8 changed files with 73 additions and 35 deletions

@ -41,6 +41,8 @@ public:
template <typename Invocation> template <typename Invocation>
VTKM_CONT void DoInvoke(Invocation& invocation) const VTKM_CONT void DoInvoke(Invocation& invocation) const
{ {
using namespace vtkm::worklet::internal;
// This is the type for the input domain // This is the type for the input domain
using InputDomainType = typename Invocation::InputDomainType; using InputDomainType = typename Invocation::InputDomainType;
@ -52,7 +54,7 @@ public:
// an VariantArrayHandle that gets cast to one). The size of the domain // an VariantArrayHandle that gets cast to one). The size of the domain
// (number of threads/worklet instances) is equal to the size of the // (number of threads/worklet instances) is equal to the size of the
// array. // array.
auto numInstances = internal::scheduling_range(inputDomain); auto numInstances = SchedulingRange(inputDomain);
// A MapField is a pretty straightforward dispatch. Once we know the number // A MapField is a pretty straightforward dispatch. Once we know the number
// of invocations, the superclass can take care of the rest. // of invocations, the superclass can take care of the rest.

@ -44,6 +44,8 @@ public:
template <typename Invocation> template <typename Invocation>
VTKM_CONT void DoInvoke(Invocation& invocation) const VTKM_CONT void DoInvoke(Invocation& invocation) const
{ {
using namespace vtkm::worklet::internal;
// This is the type for the input domain // This is the type for the input domain
using InputDomainType = typename Invocation::InputDomainType; using InputDomainType = typename Invocation::InputDomainType;
using SchedulingRangeType = typename WorkletType::VisitTopologyType; using SchedulingRangeType = typename WorkletType::VisitTopologyType;
@ -59,7 +61,7 @@ public:
// Now that we have the input domain, we can extract the range of the // Now that we have the input domain, we can extract the range of the
// scheduling and call BadicInvoke. // scheduling and call BadicInvoke.
this->BasicInvoke(invocation, internal::scheduling_range(inputDomain, SchedulingRangeType{})); this->BasicInvoke(invocation, SchedulingRange(inputDomain, SchedulingRangeType{}));
} }
}; };
} }

@ -45,6 +45,8 @@ public:
template <typename Invocation> template <typename Invocation>
void DoInvoke(Invocation& invocation) const void DoInvoke(Invocation& invocation) const
{ {
using namespace vtkm::worklet::internal;
// This is the type for the input domain // This is the type for the input domain
using InputDomainType = typename Invocation::InputDomainType; using InputDomainType = typename Invocation::InputDomainType;
@ -56,7 +58,7 @@ public:
// We can pull the input domain parameter (the data specifying the input // We can pull the input domain parameter (the data specifying the input
// domain) from the invocation object. // domain) from the invocation object.
const InputDomainType& inputDomain = invocation.GetInputDomain(); const InputDomainType& inputDomain = invocation.GetInputDomain();
auto inputRange = internal::scheduling_range(inputDomain, vtkm::TopologyElementTagPoint{}); auto inputRange = SchedulingRange(inputDomain, vtkm::TopologyElementTagPoint{});
// This is pretty straightforward dispatch. Once we know the number // This is pretty straightforward dispatch. Once we know the number
// of invocations, the superclass can take care of the rest. // of invocations, the superclass can take care of the rest.

@ -44,6 +44,8 @@ public:
template <typename Invocation> template <typename Invocation>
void DoInvoke(Invocation& invocation) const void DoInvoke(Invocation& invocation) const
{ {
using namespace vtkm::worklet::internal;
// This is the type for the input domain // This is the type for the input domain
using InputDomainType = typename Invocation::InputDomainType; using InputDomainType = typename Invocation::InputDomainType;
@ -60,7 +62,7 @@ public:
// Now that we have the input domain, we can extract the range of the // Now that we have the input domain, we can extract the range of the
// scheduling and call BasicInvoke. // scheduling and call BasicInvoke.
this->BasicInvoke(invocation, internal::scheduling_range(inputDomain)); this->BasicInvoke(invocation, SchedulingRange(inputDomain));
} }
}; };
} }

@ -214,6 +214,8 @@ public:
template <typename Invocation> template <typename Invocation>
VTKM_CONT void DoInvoke(Invocation& invocation) const VTKM_CONT void DoInvoke(Invocation& invocation) const
{ {
using namespace vtkm::worklet::internal;
// This is the type for the input domain // This is the type for the input domain
using InputDomainType = typename Invocation::InputDomainType; using InputDomainType = typename Invocation::InputDomainType;
@ -225,15 +227,15 @@ public:
// an VariantArrayHandle that gets cast to one). The size of the domain // an VariantArrayHandle that gets cast to one). The size of the domain
// (number of threads/worklet instances) is equal to the size of the // (number of threads/worklet instances) is equal to the size of the
// array. // array.
vtkm::Id fullSize = internal::scheduling_range(inputDomain); vtkm::Id fullSize = SchedulingRange(inputDomain);
vtkm::Id blockSize = fullSize / NumberOfBlocks; vtkm::Id blockSize = fullSize / NumberOfBlocks;
if (fullSize % NumberOfBlocks != 0) if (fullSize % NumberOfBlocks != 0)
blockSize += 1; blockSize += 1;
using TransformFunctorType = using TransformFunctorType = vtkm::worklet::detail::DispatcherStreamingMapFieldTransformFunctor<
detail::DispatcherStreamingMapFieldTransformFunctor<typename Invocation::ControlInterface>; typename Invocation::ControlInterface>;
using TransferFunctorType = using TransferFunctorType = vtkm::worklet::detail::DispatcherStreamingMapFieldTransferFunctor<
detail::DispatcherStreamingMapFieldTransferFunctor<typename Invocation::ControlInterface>; typename Invocation::ControlInterface>;
for (vtkm::Id block = 0; block < NumberOfBlocks; block++) for (vtkm::Id block = 0; block < NumberOfBlocks; block++)
{ {

@ -176,6 +176,20 @@ private:
template <typename T> template <typename T>
VTKM_CONT Keys<T>::Keys() = default; VTKM_CONT Keys<T>::Keys() = default;
template <typename KeyType>
inline auto SchedulingRange(const vtkm::worklet::Keys<KeyType>& inputDomain)
-> decltype(inputDomain.GetInputRange())
{
return inputDomain.GetInputRange();
}
template <typename KeyType>
inline auto SchedulingRange(const vtkm::worklet::Keys<KeyType>* const inputDomain)
-> decltype(inputDomain->GetInputRange())
{
return inputDomain->GetInputRange();
}
} }
} // namespace vtkm::worklet } // namespace vtkm::worklet

@ -48,47 +48,31 @@ namespace vtkm
{ {
namespace worklet namespace worklet
{ {
template <typename T>
class Keys;
namespace internal namespace internal
{ {
template <typename Domain> template <typename Domain>
inline auto scheduling_range(const Domain& inputDomain) -> decltype(inputDomain.GetNumberOfValues()) inline auto SchedulingRange(const Domain& inputDomain) -> decltype(inputDomain.GetNumberOfValues())
{ {
return inputDomain.GetNumberOfValues(); return inputDomain.GetNumberOfValues();
} }
template <typename KeyType>
inline auto scheduling_range(const vtkm::worklet::Keys<KeyType>& inputDomain)
-> decltype(inputDomain.GetInputRange())
{
return inputDomain.GetInputRange();
}
template <typename Domain> template <typename Domain>
inline auto scheduling_range(const Domain* const inputDomain) inline auto SchedulingRange(const Domain* const inputDomain)
-> decltype(inputDomain->GetNumberOfValues()) -> decltype(inputDomain->GetNumberOfValues())
{ {
return inputDomain->GetNumberOfValues(); return inputDomain->GetNumberOfValues();
} }
template <typename KeyType>
inline auto scheduling_range(const vtkm::worklet::Keys<KeyType>* const inputDomain)
-> decltype(inputDomain->GetInputRange())
{
return inputDomain->GetInputRange();
}
template <typename Domain, typename SchedulingRangeType> template <typename Domain, typename SchedulingRangeType>
inline auto scheduling_range(const Domain& inputDomain, SchedulingRangeType type) inline auto SchedulingRange(const Domain& inputDomain, SchedulingRangeType type)
-> decltype(inputDomain.GetSchedulingRange(type)) -> decltype(inputDomain.GetSchedulingRange(type))
{ {
return inputDomain.GetSchedulingRange(type); return inputDomain.GetSchedulingRange(type);
} }
template <typename Domain, typename SchedulingRangeType> template <typename Domain, typename SchedulingRangeType>
inline auto scheduling_range(const Domain* const inputDomain, SchedulingRangeType type) inline auto SchedulingRange(const Domain* const inputDomain, SchedulingRangeType type)
-> decltype(inputDomain->GetSchedulingRange(type)) -> decltype(inputDomain->GetSchedulingRange(type))
{ {
return inputDomain->GetSchedulingRange(type); return inputDomain->GetSchedulingRange(type);

@ -284,6 +284,18 @@ public:
} }
}; };
template <typename T>
inline vtkm::Id SchedulingRange(const std::vector<T>& inputDomain)
{
return static_cast<vtkm::Id>(inputDomain.size());
}
template <typename T>
inline vtkm::Id SchedulingRange(const std::vector<T>* const inputDomain)
{
return static_cast<vtkm::Id>(inputDomain->size());
}
template <typename WorkletType> template <typename WorkletType>
class TestDispatcher : public vtkm::worklet::internal::DispatcherBase<TestDispatcher<WorkletType>, class TestDispatcher : public vtkm::worklet::internal::DispatcherBase<TestDispatcher<WorkletType>,
WorkletType, WorkletType,
@ -295,19 +307,37 @@ class TestDispatcher : public vtkm::worklet::internal::DispatcherBase<TestDispat
using ScatterType = typename Superclass::ScatterType; using ScatterType = typename Superclass::ScatterType;
public: public:
VTKM_CONT template <typename... T>
TestDispatcher(const WorkletType& worklet = WorkletType(), VTKM_CONT TestDispatcher(T&&... args)
const ScatterType& scatter = ScatterType()) : Superclass(std::forward<T>(args)...)
: Superclass(worklet, scatter)
{ {
} }
VTKM_CONT VTKM_CONT
template <typename Invocation> template <typename Invocation>
void DoInvoke(Invocation&& invocation) const void DoInvoke(Invocation& invocation) const
{ {
std::cout << "In TestDispatcher::DoInvoke()" << std::endl; std::cout << "In TestDispatcher::DoInvoke()" << std::endl;
this->BasicInvoke(invocation, ARRAY_SIZE);
using namespace vtkm::worklet::internal;
// This is the type for the input domain
using InputDomainType = typename Invocation::InputDomainType;
// We can pull the input domain parameter (the data specifying the input
// domain) from the invocation object.
const InputDomainType& inputDomain = invocation.GetInputDomain();
// For a DispatcherMapField, the inputDomain must be an ArrayHandle (or
// an VariantArrayHandle that gets cast to one). The size of the domain
// (number of threads/worklet instances) is equal to the size of the
// array.
//verify the overloads for SchedulingRange work
auto numInstances = SchedulingRange(inputDomain);
// A MapField is a pretty straightforward dispatch. Once we know the number
// of invocations, the superclass can take care of the rest.
this->BasicInvoke(invocation, numInstances);
} }
private: private: