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.
88 lines
3.0 KiB
Docker
88 lines
3.0 KiB
Docker
# ollama-gfx906/Dockerfile
|
|
#
|
|
# Custom ollama image with ROCm 6.1 + gfx906 (MI50) support.
|
|
# 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
|
|
|
|
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 \
|
|
curl git ccache build-essential pkg-config unzip \
|
|
&& 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
|
|
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
|
|
|
|
# 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-" \
|
|
-DCMAKE_BUILD_TYPE=Release && \
|
|
CC=hipcc CXX=hipcc cmake --build . --target ggml-hip -- -l $(nproc) && \
|
|
cmake --install . --component HIP --strip --prefix /build/dist
|
|
|
|
# Step 3: Build Go binary (uses GCC for CGo linking)
|
|
ENV CGO_ENABLED=1
|
|
RUN go build -trimpath -o /build/dist/ollama .
|
|
|
|
# ---------- Runtime image ----------
|
|
FROM ubuntu:24.04
|
|
|
|
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
|
|
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 + all backends (CPU + HIP)
|
|
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
|
|
ENV HCC_AMDGPU_TARGET=gfx906
|
|
ENV HSA_ENABLE_SDMA=0
|
|
|
|
EXPOSE 11434
|
|
ENTRYPOINT ["/bin/ollama"]
|
|
CMD ["serve"]
|