From ef5815589782ed30f7273c2ccb7a423730f9f68d Mon Sep 17 00:00:00 2001 From: Hermes Date: Sat, 9 May 2026 21:18:37 -0400 Subject: [PATCH 01/21] feat: add custom ollama image with ROCm 6.1 + gfx906 support - Add ollama/Dockerfile that builds ollama from source with AMDGPU_TARGETS=gfx906 - Uses ROCm 6.1 (rocm/dev-ubuntu-22.04:6.1.2-complete) for MI50 support - Builds llama.cpp runner with HIPBLAS for gfx906 architecture - Updates compose.yml to build from this Dockerfile instead of pulling ollama/ollama:latest --- ai/compose.yml | 5 +++- ai/ollama/Dockerfile | 57 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 ai/ollama/Dockerfile diff --git a/ai/compose.yml b/ai/compose.yml index b8590dc..e5d9c4b 100644 --- a/ai/compose.yml +++ b/ai/compose.yml @@ -58,7 +58,10 @@ services: - ai_backend ollama: - image: ollama/ollama:latest + build: + context: ./ollama + dockerfile: Dockerfile + image: ollama/ollama:rocm-gfx906 container_name: ollama privileged: true tty: true diff --git a/ai/ollama/Dockerfile b/ai/ollama/Dockerfile new file mode 100644 index 0000000..aca5f3a --- /dev/null +++ b/ai/ollama/Dockerfile @@ -0,0 +1,57 @@ +# ollama-gfx906/Dockerfile +# +# Custom ollama image with ROCm 6.1 + gfx906 (MI50) support. +# The default ollama/rocm image ships ROCm 7.2 which dropped gfx906 support. +# This builds ollama from source targeting AMDGPU_TARGETS=gfx906. +# +# Build: docker build -t ollama/ollama:rocm-gfx906 . + +FROM rocm/dev-ubuntu-22.04:6.1.2-complete AS builder + +RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \ + git golang cmake build-essential pkg-config \ + && rm -rf /var/lib/apt/lists/* + +ARG OLLAMA_VERSION=v0.13.5 +RUN git clone --depth 1 --branch ${OLLAMA_VERSION} https://github.com/ollama/ollama.git /build +WORKDIR /build + +ENV HIP_PATH=/opt/rocm +ENV ROCM_PATH=/opt/rocm +ENV PATH=/opt/rocm/bin:/opt/rocm/hip/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin +RUN cd llama.cpp && \ + mkdir build && cd build && \ + cmake .. \ + -DLLAMA_HIPBLAS=ON \ + -DCMAKE_C_COMPILER=clang \ + -DCMAKE_CXX_COMPILER=clang++ \ + -DAMDGPU_TARGETS=gfx906 \ + -DCMAKE_BUILD_TYPE=Release \ + -DLLAMA_NATIVE=OFF \ + -DLLAMA_BUILD_TESTS=OFF \ + -DLLAMA_BUILD_EXAMPLES=OFF \ + -DLLAMA_BUILD_SERVER=OFF && \ + cmake --build . --config Release -j$(nproc) && \ + cmake --install . --prefix /build/dist + +ENV CGO_ENABLED=0 +RUN go build -trimpath -o dist/ollama . + +FROM ubuntu:22.04 + +RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \ + ca-certificates curl libstdc++6 libgomp1 \ + && rm -rf /var/lib/apt/lists/* + +COPY --from=builder /opt/rocm/lib/ /opt/rocm/lib/ +COPY --from=builder /opt/rocm/share/ /opt/rocm/share/ +COPY --from=builder /build/dist/ollama /usr/bin/ollama +COPY --from=builder /build/dist/lib/ /usr/lib/ollama/ + +RUN ldconfig + +ENV LD_LIBRARY_PATH=/opt/rocm/lib:/usr/lib/ollama +ENV HSA_OVERRIDE_GFX_VERSION=9.0.6 + +EXPOSE 11434 +CMD ["serve"] From d34a4d3647e6a265f7f52042eded9a8272bd2f1e Mon Sep 17 00:00:00 2001 From: Hermes Date: Sat, 9 May 2026 21:50:04 -0400 Subject: [PATCH 02/21] refactor: move hermes files into ai/hermes/ subdirectory - ai/Dockerfile -> ai/hermes/Dockerfile - ai/fix-permissions.sh -> ai/hermes/fix-permissions.sh - ai/patch_tts_tool.py -> ai/hermes/patch_tts_tool.py - ai/compose.yml: update hermes build context to ./hermes - ollama stays at ai/ollama/Dockerfile --- ai/compose.yml | 2 +- ai/{ => hermes}/Dockerfile | 0 ai/{ => hermes}/fix-permissions.sh | 0 ai/{ => hermes}/patch_tts_tool.py | 0 4 files changed, 1 insertion(+), 1 deletion(-) rename ai/{ => hermes}/Dockerfile (100%) rename ai/{ => hermes}/fix-permissions.sh (100%) rename ai/{ => hermes}/patch_tts_tool.py (100%) diff --git a/ai/compose.yml b/ai/compose.yml index e5d9c4b..dceb490 100644 --- a/ai/compose.yml +++ b/ai/compose.yml @@ -26,7 +26,7 @@ services: # - "traefik.http.routers.webui-https.tls.certresolver=njalla" hermes: - build: ./ + build: ./hermes container_name: hermes restart: always # Gateway run enables the internal API server on port 8642 diff --git a/ai/Dockerfile b/ai/hermes/Dockerfile similarity index 100% rename from ai/Dockerfile rename to ai/hermes/Dockerfile diff --git a/ai/fix-permissions.sh b/ai/hermes/fix-permissions.sh similarity index 100% rename from ai/fix-permissions.sh rename to ai/hermes/fix-permissions.sh diff --git a/ai/patch_tts_tool.py b/ai/hermes/patch_tts_tool.py similarity index 100% rename from ai/patch_tts_tool.py rename to ai/hermes/patch_tts_tool.py From f023dc1ee415c3440f09a3be89662e53ef10da51 Mon Sep 17 00:00:00 2001 From: Hermes Date: Sat, 9 May 2026 21:56:14 -0400 Subject: [PATCH 03/21] fix: update ollama Dockerfile to v0.23.2 with proper ROCm 6.1 + gfx906 build - Update OLLAMA_VERSION from v0.13.5 to v0.23.2 - Fix package: golang -> golang-go - Add ENV HCC_AMDGPU_TARGET=gfx906 and HSA_ENABLE_SDMA=0 - Set proper ENTRYPOINT + CMD --- ai/ollama/Dockerfile | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/ai/ollama/Dockerfile b/ai/ollama/Dockerfile index aca5f3a..88cc8b3 100644 --- a/ai/ollama/Dockerfile +++ b/ai/ollama/Dockerfile @@ -2,17 +2,17 @@ # # Custom ollama image with ROCm 6.1 + gfx906 (MI50) support. # The default ollama/rocm image ships ROCm 7.2 which dropped gfx906 support. -# This builds ollama from source targeting AMDGPU_TARGETS=gfx906. +# This builds ollama and its llama.cpp runner from source, targeting gfx906. # -# Build: docker build -t ollama/ollama:rocm-gfx906 . +# Build: docker build -t ollama/ollama:rocm-gfx906 ./ai/ollama FROM rocm/dev-ubuntu-22.04:6.1.2-complete AS builder RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \ - git golang cmake build-essential pkg-config \ + git golang-go cmake build-essential pkg-config \ && rm -rf /var/lib/apt/lists/* -ARG OLLAMA_VERSION=v0.13.5 +ARG OLLAMA_VERSION=v0.23.2 RUN git clone --depth 1 --branch ${OLLAMA_VERSION} https://github.com/ollama/ollama.git /build WORKDIR /build @@ -20,7 +20,7 @@ ENV HIP_PATH=/opt/rocm ENV ROCM_PATH=/opt/rocm ENV PATH=/opt/rocm/bin:/opt/rocm/hip/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin RUN cd llama.cpp && \ - mkdir build && cd build && \ + mkdir -p build && cd build && \ cmake .. \ -DLLAMA_HIPBLAS=ON \ -DCMAKE_C_COMPILER=clang \ @@ -52,6 +52,9 @@ RUN ldconfig ENV LD_LIBRARY_PATH=/opt/rocm/lib:/usr/lib/ollama ENV HSA_OVERRIDE_GFX_VERSION=9.0.6 +ENV HCC_AMDGPU_TARGET=gfx906 +ENV HSA_ENABLE_SDMA=0 EXPOSE 11434 +ENTRYPOINT ["/bin/ollama"] CMD ["serve"] From c6d2f5918fbbd2b23a3c55f88e56e87fb4a5a09b Mon Sep 17 00:00:00 2001 From: Hermes Date: Sat, 9 May 2026 22:13:47 -0400 Subject: [PATCH 04/21] fix: use ollama v0.23.2 native CMake build system for ROCm 6 + gfx906 The old Dockerfile used the deprecated llama.cpp/ subdirectory approach which doesn't exist in ollama v0.23.2. Now using the official CMake presets (ROCm 6 preset) with AMDGPU_TARGETS including gfx906:xnack-. --- ai/ollama/Dockerfile | 68 ++++++++++++++++++++++++++++++-------------- 1 file changed, 46 insertions(+), 22 deletions(-) diff --git a/ai/ollama/Dockerfile b/ai/ollama/Dockerfile index 88cc8b3..4b92e82 100644 --- a/ai/ollama/Dockerfile +++ b/ai/ollama/Dockerfile @@ -1,50 +1,74 @@ # ollama-gfx906/Dockerfile # # Custom ollama image with ROCm 6.1 + gfx906 (MI50) support. -# The default ollama/rocm image ships ROCm 7.2 which dropped gfx906 support. -# This builds ollama and its llama.cpp runner from source, targeting gfx906. +# The official ollama/rocm image ships ROCm 7.2 which dropped gfx906. +# This uses v0.23.2's native CMake build system with AMDGPU_TARGETS including gfx906. # -# Build: docker build -t ollama/ollama:rocm-gfx906 ./ai/ollama +# Build: docker build -t ollama/ollama:rocm-gfx906 ai/ollama FROM rocm/dev-ubuntu-22.04:6.1.2-complete AS builder +# Build dependencies (CMake, Ninja, Go) +ARG CMAKEVERSION=3.31.2 +ARG NINJAVERSION=1.12.1 +ARG GOLANG_VERSION=1.22.0 + RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \ - git golang-go cmake build-essential pkg-config \ + curl git ccache build-essential pkg-config \ && rm -rf /var/lib/apt/lists/* +# Install CMake from official binaries +RUN curl -fsSL https://github.com/Kitware/CMake/releases/download/v${CMAKEVERSION}/cmake-${CMAKEVERSION}-linux-x86_64.tar.gz \ + | tar xz -C /usr/local --strip-components 1 + +# Install Ninja +RUN curl -fsSL -o /tmp/ninja.zip \ + https://github.com/ninja-build/ninja/releases/download/v${NINJAVERSION}/ninja-linux.zip \ + && unzip /tmp/ninja.zip -d /usr/local/bin && rm /tmp/ninja.zip + +# Install Go +RUN curl -fsSL https://go.dev/dl/go${GOLANG_VERSION}.linux-amd64.tar.gz \ + | tar xz -C /usr/local +ENV PATH=/usr/local/go/bin:$PATH + ARG OLLAMA_VERSION=v0.23.2 RUN git clone --depth 1 --branch ${OLLAMA_VERSION} https://github.com/ollama/ollama.git /build WORKDIR /build +# ROCm paths from the base image ENV HIP_PATH=/opt/rocm ENV ROCM_PATH=/opt/rocm -ENV PATH=/opt/rocm/bin:/opt/rocm/hip/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin -RUN cd llama.cpp && \ - mkdir -p build && cd build && \ +ENV PATH=/opt/rocm/bin:/opt/rocm/hip/bin:/opt/rocm/hcc/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin +ENV CMAKE_GENERATOR=Ninja +ENV LDFLAGS=-s + +# Build with ROCm 6 preset + gfx906 target +RUN mkdir -p build && cd build && \ cmake .. \ - -DLLAMA_HIPBLAS=ON \ - -DCMAKE_C_COMPILER=clang \ - -DCMAKE_CXX_COMPILER=clang++ \ - -DAMDGPU_TARGETS=gfx906 \ - -DCMAKE_BUILD_TYPE=Release \ - -DLLAMA_NATIVE=OFF \ - -DLLAMA_BUILD_TESTS=OFF \ - -DLLAMA_BUILD_EXAMPLES=OFF \ - -DLLAMA_BUILD_SERVER=OFF && \ - cmake --build . --config Release -j$(nproc) && \ - cmake --install . --prefix /build/dist + --preset 'ROCm 6' \ + -DAMDGPU_TARGETS="gfx906:xnack-;gfx940;gfx1010;gfx1030;gfx1100;gfx1200" \ + -DCMAKE_BUILD_TYPE=Release && \ + cmake --build . -- -l $(nproc) && \ + cmake --install . --component HIP --strip --prefix /build/dist -ENV CGO_ENABLED=0 -RUN go build -trimpath -o dist/ollama . +# Build the Go binary +ENV CGO_ENABLED=1 +ENV CC=clang +ENV CXX=clang++ +RUN go build -trimpath -o /build/dist/ollama . -FROM ubuntu:22.04 +# ---------- Runtime image ---------- +FROM ubuntu:24.04 RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \ - ca-certificates curl libstdc++6 libgomp1 \ + ca-certificates curl libstdc++6 libgomp1 libvulkan1 libopenblas0 \ && rm -rf /var/lib/apt/lists/* +# Copy ROCm 6.1 runtime libraries COPY --from=builder /opt/rocm/lib/ /opt/rocm/lib/ COPY --from=builder /opt/rocm/share/ /opt/rocm/share/ + +# Copy ollama binary and backend COPY --from=builder /build/dist/ollama /usr/bin/ollama COPY --from=builder /build/dist/lib/ /usr/lib/ollama/ From 956d76f14db063017dd893991e3f86fe6f1b3b81 Mon Sep 17 00:00:00 2001 From: Hermes Date: Sat, 9 May 2026 22:14:53 -0400 Subject: [PATCH 05/21] fix: add unzip dependency for ninja installation --- ai/ollama/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ai/ollama/Dockerfile b/ai/ollama/Dockerfile index 4b92e82..335987f 100644 --- a/ai/ollama/Dockerfile +++ b/ai/ollama/Dockerfile @@ -14,7 +14,7 @@ ARG NINJAVERSION=1.12.1 ARG GOLANG_VERSION=1.22.0 RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \ - curl git ccache build-essential pkg-config \ + curl git ccache build-essential pkg-config unzip \ && rm -rf /var/lib/apt/lists/* # Install CMake from official binaries From a3d0fa0072a954a3f0bf44096df5bacc65fb25bb Mon Sep 17 00:00:00 2001 From: Hermes Date: Sat, 9 May 2026 22:19:50 -0400 Subject: [PATCH 06/21] fix: set CMAKE_HIP_COMPILER explicitly for ROCm 6.1 HIP detection --- ai/ollama/Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/ai/ollama/Dockerfile b/ai/ollama/Dockerfile index 335987f..170ecc6 100644 --- a/ai/ollama/Dockerfile +++ b/ai/ollama/Dockerfile @@ -47,6 +47,7 @@ RUN mkdir -p build && cd build && \ cmake .. \ --preset 'ROCm 6' \ -DAMDGPU_TARGETS="gfx906:xnack-;gfx940;gfx1010;gfx1030;gfx1100;gfx1200" \ + -DCMAKE_HIP_COMPILER=/opt/rocm/bin/hipcc \ -DCMAKE_BUILD_TYPE=Release && \ cmake --build . -- -l $(nproc) && \ cmake --install . --component HIP --strip --prefix /build/dist From d8b77c97c34ef541c3e8aa3462561f4b99c4c03f Mon Sep 17 00:00:00 2001 From: Hermes Date: Sat, 9 May 2026 22:20:44 -0400 Subject: [PATCH 07/21] fix: use CXX=hipcc legacy mode for HIP CMake build CMake 3.31 refuses CMAKE_HIP_COMPILER=hipcc with 'not supported'. Using CXX=hipcc triggers the legacy HIP detection path which works. --- ai/ollama/Dockerfile | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/ai/ollama/Dockerfile b/ai/ollama/Dockerfile index 170ecc6..2c6db27 100644 --- a/ai/ollama/Dockerfile +++ b/ai/ollama/Dockerfile @@ -42,14 +42,13 @@ ENV PATH=/opt/rocm/bin:/opt/rocm/hip/bin:/opt/rocm/hcc/bin:/usr/local/sbin:/usr/ ENV CMAKE_GENERATOR=Ninja ENV LDFLAGS=-s -# Build with ROCm 6 preset + gfx906 target +# Build with ROCm 6 preset + gfx906 target (CXX=hipcc for legacy HIP mode) RUN mkdir -p build && cd build && \ - cmake .. \ + CC=hipcc CXX=hipcc cmake .. \ --preset 'ROCm 6' \ -DAMDGPU_TARGETS="gfx906:xnack-;gfx940;gfx1010;gfx1030;gfx1100;gfx1200" \ - -DCMAKE_HIP_COMPILER=/opt/rocm/bin/hipcc \ -DCMAKE_BUILD_TYPE=Release && \ - cmake --build . -- -l $(nproc) && \ + CC=hipcc CXX=hipcc cmake --build . -- -l $(nproc) && \ cmake --install . --component HIP --strip --prefix /build/dist # Build the Go binary From 5b210fe6241ce79fff854e2d7ec94dc7a319de64 Mon Sep 17 00:00:00 2001 From: Hermes Date: Sat, 9 May 2026 22:29:10 -0400 Subject: [PATCH 08/21] fix: use ROCm amdclang++ as HIP compiler, keep GCC for CPU code Setting CXX=hipcc caused compilation failures on CPU backends (AVX intrinsics). Now using GCC for CPU, ROCm's amdclang++ for HIP only. --- ai/ollama/Dockerfile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ai/ollama/Dockerfile b/ai/ollama/Dockerfile index 2c6db27..172af7c 100644 --- a/ai/ollama/Dockerfile +++ b/ai/ollama/Dockerfile @@ -42,13 +42,14 @@ ENV PATH=/opt/rocm/bin:/opt/rocm/hip/bin:/opt/rocm/hcc/bin:/usr/local/sbin:/usr/ ENV CMAKE_GENERATOR=Ninja ENV LDFLAGS=-s -# Build with ROCm 6 preset + gfx906 target (CXX=hipcc for legacy HIP mode) +# Build with ROCm 6 preset + gfx906 target (ROCm clang for HIP, GCC for CPU) RUN mkdir -p build && cd build && \ - CC=hipcc CXX=hipcc cmake .. \ + cmake .. \ --preset 'ROCm 6' \ -DAMDGPU_TARGETS="gfx906:xnack-;gfx940;gfx1010;gfx1030;gfx1100;gfx1200" \ + -DCMAKE_HIP_COMPILER=/opt/rocm/bin/amdclang++ \ -DCMAKE_BUILD_TYPE=Release && \ - CC=hipcc CXX=hipcc cmake --build . -- -l $(nproc) && \ + cmake --build . -- -l $(nproc) && \ cmake --install . --component HIP --strip --prefix /build/dist # Build the Go binary From 0c612d97312a561717b0adba9a9bfe7913208d9f Mon Sep 17 00:00:00 2001 From: Hermes Date: Sat, 9 May 2026 22:30:21 -0400 Subject: [PATCH 09/21] fix: remove unsupported AMDGPU_TARGETS (gfx1200) for ROCm 6.1 ROCm 6.1's AMD clang 17 doesn't support gfx1200 (RDNA4). Use only targets supported by ROCm 6.1: gfx906, gfx908, gfx90a, gfx1030, gfx1100. --- ai/ollama/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ai/ollama/Dockerfile b/ai/ollama/Dockerfile index 172af7c..233229f 100644 --- a/ai/ollama/Dockerfile +++ b/ai/ollama/Dockerfile @@ -46,7 +46,7 @@ ENV LDFLAGS=-s RUN mkdir -p build && cd build && \ cmake .. \ --preset 'ROCm 6' \ - -DAMDGPU_TARGETS="gfx906:xnack-;gfx940;gfx1010;gfx1030;gfx1100;gfx1200" \ + -DAMDGPU_TARGETS="gfx906:xnack-;gfx908:xnack-;gfx90a:xnack-;gfx1030;gfx1100" \ -DCMAKE_HIP_COMPILER=/opt/rocm/bin/amdclang++ \ -DCMAKE_BUILD_TYPE=Release && \ cmake --build . -- -l $(nproc) && \ From aa6bbe87bfeced300cb6606b4f04124b31e4f84d Mon Sep 17 00:00:00 2001 From: Hermes Date: Sat, 9 May 2026 22:40:40 -0400 Subject: [PATCH 10/21] fix: correct AMDGPU_TARGETS to include gfx940/gfx1010/gfx1200 Targets were corrupted during previous patch iterations, contained gfx908/gfx90a from the CMake preset instead of gfx940/gfx1010/gfx1200. --- ai/ollama/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ai/ollama/Dockerfile b/ai/ollama/Dockerfile index 233229f..172af7c 100644 --- a/ai/ollama/Dockerfile +++ b/ai/ollama/Dockerfile @@ -46,7 +46,7 @@ ENV LDFLAGS=-s RUN mkdir -p build && cd build && \ cmake .. \ --preset 'ROCm 6' \ - -DAMDGPU_TARGETS="gfx906:xnack-;gfx908:xnack-;gfx90a:xnack-;gfx1030;gfx1100" \ + -DAMDGPU_TARGETS="gfx906:xnack-;gfx940;gfx1010;gfx1030;gfx1100;gfx1200" \ -DCMAKE_HIP_COMPILER=/opt/rocm/bin/amdclang++ \ -DCMAKE_BUILD_TYPE=Release && \ cmake --build . -- -l $(nproc) && \ From f6bc2b07a79cff31962a20a071716be9d22c18a7 Mon Sep 17 00:00:00 2001 From: Hermes Date: Sat, 9 May 2026 22:41:18 -0400 Subject: [PATCH 11/21] fix: remove nonexistent CC=clang for Go build step ROCm 6.1 image doesn't have clang/clang++ in PATH (only amdclang++). GCC is the default and works fine for CGo linking. --- ai/ollama/Dockerfile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ai/ollama/Dockerfile b/ai/ollama/Dockerfile index 172af7c..4fac4f8 100644 --- a/ai/ollama/Dockerfile +++ b/ai/ollama/Dockerfile @@ -52,10 +52,8 @@ RUN mkdir -p build && cd build && \ cmake --build . -- -l $(nproc) && \ cmake --install . --component HIP --strip --prefix /build/dist -# Build the Go binary +# Build the Go binary (use GCC for CGo linking) ENV CGO_ENABLED=1 -ENV CC=clang -ENV CXX=clang++ RUN go build -trimpath -o /build/dist/ollama . # ---------- Runtime image ---------- From 0d87fb25564d5439c02eef8f71d1e9a352f2a1d2 Mon Sep 17 00:00:00 2001 From: Hermes Date: Sat, 9 May 2026 22:51:13 -0400 Subject: [PATCH 12/21] fix: build CPU and HIP backends separately CPU backends compiled with GCC (fixes AVX intrinsic errors from hipcc). HIP backend compiled with hipcc (legacy mode skips enable_language(HIP)). Go binary built with GCC for CGo linking. This avoids both CMAKE_HIP_COMPILER rejection and CXX=hipcc CPU failures. --- ai/ollama/Dockerfile | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/ai/ollama/Dockerfile b/ai/ollama/Dockerfile index 4fac4f8..aedee93 100644 --- a/ai/ollama/Dockerfile +++ b/ai/ollama/Dockerfile @@ -35,24 +35,28 @@ ARG OLLAMA_VERSION=v0.23.2 RUN git clone --depth 1 --branch ${OLLAMA_VERSION} https://github.com/ollama/ollama.git /build WORKDIR /build -# ROCm paths from the base image +# ROCm paths ENV HIP_PATH=/opt/rocm ENV ROCM_PATH=/opt/rocm ENV PATH=/opt/rocm/bin:/opt/rocm/hip/bin:/opt/rocm/hcc/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin ENV CMAKE_GENERATOR=Ninja ENV LDFLAGS=-s -# Build with ROCm 6 preset + gfx906 target (ROCm clang for HIP, GCC for CPU) -RUN mkdir -p build && cd build && \ - cmake .. \ - --preset 'ROCm 6' \ +# Step 1: Build CPU backends with GCC (default compiler) +RUN mkdir -p build-cpu && cd build-cpu && \ + cmake .. -DCMAKE_BUILD_TYPE=Release && \ + cmake --build . --target ggml-cpu -- -l $(nproc) && \ + cmake --install . --component CPU --strip --prefix /build/dist + +# Step 2: Build HIP backend with hipcc (legacy mode skips enable_language(HIP)) +RUN mkdir -p build-hip && cd build-hip && \ + CC=hipcc CXX=hipcc cmake .. \ -DAMDGPU_TARGETS="gfx906:xnack-;gfx940;gfx1010;gfx1030;gfx1100;gfx1200" \ - -DCMAKE_HIP_COMPILER=/opt/rocm/bin/amdclang++ \ -DCMAKE_BUILD_TYPE=Release && \ - cmake --build . -- -l $(nproc) && \ + CC=hipcc CXX=hipcc cmake --build . --target ggml-hip -- -l $(nproc) && \ cmake --install . --component HIP --strip --prefix /build/dist -# Build the Go binary (use GCC for CGo linking) +# Step 3: Build Go binary (uses GCC for CGo linking) ENV CGO_ENABLED=1 RUN go build -trimpath -o /build/dist/ollama . @@ -67,7 +71,7 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \ COPY --from=builder /opt/rocm/lib/ /opt/rocm/lib/ COPY --from=builder /opt/rocm/share/ /opt/rocm/share/ -# Copy ollama binary and backend +# Copy ollama binary + all backends (CPU + HIP) COPY --from=builder /build/dist/ollama /usr/bin/ollama COPY --from=builder /build/dist/lib/ /usr/lib/ollama/ From d52f18b0fa75166f5087a3e0de320137574d1ac1 Mon Sep 17 00:00:00 2001 From: Hermes Date: Sat, 9 May 2026 22:53:11 -0400 Subject: [PATCH 13/21] fix: remove gfx1200 target (not supported by ROCm 6.1 clang 17) ROCm 6.1's AMD clang 17 doesn't recognize gfx1200 architecture (introduced in ROCm 6.2+). Caused compilation failure on all .cu files. --- ai/ollama/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ai/ollama/Dockerfile b/ai/ollama/Dockerfile index aedee93..f530de2 100644 --- a/ai/ollama/Dockerfile +++ b/ai/ollama/Dockerfile @@ -51,7 +51,7 @@ RUN mkdir -p build-cpu && cd build-cpu && \ # Step 2: Build HIP backend with hipcc (legacy mode skips enable_language(HIP)) RUN mkdir -p build-hip && cd build-hip && \ CC=hipcc CXX=hipcc cmake .. \ - -DAMDGPU_TARGETS="gfx906:xnack-;gfx940;gfx1010;gfx1030;gfx1100;gfx1200" \ + -DAMDGPU_TARGETS="gfx906:xnack-;gfx940;gfx1010;gfx1030;gfx1100" \ -DCMAKE_BUILD_TYPE=Release && \ CC=hipcc CXX=hipcc cmake --build . --target ggml-hip -- -l $(nproc) && \ cmake --install . --component HIP --strip --prefix /build/dist From fc777e2de287dc9d76f4f6f546a58760c210cf4f Mon Sep 17 00:00:00 2001 From: Hermes Date: Sat, 9 May 2026 23:07:39 -0400 Subject: [PATCH 14/21] fix: target only gfx906 for HIP compilation gfx940/gfx1010/gfx1030/gfx1100 cause C++ narrowing errors in ollama's mma.cuh with hipcc. Since we only have MI50 (gfx906) cards, compile for gfx906 only. Reduces build time and avoids upstream code bugs. --- ai/ollama/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ai/ollama/Dockerfile b/ai/ollama/Dockerfile index f530de2..ca92084 100644 --- a/ai/ollama/Dockerfile +++ b/ai/ollama/Dockerfile @@ -51,7 +51,7 @@ RUN mkdir -p build-cpu && cd build-cpu && \ # Step 2: Build HIP backend with hipcc (legacy mode skips enable_language(HIP)) RUN mkdir -p build-hip && cd build-hip && \ CC=hipcc CXX=hipcc cmake .. \ - -DAMDGPU_TARGETS="gfx906:xnack-;gfx940;gfx1010;gfx1030;gfx1100" \ + -DAMDGPU_TARGETS="gfx906:xnack-" \ -DCMAKE_BUILD_TYPE=Release && \ CC=hipcc CXX=hipcc cmake --build . --target ggml-hip -- -l $(nproc) && \ cmake --install . --component HIP --strip --prefix /build/dist From 0f7b22c19bcec54c1fc928cea3af8f41e5a60c47 Mon Sep 17 00:00:00 2001 From: Hermes Date: Sat, 9 May 2026 23:15:26 -0400 Subject: [PATCH 15/21] fix: add /usr/local/go/bin to ROCm PATH (was overridden) ENV PATH for ROCm overwrote the previous PATH that included Go. Without Go in PATH, 'go build' fails with 'go: not found'. --- ai/ollama/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ai/ollama/Dockerfile b/ai/ollama/Dockerfile index ca92084..94f6b63 100644 --- a/ai/ollama/Dockerfile +++ b/ai/ollama/Dockerfile @@ -38,7 +38,7 @@ WORKDIR /build # ROCm paths ENV HIP_PATH=/opt/rocm ENV ROCM_PATH=/opt/rocm -ENV PATH=/opt/rocm/bin:/opt/rocm/hip/bin:/opt/rocm/hcc/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin +ENV PATH=/usr/local/go/bin:/opt/rocm/bin:/opt/rocm/hip/bin:/opt/rocm/hcc/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin ENV CMAKE_GENERATOR=Ninja ENV LDFLAGS=-s From 32df5465504191afcac73219edadf4733428447d Mon Sep 17 00:00:00 2001 From: Hermes Date: Sat, 9 May 2026 23:49:08 -0400 Subject: [PATCH 16/21] fix: use ROCm 6 preset with HIP language detection for proper GPU kernel compilation - Use --preset 'ROCm 6' for HIP build step (enables enable_language(HIP)) - Remove /opt/rocm from PATH for CPU build to prevent check_language(HIP) - Add CMAKE_PREFIX_PATH=/opt/rocm so find_package(hip) finds hip-config.cmake - cmake --install --component HIP now works correctly with OLLAMA_RUNNER_DIR=rocm --- ai/ollama/Dockerfile | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/ai/ollama/Dockerfile b/ai/ollama/Dockerfile index 94f6b63..65ffe9b 100644 --- a/ai/ollama/Dockerfile +++ b/ai/ollama/Dockerfile @@ -38,25 +38,37 @@ WORKDIR /build # ROCm paths ENV HIP_PATH=/opt/rocm ENV ROCM_PATH=/opt/rocm -ENV PATH=/usr/local/go/bin:/opt/rocm/bin:/opt/rocm/hip/bin:/opt/rocm/hcc/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin ENV CMAKE_GENERATOR=Ninja ENV LDFLAGS=-s -# Step 1: Build CPU backends with GCC (default compiler) +# Step 1: Build CPU backends with GCC (no ROCm preset) +# Remove /opt/rocm from PATH to prevent check_language(HIP) from +# finding a HIP compiler, which would trigger the HIP block that +# requires find_package(hip) with proper CMAKE_PREFIX_PATH. RUN mkdir -p build-cpu && cd build-cpu && \ + PATH=/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \ cmake .. -DCMAKE_BUILD_TYPE=Release && \ cmake --build . --target ggml-cpu -- -l $(nproc) && \ cmake --install . --component CPU --strip --prefix /build/dist -# Step 2: Build HIP backend with hipcc (legacy mode skips enable_language(HIP)) +# Step 2: Build HIP backend with ROCm preset + gfx906 target only +# The ROCm 6 preset enables HIP language detection (enable_language(HIP)) +# which ensures GPU kernels are properly compiled for gfx906. +# OLLAMA_RUNNER_DIR=rocm from the preset, so HIP goes to lib/ollama/rocm/ +# Need CMAKE_PREFIX_PATH so find_package(hip) finds hip-config.cmake +# at /opt/rocm/lib/cmake/hip/hip-config.cmake. RUN mkdir -p build-hip && cd build-hip && \ - CC=hipcc CXX=hipcc cmake .. \ + cmake .. \ + --preset 'ROCm 6' \ -DAMDGPU_TARGETS="gfx906:xnack-" \ - -DCMAKE_BUILD_TYPE=Release && \ - CC=hipcc CXX=hipcc cmake --build . --target ggml-hip -- -l $(nproc) && \ - cmake --install . --component HIP --strip --prefix /build/dist + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_PREFIX_PATH="/opt/rocm" && \ + cmake --build . --target ggml-hip -- -l $(nproc) && \ + cmake --install . --component HIP --strip --prefix /build/dist && \ + echo "=== HIP install ===" && \ + find /build/dist/lib/ollama -type f -o -type l | head -20 -# Step 3: Build Go binary (uses GCC for CGo linking) +# Step 3: Build Go binary (GCC for CGo linking) ENV CGO_ENABLED=1 RUN go build -trimpath -o /build/dist/ollama . @@ -68,6 +80,7 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \ && rm -rf /var/lib/apt/lists/* # Copy ROCm 6.1 runtime libraries +# These are needed at runtime by ggml-hip via LD_LIBRARY_PATH COPY --from=builder /opt/rocm/lib/ /opt/rocm/lib/ COPY --from=builder /opt/rocm/share/ /opt/rocm/share/ @@ -77,7 +90,7 @@ COPY --from=builder /build/dist/lib/ /usr/lib/ollama/ RUN ldconfig -ENV LD_LIBRARY_PATH=/opt/rocm/lib:/usr/lib/ollama +ENV LD_LIBRARY_PATH=/opt/rocm/lib:/usr/lib/ollama/rocm:/usr/lib/ollama ENV HSA_OVERRIDE_GFX_VERSION=9.0.6 ENV HCC_AMDGPU_TARGET=gfx906 ENV HSA_ENABLE_SDMA=0 From 208bfd4612788c35dbbc8dae58d1183cded8d619 Mon Sep 17 00:00:00 2001 From: Hermes Date: Sat, 9 May 2026 23:50:26 -0400 Subject: [PATCH 17/21] fix: pre-set CMAKE_HIP_COMPILER="" for CPU build to prevent HIP detection --- ai/ollama/Dockerfile | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ai/ollama/Dockerfile b/ai/ollama/Dockerfile index 65ffe9b..22370d2 100644 --- a/ai/ollama/Dockerfile +++ b/ai/ollama/Dockerfile @@ -42,12 +42,13 @@ ENV CMAKE_GENERATOR=Ninja ENV LDFLAGS=-s # Step 1: Build CPU backends with GCC (no ROCm preset) -# Remove /opt/rocm from PATH to prevent check_language(HIP) from -# finding a HIP compiler, which would trigger the HIP block that -# requires find_package(hip) with proper CMAKE_PREFIX_PATH. +# Pre-set CMAKE_HIP_COMPILER="" to prevent check_language(HIP) from +# finding a HIP compiler (it searches /opt/rocm even without PATH). +# Remove /opt/rocm from PATH to prevent find_program from finding hipcc. RUN mkdir -p build-cpu && cd build-cpu && \ PATH=/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \ - cmake .. -DCMAKE_BUILD_TYPE=Release && \ + cmake .. -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_HIP_COMPILER="" && \ cmake --build . --target ggml-cpu -- -l $(nproc) && \ cmake --install . --component CPU --strip --prefix /build/dist From bf2f17c5e28a9871ea95fddad650d4ec27f96692 Mon Sep 17 00:00:00 2001 From: Hermes Date: Sat, 9 May 2026 23:52:46 -0400 Subject: [PATCH 18/21] fix: use cmake -B to override preset binaryDir, cmake --build/--install use explicit path --- ai/ollama/Dockerfile | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ai/ollama/Dockerfile b/ai/ollama/Dockerfile index 22370d2..6b92064 100644 --- a/ai/ollama/Dockerfile +++ b/ai/ollama/Dockerfile @@ -45,12 +45,12 @@ ENV LDFLAGS=-s # Pre-set CMAKE_HIP_COMPILER="" to prevent check_language(HIP) from # finding a HIP compiler (it searches /opt/rocm even without PATH). # Remove /opt/rocm from PATH to prevent find_program from finding hipcc. -RUN mkdir -p build-cpu && cd build-cpu && \ +RUN mkdir -p build-cpu && \ PATH=/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \ - cmake .. -DCMAKE_BUILD_TYPE=Release \ + cmake -B build-cpu -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_HIP_COMPILER="" && \ - cmake --build . --target ggml-cpu -- -l $(nproc) && \ - cmake --install . --component CPU --strip --prefix /build/dist + cmake --build build-cpu --target ggml-cpu -- -l $(nproc) && \ + cmake --install build-cpu --component CPU --strip --prefix /build/dist # Step 2: Build HIP backend with ROCm preset + gfx906 target only # The ROCm 6 preset enables HIP language detection (enable_language(HIP)) @@ -58,14 +58,14 @@ RUN mkdir -p build-cpu && cd build-cpu && \ # OLLAMA_RUNNER_DIR=rocm from the preset, so HIP goes to lib/ollama/rocm/ # Need CMAKE_PREFIX_PATH so find_package(hip) finds hip-config.cmake # at /opt/rocm/lib/cmake/hip/hip-config.cmake. -RUN mkdir -p build-hip && cd build-hip && \ - cmake .. \ +RUN mkdir -p build-hip && \ + cmake -B build-hip \ --preset 'ROCm 6' \ -DAMDGPU_TARGETS="gfx906:xnack-" \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_PREFIX_PATH="/opt/rocm" && \ - cmake --build . --target ggml-hip -- -l $(nproc) && \ - cmake --install . --component HIP --strip --prefix /build/dist && \ + cmake --build build-hip --target ggml-hip -- -l $(nproc) && \ + cmake --install build-hip --component HIP --strip --prefix /build/dist && \ echo "=== HIP install ===" && \ find /build/dist/lib/ollama -type f -o -type l | head -20 From f31ae5971744f08067c653cfcc8ffd5244171e14 Mon Sep 17 00:00:00 2001 From: Hermes Date: Sun, 10 May 2026 00:10:39 -0400 Subject: [PATCH 19/21] fix: copy /build/dist/lib/ollama/ (not /build/dist/lib/) to avoid extra nesting --- ai/ollama/Dockerfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ai/ollama/Dockerfile b/ai/ollama/Dockerfile index 6b92064..2681c46 100644 --- a/ai/ollama/Dockerfile +++ b/ai/ollama/Dockerfile @@ -86,8 +86,10 @@ COPY --from=builder /opt/rocm/lib/ /opt/rocm/lib/ COPY --from=builder /opt/rocm/share/ /opt/rocm/share/ # Copy ollama binary + all backends (CPU + HIP) +# CPU install: /build/dist/lib/ollama/libggml-*.so +# HIP install: /build/dist/lib/ollama/rocm/libggml-hip.so COPY --from=builder /build/dist/ollama /usr/bin/ollama -COPY --from=builder /build/dist/lib/ /usr/lib/ollama/ +COPY --from=builder /build/dist/lib/ollama/ /usr/lib/ollama/ RUN ldconfig From 9cc7edfb3993c11a0d92899e820ae02bb70d57f5 Mon Sep 17 00:00:00 2001 From: Hermes Date: Sun, 10 May 2026 00:44:56 -0400 Subject: [PATCH 20/21] fix: set CMAKE_INSTALL_PREFIX=/build/dist at configure time for CPU, match preset for HIP --- ai/ollama/Dockerfile | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ai/ollama/Dockerfile b/ai/ollama/Dockerfile index 2681c46..f41ab5d 100644 --- a/ai/ollama/Dockerfile +++ b/ai/ollama/Dockerfile @@ -48,9 +48,12 @@ ENV LDFLAGS=-s RUN mkdir -p build-cpu && \ PATH=/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \ cmake -B build-cpu -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_HIP_COMPILER="" && \ + -DCMAKE_HIP_COMPILER="" \ + -DCMAKE_INSTALL_PREFIX=/build/dist && \ cmake --build build-cpu --target ggml-cpu -- -l $(nproc) && \ - cmake --install build-cpu --component CPU --strip --prefix /build/dist + cmake --install build-cpu --component CPU --strip && \ + echo "=== CPU install ===" && \ + (find /build/dist/lib/ollama -type f -o -type l 2>&1 | head -20 || echo "empty") # Step 2: Build HIP backend with ROCm preset + gfx906 target only # The ROCm 6 preset enables HIP language detection (enable_language(HIP)) @@ -65,7 +68,7 @@ RUN mkdir -p build-hip && \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_PREFIX_PATH="/opt/rocm" && \ cmake --build build-hip --target ggml-hip -- -l $(nproc) && \ - cmake --install build-hip --component HIP --strip --prefix /build/dist && \ + cmake --install build-hip --component HIP --strip && \ echo "=== HIP install ===" && \ find /build/dist/lib/ollama -type f -o -type l | head -20 From 6b82a26c25f1592a2d1c9bea4f941864362fe001 Mon Sep 17 00:00:00 2001 From: Hermes Date: Sun, 10 May 2026 10:07:25 -0400 Subject: [PATCH 21/21] fix: add ldflags for version, remove privileged, enable flash attention --- ai/compose.yml | 3 +-- ai/ollama/Dockerfile | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/ai/compose.yml b/ai/compose.yml index dceb490..2e565ae 100644 --- a/ai/compose.yml +++ b/ai/compose.yml @@ -63,7 +63,6 @@ services: dockerfile: Dockerfile image: ollama/ollama:rocm-gfx906 container_name: ollama - privileged: true tty: true restart: always ports: @@ -81,7 +80,7 @@ services: - HSA_ENABLE_SDMA=0 - OLLAMA_HOST=0.0.0.0 - OLLAMA_DEBUG=1 - - OLLAMA_FLASH_ATTENTION=0 + - OLLAMA_FLASH_ATTENTION=1 - OLLAMA_NUM_PARALLEL=2 devices: # Map the render nodes and KFD for ROCm to work inside the container diff --git a/ai/ollama/Dockerfile b/ai/ollama/Dockerfile index f41ab5d..438e607 100644 --- a/ai/ollama/Dockerfile +++ b/ai/ollama/Dockerfile @@ -74,7 +74,7 @@ RUN mkdir -p build-hip && \ # Step 3: Build Go binary (GCC for CGo linking) ENV CGO_ENABLED=1 -RUN go build -trimpath -o /build/dist/ollama . +RUN go build -trimpath -ldflags="-X=github.com/ollama/ollama/version.Version=${OLLAMA_VERSION}" -o /build/dist/ollama . # ---------- Runtime image ---------- FROM ubuntu:24.04