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

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
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
57 changes: 28 additions & 29 deletions src/compiler/cicc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,10 @@ 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 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 All @@ -142,15 +140,30 @@ where
);
continue;
}
Some(UnhashedGenModuleIdFileFlag) => {
Some(GenModuleIdFileFlag) => {
take_next = false;
// Skip if we already added --gen_module_id_file when handling --module_id_file_name
if gen_module_id_file {
continue;
}
gen_module_id_file = true;
&mut unhashed_args
&mut common_args
}
Some(UnhashedModuleIdFileName(o)) => {
Some(ModuleIdFileName(o)) => {
take_next = false;
module_id_file_name = Some(cwd.join(o));
&mut unhashed_args
outputs.insert(
"--module_id_file_name",
ArtifactDescriptor {
path: cwd.join(o),
optional: true,
},
);
// Always add --gen_module_id_file if --module_id_file_name is specified
if !gen_module_id_file {
gen_module_id_file = true;
common_args.push("--gen_module_id_file".into());
}
&mut common_args
}
Some(UnhashedOutput(o)) => {
take_next = false;
Expand Down Expand Up @@ -193,20 +206,6 @@ where
};
}

if let Some(module_id_path) = module_id_file_name {
if gen_module_id_file {
outputs.insert(
"--module_id_file_name",
ArtifactDescriptor {
path: module_id_path,
optional: true,
},
);
} else {
extra_dist_files.push(module_id_path);
}
}

CompilerArguments::Ok(ParsedArguments {
input: input.into(),
outputs,
Expand All @@ -219,7 +218,7 @@ where
common_args,
arch_args: vec![],
unhashed_args,
extra_dist_files,
extra_dist_files: vec![],
extra_hash_files: vec![],
msvc_show_includes: false,
profile_generate: false,
Expand Down Expand Up @@ -310,22 +309,22 @@ pub fn generate_compile_commands(
}

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

use self::ArgData::*;

counted_array!(pub static ARGS: [ArgInfo<ArgData>; _] = [
take_arg!("--gen_c_file_name", PathBuf, Separated, UnhashedOutput),
take_arg!("--gen_device_file_name", PathBuf, Separated, UnhashedOutput),
flag!("--gen_module_id_file", UnhashedGenModuleIdFileFlag),
flag!("--gen_module_id_file", GenModuleIdFileFlag),
take_arg!("--include_file_name", OsString, Separated, PassThrough),
take_arg!("--module_id_file_name", PathBuf, Separated, UnhashedModuleIdFileName),
take_arg!("--module_id_file_name", PathBuf, Separated, ModuleIdFileName),
take_arg!("--stub_file_name", PathBuf, Separated, UnhashedOutput),
take_arg!("-o", PathBuf, Separated, Output),
]);
3 changes: 3 additions & 0 deletions src/compiler/clang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,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
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
112 changes: 62 additions & 50 deletions src/compiler/gcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use fs_err as fs;
use log::Level::Trace;
use std::collections::HashMap;
use std::env;
use std::ffi::OsString;
use std::ffi::{OsStr, OsString};
use std::io::Read;
use std::path::{Path, PathBuf};
use std::process;
Expand Down Expand Up @@ -856,8 +856,6 @@ where
let _ = rewrite_includes_only;
}

trace!("compile");

let out_file = match parsed_args.outputs.get("obj") {
Some(obj) => &obj.path,
None => return Err(anyhow!("Missing object file output")),
Expand All @@ -884,6 +882,16 @@ where
arguments.push("--".into());
}
arguments.push(parsed_args.input.clone().into());

trace!(
"compile: {} {}",
executable.to_string_lossy(),
arguments.join(OsStr::new(" ")).to_string_lossy()
);

let has_verbose_flag = arguments.contains(&OsString::from("-v"))
|| arguments.contains(&OsString::from("--verbose"));

let command = SingleCompileCommand {
executable: executable.to_owned(),
arguments,
Expand All @@ -894,56 +902,60 @@ where
#[cfg(not(feature = "dist-client"))]
let dist_command = None;
#[cfg(feature = "dist-client")]
let dist_command = (|| {
// https://gcc.gnu.org/onlinedocs/gcc-4.9.0/gcc/Overall-Options.html
let mut language: Option<String> =
language_to_arg(parsed_args.language).map(|lang| lang.into());
if !rewrite_includes_only {
match parsed_args.language {
Language::C => language = Some("cpp-output".into()),
Language::GenericHeader | Language::CHeader | Language::CxxHeader => {}
_ => language.as_mut()?.push_str("-cpp-output"),
let dist_command = if has_verbose_flag {
None
} else {
(|| {
// https://gcc.gnu.org/onlinedocs/gcc-4.9.0/gcc/Overall-Options.html
let mut language: Option<String> =
language_to_arg(parsed_args.language).map(|lang| lang.into());
if !rewrite_includes_only {
match parsed_args.language {
Language::C => language = Some("cpp-output".into()),
Language::GenericHeader | Language::CHeader | Language::CxxHeader => {}
_ => language.as_mut()?.push_str("-cpp-output"),
}
}
}

let mut arguments: Vec<String> = vec![];
// Language needs to be before input
if let Some(lang) = &language {
arguments.extend(vec!["-x".into(), lang.into()])
}
arguments.extend(vec![
parsed_args.compilation_flag.clone().into_string().ok()?,
path_transformer.as_dist(&parsed_args.input)?,
"-o".into(),
path_transformer.as_dist(out_file)?,
]);
if let CCompilerKind::Gcc = kind {
// From https://gcc.gnu.org/onlinedocs/gcc/Preprocessor-Options.html:
//
// -fdirectives-only
//
// [...]
//
// With -fpreprocessed, predefinition of command line and most
// builtin macros is disabled. Macros such as __LINE__, which
// are contextually dependent, are handled normally. This
// enables compilation of files previously preprocessed with -E
// -fdirectives-only.
//
// Which is exactly what we do :-)
if rewrite_includes_only && !parsed_args.suppress_rewrite_includes_only {
arguments.push("-fdirectives-only".into());
let mut arguments: Vec<String> = vec![];
// Language needs to be before input
if let Some(lang) = &language {
arguments.extend(vec!["-x".into(), lang.into()])
}
arguments.push("-fpreprocessed".into());
}
arguments.extend(dist::osstrings_to_strings(&parsed_args.common_args)?);
Some(dist::CompileCommand {
executable: path_transformer.as_dist(executable)?,
arguments,
env_vars: dist::osstring_tuples_to_strings(env_vars)?,
cwd: path_transformer.as_dist_abs(cwd)?,
})
})();
arguments.extend(vec![
parsed_args.compilation_flag.clone().into_string().ok()?,
path_transformer.as_dist(&parsed_args.input)?,
"-o".into(),
path_transformer.as_dist(out_file)?,
]);
if let CCompilerKind::Gcc = kind {
// From https://gcc.gnu.org/onlinedocs/gcc/Preprocessor-Options.html:
//
// -fdirectives-only
//
// [...]
//
// With -fpreprocessed, predefinition of command line and most
// builtin macros is disabled. Macros such as __LINE__, which
// are contextually dependent, are handled normally. This
// enables compilation of files previously preprocessed with -E
// -fdirectives-only.
//
// Which is exactly what we do :-)
if rewrite_includes_only && !parsed_args.suppress_rewrite_includes_only {
arguments.push("-fdirectives-only".into());
}
arguments.push("-fpreprocessed".into());
}
arguments.extend(dist::osstrings_to_strings(&parsed_args.common_args)?);
Some(dist::CompileCommand {
executable: path_transformer.as_dist(executable)?,
arguments,
env_vars: dist::osstring_tuples_to_strings(env_vars)?,
cwd: path_transformer.as_dist_abs(cwd)?,
})
})()
};

Ok((command, dist_command, Cacheable::Yes))
}
Expand Down
Loading