Add AMD GPU (HIP/ROCm) support - #46
Conversation
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.
|
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. |
|
K; I'll merge this once the CI builds are passing. |
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_HIPCMake option that defaults toOFF, 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:LANGUAGE HIPunderUSE_HIP; OptiX is NVIDIA-only and is not used in this configuration.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.cmakelocates the HIPRT SDK as a discovered dependency (never vendored), the same way barney finds OptiX.Building for AMD GPUs
Add
-DUSE_HIP=ONand select the target architecture with-DCMAKE_HIP_ARCHITECTURES=<arch>(for examplegfx90afor CDNA2, orgfx1100for RDNA3); when unset it defaults togfx90a. 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 (
gfx90aCDNA2 andgfx1100RDNA3) and Windows (gfx1201RDNA4): 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_HIPis off.This work was authored with assistance from Claude.