Skip to content

Commit 5f66f7f

Browse files
committed
devops: add custom openblas patch
Signed-off-by: Aaron Teo <[email protected]>
1 parent 4f65e33 commit 5f66f7f

File tree

1 file changed

+38
-9
lines changed

1 file changed

+38
-9
lines changed

.devops/s390x.Dockerfile

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,44 @@
11
ARG GCC_VERSION=15.2.0
22
ARG UBUNTU_VERSION=24.04
33

4-
### Build stage
5-
FROM --platform=linux/s390x gcc:${GCC_VERSION} AS build
4+
### Build OpenBLAS stage
5+
FROM --platform=linux/s390x gcc:${GCC_VERSION} AS build-openblas
6+
7+
ARG OPENBLAS_THREADS=8
68

79
RUN --mount=type=cache,target=/var/cache/apt \
810
--mount=type=cache,target=/var/lib/apt/lists \
911
apt update -y && \
1012
apt upgrade -y && \
1113
apt install -y --no-install-recommends \
12-
git cmake ccache ninja-build \
13-
libcurl4-openssl-dev libopenblas-openmp-dev && \
14+
git pkg-config && \
15+
rm -rf /var/lib/apt/lists/*
16+
17+
WORKDIR /build
18+
RUN git clone https://github.com/taronaeo/OpenBLAS-s390x /build
19+
20+
RUN export NUM_THREADS=${OPENBLAS_THREADS} && \
21+
export OPENBLAS_NUM_THREADS=$NUM_THREADS && \
22+
export GOTO_NUM_THREADS=$NUM_THREADS && \
23+
export OMP_NUM_THREADS=$NUM_THREADS && \
24+
make -j $(nproc) USE_OPENMP=1 && \
25+
make -j $(nproc) USE_OPENMP=1 PREFIX=/opt/openblas-libs install
26+
27+
28+
### Build Llama.cpp stage
29+
FROM --platform=linux/s390x gcc:${GCC_VERSION} AS build-llama
30+
31+
RUN --mount=type=cache,target=/var/cache/apt \
32+
--mount=type=cache,target=/var/lib/apt/lists \
33+
apt update -y && \
34+
apt upgrade -y && \
35+
apt install -y --no-install-recommends \
36+
git cmake ccache ninja-build libcurl4-openssl-dev && \
1437
rm -rf /var/lib/apt/lists/*
1538

1639
WORKDIR /app
1740
COPY . .
41+
COPY --from=build-openblas /opt/openblas-libs /opt/openblas-libs
1842

1943
RUN --mount=type=cache,target=/root/.ccache \
2044
--mount=type=cache,target=/app/build \
@@ -26,7 +50,9 @@ RUN --mount=type=cache,target=/root/.ccache \
2650
-DGGML_BACKEND_DL=OFF \
2751
-DGGML_NATIVE=OFF \
2852
-DGGML_BLAS=ON \
29-
-DGGML_BLAS_VENDOR=OpenBLAS && \
53+
-DGGML_BLAS_VENDOR=OpenBLAS \
54+
-DBLAS_LIBRARIES="/opt/openblas-libs/lib/libopenblas.so" \
55+
-DBLAS_INCLUDE_DIRS="/opt/openblas-libs/include" && \
3056
cmake --build build --config Release -j $(nproc) && \
3157
cmake --install build --prefix /opt/llama.cpp
3258

@@ -42,9 +68,12 @@ COPY requirements /opt/llama.cpp/gguf-py/requirements
4268
FROM --platform=linux/s390x scratch AS collector
4369

4470
# Copy llama.cpp binaries and libraries
45-
COPY --from=build /opt/llama.cpp/bin /llama.cpp/bin
46-
COPY --from=build /opt/llama.cpp/lib /llama.cpp/lib
47-
COPY --from=build /opt/llama.cpp/gguf-py /llama.cpp/gguf-py
71+
COPY --from=build-llama /opt/llama.cpp/bin /llama.cpp/bin
72+
COPY --from=build-llama /opt/llama.cpp/lib /llama.cpp/lib
73+
COPY --from=build-llama /opt/llama.cpp/gguf-py /llama.cpp/gguf-py
74+
75+
# Copy patched OpenBLAS libraries
76+
COPY --from=build-openblas /opt/openblas-libs/lib /llama.cpp/lib
4877

4978

5079
### Base image
@@ -54,7 +83,7 @@ RUN --mount=type=cache,target=/var/cache/apt \
5483
--mount=type=cache,target=/var/lib/apt/lists \
5584
apt update -y && \
5685
apt install -y --no-install-recommends \
57-
curl libgomp1 libopenblas-dev && \
86+
curl libgfortran5 && \
5887
apt autoremove -y && \
5988
apt clean -y && \
6089
rm -rf /tmp/* /var/tmp/* && \

0 commit comments

Comments
 (0)