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 150d54a
Show file tree
Hide file tree
Showing 7 changed files with 211 additions and 22 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
39 changes: 34 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,44 +66,66 @@ jobs:
matrix:
include:
- os: ubuntu-20.04
cuda: "12.6"
# Oldest supported version, keep in sync with README.md
rustc: "1.75.0"
extra_args: --features=all,dist-server -- --nocapture
- 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
extra_args: --no-default-features --features=dist-tests test_dist_ -- --nocapture --test-threads 1
- os: ubuntu-20.04
cuda: "12.6"
rustc: stable
extra_args: --features=all,dist-server -- --nocapture
- os: ubuntu-20.04
cuda: "12.6"
rustc: beta
extra_args: --features=all,dist-server -- --nocapture
- os: ubuntu-20.04
cuda: "12.6"
rustc: nightly
allow_failure: true
extra_args: --features=unstable
extra_args: --features=all,dist-server,unstable -- --nocapture
- os: ubuntu-20.04
cuda: "12.6"
extra_desc: no-default-features
extra_args: --no-default-features
extra_args: --no-default-features -- --nocapture
allow_failure: true
- os: ubuntu-22.04
cuda: "12.6"
extra_args: --features=all,dist-server -- --nocapture
- 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"
extra_args: --features=all,dist-server -- --nocapture
- os: windows-2019
cuda: "12.6"
rustc: nightly
allow_failure: true
extra_args: --features=unstable
extra_args: --features=all,dist-server,unstable
- os: windows-2019
cuda: "12.6"
rustc: beta
extra_args: --features=all,dist-server -- --nocapture
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 Down Expand Up @@ -207,9 +229,10 @@ jobs:
matrix:
include:
- os: ubuntu-20.04
cuda: "12.6"
rustc: nightly
allow_failure: true
extra_args: --features=unstable
extra_args: --features=all,dist-server,unstable -- --nocapture
- os: macos-13
rustc: nightly
# Disable on Windows for now as it fails with:
Expand All @@ -222,6 +245,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 Down
2 changes: 2 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1391,6 +1391,7 @@ fn test_s3_no_credentials_valid_false() {

#[test]
fn test_gcs_service_account() {
env::set_var("SCCACHE_S3_NO_CREDENTIALS", "false");
env::set_var("SCCACHE_GCS_BUCKET", "my-bucket");
env::set_var("SCCACHE_GCS_SERVICE_ACCOUNT", "my@example.com");
env::set_var("SCCACHE_GCS_RW_MODE", "READ_WRITE");
Expand All @@ -1410,6 +1411,7 @@ fn test_gcs_service_account() {
None => unreachable!(),
};

env::remove_var("SCCACHE_S3_NO_CREDENTIALS");
env::remove_var("SCCACHE_GCS_BUCKET");
env::remove_var("SCCACHE_GCS_SERVICE_ACCOUNT");
env::remove_var("SCCACHE_GCS_RW_MODE");
Expand Down
2 changes: 1 addition & 1 deletion tests/harness/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub fn get_stats<F: 'static + Fn(ServerInfo)>(f: F) {
.stdout(predicate::function(move |output: &[u8]| {
let s = str::from_utf8(output).expect("Output not UTF-8");
let stats = serde_json::from_str(s).expect("Failed to parse JSON stats");
eprintln!("get server stats: {stats:?}");
// eprintln!("get server stats: {stats:?}");
f(stats);
true
}));
Expand Down
Loading

0 comments on commit 150d54a

Please sign in to comment.