DeviceAdapter Tags now always exist, and contain if the device is valid.

Previously it was really hard to verify if a device adapter was valid. Since
you would have to check for the existence of the tag. Now the tag always
exists, but instead you query the traits of the DeviceAdapter to see if
it is a valid adapter.

This makes compiling with multiple backends alot easier.
This commit is contained in:
Robert Maynard 2015-09-16 16:59:28 -04:00
parent cf32b430dc
commit 4d635d642b
8 changed files with 52 additions and 8 deletions

@ -21,7 +21,10 @@
#define vtk_m_cont_cuda_DeviceAdapterCuda_h
#include <vtkm/cont/cuda/internal/DeviceAdapterTagCuda.h>
#ifdef VTKM_ENABLE_CUDA
#include <vtkm/cont/cuda/internal/ArrayManagerExecutionCuda.h>
#include <vtkm/cont/cuda/internal/DeviceAdapterAlgorithmCuda.h>
#endif
#endif //vtk_m_cont_cuda_DeviceAdapterCuda_h

@ -22,7 +22,13 @@
#include <vtkm/cont/internal/DeviceAdapterTag.h>
VTKM_CREATE_DEVICE_ADAPTER(Cuda);
//We always create the cuda tag when included, but we only mark it as
//a valid tag when VTKM_ENABLE_CUDA is true. This is for easier development
//of multi-backend systems
#ifdef VTKM_ENABLE_CUDA
VTKM_VALID_DEVICE_ADAPTER(Cuda);
#else
VTKM_INVALID_DEVICE_ADAPTER(Cuda);
#endif
#endif //vtk_m_cont_cuda_internal_DeviceAdapterTagCuda_h

@ -27,6 +27,6 @@
/// point, you have to specify an appropriate DeviceAdapter or else get a
/// compile error.
///
VTKM_CREATE_DEVICE_ADAPTER(Error);
VTKM_VALID_DEVICE_ADAPTER(Error);
#endif //vtk_m_cont_internal_DeviceAdapterError_h

@ -61,7 +61,7 @@ struct DeviceAdapterTagCheck
/// Creates a tag named vtkm::cont::DeviceAdapterTagName and associated MPL
/// structures to use this tag. Always use this macro (in the base namespace)
/// when creating a device adapter.
#define VTKM_CREATE_DEVICE_ADAPTER(Name) \
#define VTKM_VALID_DEVICE_ADAPTER(Name) \
namespace vtkm { \
namespace cont { \
struct DeviceAdapterTag##Name { }; \
@ -71,6 +71,7 @@ struct DeviceAdapterTagCheck
static DeviceAdapterId GetId() { \
return DeviceAdapterId(#Name); \
} \
static const bool Valid = true;\
}; \
template<> \
struct DeviceAdapterTagCheck<vtkm::cont::DeviceAdapterTag##Name> { \
@ -80,6 +81,31 @@ struct DeviceAdapterTagCheck
} \
}
/// Marks the tag named vtkm::cont::DeviceAdapterTagName and associated
/// structures as valid to use. Always use this macro (in the base namespace)
/// when creating a device adapter.
#define VTKM_INVALID_DEVICE_ADAPTER(Name) \
namespace vtkm { \
namespace cont { \
struct DeviceAdapterTag##Name { }; \
namespace internal { \
template<> \
struct DeviceAdapterTraits<vtkm::cont::DeviceAdapterTag##Name> { \
static DeviceAdapterId GetId() { \
return DeviceAdapterId(#Name); \
} \
static const bool Valid = false;\
}; \
template<> \
struct DeviceAdapterTagCheck<vtkm::cont::DeviceAdapterTag##Name> { \
static const bool Valid = false; \
}; \
} \
} \
}
/// Checks that the argument is a proper device adapter tag. This is a handy
/// concept check for functions and classes to make sure that a template
/// argument is actually a device adapter tag. (You can get weird errors

@ -22,6 +22,6 @@
#include <vtkm/cont/internal/DeviceAdapterTag.h>
VTKM_CREATE_DEVICE_ADAPTER(Serial);
VTKM_VALID_DEVICE_ADAPTER(Serial);
#endif //vtk_m_cont_internal_DeviceAdapterTagSerial_h

@ -21,7 +21,10 @@
#define vtk_m_cont_tbb_DeviceAdapterTBB_h
#include <vtkm/cont/tbb/internal/DeviceAdapterTagTBB.h>
#ifdef VTKM_ENABLE_TBB
#include <vtkm/cont/tbb/internal/ArrayManagerExecutionTBB.h>
#include <vtkm/cont/tbb/internal/DeviceAdapterAlgorithmTBB.h>
#endif
#endif //vtk_m_cont_tbb_DeviceAdapterTBB_h

@ -22,7 +22,13 @@
#include <vtkm/cont/internal/DeviceAdapterTag.h>
VTKM_CREATE_DEVICE_ADAPTER(TBB);
//We always create the tbb tag when included, but we only mark it as
//a valid tag when VTKM_ENABLE_TBB is true. This is for easier development
//of multi-backend systems
#ifdef VTKM_ENABLE_TBB
VTKM_VALID_DEVICE_ADAPTER(TBB);
#else
VTKM_INVALID_DEVICE_ADAPTER(TBB);
#endif
#endif //vtk_m_cont_tbb_internal_DeviceAdapterTagTBB_h

@ -33,7 +33,7 @@
#include <vtkm/cont/testing/TestingDeviceAdapter.h>
VTKM_CREATE_DEVICE_ADAPTER(TestAlgorithmGeneral);
VTKM_VALID_DEVICE_ADAPTER(TestAlgorithmGeneral);
namespace vtkm {
namespace cont {