From 2224ca7a4d83600febec8bbfd5e7890c985d66a3 Mon Sep 17 00:00:00 2001 From: Mikhail Kuznetsov Date: Tue, 20 Oct 2026 11:50:45 +0200 Subject: [PATCH 1/6] fix(rccl): build the RMSNorm kernel fusion examples on ROCm The 07_kernel_fusion examples came in with NCCL 2.30.7 but their Makefiles still included the upstream NVIDIA build rules, which resolve outside the repo and compile .cu with nvcc. Point them at rccl_examples.mk, which hipifies the unmodified upstream main.cu at build time, as 06_device_api already does. rmsnorm_utils.cuh includes , so add a rule that hipifies .cuh headers into HIPIFY_DIR as well; the hipified main.cu finds that copy first through its quoted include. Ignore the built example binaries. Co-authored-by: Cursor --- projects/rccl/examples/.gitignore | 4 ++++ .../01_rmsnorm_lsa/c/Makefile | 22 +++++++++---------- .../02_rmsnorm_multimem/c/Makefile | 22 +++++++++---------- .../03_rmsnorm_gin/c/Makefile | 22 +++++++++---------- .../04_rmsnorm_hybrid/c/Makefile | 22 +++++++++---------- .../rccl/examples/makefiles/rccl_examples.mk | 9 +++++++- 6 files changed, 56 insertions(+), 45 deletions(-) diff --git a/projects/rccl/examples/.gitignore b/projects/rccl/examples/.gitignore index fd8bc52c2e07..8aa2e7e14935 100644 --- a/projects/rccl/examples/.gitignore +++ b/projects/rccl/examples/.gitignore @@ -16,3 +16,7 @@ 06_device_api/01_allreduce_lsa/c/allreduce_lsa 06_device_api/02_alltoall_gin/c/alltoall_gin 06_device_api/03_alltoall_hybrid/c/alltoall_hybrid +07_kernel_fusion/01_rmsnorm_lsa/c/rmsnorm_lsa +07_kernel_fusion/02_rmsnorm_multimem/c/rmsnorm_multimem +07_kernel_fusion/03_rmsnorm_gin/c/rmsnorm_gin +07_kernel_fusion/04_rmsnorm_hybrid/c/rmsnorm_hybrid diff --git a/projects/rccl/examples/07_kernel_fusion/01_rmsnorm_lsa/c/Makefile b/projects/rccl/examples/07_kernel_fusion/01_rmsnorm_lsa/c/Makefile index 0a62f3b9c695..5804887fa0d5 100644 --- a/projects/rccl/examples/07_kernel_fusion/01_rmsnorm_lsa/c/Makefile +++ b/projects/rccl/examples/07_kernel_fusion/01_rmsnorm_lsa/c/Makefile @@ -6,8 +6,7 @@ # # Include common build rules -include ../../../../../makefiles/common.mk -include ../../../../../makefiles/examples.mk +include ../../../makefiles/rccl_examples.mk # Target executable TARGET = rmsnorm_lsa @@ -20,18 +19,20 @@ RMSNORM_INC = ../../include # Build configuration INCLUDES += -I$(COMMON_INC) -I$(RMSNORM_INC) -# Source files +# Source files (.cu is hipified into $(HIPIFY_DIR) at build time) SOURCES = main.cu utils.cc # utils.cc is a shared helper in common/src, compiled per-example into a local # utils.o so parallel example builds do not race on one shared object. # vpath NAME DIR tells make to search DIR for the prerequisite NAME, so the # %.o: %.cc rule below finds utils.cc in $(COMMON_SRC) and builds a local utils.o. vpath utils.cc $(COMMON_SRC) -OBJECTS = $(SOURCES:.cu=.o) -OBJECTS := $(OBJECTS:.cc=.o) +OBJECTS = $(patsubst %.cu,$(HIPIFY_DIR)/%.cu.o,$(filter %.cu,$(SOURCES))) \ + $(patsubst %.cc,%.o,$(filter %.cc,$(SOURCES))) -# Header dependencies (rmsnorm_utils.cuh needed for main.cu) -CU_HEADERS = $(RMSNORM_INC)/rmsnorm_utils.cuh +# Header dependencies (rmsnorm_utils.cuh needed for main.cu). It includes +# , so main.cu compiles against its hipified copy. +vpath rmsnorm_utils.cuh $(RMSNORM_INC) +CU_HEADERS = $(HIPIFY_DIR)/rmsnorm_utils.cuh # Default target all: $(TARGET) @@ -45,9 +46,8 @@ else endif @echo "Built target $@" -# Compile CUDA files with rmsnorm header dependency -%.o: %.cu $(CU_HEADERS) - $(NVCC) $(NVCUFLAGS) $(INCLUDES) -c $< -o $@ +# Compile the hipified main.cu against the hipified rmsnorm header +$(HIPIFY_DIR)/main.cu.o: $(CU_HEADERS) # Compile C++ files %.o: %.cc @@ -70,7 +70,7 @@ endif # Clean build artifacts clean: - rm -f $(OBJECTS) $(TARGET) + rm -rf $(OBJECTS) $(TARGET) $(HIPIFY_DIR) # Install target install: $(TARGET) diff --git a/projects/rccl/examples/07_kernel_fusion/02_rmsnorm_multimem/c/Makefile b/projects/rccl/examples/07_kernel_fusion/02_rmsnorm_multimem/c/Makefile index b96a1acfe152..8fff14c3fc13 100644 --- a/projects/rccl/examples/07_kernel_fusion/02_rmsnorm_multimem/c/Makefile +++ b/projects/rccl/examples/07_kernel_fusion/02_rmsnorm_multimem/c/Makefile @@ -6,8 +6,7 @@ # # Include common build rules -include ../../../../../makefiles/common.mk -include ../../../../../makefiles/examples.mk +include ../../../makefiles/rccl_examples.mk # Target executable TARGET = rmsnorm_multimem @@ -20,18 +19,20 @@ RMSNORM_INC = ../../include # Build configuration INCLUDES += -I$(COMMON_INC) -I$(RMSNORM_INC) -# Source files +# Source files (.cu is hipified into $(HIPIFY_DIR) at build time) SOURCES = main.cu utils.cc # utils.cc is a shared helper in common/src, compiled per-example into a local # utils.o so parallel example builds do not race on one shared object. # vpath NAME DIR tells make to search DIR for the prerequisite NAME, so the # %.o: %.cc rule below finds utils.cc in $(COMMON_SRC) and builds a local utils.o. vpath utils.cc $(COMMON_SRC) -OBJECTS = $(SOURCES:.cu=.o) -OBJECTS := $(OBJECTS:.cc=.o) +OBJECTS = $(patsubst %.cu,$(HIPIFY_DIR)/%.cu.o,$(filter %.cu,$(SOURCES))) \ + $(patsubst %.cc,%.o,$(filter %.cc,$(SOURCES))) -# Header dependencies (rmsnorm_utils.cuh needed for main.cu) -CU_HEADERS = $(RMSNORM_INC)/rmsnorm_utils.cuh +# Header dependencies (rmsnorm_utils.cuh needed for main.cu). It includes +# , so main.cu compiles against its hipified copy. +vpath rmsnorm_utils.cuh $(RMSNORM_INC) +CU_HEADERS = $(HIPIFY_DIR)/rmsnorm_utils.cuh # Default target all: $(TARGET) @@ -45,9 +46,8 @@ else endif @echo "Built target $@" -# Compile CUDA files with rmsnorm header dependency -%.o: %.cu $(CU_HEADERS) - $(NVCC) $(NVCUFLAGS) $(INCLUDES) -c $< -o $@ +# Compile the hipified main.cu against the hipified rmsnorm header +$(HIPIFY_DIR)/main.cu.o: $(CU_HEADERS) # Compile C++ files %.o: %.cc @@ -70,7 +70,7 @@ endif # Clean build artifacts clean: - rm -f $(OBJECTS) $(TARGET) + rm -rf $(OBJECTS) $(TARGET) $(HIPIFY_DIR) # Install target install: $(TARGET) diff --git a/projects/rccl/examples/07_kernel_fusion/03_rmsnorm_gin/c/Makefile b/projects/rccl/examples/07_kernel_fusion/03_rmsnorm_gin/c/Makefile index f47ade6343d1..80a5633637d7 100644 --- a/projects/rccl/examples/07_kernel_fusion/03_rmsnorm_gin/c/Makefile +++ b/projects/rccl/examples/07_kernel_fusion/03_rmsnorm_gin/c/Makefile @@ -6,8 +6,7 @@ # # Include common build rules -include ../../../../../makefiles/common.mk -include ../../../../../makefiles/examples.mk +include ../../../makefiles/rccl_examples.mk # Target executable TARGET = rmsnorm_gin @@ -20,18 +19,20 @@ RMSNORM_INC = ../../include # Build configuration INCLUDES += -I$(COMMON_INC) -I$(RMSNORM_INC) -# Source files +# Source files (.cu is hipified into $(HIPIFY_DIR) at build time) SOURCES = main.cu utils.cc # utils.cc is a shared helper in common/src, compiled per-example into a local # utils.o so parallel example builds do not race on one shared object. # vpath NAME DIR tells make to search DIR for the prerequisite NAME, so the # %.o: %.cc rule below finds utils.cc in $(COMMON_SRC) and builds a local utils.o. vpath utils.cc $(COMMON_SRC) -OBJECTS = $(SOURCES:.cu=.o) -OBJECTS := $(OBJECTS:.cc=.o) +OBJECTS = $(patsubst %.cu,$(HIPIFY_DIR)/%.cu.o,$(filter %.cu,$(SOURCES))) \ + $(patsubst %.cc,%.o,$(filter %.cc,$(SOURCES))) -# Header dependencies (rmsnorm_utils.cuh needed for main.cu) -CU_HEADERS = $(RMSNORM_INC)/rmsnorm_utils.cuh +# Header dependencies (rmsnorm_utils.cuh needed for main.cu). It includes +# , so main.cu compiles against its hipified copy. +vpath rmsnorm_utils.cuh $(RMSNORM_INC) +CU_HEADERS = $(HIPIFY_DIR)/rmsnorm_utils.cuh # Default target all: $(TARGET) @@ -45,9 +46,8 @@ else endif @echo "Built target $@" -# Compile CUDA files with rmsnorm header dependency -%.o: %.cu $(CU_HEADERS) - $(NVCC) $(NVCUFLAGS) $(INCLUDES) -c $< -o $@ +# Compile the hipified main.cu against the hipified rmsnorm header +$(HIPIFY_DIR)/main.cu.o: $(CU_HEADERS) # Compile C++ files %.o: %.cc @@ -70,7 +70,7 @@ endif # Clean build artifacts clean: - rm -f $(OBJECTS) $(TARGET) + rm -rf $(OBJECTS) $(TARGET) $(HIPIFY_DIR) # Install target install: $(TARGET) diff --git a/projects/rccl/examples/07_kernel_fusion/04_rmsnorm_hybrid/c/Makefile b/projects/rccl/examples/07_kernel_fusion/04_rmsnorm_hybrid/c/Makefile index 5ed8d5baf3b1..1716ced2da29 100644 --- a/projects/rccl/examples/07_kernel_fusion/04_rmsnorm_hybrid/c/Makefile +++ b/projects/rccl/examples/07_kernel_fusion/04_rmsnorm_hybrid/c/Makefile @@ -6,8 +6,7 @@ # # Include common build rules -include ../../../../../makefiles/common.mk -include ../../../../../makefiles/examples.mk +include ../../../makefiles/rccl_examples.mk # Target executable TARGET = rmsnorm_hybrid @@ -20,18 +19,20 @@ RMSNORM_INC = ../../include # Build configuration INCLUDES += -I$(COMMON_INC) -I$(RMSNORM_INC) -# Source files +# Source files (.cu is hipified into $(HIPIFY_DIR) at build time) SOURCES = main.cu utils.cc # utils.cc is a shared helper in common/src, compiled per-example into a local # utils.o so parallel example builds do not race on one shared object. # vpath NAME DIR tells make to search DIR for the prerequisite NAME, so the # %.o: %.cc rule below finds utils.cc in $(COMMON_SRC) and builds a local utils.o. vpath utils.cc $(COMMON_SRC) -OBJECTS = $(SOURCES:.cu=.o) -OBJECTS := $(OBJECTS:.cc=.o) +OBJECTS = $(patsubst %.cu,$(HIPIFY_DIR)/%.cu.o,$(filter %.cu,$(SOURCES))) \ + $(patsubst %.cc,%.o,$(filter %.cc,$(SOURCES))) -# Header dependencies (rmsnorm_utils.cuh needed for main.cu) -CU_HEADERS = $(RMSNORM_INC)/rmsnorm_utils.cuh +# Header dependencies (rmsnorm_utils.cuh needed for main.cu). It includes +# , so main.cu compiles against its hipified copy. +vpath rmsnorm_utils.cuh $(RMSNORM_INC) +CU_HEADERS = $(HIPIFY_DIR)/rmsnorm_utils.cuh # Default target all: $(TARGET) @@ -45,9 +46,8 @@ else endif @echo "Built target $@" -# Compile CUDA files with rmsnorm header dependency -%.o: %.cu $(CU_HEADERS) - $(NVCC) $(NVCUFLAGS) $(INCLUDES) -c $< -o $@ +# Compile the hipified main.cu against the hipified rmsnorm header +$(HIPIFY_DIR)/main.cu.o: $(CU_HEADERS) # Compile C++ files %.o: %.cc @@ -70,7 +70,7 @@ endif # Clean build artifacts clean: - rm -f $(OBJECTS) $(TARGET) + rm -rf $(OBJECTS) $(TARGET) $(HIPIFY_DIR) # Install target install: $(TARGET) diff --git a/projects/rccl/examples/makefiles/rccl_examples.mk b/projects/rccl/examples/makefiles/rccl_examples.mk index e3d2fce1b078..f1425fd9a710 100644 --- a/projects/rccl/examples/makefiles/rccl_examples.mk +++ b/projects/rccl/examples/makefiles/rccl_examples.mk @@ -61,5 +61,12 @@ else $(CXX) $(CXXFLAGS) -x hip $(INCLUDES) -c $< -o $@ endif +# Upstream .cuh headers are hipified into HIPIFY_DIR too. A quoted #include in a +# hipified source searches HIPIFY_DIR first, so it picks up the HIP copy rather +# than the CUDA original. Point vpath at the header's directory to use this rule. +$(HIPIFY_DIR)/%.cuh: %.cuh + @mkdir -p $(dir $@) + $(HIPIFY) -experimental -quiet-warnings $< -o $@.tmp && mv -f $@.tmp $@ + # Keep the hipified source so it is not deleted as a make intermediate. -.PRECIOUS: $(HIPIFY_DIR)/%.cu.cpp +.PRECIOUS: $(HIPIFY_DIR)/%.cu.cpp $(HIPIFY_DIR)/%.cuh From cb25dbc19f12a70e6f8c55665d9ab5b9837249c4 Mon Sep 17 00:00:00 2001 From: Mikhail Kuznetsov Date: Tue, 20 Oct 2026 12:26:21 +0200 Subject: [PATCH 2/6] docs(rccl): use ROCm build variables in the RMSNorm example READMEs Co-authored-by: Cursor --- .../rccl/examples/07_kernel_fusion/01_rmsnorm_lsa/c/README.md | 2 +- .../examples/07_kernel_fusion/02_rmsnorm_multimem/c/README.md | 2 +- .../rccl/examples/07_kernel_fusion/03_rmsnorm_gin/c/README.md | 2 +- .../examples/07_kernel_fusion/04_rmsnorm_hybrid/c/README.md | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/projects/rccl/examples/07_kernel_fusion/01_rmsnorm_lsa/c/README.md b/projects/rccl/examples/07_kernel_fusion/01_rmsnorm_lsa/c/README.md index 12cb1b45e290..0f38d1d89db2 100644 --- a/projects/rccl/examples/07_kernel_fusion/01_rmsnorm_lsa/c/README.md +++ b/projects/rccl/examples/07_kernel_fusion/01_rmsnorm_lsa/c/README.md @@ -16,7 +16,7 @@ operation within a single GPU kernel. From this directory: ```shell -make [MPI=1] [MPI_HOME=] [NCCL_HOME=] [CUDA_HOME=] +make [MPI=1] [MPI_HOME=] [RCCL_HOME=] [ROCM_PATH=] [GPU_TARGETS=" ..."] ``` ## Run diff --git a/projects/rccl/examples/07_kernel_fusion/02_rmsnorm_multimem/c/README.md b/projects/rccl/examples/07_kernel_fusion/02_rmsnorm_multimem/c/README.md index cdea11b1aae1..e8115f72c137 100644 --- a/projects/rccl/examples/07_kernel_fusion/02_rmsnorm_multimem/c/README.md +++ b/projects/rccl/examples/07_kernel_fusion/02_rmsnorm_multimem/c/README.md @@ -15,7 +15,7 @@ API (hardware multicast memory operations, SM 9.0+). From this directory: ```shell -make [MPI=1] [MPI_HOME=] [NCCL_HOME=] [CUDA_HOME=] +make [MPI=1] [MPI_HOME=] [RCCL_HOME=] [ROCM_PATH=] [GPU_TARGETS=" ..."] ``` ## Run diff --git a/projects/rccl/examples/07_kernel_fusion/03_rmsnorm_gin/c/README.md b/projects/rccl/examples/07_kernel_fusion/03_rmsnorm_gin/c/README.md index 29ab81f99bb0..a778166ca2fe 100644 --- a/projects/rccl/examples/07_kernel_fusion/03_rmsnorm_gin/c/README.md +++ b/projects/rccl/examples/07_kernel_fusion/03_rmsnorm_gin/c/README.md @@ -16,7 +16,7 @@ operation within a single GPU kernel. From this directory: ```shell -make [MPI=1] [MPI_HOME=] [NCCL_HOME=] [CUDA_HOME=] +make [MPI=1] [MPI_HOME=] [RCCL_HOME=] [ROCM_PATH=] [GPU_TARGETS=" ..."] ``` ## Run diff --git a/projects/rccl/examples/07_kernel_fusion/04_rmsnorm_hybrid/c/README.md b/projects/rccl/examples/07_kernel_fusion/04_rmsnorm_hybrid/c/README.md index 27438b673b18..c12d046afad7 100644 --- a/projects/rccl/examples/07_kernel_fusion/04_rmsnorm_hybrid/c/README.md +++ b/projects/rccl/examples/07_kernel_fusion/04_rmsnorm_hybrid/c/README.md @@ -16,7 +16,7 @@ distributed RMSNorm operation within a single GPU kernel. From this directory: ```shell -make [MPI=1] [MPI_HOME=] [NCCL_HOME=] [CUDA_HOME=] +make [MPI=1] [MPI_HOME=] [RCCL_HOME=] [ROCM_PATH=] [GPU_TARGETS=" ..."] ``` ## Run From b0137b2f54836a2188a58778a12b948361b0b9c4 Mon Sep 17 00:00:00 2001 From: Mikhail Kuznetsov Date: Wed, 21 Oct 2026 13:24:26 +0200 Subject: [PATCH 3/6] fix(rccl): use the HIP version for warp sync in user device-API kernels nccl_device/coop.h picked __syncwarp from ROCM_VERSION, which only RCCL's own build defines. Application kernels including the installed headers fell back to __syncthreads() in the thread and warp coops; the GIN barrier calls those from a subset of threads, so the block's waves went out of step and the 07_kernel_fusion GIN/hybrid examples returned wrong results. Fall back to HIP_VERSION_MAJOR when ROCM_VERSION is not defined. Also list 07_kernel_fusion in the examples README and drop the CUDA requirements from the RMSNorm example Makefile help. Co-authored-by: Cursor --- projects/rccl/CHANGELOG.md | 1 + .../07_kernel_fusion/01_rmsnorm_lsa/c/Makefile | 3 --- .../02_rmsnorm_multimem/c/Makefile | 5 ----- .../07_kernel_fusion/03_rmsnorm_gin/c/Makefile | 3 --- .../04_rmsnorm_hybrid/c/Makefile | 3 --- projects/rccl/examples/README.md | 3 ++- projects/rccl/src/include/nccl_device/coop.h | 18 +++++++++++++++--- 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/projects/rccl/CHANGELOG.md b/projects/rccl/CHANGELOG.md index 5850683da209..ed43546a41bd 100644 --- a/projects/rccl/CHANGELOG.md +++ b/projects/rccl/CHANGELOG.md @@ -163,6 +163,7 @@ Full documentation for RCCL is available at [https://rccl.readthedocs.io](https: * Fixed a 15 to 30% `ncclScatter` bandwidth loss from 16 MB upward on multi-node AINIC jobs, caused by the move to two network channels per peer (for example on 4 nodes of 8 GPUs). Scatter now uses and connects the most channels per peer whose flows still fit the P2P channel pool. Point-to-point operations and the other collectives keep their channel count. * Fixed intermittent data corruption in multi-node collectives, seen as out-of-bounds values in 8-node AllToAll, on hosts that use GPU Direct RDMA through peermem. Since RCCL 2.30.4 the GDR flush scratchpad was registered only through dma-buf, so on peermem hosts the flush degraded to a single RDMA read of the receive buffer, which does not order earlier relaxed-ordering writes. The scratchpad is now also registered through peermem, restoring the strictly ordered RDMA write that precedes the flush read. * Fixed `ncclCommAbort` and `ncclCommRevoke` hanging when a DDA collective (IPC on gfx942/gfx950, fabric LL/LL128/VMM on gfx1250) was waiting on a peer that never joined. DDA kernels now observe the communicator abort flag while waiting. A parent communicator shrunk with `NCCL_SHRINK_ABORT` no longer uses DDA for later collectives. +* Fixed wrong results and hangs in application kernels that use the GIN device API, such as the `07_kernel_fusion` GIN and hybrid RMSNorm examples. `nccl_device/coop.h` selected `__syncwarp` from `ROCM_VERSION`, which only RCCL's own build defines, so in application code the thread and warp cooperative groups synchronized the whole block with `__syncthreads()`. The GIN barrier calls them from a subset of threads, which left the block's waves out of step. The headers now fall back to the HIP version when `ROCM_VERSION` is not defined. * Fixed FP8 E4M3 and E5M2 `ncclAvg` returning wrong values for every element of every reduction collective on gfx942, and on architectures that use the software FP8 fallback. The `1/nRanks` scale was packed as an FP8 value in the host's OCP encoding, which those devices decode as FNUZ, so every result came out half as large. The scale is now carried as `float` on all architectures, which also keeps it exact at rank counts FP8 cannot represent: in OCP E4M3, `1/384` was off by 25% and `1/1024` rounded to zero. Single-rank FP8 reductions on gfx942 no longer fail to launch the `oneRankReduce` kernel, and rccl-tests no longer skips FP8 `avg` for `all_reduce`, `all_reduce_bias` and `reduce`. * Fixed the GIN plugin never being finalized for a communicator that had connected a GIN backend, leaking the plugin's per-communicator context and leaving its reference count one too high after every `ncclCommDestroy`. `ncclGinHostFinalize` closed the GIN connections and then zeroed the whole `ncclGinState`, so the `ncclGinFinalize` that follows it in `commFree` saw no active backend and skipped the plugin `finalize()` call. Host finalize now clears only the per-connection state and hands the backend records to `ncclGinFinalize`, which finalizes each one on the last shared-resource reference. `commFree` returns the first of a `closeColl` or plugin-finalize error after those frees; if both fail, the `closeColl` error is the one reported. An `ncclRmaProxyFinalize` error still aborts the rest of teardown immediately. On the Anvil SDMA backend (`NCCL_GIN_TYPE=7`) this was one leaked init context per connected communicator. * Restored topo tuning-model init (`ncclTopoTuneModel`) after the 2.31 `ncclTuningInit` switch so multi-node kernels do not launch with `blockDim.x=0`. diff --git a/projects/rccl/examples/07_kernel_fusion/01_rmsnorm_lsa/c/Makefile b/projects/rccl/examples/07_kernel_fusion/01_rmsnorm_lsa/c/Makefile index 5804887fa0d5..878ab2cde1fa 100644 --- a/projects/rccl/examples/07_kernel_fusion/01_rmsnorm_lsa/c/Makefile +++ b/projects/rccl/examples/07_kernel_fusion/01_rmsnorm_lsa/c/Makefile @@ -85,9 +85,6 @@ help: @echo "This example demonstrates fused computation and communication" @echo "using Load Store Accessible (LSA) for RMSNorm operations." @echo "" - @echo "Requirements:" - @echo " - CUDA 12.2 or above" - @echo "" @echo "Targets:" @echo " all - Build the example (default)" @echo " test - Build and run test with all GPUs" diff --git a/projects/rccl/examples/07_kernel_fusion/02_rmsnorm_multimem/c/Makefile b/projects/rccl/examples/07_kernel_fusion/02_rmsnorm_multimem/c/Makefile index 8fff14c3fc13..fc8c934215f9 100644 --- a/projects/rccl/examples/07_kernel_fusion/02_rmsnorm_multimem/c/Makefile +++ b/projects/rccl/examples/07_kernel_fusion/02_rmsnorm_multimem/c/Makefile @@ -85,11 +85,6 @@ help: @echo "This example demonstrates fused computation and communication" @echo "using Multimem (LSA) for RMSNorm operations." @echo "" - @echo "Requirements:" - @echo " - CUDA 12.2 or above" - @echo " - CUDA Compute Capability 9.0 or higher (Hopper H100+)" - @echo " - Multimem support (nLsaTeams == 1)" - @echo "" @echo "Targets:" @echo " all - Build the example (default)" @echo " test - Build and run test with all GPUs" diff --git a/projects/rccl/examples/07_kernel_fusion/03_rmsnorm_gin/c/Makefile b/projects/rccl/examples/07_kernel_fusion/03_rmsnorm_gin/c/Makefile index 80a5633637d7..93a2fad06f2d 100644 --- a/projects/rccl/examples/07_kernel_fusion/03_rmsnorm_gin/c/Makefile +++ b/projects/rccl/examples/07_kernel_fusion/03_rmsnorm_gin/c/Makefile @@ -85,9 +85,6 @@ help: @echo "This example demonstrates fused computation and communication" @echo "using GPU-Initiated Networking (GIN) for RMSNorm operations." @echo "" - @echo "Requirements:" - @echo " - CUDA 12.2 or above" - @echo "" @echo "Targets:" @echo " all - Build the example (default)" @echo " test - Build and run test with all GPUs" diff --git a/projects/rccl/examples/07_kernel_fusion/04_rmsnorm_hybrid/c/Makefile b/projects/rccl/examples/07_kernel_fusion/04_rmsnorm_hybrid/c/Makefile index 1716ced2da29..19c869915e93 100644 --- a/projects/rccl/examples/07_kernel_fusion/04_rmsnorm_hybrid/c/Makefile +++ b/projects/rccl/examples/07_kernel_fusion/04_rmsnorm_hybrid/c/Makefile @@ -86,9 +86,6 @@ help: @echo "using a hybrid approach combining LSA for intra-node and GIN" @echo "for inter-node communication for RMSNorm operations." @echo "" - @echo "Requirements:" - @echo " - CUDA 12.2 or above" - @echo "" @echo "Targets:" @echo " all - Build the example (default)" @echo " test - Build and run test with all GPUs" diff --git a/projects/rccl/examples/README.md b/projects/rccl/examples/README.md index ea51ec0623b3..e949f7c76e17 100644 --- a/projects/rccl/examples/README.md +++ b/projects/rccl/examples/README.md @@ -28,6 +28,7 @@ full reference. | `04_user_buffer_registration` | `ncclCommRegister` to pre-register user buffers for faster collectives | | `05_symmetric_memory` | `ncclCommWindowRegister` symmetric memory windows | | `06_device_api` | Device-side API (kept as the RCCL-specific examples already present in the project) | +| `07_kernel_fusion` | RMSNorm fused with its communication in a single kernel through the Device API: LSA, Multimem, GIN, and hybrid LSA/GIN. Multimem is not supported on AMD GPUs; the GIN examples need `NCCL_CUMEM_ENABLE=1` and an RDMA NIC (`NCCL_GIN_TYPE=2`) | ## Prerequisites @@ -41,7 +42,7 @@ full reference. From this directory: ```bash -make GPU_TARGETS="gfx942" # build all 01..05 categories +make GPU_TARGETS="gfx942" # build all 01..07 categories make -C 03_collectives/01_allreduce # build one example make MPI=1 -C 01_communicators/03_one_device_per_process_mpi ``` diff --git a/projects/rccl/src/include/nccl_device/coop.h b/projects/rccl/src/include/nccl_device/coop.h index 199af795d967..1fdbed9c27f1 100644 --- a/projects/rccl/src/include/nccl_device/coop.h +++ b/projects/rccl/src/include/nccl_device/coop.h @@ -9,6 +9,18 @@ #define _NCCL_DEVICE_COOP_H_ #include "utility.h" +// ROCM_VERSION is defined only when building RCCL itself; applications that +// include these headers get the HIP version instead. Without __syncwarp, warp +// and thread coops fall back to a block-wide __syncthreads(). +#if defined(ROCM_VERSION) +#define NCCL_COOP_HAS_WARP_SYNC (ROCM_VERSION >= 70000) +#elif defined(__HIP_PLATFORM_AMD__) +#include +#define NCCL_COOP_HAS_WARP_SYNC (HIP_VERSION_MAJOR >= 7) +#else +#define NCCL_COOP_HAS_WARP_SYNC 0 +#endif + // ncclCoop[Foo]: NCCL's versions of CUDA's Cooperative Groups. They conform // to just this subset of the CUDA API: // int Coop::thread_rank(); @@ -125,7 +137,7 @@ struct ncclCoopTile { // An aligned pow2 set of threads within the warp. return (ncclCoopLaneWindow >> (WARP_SIZE - nThreadsPow2)) << (nccl::utility::lane() & -nThreadsPow2); } NCCL_DEVICE_INLINE void sync() { -#if ROCM_VERSION >= 70000 +#if NCCL_COOP_HAS_WARP_SYNC if (nThreadsPow2 > 1) __syncwarp(laneMask()); #else __syncthreads(); @@ -156,7 +168,7 @@ struct ncclCoopLanes { // Some lanes of this warp. return ncclCoopPopc(lmask); } NCCL_DEVICE_INLINE void sync() { -#if ROCM_VERSION >= 70000 +#if NCCL_COOP_HAS_WARP_SYNC __syncwarp(lmask); #else __syncthreads(); @@ -347,7 +359,7 @@ NCCL_DEVICE_INLINE constexpr bool ncclCoopWithinWarp(ncclCoopCta) { #ifdef __CUDACC__ // Pick threads of our warp that are safe to use collectively. NCCL_DEVICE_INLINE ncclCoopLanes ncclCoopCoalesced() { -#if ROCM_VERSION >= 70000 +#if NCCL_COOP_HAS_WARP_SYNC return ncclCoopLanes{static_cast(__activemask())}; #else return ncclCoopLanes{static_cast(__ballot(1))}; From bf3a6b6408e289b8895f728263d25178d63e56f4 Mon Sep 17 00:00:00 2001 From: Mikhail Kuznetsov Date: Wed, 21 Oct 2026 14:50:33 +0200 Subject: [PATCH 4/6] test(rccl): cover the coop warp-sync gate without ROCM_VERSION Add a device test that compiles nccl_device/coop.h the way an application does, with RCCL's ROCM_VERSION undefined. A static_assert pins the gate to the HIP version, and three kernels run ncclCoopThread, ncclCoopWarp, and ncclCoopLanes sync in one wave only; if any of them is a block barrier, the block reduction reads a slot before that wave publishes it. Shorten the hipify .cuh rule and coop.h comments, and update the rccl_ep comment that still described the old __syncthreads() fallback. Co-authored-by: Cursor --- .../rccl/examples/makefiles/rccl_examples.mk | 5 +- .../src/algorithms/rccl_ep/CMakeLists.txt | 5 +- projects/rccl/src/include/nccl_device/coop.h | 3 +- projects/rccl/test/CMakeLists.txt | 1 + .../test/device/CoopApplicationBuildTests.cpp | 100 ++++++++++++++++++ 5 files changed, 106 insertions(+), 8 deletions(-) create mode 100644 projects/rccl/test/device/CoopApplicationBuildTests.cpp diff --git a/projects/rccl/examples/makefiles/rccl_examples.mk b/projects/rccl/examples/makefiles/rccl_examples.mk index f1425fd9a710..1ce3432e210c 100644 --- a/projects/rccl/examples/makefiles/rccl_examples.mk +++ b/projects/rccl/examples/makefiles/rccl_examples.mk @@ -61,9 +61,8 @@ else $(CXX) $(CXXFLAGS) -x hip $(INCLUDES) -c $< -o $@ endif -# Upstream .cuh headers are hipified into HIPIFY_DIR too. A quoted #include in a -# hipified source searches HIPIFY_DIR first, so it picks up the HIP copy rather -# than the CUDA original. Point vpath at the header's directory to use this rule. +# Quoted #includes in hipified sources search HIPIFY_DIR first, so this HIP copy +# shadows the CUDA header. Needs a vpath to the header's directory. $(HIPIFY_DIR)/%.cuh: %.cuh @mkdir -p $(dir $@) $(HIPIFY) -experimental -quiet-warnings $< -o $@.tmp && mv -f $@.tmp $@ diff --git a/projects/rccl/src/algorithms/rccl_ep/CMakeLists.txt b/projects/rccl/src/algorithms/rccl_ep/CMakeLists.txt index caa4ff7d7a02..e63e21964f2a 100644 --- a/projects/rccl/src/algorithms/rccl_ep/CMakeLists.txt +++ b/projects/rccl/src/algorithms/rccl_ep/CMakeLists.txt @@ -52,9 +52,8 @@ find_path(RCCL_EP_RCCL_INCLUDE_DIR find_package(hip REQUIRED) -# is version-gated and degrades silently when ROCM_VERSION is -# undefined: coop.h:124 and :154 fall back from __syncwarp() to __syncthreads() -# in ncclCoopTile::sync() and ncclCoopLanes::sync(), and hip_compat.h:63 defines +# is version-gated on ROCM_VERSION: without it, coop.h takes its +# warp-sync gate from HIP_VERSION_MAJOR instead, and hip_compat.h:63 defines # CU_MEM_LOCATION_TYPE_HOST_NUMA that a ROCm >= 7.12 build already provides. # RCCL's own build passes -DROCM_VERSION for this exact file # (cmake/DeviceLinker.cmake:772), so the standalone artifact has to agree or the diff --git a/projects/rccl/src/include/nccl_device/coop.h b/projects/rccl/src/include/nccl_device/coop.h index 1fdbed9c27f1..70c675c893ff 100644 --- a/projects/rccl/src/include/nccl_device/coop.h +++ b/projects/rccl/src/include/nccl_device/coop.h @@ -10,8 +10,7 @@ #include "utility.h" // ROCM_VERSION is defined only when building RCCL itself; applications that -// include these headers get the HIP version instead. Without __syncwarp, warp -// and thread coops fall back to a block-wide __syncthreads(). +// include these headers get the HIP version instead. #if defined(ROCM_VERSION) #define NCCL_COOP_HAS_WARP_SYNC (ROCM_VERSION >= 70000) #elif defined(__HIP_PLATFORM_AMD__) diff --git a/projects/rccl/test/CMakeLists.txt b/projects/rccl/test/CMakeLists.txt index 1407fa20cc2d..23fd80f7014b 100644 --- a/projects/rccl/test/CMakeLists.txt +++ b/projects/rccl/test/CMakeLists.txt @@ -422,6 +422,7 @@ if(BUILD_TESTS) device/HierarchicalShuffleTests.cpp device/NcclUtilityDeviceTests.cpp device/ChannelMaskMapTests.cpp + device/CoopApplicationBuildTests.cpp DeviceApiTests.cpp common/main_fixtures.cpp common/EnvVars.cpp diff --git a/projects/rccl/test/device/CoopApplicationBuildTests.cpp b/projects/rccl/test/device/CoopApplicationBuildTests.cpp new file mode 100644 index 000000000000..8822a2fe4dab --- /dev/null +++ b/projects/rccl/test/device/CoopApplicationBuildTests.cpp @@ -0,0 +1,100 @@ +/************************************************************************* + * Copyright (c) 2026 Advanced Micro Devices, Inc. All rights reserved. + * + * See LICENSE.txt for license information + ************************************************************************/ + +// Device tests for nccl_device/coop.h as an application compiles it: RCCL's own +// -DROCM_VERSION is not visible there, so the warp-sync gate comes from HIP. +#undef ROCM_VERSION + +#include +#include + +#include "DeviceTestBase.hpp" + +#include "nccl_device/coop.h" + +static_assert(NCCL_COOP_HAS_WARP_SYNC == (HIP_VERSION_MAJOR >= 7), + "coop.h must take the warp-sync gate from HIP when ROCM_VERSION is undefined"); + +namespace RcclUnitTesting { +namespace { + +constexpr int kWaves = 4; +// Wave 1 publishes this late, so a block barrier that releases early is seen by thread 0. +constexpr long long kPublishDelayCycles = 200000; + +struct CoopThreadCase { + __device__ static bool participates(int lane) { return lane == 0; } + __device__ static void sync() { ncclCoopThread().sync(); } +}; + +struct CoopWarpCase { + __device__ static bool participates(int) { return true; } + __device__ static void sync() { ncclCoopWarp().sync(); } +}; + +struct CoopLanesCase { + __device__ static bool participates(int lane) { return lane < 2; } + __device__ static void sync() { ncclCoopLanes(0x3).sync(); } +}; + +// Only wave 1 runs the sub-warp coop sync. If that sync is a block-wide +// __syncthreads(), it pairs with the block barrier the other waves reach, and +// thread 0 sums the slots before wave 1 has published its own. +template +__global__ void kernelCoopSyncInOneWave(int* out) { + __shared__ int slots[kWaves]; + const int wave = threadIdx.x / warpSize; + const int lane = threadIdx.x % warpSize; + if (threadIdx.x < kWaves) slots[threadIdx.x] = 0; + __syncthreads(); + if (wave == 1 && Case::participates(lane)) Case::sync(); + if (lane == 0) { + if (wave == 1) { + const long long start = clock64(); + while (clock64() - start < kPublishDelayCycles) { + } + } + slots[wave] = 1; + } + __syncthreads(); + if (threadIdx.x == 0) { + int sum = 0; + for (int w = 0; w < kWaves; ++w) sum += slots[w]; + *out = sum; + } +} + +class CoopApplicationBuildTest : public DeviceTestBase { +protected: + template + void runCase() { + if (HIP_VERSION_MAJOR < 7) { + GTEST_SKIP() << "HIP < 7 has no __syncwarp; coop sync is block-wide by design"; + } + hipDeviceProp_t prop{}; + ASSERT_EQ(hipGetDeviceProperties(&prop, 0), hipSuccess); + DeviceBuffer out(1); + ASSERT_NO_FATAL_FAILURE(out.zero()); + kernelCoopSyncInOneWave<<<1, kWaves * prop.warpSize>>>(out.ptr); + ASSERT_NO_FATAL_FAILURE(syncAndCheck()); + EXPECT_EQ(out.download(), kWaves); + } +}; + +TEST_F(CoopApplicationBuildTest, CoopThreadSyncIsNotBlockBarrier) { + runCase(); +} + +TEST_F(CoopApplicationBuildTest, CoopWarpSyncIsNotBlockBarrier) { + runCase(); +} + +TEST_F(CoopApplicationBuildTest, CoopLanesSyncIsNotBlockBarrier) { + runCase(); +} + +} // namespace +} // namespace RcclUnitTesting From f4ba1aa0d0480d0182f9205971678884abffa77c Mon Sep 17 00:00:00 2001 From: Mikhail Kuznetsov Date: Wed, 21 Oct 2026 17:04:31 +0200 Subject: [PATCH 5/6] test(rccl): time the coop test delay with wall_clock64() clock64() is the 20-bit SHADER_CYCLES counter on gfx11, so the delay loop could wrap and never exit. wall_clock64() is 64-bit on every arch. Co-authored-by: Cursor --- projects/rccl/test/device/CoopApplicationBuildTests.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/projects/rccl/test/device/CoopApplicationBuildTests.cpp b/projects/rccl/test/device/CoopApplicationBuildTests.cpp index 8822a2fe4dab..e39db9c3a493 100644 --- a/projects/rccl/test/device/CoopApplicationBuildTests.cpp +++ b/projects/rccl/test/device/CoopApplicationBuildTests.cpp @@ -23,7 +23,8 @@ namespace { constexpr int kWaves = 4; // Wave 1 publishes this late, so a block barrier that releases early is seen by thread 0. -constexpr long long kPublishDelayCycles = 200000; +// wall_clock64() ticks: clock64() is a 20-bit counter on gfx11 and can wrap inside the loop. +constexpr long long kPublishDelayTicks = 200000; struct CoopThreadCase { __device__ static bool participates(int lane) { return lane == 0; } @@ -53,8 +54,8 @@ __global__ void kernelCoopSyncInOneWave(int* out) { if (wave == 1 && Case::participates(lane)) Case::sync(); if (lane == 0) { if (wave == 1) { - const long long start = clock64(); - while (clock64() - start < kPublishDelayCycles) { + const long long start = wall_clock64(); + while (wall_clock64() - start < kPublishDelayTicks) { } } slots[wave] = 1; From 57d21a3ea5b8c40b4426be137b5a9bf693b80100 Mon Sep 17 00:00:00 2001 From: Mikhail Kuznetsov Date: Wed, 21 Oct 2026 17:12:04 +0200 Subject: [PATCH 6/6] ci(rccl): run CoopApplicationBuildTest in precheckin The precheckin config lists rccl-UnitTestsFixtures filters explicitly, so the new coop test was built but never run. Co-authored-by: Cursor --- .../rccl/tools/scripts/test_runner/configs/ci-precheckin.json | 1 + 1 file changed, 1 insertion(+) diff --git a/projects/rccl/tools/scripts/test_runner/configs/ci-precheckin.json b/projects/rccl/tools/scripts/test_runner/configs/ci-precheckin.json index 9bc4d20e6c33..2edc1df5dbf1 100644 --- a/projects/rccl/tools/scripts/test_runner/configs/ci-precheckin.json +++ b/projects/rccl/tools/scripts/test_runner/configs/ci-precheckin.json @@ -181,6 +181,7 @@ {"name": "DdaIpcGpuBarrierOrdering", "description": "DDA IPC barrier release/acquire cross-GPU message passing (8 GPUs)", "test_filter": "DdaIpcGpuBarrierOrdering.*", "timeout": 600}, {"name": "NcclUtility", "description": "nccl::utility host tests: integer/pointer align, rcp division, rolling compares, order maps, Optional", "test_filter": "NcclUtility*-NcclUtilityDeviceTest.*"}, {"name": "NcclUtilityDeviceTest", "description": "nccl::utility device tests: loadConstLdg branches, testAbort, atomics, fences, lanes, rcp tables", "test_filter": "NcclUtilityDeviceTest.*"}, + {"name": "CoopApplicationBuildTest", "description": "nccl_device coop sync built without ROCM_VERSION, as in an application: thread/warp/lanes sync is not a block barrier", "test_filter": "CoopApplicationBuildTest.*"}, {"name": "DdaCollCommon", "description": "DDA collective common helper tests", "test_filter": "DdaCollCommon.*"} ] },