Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix icpx atomic OpenMP methods #2213

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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