diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 01ed32be..00000000 --- a/Dockerfile +++ /dev/null @@ -1,37 +0,0 @@ -FROM nvidia/cuda:11.4.1-cudnn8-devel-ubuntu18.04 - -# Update default packages -RUN apt-get update - -# Get Ubuntu packages -RUN apt-get install -y \ - build-essential \ - curl xz-utils pkg-config libssl-dev zlib1g-dev libtinfo-dev libxml2-dev - -# Update new packages -RUN apt-get update - -# Get Rust -RUN curl https://sh.rustup.rs -sSf | bash -s -- -y - - -# get prebuilt llvm -RUN curl -O https://releases.llvm.org/7.0.1/clang+llvm-7.0.1-x86_64-linux-gnu-ubuntu-18.04.tar.xz &&\ - xz -d /clang+llvm-7.0.1-x86_64-linux-gnu-ubuntu-18.04.tar.xz &&\ - tar xf /clang+llvm-7.0.1-x86_64-linux-gnu-ubuntu-18.04.tar &&\ - rm /clang+llvm-7.0.1-x86_64-linux-gnu-ubuntu-18.04.tar &&\ - mv /clang+llvm-7.0.1-x86_64-linux-gnu-ubuntu-18.04 /root/llvm - -# set env -ENV LLVM_CONFIG=/root/llvm/bin/llvm-config -ENV CUDA_ROOT=/usr/local/cuda -ENV CUDA_PATH=$CUDA_ROOT -ENV LLVM_LINK_STATIC=1 -ENV RUST_LOG=info -ENV PATH=$CUDA_ROOT/nvvm/lib64:/root/.cargo/bin:$PATH - -# make ld aware of necessary *.so libraries -RUN echo $CUDA_ROOT/lib64 >> /etc/ld.so.conf &&\ - echo $CUDA_ROOT/compat >> /etc/ld.so.conf &&\ - echo $CUDA_ROOT/nvvm/lib64 >> /etc/ld.so.conf &&\ - ldconfig diff --git a/README.md b/README.md index d715320c..4fdb9182 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,15 @@ Other projects related to using Rust on the GPU: cargo build ``` +## Use Rust-CUDA in Container Environments + +```bash +# The distribution related Dockerfile are located in `container` folder. +# Taking ubuntu 24.04 as an example, run the following command in repository root: +docker build -f ./container/ubuntu24/Dockerfile -t rust-cuda-ubuntu24 . +docker run --rm --runtime=nvidia --gpus all -it rust-cuda-ubuntu24 +``` + ## License Licensed under either of diff --git a/container/rockylinux9-cuda12/Dockerfile b/container/rockylinux9-cuda12/Dockerfile new file mode 100644 index 00000000..2f9205a9 --- /dev/null +++ b/container/rockylinux9-cuda12/Dockerfile @@ -0,0 +1,31 @@ +FROM nvidia/cuda:12.8.1-cudnn-devel-rockylinux9 + +RUN dnf -y install \ + openssl-devel \ + pkgconfig \ + redhat-rpm-config \ + which \ + xz \ + zlib-devel + +# Get LLVM 7 & libffi.so.6 +WORKDIR /data/llvm7 +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 +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 +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 +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 +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 +RUN dnf -y install ./*.rpm +RUN ln -s /usr/bin/llvm-config-7-64 /usr/bin/llvm-config + +# Get Rust +RUN curl -sSf -L https://sh.rustup.rs | bash -s -- -y +ENV PATH="/root/.cargo/bin:${PATH}" + +# Setup the workspace +ADD . /data/Rust-CUDA +WORKDIR /data/Rust-CUDA +RUN rustup show + +ENV LLVM_LINK_STATIC=1 +ENV RUST_LOG=info \ No newline at end of file diff --git a/container/ubuntu20-cuda11/Dockerfile b/container/ubuntu20-cuda11/Dockerfile new file mode 100644 index 00000000..baeb1826 --- /dev/null +++ b/container/ubuntu20-cuda11/Dockerfile @@ -0,0 +1,32 @@ +FROM nvidia/cuda:11.2.2-cudnn8-devel-ubuntu20.04 + +RUN apt-get update +RUN DEBIAN_FRONTEND=noninteractive apt-get -qq -y install \ + build-essential \ + curl \ + libssl-dev \ + libtinfo-dev \ + pkg-config \ + xz-utils \ + zlib1g-dev + +# Get LLVM 7 +WORKDIR /data/llvm7 +RUN curl -sSf -L -O http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/llvm-7_7.0.1-12_amd64.deb +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 +RUN curl -sSf -L -O http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/libllvm7_7.0.1-12_amd64.deb +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 +RUN apt-get install -y ./*.deb +RUN ln -s /usr/bin/llvm-config-7 /usr/bin/llvm-config + +# Get Rust +RUN curl -sSf -L https://sh.rustup.rs | bash -s -- -y +ENV PATH="/root/.cargo/bin:${PATH}" + +# Setup the workspace +ADD . /data/Rust-CUDA +WORKDIR /data/Rust-CUDA +RUN rustup show + +ENV LLVM_LINK_STATIC=1 +ENV RUST_LOG=info \ No newline at end of file diff --git a/container/ubuntu20-cuda12/Dockerfile b/container/ubuntu20-cuda12/Dockerfile new file mode 100644 index 00000000..51a9ab28 --- /dev/null +++ b/container/ubuntu20-cuda12/Dockerfile @@ -0,0 +1,32 @@ +FROM nvidia/cuda:12.8.1-cudnn-devel-ubuntu20.04 + +RUN apt-get update +RUN DEBIAN_FRONTEND=noninteractive apt-get -qq -y install \ + build-essential \ + curl \ + libssl-dev \ + libtinfo-dev \ + pkg-config \ + xz-utils \ + zlib1g-dev + +# Get LLVM 7 +WORKDIR /data/llvm7 +RUN curl -sSf -L -O http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/llvm-7_7.0.1-12_amd64.deb +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 +RUN curl -sSf -L -O http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/libllvm7_7.0.1-12_amd64.deb +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 +RUN apt-get install -y ./*.deb +RUN ln -s /usr/bin/llvm-config-7 /usr/bin/llvm-config + +# Get Rust +RUN curl -sSf -L https://sh.rustup.rs | bash -s -- -y +ENV PATH="/root/.cargo/bin:${PATH}" + +# Setup the workspace +ADD . /data/Rust-CUDA +WORKDIR /data/Rust-CUDA +RUN rustup show + +ENV LLVM_LINK_STATIC=1 +ENV RUST_LOG=info \ No newline at end of file diff --git a/container/ubuntu24-cuda12/Dockerfile b/container/ubuntu24-cuda12/Dockerfile new file mode 100644 index 00000000..f2cc618c --- /dev/null +++ b/container/ubuntu24-cuda12/Dockerfile @@ -0,0 +1,33 @@ +FROM nvidia/cuda:12.8.1-cudnn-devel-ubuntu24.04 + +RUN apt-get update +RUN DEBIAN_FRONTEND=noninteractive apt-get -qq -y install \ + build-essential \ + curl \ + libssl-dev \ + libtinfo-dev \ + pkg-config \ + xz-utils \ + zlib1g-dev + +# Get LLVM 7 & libffi7 +WORKDIR /data/llvm7 +RUN curl -sSf -L -O http://security.ubuntu.com/ubuntu/pool/universe/libf/libffi7/libffi7_3.3-5ubuntu1_amd64.deb +RUN curl -sSf -L -O http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/llvm-7_7.0.1-12_amd64.deb +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 +RUN curl -sSf -L -O http://mirrors.kernel.org/ubuntu/pool/universe/l/llvm-toolchain-7/libllvm7_7.0.1-12_amd64.deb +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 +RUN apt-get install -y ./*.deb +RUN ln -s /usr/bin/llvm-config-7 /usr/bin/llvm-config + +# Get Rust +RUN curl -sSf -L https://sh.rustup.rs | bash -s -- -y +ENV PATH="/root/.cargo/bin:${PATH}" + +# Setup the workspace +ADD . /data/Rust-CUDA +WORKDIR /data/Rust-CUDA +RUN rustup show + +ENV LLVM_LINK_STATIC=1 +ENV RUST_LOG=info \ No newline at end of file diff --git a/crates/rustc_codegen_nvvm/build.rs b/crates/rustc_codegen_nvvm/build.rs index f9461a20..a1c45b4e 100644 --- a/crates/rustc_codegen_nvvm/build.rs +++ b/crates/rustc_codegen_nvvm/build.rs @@ -350,8 +350,9 @@ fn rustc_llvm_build() { #[cfg(not(target_os = "windows"))] fn link_llvm_system_libs(llvm_config: &Path, components: &[&str]) { - let mut cmd = Command::new(llvm_config); - cmd.arg("--system-libs"); + let (_, llvm_link_arg) = detect_llvm_link(); + let mut cmd: Command = Command::new(llvm_config); + cmd.arg(llvm_link_arg).arg("--system-libs"); for comp in components { cmd.arg(comp);