Revert removal of print statements.

This commit is contained in:
Nick Thompson 2021-04-10 11:44:12 -04:00
parent e7c075b5c4
commit eb760e04ef
2 changed files with 247 additions and 7 deletions

@ -458,6 +458,9 @@ public:
private:
static VTKM_CONT void TestDeviceAdapterTag()
{
std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing device adapter tag" << std::endl;
constexpr DeviceAdapterTag deviceTag;
constexpr vtkm::cont::DeviceAdapterTagUndefined undefinedTag;
@ -473,6 +476,9 @@ private:
static VTKM_CONT void TestMemoryTransfer()
{
std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing Memory Transfer" << std::endl;
using T = vtkm::Id;
using PortalType = vtkm::cont::internal::ArrayPortalFromIterators<T*>;
auto makePortal = [](const vtkm::cont::internal::BufferInfo& buffer) {
@ -492,30 +498,37 @@ private:
vtkm::cont::internal::DeviceAdapterMemoryManager<DeviceAdapterTag> memoryManager;
// Allocate a buffer.
vtkm::cont::internal::BufferInfo allocatedMemory = memoryManager.Allocate(BUFFER_SIZE);
VTKM_TEST_ASSERT(allocatedMemory.GetSize() == BUFFER_SIZE);
// Copy data from host to device.
allocatedMemory = memoryManager.CopyHostToDevice(hostBufferSrc);
// Copy data within device.
vtkm::cont::internal::BufferInfo workingMemory =
memoryManager.CopyDeviceToDevice(allocatedMemory);
VTKM_TEST_ASSERT(workingMemory.GetSize() == BUFFER_SIZE);
// Copy data back to host.
vtkm::cont::internal::BufferInfo hostBufferDest = memoryManager.CopyDeviceToHost(workingMemory);
VTKM_TEST_ASSERT(hostBufferDest.GetSize() == BUFFER_SIZE);
CheckPortal(makePortal(hostBufferDest));
// 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));
// 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));
// 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);
@ -538,9 +551,12 @@ private:
// a 64 bit OS (common), it is simply too hard to get a reliable allocation
// that is too much memory.
#ifdef VTKM_USE_64BIT_IDS
bool caught_expected = false;
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;
vtkm::cont::Token token;
vtkm::cont::ArrayHandle<vtkm::Vec4f_32, StorageTagBasic> bigArray;
const vtkm::Id bigSize = 0x7FFFFFFFFFFFFFFELL;
@ -553,16 +569,17 @@ private:
}
catch (vtkm::cont::ErrorBadAllocation&)
{
caught_expected = true;
caughtBadAlloc = true;
}
VTKM_TEST_ASSERT(caught_expected,
"Should have caught an exception from a monstrous allocation, but did not.");
VTKM_TEST_ASSERT(caughtBadAlloc);
#endif
}
VTKM_CONT
static void TestTimer()
{
std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing Timer" << std::endl;
auto& tracker = vtkm::cont::GetRuntimeDeviceTracker();
if (tracker.CanRunOn(DeviceAdapterTag()))
{
@ -570,11 +587,17 @@ private:
timer.Start();
Algorithm::Synchronize();
std::cout << "Timer started. Sleeping..." << std::endl;
std::this_thread::sleep_for(std::chrono::milliseconds(500));
std::cout << "Woke up. Check time." << std::endl;
timer.Stop();
vtkm::Float64 elapsedTime = timer.GetElapsedTime();
std::cout << "Elapsed time: " << elapsedTime << std::endl;
VTKM_TEST_ASSERT(elapsedTime > 0.499, "Timer did not capture full second wait.");
VTKM_TEST_ASSERT(elapsedTime < 1.0, "Timer counted too far or system really busy.");
}
@ -583,6 +606,9 @@ private:
VTKM_CONT
static void TestVirtualObjectTransfer()
{
std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing VirtualObjectTransfer" << std::endl;
using BaseType = typename VirtualObjectTransferKernel::Interface;
using TargetType = typename VirtualObjectTransferKernel::Concrete;
using Transfer = vtkm::cont::internal::VirtualObjectTransfer<TargetType, DeviceAdapterTag>;
@ -616,8 +642,11 @@ private:
static VTKM_CONT void TestAlgorithmSchedule()
{
std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing single value Scheduling with vtkm::Id" << std::endl;
{
// Allocating execution array
vtkm::cont::ArrayHandle<vtkm::Id> handle;
{
@ -641,6 +670,8 @@ private:
}
} //release memory
std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing Schedule with vtkm::Id" << std::endl;
{
vtkm::cont::ArrayHandle<vtkm::Id> handle;
@ -666,7 +697,11 @@ private:
}
} //release memory
std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing Schedule with a vary large Id value" << std::endl;
{
// Allocating execution array.
vtkm::cont::ArrayHandle<vtkm::Id> handle;
//size is selected to be larger than the CUDA backend can launch in a
@ -699,7 +734,11 @@ private:
} //release memory
//verify that the schedule call works with id3
std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing Schedule with vtkm::Id3" << std::endl;
{
std::cout << "Allocating execution array" << std::endl;
vtkm::cont::ArrayHandle<vtkm::Id> handle;
vtkm::Id3 maxRange(DIM_SIZE);
@ -729,6 +768,9 @@ private:
} //release memory
// Ensure that each element is only visited once:
std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing Schedule for overlap" << std::endl;
{
using BoolArray = ArrayHandle<bool>;
using BoolPortal = typename BoolArray::WritePortalType;
@ -736,6 +778,7 @@ private:
BoolArray valid;
// Initialize tracker with 'false' values
std::cout << "Allocating and initializing memory" << std::endl;
{
vtkm::cont::Token token;
Algorithm::Schedule(
@ -747,6 +790,7 @@ private:
ARRAY_SIZE);
}
std::cout << "Running Overlap kernel." << std::endl;
{
vtkm::cont::Token token;
Algorithm::Schedule(OverlapKernel(tracker.PrepareForInPlace(DeviceAdapterTag(), token),
@ -763,6 +807,8 @@ private:
} // release memory
// Ensure that each element is only visited once:
std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing Schedule for overlap with vtkm::Id3" << std::endl;
{
static constexpr vtkm::Id numElems{ DIM_SIZE * DIM_SIZE * DIM_SIZE };
@ -774,6 +820,7 @@ private:
BoolArray valid;
// Initialize tracker with 'false' values
std::cout << "Allocating and initializing memory" << std::endl;
{
vtkm::cont::Token token;
Algorithm::Schedule(
@ -786,6 +833,7 @@ private:
numElems);
}
std::cout << "Running Overlap kernel." << std::endl;
{
vtkm::cont::Token token;
Algorithm::Schedule(OverlapKernel(tracker.PrepareForInPlace(DeviceAdapterTag(), token),
@ -805,6 +853,9 @@ private:
static VTKM_CONT void TestCopyIf()
{
std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing CopyIf" << std::endl;
IdArrayHandle array;
IdArrayHandle stencil;
IdArrayHandle result;
@ -831,6 +882,7 @@ private:
VTKM_TEST_ASSERT(value == (OFFSET + (index * 2) + 1), "Incorrect value in CopyIf result.");
}
std::cout << " CopyIf on fancy arrays." << std::endl;
result.Allocate(0);
FloatCastHandle arrayCast(array);
FloatCastHandle resultCast(result);
@ -846,6 +898,7 @@ private:
VTKM_TEST_ASSERT(value == (OFFSET + (index * 2) + 1), "Incorrect value in CopyIf result.");
}
std::cout << " CopyIf on zero size arrays." << std::endl;
array.ReleaseResources();
stencil.ReleaseResources();
Algorithm::CopyIf(array, stencil, result);
@ -854,6 +907,8 @@ private:
static VTKM_CONT void TestOrderedUniqueValues()
{
std::cout << "-------------------------------------------------" << std::endl;
std::cout << "Testing Sort, Unique, LowerBounds and UpperBounds" << std::endl;
std::vector<vtkm::Id> testData(ARRAY_SIZE);
for (std::size_t i = 0; i < ARRAY_SIZE; ++i)
{
@ -893,6 +948,8 @@ private:
VTKM_TEST_ASSERT(value1 >= i % 50, "Got bad value (UpperBounds)");
}
std::cout << "Testing Sort/Unique/LowerBounds/UpperBounds with random values and fancy array"
<< std::endl;
//now test it works when the id are not incrementing
const vtkm::Id RANDOMDATA_SIZE = 6;
vtkm::Id randomData[RANDOMDATA_SIZE];
@ -943,6 +1000,8 @@ private:
static VTKM_CONT void TestSort()
{
std::cout << "-------------------------------------------------" << std::endl;
std::cout << "Sort" << std::endl;
std::vector<vtkm::Id> testData(ARRAY_SIZE);
for (std::size_t i = 0; i < ARRAY_SIZE; ++i)
{
@ -971,6 +1030,8 @@ private:
static VTKM_CONT void TestSortWithComparisonObject()
{
std::cout << "-------------------------------------------------" << std::endl;
std::cout << "Sort with comparison object" << std::endl;
std::vector<vtkm::Id> testData(ARRAY_SIZE);
for (std::size_t i = 0; i < ARRAY_SIZE; ++i)
{
@ -1010,6 +1071,9 @@ private:
static VTKM_CONT void TestSortWithFancyArrays()
{
std::cout << "-------------------------------------------------" << std::endl;
std::cout << "Sort of a ArrayHandleZip" << std::endl;
std::vector<vtkm::Id> testData(ARRAY_SIZE);
for (std::size_t i = 0; i < ARRAY_SIZE; ++i)
{
@ -1035,6 +1099,9 @@ private:
"ArrayZipHandle improperly sorted");
}
std::cout << "-------------------------------------------------" << std::endl;
std::cout << "Sort of a ArrayHandlePermutation" << std::endl;
//verify that we can use ArrayHandlePermutation inplace
vtkm::cont::ArrayHandleIndex index(ARRAY_SIZE);
vtkm::cont::ArrayHandlePermutation<vtkm::cont::ArrayHandleIndex, IdArrayHandle> perm(index,
@ -1063,6 +1130,9 @@ private:
static VTKM_CONT void TestSortByKey()
{
std::cout << "-------------------------------------------------" << std::endl;
std::cout << "Sort by keys" << std::endl;
using Vec3 = vtkm::Vec<FloatDefault, 3>;
using Vec3ArrayHandle = vtkm::cont::ArrayHandle<vtkm::Vec3f, StorageTag>;
@ -1128,6 +1198,8 @@ private:
static VTKM_CONT void TestLowerBoundsWithComparisonObject()
{
std::cout << "-------------------------------------------------" << std::endl;
std::cout << "Testing LowerBounds with comparison object" << std::endl;
std::vector<vtkm::Id> testData(ARRAY_SIZE);
for (std::size_t i = 0; i < ARRAY_SIZE; ++i)
{
@ -1162,6 +1234,8 @@ private:
static VTKM_CONT void TestUpperBoundsWithComparisonObject()
{
std::cout << "-------------------------------------------------" << std::endl;
std::cout << "Testing UpperBounds with comparison object" << std::endl;
std::vector<vtkm::Id> testData(ARRAY_SIZE);
for (std::size_t i = 0; i < ARRAY_SIZE; ++i)
{
@ -1197,6 +1271,8 @@ private:
static VTKM_CONT void TestUniqueWithComparisonObject()
{
std::cout << "-------------------------------------------------" << std::endl;
std::cout << "Testing Unique with comparison object" << std::endl;
IdArrayHandle input;
input.Allocate(ARRAY_SIZE);
{
@ -1223,6 +1299,9 @@ private:
static VTKM_CONT void TestReduce()
{
std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing Reduce" << std::endl;
//construct the index array
IdArrayHandle array;
{
@ -1233,11 +1312,16 @@ private:
}
//the output of reduce and scan inclusive should be the same
std::cout << " Reduce with initial value of 0." << std::endl;
vtkm::Id reduce_sum = Algorithm::Reduce(array, 0);
std::cout << " Reduce with initial value." << std::endl;
vtkm::Id reduce_sum_with_intial_value = Algorithm::Reduce(array, vtkm::Id(ARRAY_SIZE));
std::cout << " Inclusive scan to check" << std::endl;
vtkm::Id inclusive_sum = Algorithm::ScanInclusive(array, array);
std::cout << " Reduce with 1 value." << std::endl;
array.Allocate(1, vtkm::CopyFlag::On);
vtkm::Id reduce_sum_one_value = Algorithm::Reduce(array, 0);
std::cout << " Reduce with 0 values." << std::endl;
array.Allocate(0);
vtkm::Id reduce_sum_no_values = Algorithm::Reduce(array, 0);
VTKM_TEST_ASSERT(reduce_sum == OFFSET * ARRAY_SIZE, "Got bad sum from Reduce");
@ -1252,6 +1336,11 @@ private:
static VTKM_CONT void TestReduceWithComparisonObject()
{
std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing Reduce with comparison object " << std::endl;
std::cout << " Reduce vtkm::Id array with vtkm::MinAndMax to compute range." << std::endl;
//construct the index array. Assign an abnormally large value
//to the middle of the array, that should be what we see as our sum.
std::vector<vtkm::Id> testData(ARRAY_SIZE);
@ -1269,6 +1358,9 @@ private:
VTKM_TEST_ASSERT(maxValue == range[1], "Got bad value from Reduce with comparison object");
VTKM_TEST_ASSERT(0 == range[0], "Got bad value from Reduce with comparison object");
std::cout << " Reduce vtkm::Id array with custom functor that returns vtkm::Pair<>."
<< std::endl;
auto pairInit = vtkm::Pair<vtkm::Id, vtkm::Float32>(0, 0.0f);
vtkm::Pair<vtkm::Id, vtkm::Float32> pairRange =
Algorithm::Reduce(input, pairInit, CustomPairOp());
@ -1278,6 +1370,9 @@ private:
VTKM_TEST_ASSERT(0.0f == pairRange.second,
"Got bad value from Reduce with pair comparison object");
std::cout << " Reduce bool array with vtkm::LogicalAnd to see if all values are true."
<< std::endl;
//construct an array of bools and verify that they aren't all true
auto barray =
vtkm::cont::make_ArrayHandle({ true, true, true, true, true, true, false, true, true, true,
@ -1289,6 +1384,7 @@ private:
bool all_true = Algorithm::Reduce(barray, true, vtkm::LogicalAnd());
VTKM_TEST_ASSERT(all_true == false, "reduction with vtkm::LogicalAnd should return false");
std::cout << " Reduce with custom value type and custom comparison operator." << std::endl;
//test with a custom value type with the reduction value being a vtkm::Vec<float,2>
auto farray = vtkm::cont::make_ArrayHandle<CustomTForReduce>(
{ 13.1f, -2.1f, -1.0f, 13.1f, -2.1f, -1.0f, 413.1f, -2.1f, -1.0f, 13.1f, -2.1f, -1.0f,
@ -1305,6 +1401,8 @@ private:
static VTKM_CONT void TestReduceWithFancyArrays()
{
std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing Reduce with ArrayHandleZip" << std::endl;
{
IdArrayHandle keys, values;
@ -1332,6 +1430,8 @@ private:
"Got bad sum from Reduce with initial value");
}
std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing Reduce with ArrayHandlePermutation" << std::endl;
{
//lastly test with heterogeneous zip values ( vec3, and constant array handle),
//and a custom reduce binary functor
@ -1350,12 +1450,16 @@ private:
const ValueType sum = Algorithm::Reduce(perm, ValueType(0.0f));
std::cout << "sum: " << sum << std::endl;
VTKM_TEST_ASSERT((sum == expectedSum), "Got bad sum from Reduce with permutation handle");
}
}
static VTKM_CONT void TestReduceByKey()
{
std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing Reduce By Key" << std::endl;
//first test with very basic integer key / values
{
const vtkm::Id expectedLength = 6;
@ -1428,6 +1532,9 @@ private:
static VTKM_CONT void TestReduceByKeyWithFancyArrays()
{
std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing Reduce By Key with Fancy Arrays" << std::endl;
IdComponentArrayHandle keys =
vtkm::cont::make_ArrayHandle<vtkm::IdComponent>({ 0, 0, 0, 1, 1, 4, 0, 2, 2, 2, 2, -1 });
IdArrayHandle values =
@ -1461,6 +1568,8 @@ private:
static VTKM_CONT void TestScanInclusiveByKeyOne()
{
std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing Scan Inclusive By Key with 1 elements" << std::endl;
IdArrayHandle keys = vtkm::cont::make_ArrayHandle<vtkm::Id>({ 0 });
IdArrayHandle values = vtkm::cont::make_ArrayHandle<vtkm::Id>({ 5 });
@ -1476,6 +1585,9 @@ private:
static VTKM_CONT void TestScanInclusiveByKeyTwo()
{
std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing Scan Exclusive By Key with 2 elements" << std::endl;
IdArrayHandle keys = vtkm::cont::make_ArrayHandle<vtkm::Id>({ 0, 1 });
IdArrayHandle values = vtkm::cont::make_ArrayHandle<vtkm::Id>({ 1, 1 });
@ -1497,6 +1609,9 @@ private:
}
static VTKM_CONT void TestScanInclusiveByKeyLarge()
{
std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing Scan Inclusive By Key with " << ARRAY_SIZE << " elements" << std::endl;
std::vector<vtkm::Id> inputKeys(ARRAY_SIZE);
for (vtkm::Id i = 0; i < ARRAY_SIZE; i++)
@ -1535,6 +1650,9 @@ private:
}
static VTKM_CONT void TestScanInclusiveByKey()
{
std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing Scan Inclusive By Key" << std::endl;
IdComponentArrayHandle keys =
vtkm::cont::make_ArrayHandle<vtkm::IdComponent>({ 0, 0, 0, 1, 1, 2, 3, 3, 3, 3 });
IdArrayHandle values = vtkm::cont::make_ArrayHandle<vtkm::Id>({ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 });
@ -1556,6 +1674,10 @@ private:
}
static VTKM_CONT void TestScanInclusiveByKeyInPlace()
{
std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing Scan Inclusive By Key In Place" << std::endl;
IdComponentArrayHandle keys =
vtkm::cont::make_ArrayHandle<vtkm::IdComponent>({ 0, 0, 0, 1, 1, 2, 3, 3, 3, 3 });
IdArrayHandle values = vtkm::cont::make_ArrayHandle<vtkm::Id>({ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 });
@ -1575,6 +1697,10 @@ private:
}
static VTKM_CONT void TestScanInclusiveByKeyInPlaceWithFancyArray()
{
std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing Scan Inclusive By Key In Place with a Fancy Array" << std::endl;
IdComponentArrayHandle keys =
vtkm::cont::make_ArrayHandle<vtkm::IdComponent>({ 0, 0, 0, 1, 1, 2, 3, 3, 3, 3 });
IdArrayHandle values = vtkm::cont::make_ArrayHandle<vtkm::Id>({ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 });
@ -1596,6 +1722,9 @@ private:
static VTKM_CONT void TestScanExclusiveByKeyOne()
{
std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing Scan Exclusive By Key with 1 elements" << std::endl;
vtkm::Id init = 5;
const vtkm::Id expectedLength = 1;
@ -1615,6 +1744,9 @@ private:
static VTKM_CONT void TestScanExclusiveByKeyTwo()
{
std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing Scan Exclusive By Key with 2 elements" << std::endl;
vtkm::Id init = 5;
IdArrayHandle keys = vtkm::cont::make_ArrayHandle<vtkm::Id>({ 0, 1 });
@ -1639,6 +1771,9 @@ private:
static VTKM_CONT void TestScanExclusiveByKeyLarge()
{
std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing Scan Exclusive By Key with " << ARRAY_SIZE << " elements" << std::endl;
std::vector<vtkm::Id> inputKeys(ARRAY_SIZE);
for (std::size_t i = 0; i < ARRAY_SIZE; i++)
{
@ -1678,6 +1813,9 @@ private:
static VTKM_CONT void TestScanExclusiveByKey()
{
std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing Scan Exclusive By Key" << std::endl;
vtkm::Id init = 5;
IdComponentArrayHandle keys =
@ -1702,6 +1840,10 @@ private:
}
static VTKM_CONT void TestScanExclusiveByKeyInPlace()
{
std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing Scan Inclusive By Key In Place" << std::endl;
vtkm::Id init = 5;
IdComponentArrayHandle keys =
@ -1723,6 +1865,10 @@ private:
}
static VTKM_CONT void TestScanExclusiveByKeyInPlaceWithFancyArray()
{
std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing Scan Inclusive By Key In Place with a Fancy Array" << std::endl;
vtkm::FloatDefault init = 5;
IdComponentArrayHandle keys =
@ -1746,7 +1892,11 @@ private:
static VTKM_CONT void TestScanInclusive()
{
std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing Inclusive Scan" << std::endl;
{
std::cout << " size " << ARRAY_SIZE << std::endl;
//construct the index array
IdArrayHandle array;
{
@ -1768,17 +1918,21 @@ private:
VTKM_TEST_ASSERT(value == (i + 1) * OFFSET, "Incorrect partial sum");
}
std::cout << " size 1" << std::endl;
array.Allocate(1, vtkm::CopyFlag::On);
sum = Algorithm::ScanInclusive(array, array);
VTKM_TEST_ASSERT(sum == OFFSET, "Incorrect partial sum");
const vtkm::Id value = array.ReadPortal().Get(0);
VTKM_TEST_ASSERT(value == OFFSET, "Incorrect partial sum");
std::cout << " size 0" << std::endl;
array.Allocate(0);
sum = Algorithm::ScanInclusive(array, array);
VTKM_TEST_ASSERT(sum == 0, "Incorrect partial sum");
}
std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing Inclusive Scan with multiplication operator" << std::endl;
{
std::vector<vtkm::Float64> inputValues(ARRAY_SIZE);
for (std::size_t i = 0; i < ARRAY_SIZE; ++i)
@ -1810,6 +1964,9 @@ private:
}
}
std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing Inclusive Scan with a vtkm::Vec" << std::endl;
{
using Vec3 = vtkm::Vec<Float64, 3>;
using Vec3ArrayHandle = vtkm::cont::ArrayHandle<vtkm::Vec3f_64, StorageTag>;
@ -1823,6 +1980,7 @@ private:
Vec3ArrayHandle values = vtkm::cont::make_ArrayHandle(testValues, vtkm::CopyFlag::Off);
Vec3 sum = Algorithm::ScanInclusive(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 Inclusive Scan");
}
@ -1830,6 +1988,8 @@ private:
static VTKM_CONT void TestScanInclusiveWithComparisonObject()
{
std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing Inclusive Scan with comparison object " << std::endl;
//construct the index array
IdArrayHandle array;
@ -1874,6 +2034,9 @@ private:
static VTKM_CONT void TestScanExclusive()
{
std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing Exclusive Scan" << std::endl;
{
//construct the index array
IdArrayHandle array;
@ -1896,6 +2059,7 @@ private:
VTKM_TEST_ASSERT(value == i * OFFSET, "Incorrect partial sum");
}
std::cout << " size 1" << std::endl;
array.Allocate(1, vtkm::CopyFlag::On);
array.WritePortal().Set(0, OFFSET);
sum = Algorithm::ScanExclusive(array, array);
@ -1910,6 +2074,8 @@ private:
// Enable when Exclusive Scan with custom operator is implemented for all
// device adaptors
std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing Exclusive Scan with multiplication operator" << std::endl;
{
std::vector<vtkm::Float64> inputValues(ARRAY_SIZE);
for (std::size_t i = 0; i < ARRAY_SIZE; ++i)
@ -1945,6 +2111,9 @@ private:
}
}
std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing Exclusive Scan with a vtkm::Vec" << std::endl;
{
using Vec3 = vtkm::Vec<Float64, 3>;
using Vec3ArrayHandle = vtkm::cont::ArrayHandle<vtkm::Vec3f_64, StorageTag>;
@ -1965,6 +2134,8 @@ private:
static VTKM_CONT void TestScanExtended()
{
std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing Extended Scan" << std::endl;
{
@ -2000,6 +2171,7 @@ 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);
@ -2009,6 +2181,8 @@ private:
}
}
std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing Extended Scan with multiplication operator" << std::endl;
{
std::vector<vtkm::Float64> inputValues(ARRAY_SIZE);
for (std::size_t i = 0; i < ARRAY_SIZE; ++i)
@ -2046,6 +2220,9 @@ private:
}
}
std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing Extended Scan with a vtkm::Vec" << std::endl;
{
using Vec3 = vtkm::Vec3f_64;
using Vec3ArrayHandle = vtkm::cont::ArrayHandle<Vec3, StorageTag>;
@ -2067,6 +2244,10 @@ private:
static VTKM_CONT void TestErrorExecution()
{
std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing Exceptions in Execution Environment" << std::endl;
std::cout << "Generating one error." << std::endl;
std::string message;
try
{
@ -2075,10 +2256,12 @@ 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
{
@ -2087,11 +2270,14 @@ 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.");
// This is specifically to test the cuda-backend but should pass for all backends
// This is spcifically to test the cuda-backend but should pass for all backends
std::cout << "Testing if execution errors are eventually propagated to the host "
<< "without explicit synchronization\n";
message = "";
int nkernels = 0;
try
@ -2111,8 +2297,18 @@ private:
}
catch (vtkm::cont::ErrorExecution& error)
{
std::cout << "Got expected error: \"" << error.GetMessage() << "\" ";
if (nkernels < 100)
{
std::cout << "after " << nkernels << " invocations of other kernel" << std::endl;
}
else
{
std::cout << "only after explicit synchronization" << std::endl;
}
message = error.GetMessage();
}
std::cout << "\n";
VTKM_TEST_ASSERT(message == ERROR_MESSAGE, "Did not get expected error message.");
}
@ -2344,6 +2540,8 @@ private:
static VTKM_CONT void TestCopyArraysMany()
{
std::cout << "-------------------------------------------------" << std::endl;
std::cout << "Testing Copy to same array type" << std::endl;
TestCopyArrays<vtkm::Vec3f_32>();
TestCopyArrays<vtkm::Vec4ui_8>();
//
@ -2364,6 +2562,8 @@ private:
static VTKM_CONT void TestCopyArraysInDiffTypes()
{
std::cout << "-------------------------------------------------" << std::endl;
std::cout << "Testing Copy to a different array type" << std::endl;
std::vector<vtkm::Id> testData(ARRAY_SIZE);
for (std::size_t i = 0; i < ARRAY_SIZE; ++i)
{
@ -2395,8 +2595,10 @@ private:
{
atomicCount += i;
}
std::cout << "-------------------------------------------" << std::endl;
// To test the atomics, SHORT_ARRAY_SIZE number of threads will all increment
// a single atomic value.
std::cout << "Testing Atomic Add with vtkm::Int32" << std::endl;
{
vtkm::cont::ArrayHandle<vtkm::Int32> atomicElement =
vtkm::cont::make_ArrayHandle<vtkm::Int32>({ 0 });
@ -2411,6 +2613,7 @@ private:
VTKM_TEST_ASSERT(expected == actual, "Did not get expected value: Atomic add Int32");
}
std::cout << "Testing Atomic Add with vtkm::Int64" << std::endl;
{
vtkm::cont::ArrayHandle<vtkm::Int64> atomicElement =
vtkm::cont::make_ArrayHandle<vtkm::Int64>({ 0 });
@ -2425,6 +2628,7 @@ private:
VTKM_TEST_ASSERT(expected == actual, "Did not get expected value: Atomic add Int64");
}
std::cout << "Testing Atomic CAS with vtkm::Int32" << std::endl;
{
vtkm::cont::ArrayHandle<vtkm::Int32> atomicElement =
vtkm::cont::make_ArrayHandle<vtkm::Int32>({ 0 });
@ -2439,6 +2643,7 @@ private:
VTKM_TEST_ASSERT(expected == actual, "Did not get expected value: Atomic CAS Int32");
}
std::cout << "Testing Atomic CAS with vtkm::Int64" << std::endl;
{
vtkm::cont::ArrayHandle<vtkm::Int64> atomicElement =
vtkm::cont::make_ArrayHandle<vtkm::Int64>({ 0 });
@ -2499,6 +2704,9 @@ private:
};
auto testRepeatedMask = [&](WordType mask) {
std::cout << "Testing BitFieldToUnorderedSet with repeated 32-bit word 0x" << std::hex << mask
<< std::dec << std::endl;
BitField bits;
{
bits.Allocate(NumBits);
@ -2513,6 +2721,9 @@ private:
};
auto testRandomMask = [&](WordType seed) {
std::cout << "Testing BitFieldToUnorderedSet with random sequence seeded with 0x" << std::hex
<< seed << std::dec << std::endl;
std::mt19937 mt{ seed };
std::uniform_int_distribution<std::mt19937::result_type> rng;
@ -2583,6 +2794,9 @@ private:
};
auto testRepeatedMask = [&](WordType mask) {
std::cout << "Testing CountSetBits with repeated word 0x" << std::hex << mask << std::dec
<< std::endl;
BitField bits;
{
bits.Allocate(NumBits);
@ -2597,6 +2811,9 @@ private:
};
auto testRandomMask = [&](WordType seed) {
std::cout << "Testing CountSetBits with random sequence seeded with 0x" << std::hex << seed
<< std::dec << std::endl;
std::mt19937 mt{ seed };
std::uniform_int_distribution<std::mt19937::result_type> rng;
@ -2640,6 +2857,8 @@ private:
template <typename WordType>
static VTKM_CONT void TestFillBitFieldMask(WordType mask)
{
std::cout << "Testing Fill with " << (sizeof(WordType) * CHAR_BIT) << " bit mask: " << std::hex
<< vtkm::UInt64{ mask } << std::dec << std::endl;
// Test that everything works correctly with a partial word at the end.
static constexpr vtkm::Id BitsPerWord = static_cast<vtkm::Id>(sizeof(WordType) * CHAR_BIT);
@ -2705,6 +2924,7 @@ private:
static VTKM_CONT void TestFillBitFieldBool(bool value)
{
std::cout << "Testing Fill with bool: " << value << std::endl;
// Test that everything works correctly with a partial word at the end.
// +5 to get a partial word:
@ -2791,6 +3011,8 @@ private:
{
VTKM_CONT void operator()() const
{
std::cout << "Doing DeviceAdapter tests" << std::endl;
TestMemoryTransfer();
TestOutOfMemory();
TestTimer();

@ -78,6 +78,9 @@ struct TestObject
void TestBasicAttachDetatch()
{
std::cout << "Test basic attach detach." << std::endl;
std::cout << " Create objects" << std::endl;
TestObject object1;
TestObject object2;
TestObject object3;
@ -86,8 +89,10 @@ void TestBasicAttachDetatch()
CHECK_OBJECT(object2, 0, 1);
CHECK_OBJECT(object3, 0, 1);
std::cout << " Create outer token" << std::endl;
vtkm::cont::Token outerToken;
std::cout << " Attach outer token" << std::endl;
object1.Attach(outerToken);
object2.Attach(outerToken);
object3.Attach(outerToken);
@ -97,6 +102,7 @@ void TestBasicAttachDetatch()
CHECK_OBJECT(object3, 1, 2);
{
std::cout << " Create/Attach inner token" << std::endl;
vtkm::cont::Token innerToken;
object1.Attach(innerToken);
object2.Attach(innerToken);
@ -106,16 +112,20 @@ void TestBasicAttachDetatch()
CHECK_OBJECT(object2, 2, 3);
CHECK_OBJECT(object3, 2, 3);
std::cout << " Recursively attach outer token" << std::endl;
object1.Attach(outerToken);
CHECK_OBJECT(object1, 2, 3);
CHECK_OBJECT(object2, 2, 3);
CHECK_OBJECT(object3, 2, 3);
std::cout << " Detach from inner token (through scoping)" << std::endl;
}
CHECK_OBJECT(object1, 1, 2);
CHECK_OBJECT(object2, 1, 2);
CHECK_OBJECT(object3, 1, 2);
std::cout << " Detatch outer token" << std::endl;
outerToken.DetachFromAll();
CHECK_OBJECT(object1, 0, 1);
@ -127,10 +137,13 @@ void WaitForDetachment(TestObject* object)
{
std::unique_lock<std::mutex> lock(*object->Mutex);
object->ConditionVariable->wait(lock, [object] { return *object->TokenCount < 1; });
std::cout << " Thread woke up" << std::endl;
}
void TestThreadWake()
{
std::cout << "Testing thread wakeup" << std::endl;
TestObject object;
CHECK_OBJECT(object, 0, 1);
@ -138,17 +151,22 @@ void TestThreadWake()
object.Attach(token);
CHECK_OBJECT(object, 1, 2);
std::cout << " Launching coordinated thread" << std::endl;
auto future = std::async(std::launch::async, WaitForDetachment, &object);
// 100 milliseconds 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::milliseconds(100));
std::this_thread::sleep_for(std::chrono::milliseconds(500));
std::cout << " Main thread woke up. Detach token." << std::endl;
token.DetachFromAll();
std::cout << " Wait for thread to finish. Could deadlock if did not properly wake." << std::endl;
future.get();
std::cout << " Returned to main thread" << std::endl;
CHECK_OBJECT(object, 0, 1);
}