ff687016ee
It is very easy to cause ODR violations with DeviceAdapterTagCuda. If you include that header from a C++ file and a CUDA file inside the same program we an ODR violation. The reasons is that the C++ versions will say the tag is invalid, and the CUDA will say the tag is valid. The solution to this is that any compilation unit that includes DeviceAdapterTagCuda from a version of VTK-m that has CUDA enabled must be invoked by the cuda compiler.
73 lines
2.2 KiB
C++
73 lines
2.2 KiB
C++
//============================================================================
|
|
// 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_cont_ExecutionObjectBase_h
|
|
#define vtk_m_cont_ExecutionObjectBase_h
|
|
|
|
#include <vtkm/Types.h>
|
|
|
|
#include <vtkm/cont/serial/internal/DeviceAdapterTagSerial.h>
|
|
|
|
namespace vtkm
|
|
{
|
|
namespace cont
|
|
{
|
|
|
|
/// Base \c ExecutionObjectBase for execution objects to inherit from so that
|
|
/// you can use an arbitrary object as a parameter in an execution environment
|
|
/// function. Any subclass of \c ExecutionObjectBase must implement a
|
|
/// \c PrepareForExecution method that takes a device adapter tag and returns
|
|
/// an object for that device.
|
|
///
|
|
struct ExecutionObjectBase
|
|
{
|
|
};
|
|
|
|
namespace internal
|
|
{
|
|
|
|
namespace detail
|
|
{
|
|
|
|
struct CheckPrepareForExecution
|
|
{
|
|
template <typename T>
|
|
static auto check(T* p)
|
|
-> decltype(p->PrepareForExecution(vtkm::cont::DeviceAdapterTagSerial{}), std::true_type());
|
|
|
|
template <typename T>
|
|
static auto check(...) -> std::false_type;
|
|
};
|
|
|
|
} // namespace detail
|
|
|
|
template <typename T>
|
|
using IsExecutionObjectBase =
|
|
std::is_base_of<vtkm::cont::ExecutionObjectBase, typename std::decay<T>::type>;
|
|
|
|
template <typename T>
|
|
struct HasPrepareForExecution
|
|
: decltype(detail::CheckPrepareForExecution::check<typename std::decay<T>::type>(nullptr))
|
|
{
|
|
};
|
|
|
|
} // namespace internal
|
|
}
|
|
} // namespace vtkm::cont
|
|
|
|
/// Checks that the argument is a proper execution object.
|
|
///
|
|
#define VTKM_IS_EXECUTION_OBJECT(execObject) \
|
|
static_assert(::vtkm::cont::internal::IsExecutionObjectBase<execObject>::value, \
|
|
"Provided type is not a subclass of vtkm::cont::ExecutionObjectBase."); \
|
|
static_assert(::vtkm::cont::internal::HasPrepareForExecution<execObject>::value, \
|
|
"Provided type does not have requisite PrepareForExecution method.")
|
|
|
|
#endif //vtk_m_cont_ExecutionObjectBase_h
|