Skip to content

Commit

Permalink
fix icpx atomic OpenMP methods
Browse files Browse the repository at this point in the history
fix alpaka-group#2205

The compiler requires that the atomics are written in a very spezific
syntax else the code is not compiling.
  • Loading branch information
psychocoderHPC committed Dec 22, 2023
1 parent 1cdf4f9 commit 354bb2b
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions include/alpaka/atomic/AtomicOmpBuiltIn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,16 +179,20 @@ namespace alpaka
template<typename T, typename THierarchy>
struct AtomicOp<AtomicMin, AtomicOmpBuiltIn, T, THierarchy>
{
ALPAKA_FN_HOST static auto atomicOp(AtomicOmpBuiltIn const&, T* const addr, T const& value) -> T
ALPAKA_FN_HOST static auto atomicOp(AtomicOmpBuiltIn const&, T* const addr, T value) -> T
{
T old;
auto& ref(*addr);
// atomically update ref, but capture the original value in old
# pragma omp atomic capture compare
{
old = ref;
// Do not remove the curly brackets of the if body else
// icpx 2024.0 is not able to compile the atomics.
if(value < ref)
{
ref = value;
}
}
return old;
}
Expand All @@ -198,16 +202,20 @@ namespace alpaka
template<typename T, typename THierarchy>
struct AtomicOp<AtomicMax, AtomicOmpBuiltIn, T, THierarchy>
{
ALPAKA_FN_HOST static auto atomicOp(AtomicOmpBuiltIn const&, T* const addr, T const& value) -> T
ALPAKA_FN_HOST static auto atomicOp(AtomicOmpBuiltIn const&, T* const addr, T value) -> T
{
T old;
auto& ref(*addr);
// atomically update ref, but capture the original value in old
# pragma omp atomic capture compare
{
old = ref;
// Do not remove the curly brackets of the if body else
// icpx 2024.0 is not able to compile the atomics.
if(value > ref)
{
ref = value;
}
}
return old;
}
Expand Down Expand Up @@ -249,19 +257,20 @@ namespace alpaka
template<typename T, typename THierarchy>
struct AtomicOp<AtomicCas, AtomicOmpBuiltIn, T, THierarchy>
{
ALPAKA_FN_HOST static auto atomicOp(
AtomicOmpBuiltIn const&,
T* const addr,
T const& compare,
T const& value) -> T
ALPAKA_FN_HOST static auto atomicOp(AtomicOmpBuiltIn const&, T* const addr, T compare, T value) -> T
{
T old;
auto& ref(*addr);
// atomically update ref, but capture the original value in old
# pragma omp atomic capture compare
{
old = ref;
ref = (ref == compare ? value : ref);
// Do not remove the curly brackets of the if body else
// icpx 2024.0 is not able to compile the atomics.
if(ref == compare)
{
ref = value;
}
}
return old;
}
Expand Down

0 comments on commit 354bb2b

Please sign in to comment.