mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-19 02:25:42 +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.
|
/// fit the number of elements we desire.
|
||||||
///
|
///
|
||||||
/// \par Requirements:
|
/// \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>
|
template <typename T, typename U, class CIn, class COut>
|
||||||
VTKM_CONT static bool CopySubRange(const vtkm::cont::ArrayHandle<T, CIn>& input,
|
VTKM_CONT static bool CopySubRange(const vtkm::cont::ArrayHandle<T, CIn>& input,
|
||||||
|
@ -805,6 +805,16 @@ public:
|
|||||||
vtkm::Id outputIndex = 0)
|
vtkm::Id outputIndex = 0)
|
||||||
{
|
{
|
||||||
const vtkm::Id inSize = input.GetNumberOfValues();
|
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 ||
|
if (inputStartIndex < 0 || numberOfElementsToCopy < 0 || outputIndex < 0 ||
|
||||||
inputStartIndex >= inSize)
|
inputStartIndex >= inSize)
|
||||||
{ //invalid parameters
|
{ //invalid parameters
|
||||||
|
@ -189,6 +189,16 @@ public:
|
|||||||
vtkm::Id outputIndex = 0)
|
vtkm::Id outputIndex = 0)
|
||||||
{
|
{
|
||||||
const vtkm::Id inSize = input.GetNumberOfValues();
|
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 ||
|
if (inputStartIndex < 0 || numberOfElementsToCopy < 0 || outputIndex < 0 ||
|
||||||
inputStartIndex >= inSize)
|
inputStartIndex >= inSize)
|
||||||
{ //invalid parameters
|
{ //invalid parameters
|
||||||
|
@ -108,6 +108,16 @@ public:
|
|||||||
vtkm::Id outputIndex = 0)
|
vtkm::Id outputIndex = 0)
|
||||||
{
|
{
|
||||||
const vtkm::Id inSize = input.GetNumberOfValues();
|
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 ||
|
if (inputStartIndex < 0 || numberOfElementsToCopy < 0 || outputIndex < 0 ||
|
||||||
inputStartIndex >= inSize)
|
inputStartIndex >= inSize)
|
||||||
{ //invalid parameters
|
{ //invalid parameters
|
||||||
|
@ -89,6 +89,16 @@ public:
|
|||||||
vtkm::Id outputIndex = 0)
|
vtkm::Id outputIndex = 0)
|
||||||
{
|
{
|
||||||
const vtkm::Id inSize = input.GetNumberOfValues();
|
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 ||
|
if (inputStartIndex < 0 || numberOfElementsToCopy < 0 || outputIndex < 0 ||
|
||||||
inputStartIndex >= inSize)
|
inputStartIndex >= inSize)
|
||||||
{ //invalid parameters
|
{ //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;
|
vtkm::cont::ArrayHandle<T> output;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user