From 642e6e9aea1c4972448a71b5b8967311cfe497e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Prud=27homme?= Date: Sat, 27 May 2023 19:43:19 +0200 Subject: [PATCH 1/2] feat: add CuBLAS support in Docker images MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Sébastien Prud'homme --- Dockerfile | 43 ++++++++++++++++++++++++++--- Dockerfile.dev | 73 +++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 106 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1f3830d62c54..ec72a1cab084 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,50 @@ ARG GO_VERSION=1.20 -ARG BUILD_TYPE= FROM golang:$GO_VERSION + +ARG BUILD_TYPE= +ARG GO_TAGS= +ARG CUDA_MAJOR_VERSION=11 +ARG CUDA_MINOR_VERSION=7 + +ENV BUILD_TYPE=${BUILD_TYPE} +ENV GO_TAGS=${GO_TAGS} +ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility +ENV NVIDIA_REQUIRE_CUDA="cuda>=${CUDA_MAJOR_VERSION}.0" +ENV NVIDIA_VISIBLE_DEVICES=all +ENV HEALTHCHECK_ENDPOINT=http://localhost:8080/readyz ENV REBUILD=true + WORKDIR /build -RUN apt-get update && apt-get install -y cmake curl libgomp1 libopenblas-dev libopenblas-base libopencv-dev libopencv-core-dev libopencv-core4.5 ca-certificates + +RUN apt-get update && \ + apt-get install -y ca-certificates cmake curl + +RUN if [ "${BUILD_TYPE}" = "cublas" ]; then \ + apt-get install -y software-properties-common && \ + apt-add-repository contrib && \ + curl -O https://developer.download.nvidia.com/compute/cuda/repos/debian11/x86_64/cuda-keyring_1.0-1_all.deb && \ + dpkg -i cuda-keyring_1.0-1_all.deb && \ + rm -f cuda-keyring_1.0-1_all.deb && \ + apt-get update && \ + apt-get install -y cuda-nvcc-${CUDA_MAJOR_VERSION}-${CUDA_MINOR_VERSION} libcublas-dev-${CUDA_MAJOR_VERSION}-${CUDA_MINOR_VERSION} \ + ; fi +ENV PATH /usr/local/cuda/bin:${PATH} + +RUN if [ "${BUILD_TYPE}" = "openblas" ]; then \ + apt-get install -y libopenblas-dev \ + ; fi + +RUN if [ "${GO_TAGS}" = "stablediffusion" ]; then \ + apt-get install -y libopencv-dev && \ + ln -s /usr/include/opencv4/opencv2 /usr/include/opencv2 \ + ; fi + COPY . . -RUN ln -s /usr/include/opencv4/opencv2/ /usr/include/opencv2 RUN make build -ENV HEALTHCHECK_ENDPOINT=http://localhost:8080/readyz + # Define the health check command HEALTHCHECK --interval=30s --timeout=360s --retries=10 \ CMD curl -f $HEALTHCHECK_ENDPOINT || exit 1 + EXPOSE 8080 ENTRYPOINT [ "/build/entrypoint.sh" ] diff --git a/Dockerfile.dev b/Dockerfile.dev index 1e355f1bf9e0..ad0c7eade0d0 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -1,20 +1,81 @@ ARG GO_VERSION=1.20 ARG DEBIAN_VERSION=11 +FROM golang:$GO_VERSION as builder + ARG BUILD_TYPE= +ARG GO_TAGS= +ARG CUDA_MAJOR_VERSION=11 +ARG CUDA_MINOR_VERSION=7 + +ENV BUILD_TYPE=${BUILD_TYPE} +ENV GO_TAGS=${GO_TAGS} -FROM golang:$GO_VERSION as builder WORKDIR /build -RUN apt-get update && apt-get install -y cmake libgomp1 libopenblas-dev libopenblas-base libopencv-dev libopencv-core-dev libopencv-core4.5 -RUN ln -s /usr/include/opencv4/opencv2/ /usr/include/opencv2 + +RUN apt-get update && \ + apt-get install -y cmake + +RUN if [ "${BUILD_TYPE}" = "cublas" ]; then \ + apt-get install -y software-properties-common && \ + apt-add-repository contrib && \ + curl -O https://developer.download.nvidia.com/compute/cuda/repos/debian11/x86_64/cuda-keyring_1.0-1_all.deb && \ + dpkg -i cuda-keyring_1.0-1_all.deb && \ + rm -f cuda-keyring_1.0-1_all.deb && \ + apt-get update && \ + apt-get install -y cuda-nvcc-${CUDA_MAJOR_VERSION}-${CUDA_MINOR_VERSION} libcublas-dev-${CUDA_MAJOR_VERSION}-${CUDA_MINOR_VERSION} \ + ; fi +ENV PATH /usr/local/cuda/bin:${PATH} + +RUN if [ "${BUILD_TYPE}" = "openblas" ]; then \ + apt-get install -y libopenblas-dev \ + ; fi + +RUN if [ "${GO_TAGS}" = "stablediffusion" ]; then \ + apt-get install -y libopencv-dev && \ + ln -s /usr/include/opencv4/opencv2 /usr/include/opencv2 \ + ; fi + COPY . . RUN make build FROM debian:$DEBIAN_VERSION -COPY --from=builder /build/local-ai /usr/bin/local-ai -RUN apt-get update && apt-get install -y ca-certificates curl + +ARG BUILD_TYPE= +ARG GO_TAGS= +ARG CUDA_MAJOR_VERSION=11 +ARG CUDA_MINOR_VERSION=7 + +ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility +ENV NVIDIA_REQUIRE_CUDA="cuda>=${CUDA_MAJOR_VERSION}.0" +ENV NVIDIA_VISIBLE_DEVICES=all ENV HEALTHCHECK_ENDPOINT=http://localhost:8080/readyz + +RUN apt-get update && \ + apt-get install -y ca-certificates curl + +RUN if [ "${BUILD_TYPE}" = "cublas" ]; then \ + apt-get install -y curl software-properties-common && \ + apt-add-repository contrib && \ + curl -O https://developer.download.nvidia.com/compute/cuda/repos/debian11/x86_64/cuda-keyring_1.0-1_all.deb && \ + dpkg -i cuda-keyring_1.0-1_all.deb && \ + rm -f cuda-keyring_1.0-1_all.deb && \ + apt-get update && \ + apt-get install -y cuda-cudart-${CUDA_MAJOR_VERSION}-${CUDA_MINOR_VERSION} libcublas-${CUDA_MAJOR_VERSION}-${CUDA_MINOR_VERSION} \ + ; fi + +RUN if [ "${BUILD_TYPE}" = "openblas" ]; then \ + apt-get install -y libopenblas0 \ + ; fi + +RUN if [ "${GO_TAGS}" = "stablediffusion" ]; then \ + apt-get install -y libgomp1 libopencv-core4.5 libopencv-imgcodecs4.5 \ + ; fi + +COPY --from=builder /build/local-ai /usr/bin/local-ai + # Define the health check command HEALTHCHECK --interval=30s --timeout=360s --retries=10 \ CMD curl -f $HEALTHCHECK_ENDPOINT || exit 1 + EXPOSE 8080 -ENTRYPOINT [ "/usr/bin/local-ai" ] \ No newline at end of file +ENTRYPOINT [ "/usr/bin/local-ai" ] From 65809f303e222fa14d031edc70b3c765b7557958 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Prud=27homme?= Date: Mon, 29 May 2023 21:14:09 +0200 Subject: [PATCH 2/2] fix: always install OpenBLAS and Stable Diffusion requirements --- Dockerfile | 13 ++++++------- Dockerfile.dev | 24 +++++++++++------------- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/Dockerfile b/Dockerfile index ec72a1cab084..d730d4b4514d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,6 +19,7 @@ WORKDIR /build RUN apt-get update && \ apt-get install -y ca-certificates cmake curl +# CuBLAS requirements RUN if [ "${BUILD_TYPE}" = "cublas" ]; then \ apt-get install -y software-properties-common && \ apt-add-repository contrib && \ @@ -30,14 +31,12 @@ RUN if [ "${BUILD_TYPE}" = "cublas" ]; then \ ; fi ENV PATH /usr/local/cuda/bin:${PATH} -RUN if [ "${BUILD_TYPE}" = "openblas" ]; then \ - apt-get install -y libopenblas-dev \ - ; fi +# OpenBLAS requirements +RUN apt-get install -y libopenblas-dev -RUN if [ "${GO_TAGS}" = "stablediffusion" ]; then \ - apt-get install -y libopencv-dev && \ - ln -s /usr/include/opencv4/opencv2 /usr/include/opencv2 \ - ; fi +# Stable Diffusion requirements +RUN apt-get install -y libopencv-dev && \ + ln -s /usr/include/opencv4/opencv2 /usr/include/opencv2 COPY . . RUN make build diff --git a/Dockerfile.dev b/Dockerfile.dev index ad0c7eade0d0..df44359a0ab9 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -15,6 +15,7 @@ WORKDIR /build RUN apt-get update && \ apt-get install -y cmake +# CuBLAS requirements RUN if [ "${BUILD_TYPE}" = "cublas" ]; then \ apt-get install -y software-properties-common && \ apt-add-repository contrib && \ @@ -26,14 +27,12 @@ RUN if [ "${BUILD_TYPE}" = "cublas" ]; then \ ; fi ENV PATH /usr/local/cuda/bin:${PATH} -RUN if [ "${BUILD_TYPE}" = "openblas" ]; then \ - apt-get install -y libopenblas-dev \ - ; fi +# OpenBLAS requirements +RUN apt-get install -y libopenblas-dev -RUN if [ "${GO_TAGS}" = "stablediffusion" ]; then \ - apt-get install -y libopencv-dev && \ - ln -s /usr/include/opencv4/opencv2 /usr/include/opencv2 \ - ; fi +# Stable Diffusion requirements +RUN apt-get install -y libopencv-dev && \ + ln -s /usr/include/opencv4/opencv2 /usr/include/opencv2 COPY . . RUN make build @@ -53,6 +52,7 @@ ENV HEALTHCHECK_ENDPOINT=http://localhost:8080/readyz RUN apt-get update && \ apt-get install -y ca-certificates curl +# CuBLAS requirements RUN if [ "${BUILD_TYPE}" = "cublas" ]; then \ apt-get install -y curl software-properties-common && \ apt-add-repository contrib && \ @@ -63,13 +63,11 @@ RUN if [ "${BUILD_TYPE}" = "cublas" ]; then \ apt-get install -y cuda-cudart-${CUDA_MAJOR_VERSION}-${CUDA_MINOR_VERSION} libcublas-${CUDA_MAJOR_VERSION}-${CUDA_MINOR_VERSION} \ ; fi -RUN if [ "${BUILD_TYPE}" = "openblas" ]; then \ - apt-get install -y libopenblas0 \ - ; fi +# OpenBLAS requirements +RUN apt-get install -y libopenblas0 -RUN if [ "${GO_TAGS}" = "stablediffusion" ]; then \ - apt-get install -y libgomp1 libopencv-core4.5 libopencv-imgcodecs4.5 \ - ; fi +# Stable Diffusion requirements +RUN apt-get install -y libgomp1 libopencv-core4.5 libopencv-imgcodecs4.5 COPY --from=builder /build/local-ai /usr/bin/local-ai