[ROCm] Add HIP support for AMD Instinct GPUs#31
Open
andyluo7 wants to merge 1 commit into
Open
Conversation
Port all CUDA-specific code to work on both CUDA and ROCm via HIP: - Headers: #ifdef __HIP_PLATFORM_AMD__ guards for cuda.h → hip/hip_runtime.h, cub/cub.cuh → hipcub/hipcub.hpp - API: cudaMalloc/Free/Memcpy → hipMalloc/Free/Memcpy (guarded) - CUB → hipcub namespace mapping - ::cuda::std::tuple → ::rocprim::tuple (for DeviceRadixSort decomposer) - ::cuda::std::plus → hipcub::Sum() - Vec3f: add default __host__ __device__ constructor for hipcub compatibility - ATen/cuda → ATen/hip (in cubvh submodule) - setup.py: default arch gfx942, gate CUDA-only flags behind IS_HIP check Tested on AMD MI300X (gfx942) with ROCm 7.0.2 + PyTorch 2.9.1. All code remains cross-compilable for CUDA. Signed-off-by: Andy Luo <andyluo7@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR ports CuMesh to build and run on AMD ROCm GPUs (e.g., MI300X / gfx942) by adding HIP support alongside the existing CUDA implementation.
Changes:
- Introduces HIP/ROCm conditionals (
__HIP_PLATFORM_AMD__) across core CUDA sources/headers and replaces multiple CUDA runtime calls with HIP equivalents. - Switches CUB usages to hipcub (and adjusts some related types such as tuple decomposers) to enable GPU-side primitives on ROCm.
- Adds hipify-generated HIP variants of several translation units/headers and updates
setup.pyROCm defaults (e.g., default archgfx942and gating CUDA-only flags).
Reviewed changes
Copilot reviewed 30 out of 30 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| src/utils.h | Adds HIP-vs-CUDA includes and updates error/memory helpers (Buffer/CUDA_CHECK) for HIP usage. |
| src/utils_hip.h | Adds hipify-generated utilities header. |
| src/simplify.cu | Switches CUB include to hipcub on ROCm and updates several runtime calls toward HIP. |
| src/simplify.hip | Adds hipify-generated simplify translation unit. |
| src/shared.h | Adds HIP/CUDA conditional includes and migrates several CUB calls toward hipcub. |
| src/shared_hip.h | Adds hipify-generated shared utilities header. |
| src/shared.hip | Adds hipify-generated shared kernels translation unit. |
| src/remesh/svox2vert.cu | Updates headers and several runtime/CUB calls toward HIP/hipcub. |
| src/remesh/svox2vert.hip | Adds hipify-generated svox2vert translation unit. |
| src/remesh/simple_dual_contour.cu | Updates runtime error checking to HIP. |
| src/remesh/simple_dual_contour.hip | Adds hipify-generated dual contour translation unit. |
| src/io.cu | Updates buffer→tensor copy paths toward HIP memcpy APIs. |
| src/io.hip | Adds hipify-generated IO translation unit. |
| src/hash/hash.cu | Adds HIP/CUDA conditional runtime header include. |
| src/hash/hash.hip | Adds hipify-generated hash translation unit. |
| src/geometry.cu | Switches CUB include to hipcub on ROCm and updates runtime error checking to HIP. |
| src/geometry.hip | Adds hipify-generated geometry translation unit. |
| src/dtypes.cuh | Adds HIP runtime include path and adjusts Vec3f constructors for hipcub compatibility. |
| src/dtypes_hip.cuh | Adds hipify-generated dtypes header. |
| src/cumesh.h | Adds HIP/CUDA conditional runtime header include. |
| src/cumesh_hip.h | Adds hipify-generated public HIP header for CuMesh. |
| src/cumesh.hip | Adds hipify-generated CuMesh translation unit. |
| src/connectivity.cu | Switches CUB include to hipcub on ROCm and migrates many allocations/calls toward HIP/hipcub. |
| src/connectivity.hip | Adds hipify-generated connectivity translation unit. |
| src/clean_up.cu | Migrates multiple allocations/CUB calls toward HIP/hipcub and adjusts tuple decomposer for ROCm. |
| src/atlas.cu | Migrates multiple allocations/CUB calls toward HIP/hipcub and adjusts reduce-by-key op selection. |
| src/ext_hip.cpp | Adds hipify-generated extension binding source. |
| setup.py | Sets ROCm default arch to gfx942 and gates CUDA-only nvcc flags behind IS_HIP. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
12
to
+22
| #define CUDA_CHECK(call) \ | ||
| do { \ | ||
| const cudaError_t error_code = call; \ | ||
| if (error_code != cudaSuccess) { \ | ||
| const hipError_t error_code = call; \ | ||
| if (error_code != hipSuccess) { \ | ||
| TORCH_CHECK(false, \ | ||
| "[CuMesh] CUDA error:\n", \ | ||
| "[CuMesh] HIP error:\n", \ | ||
| " File: ", __FILE__, "\n", \ | ||
| " Line: ", __LINE__, "\n", \ | ||
| " Error code: ", error_code, "\n", \ | ||
| " Error text: ", \ | ||
| cudaGetErrorString(error_code), "\n"); \ | ||
| hipGetErrorString(error_code), "\n"); \ |
Comment on lines
44
to
+50
| void init(size_t capacity) { | ||
| this->capacity = capacity; | ||
| CUDA_CHECK(cudaMalloc(&ptr, capacity * sizeof(T))); | ||
| CUDA_CHECK(hipMalloc(&ptr, capacity * sizeof(T))); | ||
| } | ||
|
|
||
| void free() { | ||
| if (ptr != nullptr) CUDA_CHECK(cudaFree(ptr)); | ||
| if (ptr != nullptr) CUDA_CHECK(hipFree(ptr)); |
| #ifdef __HIP_PLATFORM_AMD__ | ||
| #include <hipcub/hipcub.hpp> | ||
| #else | ||
| #include <cub/cub.cuh> |
Comment on lines
87
to
103
| @@ -99,7 +99,7 @@ static torch::Tensor buffer_to_tensor(const Buffer<T> buffer) { | |||
| sizeof(T), | |||
| dst_bytes, | |||
| count, | |||
| cudaMemcpyDeviceToDevice | |||
| hipMemcpyDeviceToDevice | |||
| )); | |||
| #ifdef __HIP_PLATFORM_AMD__ | ||
| #include <hipcub/hipcub.hpp> | ||
| #else | ||
| #include <cub/cub.cuh> |
Comment on lines
+1
to
+12
| // !!! This is a file automatically generated by hipify!!! | ||
| #include <torch/extension.h> | ||
| #include "hash/api.h" | ||
| #include "cumesh_hip.h" | ||
| #include "remesh/api.h" | ||
|
|
||
|
|
||
| PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) { | ||
| // Hash functions | ||
| m.def("hashmap_insert_cuda", &cumesh::hashmap_insert_cuda); | ||
| m.def("hashmap_lookup_cuda", &cumesh::hashmap_lookup_cuda); | ||
| m.def("hashmap_insert_3d_cuda", &cumesh::hashmap_insert_3d_cuda); |
| #include <hip/hip_runtime.h> | ||
| #else | ||
| #include <hip/hip_runtime.h> | ||
| #include <hip/hip_runtime.h> |
| #ifdef __HIP_PLATFORM_AMD__ | ||
| #include <hipcub/hipcub.hpp> | ||
| #else | ||
| #include <cub/cub.cuh> |
| #ifdef __HIP_PLATFORM_AMD__ | ||
| #include <hipcub/hipcub.hpp> | ||
| #else | ||
| #include <cub/cub.cuh> |
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.
Summary
Port CuMesh to support AMD ROCm GPUs (MI300X / gfx942) via HIP.
Changes
#ifdef __HIP_PLATFORM_AMD__guards for cross-compilation::cuda::std::tuple→::rocprim::tuplefor DeviceRadixSort decomposerVec3fdefault constructor added for hipcubDeviceSegmentedReducecompatibilitygfx942, CUDA-only flags gated behindIS_HIPTesting
import cumeshsucceeds on AMD MI300X__HIP_PLATFORM_AMD__)Motivation
TRELLIS.2's
setup.shalready detects ROCm and installs ROCm PyTorch, but CuMesh's CUDA-specific code prevents it from building on AMD GPUs. This PR enables the full TRELLIS.2 pipeline on AMD hardware.