This version works well

built based on this: https://github.com/whyvl/ollama-vulkan/issues/7#issuecomment-2660836871

Signed-off-by: Vadim Grinco <vadim@grinco.eu>
This commit is contained in:
Vadim Grinco 2025-03-09 23:21:57 +01:00
parent 81465ca374
commit 42bac5cadd
2 changed files with 15358 additions and 55 deletions

View File

@ -1,93 +1,99 @@
# Base Image
FROM --platform=linux/amd64 library/ubuntu:noble AS builder
FROM --platform=linux/amd64 library/ubuntu:noble as builder
# Set Environment Variables
ENV DEBIAN_FRONTEND="noninteractive"
ENV VULKAN_VER_BASE="1.3.296"
ENV VULKAN_VER="${VULKAN_VER_BASE}.0"
ENV UBUNTU_VERSION="noble"
ENV GOLANG_VERSION="1.22.8"
ENV GOARCH="amd64"
ENV CGO_ENABLED=1
ENV LDFLAGS=-s
# Set up faster package mirrors
RUN sed -i 's/archive.ubuntu.com/gb.archive.ubuntu.com/g' /etc/apt/sources.list.d/ubuntu.sources
# Default mirror was very slow
RUN \
sed -i 's/archive.ubuntu.com/gb.archive.ubuntu.com/g' /etc/apt/sources.list.d/ubuntu.sources
# Install Required Dependencies
RUN apt-get update && apt-get install -y \
ca-certificates build-essential ccache cmake wget git curl rsync xz-utils libcap-dev \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
RUN \
apt-get update && \
apt-get install -y ca-certificates build-essential ccache cmake wget git curl rsync xz-utils libcap-dev
# Install Go
RUN mkdir -p /usr/local && \
RUN \
mkdir -p /usr/local 2>/dev/null || true && \
curl -s -L https://dl.google.com/go/go${GOLANG_VERSION}.linux-${GOARCH}.tar.gz | tar -xz -C /usr/local && \
ln -s /usr/local/go/bin/go /usr/local/bin/go && \
ln -s /usr/local/go/bin/gofmt /usr/local/bin/gofmt
# Install Vulkan SDK
RUN wget -qO - https://packages.lunarg.com/lunarg-signing-key-pub.asc | gpg --dearmor -o /etc/apt/trusted.gpg.d/lunarg-signing-key-pub.gpg && \
RUN \
wget -qO - https://packages.lunarg.com/lunarg-signing-key-pub.asc | gpg --dearmor -o /etc/apt/trusted.gpg.d/lunarg-signing-key-pub.gpg && \
wget -qO /etc/apt/sources.list.d/lunarg-vulkan-${UBUNTU_VERSION}.list https://packages.lunarg.com/vulkan/${VULKAN_VER_BASE}/lunarg-vulkan-${VULKAN_VER_BASE}-${UBUNTU_VERSION}.list && \
apt update && apt install -y vulkan-sdk && \
apt-get clean && rm -rf /var/lib/apt/lists/*
apt update && apt install -y vulkan-sdk
# Install AMDVLK (Optional: If you want to use AMDVLK instead of RADV)
RUN wget -qO - http://repo.radeon.com/amdvlk/apt/debian/amdvlk.gpg.key | apt-key add && \
echo "deb [arch=amd64,i386] http://repo.radeon.com/amdvlk/apt/debian/ bionic main" > /etc/apt/sources.list.d/amdvlk.list && \
apt update && apt install -y amdvlk && \
apt-get clean && rm -rf /var/lib/apt/lists/*
# Set AMDVLK as the default Vulkan driver
ENV VK_ICD_FILENAMES=/usr/share/vulkan/icd.d/amd_icd64.json
# Clone Ollama Vulkan Fork
WORKDIR /opt
RUN git clone https://github.com/pufferffish/ollama-vulkan.git ollama-vulkan
# Download and Apply Patches Automatically
WORKDIR /opt/ollama-vulkan
RUN mkdir -p patches && \
wget -O patches/00-fix-vulkan-building.patch https://github.com/user-attachments/files/18783263/0002-fix-fix-vulkan-building.patch && \
# Last testet ollama-vulkan commit:
# 2d443b3dd660a1fd2760d64538512df93648b4bb
COPY patches/ /tmp/patches/
RUN \
git clone https://github.com/pufferffish/ollama-vulkan.git "/tmp/ollama-vulkan-git" && \
cd "/tmp/ollama-vulkan-git" && \
git checkout 2d443b3dd660a1fd2760d64538512df93648b4bb && git checkout -b ollama_vulkan_stable && \
git config user.name "Builder" && git config user.email "builder@local" && \
git remote add ollama_vanilla https://github.com/ollama/ollama.git && \
git fetch ollama_vanilla --tags && git checkout v0.5.13 && git checkout -b ollama_vanilla_stable && \
git fetch ollama_vanilla --tags && git checkout v0.5.14-rc0 && git checkout -b ollama_vanilla_stable && \
git checkout ollama_vulkan_stable && git merge ollama_vanilla_stable --allow-unrelated-histories --no-edit && \
for p in patches/*.patch; do patch -p1 < $p; done
for p in /tmp/patches/00-fix-vulkan-building.patch; do patch -p1 < $p; done
# Build Shared Libraries (CPU & Vulkan)
WORKDIR /opt/ollama-vulkan
RUN cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
RUN cmake --build build --parallel
RUN cmake --install build --component CPU --strip
RUN cmake --install build --component Vulkan --strip
RUN \
cd "/tmp/ollama-vulkan-git" && \
make -f Makefile.sync clean sync
# Install rocm
RUN apt update
RUN apt install -y wget "linux-headers-$(uname -r)" "linux-modules-extra-$(uname -r)"
RUN apt install -y python3-setuptools python3-wheel
RUN wget https://repo.radeon.com/amdgpu-install/6.3.3/ubuntu/noble/amdgpu-install_6.3.60303-1_all.deb -O /tmp/amdgpu-install_6.3.60303-1_all.deb
RUN apt install -y /tmp/amdgpu-install_6.3.60303-1_all.deb
RUN apt update && apt install -y rocm
# Build Final Binary
RUN cd /opt/ollama-vulkan && \
FROM builder AS cpu-build
RUN \
cd "/tmp/ollama-vulkan-git" && \
cmake --preset CPU && cmake --build --parallel --preset CPU && \
cmake --install build --component CPU --strip
FROM builder AS vulkan-build
RUN \
cd "/tmp/ollama-vulkan-git" && \
cmake --preset Vulkan && \
cmake --build --parallel --preset Vulkan && \
cmake --install build --component Vulkan --strip
FROM builder AS binary-build
RUN \
cd "/tmp/ollama-vulkan-git" && \
. scripts/env.sh && \
mkdir -p dist/bin && \
go build -trimpath -buildmode=pie -o dist/bin/ollama .
# Final Image
FROM --platform=linux/amd64 library/ubuntu:noble
RUN apt-get update && apt-get install -y ca-certificates libcap2 libvulkan1 && \
RUN \
apt-get update && apt -y dist-upgrade && \
apt-get install -y ca-certificates libcap2 libvulkan1 && \
apt-get clean && rm -rf /var/lib/apt/lists/*
# Copy Built Components
COPY --from=builder /opt/ollama-vulkan/dist/bin/ollama /bin/ollama
# Install ROCm
RUN \
apt update && \
apt install -y wget python3-setuptools python3-wheel && \
wget https://repo.radeon.com/amdgpu-install/6.3.3/ubuntu/noble/amdgpu-install_6.3.60303-1_all.deb -O /tmp/amdgpu-install_6.3.60303-1_all.deb && \
apt install -y /tmp/amdgpu-install_6.3.60303-1_all.deb && \
apt update && apt install -y rocm && \
apt-get clean && rm -rf /var/lib/apt/lists/*
COPY --from=cpu-build /tmp/ollama-vulkan-git/dist/lib/ollama/ /lib/ollama/
COPY --from=vulkan-build /tmp/ollama-vulkan-git/dist/lib/ollama/vulkan/ /lib/ollama/vulkan/
COPY --from=binary-build /tmp/ollama-vulkan-git/dist/bin/ /bin/
RUN find /lib/ollama && find /bin/ollama
# Expose Ollama Server Port
EXPOSE 11434
ENV OLLAMA_HOST 0.0.0.0
# Run Ollama Server
ENTRYPOINT ["/bin/ollama"]
CMD ["serve"]

File diff suppressed because it is too large Load Diff