Skip to content

Commit

Permalink
install CUDA toolkit so we test nvcc in workflows/ci.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
trxcllnt committed Oct 16, 2024
1 parent 6251699 commit 70e1a17
Show file tree
Hide file tree
Showing 5 changed files with 177 additions and 2 deletions.
16 changes: 16 additions & 0 deletions .github/actions/nvcc-toolchain/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: nvcc-toolchain
inputs:
cuda-version:
description: CUDA Toolkit version
required: true

runs:
using: composite
steps:
- if: runner.os == 'Linux'
shell: bash
run: .github/actions/nvcc-toolchain/install-cuda.sh ${{ inputs.cuda-version }}

- if: runner.os == 'Windows'
shell: powershell
run: .\.github\actions\nvcc-toolchain\install-cuda.ps1 -cudaVersion ${{ inputs.cuda-version }}
47 changes: 47 additions & 0 deletions .github/actions/nvcc-toolchain/install-cuda.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
Param(
[Parameter(Mandatory=$false)]
[string]
$cudaVersion="12.6.0"
)

# Use System.Version to tokenize version
$version = [Version]$cudaVersion

$major = $version.Major
$minor = $version.Minor
$build = $version.Build

# Minimum build is 0, not -1 as default in case "12.5" is passed
if ($build -lt 0) {
$build = 0
}

# mmb == major minor build
$mmbVersionTag = "${major}.${minor}.${build}"
# mm = major minor
$mmVersionTag = "${major}.${minor}"

$cudaMajorUri = @{
"11" = "${mmbVersionTag}/network_installers/cuda_${mmbVersionTag}_win10_network.exe"
"12" = "${mmbVersionTag}/network_installers/cuda_${mmbVersionTag}_windows_network.exe"
}["$major"]

$cudaVersionUrl = "https://developer.download.nvidia.com/compute/cuda/$cudaMajorUri"
$cudaComponents =
"nvcc_$mmVersionTag",
"curand_$mmVersionTag",
"curand_dev_$mmVersionTag",
"cudart_$mmVersionTag",
"cupti_$mmVersionTag",
"nvrtc_$mmVersionTag",
"nvrtc_dev_$mmVersionTag",
"nvml_dev_$mmVersionTag",
"nvtx_$mmVersionTag"

Invoke-WebRequest -Uri "$cudaVersionUrl" -OutFile "./cuda_network.exe" -UseBasicParsing
Start-Process -Wait -PassThru -FilePath .\cuda_network.exe -ArgumentList "-s $cudaComponents"

$ENV:PATH="$ENV:PATH;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v$mmVersionTag\bin"
$ENV:CUDA_PATH="C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v$mmVersionTag"

Remove-Item .\cuda_network.exe
88 changes: 88 additions & 0 deletions .github/actions/nvcc-toolchain/install-cuda.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#! /usr/bin/env bash
set -eux

export DEBIAN_FRONTEND=noninteractive

get_cuda_deb() {
local deb="$( \
wget --no-hsts -q -O- "${1}/Packages" \
| grep -P "^Filename: \./${2}(.*)\.deb$" \
| sort -Vr | head -n1 | cut -d' ' -f2 \
)";
if [ -z "$deb" ]; then
echo "Error: No matching .deb found for '${1}' and '${2}'" >&2
return 1
fi
wget --no-hsts -q -O "/tmp/${deb#./}" "${1}/${deb#./}";
echo -n "/tmp/${deb#./}";
}

VERSION="$1";

NVARCH="$(uname -p)";

if test "$NVARCH" = aarch64; then
NVARCH="sbsa";
fi

OSNAME="$(
. /etc/os-release;
major="$(cut -d'.' -f1 <<< "${VERSION_ID}")";
minor="$(cut -d'.' -f2 <<< "${VERSION_ID}")";
echo "$ID$((major - (major % 2)))${minor}";
)";

CUDA_HOME="/usr/local/cuda";

cuda_repo_base="https://developer.download.nvidia.com/compute/cuda/repos";
cuda_repo="${cuda_repo_base}/${OSNAME}/${NVARCH}";

cuda_ver="$VERSION";
cuda_ver="$(grep -Po '^[0-9]+\.[0-9]+' <<< "${cuda_ver}")";
cuda_ver="${cuda_ver/./-}";

if ! dpkg -s cuda-keyring; then
sudo apt-get install -y --no-install-recommends \
"$(get_cuda_deb "${cuda_repo}" cuda-keyring)" \
;
fi

PKGS=();
PKGS+=("cuda-nvcc-${cuda_ver}");

sudo apt-get update;
sudo apt-get install -y --no-install-recommends "${PKGS[@]}";

if ! test -L "${CUDA_HOME}"; then
# Create /usr/local/cuda symlink
sudo ln -s "${CUDA_HOME}-${cuda_ver}" "${CUDA_HOME}";
fi

if test -z "${CUDA_VERSION:-}"; then
if test -f "${CUDA_HOME}/include/cuda.h"; then
cuda_ver="$(grep "#define CUDA_VERSION" "${CUDA_HOME}/include/cuda.h" | cut -d' ' -f3)";
CUDA_VERSION_MAJOR="$((cuda_ver / 1000))";
CUDA_VERSION_MINOR="$((cuda_ver / 10 % 100))";
CUDA_VERSION_PATCH="$((cuda_ver % 10))";
CUDA_VERSION="$CUDA_VERSION_MAJOR.$CUDA_VERSION_MINOR.$CUDA_VERSION_PATCH";
else
CUDA_VERSION_MAJOR="$(cut -d'.' -f1 <<< "${VERSION}")";
CUDA_VERSION_MINOR="$(cut -d'.' -f2 <<< "${VERSION}")";
CUDA_VERSION_PATCH="$(cut -d'.' -f3 <<< "${VERSION}")";
CUDA_VERSION_PATCH="${CUDA_VERSION_PATCH:-0}"
CUDA_VERSION="$CUDA_VERSION_MAJOR.$CUDA_VERSION_MINOR.$CUDA_VERSION_PATCH";
fi
fi

cat <<EOF | tee -a "$GITHUB_ENV"
NVARCH="$NVARCH"
CUDA_HOME="$CUDA_HOME"
CUDA_PATH="$CUDA_HOME"
CUDA_VERSION="$CUDA_VERSION"
CUDA_VERSION_MAJOR="$CUDA_VERSION_MAJOR"
CUDA_VERSION_MINOR="$CUDA_VERSION_MINOR"
CUDA_VERSION_PATCH="$CUDA_VERSION_PATCH"
PATH="$CUDA_HOME/bin:${PATH}"
EOF

rm /tmp/*.deb
27 changes: 25 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,44 +66,60 @@ jobs:
matrix:
include:
- os: ubuntu-20.04
cuda: "12.6"
# Oldest supported version, keep in sync with README.md
rustc: "1.75.0"
- os: ubuntu-22.04
cuda: "12.6"
# Oldest supported version, keep in sync with README.md
rustc: "1.75.0"
extra_desc: dist-server
extra_args: --no-default-features --features=dist-tests test_dist_ -- --test-threads 1
- os: ubuntu-20.04
cuda: "12.6"
rustc: stable
- os: ubuntu-20.04
cuda: "12.6"
rustc: beta
- os: ubuntu-20.04
cuda: "12.6"
rustc: nightly
allow_failure: true
extra_args: --features=unstable
- os: ubuntu-20.04
cuda: "12.6"
extra_desc: no-default-features
extra_args: --no-default-features
allow_failure: true
- os: ubuntu-22.04
cuda: "12.6"
- os: macos-13
# M1 CPU
- os: macos-14
- os: windows-2019
cuda: "12.6"
# Oldest supported version, keep in sync with README.md
rustc: "1.75.0"
- os: windows-2019
cuda: "12.6"
rustc: nightly
allow_failure: true
extra_args: --features=unstable
- os: windows-2019
cuda: "12.6"
rustc: beta
env:
RUST_BACKTRACE: 1
steps:
- name: Clone repository
uses: actions/checkout@v4

- if: contains(fromJSON('["Linux", "Windows"]'), runner.os)
name: Install nvcc
uses: ./.github/actions/nvcc-toolchain
with:
cuda-version: ${{ matrix.cuda }}

- name: Install rust
uses: ./.github/actions/rust-toolchain
with:
Expand All @@ -117,7 +133,7 @@ jobs:
run: cargo test --no-run --locked --all-targets ${{ matrix.extra_args }}

- name: Run tests
run: cargo test --locked --all-targets ${{ matrix.extra_args }}
run: cargo test --locked --all-targets ${{ matrix.extra_args }} -- --nocapture

- name: Upload failure
if: failure()
Expand Down Expand Up @@ -207,6 +223,7 @@ jobs:
matrix:
include:
- os: ubuntu-20.04
cuda: "12.6"
rustc: nightly
allow_failure: true
extra_args: --features=unstable
Expand All @@ -222,6 +239,12 @@ jobs:
- name: Clone repository
uses: actions/checkout@v4

- if: contains(fromJSON('["Linux", "Windows"]'), runner.os)
name: Install nvcc
uses: ./.github/actions/nvcc-toolchain
with:
cuda-version: ${{ matrix.cuda }}

- name: Install rust
uses: ./.github/actions/rust-toolchain
with:
Expand All @@ -235,7 +258,7 @@ jobs:
run: cargo install grcov

- name: Execute tests
run: cargo test --no-fail-fast --locked --all-targets ${{ matrix.extra_args }}
run: cargo test --no-fail-fast --locked --all-targets ${{ matrix.extra_args }} -- --nocapture
env:
CARGO_INCREMENTAL: "0"
RUSTC_WRAPPER: ""
Expand Down
1 change: 1 addition & 0 deletions tests/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1492,6 +1492,7 @@ fn test_cuda_sccache_command(preprocessor_cache_mode: bool) {
&sccache_cached_cfg_path,
);
for compiler in compilers {
eprintln!("CUDA compiler: {:?}", compiler.exe);
match compiler.name {
"nvcc" => run_sccache_nvcc_cuda_command_tests(compiler, tempdir.path()),
"clang++" => run_sccache_clang_cuda_command_tests(compiler, tempdir.path()),
Expand Down

0 comments on commit 70e1a17

Please sign in to comment.