Skip to content

Commit f9a50ae

Browse files
authored
feat: minimize CUDA install with Conda (#4)
* feat: minimize CUDA install with Conda * feat: increase matrix volume * test: test CUDA Toolkit
1 parent 867c120 commit f9a50ae

File tree

3 files changed

+57
-80
lines changed

3 files changed

+57
-80
lines changed

.github/workflows/publish.yml

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build and deploy
1+
name: Publish
22

33
on:
44
push:
@@ -7,37 +7,30 @@ on:
77
- master
88

99
jobs:
10-
build_and_push_to_dockerhub:
10+
publish:
1111
runs-on: ubuntu-latest
1212

1313
strategy:
1414
matrix:
15-
version:
16-
- python: "3.8"
17-
tag: "3.8-cuda11.8"
18-
- python: "3.9"
19-
tag: "3.9-cuda11.8"
20-
- python: "3.10"
21-
tag: "3.10-cuda11.8"
15+
python-version: ["3.8", "3.9", "3.10", "3.11"]
16+
cuda-version: ["11.8", "12.2"]
2217

2318
steps:
2419
- name: Checkout
2520
uses: actions/checkout@v3
2621

27-
- name: Login to DockerHub
22+
- name: Login to Docker Hub
2823
uses: docker/login-action@v1
2924
with:
3025
username: ${{ secrets.REGISTRY_USERNAME }}
3126
password: ${{ secrets.REGISTRY_PASSWORD }}
3227

33-
- name: Setup Docker Buildx
34-
id: buildx
35-
uses: docker/setup-buildx-action@v1
36-
3728
- name: Build and push Docker image
38-
uses: docker/build-push-action@v2
29+
uses: docker/build-push-action@v4
3930
with:
31+
build-args: |
32+
"PYTHON_VERSION=${{ matrix.python-version }}"
33+
"CUDA_VERSION=${{ matrix.cuda-version }}"
4034
context: .
4135
push: true
42-
build-args: PYTHON_VERSION=${{ matrix.version.python }}
43-
tags: radixai/python-gpu:${{ matrix.version.tag }}
36+
tags: radixai/python-gpu:${{ matrix.python-version }}-cuda${{ matrix.cuda-version }}

.github/workflows/test.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Test
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
test:
8+
runs-on: ubuntu-latest
9+
10+
strategy:
11+
matrix:
12+
python-version: ["3.8", "3.11"]
13+
cuda-version: ["11.8", "12.2"]
14+
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v3
18+
19+
- name: Login to Docker Hub
20+
uses: docker/login-action@v1
21+
with:
22+
username: ${{ secrets.REGISTRY_USERNAME }}
23+
password: ${{ secrets.REGISTRY_PASSWORD }}
24+
25+
- name: Build Docker image
26+
uses: docker/build-push-action@v4
27+
with:
28+
build-args: |
29+
"PYTHON_VERSION=${{ matrix.python-version }}"
30+
"CUDA_VERSION=${{ matrix.cuda-version }}"
31+
context: .
32+
tags: radixai/python-gpu:${{ matrix.python-version }}-cuda${{ matrix.cuda-version }}
33+
34+
- name: Test Docker image
35+
run: docker run --rm radixai/python-gpu:${{ matrix.python-version }}-cuda${{ matrix.cuda-version }} nvcc --version

Dockerfile

Lines changed: 12 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,19 @@
11
# syntax=docker/dockerfile:1
22
ARG PYTHON_VERSION=3.8
3+
ARG CUDA_VERSION=11.8
34
FROM python:$PYTHON_VERSION-slim AS base
45

5-
ARG CUDA=11.8
6-
ARG NV_CUDA_CUDART_VERSION=11.8.89-1
7-
ARG NV_CUDA_COMPAT_PACKAGE=cuda-compat-11-8
8-
# CUDDN
9-
ARG CUDNN_VERSION=8.6.0.163-1+cuda11.8
10-
# TensorRT
11-
ARG LIBINVER_VERSION=8.4.3-1+cuda11.6
12-
13-
# NVIDIA: https://gitlab.com/nvidia/container-images/cuda/-/blob/master/dist/11.8.0/ubuntu2204/base/Dockerfile
14-
# specify the version of the CUDA Toolkit to use and the which driver versions are compatible for each brand of GPU.
15-
16-
ENV NVARCH x86_64
17-
ENV CUDA $CUDA
18-
ENV CUDNN_VERSION $CUDNN_VERSION
19-
ENV NV_CUDA_CUDART_VERSION $NV_CUDA_CUDART_VERSION
20-
ENV NV_CUDA_COMPAT_PACKAGE $NV_CUDA_COMPAT_PACKAGE
21-
ENV LIBINVER_VERSION $LIBINVER_VERSION
22-
ENV NVIDIA_REQUIRE_CUDA "cuda>=$CUDA brand=tesla,driver>=450,driver<451 brand=tesla,driver>=470,driver<471 brand=unknown,driver>=470,driver<471 brand=nvidia,driver>=470,driver<471 brand=nvidiartx,driver>=470,driver<471 brand=geforce,driver>=470,driver<471 brand=geforcertx,driver>=470,driver<471 brand=quadro,driver>=470,driver<471 brand=quadrortx,driver>=470,driver<471 brand=titan,driver>=470,driver<471 brand=titanrtx,driver>=470,driver<471 brand=tesla,driver>=510,driver<511 brand=unknown,driver>=510,driver<511 brand=nvidia,driver>=510,driver<511 brand=nvidiartx,driver>=510,driver<511 brand=geforce,driver>=510,driver<511 brand=geforcertx,driver>=510,driver<511 brand=quadro,driver>=510,driver<511 brand=quadrortx,driver>=510,driver<511 brand=titan,driver>=510,driver<511 brand=titanrtx,driver>=510,driver<511 brand=tesla,driver>=515,driver<516 brand=unknown,driver>=515,driver<516 brand=nvidia,driver>=515,driver<516 brand=nvidiartx,driver>=515,driver<516 brand=geforce,driver>=515,driver<516 brand=geforcertx,driver>=515,driver<516 brand=quadro,driver>=515,driver<516 brand=quadrortx,driver>=515,driver<516 brand=titan,driver>=515,driver<516 brand=titanrtx,driver>=515,driver<516"
23-
24-
# Updates the package index and installs the necessarys packages to add the CUDA repository, including `gnupg2`, `curl`, and `ca-certificates`.
25-
RUN apt-get update && apt-get install -y --no-install-recommends \
26-
gnupg2 curl ca-certificates && \
27-
curl -fsSLO https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/${NVARCH}/cuda-keyring_1.0-1_all.deb && \
28-
dpkg -i cuda-keyring_1.0-1_all.deb && \
29-
apt-get purge --autoremove -y curl \
30-
&& rm -rf /var/lib/apt/lists/*
31-
32-
# Install CUDA Toolkit, cuDNN SDK, optionally TensorRT
33-
RUN apt-get update && apt-get install -y --no-install-recommends \
34-
cuda-cudart-${CUDA%.*}-${CUDA#*.}=${NV_CUDA_CUDART_VERSION} \
35-
${NV_CUDA_COMPAT_PACKAGE} \
36-
cuda-command-line-tools-${CUDA%.*}-${CUDA#*.} \
37-
libcublas-dev-${CUDA%.*}-${CUDA#*.} \
38-
cuda-nvcc-${CUDA%.*}-${CUDA#*.} \
39-
libcublas-${CUDA%.*}-${CUDA#*.} \
40-
cuda-cupti-${CUDA%.*}-${CUDA#*.} \
41-
cuda-nvrtc-${CUDA%.*}-${CUDA#*.} \
42-
cuda-nvprune-${CUDA%.*}-${CUDA#*.} \
43-
cuda-libraries-${CUDA%.*}-${CUDA#*.} \
44-
libcufft-${CUDA%.*}-${CUDA#*.} \
45-
libcurand-${CUDA%.*}-${CUDA#*.} \
46-
libcusolver-${CUDA%.*}-${CUDA#*.} \
47-
libcusparse-${CUDA%.*}-${CUDA#*.} \
48-
libtool \
49-
libcudnn8=${CUDNN_VERSION}\
50-
libnvinfer8=${LIBINVER_VERSION} \
51-
libnvinfer-plugin8=${LIBINVER_VERSION} \
52-
build-essential \
53-
pkg-config \
54-
software-properties-common \
55-
unzip && \
56-
find /usr/local/cuda-${CUDA}/lib64/ -type f -name 'lib*_static.a' -not -name 'libcudart_static.a' -delete \
57-
&& apt-get clean && \
6+
# Install wget.
7+
RUN apt-get update && \
8+
apt-get install --yes wget && \
9+
apt-get clean && \
5810
rm -rf /var/lib/apt/lists/*
5911

60-
# # Required for nvidia-docker v1
61-
RUN echo "/usr/local/nvidia/lib" >> /etc/ld.so.conf.d/nvidia.conf \
62-
&& echo "/usr/local/nvidia/lib64" >> /etc/ld.so.conf.d/nvidia.conf
63-
64-
# Sets environment variables that are required by the `nvidia-container-runtime` to expose all the NVIDIA devices and enable compute and utility capabilities
65-
ENV NVIDIA_VISIBLE_DEVICES all
66-
ENV NVIDIA_DRIVER_CAPABILITIES compute,utility
12+
# Install Miniconda.
13+
RUN CONDA_ARCH=$([ "$TARGETARCH" = "arm64" ] && echo "aarch64" || echo "x86_64") && \
14+
wget --quiet "https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-$CONDA_ARCH.sh" --output-document ~/miniconda.sh && \
15+
/bin/bash ~/miniconda.sh -b -p /opt/conda
16+
ENV PATH=/opt/conda/bin:$PATH
6717

68-
# Adds the NVIDIA binary paths to the system's `PATH` environment variable.
69-
ENV PATH /usr/local/nvidia/bin:/usr/local/cuda/bin:${PATH}
70-
ENV LD_LIBRARY_PATH /usr/local/nvidia/lib:/usr/local/nvidia/lib64
18+
# Install CUDA.
19+
RUN conda install --channel nvidia --yes cuda="$CUDA_VERSION"

0 commit comments

Comments
 (0)