Commit 7b5ad3e8 authored by Allison Vacanti's avatar Allison Vacanti
Browse files

Expand device scheduler test to check for overlap.

Add a test that fails if DeviceAdapterAlgorithm::Schedule
executes the same instance twice. Useful for checking block
scheduling algorithms.
parent e621b6ba
......@@ -111,23 +111,31 @@ public:
IdPortalType OutputArray;
};
struct ClearArrayKernel
template <typename PortalType>
struct GenericClearArrayKernel
{
using ValueType = typename PortalType::ValueType;
VTKM_CONT
ClearArrayKernel(const IdPortalType& array)
GenericClearArrayKernel(const PortalType& array,
const ValueType& fillValue = static_cast<ValueType>(OFFSET))
: Array(array)
, Dims()
, FillValue(fillValue)
{
}
VTKM_CONT
ClearArrayKernel(const IdPortalType& array, const vtkm::Id3& dims)
GenericClearArrayKernel(const PortalType& array,
const vtkm::Id3& dims,
const ValueType& fillValue = static_cast<ValueType>(OFFSET))
: Array(array)
, Dims(dims)
, FillValue(fillValue)
{
}
VTKM_EXEC void operator()(vtkm::Id index) const { this->Array.Set(index, OFFSET); }
VTKM_EXEC void operator()(vtkm::Id index) const { this->Array.Set(index, this->FillValue); }
VTKM_EXEC void operator()(vtkm::Id3 index) const
{
......@@ -138,10 +146,13 @@ public:
VTKM_CONT void SetErrorMessageBuffer(const vtkm::exec::internal::ErrorMessageBuffer&) {}
IdPortalType Array;
PortalType Array;
vtkm::Id3 Dims;
ValueType FillValue;
};
using ClearArrayKernel = GenericClearArrayKernel<IdPortalType>;
struct ClearArrayMapKernel //: public vtkm::exec::WorkletMapField
{
......@@ -189,6 +200,57 @@ public:
vtkm::Id3 Dims;
};
// Checks that each instance is only visited once:
struct OverlapKernel
{
using ArrayType = ArrayHandle<bool>;
using PortalType = typename ArrayType::template ExecutionTypes<DeviceAdapterTag>::Portal;
PortalType TrackerPortal;
PortalType ValidPortal;
vtkm::Id3 Dims;
VTKM_CONT
OverlapKernel(const PortalType& trackerPortal,
const PortalType& validPortal,
const vtkm::Id3& dims)
: TrackerPortal(trackerPortal)
, ValidPortal(validPortal)
, Dims(dims)
{
}
VTKM_CONT
OverlapKernel(const PortalType& trackerPortal, const PortalType& validPortal)
: TrackerPortal(trackerPortal)
, ValidPortal(validPortal)
, Dims()
{
}
VTKM_EXEC void operator()(vtkm::Id index) const
{
if (this->TrackerPortal.Get(index))
{ // this index has already been visited, that's an error
this->ValidPortal.Set(index, false);
}
else
{
this->TrackerPortal.Set(index, true);
this->ValidPortal.Set(index, true);
}
}
VTKM_EXEC void operator()(vtkm::Id3 index) const
{
//convert from id3 to id
vtkm::Id flatIndex = index[0] + this->Dims[0] * (index[1] + this->Dims[1] * index[2]);
this->operator()(flatIndex);
}
VTKM_CONT void SetErrorMessageBuffer(const vtkm::exec::internal::ErrorMessageBuffer&) {}
};
struct OneErrorKernel
{
VTKM_EXEC void operator()(vtkm::Id index) const
......@@ -634,6 +696,78 @@ private:
VTKM_TEST_ASSERT(value == index + OFFSET, "Got bad value for scheduled vtkm::Id3 kernels.");
}
} //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::template ExecutionTypes<DeviceAdapterTag>::Portal;
BoolArray tracker;
BoolArray valid;
// Initialize tracker with 'false' values
std::cout << "Allocating and initializing memory" << std::endl;
Algorithm::Schedule(GenericClearArrayKernel<BoolPortal>(
tracker.PrepareForOutput(ARRAY_SIZE, DeviceAdapterTag()), false),
ARRAY_SIZE);
Algorithm::Schedule(GenericClearArrayKernel<BoolPortal>(
valid.PrepareForOutput(ARRAY_SIZE, DeviceAdapterTag()), false),
ARRAY_SIZE);
std::cout << "Running Overlap kernel." << std::endl;
Algorithm::Schedule(OverlapKernel(tracker.PrepareForInPlace(DeviceAdapterTag()),
valid.PrepareForInPlace(DeviceAdapterTag())),
ARRAY_SIZE);
std::cout << "Checking results." << std::endl;
auto vPortal = valid.GetPortalConstControl();
for (vtkm::Id i = 0; i < ARRAY_SIZE; i++)
{
bool isValid = vPortal.Get(i);
VTKM_TEST_ASSERT(isValid, "Schedule executed some elements more than once.");
}
} // 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 };
static const vtkm::Id3 dims{ DIM_SIZE, DIM_SIZE, DIM_SIZE };
using BoolArray = ArrayHandle<bool>;
using BoolPortal = typename BoolArray::template ExecutionTypes<DeviceAdapterTag>::Portal;
BoolArray tracker;
BoolArray valid;
// Initialize tracker with 'false' values
std::cout << "Allocating and initializing memory" << std::endl;
Algorithm::Schedule(GenericClearArrayKernel<BoolPortal>(
tracker.PrepareForOutput(numElems, DeviceAdapterTag()), dims, false),
numElems);
Algorithm::Schedule(GenericClearArrayKernel<BoolPortal>(
valid.PrepareForOutput(numElems, DeviceAdapterTag()), dims, false),
numElems);
std::cout << "Running Overlap kernel." << std::endl;
Algorithm::Schedule(OverlapKernel(tracker.PrepareForInPlace(DeviceAdapterTag()),
valid.PrepareForInPlace(DeviceAdapterTag()),
dims),
dims);
std::cout << "Checking results." << std::endl;
auto vPortal = valid.GetPortalConstControl();
for (vtkm::Id i = 0; i < numElems; i++)
{
bool isValid = vPortal.Get(i);
VTKM_TEST_ASSERT(isValid, "Id3 Schedule executed some elements more than once.");
}
} // release memory
}
static VTKM_CONT void TestCopyIf()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment