Skip to content

[SYCL] float atomic_ref performance fix #2714

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

Merged
Merged
Show file tree
Hide file tree
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
7 changes: 5 additions & 2 deletions sycl/include/CL/sycl/ONEAPI/atomic_ref.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,11 @@ class atomic_ref_impl<
T fetch_add(T operand, memory_order order = default_read_modify_write_order,
memory_scope scope = default_scope) const noexcept {
auto load_order = detail::getLoadOrder(order);
T expected = load(load_order, scope);
T expected;
T desired;
do {
expected =
load(load_order, scope); // performs better with load in CAS loop.
desired = expected + operand;
} while (!compare_exchange_weak(expected, desired, order, scope));
return expected;
Expand Down Expand Up @@ -563,9 +565,10 @@ class atomic_ref_impl<T *, DefaultOrder, DefaultScope, AddressSpace>
memory_scope scope = default_scope) const noexcept {
// TODO: Find a way to avoid compare_exchange here
auto load_order = detail::getLoadOrder(order);
T *expected = load(load_order, scope);
T *expected;
T *desired;
do {
expected = load(load_order, scope);
desired = expected + operand;
} while (!compare_exchange_weak(expected, desired, order, scope));
return expected;
Expand Down
3 changes: 1 addition & 2 deletions sycl/include/CL/sycl/atomic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,7 @@ class atomic {
Ptr);
cl_int TmpVal = __spirv_AtomicLoad(
TmpPtr, SpirvScope, detail::getSPIRVMemorySemanticsMask(Order));
cl_float ResVal;
detail::memcpy(&ResVal, &TmpVal, sizeof(TmpVal));
cl_float ResVal = detail::bit_cast<cl_float>(TmpVal);
return ResVal;
}
#else
Expand Down