Skip to content

Commit

Permalink
Test nvcc and clang-cuda in workflows/ci.yml
Browse files Browse the repository at this point in the history
* Test nvcc and clang-cuda in workflows/ci.yml
* Fix clang-cuda tests
* Ensure /tmp/sccache_*.txt files are included in failed job artifacts on Windows
  • Loading branch information
trxcllnt committed Oct 18, 2024
1 parent cd61917 commit 1c36942
Show file tree
Hide file tree
Showing 10 changed files with 307 additions and 39 deletions.
7 changes: 3 additions & 4 deletions .github/actions/artifact_failure/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ runs:
lsof +D `pwd` || true
killall sccache || true
killall sccache-dist || true
# possible temp dirs for either linux or windows
cp "${TMP:-${TEMP:-${TMPDIR:-/tmp}}}"/sccache_*.txt . 2>/dev/null || true
tar --exclude='target' \
--exclude='docs' \
--exclude='bins' \
Expand All @@ -25,6 +26,4 @@ runs:
- uses: actions/upload-artifact@v3
with:
name: ${{ inputs.name }}
path: |
target/failure-${{ inputs.name }}.tar.gz
/tmp/sccache_*.txt
path: target/failure-${{ inputs.name }}.tar.gz
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 }}
50 changes: 50 additions & 0 deletions .github/actions/nvcc-toolchain/install-cuda.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
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}"

# `cuda_${mmbVersionTag}_windows_network.exe` name only valid back to CUDA v11.5.1.
# Before that it was named `cuda_${mmbVersionTag}_win10_network.exe`.
$cudaVersionUrl = "https://developer.download.nvidia.com/compute/cuda/${mmbVersionTag}/network_installers/cuda_${mmbVersionTag}_windows_network.exe"
$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"

$PATH_STR="PATH=$ENV:PATH"
$PATH_STR | Out-File -Append $ENV:GITHUB_ENV

$CUDA_PATH_STR="CUDA_PATH=$ENV:CUDA_PATH"
$CUDA_PATH_STR | Out-File -Append $ENV:GITHUB_ENV

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

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-toolkit-${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

export PATH="$PATH:$CUDA_HOME/bin"

which -a nvcc
nvcc --version

cat <<EOF | tee -a "$GITHUB_ENV"
CUDA_HOME=$CUDA_HOME
CUDA_PATH=$CUDA_HOME
PATH=$PATH
EOF

rm /tmp/*.deb
72 changes: 65 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,53 @@ jobs:
extra_args: --no-default-features
allow_failure: true
- os: ubuntu-22.04
- os: macos-13
# M1 CPU
- os: macos-14
cuda: "11.8"
extra_desc: cuda11.8
- os: ubuntu-24.04
cuda: "12.6"
# Oldest supported version, keep in sync with README.md
rustc: "1.75.0"
extra_desc: cuda12.6
# - os: macos-13
# # M1 CPU
# - os: macos-14
- os: windows-2019
cuda: "11.8"
# Oldest supported version, keep in sync with README.md
rustc: "1.75.0"
extra_args: --no-fail-fast
extra_desc: cuda11.8
- os: windows-2019
cuda: "11.8"
rustc: nightly
allow_failure: true
extra_args: --features=unstable
extra_desc: cuda11.8
- os: windows-2019
cuda: "11.8"
rustc: beta
extra_desc: cuda11.8
- os: windows-2022
cuda: "12.6"
# Oldest supported version, keep in sync with README.md
rustc: "1.75.0"
extra_args: --no-fail-fast
extra_desc: cuda12.6
- os: windows-2022
cuda: "12.6"
rustc: nightly
allow_failure: true
extra_args: --features=unstable
extra_desc: cuda12.6
- os: windows-2022
cuda: "12.6"
rustc: beta
extra_desc: cuda12.6
env:
RUST_BACKTRACE: 1
steps:
- uses: ilammy/msvc-dev-cmd@v1

- name: Clone repository
uses: actions/checkout@v4

Expand All @@ -109,9 +141,28 @@ jobs:
with:
toolchain: ${{ matrix.rustc }}

- name: Install gcc & clang for tests
run: sudo apt-get install -y clang gcc
if: ${{ matrix.os == 'ubuntu-20.04' || matrix.os == 'ubuntu-22.04' }}
- if: ${{ contains(matrix.os, 'ubuntu') }}
name: Install gcc & clang for tests
env:
DEBIAN_FRONTEND: noninteractive
run: |
set -x
# Conflicts with clang-cuda
if dpkg -s gcc-14 >/dev/null 2>&1; then
sudo apt remove -y gcc-14 g++-14
sudo apt autoremove -y
fi
sudo apt install -y --no-install-recommends clang gcc
echo 'gcc version:'
gcc --version
echo 'clang version:'
clang --version
- if: matrix.cuda != '' && contains(fromJSON('["Linux", "Windows"]'), runner.os)
name: Install nvcc
uses: ./.github/actions/nvcc-toolchain
with:
cuda-version: ${{ matrix.cuda }}

- name: Build tests
run: cargo test --no-run --locked --all-targets ${{ matrix.extra_args }}
Expand Down Expand Up @@ -206,7 +257,8 @@ jobs:
fail-fast: false
matrix:
include:
- os: ubuntu-20.04
- os: ubuntu-22.04
cuda: "11.8"
rustc: nightly
allow_failure: true
extra_args: --features=unstable
Expand All @@ -231,6 +283,12 @@ jobs:
run: sudo apt-get install -y clang gcc
if: ${{ matrix.os == 'ubuntu-20.04' }}

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

- name: "`grcov` ~ install"
run: cargo install grcov

Expand Down
19 changes: 19 additions & 0 deletions src/compiler/clang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ impl CCompilerImpl for Clang {
self.kind(),
rewrite_includes_only,
ignorable_whitespace_flags,
language_to_clang_arg,
)
.await
}
Expand Down Expand Up @@ -168,13 +169,31 @@ impl CCompilerImpl for Clang {
env_vars,
self.kind(),
rewrite_includes_only,
language_to_clang_arg,
)
.map(|(command, dist_command, cacheable)| {
(CCompileCommand::new(command), dist_command, cacheable)
})
}
}

pub fn language_to_clang_arg(lang: Language) -> Option<&'static str> {
match lang {
Language::C => Some("c"),
Language::CHeader => Some("c-header"),
Language::Cxx => Some("c++"),
Language::CxxHeader => Some("c++-header"),
Language::ObjectiveC => Some("objective-c"),
Language::ObjectiveCxx => Some("objective-c++"),
Language::Cuda => Some("cuda"),
Language::Ptx => None,
Language::Cubin => None,
Language::Rust => None, // Let the compiler decide
Language::Hip => Some("hip"),
Language::GenericHeader => None, // Let the compiler decide
}
}

counted_array!(pub static ARGS: [ArgInfo<gcc::ArgData>; _] = [
take_arg!("--dependent-lib", OsString, Concatenated('='), PassThrough),
take_arg!("--hip-device-lib-path", PathBuf, Concatenated('='), PassThroughPath),
Expand Down
Loading

0 comments on commit 1c36942

Please sign in to comment.