Merge topic 'speed_up_tests'

021c3ff86 Print additional information on failure to facilitate debugging.
36b8c0d2a Merge branch 'speed_up_tests' of gitlab.kitware.com:NAThompson/vtk-m into speed_up_tests
9d6b73275 Use better variable names.
4133e40c0 Remove printing of expected errors.
eb760e04e Revert removal of print statements.
e7c075b5c Remove unused variable.
cb83b8179 Save another 10 seconds.
b0c2bc9d6 Ignore computationTime.
...

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !2465
This commit is contained in:
Nick Thompson 2021-04-13 14:07:43 +00:00 committed by Kitware Robot
commit 76877b7982
16 changed files with 96 additions and 327 deletions

@ -326,7 +326,7 @@ inline vtkm::cont::DataSet MakeTestDataSet::Make3DUniformDataSet1()
inline vtkm::cont::DataSet MakeTestDataSet::Make3DUniformDataSet2()
{
constexpr vtkm::Id base_size = 256;
constexpr vtkm::Id base_size = 64;
vtkm::cont::DataSetBuilderUniform dsb;
vtkm::Id3 dimensions(base_size, base_size, base_size);
vtkm::cont::DataSet dataSet = dsb.Create(dimensions);

@ -55,9 +55,9 @@ namespace testing
{
#define ERROR_MESSAGE "Got an error."
#define ARRAY_SIZE 10000
#define OFFSET 1000
#define DIM_SIZE 128
#define ARRAY_SIZE 100
#define OFFSET 10
#define DIM_SIZE 8
/// This class has a single static member, Run, that tests the templated
/// DeviceAdapter for conformance.
@ -498,37 +498,37 @@ private:
vtkm::cont::internal::DeviceAdapterMemoryManager<DeviceAdapterTag> memoryManager;
std::cout << "Allocate a buffer." << std::endl;
// Allocate a buffer.
vtkm::cont::internal::BufferInfo allocatedMemory = memoryManager.Allocate(BUFFER_SIZE);
VTKM_TEST_ASSERT(allocatedMemory.GetSize() == BUFFER_SIZE);
std::cout << "Copy data from host to device." << std::endl;
// Copy data from host to device.
allocatedMemory = memoryManager.CopyHostToDevice(hostBufferSrc);
std::cout << "Copy data within device." << std::endl;
// Copy data within device.
vtkm::cont::internal::BufferInfo workingMemory =
memoryManager.CopyDeviceToDevice(allocatedMemory);
VTKM_TEST_ASSERT(workingMemory.GetSize() == BUFFER_SIZE);
std::cout << "Copy data back to host." << std::endl;
// Copy data back to host.
vtkm::cont::internal::BufferInfo hostBufferDest = memoryManager.CopyDeviceToHost(workingMemory);
VTKM_TEST_ASSERT(hostBufferDest.GetSize() == BUFFER_SIZE);
CheckPortal(makePortal(hostBufferDest));
std::cout << "Shrink a buffer (and preserve memory)" << std::endl;
// Shrink a buffer (and preserve memory)
memoryManager.Reallocate(workingMemory, BUFFER_SIZE / 2);
hostBufferDest = memoryManager.CopyDeviceToHost(workingMemory);
VTKM_TEST_ASSERT(hostBufferDest.GetSize() == BUFFER_SIZE / 2);
CheckPortal(makePortal(hostBufferDest));
std::cout << "Grow a buffer (and preserve memory)" << std::endl;
// Grow a buffer (and preserve memory)
memoryManager.Reallocate(workingMemory, BUFFER_SIZE * 2);
hostBufferDest = memoryManager.CopyDeviceToHost(workingMemory);
VTKM_TEST_ASSERT(hostBufferDest.GetSize() == BUFFER_SIZE * 2);
hostBufferDest.Reallocate(BUFFER_SIZE / 2);
CheckPortal(makePortal(hostBufferDest));
std::cout << "Make sure data is actually available on the device." << std::endl;
// Make sure data is actually available on the device.
// This actually requires running schedule.
workingMemory = memoryManager.CopyDeviceToDevice(allocatedMemory);
Algorithm::Schedule(MakeAddArrayKernel(makePortal(workingMemory)), ARRAY_SIZE);
@ -553,6 +553,7 @@ private:
#ifdef VTKM_USE_64BIT_IDS
std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing Out of Memory" << std::endl;
bool caughtBadAlloc = false;
try
{
std::cout << "Do array allocation that should fail." << std::endl;
@ -566,12 +567,11 @@ private:
"or the width of vtkm::Id is not large enough to express all "
"array sizes.");
}
catch (vtkm::cont::ErrorBadAllocation& error)
catch (vtkm::cont::ErrorBadAllocation&)
{
std::cout << "Got the expected error: " << error.GetMessage() << std::endl;
caughtBadAlloc = true;
}
#else
std::cout << "--------- Skipping out of memory test" << std::endl;
VTKM_TEST_ASSERT(caughtBadAlloc);
#endif
}
@ -646,24 +646,21 @@ private:
std::cout << "Testing single value Scheduling with vtkm::Id" << std::endl;
{
std::cout << "Allocating execution array" << std::endl;
// Allocating execution array
vtkm::cont::ArrayHandle<vtkm::Id> handle;
std::cout << "Running clear." << std::endl;
{
vtkm::cont::Token token;
Algorithm::Schedule(ClearArrayKernel(handle.PrepareForOutput(1, DeviceAdapterTag{}, token)),
1);
}
std::cout << "Running add." << std::endl;
{
vtkm::cont::Token token;
Algorithm::Schedule(MakeAddArrayKernel(handle.PrepareForInPlace(DeviceAdapterTag{}, token)),
1);
}
std::cout << "Checking results." << std::endl;
auto portal = handle.ReadPortal();
for (vtkm::Id index = 0; index < 1; index++)
{
@ -677,10 +674,8 @@ private:
std::cout << "Testing Schedule with vtkm::Id" << std::endl;
{
std::cout << "Allocating execution array" << std::endl;
vtkm::cont::ArrayHandle<vtkm::Id> handle;
std::cout << "Running clear." << std::endl;
{
vtkm::cont::Token token;
Algorithm::Schedule(
@ -688,14 +683,12 @@ private:
ARRAY_SIZE);
}
std::cout << "Running add." << std::endl;
{
vtkm::cont::Token token;
Algorithm::Schedule(MakeAddArrayKernel(handle.PrepareForInPlace(DeviceAdapterTag{}, token)),
ARRAY_SIZE);
}
std::cout << "Checking results." << std::endl;
auto portal = handle.ReadPortal();
for (vtkm::Id index = 0; index < ARRAY_SIZE; index++)
{
@ -708,11 +701,9 @@ private:
std::cout << "Testing Schedule with a vary large Id value" << std::endl;
{
std::cout << "Allocating execution array" << std::endl;
// Allocating execution array.
vtkm::cont::ArrayHandle<vtkm::Id> handle;
std::cout << "Running clear." << std::endl;
//size is selected to be larger than the CUDA backend can launch in a
//single invocation when compiled for SM_2 support
const vtkm::Id size = 8400000;
@ -722,14 +713,12 @@ private:
ClearArrayKernel(handle.PrepareForOutput(size, DeviceAdapterTag{}, token)), size);
}
std::cout << "Running add." << std::endl;
{
vtkm::cont::Token token;
Algorithm::Schedule(MakeAddArrayKernel(handle.PrepareForInPlace(DeviceAdapterTag{}, token)),
size);
}
std::cout << "Checking results." << std::endl;
//Rather than testing for correctness every value of a large array,
// we randomly test a subset of that array.
std::default_random_engine generator(static_cast<unsigned int>(std::time(nullptr)));
@ -753,7 +742,6 @@ private:
vtkm::cont::ArrayHandle<vtkm::Id> handle;
vtkm::Id3 maxRange(DIM_SIZE);
std::cout << "Running clear." << std::endl;
{
vtkm::cont::Token token;
Algorithm::Schedule(
@ -763,7 +751,6 @@ private:
maxRange);
}
std::cout << "Running add." << std::endl;
{
vtkm::cont::Token token;
Algorithm::Schedule(
@ -771,7 +758,6 @@ private:
maxRange);
}
std::cout << "Checking results." << std::endl;
const vtkm::Id maxId = DIM_SIZE * DIM_SIZE * DIM_SIZE;
auto portal = handle.ReadPortal();
for (vtkm::Id index = 0; index < maxId; index++)
@ -812,8 +798,6 @@ private:
ARRAY_SIZE);
}
std::cout << "Checking results." << std::endl;
auto vPortal = valid.ReadPortal();
for (vtkm::Id i = 0; i < ARRAY_SIZE; i++)
{
@ -858,8 +842,6 @@ private:
dims);
}
std::cout << "Checking results." << std::endl;
auto vPortal = valid.ReadPortal();
for (vtkm::Id i = 0; i < numElems; i++)
{
@ -878,7 +860,6 @@ private:
IdArrayHandle stencil;
IdArrayHandle result;
std::cout << " Standard call" << std::endl;
//construct the index array
{
vtkm::cont::Token token;
@ -2057,7 +2038,6 @@ private:
std::cout << "Testing Exclusive Scan" << std::endl;
{
std::cout << " size " << ARRAY_SIZE << std::endl;
//construct the index array
IdArrayHandle array;
{
@ -2070,7 +2050,6 @@ private:
// we know have an array whose sum = (OFFSET * ARRAY_SIZE),
// let's validate that
vtkm::Id sum = Algorithm::ScanExclusive(array, array);
std::cout << " Sum that was returned " << sum << std::endl;
VTKM_TEST_ASSERT(sum == (OFFSET * ARRAY_SIZE), "Got bad sum from Exclusive Scan");
auto portal = array.ReadPortal();
@ -2088,7 +2067,6 @@ private:
const vtkm::Id value = array.ReadPortal().Get(0);
VTKM_TEST_ASSERT(value == 0, "Incorrect partial sum");
std::cout << " size 0" << std::endl;
array.Allocate(0);
sum = Algorithm::ScanExclusive(array, array);
VTKM_TEST_ASSERT(sum == 0, "Incorrect partial sum");
@ -2149,7 +2127,6 @@ private:
Vec3ArrayHandle values = vtkm::cont::make_ArrayHandle(testValues, vtkm::CopyFlag::Off);
Vec3 sum = Algorithm::ScanExclusive(values, values);
std::cout << "Sum that was returned " << sum << std::endl;
VTKM_TEST_ASSERT(test_equal(sum, (TestValue(1, Vec3()) * ARRAY_SIZE)),
"Got bad sum from Exclusive Scan");
}
@ -2161,7 +2138,6 @@ private:
std::cout << "Testing Extended Scan" << std::endl;
{
std::cout << " size " << ARRAY_SIZE << std::endl;
//construct the index array
IdArrayHandle array;
@ -2185,7 +2161,6 @@ private:
}
}
std::cout << " size 1" << std::endl;
array.Allocate(1, vtkm::CopyFlag::On);
array.WritePortal().Set(0, OFFSET);
Algorithm::ScanExtended(array, array);
@ -2196,7 +2171,6 @@ private:
VTKM_TEST_ASSERT(portal.Get(1) == OFFSET, "Incorrect total sum");
}
std::cout << " size 0" << std::endl;
array.Allocate(0);
Algorithm::ScanExtended(array, array);
VTKM_TEST_ASSERT(array.GetNumberOfValues() == 1);
@ -2272,7 +2246,6 @@ private:
std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing Exceptions in Execution Environment" << std::endl;
std::cout << "Generating one error." << std::endl;
std::string message;
try
{
@ -2281,12 +2254,10 @@ private:
}
catch (vtkm::cont::ErrorExecution& error)
{
std::cout << "Got expected error: " << error.GetMessage() << std::endl;
message = error.GetMessage();
}
VTKM_TEST_ASSERT(message == ERROR_MESSAGE, "Did not get expected error message.");
std::cout << "Generating lots of errors." << std::endl;
message = "";
try
{
@ -2295,7 +2266,6 @@ private:
}
catch (vtkm::cont::ErrorExecution& error)
{
std::cout << "Got expected error: " << error.GetMessage() << std::endl;
message = error.GetMessage();
}
VTKM_TEST_ASSERT(message == ERROR_MESSAGE, "Did not get expected error message.");

@ -13,11 +13,11 @@
void TestArrayHandleStandardNormal()
{
auto array = vtkm::cont::ArrayHandleRandomStandardNormal<vtkm::Float32>(1000000, { 0xceed });
auto array = vtkm::cont::ArrayHandleRandomStandardNormal<vtkm::Float32>(50000, { 0xceed });
auto stats = vtkm::worklet::DescriptiveStatistics::Run(array);
VTKM_TEST_ASSERT(test_equal(stats.Mean(), 0, 0.001));
VTKM_TEST_ASSERT(test_equal(stats.PopulationStddev(), 1, 0.001));
VTKM_TEST_ASSERT(test_equal(stats.Mean(), 0, 0.01));
VTKM_TEST_ASSERT(test_equal(stats.PopulationStddev(), 1, 0.01));
VTKM_TEST_ASSERT(test_equal(stats.Skewness(), 0.0f, 1.0f / 100));
VTKM_TEST_ASSERT(test_equal(stats.Kurtosis(), 3.0f, 1.0f / 100));
}

@ -15,7 +15,7 @@
void TestRangeBounds()
{
// the random numbers should fall into the range of [0, 1).
auto array = vtkm::cont::ArrayHandleRandomUniformReal<vtkm::Float32>(1000000, { 0xceed });
auto array = vtkm::cont::ArrayHandleRandomUniformReal<vtkm::Float32>(100, { 0xceed });
auto portal = array.ReadPortal();
for (vtkm::Id i = 0; i < array.GetNumberOfValues(); ++i)
{
@ -26,7 +26,7 @@ void TestRangeBounds()
void TestStatisticsProperty()
{
auto array = vtkm::cont::ArrayHandleRandomUniformReal<vtkm::Float32>(1000000, { 0xceed });
auto array = vtkm::cont::ArrayHandleRandomUniformReal<vtkm::Float32>(10000, { 0xceed });
auto result = vtkm::worklet::DescriptiveStatistics::Run(array);
VTKM_TEST_ASSERT(test_equal(result.Mean(), 0.5, 0.001));

@ -34,7 +34,7 @@ using PointType = vtkm::Vec3f;
vtkm::cont::DataSet MakeTestDataSetUniform()
{
return vtkm::cont::DataSetBuilderUniform::Create(
vtkm::Id3{ 64 }, PointType{ -32.0f }, PointType{ 1.0f / 64.0f });
vtkm::Id3{ 32 }, PointType{ -32.0f }, PointType{ 1.0f / 64.0f });
}
vtkm::cont::DataSet MakeTestDataSetRectilinear()
@ -44,7 +44,7 @@ vtkm::cont::DataSet MakeTestDataSetRectilinear()
vtkm::cont::ArrayHandle<vtkm::FloatDefault> coords[3];
for (int i = 0; i < 3; ++i)
{
coords[i].Allocate(64);
coords[i].Allocate(16);
auto portal = coords[i].WritePortal();
vtkm::FloatDefault cur = 0.0f;
@ -128,14 +128,16 @@ void GenerateRandomInput(const vtkm::cont::DataSet& ds,
pcoords.Allocate(count);
wcoords.Allocate(count);
auto cwp = cellIds.WritePortal();
auto pwp = pcoords.WritePortal();
for (vtkm::Id i = 0; i < count; ++i)
{
cellIds.WritePortal().Set(i, cellIdGen(RandomGenerator));
cwp.Set(i, cellIdGen(RandomGenerator));
PointType pc{ pcoordGen(RandomGenerator),
pcoordGen(RandomGenerator),
pcoordGen(RandomGenerator) };
pcoords.WritePortal().Set(i, pc);
pwp.Set(i, pc);
}
vtkm::worklet::DispatcherMapTopology<ParametricToWorldCoordinates> dispatcher(
@ -182,7 +184,7 @@ void TestWithDataSet(const vtkm::cont::DataSet& dataset)
vtkm::cont::ArrayHandle<vtkm::Id> expCellIds;
vtkm::cont::ArrayHandle<PointType> expPCoords;
vtkm::cont::ArrayHandle<PointType> points;
GenerateRandomInput(dataset, 128, expCellIds, expPCoords, points);
GenerateRandomInput(dataset, 32, expCellIds, expPCoords, points);
vtkm::cont::ArrayHandle<vtkm::Id> cellIds;
vtkm::cont::ArrayHandle<PointType> pcoords;
@ -194,23 +196,19 @@ void TestWithDataSet(const vtkm::cont::DataSet& dataset)
auto expCellIdsPortal = expCellIds.ReadPortal();
auto pcoordsPortal = pcoords.ReadPortal();
auto expPCoordsPortal = expPCoords.ReadPortal();
for (vtkm::Id i = 0; i < 128; ++i)
for (vtkm::Id i = 0; i < 32; ++i)
{
VTKM_TEST_ASSERT(cellIdPortal.Get(i) == expCellIdsPortal.Get(i), "Incorrect cell ids");
VTKM_TEST_ASSERT(test_equal(pcoordsPortal.Get(i), expPCoordsPortal.Get(i), 1e-3),
"Incorrect parameteric coordinates");
}
std::cout << "Passed.\n";
}
void TestCellLocatorChooser()
{
std::cout << "Test UniformGrid dataset\n";
TestWithDataSet<vtkm::cont::CellSetStructured<3>, vtkm::cont::ArrayHandleUniformPointCoordinates>(
MakeTestDataSetUniform());
std::cout << "Test Rectilinear dataset\n";
TestWithDataSet<
vtkm::cont::CellSetStructured<3>,
vtkm::cont::ArrayHandleCartesianProduct<vtkm::cont::ArrayHandle<vtkm::FloatDefault>,
@ -218,7 +216,6 @@ void TestCellLocatorChooser()
vtkm::cont::ArrayHandle<vtkm::FloatDefault>>>(
MakeTestDataSetRectilinear());
std::cout << "Test Curvilinear dataset\n";
TestWithDataSet<vtkm::cont::CellSetStructured<3>, vtkm::cont::ArrayHandle<PointType>>(
MakeTestDataSetCurvilinear());
}

@ -34,7 +34,7 @@ using PointType = vtkm::Vec3f;
vtkm::cont::DataSet MakeTestDataSetUniform()
{
return vtkm::cont::DataSetBuilderUniform::Create(
vtkm::Id3{ 64 }, PointType{ -32.0f }, PointType{ 1.0f / 64.0f });
vtkm::Id3{ 32 }, PointType{ -32.0f }, PointType{ 1.0f / 64.0f });
}
vtkm::cont::DataSet MakeTestDataSetRectilinear()
@ -44,7 +44,7 @@ vtkm::cont::DataSet MakeTestDataSetRectilinear()
vtkm::cont::ArrayHandle<vtkm::FloatDefault> coords[3];
for (int i = 0; i < 3; ++i)
{
coords[i].Allocate(64);
coords[i].Allocate(16);
auto portal = coords[i].WritePortal();
vtkm::FloatDefault cur = 0.0f;
@ -128,14 +128,16 @@ void GenerateRandomInput(const vtkm::cont::DataSet& ds,
pcoords.Allocate(count);
wcoords.Allocate(count);
auto cellIdPortal = cellIds.WritePortal();
auto pcoordsPortal = pcoords.WritePortal();
for (vtkm::Id i = 0; i < count; ++i)
{
cellIds.WritePortal().Set(i, cellIdGen(RandomGenerator));
cellIdPortal.Set(i, cellIdGen(RandomGenerator));
PointType pc{ pcoordGen(RandomGenerator),
pcoordGen(RandomGenerator),
pcoordGen(RandomGenerator) };
pcoords.WritePortal().Set(i, pc);
pcoordsPortal.Set(i, pc);
}
vtkm::worklet::DispatcherMapTopology<ParametricToWorldCoordinates> dispatcher(
@ -177,7 +179,7 @@ void TestWithDataSet(vtkm::cont::CellLocatorGeneral& locator, const vtkm::cont::
vtkm::cont::ArrayHandle<vtkm::Id> expCellIds;
vtkm::cont::ArrayHandle<PointType> expPCoords;
vtkm::cont::ArrayHandle<PointType> points;
GenerateRandomInput(dataset, 128, expCellIds, expPCoords, points);
GenerateRandomInput(dataset, 64, expCellIds, expPCoords, points);
vtkm::cont::ArrayHandle<vtkm::Id> cellIds;
vtkm::cont::ArrayHandle<PointType> pcoords;
@ -189,27 +191,22 @@ void TestWithDataSet(vtkm::cont::CellLocatorGeneral& locator, const vtkm::cont::
auto expCellIdsPortal = expCellIds.ReadPortal();
auto pcoordsPortal = pcoords.ReadPortal();
auto expPCoordsPortal = expPCoords.ReadPortal();
for (vtkm::Id i = 0; i < 128; ++i)
for (vtkm::Id i = 0; i < 64; ++i)
{
VTKM_TEST_ASSERT(cellIdPortal.Get(i) == expCellIdsPortal.Get(i), "Incorrect cell ids");
VTKM_TEST_ASSERT(test_equal(pcoordsPortal.Get(i), expPCoordsPortal.Get(i), 1e-3),
"Incorrect parameteric coordinates");
}
std::cout << "Passed.\n";
}
void TestCellLocatorGeneral()
{
vtkm::cont::CellLocatorGeneral locator;
std::cout << "Test UniformGrid dataset\n";
TestWithDataSet(locator, MakeTestDataSetUniform());
std::cout << "Test Rectilinear dataset\n";
TestWithDataSet(locator, MakeTestDataSetRectilinear());
std::cout << "Test Curvilinear dataset\n";
TestWithDataSet(locator, MakeTestDataSetCurvilinear());
}

@ -154,11 +154,11 @@ void TestThreadWake()
std::cout << " Launching coordinated thread" << std::endl;
auto future = std::async(std::launch::async, WaitForDetachment, &object);
std::cout << " Sleep 2 seconds for thread to lock" << std::endl;
// 2 seconds should be ample time for the spawned thread to launch. If the systems busy then
std::cout << " Sleep 500 milliseconds for thread to lock" << std::endl;
// 500 milliseconds should be ample time for the spawned thread to launch. If the systems busy then
// we might actually unlock the object before the thread gets there, but hopefully on some
// systems it will test correctly.
std::this_thread::sleep_for(std::chrono::seconds(2));
std::this_thread::sleep_for(std::chrono::milliseconds(500));
std::cout << " Main thread woke up. Detach token." << std::endl;
token.DetachFromAll();

@ -37,15 +37,11 @@ void TestImageMedian()
//verified by hand
{
auto portal = resultArrayHandle.ReadPortal();
std::cout << "spot to verify x = 1, y = 1, z = 0 is: ";
vtkm::Float32 temp = portal.Get(1 + pdims[0]);
std::cout << temp << std::endl << std::endl;
VTKM_TEST_ASSERT(test_equal(temp, 2), "incorrect median value");
vtkm::Float32 expected_median = portal.Get(1 + pdims[0]);
VTKM_TEST_ASSERT(test_equal(expected_median, 2), "incorrect median value");
std::cout << "spot to verify x = 1, y = 1, z = 2 is: ";
temp = portal.Get(1 + pdims[0] + (pdims[1] * pdims[0] * 2));
std::cout << temp << std::endl << std::endl;
VTKM_TEST_ASSERT(test_equal(temp, 2.82843), "incorrect median value");
expected_median = portal.Get(1 + pdims[0] + (pdims[1] * pdims[0] * 2));
VTKM_TEST_ASSERT(test_equal(expected_median, 2.82843), "incorrect median value");
}
}
}

@ -21,7 +21,7 @@ namespace
std::vector<vtkm::cont::DataSet> MakeDataSets()
{
vtkm::Bounds bounds(0, 10, 0, 10, 0, 10);
const vtkm::Id3 dims(16, 16, 16);
const vtkm::Id3 dims(8, 8, 8);
auto dataSets = vtkm::worklet::testing::CreateAllDataSets(bounds, dims, false);
vtkm::Id numPoints = dims[0] * dims[1] * dims[2];
@ -48,8 +48,7 @@ std::vector<vtkm::cont::DataSet> MakeDataSets()
void TestLagrangianFilterMultiStepInterval()
{
std::cout << "Test: Lagrangian Analysis - Uniform Dataset - Write Interval > 1" << std::endl;
vtkm::Id maxCycles = 10;
vtkm::Id maxCycles = 5;
vtkm::Id write_interval = 5;
vtkm::filter::Lagrangian lagrangianFilter2;
lagrangianFilter2.SetResetParticles(true);
@ -67,7 +66,7 @@ void TestLagrangianFilterMultiStepInterval()
{
VTKM_TEST_ASSERT(extractedBasisFlows.GetNumberOfCoordinateSystems() == 1,
"Wrong number of coordinate systems in the output dataset.");
VTKM_TEST_ASSERT(extractedBasisFlows.GetNumberOfPoints() == 4096,
VTKM_TEST_ASSERT(extractedBasisFlows.GetNumberOfPoints() == 512,
"Wrong number of basis flows extracted.");
VTKM_TEST_ASSERT(extractedBasisFlows.GetNumberOfFields() == 2, "Wrong number of fields.");
}

@ -17,7 +17,7 @@
void TestNGP()
{
const vtkm::Id N = 1000000;
const vtkm::Id N = 1000;
// This is a better way to create this array, but I am temporarily breaking this
// functionality (November 2020) so that I can split up merge requests that move
// ArrayHandles to the new buffer types. This should be restored once
@ -68,7 +68,7 @@ void TestNGP()
void TestCIC()
{
const vtkm::Id N = 1000000;
const vtkm::Id N = 1000;
// This is a better way to create this array, but I am temporarily breaking this
// functionality (November 2020) so that I can split up merge requests that move
// ArrayHandles to the new buffer types. This should be restored once

@ -225,7 +225,7 @@ void TestAMRStreamline(bool useSL)
{
vtkm::filter::Streamline filter;
filter.SetStepSize(0.1f);
filter.SetNumberOfSteps(100000);
filter.SetNumberOfSteps(1000);
filter.SetSeeds(seedArray);
filter.SetActiveField(fieldName);
@ -297,7 +297,7 @@ void TestAMRStreamline(bool useSL)
{
vtkm::filter::ParticleAdvection filter;
filter.SetStepSize(0.1f);
filter.SetNumberOfSteps(100000);
filter.SetNumberOfSteps(1000);
filter.SetSeeds(seedArray);
filter.SetActiveField(fieldName);
@ -374,7 +374,7 @@ void TestPartitionedDataSet(vtkm::Id num, bool useGhost, bool useSL)
vtkm::filter::Streamline streamline;
streamline.SetStepSize(0.1f);
streamline.SetNumberOfSteps(100000);
streamline.SetNumberOfSteps(1000);
streamline.SetSeeds(seedArray);
streamline.SetActiveField(fieldName);
@ -420,7 +420,7 @@ void TestPartitionedDataSet(vtkm::Id num, bool useGhost, bool useSL)
vtkm::filter::ParticleAdvection particleAdvection;
particleAdvection.SetStepSize(0.1f);
particleAdvection.SetNumberOfSteps(100000);
particleAdvection.SetNumberOfSteps(1000);
particleAdvection.SetSeeds(seedArray);
particleAdvection.SetActiveField(fieldName);

@ -15,17 +15,9 @@
void WaveletSourceTest()
{
vtkm::cont::Timer timer;
timer.Start();
vtkm::source::Wavelet source;
vtkm::cont::DataSet ds = source.Execute();
double time = timer.GetElapsedTime();
std::cout << "Default wavelet took " << time << "s.\n";
{
auto coords = ds.GetCoordinateSystem("coordinates");
auto data = coords.GetData();

@ -130,8 +130,6 @@ struct ScalarFieldTests : public vtkm::exec::FunctorBase
VTKM_EXEC
void TestArcTan2() const
{
// std::cout << "Testing arc tan 2" << std::endl;
VTKM_MATH_ASSERT(test_equal(vtkm::ATan2(T(0.0), T(1.0)), T(0.0)), "ATan2 x+ axis.");
VTKM_MATH_ASSERT(test_equal(vtkm::ATan2(T(1.0), T(0.0)), T(0.5 * vtkm::Pi())),
"ATan2 y+ axis.");
@ -151,7 +149,6 @@ struct ScalarFieldTests : public vtkm::exec::FunctorBase
VTKM_EXEC
void TestPow() const
{
// std::cout << "Running power tests." << std::endl;
for (vtkm::IdComponent index = 0; index < Lists::NUM_NUMBERS; index++)
{
T x = static_cast<T>(Lists{}.NumberList(index));
@ -164,7 +161,6 @@ struct ScalarFieldTests : public vtkm::exec::FunctorBase
VTKM_EXEC
void TestLog2() const
{
// std::cout << "Testing Log2" << std::endl;
VTKM_MATH_ASSERT(test_equal(vtkm::Log2(T(0.25)), T(-2.0)), "Bad value from Log2");
VTKM_MATH_ASSERT(test_equal(vtkm::Log2(vtkm::Vec<T, 4>(0.5, 1.0, 2.0, 4.0)),
vtkm::Vec<T, 4>(-1.0, 0.0, 1.0, 2.0)),
@ -174,8 +170,6 @@ struct ScalarFieldTests : public vtkm::exec::FunctorBase
VTKM_EXEC
void TestNonFinites() const
{
// std::cout << "Testing non-finites." << std::endl;
T zero = 0.0;
T finite = 1.0;
T nan = vtkm::Nan<T>();
@ -227,7 +221,6 @@ struct ScalarFieldTests : public vtkm::exec::FunctorBase
VTKM_EXEC
void TestRemainders() const
{
// std::cout << "Testing remainders." << std::endl;
Lists table;
for (vtkm::IdComponent index = 0; index < Lists::NUM_NUMBERS; index++)
{
@ -251,7 +244,6 @@ struct ScalarFieldTests : public vtkm::exec::FunctorBase
VTKM_EXEC
void TestRound() const
{
// std::cout << "Testing round." << std::endl;
Lists table;
for (vtkm::IdComponent index = 0; index < Lists::NUM_NUMBERS; index++)
{
@ -274,7 +266,6 @@ struct ScalarFieldTests : public vtkm::exec::FunctorBase
VTKM_EXEC
void TestIsNegative() const
{
// std::cout << "Testing SignBit and IsNegative." << std::endl;
T x = 0;
VTKM_MATH_ASSERT(vtkm::SignBit(x) == 0, "SignBit wrong for 0.");
VTKM_MATH_ASSERT(!vtkm::IsNegative(x), "IsNegative wrong for 0.");
@ -333,7 +324,6 @@ struct ScalarVectorFieldTests : public vtkm::exec::FunctorBase
VTKM_EXEC
void TestTriangleTrig() const
{
// std::cout << "Testing normal trig functions." << std::endl;
Lists table;
for (vtkm::IdComponent index = 0; index < Lists::NUM_NUMBERS - NUM_COMPONENTS + 1; index++)
{
@ -386,8 +376,6 @@ struct ScalarVectorFieldTests : public vtkm::exec::FunctorBase
VTKM_EXEC
void TestHyperbolicTrig() const
{
// std::cout << "Testing hyperbolic trig functions." << std::endl;
const VectorType zero(0);
Lists table;
for (vtkm::IdComponent index = 0; index < Lists::NUM_NUMBERS - NUM_COMPONENTS + 1; index++)
@ -441,11 +429,7 @@ struct ScalarVectorFieldTests : public vtkm::exec::FunctorBase
VectorType operator()(VectorType x) const { return vtkm::Sqrt(x); }
};
VTKM_EXEC
void TestSqrt() const
{
// std::cout << " Testing Sqrt" << std::endl;
RaiseToTest(SqrtFunctor(), 0.5);
}
void TestSqrt() const { RaiseToTest(SqrtFunctor(), 0.5); }
struct RSqrtFunctor
{
@ -453,11 +437,7 @@ struct ScalarVectorFieldTests : public vtkm::exec::FunctorBase
VectorType operator()(VectorType x) const { return vtkm::RSqrt(x); }
};
VTKM_EXEC
void TestRSqrt() const
{
// std::cout << " Testing RSqrt"<< std::endl;
RaiseToTest(RSqrtFunctor(), -0.5);
}
void TestRSqrt() const { RaiseToTest(RSqrtFunctor(), -0.5); }
struct CbrtFunctor
{
@ -465,11 +445,7 @@ struct ScalarVectorFieldTests : public vtkm::exec::FunctorBase
VectorType operator()(VectorType x) const { return vtkm::Cbrt(x); }
};
VTKM_EXEC
void TestCbrt() const
{
// std::cout << " Testing Cbrt" << std::endl;
RaiseToTest(CbrtFunctor(), vtkm::Float32(1.0 / 3.0));
}
void TestCbrt() const { RaiseToTest(CbrtFunctor(), vtkm::Float32(1.0 / 3.0)); }
struct RCbrtFunctor
{
@ -477,11 +453,7 @@ struct ScalarVectorFieldTests : public vtkm::exec::FunctorBase
VectorType operator()(VectorType x) const { return vtkm::RCbrt(x); }
};
VTKM_EXEC
void TestRCbrt() const
{
// std::cout << " Testing RCbrt" << std::endl;
RaiseToTest(RCbrtFunctor(), vtkm::Float32(-1.0 / 3.0));
}
void TestRCbrt() const { RaiseToTest(RCbrtFunctor(), vtkm::Float32(-1.0 / 3.0)); }
template <typename FunctionType>
VTKM_EXEC void RaiseByTest(FunctionType function,
@ -514,11 +486,7 @@ struct ScalarVectorFieldTests : public vtkm::exec::FunctorBase
VectorType operator()(VectorType x) const { return vtkm::Exp(x); }
};
VTKM_EXEC
void TestExp() const
{
// std::cout << " Testing Exp" << std::endl;
RaiseByTest(ExpFunctor(), vtkm::Float32(2.71828183));
}
void TestExp() const { RaiseByTest(ExpFunctor(), vtkm::Float32(2.71828183)); }
struct Exp2Functor
{
@ -526,11 +494,7 @@ struct ScalarVectorFieldTests : public vtkm::exec::FunctorBase
VectorType operator()(VectorType x) const { return vtkm::Exp2(x); }
};
VTKM_EXEC
void TestExp2() const
{
// std::cout << " Testing Exp2" << std::endl;
RaiseByTest(Exp2Functor(), 2.0);
}
void TestExp2() const { RaiseByTest(Exp2Functor(), 2.0); }
struct ExpM1Functor
{
@ -538,11 +502,7 @@ struct ScalarVectorFieldTests : public vtkm::exec::FunctorBase
VectorType operator()(VectorType x) const { return vtkm::ExpM1(x); }
};
VTKM_EXEC
void TestExpM1() const
{
// std::cout << " Testing ExpM1" << std::endl;
RaiseByTest(ExpM1Functor(), ComponentType(2.71828183), 0.0, -1.0);
}
void TestExpM1() const { RaiseByTest(ExpM1Functor(), ComponentType(2.71828183), 0.0, -1.0); }
struct Exp10Functor
{
@ -550,11 +510,7 @@ struct ScalarVectorFieldTests : public vtkm::exec::FunctorBase
VectorType operator()(VectorType x) const { return vtkm::Exp10(x); }
};
VTKM_EXEC
void TestExp10() const
{
// std::cout << " Testing Exp10" << std::endl;
RaiseByTest(Exp10Functor(), 10.0);
}
void TestExp10() const { RaiseByTest(Exp10Functor(), 10.0); }
template <typename FunctionType>
VTKM_EXEC void LogBaseTest(FunctionType function,
@ -588,11 +544,7 @@ struct ScalarVectorFieldTests : public vtkm::exec::FunctorBase
VectorType operator()(VectorType x) const { return vtkm::Log(x); }
};
VTKM_EXEC
void TestLog() const
{
// std::cout << " Testing Log" << std::endl;
LogBaseTest(LogFunctor(), vtkm::Float32(2.71828183));
}
void TestLog() const { LogBaseTest(LogFunctor(), vtkm::Float32(2.71828183)); }
struct Log10Functor
{
@ -600,11 +552,7 @@ struct ScalarVectorFieldTests : public vtkm::exec::FunctorBase
VectorType operator()(VectorType x) const { return vtkm::Log10(x); }
};
VTKM_EXEC
void TestLog10() const
{
// std::cout << " Testing Log10" << std::endl;
LogBaseTest(Log10Functor(), 10.0);
}
void TestLog10() const { LogBaseTest(Log10Functor(), 10.0); }
struct Log1PFunctor
{
@ -612,16 +560,11 @@ struct ScalarVectorFieldTests : public vtkm::exec::FunctorBase
VectorType operator()(VectorType x) const { return vtkm::Log1P(x); }
};
VTKM_EXEC
void TestLog1P() const
{
// std::cout << " Testing Log1P" << std::endl;
LogBaseTest(Log1PFunctor(), ComponentType(2.71828183), 1.0);
}
void TestLog1P() const { LogBaseTest(Log1PFunctor(), ComponentType(2.71828183), 1.0); }
VTKM_EXEC
void TestCopySign() const
{
// std::cout << "Testing CopySign." << std::endl;
// Assuming all TestValues positive.
VectorType positive1 = TestValue(1, VectorType());
VectorType positive2 = TestValue(2, VectorType());
@ -713,7 +656,7 @@ struct ScalarVectorFieldTests : public vtkm::exec::FunctorBase
// Now test x = y:
vtkm::Float64 x = -1;
for (int i = 0; i < 500; ++i)
for (int i = 0; i < 50; ++i)
{
dist = vtkm::FloatDistance(x, x);
VTKM_MATH_ASSERT(test_equal(vtkm::UInt64(0), dist),
@ -840,7 +783,7 @@ struct ScalarVectorFieldTests : public vtkm::exec::FunctorBase
// Now test x = y:
vtkm::Float32 x = -1;
for (int i = 0; i < 500; ++i)
for (int i = 0; i < 50; ++i)
{
dist = vtkm::FloatDistance(x, x);
VTKM_MATH_ASSERT(test_equal(vtkm::UInt64(0), dist),
@ -1001,7 +944,6 @@ struct AllTypesTests : public vtkm::exec::FunctorBase
{
T low = TestValue(2, T());
T high = TestValue(10, T());
// std::cout << "Testing min/max " << low << " " << high << std::endl;
VTKM_MATH_ASSERT(test_equal(vtkm::Min(low, high), low), "Wrong min.");
VTKM_MATH_ASSERT(test_equal(vtkm::Min(high, low), low), "Wrong min.");
VTKM_MATH_ASSERT(test_equal(vtkm::Max(low, high), high), "Wrong max.");
@ -1038,7 +980,6 @@ struct AbsTests : public vtkm::exec::FunctorBase
VTKM_EXEC
void operator()(vtkm::Id index) const
{
// std::cout << "Testing Abs." << std::endl;
T positive = TestValue(index, T()); // Assuming all TestValues positive.
T negative = -positive;
@ -1060,7 +1001,7 @@ using TypeListAbs =
vtkm::ListAppend<vtkm::List<vtkm::Int32, vtkm::Int64>, vtkm::TypeListIndex, vtkm::TypeListField>;
//-----------------------------------------------------------------------------
static constexpr vtkm::Id BitOpSamples = 1024 * 1024;
static constexpr vtkm::Id BitOpSamples = 128 * 128;
template <typename T>
struct BitOpTests : public vtkm::exec::FunctorBase
@ -1131,15 +1072,10 @@ using TypeListBitOp = vtkm::List<vtkm::UInt32, vtkm::UInt64>;
//-----------------------------------------------------------------------------
void RunMathTests()
{
std::cout << "Tests for scalar types." << std::endl;
vtkm::testing::Testing::TryTypes(TryScalarFieldTests(), vtkm::TypeListFieldScalar());
std::cout << "Test for scalar and vector types." << std::endl;
vtkm::testing::Testing::TryTypes(TryScalarVectorFieldTests(), vtkm::TypeListField());
std::cout << "Test for exemplar types." << std::endl;
vtkm::testing::Testing::TryTypes(TryAllTypesTests());
std::cout << "Test all Abs types" << std::endl;
vtkm::testing::Testing::TryTypes(TryAbsTests(), TypeListAbs());
std::cout << "Test all bit operations" << std::endl;
vtkm::testing::Testing::TryTypes(TryBitOpTests(), TypeListBitOp());
}

@ -62,45 +62,28 @@ vtkm::cont::DataSet ConstructDataSet(vtkm::Id size)
void TestBoundingIntervalHierarchy(vtkm::cont::DataSet dataSet, vtkm::IdComponent numPlanes)
{
using Timer = vtkm::cont::Timer;
vtkm::cont::DynamicCellSet cellSet = dataSet.GetCellSet();
auto vertices = dataSet.GetCoordinateSystem().GetDataAsMultiplexer();
std::cout << "Using numPlanes: " << numPlanes << "\n";
std::cout << "Building Bounding Interval Hierarchy Tree" << std::endl;
vtkm::cont::CellLocatorBoundingIntervalHierarchy bih =
vtkm::cont::CellLocatorBoundingIntervalHierarchy(numPlanes, 5);
bih.SetCellSet(cellSet);
bih.SetCoordinates(dataSet.GetCoordinateSystem());
bih.Update();
std::cout << "Built Bounding Interval Hierarchy Tree" << std::endl;
Timer centroidsTimer;
centroidsTimer.Start();
vtkm::cont::ArrayHandle<vtkm::Vec3f> centroids;
vtkm::worklet::DispatcherMapTopology<CellCentroidCalculator>().Invoke(
cellSet, vertices, centroids);
centroidsTimer.Stop();
std::cout << "Centroids calculation time: " << centroidsTimer.GetElapsedTime() << "\n";
vtkm::cont::ArrayHandleCounting<vtkm::Id> expectedCellIds(0, 1, cellSet.GetNumberOfCells());
Timer interpolationTimer;
interpolationTimer.Start();
vtkm::cont::ArrayHandle<vtkm::IdComponent> results;
vtkm::worklet::DispatcherMapField<BoundingIntervalHierarchyTester>().Invoke(
centroids, bih, expectedCellIds, results);
vtkm::Id numDiffs = vtkm::cont::Algorithm::Reduce(results, 0, vtkm::Add());
interpolationTimer.Stop();
vtkm::Float64 timeDiff = interpolationTimer.GetElapsedTime();
std::cout << "No of interpolations: " << results.GetNumberOfValues() << "\n";
std::cout << "Interpolation time: " << timeDiff << "\n";
std::cout << "Average interpolation rate: "
<< (static_cast<vtkm::Float64>(results.GetNumberOfValues()) / timeDiff) << "\n";
std::cout << "No of diffs: " << numDiffs << "\n";
VTKM_TEST_ASSERT(numDiffs == 0, "Calculated cell Ids not the same as expected cell Ids");
}
@ -113,10 +96,10 @@ void RunTest()
omp_set_num_threads(std::min(4, omp_get_max_threads()));
#endif
TestBoundingIntervalHierarchy(ConstructDataSet(16), 3);
TestBoundingIntervalHierarchy(ConstructDataSet(16), 4);
TestBoundingIntervalHierarchy(ConstructDataSet(16), 6);
TestBoundingIntervalHierarchy(ConstructDataSet(16), 9);
TestBoundingIntervalHierarchy(ConstructDataSet(8), 3);
TestBoundingIntervalHierarchy(ConstructDataSet(8), 4);
TestBoundingIntervalHierarchy(ConstructDataSet(8), 6);
TestBoundingIntervalHierarchy(ConstructDataSet(8), 9);
}
} // anonymous namespace

@ -200,10 +200,16 @@ struct ValidateNormals
vtkm::Id numVisitedCells = vtkm::cont::Algorithm::CountSetBits(this->VisitedCellsField);
if (numPoints != numVisitedPoints)
{
std::cerr << __FILE__ << ":" << __LINE__ << ":" << __func__ << "\n";
std::cerr << "\tnumPoints is " << numPoints << ", but numVisitedPoints is only "
<< numVisitedPoints << "\n";
throw vtkm::cont::ErrorBadValue("Unvisited point!");
}
if (numCells != numVisitedCells)
{
std::cerr << __FILE__ << ":" << __LINE__ << ":" << __func__ << "\n";
std::cerr << "\tnumCells is " << numCells << ", but numVisitedCells is only "
<< numVisitedCells << "\n";
throw vtkm::cont::ErrorBadValue("Unvisited cell!");
}
}
@ -252,13 +258,6 @@ private:
const NormalType curNormal = this->PointNormals.Get(curPtIdx);
if (!this->SameHemisphere(curNormal, refNormal))
{
const auto coord = points.Get(curPtIdx);
std::cerr << "BadPointNormal PtId: " << curPtIdx << "\n\t"
<< "- Normal: {" << curNormal[0] << ", " << curNormal[1] << ", " << curNormal[2]
<< "}\n\t"
<< "- Reference: {" << refNormal[0] << ", " << refNormal[1] << ", "
<< refNormal[2] << "}\n\t"
<< "- Coord: {" << coord[0] << ", " << coord[1] << ", " << coord[2] << "}\n";
throw vtkm::cont::ErrorBadValue("Bad point normal found!");
}
refNormal = curNormal;
@ -283,11 +282,6 @@ private:
const NormalType curNormal = this->CellNormals.Get(curCellIdx);
if (!this->SameHemisphere(curNormal, refNormal))
{
std::cerr << "BadCellNormal: CellId: " << curCellIdx << "\n\t"
<< "- Normal: {" << curNormal[0] << ", " << curNormal[1] << ", "
<< curNormal[2] << "}\n\t"
<< "- Reference: {" << refNormal[0] << ", " << refNormal[1] << ", "
<< refNormal[2] << "}\n";
throw vtkm::cont::ErrorBadValue("Bad cell normal found!");
}
refNormal = curNormal;
@ -326,14 +320,11 @@ void TestOrientNormals(bool testPoints, bool testCells)
const bool inputValid = [&]() -> bool {
try
{
std::cerr << "Expecting to throw a BadNormal exception...\n";
ValidateNormals::Run(dataset, testPoints, testCells);
return true; // Dataset is already oriented
}
catch (vtkm::cont::ErrorBadValue&)
{
std::cerr << "Expected exception caught! All is well. "
"Future exceptions are errors.\n";
return false; // Dataset is unoriented
}
}();
@ -348,8 +339,6 @@ void TestOrientNormals(bool testPoints, bool testCells)
const auto cells = dataset.GetCellSet();
if (testPoints && testCells)
{
std::cerr << "Testing point and cell normals...\n";
const auto pointNormalField = dataset.GetPointField("normals");
const auto cellNormalField = dataset.GetCellField("normals");
auto pointNormals = pointNormalField.GetData().AsArrayHandle<NormalArrayT>();
@ -359,7 +348,6 @@ void TestOrientNormals(bool testPoints, bool testCells)
}
else if (testPoints)
{
std::cerr << "Testing point normals...\n";
const auto pointNormalField = dataset.GetPointField("normals");
auto pointNormals = pointNormalField.GetData().AsArrayHandle<NormalArrayT>();
@ -367,7 +355,6 @@ void TestOrientNormals(bool testPoints, bool testCells)
}
else if (testCells)
{
std::cerr << "Testing cell normals...\n";
const auto cellNormalField = dataset.GetCellField("normals");
auto cellNormals = cellNormalField.GetData().AsArrayHandle<NormalArrayT>();

@ -164,11 +164,10 @@ void FillArray3D(ArrayType& array, vtkm::Id dimX, vtkm::Id dimY, vtkm::Id dimZ)
void TestDecomposeReconstruct3D(vtkm::Float64 cratio)
{
vtkm::Id sigX = 99;
vtkm::Id sigY = 99;
vtkm::Id sigZ = 99;
vtkm::Id sigX = 45;
vtkm::Id sigY = 45;
vtkm::Id sigZ = 45;
vtkm::Id sigLen = sigX * sigY * sigZ;
std::cout << "Testing 3D wavelet compressor on a (99x99x99) cube..." << std::endl;
// make input data array handle
vtkm::cont::ArrayHandle<vtkm::Float32> inputArray;
@ -179,56 +178,25 @@ void TestDecomposeReconstruct3D(vtkm::Float64 cratio)
// Use a WaveletCompressor
vtkm::worklet::wavelets::WaveletName wname = vtkm::worklet::wavelets::BIOR4_4;
if (wname == vtkm::worklet::wavelets::BIOR1_1)
std::cout << "Using wavelet kernel = Bior1.1 (HAAR)" << std::endl;
else if (wname == vtkm::worklet::wavelets::BIOR2_2)
std::cout << "Using wavelet kernel = Bior2.2 (CDF 5/3)" << std::endl;
else if (wname == vtkm::worklet::wavelets::BIOR3_3)
std::cout << "Using wavelet kernel = Bior3.3 (CDF 8/4)" << std::endl;
else if (wname == vtkm::worklet::wavelets::BIOR4_4)
std::cout << "Using wavelet kernel = Bior4.4 (CDF 9/7)" << std::endl;
vtkm::worklet::WaveletCompressor compressor(wname);
vtkm::Id XMaxLevel = compressor.GetWaveletMaxLevel(sigX);
vtkm::Id YMaxLevel = compressor.GetWaveletMaxLevel(sigY);
vtkm::Id ZMaxLevel = compressor.GetWaveletMaxLevel(sigZ);
vtkm::Id nLevels = vtkm::Min(vtkm::Min(XMaxLevel, YMaxLevel), ZMaxLevel);
std::cout << "Decomposition levels = " << nLevels << std::endl;
vtkm::Float64 computationTime = 0.0;
vtkm::Float64 elapsedTime1, elapsedTime2, elapsedTime3;
// Decompose
compressor.WaveDecompose3D(inputArray, nLevels, sigX, sigY, sigZ, outputArray, false);
vtkm::cont::Timer timer;
timer.Start();
computationTime =
compressor.WaveDecompose3D(inputArray, nLevels, sigX, sigY, sigZ, outputArray, false);
elapsedTime1 = timer.GetElapsedTime();
std::cout << "Decompose time = " << elapsedTime1 << std::endl;
std::cout << " ->computation time = " << computationTime << std::endl;
// Squash small coefficients
timer.Start();
compressor.SquashCoefficients(outputArray, cratio);
elapsedTime2 = timer.GetElapsedTime();
std::cout << "Squash time = " << elapsedTime2 << std::endl;
// Reconstruct
vtkm::cont::ArrayHandle<vtkm::Float32> reconstructArray;
timer.Start();
computationTime =
compressor.WaveReconstruct3D(outputArray, nLevels, sigX, sigY, sigZ, reconstructArray, false);
elapsedTime3 = timer.GetElapsedTime();
std::cout << "Reconstruction time = " << elapsedTime3 << std::endl;
std::cout << " ->computation time = " << computationTime << std::endl;
std::cout << "Total time = " << (elapsedTime1 + elapsedTime2 + elapsedTime3)
<< std::endl;
compressor.WaveReconstruct3D(outputArray, nLevels, sigX, sigY, sigZ, reconstructArray, false);
outputArray.ReleaseResources();
compressor.EvaluateReconstruction(inputArray, reconstructArray);
//compressor.EvaluateReconstruction(inputArray, reconstructArray);
timer.Start();
auto reconstructPortal = reconstructArray.ReadPortal();
auto inputPortal = inputArray.ReadPortal();
for (vtkm::Id i = 0; i < reconstructArray.GetNumberOfValues(); i++)
@ -236,15 +204,12 @@ void TestDecomposeReconstruct3D(vtkm::Float64 cratio)
VTKM_TEST_ASSERT(test_equal(reconstructPortal.Get(i), inputPortal.Get(i)),
"WaveletCompressor 3D failed...");
}
elapsedTime1 = timer.GetElapsedTime();
std::cout << "Verification time = " << elapsedTime1 << std::endl;
}
void TestDecomposeReconstruct2D(vtkm::Float64 cratio)
{
std::cout << "Testing 2D wavelet compressor on a (1000x1000) square... " << std::endl;
vtkm::Id sigX = 1000;
vtkm::Id sigY = 1000;
vtkm::Id sigX = 150;
vtkm::Id sigY = 150;
vtkm::Id sigLen = sigX * sigY;
// make input data array handle
@ -256,47 +221,22 @@ void TestDecomposeReconstruct2D(vtkm::Float64 cratio)
// Use a WaveletCompressor
vtkm::worklet::wavelets::WaveletName wname = vtkm::worklet::wavelets::CDF9_7;
std::cout << "Wavelet kernel = CDF 9/7" << std::endl;
vtkm::worklet::WaveletCompressor compressor(wname);
vtkm::Id XMaxLevel = compressor.GetWaveletMaxLevel(sigX);
vtkm::Id YMaxLevel = compressor.GetWaveletMaxLevel(sigY);
vtkm::Id nLevels = vtkm::Min(XMaxLevel, YMaxLevel);
std::cout << "Decomposition levels = " << nLevels << std::endl;
std::vector<vtkm::Id> L;
vtkm::Float64 computationTime = 0.0;
vtkm::Float64 elapsedTime1, elapsedTime2, elapsedTime3;
// Decompose
vtkm::cont::Timer timer;
timer.Start();
computationTime = compressor.WaveDecompose2D(inputArray, nLevels, sigX, sigY, outputArray, L);
elapsedTime1 = timer.GetElapsedTime();
std::cout << "Decompose time = " << elapsedTime1 << std::endl;
std::cout << " ->computation time = " << computationTime << std::endl;
// Squash small coefficients
timer.Start();
compressor.WaveDecompose2D(inputArray, nLevels, sigX, sigY, outputArray, L);
compressor.SquashCoefficients(outputArray, cratio);
elapsedTime2 = timer.GetElapsedTime();
std::cout << "Squash time = " << elapsedTime2 << std::endl;
// Reconstruct
vtkm::cont::ArrayHandle<vtkm::Float64> reconstructArray;
timer.Start();
computationTime =
compressor.WaveReconstruct2D(outputArray, nLevels, sigX, sigY, reconstructArray, L);
elapsedTime3 = timer.GetElapsedTime();
std::cout << "Reconstruction time = " << elapsedTime3 << std::endl;
std::cout << " ->computation time = " << computationTime << std::endl;
std::cout << "Total time = " << (elapsedTime1 + elapsedTime2 + elapsedTime3)
<< std::endl;
compressor.WaveReconstruct2D(outputArray, nLevels, sigX, sigY, reconstructArray, L);
outputArray.ReleaseResources();
compressor.EvaluateReconstruction(inputArray, reconstructArray);
//compressor.EvaluateReconstruction(inputArray, reconstructArray);
timer.Start();
auto reconstructPortal = reconstructArray.ReadPortal();
auto inputPortal = inputArray.ReadPortal();
for (vtkm::Id i = 0; i < reconstructArray.GetNumberOfValues(); i++)
@ -304,62 +244,43 @@ void TestDecomposeReconstruct2D(vtkm::Float64 cratio)
VTKM_TEST_ASSERT(test_equal(reconstructPortal.Get(i), inputPortal.Get(i)),
"WaveletCompressor 2D failed...");
}
elapsedTime1 = timer.GetElapsedTime();
std::cout << "Verification time = " << elapsedTime1 << std::endl;
}
void TestDecomposeReconstruct1D(vtkm::Float64 cratio)
{
std::cout << "Testing 1D wavelet compressor on a 1 million sized array... " << std::endl;
vtkm::Id sigLen = 1000000;
vtkm::Id sigLen = 1000;
// make input data array handle
std::vector<vtkm::Float64> tmpVector;
vtkm::cont::ArrayHandle<vtkm::Float64> inputArray;
inputArray.Allocate(sigLen);
auto wp = inputArray.WritePortal();
for (vtkm::Id i = 0; i < sigLen; i++)
{
tmpVector.push_back(100.0 * vtkm::Sin(static_cast<vtkm::Float64>(i) / 100.0));
wp.Set(i, 100.0 * vtkm::Sin(static_cast<vtkm::Float64>(i) / 100.0));
}
vtkm::cont::ArrayHandle<vtkm::Float64> inputArray =
vtkm::cont::make_ArrayHandle(tmpVector, vtkm::CopyFlag::On);
vtkm::cont::ArrayHandle<vtkm::Float64> outputArray;
// Use a WaveletCompressor
vtkm::worklet::wavelets::WaveletName wname = vtkm::worklet::wavelets::CDF9_7;
std::cout << "Wavelet kernel = CDF 9/7" << std::endl;
vtkm::worklet::WaveletCompressor compressor(wname);
// User maximum decompose levels
vtkm::Id maxLevel = compressor.GetWaveletMaxLevel(sigLen);
vtkm::Id nLevels = maxLevel;
std::cout << "Decomposition levels = " << nLevels << std::endl;
std::vector<vtkm::Id> L;
// Decompose
vtkm::cont::Timer timer;
timer.Start();
compressor.WaveDecompose(inputArray, nLevels, outputArray, L);
vtkm::Float64 elapsedTime = timer.GetElapsedTime();
std::cout << "Decompose time = " << elapsedTime << std::endl;
// Squash small coefficients
timer.Start();
compressor.SquashCoefficients(outputArray, cratio);
elapsedTime = timer.GetElapsedTime();
std::cout << "Squash time = " << elapsedTime << std::endl;
// Reconstruct
vtkm::cont::ArrayHandle<vtkm::Float64> reconstructArray;
timer.Start();
compressor.WaveReconstruct(outputArray, nLevels, L, reconstructArray);
elapsedTime = timer.GetElapsedTime();
std::cout << "Reconstruction time = " << elapsedTime << std::endl;
compressor.EvaluateReconstruction(inputArray, reconstructArray);
timer.Start();
//compressor.EvaluateReconstruction(inputArray, reconstructArray);
auto reconstructPortal = reconstructArray.ReadPortal();
auto inputPortal = inputArray.ReadPortal();
for (vtkm::Id i = 0; i < reconstructArray.GetNumberOfValues(); i++)
@ -367,22 +288,13 @@ void TestDecomposeReconstruct1D(vtkm::Float64 cratio)
VTKM_TEST_ASSERT(test_equal(reconstructPortal.Get(i), inputPortal.Get(i)),
"WaveletCompressor 1D failed...");
}
elapsedTime = timer.GetElapsedTime();
std::cout << "Verification time = " << elapsedTime << std::endl;
}
void TestWaveletCompressor()
{
vtkm::Float64 cratio = 2.0; // X:1 compression, where X >= 1
std::cout << "Compression ratio = " << cratio << ":1 ";
std::cout
<< "(Reconstruction using higher compression ratios may result in failure in verification)"
<< std::endl;
TestDecomposeReconstruct1D(cratio);
std::cout << std::endl;
TestDecomposeReconstruct2D(cratio);
std::cout << std::endl;
TestDecomposeReconstruct3D(cratio);
}