Skip to content

[ROCm] Add HIP/ROCm support for AMD GPUs#10

Open
jeffdaily wants to merge 2 commits into
botforge:masterfrom
jeffdaily:moat-port
Open

[ROCm] Add HIP/ROCm support for AMD GPUs#10
jeffdaily wants to merge 2 commits into
botforge:masterfrom
jeffdaily:moat-port

Conversation

@jeffdaily

Copy link
Copy Markdown

This adds AMD GPU support to the CUDA scan-matcher (ICP point-cloud registration) through HIP, so the project builds and runs on ROCm in addition to CUDA.

A single src/cuda_to_hip.h compatibility header maps the CUDA runtime and OpenGL-interop symbols the project uses to their HIP equivalents. The same sources compile for NVIDIA (the default) and AMD (configure with -DUSE_HIP=ON); the CUDA build path is unchanged. The GL interop is updated to the modern graphics-resource API (hipGraphicsGLRegisterBuffer and friends), which HIP provides and which supersedes the old cudaGL* entry points.

GLM device-function support is enabled through src/glm_device.h, which defines the qualifier macros GLM expects so its math functions get __host__ __device__ under hipcc. rocThrust is a drop-in for CUDA Thrust; it requires C++17, so the host language standard is raised to match. Include order matters: Thrust headers must precede GLM so rocThrust selects the HIP backend.

Build

mkdir build && cd build
cmake .. -DUSE_HIP=ON -DCMAKE_HIP_ARCHITECTURES=gfx90a -DCMAKE_PREFIX_PATH=/opt/rocm -DCMAKE_BUILD_TYPE=Release
cmake --build . --parallel

CMAKE_HIP_ARCHITECTURES selects the target GPU (for example gfx90a for CDNA2, gfx1100 for RDNA3, gfx1201 for RDNA4); it defaults to gfx90a if unset. The README documents the AMD build alongside the existing Windows and Linux CUDA instructions.

Validation

Built and run on gfx90a (MI250X, CDNA2), gfx1100 (RDNA3), and gfx1201 (RDNA4). The headless ICP run (VISUALIZE 0) completes 10 iterations on each, with stable nearest-neighbor timing per step and no errors.

Notes

This work was authored with assistance from Claude, an AI assistant by Anthropic.

Add AMD GPU support to the CUDA scan-matcher (ICP point-cloud
registration) via HIP. A single src/cuda_to_hip.h compatibility header
maps the CUDA runtime and OpenGL-interop symbols used by the project to
their HIP equivalents, so the same sources compile for NVIDIA (default)
and AMD (-DUSE_HIP=ON) GPUs. The GL interop is updated to the modern
graphics-resource API (hipGraphicsGLRegisterBuffer and friends), which
HIP provides and which deprecates the old cudaGL* entry points.

GLM device-function support is enabled through src/glm_device.h, which
defines the qualifier macros GLM expects so its math functions get
__host__ __device__ under hipcc. rocThrust is a drop-in for CUDA Thrust;
it requires C++17, so the host standard is raised accordingly. Include
order matters: Thrust must precede GLM so rocThrust selects the HIP
backend.

To review, start with src/cuda_to_hip.h and the USE_HIP branch of
CMakeLists.txt, then the GL interop and device-math call sites in
src/main.cpp and the .cu sources. The README documents the AMD build
alongside the existing Windows and Linux CUDA instructions.

This work was authored with assistance from Claude, an AI assistant by
Anthropic.

Test Plan:
```
cmake -S . -B build -DUSE_HIP=ON -DCMAKE_HIP_ARCHITECTURES=gfx90a \
  -DCMAKE_PREFIX_PATH=/opt/rocm -DCMAKE_BUILD_TYPE=Release
cmake --build build -j
HIP_VISIBLE_DEVICES=0 ./build/bin/cis565_ScanMatching
# 10 ICP iterations complete, ~440us NN timing per step on gfx90a (MI250X)
```
Built and run on gfx90a (MI250X, CDNA2), gfx1100 (RDNA3), and gfx1201
(RDNA4); the headless ICP run completes 10 iterations on each.
The default-gfx90a block preempted and duplicated CMake's own host-GPU
detection. Removing it lets enable_language(HIP) honor an explicit
-DCMAKE_HIP_ARCHITECTURES, auto-detect the host GPU, or error on a
no-GPU build host. The block was also dead code: it ran after
enable_language(HIP), by which point CMAKE_HIP_ARCHITECTURES was already
set, so its guard was always false.

This work was authored with the Claude AI assistant.
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