Skip to content

Adds AMD backend to loops - #46

Merged
neoblizz merged 10 commits into
mainfrom
neoblizz/amd
Jun 25, 2026
Merged

neoblizz merged 10 commits into
mainfrom
neoblizz/amd

Conversation

@neoblizz

Copy link
Copy Markdown
Member

This pull request introduces comprehensive support for building and running the project on AMD GPUs using the HIP/ROCm backend, in addition to the existing CUDA/NVIDIA support. The changes include backend selection in the build system, new CMake presets for AMD architectures, CI integration for HIP builds, and code updates to ensure backend-agnostic usage of GPU streams and synchronization. Some CUDA-specific examples are now conditionally excluded from HIP builds.

Build system and configuration:

  • Added a LOOPS_BACKEND CMake option to select between CUDA (default) and HIP backends, with corresponding logic for toolkit and architecture selection, dependency finding, compile flags, and target properties in CMakeLists.txt. This enables seamless building on either NVIDIA or AMD platforms. [1] [2] [3] [4] [5] [6] [7] [8] [9]
  • Added new CMake presets for AMD GPUs (gfx90a, gfx942, gfx950) in CMakePresets.json, enabling easy configuration and build for MI210/MI250, MI300X/MI325X, and MI350X architectures. [1] [2]

Continuous Integration:

  • Introduced a new GitHub Actions job for backend parity, which checks for symbol mismatches between CUDA and HIP backend headers, ensuring API consistency. Also added a HIP build job targeting multiple AMD architectures, installing necessary ROCm tools and compiling the code in CI. (.github/workflows/build.yml)

Codebase portability and backend-agnostic changes:

  • Updated all relevant algorithm implementations and examples to use xpu::stream_t and xpu::stream_synchronize instead of CUDA-specific types and functions, allowing the same code to work with both CUDA and HIP backends. [1] [2] [3] [4] [5] [6] [7] [8]

Conditional example inclusion:

  • Modified the SPMV example CMakeLists to exclude the group_mapped.cu example when building with HIP, as it relies on NVIDIA cooperative-groups, which are not available in HIP. [1] [2]

These changes collectively enable robust, cross-vendor GPU support and improve maintainability and CI coverage for both CUDA and HIP backends.

neoblizz and others added 10 commits June 23, 2026 22:46
add include/loops/util/xpu.hxx selecting cuda or hip and route every
cudaXxx call (streams, events, memcpy, device attrs, occupancy,
cooperative launch, errors) through xpu. group_mapped stays cuda-only
since hip lacks the cooperative-groups block_tile_memory path.

Co-authored-by: Cursor <cursoragent@cursor.com>
extend sm_flag_t with cdna (gfx906/908/90a/942/950) and rdna
(gfx1030/1100/1200) bits, select the target via LOOPS_TARGET_GFX on hip
builds, and give spmv wavefront/cache-aware launch params: 256-thread
(4x wavefront-64) blocks on cdna, wider tiles on large-llc gfx942/gfx950.

Co-authored-by: Cursor <cursoragent@cursor.com>
branch the build on LOOPS_BACKEND (cuda default, hip via hipcc/rocm):
enable_language(HIP), link hip::host + roc::rocthrust, compile the shared
.cu sources as hip, and map a single gfx target to LOOPS_TARGET_GFX.

Co-authored-by: Cursor <cursoragent@cursor.com>
cub/block/block_scan.cuh was included but never used; removing it also
unblocks the hip build (no cub on rocm).

Co-authored-by: Cursor <cursoragent@cursor.com>
note the per-arch numbers driving the spmv tiles (cdna wavefront 64, 256-
thread blocks; gfx90a no last-level cache vs 256 mb infinity cache on
gfx942/gfx950) and add the rdna4 gfx1201 slot.

Co-authored-by: Cursor <cursoragent@cursor.com>
release-mi210/mi300x/mi350x presets (gfx90a/gfx942/gfx950) and -Wno-
unused-result on the hip pass for the fire-and-forget xpu wrappers.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
build the hip backend compile-only in a rocm 7.2.4 container across
gfx90a/gfx942/gfx950 (release-mi210/mi300x/mi350x presets), so a hip
break or a gfx-specific divergence is caught without amd hardware. add a
fast parity job that diffs the loops::xpu symbol set across
backend/cuda.hxx and hip.hxx to catch "added to one, forgot the other".

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
a thread's first complete row can continue a row opened in the previous
partition, whose head is emitted there as a remainder atomic; storing the
first row directly raced with that atomic and intermittently dropped the
head term. fold the first row in with atomicAdd onto the zero-initialized
output, leaving interior rows as direct stores.

Co-authored-by: Cursor <cursoragent@cursor.com>
@neoblizz
neoblizz merged commit 5fe92c6 into main Jun 25, 2026
9 checks passed
@neoblizz
neoblizz deleted the neoblizz/amd branch June 25, 2026 20:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant