Skip to content

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

Open
jeffdaily wants to merge 3 commits into
facebookresearch:mainfrom
AMD-Ecosystem:moat-port
Open

[ROCm] Add HIP/ROCm support for AMD GPUs#10
jeffdaily wants to merge 3 commits into
facebookresearch:mainfrom
AMD-Ecosystem:moat-port

Conversation

@jeffdaily

Copy link
Copy Markdown

Summary

Adds support for building and running BaSpaCho on AMD GPUs via HIP/ROCm. The port uses a minimal-footprint approach: a cuda_to_hip.h compat header aliases the CUDA APIs to their HIP equivalents while keeping the source files in CUDA spelling, and CMake marks the .cu files LANGUAGE HIP when building with -DUSE_HIP=ON. The default CUDA build is unchanged. The README documents the HIP/ROCm build alongside the CUDA build.

Library substitutions (behind USE_HIP): cuBLAS -> hipBLAS (GEMM, TRSM, SYMM, batched variants), cuSOLVER -> hipSOLVER (potrf, potrfBatched), cuSPARSE -> hipSPARSE.

It also carries the Windows/amdclang++ build fixes needed to compile the GPU target on Windows, all behind _WIN32 guards so the Linux build is byte-identical: a typeid-name fallback where abi::__cxa_demangle is libstdc++-only, <malloc.h> for alloca, localtime_s for localtime_r, and a few MSVC-ABI type and overload fixes.

Test Plan

Built with -DUSE_HIP=ON and ran the ctest suite on three AMD architectures:

cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DUSE_HIP=ON -DCMAKE_HIP_ARCHITECTURES=<arch> -DBASPACHO_USE_BLAS=ON
cmake --build build -- -j$(nproc)
HIP_VISIBLE_DEVICES=0 ctest --test-dir build --output-on-failure
GPU Arch OS / ROCm ctest
Instinct MI250X gfx90a (CDNA2) Linux, ROCm 7.2.1 124/125
Radeon Pro W7800 gfx1100 (RDNA3) Linux, ROCm 7.2.1 124/125
Radeon RX 9070 XT gfx1201 (RDNA4) Windows, ROCm 7.14 124/125

The single failure (BatchedCudaFactor.CoalescedFactor_Many_float) is a float32 FMA rounding tolerance overshoot (5.06e-05 vs the 5.0e-05 threshold) identical across all GPU architectures including NVIDIA, not a ROCm-specific issue. The CPU build is unaffected.

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

Add support for building and running BaSpaCho on AMD GPUs via HIP/ROCm. The port
uses a minimal-footprint approach: a cuda_to_hip.h compat header aliases the CUDA
APIs to their HIP equivalents while keeping the source files in CUDA spelling, and
CMake marks the .cu files LANGUAGE HIP when building with -DUSE_HIP=ON. The default
CUDA build is unchanged. The README documents the HIP/ROCm build alongside the CUDA
build.

Library substitutions (behind USE_HIP):
- cuBLAS -> hipBLAS (GEMM, TRSM, SYMM, batched variants)
- cuSOLVER -> hipSOLVER (potrf, potrfBatched)
- cuSPARSE -> hipSPARSE

It also carries the Windows/amdclang++ build fixes needed to compile the GPU target
on Windows, all behind _WIN32 guards so the Linux build is byte-identical: a
typeid-name fallback where abi::__cxa_demangle is libstdc++-only, <malloc.h> for
alloca, localtime_s for localtime_r, and a few MSVC-ABI type and overload fixes.

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

Test Plan:

Built with -DUSE_HIP=ON and ran the ctest suite on three AMD architectures:

```
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DUSE_HIP=ON \
  -DCMAKE_HIP_ARCHITECTURES=<arch> -DBASPACHO_USE_BLAS=ON
cmake --build build -- -j$(nproc)
HIP_VISIBLE_DEVICES=0 ctest --test-dir build --output-on-failure
```

- gfx90a (Instinct MI250X, CDNA2), Linux ROCm 7.2.1: 124/125
- gfx1100 (Radeon Pro W7800, RDNA3), Linux ROCm 7.2.1: 124/125
- gfx1201 (Radeon RX 9070 XT, RDNA4), Windows ROCm 7.14: 124/125

The single failure (BatchedCudaFactor.CoalescedFactor_Many_float) is a float32 FMA
rounding tolerance overshoot (5.06e-05 vs the 5.0e-05 threshold) identical across all
GPU architectures including NVIDIA, not a ROCm-specific issue. The CPU build is unaffected.
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 10, 2026
The HIP/ROCm build section calls find_package on hipBLAS / hipSOLVER /
hipSPARSE, but on a clean ROCm container where ROCm is not on the default
CMake search path the configure step fails with hipBLAS/hipSOLVER/
hipSPARSE-NOTFOUND. Setting -DCMAKE_HIP_COMPILER to an absolute path or
exporting ROCM_PATH does not fix this; CMake's find_package only locates the
ROCm config packages when the install prefix is searched. Adding
-DCMAKE_PREFIX_PATH=/opt/rocm (or placing /opt/rocm/bin on PATH) resolves it.

Add the flag to the documented configure command and note that the prefix
must point at the ROCm install when it is not already on the search path.

Authored with the assistance of an AI coding agent.
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.
@maurimo

maurimo commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

This is great... I am very busy but will review as soon as I have a moment, thank a lot for contributing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. module: rocm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants