mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-08 13:23:51 +00:00
Extend vtkm::DeviceAdapterTraits to include a unique numeric identifier.
Previously each device adapter only had a unique string name. This was not the best when it came to developing data structures to track the status of a given device at runtime. This adds in a unique numeric identifier to each device adapter. This will allow classes to easily create bitmasks / lookup tables for the validity of devices.
This commit is contained in:
parent
f96206338f
commit
c70da5fc23
@ -51,8 +51,8 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
typedef VTKM_DEFAULT_DEVICE_ADAPTER_TAG DeviceAdapter;
|
||||
std::cout << "Device Adapter Id: "
|
||||
<< vtkm::cont::DeviceAdapterTraits<DeviceAdapter>::GetId()
|
||||
std::cout << "Device Adapter Name: "
|
||||
<< vtkm::cont::DeviceAdapterTraits<DeviceAdapter>::GetName()
|
||||
<< std::endl;
|
||||
|
||||
vtkm::io::reader::VTKDataSetReader reader(argv[1]);
|
||||
|
@ -198,7 +198,7 @@ int main(int argc, char** argv)
|
||||
{
|
||||
typedef vtkm::cont::DeviceAdapterTraits<DeviceAdapter> DeviceAdapterTraits;
|
||||
std::cout << "Running Hello World example on device adapter: "
|
||||
<< DeviceAdapterTraits::GetId() << std::endl;
|
||||
<< DeviceAdapterTraits::GetName() << std::endl;
|
||||
|
||||
glewExperimental = GL_TRUE;
|
||||
glutInit(&argc, argv);
|
||||
|
@ -237,7 +237,7 @@ int main(int argc, char* argv[])
|
||||
typedef vtkm::cont::CellSetStructured<3> CellSet;
|
||||
|
||||
std::cout << "Running IsosurfaceUniformGrid example on device adapter: "
|
||||
<< DeviceAdapterTraits::GetId() << std::endl;
|
||||
<< DeviceAdapterTraits::GetName() << std::endl;
|
||||
|
||||
vtkm::cont::DataSet dataSet = MakeIsosurfaceTestDataSet(dims);
|
||||
vtkm::cont::ArrayHandle<vtkm::Float32> fieldArray;
|
||||
|
@ -69,12 +69,12 @@ void run_if_valid(vtkm::cont::ArrayHandle< vtkm::Vec< T, 3 > > inHandle,
|
||||
if(DeviceAdapterTraits::Valid)
|
||||
{
|
||||
std::cout << "Running a worklet on device adapter: "
|
||||
<< DeviceAdapterTraits::GetId() << std::endl;
|
||||
<< DeviceAdapterTraits::GetName() << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Unable to run a worklet on device adapter: "
|
||||
<< DeviceAdapterTraits::GetId() << std::endl;
|
||||
<< DeviceAdapterTraits::GetName() << std::endl;
|
||||
}
|
||||
|
||||
CanRun<DeviceAdapterTraits::Valid>::run(inHandle,outCoords,outColors,tag);
|
||||
|
@ -26,9 +26,9 @@
|
||||
//a valid tag when VTKM_CUDA is true. This is for easier development
|
||||
//of multi-backend systems
|
||||
#ifdef VTKM_CUDA
|
||||
VTKM_VALID_DEVICE_ADAPTER(Cuda);
|
||||
VTKM_VALID_DEVICE_ADAPTER(Cuda, VTKM_DEVICE_ADAPTER_CUDA);
|
||||
#else
|
||||
VTKM_INVALID_DEVICE_ADAPTER(Cuda);
|
||||
VTKM_INVALID_DEVICE_ADAPTER(Cuda, VTKM_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_VALID_DEVICE_ADAPTER(Error);
|
||||
VTKM_VALID_DEVICE_ADAPTER(Error, VTKM_DEVICE_ADAPTER_ERROR);
|
||||
|
||||
#endif //vtk_m_cont_internal_DeviceAdapterError_h
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include <vtkm/StaticAssert.h>
|
||||
#include <vtkm/internal/Configure.h>
|
||||
#include <vtkm/internal/ExportMacros.h>
|
||||
#include <vtkm/Types.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
@ -49,7 +50,8 @@
|
||||
namespace vtkm {
|
||||
namespace cont {
|
||||
|
||||
typedef std::string DeviceAdapterId;
|
||||
typedef vtkm::Int8 DeviceAdapterId;
|
||||
typedef std::string DeviceAdapterNameType;
|
||||
|
||||
template<typename DeviceAdapter>
|
||||
struct DeviceAdapterTraits;
|
||||
@ -66,14 +68,17 @@ 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_VALID_DEVICE_ADAPTER(Name) \
|
||||
#define VTKM_VALID_DEVICE_ADAPTER(Name, Id) \
|
||||
namespace vtkm { \
|
||||
namespace cont { \
|
||||
struct DeviceAdapterTag##Name { }; \
|
||||
template<> \
|
||||
struct DeviceAdapterTraits<vtkm::cont::DeviceAdapterTag##Name> { \
|
||||
static DeviceAdapterId GetId() { \
|
||||
return DeviceAdapterId(#Name); \
|
||||
return DeviceAdapterId(Id); \
|
||||
} \
|
||||
static DeviceAdapterNameType GetName() { \
|
||||
return DeviceAdapterNameType(#Name); \
|
||||
} \
|
||||
static const bool Valid = true;\
|
||||
}; \
|
||||
@ -85,16 +90,19 @@ struct DeviceAdapterTagCheck
|
||||
}
|
||||
|
||||
/// Marks the tag named vtkm::cont::DeviceAdapterTagName and associated
|
||||
/// structures as valid to use. Always use this macro (in the base namespace)
|
||||
/// structures as invalid to use. Always use this macro (in the base namespace)
|
||||
/// when creating a device adapter.
|
||||
#define VTKM_INVALID_DEVICE_ADAPTER(Name) \
|
||||
#define VTKM_INVALID_DEVICE_ADAPTER(Name, Id) \
|
||||
namespace vtkm { \
|
||||
namespace cont { \
|
||||
struct DeviceAdapterTag##Name { }; \
|
||||
template<> \
|
||||
struct DeviceAdapterTraits<vtkm::cont::DeviceAdapterTag##Name> { \
|
||||
static DeviceAdapterId GetId() { \
|
||||
return DeviceAdapterId(#Name); \
|
||||
return DeviceAdapterId(Id); \
|
||||
} \
|
||||
static DeviceAdapterNameType GetName() { \
|
||||
return DeviceAdapterNameType(#Name); \
|
||||
} \
|
||||
static const bool Valid = false;\
|
||||
}; \
|
||||
|
@ -22,6 +22,6 @@
|
||||
|
||||
#include <vtkm/cont/internal/DeviceAdapterTag.h>
|
||||
|
||||
VTKM_VALID_DEVICE_ADAPTER(Serial);
|
||||
VTKM_VALID_DEVICE_ADAPTER(Serial, VTKM_DEVICE_ADAPTER_SERIAL);
|
||||
|
||||
#endif //vtk_m_cont_internal_DeviceAdapterTagSerial_h
|
||||
|
@ -26,9 +26,9 @@
|
||||
//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);
|
||||
VTKM_VALID_DEVICE_ADAPTER(TBB, VTKM_DEVICE_ADAPTER_TBB);
|
||||
#else
|
||||
VTKM_INVALID_DEVICE_ADAPTER(TBB);
|
||||
VTKM_INVALID_DEVICE_ADAPTER(TBB, VTKM_DEVICE_ADAPTER_TBB);
|
||||
#endif
|
||||
|
||||
#endif //vtk_m_cont_tbb_internal_DeviceAdapterTagTBB_h
|
||||
|
@ -292,6 +292,11 @@ private:
|
||||
"Device adapter Id does not equal itself.");
|
||||
VTKM_TEST_ASSERT(Traits::GetId() != ErrorTraits::GetId(),
|
||||
"Device adapter Id not distinguishable from others.");
|
||||
|
||||
VTKM_TEST_ASSERT(Traits::GetName() == Traits::GetName(),
|
||||
"Device adapter Name does not equal itself.");
|
||||
VTKM_TEST_ASSERT(Traits::GetName() != ErrorTraits::GetName(),
|
||||
"Device adapter Name not distinguishable from others.");
|
||||
}
|
||||
|
||||
// Note: this test does not actually test to make sure the data is available
|
||||
|
@ -33,7 +33,7 @@
|
||||
|
||||
#include <vtkm/cont/testing/TestingDeviceAdapter.h>
|
||||
|
||||
VTKM_VALID_DEVICE_ADAPTER(TestAlgorithmGeneral);
|
||||
VTKM_VALID_DEVICE_ADAPTER(TestAlgorithmGeneral, -3);
|
||||
|
||||
namespace vtkm {
|
||||
namespace cont {
|
||||
|
@ -173,7 +173,7 @@ void TestWorkletMapField()
|
||||
typedef vtkm::cont::DeviceAdapterTraits<
|
||||
VTKM_DEFAULT_DEVICE_ADAPTER_TAG> DeviceAdapterTraits;
|
||||
std::cout << "Testing Map Field on device adapter: "
|
||||
<< DeviceAdapterTraits::GetId() << std::endl;
|
||||
<< DeviceAdapterTraits::GetName() << std::endl;
|
||||
|
||||
std::cout << "--- Worklet accepting all types." << std::endl;
|
||||
vtkm::testing::Testing::TryTypes(
|
||||
|
@ -115,7 +115,7 @@ void TestWorkletMapFieldExecArg()
|
||||
typedef vtkm::cont::DeviceAdapterTraits<
|
||||
VTKM_DEFAULT_DEVICE_ADAPTER_TAG> DeviceAdapterTraits;
|
||||
std::cout << "Testing Worklet with ExecutionWholeArray on device adapter: "
|
||||
<< DeviceAdapterTraits::GetId() << std::endl;
|
||||
<< DeviceAdapterTraits::GetName() << std::endl;
|
||||
|
||||
std::cout << "--- Worklet accepting all types." << std::endl;
|
||||
vtkm::testing::Testing::TryTypes(
|
||||
|
@ -117,7 +117,7 @@ void TestWorkletMapFieldExecArg()
|
||||
typedef vtkm::cont::DeviceAdapterTraits<
|
||||
VTKM_DEFAULT_DEVICE_ADAPTER_TAG> DeviceAdapterTraits;
|
||||
std::cout << "Testing Worklet with WholeArray on device adapter: "
|
||||
<< DeviceAdapterTraits::GetId() << std::endl;
|
||||
<< DeviceAdapterTraits::GetName() << std::endl;
|
||||
|
||||
std::cout << "--- Worklet accepting all types." << std::endl;
|
||||
vtkm::testing::Testing::TryTypes(
|
||||
|
@ -139,7 +139,7 @@ void TestWorkletMapTopologyExplicit()
|
||||
typedef vtkm::cont::DeviceAdapterTraits<
|
||||
VTKM_DEFAULT_DEVICE_ADAPTER_TAG> DeviceAdapterTraits;
|
||||
std::cout << "Testing Topology Worklet ( Explicit ) on device adapter: "
|
||||
<< DeviceAdapterTraits::GetId() << std::endl;
|
||||
<< DeviceAdapterTraits::GetName() << std::endl;
|
||||
|
||||
TestMaxPointOrCell();
|
||||
TestAvgPointToCell();
|
||||
|
@ -167,7 +167,7 @@ void TestWorkletMapTopologyRegular()
|
||||
typedef vtkm::cont::DeviceAdapterTraits<
|
||||
VTKM_DEFAULT_DEVICE_ADAPTER_TAG> DeviceAdapterTraits;
|
||||
std::cout << "Testing Topology Worklet ( Regular ) on device adapter: "
|
||||
<< DeviceAdapterTraits::GetId() << std::endl;
|
||||
<< DeviceAdapterTraits::GetName() << std::endl;
|
||||
|
||||
TestMaxPointOrCell();
|
||||
TestAvgPointToCell();
|
||||
|
Loading…
Reference in New Issue
Block a user