mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-08 13:23:51 +00:00
Add a FunctorBase class for scheduling non-worklets
Whenever creating a functor to be launched in the execution environment using the device adapter Schedule algorithm, you had to also create a couple of methods to handle error message buffers. For convenience, lots of code started to just inherit from WorkletBase. Although this worked, it was a misnomer (and might cause problems in the future if worklets later require different things from its base). To get around this problem, add a FunctorBase class that is intended to be used as the superclass to functors called with Schedule.
This commit is contained in:
parent
3ed7093945
commit
b012668345
@ -24,8 +24,9 @@
|
||||
#include <vtkm/cont/ArrayHandleCounting.h>
|
||||
#include <vtkm/cont/ArrayContainerControlBasic.h>
|
||||
|
||||
#include <vtkm/exec/FunctorBase.h>
|
||||
|
||||
#include <vtkm/exec/internal/ErrorMessageBuffer.h>
|
||||
#include <vtkm/exec/internal/WorkletBase.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
@ -392,7 +393,7 @@ public:
|
||||
// Scan Inclusive
|
||||
private:
|
||||
template<typename PortalType>
|
||||
struct ScanKernel : vtkm::exec::internal::WorkletBase
|
||||
struct ScanKernel : vtkm::exec::FunctorBase
|
||||
{
|
||||
PortalType Portal;
|
||||
vtkm::Id Stride;
|
||||
@ -465,7 +466,7 @@ public:
|
||||
// Sort
|
||||
private:
|
||||
template<typename PortalType, typename CompareType>
|
||||
struct BitonicSortMergeKernel : vtkm::exec::internal::WorkletBase
|
||||
struct BitonicSortMergeKernel : vtkm::exec::FunctorBase
|
||||
{
|
||||
PortalType Portal;
|
||||
CompareType Compare;
|
||||
@ -503,7 +504,7 @@ private:
|
||||
};
|
||||
|
||||
template<typename PortalType, typename CompareType>
|
||||
struct BitonicSortCrossoverKernel : vtkm::exec::internal::WorkletBase
|
||||
struct BitonicSortCrossoverKernel : vtkm::exec::FunctorBase
|
||||
{
|
||||
PortalType Portal;
|
||||
CompareType Compare;
|
||||
|
@ -19,6 +19,7 @@
|
||||
##============================================================================
|
||||
|
||||
set(headers
|
||||
FunctorBase.h
|
||||
)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
|
67
vtkm/exec/FunctorBase.h
Normal file
67
vtkm/exec/FunctorBase.h
Normal file
@ -0,0 +1,67 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//
|
||||
// Copyright 2014 Sandia Corporation.
|
||||
// Copyright 2014 UT-Battelle, LLC.
|
||||
// Copyright 2014. Los Alamos National Security
|
||||
//
|
||||
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||
// the U.S. Government retains certain rights in this software.
|
||||
//
|
||||
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||
// this software.
|
||||
//============================================================================
|
||||
#ifndef vtk_m_exec_FunctorBase_h
|
||||
#define vtk_m_exec_FunctorBase_h
|
||||
|
||||
#include <vtkm/Types.h>
|
||||
|
||||
#include <vtkm/exec/internal/ErrorMessageBuffer.h>
|
||||
|
||||
namespace vtkm {
|
||||
namespace exec {
|
||||
|
||||
/// Base class for all functors invoked in the execution environment from a
|
||||
/// call to vtkm::cont::DeviceAdapterAlgorithm::Schedule. Subclasses must
|
||||
/// implement operator() const with an index argument.
|
||||
///
|
||||
/// This class contains a public method named RaiseError that can be called in
|
||||
/// the execution environment to signal a problem.
|
||||
///
|
||||
class FunctorBase
|
||||
{
|
||||
public:
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
FunctorBase() { }
|
||||
|
||||
VTKM_EXEC_EXPORT
|
||||
void RaiseError(const char *message) const
|
||||
{
|
||||
this->ErrorMessage.RaiseError(message);
|
||||
}
|
||||
|
||||
/// Set the error message buffer so that running algorithms can report
|
||||
/// errors. This is supposed to be set by the dispatcher. This method may be
|
||||
/// replaced as the execution semantics change.
|
||||
///
|
||||
VTKM_CONT_EXPORT
|
||||
void SetErrorMessageBuffer(
|
||||
const vtkm::exec::internal::ErrorMessageBuffer &buffer)
|
||||
{
|
||||
this->ErrorMessage = buffer;
|
||||
}
|
||||
|
||||
private:
|
||||
vtkm::exec::internal::ErrorMessageBuffer ErrorMessage;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace vtkm::exec
|
||||
|
||||
#endif //vtk_m_exec_FunctorBase_h
|
@ -17,8 +17,8 @@
|
||||
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||
// this software.
|
||||
//============================================================================
|
||||
#ifndef vtkm_exec_internal_ErrorMessageBuffer_h
|
||||
#define vtkm_exec_internal_ErrorMessageBuffer_h
|
||||
#ifndef vtk_m_exec_internal_ErrorMessageBuffer_h
|
||||
#define vtk_m_exec_internal_ErrorMessageBuffer_h
|
||||
|
||||
#include <vtkm/Types.h>
|
||||
|
||||
@ -91,4 +91,4 @@ private:
|
||||
}
|
||||
} // namespace vtkm::exec::internal
|
||||
|
||||
#endif // vtkm_exec_internal_ErrorMessageBuffer_h
|
||||
#endif // vtk_m_exec_internal_ErrorMessageBuffer_h
|
||||
|
@ -17,48 +17,25 @@
|
||||
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||
// this software.
|
||||
//============================================================================
|
||||
#ifndef vtkm_exec_WorkletBase_h
|
||||
#define vtkm_exec_WorkletBase_h
|
||||
#ifndef vtk_m_exec_internal_WorkletBase_h
|
||||
#define vtk_m_exec_internal_WorkletBase_h
|
||||
|
||||
#include <vtkm/Types.h>
|
||||
|
||||
#include <vtkm/exec/internal/ErrorMessageBuffer.h>
|
||||
#include <vtkm/exec/FunctorBase.h>
|
||||
|
||||
namespace vtkm {
|
||||
namespace exec {
|
||||
namespace internal {
|
||||
|
||||
/// Base class for all worklet classes. Worklet classes are subclasses and a
|
||||
/// operator() const is added to implement an algorithm in Dax. Different
|
||||
/// operator() const is added to implement an algorithm in VTK-m. Different
|
||||
/// worklets have different calling semantics.
|
||||
///
|
||||
class WorkletBase
|
||||
class WorkletBase : public FunctorBase
|
||||
{
|
||||
public:
|
||||
VTKM_EXEC_CONT_EXPORT WorkletBase() { }
|
||||
|
||||
VTKM_EXEC_EXPORT void RaiseError(const char *message) const
|
||||
{
|
||||
this->ErrorMessage.RaiseError(message);
|
||||
}
|
||||
|
||||
/// Set the error message buffer so that running algorithms can report
|
||||
/// errors. This is supposed to be set by the dispatcher. This method may be
|
||||
/// replaced as the execution semantics change.
|
||||
///
|
||||
VTKM_CONT_EXPORT void SetErrorMessageBuffer(
|
||||
const vtkm::exec::internal::ErrorMessageBuffer &buffer)
|
||||
{
|
||||
this->ErrorMessage = buffer;
|
||||
}
|
||||
|
||||
private:
|
||||
vtkm::exec::internal::ErrorMessageBuffer ErrorMessage;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::exec::internal
|
||||
|
||||
#endif //vtkm_exec_WorkletBase_h
|
||||
#endif //vtk_m_exec_internal_WorkletBase_h
|
||||
|
Loading…
Reference in New Issue
Block a user