Repository navigation
fix(rccl): replace __hip_atomic builtins with Clang scoped atomics #11321
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
Changes from 4 commits
84dc12a
35f73af
f2c2901
8320c7c
f3e6526
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1209,6 +1209,23 @@ if(RCCL_ROCPROFILER_REGISTER) | |
| target_link_libraries( | ||
| rccl PRIVATE rocprofiler-register::rocprofiler-register) | ||
| endif() | ||
|
|
||
| # Poison the __hip_atomic_* builtins | ||
| #================================================================================================== | ||
| # RCCL spells device atomics with the Clang scoped-atomic builtins so that memory | ||
| # scope is explicit at every call site. Force-include (rather than #include) the | ||
| # poison header so it also covers hipified and generated sources, and set it here, | ||
| # before DeviceLinker.cmake snapshots COMPILE_OPTIONS, so the per-kernel device | ||
| # compiles inherit it too. See src/include/poison_hip_atomics.h for the coverage | ||
| # this does and does not give. | ||
| if(RCCL_POISON_HIP_ATOMICS) | ||
| # Joined --include=<file> rather than separate-argument -include <file>: the | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment says the joined form was needed because rccl-device-compile "would take the path for a source file", but the same PR adds explicit
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch -- the comment was stale the moment I added that branch. Kept the branch, rewrote the comment. It now states the actual reason: On the branch being unreachable, you are right that it is, from CMake's emission. I would rather keep it than delete it: a flag forwarder that silently turns Verified that |
||
| # flag has to survive rccl-device-compile, which forwards unrecognized tokens | ||
| # one at a time and would take the path for a source file. | ||
| target_compile_options(rccl PRIVATE --include=${RCCL_SOURCE_DIR}/src/include/poison_hip_atomics.h) | ||
|
alex-breslow-amd marked this conversation as resolved.
Resolved
|
||
| message(STATUS "RCCL_POISON_HIP_ATOMICS enabled - __hip_atomic_* builtins rejected in RCCL sources") | ||
| endif() | ||
|
|
||
| # Device Linker: include pipeline and wire up dependencies | ||
| # (placed after all target_compile_definitions so DeviceLinker.cmake | ||
| # can read the rccl target's definitions directly) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -288,8 +288,8 @@ class Primitives<T, RedOp, Fan, Direct, ProtoLL, P2p, isNetOffload, Metadata, Pi | |
| *((u64_gptr)dst->v + 1) = *((u64_gptr)i4.v + 1); | ||
| #else | ||
| #if defined(__gfx1200__) || defined(__gfx1201__) | ||
| __hip_atomic_store((u64_gptr)dst->v, i4.v[0], __ATOMIC_RELAXED, __HIP_MEMORY_SCOPE_SYSTEM); | ||
| __hip_atomic_store((u64_gptr)dst->v + 1, i4.v[1], __ATOMIC_RELEASE, __HIP_MEMORY_SCOPE_SYSTEM); | ||
| __scoped_atomic_store_n((u64_gptr)dst->v, i4.v[0], __ATOMIC_RELAXED, __MEMORY_SCOPE_SYSTEM); | ||
| __scoped_atomic_store_n((u64_gptr)dst->v + 1, i4.v[1], __ATOMIC_RELEASE, __MEMORY_SCOPE_SYSTEM); | ||
| #else | ||
| *((u64_gptr)dst->v) = *((u64_gptr)i4.v); | ||
| *((u64_gptr)dst->v + 1) = *((u64_gptr)i4.v + 1); | ||
|
|
@@ -322,16 +322,16 @@ class Primitives<T, RedOp, Fan, Direct, ProtoLL, P2p, isNetOffload, Metadata, Pi | |
| #if RCCL_HAVE_GLOBAL_DWORDX4_BUILTINS | ||
| if (sizeof(U) == 1) | ||
| u1 = | ||
| __hip_atomic_load((__attribute__((address_space(1))) uint8_t*)src, __ATOMIC_RELAXED, __HIP_MEMORY_SCOPE_SYSTEM); | ||
| __scoped_atomic_load_n((__attribute__((address_space(1))) uint8_t*)src, __ATOMIC_RELAXED, __MEMORY_SCOPE_SYSTEM); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line is now 121 columns against the Could we re-run clang-format over the changed files? Note .pre-commit-config.yaml:49 matches
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. Ran clang-format restricted to the ranges this PR changed, and the output matched your line list exactly: You were right about Two things I checked that are worth passing back:
To confirm the reformat was inert I compared whitespace-normalized text for all eight files against the previous revision (token-identical), then compiled real TUs with the poison active: |
||
| else if (sizeof(U) == 2) | ||
| u2 = __hip_atomic_load((__attribute__((address_space(1))) uint16_t*)src, __ATOMIC_RELAXED, | ||
| __HIP_MEMORY_SCOPE_SYSTEM); | ||
| u2 = __scoped_atomic_load_n((__attribute__((address_space(1))) uint16_t*)src, __ATOMIC_RELAXED, | ||
| __MEMORY_SCOPE_SYSTEM); | ||
| else if (sizeof(U) == 4) | ||
| u4 = __hip_atomic_load((__attribute__((address_space(1))) uint32_t*)src, __ATOMIC_RELAXED, | ||
| __HIP_MEMORY_SCOPE_SYSTEM); | ||
| u4 = __scoped_atomic_load_n((__attribute__((address_space(1))) uint32_t*)src, __ATOMIC_RELAXED, | ||
| __MEMORY_SCOPE_SYSTEM); | ||
| else | ||
| u8 = __hip_atomic_load((__attribute__((address_space(1))) uint64_t*)src, __ATOMIC_RELAXED, | ||
| __HIP_MEMORY_SCOPE_SYSTEM); | ||
| u8 = __scoped_atomic_load_n((__attribute__((address_space(1))) uint64_t*)src, __ATOMIC_RELAXED, | ||
| __MEMORY_SCOPE_SYSTEM); | ||
| #else | ||
| if (sizeof(U) == 1) | ||
| #ifdef __GFX11__ | ||
|
|
@@ -380,17 +380,17 @@ class Primitives<T, RedOp, Fan, Direct, ProtoLL, P2p, isNetOffload, Metadata, Pi | |
| #if defined(__HIP_PLATFORM_AMD__) || defined(__HIPCC__) | ||
| #if RCCL_HAVE_GLOBAL_DWORDX4_BUILTINS | ||
| if (sizeof(U) == 1) | ||
| __hip_atomic_store((__attribute__((address_space(1))) uint8_t*)dst, u1, __ATOMIC_RELAXED, | ||
| __HIP_MEMORY_SCOPE_SYSTEM); | ||
| __scoped_atomic_store_n((__attribute__((address_space(1))) uint8_t*)dst, u1, __ATOMIC_RELAXED, | ||
| __MEMORY_SCOPE_SYSTEM); | ||
| else if (sizeof(U) == 2) | ||
| __hip_atomic_store((__attribute__((address_space(1))) uint16_t*)dst, u2, __ATOMIC_RELAXED, | ||
| __HIP_MEMORY_SCOPE_SYSTEM); | ||
| __scoped_atomic_store_n((__attribute__((address_space(1))) uint16_t*)dst, u2, __ATOMIC_RELAXED, | ||
| __MEMORY_SCOPE_SYSTEM); | ||
| else if (sizeof(U) == 4) | ||
| __hip_atomic_store((__attribute__((address_space(1))) uint32_t*)dst, u4, __ATOMIC_RELAXED, | ||
| __HIP_MEMORY_SCOPE_SYSTEM); | ||
| __scoped_atomic_store_n((__attribute__((address_space(1))) uint32_t*)dst, u4, __ATOMIC_RELAXED, | ||
| __MEMORY_SCOPE_SYSTEM); | ||
| else | ||
| __hip_atomic_store((__attribute__((address_space(1))) uint64_t*)dst, u8, __ATOMIC_RELAXED, | ||
| __HIP_MEMORY_SCOPE_SYSTEM); | ||
| __scoped_atomic_store_n((__attribute__((address_space(1))) uint64_t*)dst, u8, __ATOMIC_RELAXED, | ||
| __MEMORY_SCOPE_SYSTEM); | ||
| #else | ||
| if (sizeof(U) == 1) __builtin_nontemporal_store(u1, (uint8_t*)dst); | ||
| else if (sizeof(U) == 2) __builtin_nontemporal_store(u2, (uint16_t*)dst); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.