From 0c5346e55731d8d9466d18766cb98169edbecab5 Mon Sep 17 00:00:00 2001 From: "Felipe A. Costa" Date: Tue, 13 Feb 2024 18:32:54 -0300 Subject: [PATCH] Add oneapi docker build --- Dockerfile | 19 +++++++++++++++++++ llm/generate/gen_linux.sh | 2 +- scripts/build_docker.sh | 10 ++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 7c921df883d..f2687a08660 100644 --- a/Dockerfile +++ b/Dockerfile @@ -52,6 +52,15 @@ ARG CGO_CFLAGS ARG AMDGPU_TARGETS RUN OLLAMA_SKIP_CPU_GENERATE=1 sh gen_linux.sh +FROM --platform=linux/amd64 intel/oneapi-basekit:2024.0.1-devel-rockylinux9 AS oneapi-build-amd64 +ARG CMAKE_VERSION +COPY ./scripts/rh_linux_deps.sh / +RUN CMAKE_VERSION=${CMAKE_VERSION} sh /rh_linux_deps.sh +COPY --from=llm-code / /go/src/github.com/jmorganca/ollama/ +WORKDIR /go/src/github.com/jmorganca/ollama/llm/generate +ARG CGO_CFLAGS +RUN OLLAMA_SKIP_CPU_GENERATE=1 sh gen_linux.sh + FROM --platform=linux/amd64 centos:7 AS cpu-builder-amd64 ARG CMAKE_VERSION ARG GOLANG_VERSION @@ -93,6 +102,7 @@ COPY --from=cpu_avx2-build-amd64 /go/src/github.com/jmorganca/ollama/llm/llama.c COPY --from=cuda-build-amd64 /go/src/github.com/jmorganca/ollama/llm/llama.cpp/build/linux/ llm/llama.cpp/build/linux/ COPY --from=rocm-5-build-amd64 /go/src/github.com/jmorganca/ollama/llm/llama.cpp/build/linux/ llm/llama.cpp/build/linux/ COPY --from=rocm-6-build-amd64 /go/src/github.com/jmorganca/ollama/llm/llama.cpp/build/linux/ llm/llama.cpp/build/linux/ +COPY --from=oneapi-build-amd64 /go/src/github.com/jmorganca/ollama/llm/llama.cpp/build/linux/ llm/llama.cpp/build/linux/ ARG GOFLAGS ARG CGO_CFLAGS RUN go build . @@ -126,6 +136,15 @@ ENV OLLAMA_HOST 0.0.0.0 ENTRYPOINT ["/bin/ollama"] CMD ["serve"] +# oneAPI images are much larger so we keep it distinct from the CPU/CUDA image +FROM --platform=linux/amd64 intel/oneapi-runtime:2024.0.1-devel-rockylinux9 as runtime-oneapi +COPY --from=build-amd64 /go/src/github.com/jmorganca/ollama/ollama /bin/ollama +EXPOSE 11434 +ENV OLLAMA_HOST 0.0.0.0 + +ENTRYPOINT ["/bin/ollama"] +CMD ["serve"] + FROM runtime-$TARGETARCH EXPOSE 11434 ENV OLLAMA_HOST 0.0.0.0 diff --git a/llm/generate/gen_linux.sh b/llm/generate/gen_linux.sh index d87eb6c7d7c..1e5aa305ad9 100755 --- a/llm/generate/gen_linux.sh +++ b/llm/generate/gen_linux.sh @@ -202,7 +202,7 @@ fi if [ -d "${ONEAPI_ROOT}" ]; then echo "OneAPI libraries detected - building dynamic OneAPI library" init_vars - source ${ONEAPI_ROOT}/setvars.sh # set up environment variables for oneAPI + source ${ONEAPI_ROOT}/setvars.sh --force # set up environment variables for oneAPI CC=icx CMAKE_DEFS="${COMMON_CMAKE_DEFS} ${CMAKE_DEFS} -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx -DLLAMA_SYCL=ON -DLLAMA_SYCL_F16=OFF" BUILD_DIR="${LLAMACPP_DIR}/build/linux/${ARCH}/oneapi" diff --git a/scripts/build_docker.sh b/scripts/build_docker.sh index 40054ca69f4..6909ecd8170 100755 --- a/scripts/build_docker.sh +++ b/scripts/build_docker.sh @@ -23,3 +23,13 @@ docker build \ -f Dockerfile \ -t ollama/ollama:$VERSION-rocm \ . + +docker build \ + --load \ + --platform=linux/amd64 \ + --build-arg=VERSION \ + --build-arg=GOFLAGS \ + --target runtime-oneapi \ + -f Dockerfile \ + -t ollama/ollama:$VERSION-oneapi \ + .