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/.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..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 @@ -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) @@ -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/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/Makefile b/projects/rccl/examples/07_kernel_fusion/02_rmsnorm_multimem/c/Makefile index b96a1acfe152..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 @@ -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) @@ -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/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/Makefile b/projects/rccl/examples/07_kernel_fusion/03_rmsnorm_gin/c/Makefile index f47ade6343d1..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 @@ -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) @@ -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/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/Makefile b/projects/rccl/examples/07_kernel_fusion/04_rmsnorm_hybrid/c/Makefile index 5ed8d5baf3b1..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 @@ -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) @@ -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/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 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/examples/makefiles/rccl_examples.mk b/projects/rccl/examples/makefiles/rccl_examples.mk index e3d2fce1b078..1ce3432e210c 100644 --- a/projects/rccl/examples/makefiles/rccl_examples.mk +++ b/projects/rccl/examples/makefiles/rccl_examples.mk @@ -61,5 +61,11 @@ else $(CXX) $(CXXFLAGS) -x hip $(INCLUDES) -c $< -o $@ endif +# 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 $@ + # 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 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 199af795d967..70c675c893ff 100644 --- a/projects/rccl/src/include/nccl_device/coop.h +++ b/projects/rccl/src/include/nccl_device/coop.h @@ -9,6 +9,17 @@ #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. +#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 +136,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 +167,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 +358,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))}; 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..e39db9c3a493 --- /dev/null +++ b/projects/rccl/test/device/CoopApplicationBuildTests.cpp @@ -0,0 +1,101 @@ +/************************************************************************* + * 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. +// 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; } + __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 = wall_clock64(); + while (wall_clock64() - start < kPublishDelayTicks) { + } + } + 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 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.*"} ] },