[ROCm] Add AMD GPU support via PyTorch hipify#31
Open
jeffdaily wants to merge 1 commit into
Open
Conversation
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.
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.
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.dlldoes not export the inheritedc10::ValueError(SourceLocation, string)constructor (MSVC does not re-export inherited constructors even forC10_APIclasses). Headers pulled in via<torch/extension.h>triggerTORCH_CHECK_VALUE, which generates a dllimport reference to that constructor and fails to link with LNK2001. A win32-only/ALTERNATENAMElinker directive redirects the missing thunk toc10::Error(SourceLocation, string), which is exported;ValueErrorIS-AErrorwith no additional data members, so the redirect is semantically safe. The directive is guarded bysys.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 ordinarypip installworks on ROCm and thatPYTORCH_ROCM_ARCHselects the target architecture.Test Plan
Build against a ROCm PyTorch and run the suite on an AMD GPU:
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.