Skip to content

Add HIP backend for AMD ROCm support - #663

Open
paralin wants to merge 2 commits into
PufferAI:4.0from
paralin:rocm-hipify-fused-trainer
Open

Add HIP backend for AMD ROCm support#663
paralin wants to merge 2 commits into
PufferAI:4.0from
paralin:rocm-hipify-fused-trainer

Conversation

@paralin

@paralin paralin commented Aug 25, 2026

Copy link
Copy Markdown

Translate the CUDA training sources to HIP with HIPIFY and build them with hipcc, so the fused trainer runs on AMD GPUs. The CUDA build path is unchanged; everything new is additive.

  • src-hip/ holds the hipified bindings, kernels, models, muon, and pufferlib sources, plus a cuda->HIP forwarding shim used by the C env libraries and a stub NVML header (utilization reads as zeros).
  • src/vecenv.h maps its small CUDA surface onto HIP equivalents under HIP_PLATFORM_AMD; other platforms keep the existing declarations.
  • build-hip.sh mirrors build.sh: it compiles the static env library, then builds pufferlib/_C with hipcc --offload-arch= linking amdhip64, hipblas, hiprand, rocrand, and rccl.

Verified on an RX 7700 XT (gfx1101) with ROCm 7.2.2: cartpole trains through the fused rollout path at ~6M SPS.

@paralin
paralin force-pushed the rocm-hipify-fused-trainer branch from 14e0ca1 to 16d4d73 Compare August 26, 2026 02:24
@paralin
paralin marked this pull request as draft August 26, 2026 02:25
Translate the CUDA training sources to HIP with HIPIFY and build them
with hipcc, so the fused trainer runs on AMD GPUs. The CUDA/cuDNN build
path is unchanged; everything new is additive.

- src-hip/ holds the hipified bindings, kernels, models, muon, ocean,
  and pufferlib sources, plus a cuda->HIP forwarding shim used by the C
  env libraries and a stub NVML header (utilization reads as zeros).
- The conv encoder path has dual implementations: NVIDIA builds keep
  src/cudnn_conv2d.cu (cuDNN) untouched via ocean.cu, while AMD builds
  use src-hip/cudnn_conv2d.hip.cpp (MIOpen) with an identical interface
  via ocean.hip.cpp. Forward is miopenConvolutionForward with bias +
  in-place ReLU; backward uses the MIOpen weights/data kernels. The
  nethack encoder is not ported.
- src/vecenv.h maps its small CUDA surface onto HIP equivalents under
  __HIP_PLATFORM_AMD__; other platforms keep the existing declarations.
- build-hip.sh mirrors build.sh: it compiles the static env library,
  then builds pufferlib/_C with hipcc --offload-arch=<arch> linking
  amdhip64, hipblas, hiprand, rocrand, rccl, and MIOpen.

Verified on an RX 7700 XT (gfx1101) with ROCm 7.2.2: cartpole trains
through the fused rollout path at ~6M SPS.
@paralin
paralin force-pushed the rocm-hipify-fused-trainer branch from 16d4d73 to 8ecbb7b Compare August 26, 2026 02:27
@paralin paralin changed the title Add HIP backend for the fused PPO trainer on AMD ROCm Add HIP backend for AMD ROCm support Aug 26, 2026
@paralin
paralin marked this pull request as ready for review August 26, 2026 02:27
Remove the duplicate convolution include guard and link the MIOpen
library explicitly. This lets HIP environments compile when the fused
trainer includes the convolution encoder source.

Signed-off-by: Christian Stewart <christian@aperture.us>
@paralin
paralin force-pushed the rocm-hipify-fused-trainer branch from 437889e to 2a52210 Compare August 26, 2026 14:59
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.

1 participant