Consolidate UnitTestComputeRange

Previously, each device adapter implementation had their own version of
this test by including a common header. Simplify this by making a single
test in UnitTests_vtkm_cont_testing, which can now be compiled for and
tested on a device.

Also re-enabled the testing of ranges for Vecs of size 9, which is now
supported.
This commit is contained in:
Kenneth Moreland 2022-07-11 14:20:15 -06:00
parent bda676e7d9
commit f48789f57c
13 changed files with 127 additions and 272 deletions

@ -9,7 +9,6 @@
##============================================================================
set(unit_tests
UnitTestCudaComputeRange.cu
UnitTestCudaDataSetExplicit.cu
UnitTestCudaDataSetSingleType.cu
UnitTestCudaDeviceAdapter.cu

@ -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 <vtkm/cont/cuda/DeviceAdapterCuda.h>
#include <vtkm/cont/cuda/internal/testing/Testing.h>
#include <vtkm/cont/testing/TestingComputeRange.h>
int UnitTestCudaComputeRange(int argc, char* argv[])
{
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagCuda{});
int result =
vtkm::cont::testing::TestingComputeRange<vtkm::cont::DeviceAdapterTagCuda>::Run(argc, argv);
return vtkm::cont::cuda::internal::Testing::CheckCudaBeforeExit(result);
}

@ -9,7 +9,6 @@
##============================================================================
set(unit_tests
UnitTestKokkosComputeRange.cxx
UnitTestKokkosDataSetExplicit.cxx
UnitTestKokkosDataSetSingleType.cxx
UnitTestKokkosDeviceAdapter.cxx

@ -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 <vtkm/cont/kokkos/DeviceAdapterKokkos.h>
#include <vtkm/cont/testing/TestingComputeRange.h>
int UnitTestKokkosComputeRange(int argc, char* argv[])
{
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagKokkos{});
return vtkm::cont::testing::TestingComputeRange<vtkm::cont::DeviceAdapterTagKokkos>::Run(argc,
argv);
}

@ -9,7 +9,6 @@
##============================================================================
set(unit_tests
UnitTestOpenMPComputeRange.cxx
UnitTestOpenMPDataSetExplicit.cxx
UnitTestOpenMPDataSetSingleType.cxx
UnitTestOpenMPDeviceAdapter.cxx

@ -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 <vtkm/cont/openmp/DeviceAdapterOpenMP.h>
#include <vtkm/cont/testing/TestingComputeRange.h>
int UnitTestOpenMPComputeRange(int argc, char* argv[])
{
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagOpenMP{});
return vtkm::cont::testing::TestingComputeRange<vtkm::cont::DeviceAdapterTagOpenMP>::Run(argc,
argv);
}

@ -9,7 +9,6 @@
##============================================================================
set(unit_tests
UnitTestSerialComputeRange.cxx
UnitTestSerialDataSetExplicit.cxx
UnitTestSerialDataSetSingleType.cxx
UnitTestSerialDeviceAdapter.cxx

@ -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 <vtkm/cont/serial/DeviceAdapterSerial.h>
#include <vtkm/cont/testing/TestingComputeRange.h>
int UnitTestSerialComputeRange(int argc, char* argv[])
{
//TestingComputeRange forces the device
return vtkm::cont::testing::TestingComputeRange<vtkm::cont::DeviceAdapterTagSerial>::Run(argc,
argv);
}

@ -9,7 +9,6 @@
##============================================================================
set(unit_tests
UnitTestTBBComputeRange.cxx
UnitTestTBBDataSetExplicit.cxx
UnitTestTBBDataSetSingleType.cxx
UnitTestTBBDeviceAdapter.cxx

@ -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 <vtkm/cont/tbb/DeviceAdapterTBB.h>
#include <vtkm/cont/testing/TestingComputeRange.h>
int UnitTestTBBComputeRange(int argc, char* argv[])
{
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagTBB{});
return vtkm::cont::testing::TestingComputeRange<vtkm::cont::DeviceAdapterTagTBB>::Run(argc, argv);
}

@ -12,7 +12,6 @@ set(headers
ExplicitTestData.h
MakeTestDataSet.h
Testing.h
TestingComputeRange.h
TestingDeviceAdapter.h
TestingDataSetExplicit.h
TestingDataSetSingleType.h
@ -38,6 +37,7 @@ set(unit_tests
UnitTestArrayHandleUniformPointCoordinates.cxx
UnitTestArrayHandleVirtual.cxx
UnitTestArrayPortalToIterators.cxx
UnitTestComputeRange.cxx
UnitTestContTesting.cxx
UnitTestDataSetBuilderCurvilinear.cxx
UnitTestDataSetBuilderExplicit.cxx

@ -1,164 +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_TestingComputeRange_h
#define vtk_m_cont_testing_TestingComputeRange_h
#include <vtkm/Types.h>
#include <vtkm/cont/CoordinateSystem.h>
#include <vtkm/cont/Field.h>
#include <vtkm/cont/RuntimeDeviceTracker.h>
#include <vtkm/cont/testing/Testing.h>
// Required for implementation of ArrayRangeCompute for virtual arrays
#include <vtkm/cont/ArrayRangeComputeTemplate.h>
#include <algorithm>
#include <iostream>
#include <random>
namespace vtkm
{
namespace cont
{
namespace testing
{
using CustomTypeList = vtkm::List<vtkm::Vec<Int32, 3>,
vtkm::Vec<Int64, 3>,
vtkm::Vec<Float32, 3>,
vtkm::Vec<Float64, 3>,
vtkm::Vec<Int32, 9>,
vtkm::Vec<Int64, 9>,
vtkm::Vec<Float32, 9>,
vtkm::Vec<Float64, 9>>;
template <typename DeviceAdapterTag>
class TestingComputeRange
{
private:
template <typename T>
static void TestScalarField()
{
const vtkm::Id nvals = 11;
T data[nvals] = { 1, 2, 3, 4, 5, -5, -4, -3, -2, -1, 0 };
std::random_device rng;
std::mt19937 urng(rng());
std::shuffle(data, data + nvals, urng);
auto field = vtkm::cont::make_Field(
"TestField", vtkm::cont::Field::Association::Points, data, nvals, vtkm::CopyFlag::Off);
vtkm::Range result;
field.GetRange(&result);
std::cout << result << std::endl;
VTKM_TEST_ASSERT((test_equal(result.Min, -5.0) && test_equal(result.Max, 5.0)),
"Unexpected scalar field range.");
}
template <typename T, vtkm::IdComponent NumberOfComponents>
static void TestVecField()
{
const vtkm::Id nvals = 11;
T data[nvals] = { 1, 2, 3, 4, 5, -5, -4, -3, -2, -1, 0 };
vtkm::Vec<T, NumberOfComponents> fieldData[nvals];
std::random_device rng;
std::mt19937 urng(rng());
for (vtkm::IdComponent i = 0; i < NumberOfComponents; ++i)
{
std::shuffle(data, data + nvals, urng);
for (vtkm::Id j = 0; j < nvals; ++j)
{
fieldData[j][i] = data[j];
}
}
auto field = vtkm::cont::make_Field(
"TestField", vtkm::cont::Field::Association::Points, fieldData, nvals, vtkm::CopyFlag::Off);
vtkm::Range result[NumberOfComponents];
field.GetRange(result);
for (vtkm::IdComponent i = 0; i < NumberOfComponents; ++i)
{
VTKM_TEST_ASSERT((test_equal(result[i].Min, -5.0) && test_equal(result[i].Max, 5.0)),
"Unexpected vector field range.");
}
}
static void TestUniformCoordinateField()
{
vtkm::cont::CoordinateSystem field("TestField",
vtkm::Id3(10, 20, 5),
vtkm::Vec3f(0.0f, -5.0f, 4.0f),
vtkm::Vec3f(1.0f, 0.5f, 2.0f));
vtkm::Bounds result = field.GetBounds();
VTKM_TEST_ASSERT(test_equal(result.X.Min, 0.0), "Min x wrong.");
VTKM_TEST_ASSERT(test_equal(result.X.Max, 9.0), "Max x wrong.");
VTKM_TEST_ASSERT(test_equal(result.Y.Min, -5.0), "Min y wrong.");
VTKM_TEST_ASSERT(test_equal(result.Y.Max, 4.5), "Max y wrong.");
VTKM_TEST_ASSERT(test_equal(result.Z.Min, 4.0), "Min z wrong.");
VTKM_TEST_ASSERT(test_equal(result.Z.Max, 12.0), "Max z wrong.");
}
struct TestAll
{
VTKM_CONT void operator()() const
{
std::cout << "Testing (Int32, 1)..." << std::endl;
TestingComputeRange::TestScalarField<vtkm::Int32>();
std::cout << "Testing (Int64, 1)..." << std::endl;
TestingComputeRange::TestScalarField<vtkm::Int64>();
std::cout << "Testing (Float32, 1)..." << std::endl;
TestingComputeRange::TestScalarField<vtkm::Float32>();
std::cout << "Testing (Float64, 1)..." << std::endl;
TestingComputeRange::TestScalarField<vtkm::Float64>();
std::cout << "Testing (Int32, 3)..." << std::endl;
TestingComputeRange::TestVecField<vtkm::Int32, 3>();
std::cout << "Testing (Int64, 3)..." << std::endl;
TestingComputeRange::TestVecField<vtkm::Int64, 3>();
std::cout << "Testing (Float32, 3)..." << std::endl;
TestingComputeRange::TestVecField<vtkm::Float32, 3>();
std::cout << "Testing (Float64, 3)..." << std::endl;
TestingComputeRange::TestVecField<vtkm::Float64, 3>();
// TODO: These tests are temporarily disabled because the existing version of
// Field::GetRange does not compute the ranges for vectors of size 9. However,
// issue #575 would fix this issue. This test should be renabled when that is
// implemented.
#if 0
std::cout << "Testing (Int32, 9)..." << std::endl;
TestingComputeRange::TestVecField<vtkm::Int32, 9>();
std::cout << "Testing (Int64, 9)..." << std::endl;
TestingComputeRange::TestVecField<vtkm::Int64, 9>();
std::cout << "Testing (Float32, 9)..." << std::endl;
TestingComputeRange::TestVecField<vtkm::Float32, 9>();
std::cout << "Testing (Float64, 9)..." << std::endl;
TestingComputeRange::TestVecField<vtkm::Float64, 9>();
#endif
std::cout << "Testing UniformPointCoords..." << std::endl;
TestingComputeRange::TestUniformCoordinateField();
}
};
public:
static VTKM_CONT int Run(int argc, char* argv[])
{
vtkm::cont::GetRuntimeDeviceTracker().ForceDevice(DeviceAdapterTag());
return vtkm::cont::testing::Testing::Run(TestAll(), argc, argv);
}
};
}
}
} // namespace vtkm::cont::testing
#endif //vtk_m_cont_testing_TestingComputeRange_h

@ -0,0 +1,126 @@
//============================================================================
// 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 <vtkm/Types.h>
#include <vtkm/cont/CoordinateSystem.h>
#include <vtkm/cont/Field.h>
#include <vtkm/cont/testing/Testing.h>
#include <algorithm>
#include <iostream>
#include <random>
namespace
{
template <typename T>
void TestScalarField()
{
const vtkm::Id nvals = 11;
T data[nvals] = { 1, 2, 3, 4, 5, -5, -4, -3, -2, -1, 0 };
std::random_device rng;
std::mt19937 urng(rng());
std::shuffle(data, data + nvals, urng);
auto field = vtkm::cont::make_Field(
"TestField", vtkm::cont::Field::Association::Points, data, nvals, vtkm::CopyFlag::Off);
vtkm::Range result;
field.GetRange(&result);
std::cout << result << std::endl;
VTKM_TEST_ASSERT((test_equal(result.Min, -5.0) && test_equal(result.Max, 5.0)),
"Unexpected scalar field range.");
}
template <typename T, vtkm::IdComponent NumberOfComponents>
void TestVecField()
{
const vtkm::Id nvals = 11;
T data[nvals] = { 1, 2, 3, 4, 5, -5, -4, -3, -2, -1, 0 };
vtkm::Vec<T, NumberOfComponents> fieldData[nvals];
std::random_device rng;
std::mt19937 urng(rng());
for (vtkm::IdComponent i = 0; i < NumberOfComponents; ++i)
{
std::shuffle(data, data + nvals, urng);
for (vtkm::Id j = 0; j < nvals; ++j)
{
fieldData[j][i] = data[j];
}
}
auto field = vtkm::cont::make_Field(
"TestField", vtkm::cont::Field::Association::Points, fieldData, nvals, vtkm::CopyFlag::Off);
vtkm::Range result[NumberOfComponents];
field.GetRange(result);
for (vtkm::IdComponent i = 0; i < NumberOfComponents; ++i)
{
VTKM_TEST_ASSERT((test_equal(result[i].Min, -5.0) && test_equal(result[i].Max, 5.0)),
"Unexpected vector field range.");
}
}
void TestUniformCoordinateField()
{
vtkm::cont::CoordinateSystem field("TestField",
vtkm::Id3(10, 20, 5),
vtkm::Vec3f(0.0f, -5.0f, 4.0f),
vtkm::Vec3f(1.0f, 0.5f, 2.0f));
vtkm::Bounds result = field.GetBounds();
VTKM_TEST_ASSERT(test_equal(result.X.Min, 0.0), "Min x wrong.");
VTKM_TEST_ASSERT(test_equal(result.X.Max, 9.0), "Max x wrong.");
VTKM_TEST_ASSERT(test_equal(result.Y.Min, -5.0), "Min y wrong.");
VTKM_TEST_ASSERT(test_equal(result.Y.Max, 4.5), "Max y wrong.");
VTKM_TEST_ASSERT(test_equal(result.Z.Min, 4.0), "Min z wrong.");
VTKM_TEST_ASSERT(test_equal(result.Z.Max, 12.0), "Max z wrong.");
}
void TestAll()
{
std::cout << "Testing (Int32, 1)..." << std::endl;
TestScalarField<vtkm::Int32>();
std::cout << "Testing (Int64, 1)..." << std::endl;
TestScalarField<vtkm::Int64>();
std::cout << "Testing (Float32, 1)..." << std::endl;
TestScalarField<vtkm::Float32>();
std::cout << "Testing (Float64, 1)..." << std::endl;
TestScalarField<vtkm::Float64>();
std::cout << "Testing (Int32, 3)..." << std::endl;
TestVecField<vtkm::Int32, 3>();
std::cout << "Testing (Int64, 3)..." << std::endl;
TestVecField<vtkm::Int64, 3>();
std::cout << "Testing (Float32, 3)..." << std::endl;
TestVecField<vtkm::Float32, 3>();
std::cout << "Testing (Float64, 3)..." << std::endl;
TestVecField<vtkm::Float64, 3>();
std::cout << "Testing (Int32, 9)..." << std::endl;
TestVecField<vtkm::Int32, 9>();
std::cout << "Testing (Int64, 9)..." << std::endl;
TestVecField<vtkm::Int64, 9>();
std::cout << "Testing (Float32, 9)..." << std::endl;
TestVecField<vtkm::Float32, 9>();
std::cout << "Testing (Float64, 9)..." << std::endl;
TestVecField<vtkm::Float64, 9>();
std::cout << "Testing UniformPointCoords..." << std::endl;
TestUniformCoordinateField();
}
} // anonymous namespace
int UnitTestComputeRange(int argc, char* argv[])
{
return vtkm::cont::testing::Testing::Run(TestAll, argc, argv);
}