diff --git a/Cargo.lock b/Cargo.lock index e7570bc020..c8306aa5ce 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2413,7 +2413,7 @@ checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" [[package]] name = "gpu" -version = "0.0.1" +version = "0.1.0" dependencies = [ "ash", "gpu-allocator", diff --git a/Dockerfile b/Dockerfile index 4283720bb6..94c567a677 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,8 @@ +# Enable GPU support. +# This option can be set to `nvidia` or `amd` to enable GPU support. +# This option is defined here because it is used in `FROM` instructions. +ARG GPU + # Cross-compiling using Docker multi-platform builds/images and `xx`. # # https://docs.docker.com/build/building/multi-platform/ @@ -76,6 +81,9 @@ ARG RUSTFLAGS # Select linker (e.g., `mold`, `lld` or an empty string for the default linker) ARG LINKER=mold +# Enable GPU support +ARG GPU + COPY --from=planner /qdrant/recipe.json recipe.json # `PKG_CONFIG=...` is a workaround for `xx-cargo` bug for crates using `pkg-config`! # @@ -84,7 +92,7 @@ COPY --from=planner /qdrant/recipe.json recipe.json RUN PKG_CONFIG="/usr/bin/$(xx-info)-pkg-config" \ PATH="$PATH:/opt/mold/bin" \ RUSTFLAGS="${LINKER:+-C link-arg=-fuse-ld=}$LINKER $RUSTFLAGS" \ - xx-cargo chef cook --profile $PROFILE ${FEATURES:+--features} $FEATURES --features=stacktrace --recipe-path recipe.json + xx-cargo chef cook --profile $PROFILE ${FEATURES:+--features} $FEATURES --features=stacktrace ${GPU:+--features=gpu} --recipe-path recipe.json COPY . . # Include git commit into Qdrant binary during build @@ -96,7 +104,7 @@ ARG GIT_COMMIT_ID RUN PKG_CONFIG="/usr/bin/$(xx-info)-pkg-config" \ PATH="$PATH:/opt/mold/bin" \ RUSTFLAGS="${LINKER:+-C link-arg=-fuse-ld=}$LINKER $RUSTFLAGS" \ - xx-cargo build --profile $PROFILE ${FEATURES:+--features} $FEATURES --features=stacktrace --bin qdrant \ + xx-cargo build --profile $PROFILE ${FEATURES:+--features} $FEATURES --features=stacktrace ${GPU:+--features=gpu} --bin qdrant \ && PROFILE_DIR=$(if [ "$PROFILE" = dev ]; then echo debug; else echo $PROFILE; fi) \ && mv target/$(xx-cargo --print-target-triple)/$PROFILE_DIR/qdrant /qdrant/qdrant @@ -104,10 +112,47 @@ RUN PKG_CONFIG="/usr/bin/$(xx-info)-pkg-config" \ RUN mkdir /static && STATIC_DIR=/static ./tools/sync-web-ui.sh -FROM debian:12-slim AS qdrant +# Dockerfile does not support conditional `FROM` directly. +# To workaround this limitation, we use a multi-stage build with a different base images which have equal name to ARG value. + +# Base image for Qdrant. +FROM debian:12-slim AS qdrant-cpu + + +# Base images for Qdrant with nvidia GPU support. +FROM nvidia/opengl:1.0-glvnd-devel-ubuntu22.04 AS qdrant-gpu-nvidia +# Set non-interactive mode for apt-get. +ENV DEBIAN_FRONTEND=noninteractive +# Set NVIDIA driver capabilities. By default, all capabilities are disabled. +ENV NVIDIA_DRIVER_CAPABILITIES compute,graphics,utility +# Copy Nvidia ICD loader file into the container. +COPY --from=builder /qdrant/lib/gpu/nvidia_icd.json /etc/vulkan/icd.d/ +# Override maintainer label. Nvidia base image have it's own maintainer label. +LABEL maintainer "Qdrant Team " + + +# Base images for Qdrant with amd GPU support. +FROM rocm/dev-ubuntu-22.04 AS qdrant-gpu-amd +# Set non-interactive mode for apt-get. +ENV DEBIAN_FRONTEND=noninteractive +# Override maintainer label. AMD base image have it's own maintainer label. +LABEL maintainer "Qdrant Team " + + +FROM qdrant-${GPU:+gpu-}${GPU:-cpu} AS qdrant RUN apt-get update +# Install GPU dependencies +ARG GPU + +RUN if [ -n "$GPU" ]; then \ + apt-get install -y \ + libvulkan1 \ + libvulkan-dev \ + vulkan-tools \ + ; fi + # Install additional packages into the container. # E.g., the debugger of choice: gdb/gdbserver/lldb. ARG PACKAGES diff --git a/lib/gpu/Cargo.toml b/lib/gpu/Cargo.toml index c25a7cf7a5..f2001e4e27 100644 --- a/lib/gpu/Cargo.toml +++ b/lib/gpu/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "gpu" -version = "0.0.1" +version = "0.1.0" authors = [ "Qdrant Team ", ] diff --git a/lib/gpu/nvidia_icd.json b/lib/gpu/nvidia_icd.json new file mode 100644 index 0000000000..f86d4956c9 --- /dev/null +++ b/lib/gpu/nvidia_icd.json @@ -0,0 +1,7 @@ +{ + "file_format_version" : "1.0.0", + "ICD": { + "library_path": "libGLX_nvidia.so.0", + "api_version" : "1.3" + } +}