Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sccache for CTK 11.1 and properly track compilations in stats #2285

Merged
merged 16 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions .github/actions/nvcc-toolchain/install-cuda.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,19 @@ $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"

###
# `cuda_${mmbVersionTag}_windows_network.exe` name only valid back to CUDA v11.5.1.
# Before that it was named `cuda_${mmbVersionTag}_win10_network.exe`:
# * https://developer.download.nvidia.com/compute/cuda/11.5.1/network_installers/cuda_11.5.1_windows_network.exe
# * https://developer.download.nvidia.com/compute/cuda/11.5.0/network_installers/cuda_11.5.0_win10_network.exe
###

if ([version]$mmbVersionTag -le "11.5.0") {
$cudaVersionUrl = "https://developer.download.nvidia.com/compute/cuda/${mmbVersionTag}/network_installers/cuda_${mmbVersionTag}_win10_network.exe"
}

$cudaComponents =
"nvcc_$mmVersionTag",
"curand_$mmVersionTag",
Expand Down
17 changes: 14 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ jobs:
matrix:
include:
- os: ubuntu-20.04
# Oldest tested CUDA Toolkit version. Older CTKs might work, but they're
# difficult to test without Ubuntu18.04 GHA runners or containerized jobs.
cuda: "11.1"
extra_desc: cuda11.1
# Oldest supported version, keep in sync with README.md
rustc: "1.75.0"
- os: ubuntu-22.04
Expand Down Expand Up @@ -97,11 +101,11 @@ jobs:
# # M1 CPU
- os: macos-14
- os: windows-2019
cuda: "11.8"
cuda: "11.1"
# Oldest supported version, keep in sync with README.md
rustc: "1.75.0"
extra_args: --no-fail-fast
extra_desc: cuda11.8
extra_desc: cuda11.1
- os: windows-2019
cuda: "11.8"
rustc: nightly
Expand Down Expand Up @@ -152,7 +156,14 @@ jobs:
sudo apt remove -y gcc-14 g++-14
sudo apt autoremove -y
fi
sudo apt install -y --no-install-recommends clang gcc
# Ubuntu20.04's clang-10 is too old for CTK 11+, so install clang-12 instead
if test "${{ matrix.os }}" = "ubuntu-20.04" && test -n "${{ matrix.cuda }}"; then
sudo apt install -y --no-install-recommends gcc clang-12
sudo ln -sf $(which clang-12) /usr/bin/clang
sudo ln -sf $(which clang++-12) /usr/bin/clang++
else
sudo apt install -y --no-install-recommends gcc clang
fi
echo 'gcc version:'
gcc --version
echo 'clang version:'
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ pub trait CCompilerImpl: Clone + fmt::Debug + Send + Sync + 'static {
&self,
arguments: &[OsString],
cwd: &Path,
env_vars: &[(OsString, OsString)],
) -> CompilerArguments<ParsedArguments>;
/// Run the C preprocessor with the specified set of arguments.
#[allow(clippy::too_many_arguments)]
Expand Down Expand Up @@ -308,7 +309,7 @@ impl<T: CommandCreatorSync, I: CCompilerImpl> Compiler<T> for CCompiler<I> {
cwd: &Path,
env_vars: &[(OsString, OsString)],
) -> CompilerArguments<Box<dyn CompilerHasher<T> + 'static>> {
match self.compiler.parse_arguments(arguments, cwd) {
match self.compiler.parse_arguments(arguments, cwd, env_vars) {
CompilerArguments::Ok(mut args) => {
// Handle SCCACHE_EXTRAFILES
for (k, v) in env_vars.iter() {
Expand Down
24 changes: 20 additions & 4 deletions src/compiler/cicc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ impl CCompilerImpl for Cicc {
&self,
arguments: &[OsString],
cwd: &Path,
_env_vars: &[(OsString, OsString)],
) -> CompilerArguments<ParsedArguments> {
parse_arguments(arguments, cwd, Language::Ptx, &ARGS[..])
}
Expand Down Expand Up @@ -116,11 +117,11 @@ where
let mut take_next = false;
let mut outputs = HashMap::new();
let mut extra_dist_files = vec![];
let mut gen_module_id_file = false;
let mut module_id_file_name = Option::<PathBuf>::None;

let mut common_args = vec![];
let mut unhashed_args = vec![];
let mut gen_module_id_file = false;
let mut module_id_file_name = Option::<PathBuf>::None;

for arg in ArgsIter::new(args.iter().cloned(), arg_info) {
match arg {
Expand Down Expand Up @@ -279,6 +280,21 @@ pub fn generate_compile_commands(
out_file.into(),
]);

if log_enabled!(log::Level::Trace) {
trace!(
"[{}]: {} command: {:?}",
out_file.file_name().unwrap().to_string_lossy(),
executable.file_name().unwrap().to_string_lossy(),
[
&[format!("cd {} &&", cwd.to_string_lossy()).to_string()],
&[executable.to_str().unwrap_or_default().to_string()][..],
&dist::osstrings_to_strings(&arguments).unwrap_or_default()[..]
]
.concat()
.join(" ")
);
}

let command = SingleCompileCommand {
executable: executable.to_owned(),
arguments,
Expand Down Expand Up @@ -311,11 +327,11 @@ pub fn generate_compile_commands(

ArgData! { pub
Output(PathBuf),
UnhashedOutput(PathBuf),
PassThrough(OsString),
UnhashedFlag,
UnhashedGenModuleIdFileFlag,
UnhashedModuleIdFileName(PathBuf),
PassThrough(OsString),
UnhashedOutput(PathBuf),
}

use self::ArgData::*;
Expand Down
67 changes: 66 additions & 1 deletion src/compiler/clang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ impl CCompilerImpl for Clang {
&self,
arguments: &[OsString],
cwd: &Path,
_env_vars: &[(OsString, OsString)],
) -> CompilerArguments<ParsedArguments> {
gcc::parse_arguments(
arguments,
Expand Down Expand Up @@ -206,12 +207,15 @@ counted_array!(pub static ARGS: [ArgInfo<gcc::ArgData>; _] = [
take_arg!("-MF", PathBuf, CanBeSeparated, DepArgumentPath),
take_arg!("-MQ", OsString, CanBeSeparated, DepTarget),
take_arg!("-MT", OsString, CanBeSeparated, DepTarget),
flag!("-Wno-unknown-cuda-version", PassThroughFlag),
flag!("-Wno-unused-parameter", PassThroughFlag),
take_arg!("-Xclang", OsString, Separated, XClang),
take_arg!("-add-plugin", OsString, Separated, PassThrough),
take_arg!("-debug-info-kind", OsString, Concatenated('='), PassThrough),
take_arg!("-dependency-file", PathBuf, Separated, DepArgumentPath),
flag!("-emit-pch", PassThroughFlag),
flag!("-fcolor-diagnostics", DiagnosticsColorFlag),
flag!("-fcuda-allow-variadic-functions", PassThroughFlag),
flag!("-fcxx-modules", TooHardFlag),
take_arg!("-fdebug-compilation-dir", OsString, Separated, PassThrough),
take_arg!("-fembed-offload-object", PathBuf, Concatenated('='), ExtraHashFile),
Expand Down Expand Up @@ -267,6 +271,8 @@ mod test {
use crate::compiler::gcc;
use crate::compiler::*;
use crate::mock_command::*;
use crate::server;
use crate::test::mock_storage::MockStorage;
use crate::test::utils::*;
use std::collections::HashMap;
use std::future::Future;
Expand All @@ -279,7 +285,7 @@ mod test {
is_appleclang: false,
version: None,
}
.parse_arguments(&arguments, &std::env::current_dir().unwrap())
.parse_arguments(&arguments, &std::env::current_dir().unwrap(), &[])
}

macro_rules! parses {
Expand Down Expand Up @@ -1028,4 +1034,63 @@ mod test {
])
);
}

#[test]
fn test_compile_clang_cuda_does_not_dist_compile() {
let creator = new_creator();
let f = TestFixture::new();
let parsed_args = ParsedArguments {
input: "foo.cu".into(),
double_dash_input: false,
language: Language::Cuda,
compilation_flag: "-c".into(),
depfile: None,
outputs: vec![(
"obj",
ArtifactDescriptor {
path: "foo.cu.o".into(),
optional: false,
},
)]
.into_iter()
.collect(),
dependency_args: vec![],
preprocessor_args: vec![],
common_args: vec![],
arch_args: vec![],
unhashed_args: vec![],
extra_dist_files: vec![],
extra_hash_files: vec![],
msvc_show_includes: false,
profile_generate: false,
color_mode: ColorMode::Auto,
suppress_rewrite_includes_only: false,
too_hard_for_preprocessor_cache_mode: None,
};
let runtime = single_threaded_runtime();
let storage = MockStorage::new(None, false);
let storage: std::sync::Arc<MockStorage> = std::sync::Arc::new(storage);
let service = server::SccacheService::mock_with_storage(storage, runtime.handle().clone());
let compiler = &f.bins[0];
// Compiler invocation.
next_command(&creator, Ok(MockChild::new(exit_status(0), "", "")));
let mut path_transformer = dist::PathTransformer::new();
let (command, dist_command, cacheable) = gcc::generate_compile_commands(
&mut path_transformer,
compiler,
&parsed_args,
f.tempdir.path(),
&[],
CCompilerKind::Clang,
false,
language_to_clang_arg,
)
.unwrap();
// ClangCUDA cannot be dist-compiled
assert!(dist_command.is_none());
let _ = command.execute(&service, &creator).wait();
assert_eq!(Cacheable::Yes, cacheable);
// Ensure that we ran all processes.
assert_eq!(0, creator.lock().unwrap().children.len());
}
}
41 changes: 29 additions & 12 deletions src/compiler/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,10 @@ where
out_pretty,
fmt_duration_as_secs(&duration_compilation)
);
return Ok((CompileResult::CompileFailed, compiler_result));
return Ok((
CompileResult::CompileFailed(dist_type, duration_compilation),
compiler_result,
));
}
if miss_type == MissType::ForcedNoCache {
// Do not cache
Expand All @@ -590,7 +593,10 @@ where
out_pretty,
fmt_duration_as_secs(&duration_compilation)
);
return Ok((CompileResult::NotCached, compiler_result));
return Ok((
CompileResult::NotCached(dist_type, duration_compilation),
compiler_result,
));
}
if cacheable != Cacheable::Yes {
// Not cacheable
Expand All @@ -599,7 +605,10 @@ where
out_pretty,
fmt_duration_as_secs(&duration_compilation)
);
return Ok((CompileResult::NotCacheable, compiler_result));
return Ok((
CompileResult::NotCacheable(dist_type, duration_compilation),
compiler_result,
));
}
debug!(
"[{}]: Compiled in {}, storing in cache",
Expand Down Expand Up @@ -1043,11 +1052,11 @@ pub enum CompileResult {
Pin<Box<dyn Future<Output = Result<CacheWriteInfo>> + Send>>,
),
/// Not in cache and do not cache the results of the compilation.
NotCached,
NotCached(DistType, Duration),
/// Not in cache, but the compilation result was determined to be not cacheable.
NotCacheable,
NotCacheable(DistType, Duration),
/// Not in cache, but compilation failed.
CompileFailed,
CompileFailed(DistType, Duration),
}

/// The state of `--color` options passed to a compiler.
Expand All @@ -1068,9 +1077,15 @@ impl fmt::Debug for CompileResult {
CompileResult::CacheMiss(ref m, ref dt, ref d, _) => {
write!(f, "CompileResult::CacheMiss({:?}, {:?}, {:?}, _)", d, m, dt)
}
CompileResult::NotCached => write!(f, "CompileResult::NotCached"),
CompileResult::NotCacheable => write!(f, "CompileResult::NotCacheable"),
CompileResult::CompileFailed => write!(f, "CompileResult::CompileFailed"),
CompileResult::NotCached(ref dt, ref d) => {
write!(f, "CompileResult::NotCached({:?}, {:?}_", dt, d)
}
CompileResult::NotCacheable(ref dt, ref d) => {
write!(f, "CompileResult::NotCacheable({:?}, {:?}_", dt, d)
}
CompileResult::CompileFailed(ref dt, ref d) => {
write!(f, "CompileResult::CompileFailed({:?}, {:?})", dt, d)
}
}
}
}
Expand All @@ -1084,9 +1099,11 @@ impl PartialEq<CompileResult> for CompileResult {
(CompileResult::CacheMiss(m, dt, _, _), CompileResult::CacheMiss(n, dt2, _, _)) => {
m == n && dt == dt2
}
(&CompileResult::NotCached, &CompileResult::NotCached) => true,
(&CompileResult::NotCacheable, &CompileResult::NotCacheable) => true,
(&CompileResult::CompileFailed, &CompileResult::CompileFailed) => true,
(CompileResult::NotCached(dt, _), CompileResult::NotCached(dt2, _)) => dt == dt2,
(CompileResult::NotCacheable(dt, _), CompileResult::NotCacheable(dt2, _)) => dt == dt2,
(CompileResult::CompileFailed(dt, _), CompileResult::CompileFailed(dt2, _)) => {
dt == dt2
}
_ => false,
}
}
Expand Down
1 change: 1 addition & 0 deletions src/compiler/diab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ impl CCompilerImpl for Diab {
&self,
arguments: &[OsString],
cwd: &Path,
_env_vars: &[(OsString, OsString)],
) -> CompilerArguments<ParsedArguments> {
parse_arguments(arguments, cwd, &ARGS[..])
}
Expand Down
Loading
Loading