Skip to content

[ROCm] Add AMD GPU support via PyTorch hipify#31

Open
jeffdaily wants to merge 1 commit into
ivan-chai:mainfrom
jeffdaily:moat-port
Open

[ROCm] Add AMD GPU support via PyTorch hipify#31
jeffdaily wants to merge 1 commit into
ivan-chai:mainfrom
jeffdaily:moat-port

Conversation

@jeffdaily

Copy link
Copy Markdown

This adds AMD GPU (ROCm) support. The CUDA backend is a PyTorch CUDAExtension, so building it against a ROCm build of PyTorch runs hipify at build time to translate the CUDA sources to HIP automatically. No changes to the CUDA kernel or host C++ sources are required, and the CUDA build path is unchanged.

Two changes support the ROCm build:

  • setup.py: on Windows, c10.dll does not export the inherited c10::ValueError(SourceLocation, string) constructor (MSVC does not re-export inherited constructors even for C10_API classes). Headers pulled in via <torch/extension.h> trigger TORCH_CHECK_VALUE, which generates a dllimport reference to that constructor and fails to link with LNK2001. A win32-only /ALTERNATENAME linker directive redirects the missing thunk to c10::Error(SourceLocation, string), which is exported; ValueError IS-A Error with no additional data members, so the redirect is semantically safe. The directive is guarded by sys.platform == "win32" and does not affect Linux or the CUDA build. This is fixed upstream by [c10] Fix missing symbol exports for ValueError/NotImplementedError on Windows pytorch/pytorch#175340, so the directive can be removed once that fix is in the minimum supported PyTorch.
  • README: a note in the install section explaining that the ordinary pip install works on ROCm and that PYTORCH_ROCM_ARCH selects the target architecture.

Test Plan

Build against a ROCm PyTorch and run the suite on an AMD GPU:

PYTORCH_ROCM_ARCH=gfx1100 pip install -e .
pytest tests/

On Linux gfx1100 (Radeon Pro W7800, ROCm 7.2.1) and Windows gfx1201 (RX 9070 XT) the full suite passes 3/3 (test_simple, test_cuda_equal_to_cpu, test_compare_to_scipy). On Linux gfx90a (MI250X) the assignment checks pass with valid, optimal, deterministic GPU assignments. The CUDA build path is unchanged.

Authored with assistance from Claude.

This adds AMD GPU (ROCm) support. The CUDA backend is a PyTorch
CUDAExtension, so building it against a ROCm build of PyTorch runs hipify at
build time to translate the CUDA sources to HIP automatically. No changes to
the CUDA kernel or host C++ sources are required, and the CUDA build path is
unchanged.

Two changes support the ROCm build:

- setup.py: on Windows, c10.dll does not export the inherited
  c10::ValueError(SourceLocation, string) constructor (MSVC does not
  re-export inherited constructors even for C10_API classes). Headers pulled
  in via <torch/extension.h> trigger TORCH_CHECK_VALUE, which generates a
  dllimport reference to that constructor and fails to link with LNK2001. A
  win32-only /ALTERNATENAME linker directive redirects the missing thunk to
  c10::Error(SourceLocation, string), which is exported; ValueError IS-A
  Error with no additional data members, so the redirect is semantically
  safe. The directive is guarded by sys.platform == "win32" and does not
  affect Linux or the CUDA build. This is fixed upstream by
  pytorch/pytorch#175340, so the directive can be removed once that fix is in
  the minimum supported PyTorch.

- README: a note in the install section explaining that the ordinary pip
  install works on ROCm and that PYTORCH_ROCM_ARCH selects the target
  architecture.

Test Plan:

Build against a ROCm PyTorch and run the suite on an AMD GPU:

    PYTORCH_ROCM_ARCH=gfx1100 pip install -e .
    pytest tests/

On Linux gfx1100 (Radeon Pro W7800, ROCm 7.2.1) and Windows gfx1201 (RX 9070
XT) the full suite passes 3/3 (test_simple, test_cuda_equal_to_cpu,
test_compare_to_scipy). On Linux gfx90a (MI250X) the assignment checks pass
with valid, optimal, deterministic GPU assignments. The CUDA build path is
unchanged.

Authored with assistance from Claude.
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