Skip to content

Commit 7eb199c

Browse files
adamcavendishLegNeato
authored andcommitted
chore(docker): add support for multiple Linux distributions and CUDA versions
The Docker setup has been refactored to support Ubuntu 20.04, 24.04, and Rocky Linux 9 with CUDA 11/12. The original Dockerfile (Ubuntu 18.04 + CUDA 11.4) has been replaced with a matrix of distribution-specific Dockerfiles. Dependencies like LLVM 7 and Rust are now configured to work across these environments.
1 parent 6d79a12 commit 7eb199c

File tree

7 files changed

+140
-39
lines changed

7 files changed

+140
-39
lines changed

Dockerfile

-37
This file was deleted.

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,15 @@ Other projects related to using Rust on the GPU:
9292
cargo build
9393
```
9494

95+
## Use Rust-CUDA in Container Environments
96+
97+
```bash
98+
# The distribution related Dockerfile are located in `container` folder.
99+
# Taking ubuntu 24.04 as an example, run the following command in repository root:
100+
docker build -f ./container/ubuntu24/Dockerfile -t rust-cuda-ubuntu24 .
101+
docker run --rm --runtime=nvidia --gpus all -it rust-cuda-ubuntu24
102+
```
103+
95104
## License
96105

97106
Licensed under either of
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
FROM nvidia/cuda:12.8.1-cudnn-devel-rockylinux9
2+
3+
RUN dnf -y install \
4+
openssl-devel \
5+
pkgconfig \
6+
redhat-rpm-config \
7+
which \
8+
xz \
9+
zlib-devel
10+
11+
# Get LLVM 7 & libffi.so.6
12+
WORKDIR /data/llvm7
13+
RUN curl -sSf -L -O https://dl.fedoraproject.org/pub/epel/9/Everything/x86_64/Packages/l/libffi3.1-3.1-36.el9.x86_64.rpm
14+
RUN curl -sSf -L -O https://dl.fedoraproject.org/pub/epel/8/Everything/x86_64/Packages/l/llvm7.0-7.0.1-7.el8.x86_64.rpm
15+
RUN curl -sSf -L -O https://dl.fedoraproject.org/pub/epel/8/Everything/x86_64/Packages/l/llvm7.0-devel-7.0.1-7.el8.x86_64.rpm
16+
RUN curl -sSf -L -O https://dl.fedoraproject.org/pub/epel/8/Everything/x86_64/Packages/l/llvm7.0-libs-7.0.1-7.el8.x86_64.rpm
17+
RUN curl -sSf -L -O https://dl.fedoraproject.org/pub/epel/8/Everything/x86_64/Packages/l/llvm7.0-static-7.0.1-7.el8.x86_64.rpm
18+
RUN dnf -y install ./*.rpm
19+
RUN ln -s /usr/bin/llvm-config-7-64 /usr/bin/llvm-config
20+
21+
# Get Rust
22+
RUN curl -sSf -L https://sh.rustup.rs | bash -s -- -y
23+
ENV PATH="/root/.cargo/bin:${PATH}"
24+
25+
# Setup the workspace
26+
ADD . /data/Rust-CUDA
27+
WORKDIR /data/Rust-CUDA
28+
RUN rustup show
29+
30+
ENV LLVM_LINK_STATIC=1
31+
ENV RUST_LOG=info

container/ubuntu20-cuda11/Dockerfile

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
FROM nvidia/cuda:11.2.2-cudnn8-devel-ubuntu20.04
2+
3+
RUN apt-get update
4+
RUN DEBIAN_FRONTEND=noninteractive apt-get -qq -y install \
5+
build-essential \
6+
curl \
7+
libssl-dev \
8+
libtinfo-dev \
9+
pkg-config \
10+
xz-utils \
11+
zlib1g-dev
12+
13+
# Get LLVM 7
14+
WORKDIR /data/llvm7
15+
RUN curl -sSf -L -O http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/llvm-7_7.0.1-12_amd64.deb
16+
RUN curl -sSf -L -O http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/llvm-7-dev_7.0.1-12_amd64.deb
17+
RUN curl -sSf -L -O http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/libllvm7_7.0.1-12_amd64.deb
18+
RUN curl -sSf -L -O http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/llvm-7-runtime_7.0.1-12_amd64.deb
19+
RUN apt-get install -y ./*.deb
20+
RUN ln -s /usr/bin/llvm-config-7 /usr/bin/llvm-config
21+
22+
# Get Rust
23+
RUN curl -sSf -L https://sh.rustup.rs | bash -s -- -y
24+
ENV PATH="/root/.cargo/bin:${PATH}"
25+
26+
# Setup the workspace
27+
ADD . /data/Rust-CUDA
28+
WORKDIR /data/Rust-CUDA
29+
RUN rustup show
30+
31+
ENV LLVM_LINK_STATIC=1
32+
ENV RUST_LOG=info

container/ubuntu20-cuda12/Dockerfile

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
FROM nvidia/cuda:12.8.1-cudnn-devel-ubuntu20.04
2+
3+
RUN apt-get update
4+
RUN DEBIAN_FRONTEND=noninteractive apt-get -qq -y install \
5+
build-essential \
6+
curl \
7+
libssl-dev \
8+
libtinfo-dev \
9+
pkg-config \
10+
xz-utils \
11+
zlib1g-dev
12+
13+
# Get LLVM 7
14+
WORKDIR /data/llvm7
15+
RUN curl -sSf -L -O http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/llvm-7_7.0.1-12_amd64.deb
16+
RUN curl -sSf -L -O http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/llvm-7-dev_7.0.1-12_amd64.deb
17+
RUN curl -sSf -L -O http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/libllvm7_7.0.1-12_amd64.deb
18+
RUN curl -sSf -L -O http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/llvm-7-runtime_7.0.1-12_amd64.deb
19+
RUN apt-get install -y ./*.deb
20+
RUN ln -s /usr/bin/llvm-config-7 /usr/bin/llvm-config
21+
22+
# Get Rust
23+
RUN curl -sSf -L https://sh.rustup.rs | bash -s -- -y
24+
ENV PATH="/root/.cargo/bin:${PATH}"
25+
26+
# Setup the workspace
27+
ADD . /data/Rust-CUDA
28+
WORKDIR /data/Rust-CUDA
29+
RUN rustup show
30+
31+
ENV LLVM_LINK_STATIC=1
32+
ENV RUST_LOG=info

container/ubuntu24-cuda12/Dockerfile

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
FROM nvidia/cuda:12.8.1-cudnn-devel-ubuntu24.04
2+
3+
RUN apt-get update
4+
RUN DEBIAN_FRONTEND=noninteractive apt-get -qq -y install \
5+
build-essential \
6+
curl \
7+
libssl-dev \
8+
libtinfo-dev \
9+
pkg-config \
10+
xz-utils \
11+
zlib1g-dev
12+
13+
# Get LLVM 7 & libffi7
14+
WORKDIR /data/llvm7
15+
RUN curl -sSf -L -O http://security.ubuntu.com/ubuntu/pool/universe/libf/libffi7/libffi7_3.3-5ubuntu1_amd64.deb
16+
RUN curl -sSf -L -O http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/llvm-7_7.0.1-12_amd64.deb
17+
RUN curl -sSf -L -O http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/llvm-7-dev_7.0.1-12_amd64.deb
18+
RUN curl -sSf -L -O http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/libllvm7_7.0.1-12_amd64.deb
19+
RUN curl -sSf -L -O http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/llvm-7-runtime_7.0.1-12_amd64.deb
20+
RUN apt-get install -y ./*.deb
21+
RUN ln -s /usr/bin/llvm-config-7 /usr/bin/llvm-config
22+
23+
# Get Rust
24+
RUN curl -sSf -L https://sh.rustup.rs | bash -s -- -y
25+
ENV PATH="/root/.cargo/bin:${PATH}"
26+
27+
# Setup the workspace
28+
ADD . /data/Rust-CUDA
29+
WORKDIR /data/Rust-CUDA
30+
RUN rustup show
31+
32+
ENV LLVM_LINK_STATIC=1
33+
ENV RUST_LOG=info

crates/rustc_codegen_nvvm/build.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,9 @@ fn rustc_llvm_build() {
350350

351351
#[cfg(not(target_os = "windows"))]
352352
fn link_llvm_system_libs(llvm_config: &Path, components: &[&str]) {
353-
let mut cmd = Command::new(llvm_config);
354-
cmd.arg("--system-libs");
353+
let (_, llvm_link_arg) = detect_llvm_link();
354+
let mut cmd: Command = Command::new(llvm_config);
355+
cmd.arg(llvm_link_arg).arg("--system-libs");
355356

356357
for comp in components {
357358
cmd.arg(comp);

0 commit comments

Comments
 (0)