From bedf4bc80799d74e34b9a6e4c0b44730501696ae Mon Sep 17 00:00:00 2001 From: Kenneth Moreland Date: Wed, 13 Jul 2022 14:04:08 -0600 Subject: [PATCH] Compile transport on device Now that it is easier to select which unit tests should be compiled by a device compiler (and run on a device), allow the transport classes to be tested on actual devices rather than just the serial device. --- vtkm/cont/arg/testing/CMakeLists.txt | 17 ++++++++------- .../testing/UnitTestControlSignatureTag.cxx | 3 +++ .../arg/testing/UnitTestTransportArrayIn.cxx | 10 +++++---- .../testing/UnitTestTransportArrayInOut.cxx | 9 +++++--- .../arg/testing/UnitTestTransportArrayOut.cxx | 11 ++++++---- .../testing/UnitTestTransportCellSetIn.cxx | 14 ++++++++----- .../testing/UnitTestTransportExecObject.cxx | 21 ++++++++++++------- .../arg/testing/UnitTestTypeCheckArray.cxx | 3 +++ .../arg/testing/UnitTestTypeCheckCellSet.cxx | 3 +++ .../testing/UnitTestTypeCheckExecObject.cxx | 3 +++ .../arg/testing/UnitTestTypeCheckKeys.cxx | 3 +++ 11 files changed, 66 insertions(+), 31 deletions(-) diff --git a/vtkm/cont/arg/testing/CMakeLists.txt b/vtkm/cont/arg/testing/CMakeLists.txt index ecaac866a..209736640 100644 --- a/vtkm/cont/arg/testing/CMakeLists.txt +++ b/vtkm/cont/arg/testing/CMakeLists.txt @@ -10,16 +10,19 @@ set(unit_tests UnitTestControlSignatureTag.cxx - UnitTestTransportArrayIn.cxx - UnitTestTransportArrayInOut.cxx - UnitTestTransportArrayOut.cxx - UnitTestTransportCellSetIn.cxx - UnitTestTransportExecObject.cxx - UnitTestTransportWholeArray.cxx UnitTestTypeCheckArray.cxx UnitTestTypeCheckCellSet.cxx UnitTestTypeCheckExecObject.cxx UnitTestTypeCheckKeys.cxx ) -vtkm_unit_tests(SOURCES ${unit_tests} DEFINES VTKM_NO_ERROR_ON_MIXED_CUDA_CXX_TAG) +set(unit_tests_device + UnitTestTransportArrayIn.cxx + UnitTestTransportArrayInOut.cxx + UnitTestTransportArrayOut.cxx + UnitTestTransportCellSetIn.cxx + UnitTestTransportExecObject.cxx + UnitTestTransportWholeArray.cxx + ) + +vtkm_unit_tests(SOURCES ${unit_tests} DEVICE_SOURCES ${unit_tests_device}) diff --git a/vtkm/cont/arg/testing/UnitTestControlSignatureTag.cxx b/vtkm/cont/arg/testing/UnitTestControlSignatureTag.cxx index e16ea9252..79df7f546 100644 --- a/vtkm/cont/arg/testing/UnitTestControlSignatureTag.cxx +++ b/vtkm/cont/arg/testing/UnitTestControlSignatureTag.cxx @@ -8,6 +8,9 @@ // PURPOSE. See the above copyright notice for more information. //============================================================================ +// This test does not really need a device compiler +#define VTKM_NO_ERROR_ON_MIXED_CUDA_CXX_TAG + #include #include diff --git a/vtkm/cont/arg/testing/UnitTestTransportArrayIn.cxx b/vtkm/cont/arg/testing/UnitTestTransportArrayIn.cxx index 85c9221f9..4bae71e73 100644 --- a/vtkm/cont/arg/testing/UnitTestTransportArrayIn.cxx +++ b/vtkm/cont/arg/testing/UnitTestTransportArrayIn.cxx @@ -13,7 +13,8 @@ #include #include -#include +#include +#include #include @@ -68,15 +69,16 @@ struct TryArrayInType }; template -void TryArrayInTransport(Device) +bool TryArrayInTransport(Device device) { + std::cout << "Trying ArrayIn transport with " << device.GetName() << std::endl; vtkm::testing::Testing::TryTypes(TryArrayInType()); + return true; } void TestArrayInTransport() { - std::cout << "Trying ArrayIn transport with serial device." << std::endl; - TryArrayInTransport(vtkm::cont::DeviceAdapterTagSerial()); + VTKM_TEST_ASSERT(vtkm::cont::TryExecute([](auto device) { return TryArrayInTransport(device); })); } } // Anonymous namespace diff --git a/vtkm/cont/arg/testing/UnitTestTransportArrayInOut.cxx b/vtkm/cont/arg/testing/UnitTestTransportArrayInOut.cxx index 54ea151c3..7364caf96 100644 --- a/vtkm/cont/arg/testing/UnitTestTransportArrayInOut.cxx +++ b/vtkm/cont/arg/testing/UnitTestTransportArrayInOut.cxx @@ -14,6 +14,7 @@ #include #include +#include #include @@ -78,15 +79,17 @@ struct TryArrayInOutType }; template -void TryArrayInOutTransport(Device) +bool TryArrayInOutTransport(Device device) { + std::cout << "Trying ArrayInOut transport with " << device.GetName() << std::endl; vtkm::testing::Testing::TryTypes(TryArrayInOutType(), vtkm::TypeListCommon()); + return true; } void TestArrayInOutTransport() { - std::cout << "Trying ArrayInOut transport with serial device." << std::endl; - TryArrayInOutTransport(vtkm::cont::DeviceAdapterTagSerial()); + VTKM_TEST_ASSERT( + vtkm::cont::TryExecute([](auto device) { return TryArrayInOutTransport(device); })); } } // anonymous namespace diff --git a/vtkm/cont/arg/testing/UnitTestTransportArrayOut.cxx b/vtkm/cont/arg/testing/UnitTestTransportArrayOut.cxx index 287deafb4..136b78a11 100644 --- a/vtkm/cont/arg/testing/UnitTestTransportArrayOut.cxx +++ b/vtkm/cont/arg/testing/UnitTestTransportArrayOut.cxx @@ -14,7 +14,8 @@ #include #include -#include +#include +#include #include @@ -67,15 +68,17 @@ struct TryArrayOutType }; template -void TryArrayOutTransport(Device) +bool TryArrayOutTransport(Device device) { + std::cout << "Trying ArrayOut transport with " << device.GetName() << std::endl; vtkm::testing::Testing::TryTypes(TryArrayOutType()); + return true; } void TestArrayOutTransport() { - std::cout << "Trying ArrayOut transport with serial device." << std::endl; - TryArrayOutTransport(vtkm::cont::DeviceAdapterTagSerial()); + VTKM_TEST_ASSERT( + vtkm::cont::TryExecute([](auto device) { return TryArrayOutTransport(device); })); } } // Anonymous namespace diff --git a/vtkm/cont/arg/testing/UnitTestTransportCellSetIn.cxx b/vtkm/cont/arg/testing/UnitTestTransportCellSetIn.cxx index 25e04e212..ed4012c7f 100644 --- a/vtkm/cont/arg/testing/UnitTestTransportCellSetIn.cxx +++ b/vtkm/cont/arg/testing/UnitTestTransportCellSetIn.cxx @@ -11,11 +11,11 @@ #include #include +#include +#include #include -#include - #include #include @@ -49,8 +49,10 @@ struct TestKernel : public vtkm::exec::FunctorBase }; template -void TransportWholeCellSetIn(Device) +bool TransportWholeCellSetIn(Device device) { + std::cout << "Trying CellSetIn transport with " << device.GetName() << std::endl; + //build a fake cell set const int nVerts = 5; vtkm::cont::CellSetExplicit<> contObject; @@ -78,12 +80,14 @@ void TransportWholeCellSetIn(Device) kernel.CellSet = transport(contObject, nullptr, 1, 1, token); vtkm::cont::DeviceAdapterAlgorithm::Schedule(kernel, 1); + + return true; } void UnitTestCellSetIn() { - std::cout << "Trying CellSetIn transport with serial device." << std::endl; - TransportWholeCellSetIn(vtkm::cont::DeviceAdapterTagSerial()); + VTKM_TEST_ASSERT( + vtkm::cont::TryExecute([](auto device) { return TransportWholeCellSetIn(device); })); } } // Anonymous namespace diff --git a/vtkm/cont/arg/testing/UnitTestTransportExecObject.cxx b/vtkm/cont/arg/testing/UnitTestTransportExecObject.cxx index 14954eb88..620e66caf 100644 --- a/vtkm/cont/arg/testing/UnitTestTransportExecObject.cxx +++ b/vtkm/cont/arg/testing/UnitTestTransportExecObject.cxx @@ -12,15 +12,15 @@ #include -#include - +#include #include +#include #include #define EXPECTED_NUMBER 42 -namespace +namespace unittesttransportexecobject { struct NotAnExecutionObject @@ -65,8 +65,10 @@ struct TestKernel : public vtkm::exec::FunctorBase }; template -void TryExecObjectTransport(Device) +bool TryExecObjectTransport(Device device) { + std::cout << "Trying ExecObject transport with " << device.GetName() << std::endl; + TestExecutionObject contObject; contObject.Number = EXPECTED_NUMBER; @@ -79,6 +81,8 @@ void TryExecObjectTransport(Device) kernel.Object = transport(contObject, nullptr, 1, 1, token); vtkm::cont::DeviceAdapterAlgorithm::Schedule(kernel, 1); + + return true; } void TestExecObjectTransport() @@ -98,13 +102,14 @@ void TestExecObjectTransport() VTKM_TEST_ASSERT(vtkm::cont::internal::HasPrepareForExecution::value, "Bad query"); - std::cout << "Trying ExecObject transport with serial device." << std::endl; - TryExecObjectTransport(vtkm::cont::DeviceAdapterTagSerial()); + VTKM_TEST_ASSERT( + vtkm::cont::TryExecute([](auto device) { return TryExecObjectTransport(device); })); } -} // Anonymous namespace +} // namespace unittesttransportexecobject int UnitTestTransportExecObject(int argc, char* argv[]) { - return vtkm::cont::testing::Testing::Run(TestExecObjectTransport, argc, argv); + return vtkm::cont::testing::Testing::Run( + unittesttransportexecobject::TestExecObjectTransport, argc, argv); } diff --git a/vtkm/cont/arg/testing/UnitTestTypeCheckArray.cxx b/vtkm/cont/arg/testing/UnitTestTypeCheckArray.cxx index ade6eccf3..7e614eead 100644 --- a/vtkm/cont/arg/testing/UnitTestTypeCheckArray.cxx +++ b/vtkm/cont/arg/testing/UnitTestTypeCheckArray.cxx @@ -8,6 +8,9 @@ // PURPOSE. See the above copyright notice for more information. //============================================================================ +// This test does not really need a device compiler +#define VTKM_NO_ERROR_ON_MIXED_CUDA_CXX_TAG + #include #include #include diff --git a/vtkm/cont/arg/testing/UnitTestTypeCheckCellSet.cxx b/vtkm/cont/arg/testing/UnitTestTypeCheckCellSet.cxx index e35726305..1f87ab6f4 100644 --- a/vtkm/cont/arg/testing/UnitTestTypeCheckCellSet.cxx +++ b/vtkm/cont/arg/testing/UnitTestTypeCheckCellSet.cxx @@ -8,6 +8,9 @@ // PURPOSE. See the above copyright notice for more information. //============================================================================ +// This test does not really need a device compiler +#define VTKM_NO_ERROR_ON_MIXED_CUDA_CXX_TAG + #include #include diff --git a/vtkm/cont/arg/testing/UnitTestTypeCheckExecObject.cxx b/vtkm/cont/arg/testing/UnitTestTypeCheckExecObject.cxx index bc64c8bf7..504e139d4 100644 --- a/vtkm/cont/arg/testing/UnitTestTypeCheckExecObject.cxx +++ b/vtkm/cont/arg/testing/UnitTestTypeCheckExecObject.cxx @@ -8,6 +8,9 @@ // PURPOSE. See the above copyright notice for more information. //============================================================================ +// This test does not really need a device compiler +#define VTKM_NO_ERROR_ON_MIXED_CUDA_CXX_TAG + #include #include diff --git a/vtkm/cont/arg/testing/UnitTestTypeCheckKeys.cxx b/vtkm/cont/arg/testing/UnitTestTypeCheckKeys.cxx index 38cdfedca..40ab1b294 100644 --- a/vtkm/cont/arg/testing/UnitTestTypeCheckKeys.cxx +++ b/vtkm/cont/arg/testing/UnitTestTypeCheckKeys.cxx @@ -8,6 +8,9 @@ // PURPOSE. See the above copyright notice for more information. //============================================================================ +// This test does not really need a device compiler +#define VTKM_NO_ERROR_ON_MIXED_CUDA_CXX_TAG + #include #include