From ebf74a34c195139fcefde302ae1d64618a39c501 Mon Sep 17 00:00:00 2001 From: Robert Oswald <47303535+robertosw@users.noreply.github.com> Date: Sat, 3 Oct 2026 12:45:44 +0200 Subject: [PATCH] Add ROCm Dockerfile --- docker/Dockerfile.rocm | 49 ++++++++++++++++++++++++++++++++++++++++++ docs/docker.md | 6 ++++++ 2 files changed, 55 insertions(+) create mode 100644 docker/Dockerfile.rocm diff --git a/docker/Dockerfile.rocm b/docker/Dockerfile.rocm new file mode 100644 index 0000000000..428a6ab102 --- /dev/null +++ b/docker/Dockerfile.rocm @@ -0,0 +1,49 @@ +FROM rocm/dev-ubuntu-24.04 AS build + +# sd-server embeds the web UI at build time, so the build image needs Node/pnpm. +RUN apt-get update && apt-get install -y --no-install-recommends \ + build-essential git cmake ninja-build ccache ca-certificates curl gnupg && \ + mkdir -p /etc/apt/keyrings && \ + curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key -o /tmp/nodesource-repo.gpg.key && \ + gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg /tmp/nodesource-repo.gpg.key && \ + rm /tmp/nodesource-repo.gpg.key && \ + echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" > /etc/apt/sources.list.d/nodesource.list && \ + apt-get update && apt-get install -y --no-install-recommends nodejs && \ + npm install -g pnpm@10.15.1 && \ + apt-get clean && rm -rf /var/lib/apt/lists/* + +WORKDIR /sd.cpp + +# ROCm's clang is not on PATH in Docker RUN shells (profile scripts are not loaded). +ENV PATH="/opt/rocm/llvm/bin:$PATH" + +COPY . . + +ARG AMDGPU_TARGETS=gfx1100 + +RUN cmake . -B ./build -G Ninja \ + -DCMAKE_C_COMPILER=clang \ + -DCMAKE_CXX_COMPILER=clang++ \ + -DSD_HIPBLAS=ON \ + -DAMDGPU_TARGETS=${AMDGPU_TARGETS} \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON \ + -DCMAKE_POSITION_INDEPENDENT_CODE=ON +RUN cmake --build ./build --config Release --parallel + +FROM rocm/dev-ubuntu-24.04 AS runtime + +# ROCm clang links against its own OpenMP runtime in /opt/rocm/llvm/lib, +# and the ROCm runtime libs (hipblas, rocblas, amdhip64) live in /opt/rocm/lib. +ENV LD_LIBRARY_PATH="/opt/rocm/llvm/lib:/opt/rocm/lib:$LD_LIBRARY_PATH" + +RUN apt-get update && \ + apt-get install --yes --no-install-recommends libgomp1 && \ + apt-get clean && rm -rf /var/lib/apt/lists/* + +COPY --from=build /sd.cpp/build/bin /sd.cpp/bin +RUN printf '#!/bin/sh\nexec /sd.cpp/bin/sd-cli "$@"\n' > /sd-cli && \ + printf '#!/bin/sh\nexec /sd.cpp/bin/sd-server "$@"\n' > /sd-server && \ + chmod +x /sd-cli /sd-server + +ENTRYPOINT [ "/sd-cli" ] diff --git a/docs/docker.md b/docs/docker.md index 5bacdd2d4b..0dc106e29d 100644 --- a/docs/docker.md +++ b/docs/docker.md @@ -30,6 +30,12 @@ Vulkan: docker build -f docker/Dockerfile.vulkan -t sd . ``` +ROCm (AMD GPU): + +```shell +docker build -f docker/Dockerfile.rocm --build-arg AMDGPU_TARGETS=gfx1100 -t sd . +``` + ## Run locally built image's CLI ```shell