Merge branch 'master' of https://gitlab.kitware.com/vtk/vtk-m into sl_comm_probe

This commit is contained in:
Dave Pugmire 2024-04-01 15:44:57 -04:00
commit c75dcace78
3 changed files with 102 additions and 54 deletions

@ -0,0 +1,3 @@
# AtomicArrayExecutionObject: Allow order of atomic operations
AtomicArrayExecutionObject now allows order of atomic operations for Get/Set/Add/CompareExchange.

@ -112,30 +112,34 @@ public:
/// \brief Perform an atomic load of the indexed element with acquire memory
/// ordering.
/// \param index The index of the element to load.
/// \param order The memory ordering to use for the load operation.
/// \return The value of the atomic array at \a index.
///
VTKM_SUPPRESS_EXEC_WARNINGS
VTKM_EXEC
ValueType Get(vtkm::Id index) const
ValueType Get(vtkm::Id index, vtkm::MemoryOrder order = vtkm::MemoryOrder::Acquire) const
{
// We only support 32/64 bit signed/unsigned ints, and vtkm::Atomic
// currently only provides API for unsigned types.
// We'll cast the signed types to unsigned to work around this.
using APIType = typename detail::MakeUnsigned<ValueType>::type;
return static_cast<T>(vtkm::AtomicLoad(reinterpret_cast<APIType*>(this->Data + index)));
return static_cast<T>(vtkm::AtomicLoad(reinterpret_cast<APIType*>(this->Data + index), order));
}
/// \brief Peform an atomic addition with sequentially consistent memory
/// ordering.
/// \param index The index of the array element that will be added to.
/// \param value The addend of the atomic add operation.
/// \param order The memory ordering to use for the add operation.
/// \return The original value of the element at \a index (before addition).
/// \warning Overflow behavior from this operation is undefined.
///
VTKM_SUPPRESS_EXEC_WARNINGS
VTKM_EXEC
ValueType Add(vtkm::Id index, const ValueType& value) const
ValueType Add(vtkm::Id index,
const ValueType& value,
vtkm::MemoryOrder order = vtkm::MemoryOrder::SequentiallyConsistent) const
{
// We only support 32/64 bit signed/unsigned ints, and vtkm::Atomic
// currently only provides API for unsigned types.
@ -145,14 +149,15 @@ public:
// document that overflow is undefined for this operation.
using APIType = typename detail::ArithType<ValueType>::type;
return static_cast<T>(
vtkm::AtomicAdd(reinterpret_cast<APIType*>(this->Data + index), static_cast<APIType>(value)));
return static_cast<T>(vtkm::AtomicAdd(
reinterpret_cast<APIType*>(this->Data + index), static_cast<APIType>(value), order));
}
/// \brief Peform an atomic store to memory while enforcing, at minimum, "release"
/// memory ordering.
/// \param index The index of the array element that will be added to.
/// \param value The value to write for the atomic store operation.
/// \param order The memory ordering to use for the store operation.
/// \warning Using something like:
/// ```
/// Set(index, Get(index)+N)
@ -162,7 +167,9 @@ public:
///
VTKM_SUPPRESS_EXEC_WARNINGS
VTKM_EXEC
void Set(vtkm::Id index, const ValueType& value) const
void Set(vtkm::Id index,
const ValueType& value,
vtkm::MemoryOrder order = vtkm::MemoryOrder::Release) const
{
// We only support 32/64 bit signed/unsigned ints, and vtkm::Atomic
// currently only provides API for unsigned types.
@ -172,7 +179,8 @@ public:
// document that overflow is undefined for this operation.
using APIType = typename detail::MakeUnsigned<ValueType>::type;
vtkm::AtomicStore(reinterpret_cast<APIType*>(this->Data + index), static_cast<APIType>(value));
vtkm::AtomicStore(
reinterpret_cast<APIType*>(this->Data + index), static_cast<APIType>(value), order);
}
/// \brief Perform an atomic compare and exchange operation with sequentially consistent
@ -181,6 +189,7 @@ public:
/// modified.
/// \param oldValue A pointer to the expected value of the indexed element.
/// \param newValue The value to replace the indexed element with.
/// \param order The memory ordering to use for the compare and exchange operation.
/// \return If the operation is successful, \a true is returned. Otherwise,
/// \a oldValue is replaced with the current value of the indexed element,
/// the element is not modified, and \a false is returned. In either case, \a oldValue
@ -220,7 +229,10 @@ public:
///
VTKM_SUPPRESS_EXEC_WARNINGS
VTKM_EXEC
bool CompareExchange(vtkm::Id index, ValueType* oldValue, const ValueType& newValue) const
bool CompareExchange(vtkm::Id index,
ValueType* oldValue,
const ValueType& newValue,
vtkm::MemoryOrder order = vtkm::MemoryOrder::SequentiallyConsistent) const
{
// We only support 32/64 bit signed/unsigned ints, and vtkm::Atomic
// currently only provides API for unsigned types.
@ -231,7 +243,8 @@ public:
return vtkm::AtomicCompareExchange(reinterpret_cast<APIType*>(this->Data + index),
reinterpret_cast<APIType*>(oldValue),
static_cast<APIType>(newValue));
static_cast<APIType>(newValue),
order);
}
private:

@ -89,26 +89,38 @@ public:
vtkm::Vec3f& parametric,
LastCell& lastCell) const
{
//See if point is inside the last cell.
vtkm::Vec3f pc;
if ((lastCell.CellId >= 0) && (lastCell.CellId < this->CellSet.GetNumberOfElements()) &&
this->PointInCell(point, lastCell.CellId, pc) == vtkm::ErrorCode::Success)
{
parametric = pc;
cellId = lastCell.CellId;
return vtkm::ErrorCode::Success;
}
vtkm::Id binIdx = this->FindBinIdx(point);
//See if it's in the last bin.
if ((lastCell.BinIdx >= 0) && (lastCell.BinIdx < this->CellIds.GetNumberOfValues()) &&
this->PointInBin(point, lastCell.BinIdx, cellId, pc) == vtkm::ErrorCode::Success)
if (binIdx == -1)
{
parametric = pc;
lastCell.CellId = cellId;
return vtkm::ErrorCode::Success;
lastCell.CellId = -1;
lastCell.BinIdx = -1;
cellId = -1;
return vtkm::ErrorCode::CellNotFound;
}
//See if the point is still in the same bin.
else if (binIdx == lastCell.BinIdx && this->LastCellValid(lastCell))
{
vtkm::Vec3f pc;
//Check the last cell first.
if (this->PointInCell(point, lastCell.CellId, pc))
{
parametric = pc;
cellId = lastCell.CellId;
return vtkm::ErrorCode::Success;
}
//Otherwise, check cells in the bin, but skip lastCell.CellId
else if (this->PointInBin(point, lastCell.BinIdx, cellId, pc, lastCell.CellId))
{
parametric = pc;
return vtkm::ErrorCode::Success;
}
}
//if cell still not found, drop to the general find cell below.
return this->FindCellImpl(point, cellId, parametric, lastCell);
//LastCell not initialized, or not in the same bin: do a full test.
//Since already computed the binIdx, re-use it.
return this->FindCellImpl(point, cellId, parametric, lastCell, binIdx);
}
VTKM_DEPRECATED(1.6, "Locators are no longer pointers. Use . operator.")
@ -117,6 +129,30 @@ public:
VTKM_EXEC const CellLocatorUniformBins* operator->() const { return this; }
private:
VTKM_EXEC vtkm::Id FindBinIdx(const vtkm::Vec3f& point) const
{
if (!this->IsInside(point))
return -1;
vtkm::Vec3f temp;
temp = point - this->Origin;
temp = temp * this->InvSpacing;
//make sure that if we border the upper edge, we sample the correct cell
vtkm::Id3 logicalCell = vtkm::Min(vtkm::Id3(temp), this->MaxCellIds);
vtkm::Id binIdx =
(logicalCell[2] * this->CellDims[1] + logicalCell[1]) * this->CellDims[0] + logicalCell[0];
return binIdx;
}
VTKM_EXEC bool LastCellValid(const LastCell& lastCell) const
{
return lastCell.BinIdx >= 0 && lastCell.BinIdx < this->CellIds.GetNumberOfValues() &&
lastCell.CellId >= 0 && lastCell.CellId < this->CellSet.GetNumberOfElements();
}
VTKM_EXEC bool IsInside(const vtkm::Vec3f& point) const
{
if (point[0] < this->Origin[0] || point[0] > this->MaxPoint[0])
@ -133,32 +169,29 @@ private:
vtkm::ErrorCode FindCellImpl(const vtkm::Vec3f& point,
vtkm::Id& cellId,
vtkm::Vec3f& parametric,
LastCell& lastCell) const
LastCell& lastCell,
vtkm::Id ptBinIdx = -1) const
{
lastCell.CellId = -1;
lastCell.BinIdx = -1;
if (!this->IsInside(point))
//if ptBinIdx is set, use it. Otherwise, compute the bin idx.
vtkm::Id binIdx = -1;
if (ptBinIdx == -1)
binIdx = this->FindBinIdx(point);
else
binIdx = ptBinIdx;
//point not in a bin. return not found.
if (binIdx == -1)
{
cellId = -1;
return vtkm::ErrorCode::CellNotFound;
}
//Find the bin containing the point.
vtkm::Id3 logicalCell(0, 0, 0);
vtkm::Vec3f temp;
temp = point - this->Origin;
temp = temp * this->InvSpacing;
//make sure that if we border the upper edge, we sample the correct cell
logicalCell = vtkm::Min(vtkm::Id3(temp), this->MaxCellIds);
vtkm::Id binIdx =
(logicalCell[2] * this->CellDims[1] + logicalCell[1]) * this->CellDims[0] + logicalCell[0];
//search cells in the bin.
vtkm::Vec3f pc;
if (this->PointInBin(point, binIdx, cellId, pc) == vtkm::ErrorCode::Success)
if (this->PointInBin(point, binIdx, cellId, pc))
{
parametric = pc;
lastCell.CellId = cellId;
@ -207,32 +240,31 @@ private:
}
VTKM_EXEC
vtkm::ErrorCode PointInBin(const vtkm::Vec3f& point,
const vtkm::Id& binIdx,
vtkm::Id& cellId,
vtkm::Vec3f& parametric) const
bool PointInBin(const vtkm::Vec3f& point,
const vtkm::Id& binIdx,
vtkm::Id& cellId,
vtkm::Vec3f& parametric,
const vtkm::Id& skipCellId = -1) const
{
auto binIds = this->CellIds.Get(binIdx);
vtkm::Vec3f pc;
for (vtkm::IdComponent i = 0; i < binIds.GetNumberOfComponents(); i++)
{
vtkm::Id cid = binIds[i];
vtkm::Vec3f pc;
if (this->PointInCell(point, cid, pc) == vtkm::ErrorCode::Success)
if (cid != skipCellId && this->PointInCell(point, cid, pc))
{
cellId = cid;
parametric = pc;
return vtkm::ErrorCode::Success;
return true;
}
}
return vtkm::ErrorCode::CellNotFound;
return false;
}
VTKM_EXEC
vtkm::ErrorCode PointInCell(const vtkm::Vec3f& point,
const vtkm::Id& cid,
vtkm::Vec3f& parametric) const
bool PointInCell(const vtkm::Vec3f& point, const vtkm::Id& cid, vtkm::Vec3f& parametric) const
{
auto indices = this->CellSet.GetIndices(cid);
auto pts = vtkm::make_VecFromPortalPermute(&indices, this->Coords);
@ -242,10 +274,10 @@ private:
if (status == vtkm::ErrorCode::Success && inside)
{
parametric = pc;
return vtkm::ErrorCode::Success;
return true;
}
return vtkm::ErrorCode::CellNotFound;
return false;
}
vtkm::Id3 CellDims;