Skip to content

Add AMD GPU (HIP/ROCm) support - #46

Merged
iwald-nvidia merged 2 commits into
NVIDIA:mainfrom
AMD-Ecosystem:moat-port
Jun 26, 2026
Merged

Add AMD GPU (HIP/ROCm) support#46
iwald-nvidia merged 2 commits into
NVIDIA:mainfrom
AMD-Ecosystem:moat-port

Conversation

@jeffdaily

Copy link
Copy Markdown
Contributor

This adds the ability to build and run barney's GPU rendering on AMD GPUs with HIP for ROCm, alongside the existing CUDA/OptiX path. The support is additive and gated behind a new USE_HIP CMake option that defaults to OFF, so the CUDA/OptiX build is unchanged when it is not enabled.

What this does

Two ROCm backends are added under rtcore/, mirroring the existing CUDA backends:

  • A software ray-tracing backend that reuses barney's CUDA device code compiled with HIP, traversing the cuBQL BVH (no vendor RT hardware required). The CUDA backend's GPU sources are retagged LANGUAGE HIP under USE_HIP; OptiX is NVIDIA-only and is not used in this configuration.
  • A HIPRT hardware-traversal backend (rtcore/hiprt/, enabled with -DBARNEY_BACKEND_HIPRT=ON), the AMD analogue of the OptiX backend: it builds HIPRT scenes, runs the single trace kernel, and maps barney's anyHit/closestHit/intersect programs onto HIPRT's filter and custom-geometry function tables.

A small compatibility header (rtcore/cudaCommon/cuda_to_hip.h) maps the CUDA runtime spellings the shared code uses onto their HIP equivalents; it is included only on the HIP build and falls through to <cuda_runtime.h> otherwise, so the CUDA translation units are unaffected. cmake/Findhiprt.cmake locates the HIPRT SDK as a discovered dependency (never vendored), the same way barney finds OptiX.

Building for AMD GPUs

Add -DUSE_HIP=ON and select the target architecture with -DCMAKE_HIP_ARCHITECTURES=<arch> (for example gfx90a for CDNA2, or gfx1100 for RDNA3); when unset it defaults to gfx90a. To use HIPRT hardware traversal, also add -DBARNEY_BACKEND_HIPRT=ON -Dhiprt_ROOT=<HIPRT-install>. The README's "Building and Running" section documents the ROCm path alongside the CUDA/OptiX one.

Validation

Validated on Linux (gfx90a CDNA2 and gfx1100 RDNA3) and Windows (gfx1201 RDNA4): both backends build and the bundled validation scenes (triangles, spheres, cylinders, instances, and the opaque/transparent path-traced scenes) render with pixel statistics identical to the CUDA reference; the HIPRT custom-geometry path is pixel-identical to the software backend.

This support targets ROCm. The CUDA/OptiX build is unchanged when USE_HIP is off.

This work was authored with assistance from Claude.

Add the ability to build and run barney's GPU rendering on AMD GPUs with HIP
for ROCm, alongside the existing CUDA/OptiX path. The support is additive and
gated behind a new USE_HIP CMake option (default OFF), so the CUDA/OptiX build
is unchanged when it is not enabled.

How to review, in order:
1. Build wiring (CMakeLists.txt, rtcore/CMakeLists.txt, barney/CMakeLists.txt):
   under USE_HIP, enable_language(HIP) and set the HIP architecture from
   CMAKE_HIP_ARCHITECTURES (default gfx90a when unset), and retag the reused
   CUDA backend sources LANGUAGE HIP. The new backend slots into the existing
   rtcore backend selection without disturbing the CUDA/OptiX path.
2. The compat shim (rtcore/cudaCommon/cuda_to_hip.h): force-included only on the
   HIP build, it maps the small set of CUDA runtime spellings the shared backend
   uses to their hipXxx equivalents and otherwise falls through to
   <cuda_runtime.h>, so the CUDA translation units are unchanged.
3. Software ray-tracing backend: the CUDA device code is reused under HIP,
   traversing the cuBQL BVH; no vendor RT hardware is required. OptiX is
   NVIDIA-only and is not used in this configuration.
4. HIPRT hardware-traversal backend (rtcore/hiprt/, -DBARNEY_BACKEND_HIPRT=ON):
   the AMD analogue of the OptiX backend, derived from the CUDA backend; it
   builds HIPRT scenes and maps barney's anyHit/closestHit/intersect programs
   onto HIPRT's filter and custom-geometry function tables.
5. cmake/Findhiprt.cmake locates the HIPRT SDK as a discovered dependency
   (never vendored), the way barney finds OptiX.

Building for AMD GPUs: add -DUSE_HIP=ON and select the architecture with
-DCMAKE_HIP_ARCHITECTURES=<arch> (defaults to gfx90a); add
-DBARNEY_BACKEND_HIPRT=ON -Dhiprt_ROOT=<HIPRT-install> for HIPRT traversal.

Validated on Linux (gfx90a CDNA2, gfx1100 RDNA3) and Windows (gfx1201 RDNA4):
both backends build, and the bundled validation scenes (triangles, spheres,
cylinders, instances, and the opaque/transparent path-traced scenes) render with
pixel statistics identical to the CUDA reference; the HIPRT custom-geometry path
is pixel-identical to the software backend. The CUDA/OptiX build is unchanged
when USE_HIP is off.

This work was authored with the assistance of Claude (Anthropic).

Test Plan:
```
# software backend (gfx90a)
cmake -S . -B build-hip -DUSE_HIP=ON -DCMAKE_HIP_ARCHITECTURES=gfx90a -DCMAKE_BUILD_TYPE=Release
cmake --build build-hip -j

# HIPRT hardware backend
cmake -S . -B build-hiprt -DUSE_HIP=ON -DBARNEY_BACKEND_HIPRT=ON \
  -Dhiprt_ROOT=<HIPRT-install> -DCMAKE_HIP_ARCHITECTURES=gfx90a -DCMAKE_BUILD_TYPE=Release
cmake --build build-hiprt -j

# render the validation scenes and compare pixel stats to the CUDA reference
```

Signed-off-by: Jeff Daily <jeff.daily@amd.com>
The gfx90a pin sat after enable_language(HIP), so its
if(NOT DEFINED CMAKE_HIP_ARCHITECTURES) guard was always false and the
block was dead -- enable_language(HIP) has already detected the host arch
(or errored). Removing it makes intent clear and keeps the build honoring
-DCMAKE_HIP_ARCHITECTURES, auto-detecting the host GPU, or erroring on a
no-GPU host, rather than risking a silently wrong gfx90a default if file
order ever changed.

This change was authored with the assistance of the Claude AI assistant.
@iwald-nvidia

Copy link
Copy Markdown
Collaborator

just to leave a note of why i haven't merged this yet - when running on some internal test cases i'm seeing some crashes on three of my internal test cases, and i haven't figured out why that happens, yet. This is on rocm-7.2.3 and a radeon 7800xt. All three fails involve user geometry - triangles seem to be all working, as do volumes - but that's as far as i cornered it yet. Takes a while because I need to cross-compare to other builds to see if these fails are specific to this config or were in there before. I'm on it.

@iwald-nvidia

Copy link
Copy Markdown
Collaborator

K; I'll merge this once the CI builds are passing.
As of yesterday I finally managed to track the failing tests, and they seem to be compiler-related - the crashes happen in code that's been used for ages, that works fine in both C and CUDA, and even works find in HIP if I force all rays to be traced by a single thread. I'll file info on how to reproduce on your side as a github issue, but since that's not a code issue - and only happens for a rather seldomly used geometry type - I think it would be wrong to delay merging.

@iwald-nvidia
iwald-nvidia merged commit 8f367fa into NVIDIA:main Jun 26, 2026
12 checks passed
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.

2 participants