Skip to content

Instantly share code, notes, and snippets.

@kklemon
Created April 3, 2026 12:17
Show Gist options
  • Select an option

  • Save kklemon/c368cdba7b361c37a34326f4293e1ee5 to your computer and use it in GitHub Desktop.

Select an option

Save kklemon/c368cdba7b361c37a34326f4293e1ee5 to your computer and use it in GitHub Desktop.
rocm-onnx-migraphx gfx1103 dockerfile
# Multi-stage build for a ROCm + MIGraphX + ONNX Runtime image on Ubuntu 24.04.
#
# This Dockerfile intentionally uses:
# - A remote TheRock checkout as the ROCm source tree.
# - A separate AMDMIGraphX build, because this TheRock checkout does not
# currently build/install MIGraphX itself.
# - ONNX Runtime's MIGraphX execution provider, not the deprecated ROCm EP.
#
# Build example:
# docker build \
# -f dockerfiles/rocm_onnxruntime_migraphx_ubuntu24_04_gfx1103.Dockerfile \
# --build-arg THEROCK_REF=main \
# -t therock-onnxruntime-migraphx:gfx1103 \
# dockerfiles/
#
# Run example:
# docker run --rm -it \
# --device=/dev/kfd --device=/dev/dri \
# --ipc=host \
# --group-add=video --group-add=render \
# therock-onnxruntime-migraphx:gfx1103
ARG UBUNTU_VERSION=24.04
FROM ubuntu:${UBUNTU_VERSION} AS therock-build
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
ENV DEBIAN_FRONTEND=noninteractive
ARG AMDGPU_TARGET=gfx1103
ARG AMDGPU_FAMILY=gfx110X-igpu
ARG THEROCK_BUILD_TYPE=Release
ARG THEROCK_REPO=https://github.com/ROCm/TheRock.git
ARG THEROCK_REF=main
RUN apt-get update && apt-get install -y --no-install-recommends \
automake \
bison \
build-essential \
ca-certificates \
cmake \
curl \
flex \
gfortran \
git \
-DTHEROCK_ENABLE_CORE_RUNTIME=ON \
-DTHEROCK_ENABLE_HIP_RUNTIME=ON \
-DTHEROCK_ENABLE_BLAS=ON \
-DTHEROCK_ENABLE_RAND=ON \
-DTHEROCK_ENABLE_MIOPEN=ON \
-DTHEROCK_ENABLE_COMPOSABLE_KERNEL=OFF \
-DTHEROCK_AMDGPU_FAMILIES="${AMDGPU_FAMILY}" \
-DTHEROCK_DIST_AMDGPU_FAMILIES="${AMDGPU_FAMILY}"
RUN source .venv/bin/activate && \
cmake --build build --target install-rocm --parallel "$(nproc)"
FROM ubuntu:${UBUNTU_VERSION} AS migraphx-build
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
ENV DEBIAN_FRONTEND=noninteractive
ARG AMDGPU_TARGET=gfx1103
ARG AMDMIGRAPHX_REF=rocm-7.2.1
COPY --from=therock-build /opt/rocm /opt/rocm
ENV ROCM_HOME=/opt/rocm
ENV ROCM_PATH=/opt/rocm
ENV HIP_PATH=/opt/rocm
ENV PATH="/opt/rocm/bin:/opt/rocm/llvm/bin:${PATH}"
ENV LD_LIBRARY_PATH="/opt/rocm/lib:/opt/rocm/llvm/lib:${LD_LIBRARY_PATH}"
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
ca-certificates \
cmake \
curl \
git \
libgfortran5 \
libnuma-dev \
libtbb-dev \
make \
ninja-build \
pkg-config \
python3 \
python3-dev \
python3-pip \
python3-venv \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /src
RUN git clone --depth=1 --branch "${AMDMIGRAPHX_REF}" \
https://github.com/ROCm/AMDMIGraphX.git /src/AMDMIGraphX
WORKDIR /src/AMDMIGraphX
RUN python3 -m venv /opt/rbuild-venv && \
source /opt/rbuild-venv/bin/activate && \
pip install --upgrade pip setuptools wheel && \
pip install https://github.com/RadeonOpenCompute/rbuild/archive/master.tar.gz && \
rbuild prepare -d /opt/migraphx-deps -s develop
ENV CMAKE_PREFIX_PATH="/opt/rocm:/opt/migraphx-deps"
ENV LD_LIBRARY_PATH="/opt/migraphx-deps/lib:/opt/migraphx-deps/lib64:/opt/rocm/lib:/opt/rocm/llvm/lib:${LD_LIBRARY_PATH}"
ENV PATH="/opt/migraphx-deps/bin:${PATH}"
RUN cmake -S . -B build -GNinja \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/opt/rocm \
-DCMAKE_PREFIX_PATH="/opt/rocm;/opt/migraphx-deps" \
-DBUILD_TESTING=OFF \
-DMIGRAPHX_ENABLE_PYTHON=OFF \
-DMIGRAPHX_USE_COMPOSABLEKERNEL=OFF \
-DGPU_TARGETS="${AMDGPU_TARGET}" \
-DCMAKE_C_COMPILER=/opt/rocm/llvm/bin/clang \
-DCMAKE_CXX_COMPILER=/opt/rocm/llvm/bin/clang++ && \
cmake --build build --parallel "$(nproc)" && \
cmake --install build
FROM ubuntu:${UBUNTU_VERSION} AS onnxruntime-build
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
ENV DEBIAN_FRONTEND=noninteractive
ARG ONNXRUNTIME_REF=v1.24.4
COPY --from=migraphx-build /opt/rocm /opt/rocm
COPY --from=migraphx-build /opt/migraphx-deps /opt/migraphx-deps
ENV ROCM_HOME=/opt/rocm
ENV ROCM_PATH=/opt/rocm
ENV HIP_PATH=/opt/rocm
ENV CMAKE_PREFIX_PATH="/opt/rocm"
ENV HIP_DEVICE_LIB_PATH="/opt/rocm/lib/llvm/amdgcn/bitcode"
ENV PATH="/opt/migraphx-deps/bin:/opt/rocm/bin:/opt/rocm/llvm/bin:${PATH}"
ENV LD_LIBRARY_PATH="/opt/migraphx-deps/lib:/opt/migraphx-deps/lib64:/opt/rocm/lib:/opt/rocm/llvm/lib:${LD_LIBRARY_PATH}"
ENV HIP_PLATFORM=amd
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
ca-certificates \
cmake \
curl \
git \
ninja-build \
pkg-config \
python3 \
python3-dev \
python3-pip \
python3-venv \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /src
RUN git clone --recursive --shallow-submodules --depth=1 --branch "${ONNXRUNTIME_REF}" \
https://github.com/microsoft/onnxruntime.git /src/onnxruntime
WORKDIR /src/onnxruntime
RUN python3 -m venv /opt/ort-venv && \
source /opt/ort-venv/bin/activate && \
pip install --upgrade pip setuptools wheel numpy && \
./build.sh \
--config Release \
--build_shared_lib \
--build_wheel \
--parallel "$(nproc)" \
--allow_running_as_root \
--cmake_generator Ninja \
--use_migraphx \
--migraphx_home /opt/rocm \
--skip_tests \
--skip_submodule_sync \
--cmake_extra_defines \
CMAKE_PREFIX_PATH=/opt/rocm \
migraphx_DIR=/opt/rocm/lib/cmake/migraphx \
FETCHCONTENT_TRY_FIND_PACKAGE_MODE=NEVER \
Python_EXECUTABLE=/opt/ort-venv/bin/python \
Python3_EXECUTABLE=/opt/ort-venv/bin/python
FROM ubuntu:${UBUNTU_VERSION}
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
ENV DEBIAN_FRONTEND=noninteractive
COPY --from=therock-build /src/TheRock/dockerfiles/install_rocm_deps.sh /tmp/install_rocm_deps.sh
RUN chmod +x /tmp/install_rocm_deps.sh && \
/tmp/install_rocm_deps.sh && \
apt-get update && apt-get install -y --no-install-recommends \
libgfortran5 \
libtbb12 \
&& rm -rf /var/lib/apt/lists/* /tmp/install_rocm_deps.sh
COPY --from=migraphx-build /opt/rocm /opt/rocm
COPY --from=migraphx-build /opt/migraphx-deps /opt/migraphx-deps
COPY --from=onnxruntime-build /src/onnxruntime/build/Linux/Release/dist /tmp/onnxruntime-dist
RUN python3 -m pip install --break-system-packages /tmp/onnxruntime-dist/*.whl && \
rm -rf /tmp/onnxruntime-dist
ENV ROCM_HOME=/opt/rocm
ENV ROCM_PATH=/opt/rocm
ENV HIP_PATH=/opt/rocm
ENV CMAKE_PREFIX_PATH="/opt/rocm:/opt/migraphx-deps"
ENV HIP_DEVICE_LIB_PATH="/opt/rocm/lib/llvm/amdgcn/bitcode"
ENV PATH="/opt/migraphx-deps/bin:/opt/rocm/bin:/opt/rocm/llvm/bin:${PATH}"
ENV LD_LIBRARY_PATH="/opt/migraphx-deps/lib:/opt/migraphx-deps/lib64:/opt/rocm/lib:/opt/rocm/llvm/lib:${LD_LIBRARY_PATH}"
# Runtime workaround for Radeon 780M / gfx1103.
ENV HSA_OVERRIDE_GFX_VERSION=11.0.2
WORKDIR /app
CMD ["python3"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment