-
Notifications
You must be signed in to change notification settings - Fork 0
enable upstream MONAI to build and run on AMD Instinct GPUs (MI300X/MI325X/MI355X). #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,133 @@ | ||||||||||
| # Copyright (c) MONAI Consortium | ||||||||||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||
| # you may not use this file except in compliance with the License. | ||||||||||
| # You may obtain a copy of the License at | ||||||||||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||
| # Unless required by applicable law or agreed to in writing, software | ||||||||||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||
| # See the License for the specific language governing permissions and | ||||||||||
| # limitations under the License. | ||||||||||
|
|
||||||||||
| # MONAI on AMD ROCm (AMD Instinct MI300X / MI325X / MI355X). | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can drop the exact enumeration - just mention AMD Instinct.
Suggested change
|
||||||||||
| # | ||||||||||
| # The default Dockerfile builds on the NVIDIA PyTorch container, which has no ROCm | ||||||||||
| # equivalent, so ROCm gets its own recipe rather than a branch inside that one. | ||||||||||
|
Comment on lines
+14
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Delete this line.
Suggested change
|
||||||||||
| # This image installs the upstream `monai` package -- it is not a separate | ||||||||||
| # distribution and does not rename the wheel. | ||||||||||
|
Comment on lines
+16
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| # | ||||||||||
| # docker build -f Dockerfile.rocm -t monai:rocm . | ||||||||||
| # | ||||||||||
| # docker run --device=/dev/kfd --device=/dev/dri --group-add video \ | ||||||||||
| # --ipc=host --shm-size=8g -it monai:rocm | ||||||||||
| # | ||||||||||
| # Select the GPU architecture with --build-arg AMDGPU_TARGETS=...: | ||||||||||
| # gfx942 MI300X, MI325X (default) | ||||||||||
| # gfx950 MI355X | ||||||||||
|
Comment on lines
+24
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
|
||||||||||
| ARG BASE_IMAGE=ubuntu:24.04 | ||||||||||
| FROM ${BASE_IMAGE} | ||||||||||
|
|
||||||||||
| LABEL maintainer="monai.contact@gmail.com" | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest we remove this. We don't own this email and can't ask people to contact them for ROCm. |
||||||||||
|
|
||||||||||
| ARG AMDGPU_TARGETS="gfx942" | ||||||||||
| ARG ROCM_SERIES="10.0" | ||||||||||
| ARG ROCM_INDEX_URL="https://stable.repo.amd.com/rocm/whl-next/" | ||||||||||
|
|
||||||||||
| ENV DEBIAN_FRONTEND=noninteractive | ||||||||||
|
|
||||||||||
| # build-essential/cmake/ninja-build are not optional: MONAI JIT-compiles its C++/HIP | ||||||||||
| # extensions at first use via torch.utils.cpp_extension, which aborts with | ||||||||||
| # "RuntimeError: Ninja is required to load C++ extensions" when ninja is absent. | ||||||||||
| # libopenslide-dev is the whole-slide-image backend; libgomp1 is needed by OpenMP. | ||||||||||
| RUN apt-get update \ | ||||||||||
| && apt-get install -y --no-install-recommends \ | ||||||||||
| ca-certificates curl git openssh-client \ | ||||||||||
| python3-venv python3-pip python3-dev \ | ||||||||||
| build-essential cmake ninja-build yasm \ | ||||||||||
| libgomp1 libstdc++-13-dev \ | ||||||||||
| libopenslide-dev libwebp-dev libzstd-dev \ | ||||||||||
| && rm -rf /var/lib/apt/lists/* | ||||||||||
|
|
||||||||||
| RUN python3 -m venv /opt/venv | ||||||||||
| ENV PATH="/opt/venv/bin:${PATH}" | ||||||||||
| RUN pip install --no-cache-dir --upgrade pip wheel | ||||||||||
|
|
||||||||||
| # ROCm runtime, devel headers and a matching ROCm build of PyTorch. Installed in one | ||||||||||
| # resolve so the SDK and torch agree on a single ROCm version. | ||||||||||
| RUN pip install --no-cache-dir --index-url ${ROCM_INDEX_URL} \ | ||||||||||
| "rocm[libraries,devel,device-${AMDGPU_TARGETS}]==${ROCM_SERIES}.*" \ | ||||||||||
| "torch[device-${AMDGPU_TARGETS}]" \ | ||||||||||
| "torchvision[device-${AMDGPU_TARGETS}]" \ | ||||||||||
| torchaudio \ | ||||||||||
| && rocm-sdk init | ||||||||||
|
|
||||||||||
| 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" | ||||||||||
| ENV PATH="${ROCM_PATH}/bin:${PATH}" | ||||||||||
| ENV LD_LIBRARY_PATH="${ROCM_PATH}/lib:${ROCM_PATH}/lib/rocm_sysdeps/lib:${ROCM_PATH}/lib/llvm/lib:${ROCM_LIBRARIES_PATH}/lib" | ||||||||||
| ENV CPATH="${ROCM_DEVEL_PATH}/include:/usr/lib/gcc/x86_64-linux-gnu/13/include" | ||||||||||
| ENV LIBRARY_PATH="${ROCM_DEVEL_PATH}/lib:${ROCM_PATH}/lib" | ||||||||||
| ENV AMDGPU_TARGETS=${AMDGPU_TARGETS} | ||||||||||
| ENV PYTORCH_ROCM_ARCH=${AMDGPU_TARGETS} | ||||||||||
|
|
||||||||||
| # hipcc resolves GPU bitcode relative to ROCM_PATH/amdgcn. | ||||||||||
| RUN mkdir -p "${ROCM_PATH}/amdgcn" \ | ||||||||||
| && ln -sf "${ROCM_PATH}/lib/llvm/amdgcn/bitcode" "${ROCM_PATH}/amdgcn/bitcode" | ||||||||||
|
|
||||||||||
| # MIOpen writes its compiled-kernel database at runtime. If it inherits a read-only | ||||||||||
| # location, convolutions fail outright with "RuntimeError: miopenStatusInternalError" | ||||||||||
| # rather than degrading, so point it somewhere world-writable inside the image. | ||||||||||
| ENV MIOPEN_USER_DB_PATH="/tmp/miopen" | ||||||||||
| ENV MIOPEN_CUSTOM_CACHE_DIR="/tmp/miopen" | ||||||||||
| RUN mkdir -p /tmp/miopen && chmod 1777 /tmp/miopen | ||||||||||
|
Comment on lines
+83
to
+85
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are risky and prone to clashes if multiple users are on the same node. |
||||||||||
|
|
||||||||||
| # OpenBLAS spawns a thread per core and can exhaust thread limits under MONAI's | ||||||||||
| # multiprocessing dataloaders on high-core-count Instinct hosts. | ||||||||||
| ENV OMP_NUM_THREADS=1 | ||||||||||
|
|
||||||||||
| WORKDIR /opt/monai | ||||||||||
|
|
||||||||||
| COPY LICENSE CHANGELOG.md CODE_OF_CONDUCT.md CONTRIBUTING.md README.md versioneer.py setup.py pyproject.toml runtests.sh MANIFEST.in ./ | ||||||||||
| COPY tests ./tests | ||||||||||
| COPY monai ./monai | ||||||||||
|
|
||||||||||
| # The "all" extra is installed via print_dependencies.py rather than as -e .[all,testing] | ||||||||||
| # so that cucim, nvidia-ml-py, and nni can be filtered out: | ||||||||||
| # cucim-cu13 → cupy-cuda13x[ctk] → cuda-toolkit → ~1.2 GB of nvidia-* wheels unusable on ROCm | ||||||||||
| # nvidia-ml-py loads libnvidia-ml.so.1 at import time; absent on ROCm, breaks collection | ||||||||||
| # nni hard-depends on nvidia-ml-py | ||||||||||
|
Comment on lines
+97
to
+101
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If possible, avoid the mention of NVIDIA. |
||||||||||
| # hipCIM is the ROCm equivalent of cucim and is installed in the optional layer below. | ||||||||||
| # | ||||||||||
| # BUILD_MONAI is intentionally NOT set here. docker build has no GPU device (/dev/kfd, | ||||||||||
| # /dev/dri are not mounted), so torch.cuda.is_available() returns False and the C++/HIP | ||||||||||
| # extensions compile as CPU-only stubs. Setting BUILD_MONAI=1 would silently produce a | ||||||||||
| # broken _C module. Instead, extensions JIT-compile at first use when the container is | ||||||||||
| # run with --device=/dev/kfd --device=/dev/dri, at which point the GPU is present and | ||||||||||
| # hipcc can target the correct architecture. | ||||||||||
| RUN python monai/config/print_dependencies.py build-system \ | ||||||||||
| | xargs -d '\n' pip install --no-cache-dir --no-build-isolation \ | ||||||||||
| && python monai/config/print_dependencies.py all testing \ | ||||||||||
| | grep -vE '^cucim-cu|^nvidia-ml-py|^nni' > /tmp/rocm-requirements.txt \ | ||||||||||
| && pip install --no-cache-dir --no-build-isolation \ | ||||||||||
| -r /tmp/rocm-requirements.txt -e . | ||||||||||
|
|
||||||||||
| # Whole-slide-image support on ROCm is provided by hipCIM rather than cucim, which is | ||||||||||
| # CUDA-only. It is not currently published on PyPI at a usable version, so it is an | ||||||||||
|
Comment on lines
+117
to
+118
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Comment on lines
+117
to
+118
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is it not usable? The 26.08 release is already public and should be usable. |
||||||||||
| # optional layer: pass --build-arg HIPCIM_INDEX_URL=<index> to enable WSI workloads. | ||||||||||
| ARG HIPCIM_INDEX_URL="" | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the published URL based on the 26.08 release. |
||||||||||
| RUN if [ -n "${HIPCIM_INDEX_URL}" ]; then \ | ||||||||||
| pip install --no-cache-dir --extra-index-url "${HIPCIM_INDEX_URL}" "amd-hipcim" \ | ||||||||||
| && python -c "import cucim; print('hipCIM', cucim.__version__)"; \ | ||||||||||
| else \ | ||||||||||
| echo "hipCIM not installed; whole-slide-image (cucim) backends are unavailable."; \ | ||||||||||
| fi | ||||||||||
|
|
||||||||||
| RUN python -c "import torch, monai; \ | ||||||||||
| print('MONAI :', monai.__version__); \ | ||||||||||
| print('PyTorch:', torch.__version__); \ | ||||||||||
| print('ROCm :', torch.version.hip)" | ||||||||||
|
|
||||||||||
| CMD ["bash"] | ||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we are adding this file, then copyright should be AMD, not MONAI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we need add AMD copy right banner