[ROCm] Fix the HIP GPU build for ROCm 7 and a wave64 LSTM bug#4986
Open
jeffdaily wants to merge 1 commit into
Open
[ROCm] Fix the HIP GPU build for ROCm 7 and a wave64 LSTM bug#4986jeffdaily wants to merge 1 commit into
jeffdaily wants to merge 1 commit into
Conversation
Kaldi already ships a ROCm/HIP GPU backend (configure --use-rocm, the
src/makefiles/hip_64bit.mk toolchain block, and the src/hip/hipify.h compat
header). It was written against ROCm 5.0-5.2 and had bit-rotted: it no longer
builds on ROCm 7, and once built it computed a wrong result on 64-wide
wavefronts. This change brings the existing backend back to green on a current
ROCm and makes it correct on both 32- and 64-lane GPUs.
Review it in three parts:
1. Build break on ROCm 7. cu-kernels.cu and feature-online-cmvn-cuda.cu defined
__CUDA_ARCH__=800 before including <hipcub/hipcub.hpp>. On hipcc that
suppressed the __gfx90a__ device macro, so rocPRIM fell through to a generic
path that fails to compile against the ROCm 7 headers. The CUDA-version and
warp definitions are reordered/guarded so hipcub sees the real device macros;
the CUDA build is unchanged.
2. wave64 correctness. cu-math-test's UnitTestBackpropLstmNonlinearity was the
one cudamatrix test that failed before the fix. The LSTM nonlinearity kernel
partitioned a 256-thread block into 256/warpSize groups, assuming that value
is 8. It is 8 on a 32-lane warp (NVIDIA, RDNA) but 4 on a 64-lane wavefront
(CDNA, gfx90a), so rows past the fourth were left unprocessed. The kernel now
derives the host warp size rather than assuming 32.
3. Multi-arch builds. The host warp size is resolved at runtime so a single
build serves both wave32 and wave64 targets; --rocm-targets can list several
GPUs (for example gfx90a,gfx1100) in one configure.
Documentation and attribution: configure's header gains a --use-rocm worked
example next to the existing --use-cuda one, and the cudamatrix files extended
here carry an AMD copyright line.
Scope: Linux. The configure ROCm path is POSIX-only by design (it gates on a
Linux host); the Windows .sln build documents no GPU support upstream, so the
GPU backend is built and tested on Linux.
Test Plan:
cd tools && make -j"$(nproc)" openfst
cd ../src && ./configure --use-rocm --rocm-dir=/opt/rocm \
--rocm-targets=gfx90a --use-cuda=no
make -j"$(nproc)" depend && make -j"$(nproc)"
cd cudamatrix && make test
All 12 cudamatrix correctness unit tests pass on an AMD Instinct MI250X
(gfx90a), ROCm 7.2.1 -- including cu-math-test's UnitTestBackpropLstmNonlinearity,
which fails without the wave64 fix. The same branch builds and passes the
cudamatrix tests on an RDNA3 GPU (gfx1100) via --rocm-targets=gfx1100.
This work was authored with assistance from Claude (Anthropic).
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.
Kaldi already ships a ROCm/HIP GPU backend (
configure --use-rocm, thesrc/makefiles/hip_64bit.mktoolchain block, and thesrc/hip/hipify.hcompat header). It was written against ROCm 5.0-5.2 and had bit-rotted: it no longer builds on ROCm 7, and once built it computed a wrong result on 64-wide wavefronts. This change brings the existing backend back to green on a current ROCm and makes it correct on both 32- and 64-lane GPUs.Review it in three parts:
Build break on ROCm 7.
cu-kernels.cuandfeature-online-cmvn-cuda.cudefined__CUDA_ARCH__=800before including<hipcub/hipcub.hpp>. On hipcc that suppressed the__gfx90a__device macro, so rocPRIM fell through to a generic path that fails to compile against the ROCm 7 headers. The CUDA-version and warp definitions are reordered/guarded so hipcub sees the real device macros; the CUDA build is unchanged.wave64 correctness.
cu-math-test'sUnitTestBackpropLstmNonlinearitywas the one cudamatrix test that failed before the fix. The LSTM nonlinearity kernel partitioned a 256-thread block into256/warpSizegroups, assuming that value is 8. It is 8 on a 32-lane warp (NVIDIA, RDNA) but 4 on a 64-lane wavefront (CDNA, gfx90a), so rows past the fourth were left unprocessed. The kernel now derives the host warp size rather than assuming 32.Multi-arch builds. The host warp size is resolved at runtime (via
hipDeviceGetAttribute) so a single build serves both wave32 and wave64 targets;--rocm-targetscan list several GPUs (for examplegfx90a,gfx1100) in one configure, and each kernel launch selects its tiling from the running device's wavefront width.Documentation and attribution: configure's header gains a
--use-rocmworked example next to the existing--use-cudaone, and the cudamatrix files extended here carry an AMD copyright line.Scope: Linux. The configure ROCm path is POSIX-only by design (it gates on a Linux host); the Windows .sln build documents no GPU support upstream, so the GPU backend is built and tested on Linux.
Test Plan:
All 12 cudamatrix correctness unit tests pass on an AMD Instinct MI250X (gfx90a), ROCm 7.2.1, including
cu-math-test'sUnitTestBackpropLstmNonlinearity, which fails without the wave64 fix. The same branch builds and passes the cudamatrix tests on an RDNA3 GPU (gfx1100) via--rocm-targets=gfx1100, and a combinedgfx90a,gfx1100build passes as well. The CUDA path was compile-checked unchanged with nvcc 12.8 (sm_80).This work was authored with assistance from Claude (Anthropic).