mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-16 17:22:55 +00:00
Check for overlap in CopySubRange.
Some parallel copy implementations will not handle this sanely.
This commit is contained in:
parent
374321e027
commit
1018d981a0
@ -108,7 +108,8 @@ struct DeviceAdapterAlgorithm
|
||||
/// fit the number of elements we desire.
|
||||
///
|
||||
/// \par Requirements:
|
||||
/// \arg \c input must already be sorted
|
||||
/// \arg If \c input and \c output share memory, the input and output ranges
|
||||
/// must not overlap.
|
||||
///
|
||||
template <typename T, typename U, class CIn, class COut>
|
||||
VTKM_CONT static bool CopySubRange(const vtkm::cont::ArrayHandle<T, CIn>& input,
|
||||
|
@ -805,6 +805,16 @@ public:
|
||||
vtkm::Id outputIndex = 0)
|
||||
{
|
||||
const vtkm::Id inSize = input.GetNumberOfValues();
|
||||
|
||||
// Check if the ranges overlap and fail if they do.
|
||||
if (input == output && ((outputIndex >= inputStartIndex &&
|
||||
outputIndex < inputStartIndex + numberOfElementsToCopy) ||
|
||||
(inputStartIndex >= outputIndex &&
|
||||
inputStartIndex < outputIndex + numberOfElementsToCopy)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (inputStartIndex < 0 || numberOfElementsToCopy < 0 || outputIndex < 0 ||
|
||||
inputStartIndex >= inSize)
|
||||
{ //invalid parameters
|
||||
|
@ -189,6 +189,16 @@ public:
|
||||
vtkm::Id outputIndex = 0)
|
||||
{
|
||||
const vtkm::Id inSize = input.GetNumberOfValues();
|
||||
|
||||
// Check if the ranges overlap and fail if they do.
|
||||
if (input == output && ((outputIndex >= inputStartIndex &&
|
||||
outputIndex < inputStartIndex + numberOfElementsToCopy) ||
|
||||
(inputStartIndex >= outputIndex &&
|
||||
inputStartIndex < outputIndex + numberOfElementsToCopy)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (inputStartIndex < 0 || numberOfElementsToCopy < 0 || outputIndex < 0 ||
|
||||
inputStartIndex >= inSize)
|
||||
{ //invalid parameters
|
||||
|
@ -108,6 +108,16 @@ public:
|
||||
vtkm::Id outputIndex = 0)
|
||||
{
|
||||
const vtkm::Id inSize = input.GetNumberOfValues();
|
||||
|
||||
// Check if the ranges overlap and fail if they do.
|
||||
if (input == output && ((outputIndex >= inputStartIndex &&
|
||||
outputIndex < inputStartIndex + numberOfElementsToCopy) ||
|
||||
(inputStartIndex >= outputIndex &&
|
||||
inputStartIndex < outputIndex + numberOfElementsToCopy)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (inputStartIndex < 0 || numberOfElementsToCopy < 0 || outputIndex < 0 ||
|
||||
inputStartIndex >= inSize)
|
||||
{ //invalid parameters
|
||||
|
@ -89,6 +89,16 @@ public:
|
||||
vtkm::Id outputIndex = 0)
|
||||
{
|
||||
const vtkm::Id inSize = input.GetNumberOfValues();
|
||||
|
||||
// Check if the ranges overlap and fail if they do.
|
||||
if (input == output && ((outputIndex >= inputStartIndex &&
|
||||
outputIndex < inputStartIndex + numberOfElementsToCopy) ||
|
||||
(inputStartIndex >= outputIndex &&
|
||||
inputStartIndex < outputIndex + numberOfElementsToCopy)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (inputStartIndex < 0 || numberOfElementsToCopy < 0 || outputIndex < 0 ||
|
||||
inputStartIndex >= inSize)
|
||||
{ //invalid parameters
|
||||
|
@ -1967,6 +1967,29 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
// 7. Test that overlapping ranges trigger a failure:
|
||||
// 7.1 output starts inside input range:
|
||||
{
|
||||
const vtkm::Id inBegin = 100;
|
||||
const vtkm::Id inEnd = 200;
|
||||
const vtkm::Id outBegin = 150;
|
||||
|
||||
const vtkm::Id numVals = inEnd - inBegin;
|
||||
bool result = Algorithm::CopySubRange(input, inBegin, numVals, input, outBegin);
|
||||
VTKM_TEST_ASSERT(result == false, "Overlapping subrange did not fail.");
|
||||
}
|
||||
|
||||
// 7.2 input starts inside output range
|
||||
{
|
||||
const vtkm::Id inBegin = 100;
|
||||
const vtkm::Id inEnd = 200;
|
||||
const vtkm::Id outBegin = 50;
|
||||
|
||||
const vtkm::Id numVals = inEnd - inBegin;
|
||||
bool result = Algorithm::CopySubRange(input, inBegin, numVals, input, outBegin);
|
||||
VTKM_TEST_ASSERT(result == false, "Overlapping subrange did not fail.");
|
||||
}
|
||||
|
||||
{
|
||||
vtkm::cont::ArrayHandle<T> output;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user