Skip to content

[ROCm] Fix HIP build on systems with partial GCC installs and off-PATH amdgpu-arch - #1

Merged
jeffdaily merged 1 commit into
AMD-Ecosystem:moat-portfrom
mycpuorg:rocm-build-fixes
Jun 12, 2026
Merged

[ROCm] Fix HIP build on systems with partial GCC installs and off-PATH amdgpu-arch#1
jeffdaily merged 1 commit into
AMD-Ecosystem:moat-portfrom
mycpuorg:rocm-build-fixes

Conversation

@mycpuorg

Copy link
Copy Markdown

Stacked on the moat-port branch behind karpathy#854 — two small Makefile fixes for portability of the USE_HIP=1 build:

  1. Partial GCC installs break the build. ROCm's clang selects the highest /usr/lib/gcc/<triple>/<ver> dir even when that GCC's libstdc++ headers are absent (e.g. Ubuntu 24.04 ships libgcc-14-dev without libstdc++-14-dev), failing with Could not find standard C++ header 'cmath'. The Makefile now probes hipcc with a syntax-only compile and, when it fails, pins --gcc-install-dir to the newest GCC version that has matching headers under /usr/include/c++/<ver>.

  2. Silent gfx90a fallback when amdgpu-arch is off PATH. The tool ships in <rocm>/llvm/bin, which is often not on PATH, so arch auto-detection silently fell back to gfx90a and produced binaries that cannot run on the local GPUs. Detection now locates the tool via hipconfig --rocmpath as a fallback.

Testing

On 2x AMD Radeon AI PRO R9700 (gfx1201, RDNA4), ROCm 7.1.0, Ubuntu 24.04:

  • test_gpt2fp32cu and test_gpt2cu (default, -r 0, -r 2, -w 0, -b 32): all overall okay: 1 — on gfx1201 all 16/16 grad tensors pass, including ln1b/lnfb
  • FP32 train_gpt2cu 10-step run vs PyTorch reference (dev/loss_checker_ci.py): success, max deviation 0.18%
  • BF16 train_gpt2cu on tinyshakespeare: train loss 4.29 → 3.38, val loss 3.50, coherent samples, no NaNs, ~49k tok/s
  • CPU regression: test_gpt2 overall okay: 1; dev/test dataloader tests all OK

…H amdgpu-arch

Two Makefile fixes for the USE_HIP=1 build:

1. ROCm's clang selects the highest /usr/lib/gcc/<triple>/<ver> dir even
   when that GCC's libstdc++ headers are absent (e.g. Ubuntu installs
   libgcc-14-dev without libstdc++-14-dev), failing with "Could not find
   standard C++ header 'cmath'". Probe hipcc with a syntax-only compile
   and, when it fails, pin --gcc-install-dir to the newest GCC version
   that has matching headers under /usr/include/c++/<ver>.

2. amdgpu-arch often is not on PATH (it ships in <rocm>/llvm/bin), which
   made the arch auto-detection silently fall back to gfx90a and produce
   binaries that cannot run on the local GPUs. Locate the tool via
   hipconfig --rocmpath when it is not on PATH.

Tested on 2x AMD Radeon AI PRO R9700 (gfx1201), ROCm 7.1.0:
test_gpt2fp32cu and test_gpt2cu (default, -r 0/2, -w 0, -b 32) all pass;
FP32 train_gpt2cu matches the PyTorch reference losses (loss_checker_ci
max diff 0.18%); BF16 tinyshakespeare run reaches val loss 3.50 with no
NaNs; CPU test_gpt2 and dev/test dataloader tests unaffected.
@jeffdaily
jeffdaily merged commit de1dd62 into AMD-Ecosystem:moat-port Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants