2016-12-19 20:55:17 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2016-12-19 20:55:17 +00:00
|
|
|
// 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_DispatcherReduceByKey_h
|
|
|
|
#define vtk_m_worklet_DispatcherReduceByKey_h
|
|
|
|
|
|
|
|
#include <vtkm/cont/DeviceAdapter.h>
|
|
|
|
|
|
|
|
#include <vtkm/worklet/WorkletReduceByKey.h>
|
|
|
|
|
|
|
|
#include <vtkm/worklet/internal/DispatcherBase.h>
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace worklet
|
|
|
|
{
|
2016-12-19 20:55:17 +00:00
|
|
|
|
|
|
|
/// \brief Dispatcher for worklets that inherit from \c WorkletReduceByKey.
|
|
|
|
///
|
2018-08-28 20:36:50 +00:00
|
|
|
template <typename WorkletType>
|
2016-12-19 20:55:17 +00:00
|
|
|
class DispatcherReduceByKey
|
2018-08-28 20:36:50 +00:00
|
|
|
: public vtkm::worklet::internal::DispatcherBase<DispatcherReduceByKey<WorkletType>,
|
2017-05-26 17:53:28 +00:00
|
|
|
WorkletType,
|
|
|
|
vtkm::worklet::WorkletReduceByKey>
|
2016-12-19 20:55:17 +00:00
|
|
|
{
|
2018-08-28 20:36:50 +00:00
|
|
|
using Superclass = vtkm::worklet::internal::DispatcherBase<DispatcherReduceByKey<WorkletType>,
|
|
|
|
WorkletType,
|
|
|
|
vtkm::worklet::WorkletReduceByKey>;
|
Move Scatter from Worklet to Dispatcher
Previously, when a Worklet needed a scatter, the scatter object was
stored in the Worklet object. That was problematic because that means
the Scatter, which is a control object, was shoved into the execution
environment.
To prevent that, move the Scatter into the Dispatcher object. The
worklet still declares a ScatterType alias, but no longer has a
GetScatter method. Instead, the Dispatcher now takes a Scatter object in
its constructor. If using the default scatter (ScatterIdentity), the
default constructor is used. If using another type of Scatter that
requires data to set up its state, then the caller of the worklet needs
to provide that to the dispatcher. For convenience, worklets are
encouraged to have a MakeScatter method to help construct a proper
scatter object.
2018-04-27 04:43:51 +00:00
|
|
|
using ScatterType = typename Superclass::ScatterType;
|
2016-12-19 20:55:17 +00:00
|
|
|
|
|
|
|
public:
|
2019-01-21 02:14:55 +00:00
|
|
|
template <typename... T>
|
|
|
|
VTKM_CONT DispatcherReduceByKey(T&&... args)
|
|
|
|
: Superclass(std::forward<T>(args)...)
|
2017-05-18 14:29:41 +00:00
|
|
|
{
|
|
|
|
}
|
2016-12-19 20:55:17 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename Invocation>
|
2018-06-28 18:29:27 +00:00
|
|
|
void DoInvoke(Invocation& invocation) const
|
2016-12-19 20:55:17 +00:00
|
|
|
{
|
|
|
|
// This is the type for the input domain
|
|
|
|
using InputDomainType = typename Invocation::InputDomainType;
|
|
|
|
|
|
|
|
// If you get a compile error on this line, then you have tried to use
|
|
|
|
// something other than vtkm::worklet::Keys as the input domain, which
|
|
|
|
// is illegal.
|
|
|
|
VTKM_STATIC_ASSERT_MSG(
|
2017-05-18 14:29:41 +00:00
|
|
|
(vtkm::cont::arg::TypeCheck<vtkm::cont::arg::TypeCheckTagKeys, InputDomainType>::value),
|
|
|
|
"Invalid input domain for WorkletReduceByKey.");
|
2016-12-19 20:55:17 +00:00
|
|
|
|
|
|
|
// We can pull the input domain parameter (the data specifying the input
|
|
|
|
// domain) from the invocation object.
|
2017-05-18 14:29:41 +00:00
|
|
|
const InputDomainType& inputDomain = invocation.GetInputDomain();
|
2016-12-19 20:55:17 +00:00
|
|
|
|
|
|
|
// Now that we have the input domain, we can extract the range of the
|
2019-05-15 15:42:02 +00:00
|
|
|
// scheduling and call BasicInvoke.
|
|
|
|
this->BasicInvoke(invocation, internal::scheduling_range(inputDomain));
|
2016-12-19 20:55:17 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
} // namespace vtkm::worklet
|
|
|
|
|
|
|
|
#endif //vtk_m_worklet_DispatcherReduceByKey_h
|