From b2b075f0474154dd5c4824324f20369dd8132d4a Mon Sep 17 00:00:00 2001 From: Kenneth Moreland Date: Mon, 11 Jul 2022 14:44:51 -0600 Subject: [PATCH] Consolidate UnitTestDataSet* Previously, each device adapter implementation had their own version of these tests by including a common header. Simplify this by making a single test in UnitTests_vtkm_cont_testing for each, which can now be compiled for and tested on a device. --- vtkm/cont/cuda/testing/CMakeLists.txt | 2 - .../testing/UnitTestCudaDataSetExplicit.cu | 22 --- .../testing/UnitTestCudaDataSetSingleType.cu | 23 --- vtkm/cont/kokkos/testing/CMakeLists.txt | 2 - .../testing/UnitTestKokkosDataSetExplicit.cxx | 20 --- .../UnitTestKokkosDataSetSingleType.cxx | 20 --- vtkm/cont/openmp/testing/CMakeLists.txt | 2 - .../testing/UnitTestOpenMPDataSetExplicit.cxx | 19 -- .../UnitTestOpenMPDataSetSingleType.cxx | 19 -- vtkm/cont/serial/testing/CMakeLists.txt | 2 - .../testing/UnitTestSerialDataSetExplicit.cxx | 20 --- .../UnitTestSerialDataSetSingleType.cxx | 20 --- vtkm/cont/tbb/testing/CMakeLists.txt | 2 - .../testing/UnitTestTBBDataSetExplicit.cxx | 21 --- .../testing/UnitTestTBBDataSetSingleType.cxx | 21 --- vtkm/cont/testing/CMakeLists.txt | 4 +- vtkm/cont/testing/TestingDataSetExplicit.h | 165 ------------------ vtkm/cont/testing/TestingDataSetSingleType.h | 153 ---------------- vtkm/cont/testing/UnitTestDataSetExplicit.cxx | 144 +++++++++++++++ .../testing/UnitTestDataSetSingleType.cxx | 160 +++++++++++++++++ 20 files changed, 306 insertions(+), 535 deletions(-) delete mode 100644 vtkm/cont/cuda/testing/UnitTestCudaDataSetExplicit.cu delete mode 100644 vtkm/cont/cuda/testing/UnitTestCudaDataSetSingleType.cu delete mode 100644 vtkm/cont/kokkos/testing/UnitTestKokkosDataSetExplicit.cxx delete mode 100644 vtkm/cont/kokkos/testing/UnitTestKokkosDataSetSingleType.cxx delete mode 100644 vtkm/cont/openmp/testing/UnitTestOpenMPDataSetExplicit.cxx delete mode 100644 vtkm/cont/openmp/testing/UnitTestOpenMPDataSetSingleType.cxx delete mode 100644 vtkm/cont/serial/testing/UnitTestSerialDataSetExplicit.cxx delete mode 100644 vtkm/cont/serial/testing/UnitTestSerialDataSetSingleType.cxx delete mode 100644 vtkm/cont/tbb/testing/UnitTestTBBDataSetExplicit.cxx delete mode 100644 vtkm/cont/tbb/testing/UnitTestTBBDataSetSingleType.cxx delete mode 100644 vtkm/cont/testing/TestingDataSetExplicit.h delete mode 100644 vtkm/cont/testing/TestingDataSetSingleType.h create mode 100644 vtkm/cont/testing/UnitTestDataSetExplicit.cxx create mode 100644 vtkm/cont/testing/UnitTestDataSetSingleType.cxx diff --git a/vtkm/cont/cuda/testing/CMakeLists.txt b/vtkm/cont/cuda/testing/CMakeLists.txt index 099d45308..df67c6938 100644 --- a/vtkm/cont/cuda/testing/CMakeLists.txt +++ b/vtkm/cont/cuda/testing/CMakeLists.txt @@ -9,8 +9,6 @@ ##============================================================================ set(unit_tests - UnitTestCudaDataSetExplicit.cu - UnitTestCudaDataSetSingleType.cu UnitTestCudaDeviceAdapter.cu UnitTestCudaImplicitFunction.cu UnitTestCudaIterators.cu diff --git a/vtkm/cont/cuda/testing/UnitTestCudaDataSetExplicit.cu b/vtkm/cont/cuda/testing/UnitTestCudaDataSetExplicit.cu deleted file mode 100644 index 5b66bae0b..000000000 --- a/vtkm/cont/cuda/testing/UnitTestCudaDataSetExplicit.cu +++ /dev/null @@ -1,22 +0,0 @@ -//============================================================================ -// 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. -//============================================================================ - -#include -#include -#include - -int UnitTestCudaDataSetExplicit(int argc, char* argv[]) -{ - auto& tracker = vtkm::cont::GetRuntimeDeviceTracker(); - tracker.ForceDevice(vtkm::cont::DeviceAdapterTagCuda{}); - int result = - vtkm::cont::testing::TestingDataSetExplicit::Run(argc, argv); - return vtkm::cont::cuda::internal::Testing::CheckCudaBeforeExit(result); -} diff --git a/vtkm/cont/cuda/testing/UnitTestCudaDataSetSingleType.cu b/vtkm/cont/cuda/testing/UnitTestCudaDataSetSingleType.cu deleted file mode 100644 index b9bdb6d69..000000000 --- a/vtkm/cont/cuda/testing/UnitTestCudaDataSetSingleType.cu +++ /dev/null @@ -1,23 +0,0 @@ -//============================================================================ -// 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. -//============================================================================ - -#include - -#include -#include - -int UnitTestCudaDataSetSingleType(int argc, char* argv[]) -{ - auto& tracker = vtkm::cont::GetRuntimeDeviceTracker(); - tracker.ForceDevice(vtkm::cont::DeviceAdapterTagCuda{}); - int result = vtkm::cont::testing::TestingDataSetSingleType::Run( - argc, argv); - return vtkm::cont::cuda::internal::Testing::CheckCudaBeforeExit(result); -} diff --git a/vtkm/cont/kokkos/testing/CMakeLists.txt b/vtkm/cont/kokkos/testing/CMakeLists.txt index 2d535145b..5aacb1bcd 100644 --- a/vtkm/cont/kokkos/testing/CMakeLists.txt +++ b/vtkm/cont/kokkos/testing/CMakeLists.txt @@ -9,8 +9,6 @@ ##============================================================================ set(unit_tests - UnitTestKokkosDataSetExplicit.cxx - UnitTestKokkosDataSetSingleType.cxx UnitTestKokkosDeviceAdapter.cxx UnitTestKokkosImplicitFunction.cxx UnitTestKokkosPointLocatorSparseGrid.cxx diff --git a/vtkm/cont/kokkos/testing/UnitTestKokkosDataSetExplicit.cxx b/vtkm/cont/kokkos/testing/UnitTestKokkosDataSetExplicit.cxx deleted file mode 100644 index 73a07e180..000000000 --- a/vtkm/cont/kokkos/testing/UnitTestKokkosDataSetExplicit.cxx +++ /dev/null @@ -1,20 +0,0 @@ -//============================================================================ -// 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. -//============================================================================ - -#include -#include - -int UnitTestKokkosDataSetExplicit(int argc, char* argv[]) -{ - auto& tracker = vtkm::cont::GetRuntimeDeviceTracker(); - tracker.ForceDevice(vtkm::cont::DeviceAdapterTagKokkos{}); - return vtkm::cont::testing::TestingDataSetExplicit::Run(argc, - argv); -} diff --git a/vtkm/cont/kokkos/testing/UnitTestKokkosDataSetSingleType.cxx b/vtkm/cont/kokkos/testing/UnitTestKokkosDataSetSingleType.cxx deleted file mode 100644 index ed4ed41aa..000000000 --- a/vtkm/cont/kokkos/testing/UnitTestKokkosDataSetSingleType.cxx +++ /dev/null @@ -1,20 +0,0 @@ -//============================================================================ -// 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. -//============================================================================ - -#include -#include - -int UnitTestKokkosDataSetSingleType(int argc, char* argv[]) -{ - auto& tracker = vtkm::cont::GetRuntimeDeviceTracker(); - tracker.ForceDevice(vtkm::cont::DeviceAdapterTagKokkos{}); - return vtkm::cont::testing::TestingDataSetSingleType::Run( - argc, argv); -} diff --git a/vtkm/cont/openmp/testing/CMakeLists.txt b/vtkm/cont/openmp/testing/CMakeLists.txt index 850dc971d..2c6e63f63 100644 --- a/vtkm/cont/openmp/testing/CMakeLists.txt +++ b/vtkm/cont/openmp/testing/CMakeLists.txt @@ -9,8 +9,6 @@ ##============================================================================ set(unit_tests - UnitTestOpenMPDataSetExplicit.cxx - UnitTestOpenMPDataSetSingleType.cxx UnitTestOpenMPDeviceAdapter.cxx UnitTestOpenMPImplicitFunction.cxx UnitTestOpenMPPointLocatorSparseGrid.cxx diff --git a/vtkm/cont/openmp/testing/UnitTestOpenMPDataSetExplicit.cxx b/vtkm/cont/openmp/testing/UnitTestOpenMPDataSetExplicit.cxx deleted file mode 100644 index ce76f1d92..000000000 --- a/vtkm/cont/openmp/testing/UnitTestOpenMPDataSetExplicit.cxx +++ /dev/null @@ -1,19 +0,0 @@ -//============================================================================ -// 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. -//============================================================================ -#include -#include - -int UnitTestOpenMPDataSetExplicit(int argc, char* argv[]) -{ - auto& tracker = vtkm::cont::GetRuntimeDeviceTracker(); - tracker.ForceDevice(vtkm::cont::DeviceAdapterTagOpenMP{}); - return vtkm::cont::testing::TestingDataSetExplicit::Run(argc, - argv); -} diff --git a/vtkm/cont/openmp/testing/UnitTestOpenMPDataSetSingleType.cxx b/vtkm/cont/openmp/testing/UnitTestOpenMPDataSetSingleType.cxx deleted file mode 100644 index 569ad65f5..000000000 --- a/vtkm/cont/openmp/testing/UnitTestOpenMPDataSetSingleType.cxx +++ /dev/null @@ -1,19 +0,0 @@ -//============================================================================ -// 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. -//============================================================================ -#include -#include - -int UnitTestOpenMPDataSetSingleType(int argc, char* argv[]) -{ - auto& tracker = vtkm::cont::GetRuntimeDeviceTracker(); - tracker.ForceDevice(vtkm::cont::DeviceAdapterTagOpenMP{}); - return vtkm::cont::testing::TestingDataSetSingleType::Run( - argc, argv); -} diff --git a/vtkm/cont/serial/testing/CMakeLists.txt b/vtkm/cont/serial/testing/CMakeLists.txt index 61670c6a9..6b7c6b4b7 100644 --- a/vtkm/cont/serial/testing/CMakeLists.txt +++ b/vtkm/cont/serial/testing/CMakeLists.txt @@ -9,8 +9,6 @@ ##============================================================================ set(unit_tests - UnitTestSerialDataSetExplicit.cxx - UnitTestSerialDataSetSingleType.cxx UnitTestSerialDeviceAdapter.cxx UnitTestSerialImplicitFunction.cxx UnitTestSerialPointLocatorSparseGrid.cxx diff --git a/vtkm/cont/serial/testing/UnitTestSerialDataSetExplicit.cxx b/vtkm/cont/serial/testing/UnitTestSerialDataSetExplicit.cxx deleted file mode 100644 index 687427194..000000000 --- a/vtkm/cont/serial/testing/UnitTestSerialDataSetExplicit.cxx +++ /dev/null @@ -1,20 +0,0 @@ -//============================================================================ -// 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. -//============================================================================ - -#include -#include - -int UnitTestSerialDataSetExplicit(int argc, char* argv[]) -{ - auto& tracker = vtkm::cont::GetRuntimeDeviceTracker(); - tracker.ForceDevice(vtkm::cont::DeviceAdapterTagSerial{}); - return vtkm::cont::testing::TestingDataSetExplicit::Run(argc, - argv); -} diff --git a/vtkm/cont/serial/testing/UnitTestSerialDataSetSingleType.cxx b/vtkm/cont/serial/testing/UnitTestSerialDataSetSingleType.cxx deleted file mode 100644 index adc645e8e..000000000 --- a/vtkm/cont/serial/testing/UnitTestSerialDataSetSingleType.cxx +++ /dev/null @@ -1,20 +0,0 @@ -//============================================================================ -// 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. -//============================================================================ - -#include -#include - -int UnitTestSerialDataSetSingleType(int argc, char* argv[]) -{ - auto& tracker = vtkm::cont::GetRuntimeDeviceTracker(); - tracker.ForceDevice(vtkm::cont::DeviceAdapterTagSerial{}); - return vtkm::cont::testing::TestingDataSetSingleType::Run( - argc, argv); -} diff --git a/vtkm/cont/tbb/testing/CMakeLists.txt b/vtkm/cont/tbb/testing/CMakeLists.txt index 528a8c27e..a1a982cb6 100644 --- a/vtkm/cont/tbb/testing/CMakeLists.txt +++ b/vtkm/cont/tbb/testing/CMakeLists.txt @@ -9,8 +9,6 @@ ##============================================================================ set(unit_tests - UnitTestTBBDataSetExplicit.cxx - UnitTestTBBDataSetSingleType.cxx UnitTestTBBDeviceAdapter.cxx UnitTestTBBImplicitFunction.cxx UnitTestTBBPointLocatorSparseGrid.cxx diff --git a/vtkm/cont/tbb/testing/UnitTestTBBDataSetExplicit.cxx b/vtkm/cont/tbb/testing/UnitTestTBBDataSetExplicit.cxx deleted file mode 100644 index 58227cee6..000000000 --- a/vtkm/cont/tbb/testing/UnitTestTBBDataSetExplicit.cxx +++ /dev/null @@ -1,21 +0,0 @@ -//============================================================================ -// 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. -//============================================================================ - -#include - -#include - -int UnitTestTBBDataSetExplicit(int argc, char* argv[]) -{ - auto& tracker = vtkm::cont::GetRuntimeDeviceTracker(); - tracker.ForceDevice(vtkm::cont::DeviceAdapterTagTBB{}); - return vtkm::cont::testing::TestingDataSetExplicit::Run(argc, - argv); -} diff --git a/vtkm/cont/tbb/testing/UnitTestTBBDataSetSingleType.cxx b/vtkm/cont/tbb/testing/UnitTestTBBDataSetSingleType.cxx deleted file mode 100644 index 9df35b73c..000000000 --- a/vtkm/cont/tbb/testing/UnitTestTBBDataSetSingleType.cxx +++ /dev/null @@ -1,21 +0,0 @@ -//============================================================================ -// 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. -//============================================================================ - -#include - -#include - -int UnitTestTBBDataSetSingleType(int argc, char* argv[]) -{ - auto& tracker = vtkm::cont::GetRuntimeDeviceTracker(); - tracker.ForceDevice(vtkm::cont::DeviceAdapterTagTBB{}); - return vtkm::cont::testing::TestingDataSetSingleType::Run(argc, - argv); -} diff --git a/vtkm/cont/testing/CMakeLists.txt b/vtkm/cont/testing/CMakeLists.txt index 7791f4c10..be6a5bfae 100644 --- a/vtkm/cont/testing/CMakeLists.txt +++ b/vtkm/cont/testing/CMakeLists.txt @@ -13,8 +13,6 @@ set(headers MakeTestDataSet.h Testing.h TestingDeviceAdapter.h - TestingDataSetExplicit.h - TestingDataSetSingleType.h TestingImplicitFunction.h TestingPointLocatorSparseGrid.h TestingRuntimeDeviceConfiguration.h @@ -44,6 +42,7 @@ set(unit_tests UnitTestDataSetBuilderRectilinear.cxx UnitTestDataSetBuilderUniform.cxx UnitTestDataSetConvertToExpected.cxx + UnitTestDataSetExplicit.cxx UnitTestDataSetRectilinear.cxx UnitTestDataSetUniform.cxx UnitTestDeviceAdapterAlgorithmGeneral.cxx @@ -106,6 +105,7 @@ set(unit_tests_device UnitTestCellSetPermutation.cxx UnitTestColorTable.cxx UnitTestDataSetPermutation.cxx + UnitTestDataSetSingleType.cxx UnitTestDeviceAdapterAlgorithmDependency.cxx UnitTestParticleArrayCopy.cxx ) diff --git a/vtkm/cont/testing/TestingDataSetExplicit.h b/vtkm/cont/testing/TestingDataSetExplicit.h deleted file mode 100644 index 7525c19d8..000000000 --- a/vtkm/cont/testing/TestingDataSetExplicit.h +++ /dev/null @@ -1,165 +0,0 @@ -//============================================================================ -// 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_testing_TestingDataSetExplicit_h -#define vtk_m_cont_testing_TestingDataSetExplicit_h - -#include -#include -#include -#include - -#include - -namespace vtkm -{ -namespace cont -{ -namespace testing -{ - -/// This class has a single static member, Run, that tests DataSetExplicit -/// with the given DeviceAdapter -/// -template -class TestingDataSetExplicit -{ -private: - template - static bool TestArrayHandle(const vtkm::cont::ArrayHandle& ah, - const T* expected, - vtkm::Id size) - { - if (size != ah.GetNumberOfValues()) - { - return false; - } - - auto ahPortal = ah.ReadPortal(); - for (vtkm::Id i = 0; i < size; ++i) - { - if (ahPortal.Get(i) != expected[i]) - { - return false; - } - } - - return true; - } - - static void TestDataSet_Explicit() - { - vtkm::cont::testing::MakeTestDataSet tds; - vtkm::cont::DataSet ds = tds.Make3DExplicitDataSet0(); - - VTKM_TEST_ASSERT(ds.GetNumberOfFields() == 2, "Incorrect number of fields"); - - // test various field-getting methods and associations - const vtkm::cont::Field& f1 = ds.GetField("pointvar"); - VTKM_TEST_ASSERT(f1.GetAssociation() == vtkm::cont::Field::Association::Points, - "Association of 'pointvar' was not Association::Points"); - try - { - ds.GetCellField("cellvar"); - } - catch (...) - { - VTKM_TEST_FAIL("Failed to get field 'cellvar' with Association::Cells."); - } - - try - { - ds.GetPointField("cellvar"); - VTKM_TEST_FAIL("Failed to get expected error for association mismatch."); - } - catch (vtkm::cont::ErrorBadValue& error) - { - std::cout << "Caught expected error for association mismatch: " << std::endl - << " " << error.GetMessage() << std::endl; - } - - VTKM_TEST_ASSERT(ds.GetNumberOfCoordinateSystems() == 1, - "Incorrect number of coordinate systems"); - - // test cell-to-point connectivity - vtkm::cont::CellSetExplicit<> cellset; - ds.GetCellSet().AsCellSet(cellset); - - vtkm::Id connectivitySize = 7; - vtkm::Id numPoints = 5; - - vtkm::UInt8 correctShapes[] = { 1, 1, 1, 1, 1 }; - vtkm::IdComponent correctNumIndices[] = { 1, 2, 2, 1, 1 }; - vtkm::Id correctConnectivity[] = { 0, 0, 1, 0, 1, 1, 1 }; - - vtkm::cont::ArrayHandleConstant shapes = - cellset.GetShapesArray(vtkm::TopologyElementTagPoint(), vtkm::TopologyElementTagCell()); - auto numIndices = - cellset.GetNumIndicesArray(vtkm::TopologyElementTagPoint(), vtkm::TopologyElementTagCell()); - vtkm::cont::ArrayHandle conn = - cellset.GetConnectivityArray(vtkm::TopologyElementTagPoint(), vtkm::TopologyElementTagCell()); - - VTKM_TEST_ASSERT(TestArrayHandle(shapes, correctShapes, numPoints), "Got incorrect shapes"); - VTKM_TEST_ASSERT(TestArrayHandle(numIndices, correctNumIndices, numPoints), - "Got incorrect numIndices"); - - // Some device adapters have unstable sorts, which may cause the order of - // the indices for each point to be different but still correct. Iterate - // over all the points and check the connectivity for each one. - VTKM_TEST_ASSERT(conn.GetNumberOfValues() == connectivitySize, - "Connectivity array wrong size."); - vtkm::Id connectivityIndex = 0; - auto connPortal = conn.ReadPortal(); - for (vtkm::Id pointIndex = 0; pointIndex < numPoints; pointIndex++) - { - vtkm::IdComponent numIncidentCells = correctNumIndices[pointIndex]; - std::set correctIncidentCells; - for (vtkm::IdComponent cellIndex = 0; cellIndex < numIncidentCells; cellIndex++) - { - correctIncidentCells.insert(correctConnectivity[connectivityIndex + cellIndex]); - } - for (vtkm::IdComponent cellIndex = 0; cellIndex < numIncidentCells; cellIndex++) - { - vtkm::Id expectedCell = connPortal.Get(connectivityIndex + cellIndex); - std::set::iterator foundCell = correctIncidentCells.find(expectedCell); - VTKM_TEST_ASSERT(foundCell != correctIncidentCells.end(), - "An incident cell in the connectivity list is wrong or repeated."); - correctIncidentCells.erase(foundCell); - } - connectivityIndex += numIncidentCells; - } - - //verify that GetIndices works properly - vtkm::Id expectedPointIds[4] = { 2, 1, 3, 4 }; - vtkm::Id4 retrievedPointIds; - cellset.GetIndices(1, retrievedPointIds); - for (vtkm::IdComponent i = 0; i < 4; i++) - { - VTKM_TEST_ASSERT(retrievedPointIds[i] == expectedPointIds[i], - "Incorrect point ID for quad cell"); - } - } - - struct TestAll - { - VTKM_CONT void operator()() const { TestingDataSetExplicit::TestDataSet_Explicit(); } - }; - -public: - static VTKM_CONT int Run(int argc, char* argv[]) - { - return vtkm::cont::testing::Testing::Run(TestAll(), argc, argv); - } -}; -} -} -} // namespace vtkm::cont::testing - -#endif // vtk_m_cont_testing_TestingDataSetExplicit_h diff --git a/vtkm/cont/testing/TestingDataSetSingleType.h b/vtkm/cont/testing/TestingDataSetSingleType.h deleted file mode 100644 index 93658e1b3..000000000 --- a/vtkm/cont/testing/TestingDataSetSingleType.h +++ /dev/null @@ -1,153 +0,0 @@ -//============================================================================ -// 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_testing_TestingDataSetSingleType_h -#define vtk_m_cont_testing_TestingDataSetSingleType_h - -#include -#include -#include -#include -#include - -#include -#include - -namespace vtkm -{ -namespace cont -{ -namespace testing -{ - -/// This class has a single static member, Run, that tests DataSetSingleType -/// with the given DeviceAdapter -/// -template -class TestingDataSetSingleType -{ -private: - template - static bool TestArrayHandle(const vtkm::cont::ArrayHandle& ah, - const T* expected, - vtkm::Id size) - { - if (size != ah.GetNumberOfValues()) - { - return false; - } - - auto portal = ah.ReadPortal(); - for (vtkm::Id i = 0; i < size; ++i) - { - if (portal.Get(i) != expected[i]) - { - return false; - } - } - - return true; - } - - static inline vtkm::cont::DataSet make_SingleTypeDataSet() - { - using CoordType = vtkm::Vec3f_32; - std::vector coordinates; - coordinates.push_back(CoordType(0, 0, 0)); - coordinates.push_back(CoordType(1, 0, 0)); - coordinates.push_back(CoordType(1, 1, 0)); - coordinates.push_back(CoordType(2, 1, 0)); - coordinates.push_back(CoordType(2, 2, 0)); - - std::vector conn; - // First Cell - conn.push_back(0); - conn.push_back(1); - conn.push_back(2); - // Second Cell - conn.push_back(1); - conn.push_back(2); - conn.push_back(3); - // Third Cell - conn.push_back(2); - conn.push_back(3); - conn.push_back(4); - - vtkm::cont::DataSet ds; - vtkm::cont::DataSetBuilderExplicit builder; - ds = builder.Create(coordinates, vtkm::CellShapeTagTriangle(), 3, conn); - - //Set point scalar - const int nVerts = 5; - vtkm::Float32 vars[nVerts] = { 10.1f, 20.1f, 30.2f, 40.2f, 50.3f }; - - ds.AddPointField("pointvar", vars, nVerts); - - return ds; - } - - static void TestDataSet_SingleType() - { - vtkm::cont::DataSet dataSet = make_SingleTypeDataSet(); - - //verify that we can get a CellSetSingleType from a dataset - vtkm::cont::CellSetSingleType<> cellset; - dataSet.GetCellSet().AsCellSet(cellset); - - //verify that the point to cell connectivity types are correct - vtkm::cont::ArrayHandleConstant shapesPointToCell = - cellset.GetShapesArray(vtkm::TopologyElementTagCell(), vtkm::TopologyElementTagPoint()); - vtkm::cont::ArrayHandle connPointToCell = - cellset.GetConnectivityArray(vtkm::TopologyElementTagCell(), vtkm::TopologyElementTagPoint()); - - VTKM_TEST_ASSERT(shapesPointToCell.GetNumberOfValues() == 3, "Wrong number of shapes"); - VTKM_TEST_ASSERT(connPointToCell.GetNumberOfValues() == 9, "Wrong connectivity length"); - - //verify that the cell to point connectivity types are correct - //note the handle storage types differ compared to point to cell - vtkm::cont::ArrayHandleConstant shapesCellToPoint = - cellset.GetShapesArray(vtkm::TopologyElementTagPoint(), vtkm::TopologyElementTagCell()); - vtkm::cont::ArrayHandle connCellToPoint = - cellset.GetConnectivityArray(vtkm::TopologyElementTagPoint(), vtkm::TopologyElementTagCell()); - - VTKM_TEST_ASSERT(shapesCellToPoint.GetNumberOfValues() == 5, "Wrong number of shapes"); - VTKM_TEST_ASSERT(connCellToPoint.GetNumberOfValues() == 9, "Wrong connectivity length"); - - //run a basic for-each topology algorithm on this - vtkm::cont::ArrayHandle result; - vtkm::worklet::DispatcherMapTopology dispatcher; - dispatcher.SetDevice(DeviceAdapterTag()); - dispatcher.Invoke(cellset, dataSet.GetField("pointvar"), result); - - vtkm::Float32 expected[3] = { 20.1333f, 30.1667f, 40.2333f }; - auto portal = result.ReadPortal(); - for (int i = 0; i < 3; ++i) - { - VTKM_TEST_ASSERT(test_equal(portal.Get(i), expected[i]), - "Wrong result for CellAverage worklet on explicit single type cellset data"); - } - } - - struct TestAll - { - VTKM_CONT void operator()() const { TestingDataSetSingleType::TestDataSet_SingleType(); } - }; - -public: - static VTKM_CONT int Run(int argc, char* argv[]) - { - return vtkm::cont::testing::Testing::Run(TestAll(), argc, argv); - } -}; -} -} -} // namespace vtkm::cont::testing - -#endif // vtk_m_cont_testing_TestingDataSetSingleType_h diff --git a/vtkm/cont/testing/UnitTestDataSetExplicit.cxx b/vtkm/cont/testing/UnitTestDataSetExplicit.cxx new file mode 100644 index 000000000..56abcf63a --- /dev/null +++ b/vtkm/cont/testing/UnitTestDataSetExplicit.cxx @@ -0,0 +1,144 @@ +//============================================================================ +// 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. +//============================================================================ + +#include +#include +#include + +#include + +namespace +{ + +template +bool TestArrayHandle(const vtkm::cont::ArrayHandle& ah, + const T* expected, + vtkm::Id size) +{ + if (size != ah.GetNumberOfValues()) + { + return false; + } + + auto ahPortal = ah.ReadPortal(); + for (vtkm::Id i = 0; i < size; ++i) + { + if (ahPortal.Get(i) != expected[i]) + { + return false; + } + } + + return true; +} + +void TestDataSet_Explicit() +{ + vtkm::cont::testing::MakeTestDataSet tds; + vtkm::cont::DataSet ds = tds.Make3DExplicitDataSet0(); + + VTKM_TEST_ASSERT(ds.GetNumberOfFields() == 2, "Incorrect number of fields"); + + // test various field-getting methods and associations + const vtkm::cont::Field& f1 = ds.GetField("pointvar"); + VTKM_TEST_ASSERT(f1.GetAssociation() == vtkm::cont::Field::Association::Points, + "Association of 'pointvar' was not Association::Points"); + try + { + ds.GetCellField("cellvar"); + } + catch (...) + { + VTKM_TEST_FAIL("Failed to get field 'cellvar' with Association::Cells."); + } + + try + { + ds.GetPointField("cellvar"); + VTKM_TEST_FAIL("Failed to get expected error for association mismatch."); + } + catch (vtkm::cont::ErrorBadValue& error) + { + std::cout << "Caught expected error for association mismatch: " << std::endl + << " " << error.GetMessage() << std::endl; + } + + VTKM_TEST_ASSERT(ds.GetNumberOfCoordinateSystems() == 1, + "Incorrect number of coordinate systems"); + + // test cell-to-point connectivity + vtkm::cont::CellSetExplicit<> cellset; + ds.GetCellSet().AsCellSet(cellset); + + vtkm::Id connectivitySize = 7; + vtkm::Id numPoints = 5; + + vtkm::UInt8 correctShapes[] = { 1, 1, 1, 1, 1 }; + vtkm::IdComponent correctNumIndices[] = { 1, 2, 2, 1, 1 }; + vtkm::Id correctConnectivity[] = { 0, 0, 1, 0, 1, 1, 1 }; + + vtkm::cont::ArrayHandleConstant shapes = + cellset.GetShapesArray(vtkm::TopologyElementTagPoint(), vtkm::TopologyElementTagCell()); + auto numIndices = + cellset.GetNumIndicesArray(vtkm::TopologyElementTagPoint(), vtkm::TopologyElementTagCell()); + vtkm::cont::ArrayHandle conn = + cellset.GetConnectivityArray(vtkm::TopologyElementTagPoint(), vtkm::TopologyElementTagCell()); + + VTKM_TEST_ASSERT(TestArrayHandle(shapes, correctShapes, numPoints), "Got incorrect shapes"); + VTKM_TEST_ASSERT(TestArrayHandle(numIndices, correctNumIndices, numPoints), + "Got incorrect numIndices"); + + // Some device adapters have unstable sorts, which may cause the order of + // the indices for each point to be different but still correct. Iterate + // over all the points and check the connectivity for each one. + VTKM_TEST_ASSERT(conn.GetNumberOfValues() == connectivitySize, "Connectivity array wrong size."); + vtkm::Id connectivityIndex = 0; + auto connPortal = conn.ReadPortal(); + for (vtkm::Id pointIndex = 0; pointIndex < numPoints; pointIndex++) + { + vtkm::IdComponent numIncidentCells = correctNumIndices[pointIndex]; + std::set correctIncidentCells; + for (vtkm::IdComponent cellIndex = 0; cellIndex < numIncidentCells; cellIndex++) + { + correctIncidentCells.insert(correctConnectivity[connectivityIndex + cellIndex]); + } + for (vtkm::IdComponent cellIndex = 0; cellIndex < numIncidentCells; cellIndex++) + { + vtkm::Id expectedCell = connPortal.Get(connectivityIndex + cellIndex); + std::set::iterator foundCell = correctIncidentCells.find(expectedCell); + VTKM_TEST_ASSERT(foundCell != correctIncidentCells.end(), + "An incident cell in the connectivity list is wrong or repeated."); + correctIncidentCells.erase(foundCell); + } + connectivityIndex += numIncidentCells; + } + + //verify that GetIndices works properly + vtkm::Id expectedPointIds[4] = { 2, 1, 3, 4 }; + vtkm::Id4 retrievedPointIds; + cellset.GetIndices(1, retrievedPointIds); + for (vtkm::IdComponent i = 0; i < 4; i++) + { + VTKM_TEST_ASSERT(retrievedPointIds[i] == expectedPointIds[i], + "Incorrect point ID for quad cell"); + } +} + +void TestAll() +{ + TestDataSet_Explicit(); +}; + +} // anonymous namespace + +int UnitTestDataSetExplicit(int argc, char* argv[]) +{ + return vtkm::cont::testing::Testing::Run(TestAll, argc, argv); +} diff --git a/vtkm/cont/testing/UnitTestDataSetSingleType.cxx b/vtkm/cont/testing/UnitTestDataSetSingleType.cxx new file mode 100644 index 000000000..b44dce4ab --- /dev/null +++ b/vtkm/cont/testing/UnitTestDataSetSingleType.cxx @@ -0,0 +1,160 @@ +//============================================================================ +// 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. +//============================================================================ + +#include +#include +#include +#include +#include +#include + +#include +#include + +namespace +{ + +//simple functor that returns the average point value as a cell field +class CellAverage : public vtkm::worklet::WorkletVisitCellsWithPoints +{ +public: + using ControlSignature = void(CellSetIn cellset, FieldInPoint inPoints, FieldOutCell outCells); + using ExecutionSignature = void(PointCount, _2, _3); + using InputDomain = _1; + + template + VTKM_EXEC void operator()(const vtkm::IdComponent& numPoints, + const PointValueVecType& pointValues, + OutType& average) const + { + average = OutType(pointValues[0]); + for (vtkm::IdComponent pointIndex = 1; pointIndex < numPoints; ++pointIndex) + { + average = average + pointValues[pointIndex]; + } + + average = static_cast(average * (1.0 / numPoints)); + } +}; + +template +bool TestArrayHandle(const vtkm::cont::ArrayHandle& ah, + const T* expected, + vtkm::Id size) +{ + if (size != ah.GetNumberOfValues()) + { + return false; + } + + auto portal = ah.ReadPortal(); + for (vtkm::Id i = 0; i < size; ++i) + { + if (portal.Get(i) != expected[i]) + { + return false; + } + } + + return true; +} + +inline vtkm::cont::DataSet make_SingleTypeDataSet() +{ + using CoordType = vtkm::Vec3f_32; + std::vector coordinates; + coordinates.push_back(CoordType(0, 0, 0)); + coordinates.push_back(CoordType(1, 0, 0)); + coordinates.push_back(CoordType(1, 1, 0)); + coordinates.push_back(CoordType(2, 1, 0)); + coordinates.push_back(CoordType(2, 2, 0)); + + std::vector conn; + // First Cell + conn.push_back(0); + conn.push_back(1); + conn.push_back(2); + // Second Cell + conn.push_back(1); + conn.push_back(2); + conn.push_back(3); + // Third Cell + conn.push_back(2); + conn.push_back(3); + conn.push_back(4); + + vtkm::cont::DataSet ds; + vtkm::cont::DataSetBuilderExplicit builder; + ds = builder.Create(coordinates, vtkm::CellShapeTagTriangle(), 3, conn); + + //Set point scalar + const int nVerts = 5; + vtkm::Float32 vars[nVerts] = { 10.1f, 20.1f, 30.2f, 40.2f, 50.3f }; + + ds.AddPointField("pointvar", vars, nVerts); + + return ds; +} + +void TestDataSet_SingleType() +{ + vtkm::cont::Invoker invoke; + + vtkm::cont::DataSet dataSet = make_SingleTypeDataSet(); + + //verify that we can get a CellSetSingleType from a dataset + vtkm::cont::CellSetSingleType<> cellset; + dataSet.GetCellSet().AsCellSet(cellset); + + //verify that the point to cell connectivity types are correct + vtkm::cont::ArrayHandleConstant shapesPointToCell = + cellset.GetShapesArray(vtkm::TopologyElementTagCell(), vtkm::TopologyElementTagPoint()); + vtkm::cont::ArrayHandle connPointToCell = + cellset.GetConnectivityArray(vtkm::TopologyElementTagCell(), vtkm::TopologyElementTagPoint()); + + VTKM_TEST_ASSERT(shapesPointToCell.GetNumberOfValues() == 3, "Wrong number of shapes"); + VTKM_TEST_ASSERT(connPointToCell.GetNumberOfValues() == 9, "Wrong connectivity length"); + + //verify that the cell to point connectivity types are correct + //note the handle storage types differ compared to point to cell + vtkm::cont::ArrayHandleConstant shapesCellToPoint = + cellset.GetShapesArray(vtkm::TopologyElementTagPoint(), vtkm::TopologyElementTagCell()); + vtkm::cont::ArrayHandle connCellToPoint = + cellset.GetConnectivityArray(vtkm::TopologyElementTagPoint(), vtkm::TopologyElementTagCell()); + + VTKM_TEST_ASSERT(shapesCellToPoint.GetNumberOfValues() == 5, "Wrong number of shapes"); + VTKM_TEST_ASSERT(connCellToPoint.GetNumberOfValues() == 9, "Wrong connectivity length"); + + //run a basic for-each topology algorithm on this + vtkm::cont::ArrayHandle input; + vtkm::cont::ArrayCopyShallowIfPossible(dataSet.GetField("pointvar").GetData(), input); + vtkm::cont::ArrayHandle result; + invoke(CellAverage{}, cellset, input, result); + + vtkm::Float32 expected[3] = { 20.1333f, 30.1667f, 40.2333f }; + auto portal = result.ReadPortal(); + for (int i = 0; i < 3; ++i) + { + VTKM_TEST_ASSERT(test_equal(portal.Get(i), expected[i]), + "Wrong result for CellAverage worklet on explicit single type cellset data"); + } +} + +VTKM_CONT void Run() +{ + TestDataSet_SingleType(); +} + +} // anonymous namespace + +int UnitTestDataSetSingleType(int argc, char* argv[]) +{ + return vtkm::cont::testing::Testing::Run(Run, argc, argv); +}