Conversation
MONAI runs on ROCm unmodified for the most part, since a ROCm build of PyTorch presents itself as `cuda`. Three places assume a CUDA toolkit specifically, and the Docker image has no ROCm equivalent. setup.py: `CUDA_HOME` is None on a ROCm torch, where the toolkit is found via `ROCM_HOME` instead, so BUILD_CUDA evaluated False and the C++/HIP extensions were silently skipped. Accept either. `CUDAExtension` hipifies the .cu sources transparently, so no source changes are needed. monai/_extensions/loader.py: the JIT build cache key included `torch.version.cuda`, which is None on ROCm, so every ROCm toolkit version collided on one cache entry. Fall back to `torch.version.hip`. tests/networks/nets/test_densenet.py: test_pretrain_consistency compares two separately-constructed module graphs holding identical weights for bit-exactness. The backend may select different convolution algorithms per graph, so this was never guaranteed; skip it on ROCm. Dockerfile.rocm: the default Dockerfile builds on the NVIDIA PyTorch container, so ROCm gets its own recipe. It installs the ROCm SDK and a matching PyTorch from AMD's public index, filters the CUDA-only extras (cucim-cu*, nvidia-ml-py, nni), and installs hipCIM, which provides the `cucim` module that MONAI's whole-slide-image paths need on ROCm. Assisted-by: Claude Opus 5 <noreply@anthropic.com> Signed-off-by: Patel, Nilaykumar K <NilaykumarKantibhai.Patel@amd.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (4)
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughAdds a configurable ROCm container recipe for MONAI. Extension detection now accepts PyTorch’s Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~20 minutes Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to No confirmed issue currently prevents merging. The container build should still receive its normal validation. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 3 files. (1 skipped: 1 unsupported.)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| "ROCm may select different conv algorithms per graph; bit-exactness not guaranteed.", | ||
| ) | ||
| def test_pretrain_consistency(self, model, input_param, input_shape): | ||
| if torch.version.hip is not None: |
There was a problem hiding this comment.
Is this needed with the decorator?
| ENV ROCM_PATH="/opt/venv/lib/python3.12/site-packages/_rocm_sdk_core" | ||
| ENV ROCM_HOME="${ROCM_PATH}" | ||
| ENV ROCM_DEVEL_PATH="/opt/venv/lib/python3.12/site-packages/_rocm_sdk_devel" | ||
| ENV ROCM_LIBRARIES_PATH="/opt/venv/lib/python3.12/site-packages/_rocm_sdk_libraries" |
There was a problem hiding this comment.
| ENV ROCM_PATH="/opt/venv/lib/python3.12/site-packages/_rocm_sdk_core" | |
| ENV ROCM_HOME="${ROCM_PATH}" | |
| ENV ROCM_DEVEL_PATH="/opt/venv/lib/python3.12/site-packages/_rocm_sdk_devel" | |
| ENV ROCM_LIBRARIES_PATH="/opt/venv/lib/python3.12/site-packages/_rocm_sdk_libraries" | |
| ARG PYTHON_VER=3.12 | |
| ENV ROCM_PATH="/opt/venv/lib/python${PYTHON_VER}/site-packages/_rocm_sdk_core" | |
| ENV ROCM_HOME="${ROCM_PATH}" | |
| ENV ROCM_DEVEL_PATH="/opt/venv/lib/python${PYTHON_VER}/site-packages/_rocm_sdk_devel" | |
| ENV ROCM_LIBRARIES_PATH="/opt/venv/lib/python${PYTHON_VER}/site-packages/_rocm_sdk_libraries" |
I'd suggest making the Python version an ARG here, if BASE_IMAGE is set to some other image then the Python that comes with it may be different from 3.12 so users would need an ARG to change it as well.
|
|
||
| # Use print_dependencies.py rather than -e .[all,testing] to filter CUDA-only packages: | ||
| # cucim-cu* pulls in cuda-toolkit (~1.2 GB); nvidia-ml-py fails at import on ROCm; nni depends on it. | ||
| # BUILD_MONAI is not set: docker build has no GPU, so extensions JIT-compile at container runtime. |
There was a problem hiding this comment.
BUILD_MONAI does need to be set for MONAI to actually use the compiled code at runtime. This is buried in the code unfortunately and is something we should update to make clearer or change the behaviour. If the argument causes a problem in this RUN it should be set afterward
ericspod
left a comment
There was a problem hiding this comment.
hi @nilapate thanks for this, we're happy to support ROCm in MONAI but we do have the issue of having no means to test it. The Dockerfile for example isn't something we can test without AMD hardware so we would have to rely on users to report any issues. I made a few comments about minor things but the changes look good to me as they are, if you can address things we should be good to merge once tests get through.
Fixes #9152.
Description
Minimal ROCm enablement for AMD Instinct GPUs. Most of MONAI is already portable; this fixes the few places that assume a single GPU toolkit, plus adds a container recipe.
setup.py—CUDA_HOMEis unset on a ROCm build, where the toolkit is located viaROCM_HOME, soBUILD_CUDAevaluatedFalseand the C++ extensions were silently skipped. Accept either.CUDAExtensionhandles the source translation, so no kernel source changes are needed.monai/_extensions/loader.py— the JIT build cache key includedtorch.version.cuda, unset on ROCm, so every ROCm toolkit version collided on one cache entry. Fall back totorch.version.hip.tests/networks/nets/test_densenet.py—test_pretrain_consistencycompares two separately-constructed module graphs holding identical weights for bit-exactness. Convolution algorithm selection is free to differ between the graphs, so this was never a guaranteed property; skipped on ROCm for now.Dockerfile.rocm— the defaultDockerfileuses a vendor-specific base image, so ROCm gets its own recipe. Installs the ROCm SDK and a matching PyTorch, filters packages that don't apply on this platform (cucim-cu*,nvidia-ml-py,nni), and installs hipCIM to provide thecucimmodule the whole-slide-image paths need.3 lines of library code changed; everything else is additive. Existing code paths are unchanged — both edits short-circuit on the current value, so CUDA and CPU-only behaviour is identical.
Validated on MI300X (gfx942); MI355X (gfx950) validated separately.
tests/networks/layers/test_gmm.pypasses (5 passed), which exercises theloader.pychange through a real JIT extension build.Types of changes
./runtests.sh -f -u --net --coverage../runtests.sh --quick --unittests --disttests.make htmlcommand in thedocs/folder.