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.
This commit is contained in:
@@ -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/
|
||||
|
||||
|
||||
Reference in New Issue
Block a user