VTK-m
2.1
|
#include <AtomicArrayExecutionObject.h>
Classes | |
struct | HasPointerAccess |
Public Types | |
using | ValueType = T |
Public Member Functions | |
AtomicArrayExecutionObject ()=default | |
AtomicArrayExecutionObject (vtkm::cont::ArrayHandle< T > handle, vtkm::cont::DeviceAdapterId device, vtkm::cont::Token &token) | |
vtkm::Id | GetNumberOfValues () const |
ValueType | Get (vtkm::Id index, vtkm::MemoryOrder order=vtkm::MemoryOrder::Acquire) const |
Perform an atomic load of the indexed element with acquire memory ordering. More... | |
ValueType | Add (vtkm::Id index, const ValueType &value, vtkm::MemoryOrder order=vtkm::MemoryOrder::SequentiallyConsistent) const |
Peform an atomic addition with sequentially consistent memory ordering. More... | |
void | Set (vtkm::Id index, const ValueType &value, vtkm::MemoryOrder order=vtkm::MemoryOrder::Release) const |
Peform an atomic store to memory while enforcing, at minimum, "release" memory ordering. More... | |
bool | CompareExchange (vtkm::Id index, ValueType *oldValue, const ValueType &newValue, vtkm::MemoryOrder order=vtkm::MemoryOrder::SequentiallyConsistent) const |
Perform an atomic compare and exchange operation with sequentially consistent memory ordering. More... | |
Private Attributes | |
ValueType * | Data { nullptr } |
vtkm::Id | NumberOfValues { 0 } |
using vtkm::exec::AtomicArrayExecutionObject< T >::ValueType = T |
|
default |
|
inline |
|
inline |
Peform an atomic addition with sequentially consistent memory ordering.
index | The index of the array element that will be added to. |
value | The addend of the atomic add operation. |
order | The memory ordering to use for the add operation. |
|
inline |
Perform an atomic compare and exchange operation with sequentially consistent memory ordering.
index | The index of the array element that will be atomically modified. |
oldValue | A pointer to the expected value of the indexed element. |
newValue | The value to replace the indexed element with. |
order | The memory ordering to use for the compare and exchange operation. |
This operation is typically used in a loop. For example usage, an atomic multiplication may be implemented using compare-exchange as follows:
The while condition here updates newVal what the proper multiplication is given the expected current value. It then compares this to the value in the array. If the values match, the operation was successful and the loop exits. If the values do not match, the value at idx was changed by another thread since the initial Get, and the compare-exchange operation failed – the target element was not modified by the compare-exchange call. If this happens, the loop body re-executes using the new value of current and tries again until it succeeds.
Note that for demonstration purposes, the previous code is unnecessarily verbose. We can express the same atomic operation more succinctly with just two lines where newVal is just computed in place.
|
inline |
Perform an atomic load of the indexed element with acquire memory ordering.
index | The index of the element to load. |
order | The memory ordering to use for the load operation. |
|
inline |
|
inline |
Peform an atomic store to memory while enforcing, at minimum, "release" memory ordering.
index | The index of the array element that will be added to. |
value | The value to write for the atomic store operation. |
order | The memory ordering to use for the store operation. |
Should not be done as it is not thread safe, instead you should use the provided Add method instead.
|
private |
|
private |