Skip to content

Commit

Permalink
HIP: usa atomic load within atomicCas emulation
Browse files Browse the repository at this point in the history
  • Loading branch information
psychocoderHPC committed Jul 29, 2022
1 parent afb3376 commit 05b8a60
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions include/alpaka/atomic/AtomicUniformCudaHipBuiltIn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,21 @@ namespace alpaka
T* const addr,
T const& value) -> T
{
// Emulating atomics with atomicCAS is mentioned in the programming guide too.
// http://docs.nvidia.com/cuda/cuda-c-programming-guide/#atomic-functions
auto* const addressAsIntegralType = reinterpretAddress(addr);
using EmulatedType = ALPAKA_DECAY_T(decltype(*addressAsIntegralType));
EmulatedType old = *addressAsIntegralType;

// Emulating atomics with atomicCAS is mentioned in the programming guide too.
// http://docs.nvidia.com/cuda/cuda-c-programming-guide/#atomic-functions
# if BOOST_LANG_HIP
# if __has_builtin(__hip_atomic_load)
EmulatedType old{
__hip_atomic_load(addressAsIntegralType, __ATOMIC_RELAXED, __HIP_MEMORY_SCOPE_AGENT)};
# else
EmulatedType old{__atomic_load_n(addressAsIntegralType, __ATOMIC_RELAXED)};
# endif
# else
EmulatedType old{*addressAsIntegralType};
# endif
EmulatedType assumed;
do
{
Expand Down

0 comments on commit 05b8a60

Please sign in to comment.