[ROCm] Add an AMD GPU build with HIP#9
Open
jeffdaily wants to merge 1 commit into
Open
Conversation
This adds a HIP/ROCm build of Velvet so the cloth simulator runs on AMD GPUs, alongside the existing CUDA build. The AMD support is added through a new CMake build with a USE_HIP option; the upstream Visual Studio / CUDA project is left intact: no source files are renamed (the HIP build selects the HIP language in CMake instead), and all AMD-specific code is guarded by USE_HIP, so every effort has been made to leave the CUDA build unchanged. The CUDA GPU sources were compile-checked with nvcc but not run, as the development hosts have no NVIDIA GPU.
How to review: CMakeLists.txt first (the build wiring), then Velvet/cuda_to_hip.h (the CUDA->HIP symbol mapping), then the small per-source changes, then the README build section.
CMakeLists.txt is new (the project shipped only a Visual Studio solution). It builds with CUDA by default and with HIP when -DUSE_HIP=ON. Because a mixed CXX/HIP target would apply the HIP offload-arch flags to the plain .cpp sources and fail, the HIP build marks the sources LANGUAGE HIP with set_source_files_properties rather than renaming them to .cu; this keeps the .cpp filenames the Visual Studio project references. Dependencies come from vcpkg, matching the upstream build instructions, using the x64-linux triplet on Linux (glfw3, glad, fmt, glm, assimp, imgui); GLM is taken from vcpkg because its 1.0.x release adds the HIP compiler detection the bundled system copy lacked.
Velvet/cuda_to_hip.h is the compatibility shim, active only under USE_HIP. It maps the CUDA runtime and OpenGL-interop symbols the project uses onto their hip* equivalents, and defines THRUST_DEVICE_SYSTEM as HIP before Thrust is included (rocThrust checks __CUDACC__ before __HIP__, so without this it would select the CUDA backend). On NVIDIA the header is an empty passthrough, so the CUDA path is unaffected.
The one functional fix outside the build system is in the CUDA_CALL macros (Velvet/Common.cuh): they were gated on __CUDACC__ only, which hipcc does not define, so on HIP they expanded to empty and every kernel launch silently did nothing. They are now also enabled under __HIPCC__. The .gitignore also gains the CMake build/ directory. One template parameter pack (VtCallback::Invoke in Common.hpp) is renamed so it stops shadowing the enclosing class's pack, which nvcc and gcc reject.
Velvet renders with OpenGL and shares vertex buffers with the GPU through graphics interop, so it needs an AMD GPU with a graphics pipeline. RDNA parts (Radeon RX 7000/9000) work; compute-only datacenter parts (CDNA, Instinct MI series) cannot create the required OpenGL context and so cannot run it.
This work was authored with the assistance of Claude, an AI assistant by Anthropic.
Test Plan:
Build the dependencies once with vcpkg (x64-linux on Linux), then configure with HIP and run the simulator:
./vcpkg install glfw3 glad fmt glm assimp "imgui[core,opengl3-binding,glfw-binding]" --triplet x64-linux
cmake -B build -DUSE_HIP=ON -DCMAKE_HIP_ARCHITECTURES=gfx1100 \
-DCMAKE_TOOLCHAIN_FILE=<vcpkg>/scripts/buildsystems/vcpkg.cmake
cmake --build build -j
./build/bin/Velvet
Validated by building and running the cloth simulation on real GPUs: Linux gfx1100 (RDNA3) and Windows gfx1201 (RDNA4); the simulation runs and renders correctly. The build also compiles and links on gfx90a (CDNA2), but that part is compute-only and cannot run the OpenGL/HIP interop path, so it is not a runtime target. The CUDA GPU sources were compile-checked with nvcc (CUDA 13.3); the build was not linked or run, as no NVIDIA GPU was available, and is otherwise preserved by guarding all AMD code under USE_HIP and not renaming any sources.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds a HIP/ROCm build of Velvet so the cloth simulator runs on AMD GPUs, alongside the existing CUDA build. The AMD support is added through a new CMake build with a USE_HIP option; the upstream Visual Studio / CUDA project is left intact: no source files are renamed (the HIP build selects the HIP language in CMake instead), and all AMD-specific code is guarded by USE_HIP, so every effort has been made to leave the CUDA build unchanged. The CUDA GPU sources were compile-checked with nvcc but not run, as the development hosts have no NVIDIA GPU.
How to review: CMakeLists.txt first (the build wiring), then Velvet/cuda_to_hip.h (the CUDA->HIP symbol mapping), then the small per-source changes, then the README build section.
CMakeLists.txt is new (the project shipped only a Visual Studio solution). It builds with CUDA by default and with HIP when -DUSE_HIP=ON. Because a mixed CXX/HIP target would apply the HIP offload-arch flags to the plain .cpp sources and fail, the HIP build marks the sources LANGUAGE HIP with set_source_files_properties rather than renaming them to .cu; this keeps the .cpp filenames the Visual Studio project references. Dependencies come from vcpkg, matching the upstream build instructions, using the x64-linux triplet on Linux (glfw3, glad, fmt, glm, assimp, imgui); GLM is taken from vcpkg because its 1.0.x release adds the HIP compiler detection the bundled system copy lacked.
Velvet/cuda_to_hip.h is the compatibility shim, active only under USE_HIP. It maps the CUDA runtime and OpenGL-interop symbols the project uses onto their hip* equivalents, and defines THRUST_DEVICE_SYSTEM as HIP before Thrust is included (rocThrust checks
__CUDACC__before__HIP__, so without this it would select the CUDA backend). On NVIDIA the header is an empty passthrough, so the CUDA path is unaffected.The one functional fix outside the build system is in the CUDA_CALL macros (Velvet/Common.cuh): they were gated on
__CUDACC__only, which hipcc does not define, so on HIP they expanded to empty and every kernel launch silently did nothing. They are now also enabled under__HIPCC__. The .gitignore also gains the CMake build/ directory. One template parameter pack (VtCallback::Invoke in Common.hpp) is renamed so it stops shadowing the enclosing class's pack, which nvcc and gcc reject.Velvet renders with OpenGL and shares vertex buffers with the GPU through graphics interop, so it needs an AMD GPU with a graphics pipeline. RDNA parts (Radeon RX 7000/9000) work; compute-only datacenter parts (CDNA, Instinct MI series) cannot create the required OpenGL context and so cannot run it.
This work was authored with the assistance of Claude, an AI assistant by Anthropic.
Test Plan:
Build the dependencies once with vcpkg (x64-linux on Linux), then configure with HIP and run the simulator:
Validated by building and running the cloth simulation on real GPUs: Linux gfx1100 (RDNA3) and Windows gfx1201 (RDNA4); the simulation runs and renders correctly. The build also compiles and links on gfx90a (CDNA2), but that part is compute-only and cannot run the OpenGL/HIP interop path, so it is not a runtime target. The CUDA GPU sources were compile-checked with nvcc (CUDA 13.3); the build was not linked or run, as no NVIDIA GPU was available, and is otherwise preserved by guarding all AMD code under USE_HIP and not renaming any sources.