Skip to content

Port libtorchaudio GPU extensions to build under ROCm/HIP#16

Closed
ethanwee1 wants to merge 2 commits into
ROCm:release/2.11.0.1from
ethanwee1:ew/rocm-24803-hip-port-gpu-ext
Closed

Port libtorchaudio GPU extensions to build under ROCm/HIP#16
ethanwee1 wants to merge 2 commits into
ROCm:release/2.11.0.1from
ethanwee1:ew/rocm-24803-hip-port-gpu-ext

Conversation

@ethanwee1

Copy link
Copy Markdown

The torch CUDAExtension HIPIFY path only rewrites source files, not
headers, so CUDA symbols used in headers survived un-hipified and broke
the ROCm build (e.g. "cuda_runtime_api.h file not found", and the
rnnt/forced_align GPU kernels were entirely gated behind #ifdef USE_CUDA).

- Add cuda_compat.h mapping the CUDA runtime names used in headers
  (cudaStream_t, cudaError_t, cudaSuccess, cudaGetErrorString,
  cudaGetLastError) to their HIP equivalents under USE_ROCM. HIP
  natively supports the <<<>>> launch syntax and warp shuffle
  intrinsics already guarded in the kernels.
- Extend the #ifdef USE_CUDA guards in the rnnt GPU headers, macros.h,
  options.h, and cuctc headers to also cover USE_ROCM, including HIP
  fp16/runtime headers.
ethanwee1 added a commit to ROCm/pytorch that referenced this pull request Jul 1, 2026
Temporarily points torchaudio at the ROCm/audio#16 HIP-port commit
(ethanwee1/audio fork) so TheRock can build/validate it. Repoint to the
merged ROCm/audio release/2.11.0.1 commit once ROCm/audio#16 lands.
@ethanwee1

Copy link
Copy Markdown
Author

TheRock test build (Windows gfx110X-all) exercising this HIP port via ROCm/pytorch#3382:
https://github.com/ROCm/TheRock/actions/runs/28488199046

- cuda_compat.h: alias the CUDA runtime functions/enums used by the
  sources (cudaSetDevice, cudaMemcpy*, cudaMemset*, cudaStreamSynchronize,
  cudaGetErrorName, cudaMemcpy kinds) to HIP under USE_ROCM.
- Route cub through hipcub (namespace cub = hipcub) under USE_ROCM in
  forced_align and cuctc kernels.
- Enable Options::stream_ for USE_ROCM.
- ctc_prefix_decoder.cpp includes cuda_compat.h instead of cuda_runtime.h.
@ethanwee1

Copy link
Copy Markdown
Author

Build with hipcub + runtime shim + Options::stream_ (via ROCm/pytorch#3382):
https://github.com/ROCm/TheRock/actions/runs/28529085509

Fixes this round: cuda_compat.h now aliases the CUDA runtime funcs used by the sources (cudaSetDevice/cudaMemcpy*/cudaMemset*/cudaStreamSynchronize/cudaGetErrorName), cub routed through hipcub, and Options::stream_ enabled for USE_ROCM.

jithunnair-amd pushed a commit to ROCm/pytorch that referenced this pull request Jul 1, 2026
https://amd-hub.atlassian.net/browse/ROCM-24803?focusedCommentId=500051

Interim unblock: pins torchaudio to the stable release/2.11 (2.11.0),
which already builds and publishes on Windows, replacing the floating
pytorch/audio main (2.11.0a0) pin.

The torchaudio 2.11.0.1 ROCm GPU port is tracked separately in
#3382 and ROCm/audio#16.
@ethanwee1

Copy link
Copy Markdown
Author

Superseded by the HIPIFY-based approach (mirrors torchvision's setup.py) instead of a hand-written CUDA->HIP compat shim.

@ethanwee1 ethanwee1 closed this Jul 1, 2026
ethanwee1 added a commit to ROCm/pytorch that referenced this pull request Jul 6, 2026
…io#16)

Revert the temporary HIPIFY-based pin (ROCm/audio#17) back to the
compat-shim port commit that passed TheRock Windows validation
(28529085509). The HIPIFY setup.py approach still leaves CUDA headers
unconverted; the cuda_compat.h port in ROCm/audio#16 is the validated path.

The Windows cross-drive HIPIFY fix remains in torch/utils/cpp_extension.py
(this PR); it is unrelated to the audio-side port strategy.
@ethanwee1 ethanwee1 reopened this Jul 6, 2026
@ethanwee1

Copy link
Copy Markdown
Author

Reopened — this is the validated port path. ROCm/pytorch#3382 pin repointed back here (a890448a). #17 (HIPIFY in extension.py) closed as superseded.

Validated TheRock Windows build: https://github.com/ROCm/TheRock/actions/runs/28529085509

@ethanwee1

Copy link
Copy Markdown
Author

Superseded by #17 (HIPIFY). The compat-shim approach validated on TheRock 28529085509 but is not the desired long-term port; #17 v2 (0c7509e) fixes hipify scope, realpath, and header guards.

@ethanwee1 ethanwee1 closed this Jul 6, 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.

1 participant