[ROCm] Add HIP/ROCm support for AMD GPUs - #10
Open
jeffdaily wants to merge 3 commits into
Open
Conversation
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.
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.
Contributor
|
This is great... I am very busy but will review as soon as I have a moment, thank a lot for contributing. |
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
Adds support for building and running BaSpaCho on AMD GPUs via HIP/ROCm. The port uses a minimal-footprint approach: a
cuda_to_hip.hcompat header aliases the CUDA APIs to their HIP equivalents while keeping the source files in CUDA spelling, and CMake marks the.cufilesLANGUAGE HIPwhen 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
_WIN32guards so the Linux build is byte-identical: a typeid-name fallback whereabi::__cxa_demangleis libstdc++-only,<malloc.h>foralloca,localtime_sforlocaltime_r, and a few MSVC-ABI type and overload fixes.Test Plan
Built with
-DUSE_HIP=ONand ran the ctest suite on three AMD architectures: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.