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