Skip to content

Commit 63e9d72

Browse files
committed
support nvcc --device-debug
1 parent ffe68b9 commit 63e9d72

File tree

3 files changed

+147
-21
lines changed

3 files changed

+147
-21
lines changed

src/compiler/clang.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ mod test {
412412
"-x",
413413
"cuda",
414414
"--cuda-gpu-arch=sm_50",
415+
"--cuda-noopt-device-debug",
415416
"-o",
416417
"foo.o"
417418
);
@@ -428,7 +429,10 @@ mod test {
428429
)
429430
);
430431
assert!(a.preprocessor_args.is_empty());
431-
assert_eq!(ovec!["--cuda-gpu-arch=sm_50"], a.common_args);
432+
assert_eq!(
433+
ovec!["--cuda-gpu-arch=sm_50", "--cuda-noopt-device-debug"],
434+
a.common_args
435+
);
432436

433437
let b = parses!(
434438
"-c",

src/compiler/nvcc.rs

+63
Original file line numberDiff line numberDiff line change
@@ -1632,6 +1632,7 @@ counted_array!(pub static ARGS: [ArgInfo<gcc::ArgData>; _] = [
16321632
flag!("--cubin", DoCompilation),
16331633
take_arg!("--default-stream", OsString, CanBeSeparated('='), PassThrough),
16341634
flag!("--device-c", DoCompilation),
1635+
flag!("--device-debug", PassThroughFlag),
16351636
flag!("--device-w", DoCompilation),
16361637
take_arg!("--diag-suppress", OsString, CanBeSeparated('='), PassThrough),
16371638
flag!("--expt-extended-lambda", PreprocessorArgumentFlag),
@@ -1664,6 +1665,7 @@ counted_array!(pub static ARGS: [ArgInfo<gcc::ArgData>; _] = [
16641665
take_arg!("--time=", OsString, Concatenated, TooHard),
16651666
take_arg!("--x", OsString, CanBeSeparated('='), Language),
16661667

1668+
flag!("-G", PassThroughFlag),
16671669
take_arg!("-Werror", OsString, CanBeSeparated('='), PreprocessorArgument),
16681670
take_arg!("-Xarchive", OsString, CanBeSeparated('='), PassThrough),
16691671
take_arg!("-Xcompiler", OsString, CanBeSeparated('='), PreprocessorArgument),
@@ -2282,4 +2284,65 @@ mod test {
22822284
);
22832285
}
22842286
}
2287+
2288+
#[test]
2289+
fn test_parse_device_debug_flag_short_cu() {
2290+
let a = parses!(
2291+
"-x", "cu", "-c", "foo.c", "-G", "-MD", "-MT", "foo.o", "-MF", "foo.o.d", "-o", "foo.o"
2292+
);
2293+
assert_eq!(Some("foo.c"), a.input.to_str());
2294+
assert_eq!(Language::Cuda, a.language);
2295+
assert_eq!(Some("-c"), a.compilation_flag.to_str());
2296+
assert_map_contains!(
2297+
a.outputs,
2298+
(
2299+
"obj",
2300+
ArtifactDescriptor {
2301+
path: "foo.o".into(),
2302+
optional: false
2303+
}
2304+
)
2305+
);
2306+
assert_eq!(
2307+
ovec!["-MD", "-MF", "foo.o.d", "-MT", "foo.o"],
2308+
a.dependency_args
2309+
);
2310+
assert_eq!(ovec!["-G", "-c"], a.common_args);
2311+
}
2312+
2313+
#[test]
2314+
fn test_parse_device_debug_flag_long_cu() {
2315+
let a = parses!(
2316+
"-x",
2317+
"cu",
2318+
"-c",
2319+
"foo.c",
2320+
"--device-debug",
2321+
"-MD",
2322+
"-MT",
2323+
"foo.o",
2324+
"-MF",
2325+
"foo.o.d",
2326+
"-o",
2327+
"foo.o"
2328+
);
2329+
assert_eq!(Some("foo.c"), a.input.to_str());
2330+
assert_eq!(Language::Cuda, a.language);
2331+
assert_eq!(Some("-c"), a.compilation_flag.to_str());
2332+
assert_map_contains!(
2333+
a.outputs,
2334+
(
2335+
"obj",
2336+
ArtifactDescriptor {
2337+
path: "foo.o".into(),
2338+
optional: false
2339+
}
2340+
)
2341+
);
2342+
assert_eq!(
2343+
ovec!["-MD", "-MF", "foo.o.d", "-MT", "foo.o"],
2344+
a.dependency_args
2345+
);
2346+
assert_eq!(ovec!["--device-debug", "-c"], a.common_args);
2347+
}
22852348
}

tests/system.rs

+79-20
Original file line numberDiff line numberDiff line change
@@ -732,11 +732,19 @@ struct AdditionalStats {
732732
cache_misses: Option<Vec<(CCompilerKind, Language, u64)>>,
733733
}
734734

735-
fn test_nvcc_cuda_compiles(client: &SccacheClient, compiler: &Compiler, tempdir: &Path) {
735+
fn test_nvcc_cuda_compiles(
736+
client: &SccacheClient,
737+
compiler: &Compiler,
738+
tempdir: &Path,
739+
with_debug_flags: bool,
740+
) {
736741
let mut stats = client.stats().unwrap();
737742

738-
let extra_args = vec![];
739-
let with_debug_flags = false;
743+
let extra_args = if with_debug_flags {
744+
vec!["-G".into()]
745+
} else {
746+
vec![]
747+
};
740748

741749
let Compiler {
742750
name,
@@ -1406,10 +1414,15 @@ fn test_nvcc_proper_lang_stat_tracking(
14061414
client: &SccacheClient,
14071415
compiler: &Compiler,
14081416
tempdir: &Path,
1417+
with_debug_flags: bool,
14091418
) {
14101419
let mut stats = client.stats().unwrap();
14111420

1412-
let extra_args = vec![];
1421+
let extra_args = if with_debug_flags {
1422+
vec!["-G".into()]
1423+
} else {
1424+
vec![]
1425+
};
14131426

14141427
let Compiler {
14151428
name,
@@ -1576,15 +1589,29 @@ fn test_nvcc_proper_lang_stat_tracking(
15761589
);
15771590
}
15781591

1579-
fn run_sccache_nvcc_cuda_command_tests(client: &SccacheClient, compiler: Compiler, tempdir: &Path) {
1580-
test_nvcc_cuda_compiles(client, &compiler, tempdir);
1581-
test_nvcc_proper_lang_stat_tracking(client, &compiler, tempdir);
1592+
fn run_sccache_nvcc_cuda_command_tests(
1593+
client: &SccacheClient,
1594+
compiler: Compiler,
1595+
tempdir: &Path,
1596+
with_debug_flags: bool,
1597+
) {
1598+
test_nvcc_cuda_compiles(client, &compiler, tempdir, with_debug_flags);
1599+
test_nvcc_proper_lang_stat_tracking(client, &compiler, tempdir, with_debug_flags);
15821600
}
15831601

1584-
fn test_clang_cuda_compiles(client: &SccacheClient, compiler: &Compiler, tempdir: &Path) {
1602+
fn test_clang_cuda_compiles(
1603+
client: &SccacheClient,
1604+
compiler: &Compiler,
1605+
tempdir: &Path,
1606+
with_debug_flags: bool,
1607+
) {
15851608
let mut stats = client.stats().unwrap();
15861609

1587-
let extra_args = vec![];
1610+
let extra_args = if with_debug_flags {
1611+
vec!["-g".into(), "--cuda-noopt-device-debug".into()]
1612+
} else {
1613+
vec![]
1614+
};
15881615

15891616
let Compiler {
15901617
name,
@@ -1703,9 +1730,16 @@ fn test_clang_proper_lang_stat_tracking(
17031730
client: &SccacheClient,
17041731
compiler: &Compiler,
17051732
tempdir: &Path,
1733+
with_debug_flags: bool,
17061734
) {
17071735
let mut stats = client.stats().unwrap();
17081736

1737+
let extra_args = if with_debug_flags {
1738+
vec!["-g".into(), "--cuda-noopt-device-debug".into()]
1739+
} else {
1740+
vec![]
1741+
};
1742+
17091743
let Compiler {
17101744
name,
17111745
exe,
@@ -1726,7 +1760,7 @@ fn test_clang_proper_lang_stat_tracking(
17261760
"-c",
17271761
INPUT_FOR_CUDA_C,
17281762
OUTPUT,
1729-
&[],
1763+
&extra_args,
17301764
))
17311765
.current_dir(tempdir)
17321766
.envs(env_vars.clone())
@@ -1759,7 +1793,7 @@ fn test_clang_proper_lang_stat_tracking(
17591793
"-c",
17601794
INPUT_FOR_CUDA_C,
17611795
OUTPUT,
1762-
&[],
1796+
&extra_args,
17631797
))
17641798
.current_dir(tempdir)
17651799
.envs(env_vars.clone())
@@ -1784,7 +1818,13 @@ fn test_clang_proper_lang_stat_tracking(
17841818
trace!("compile C++ A");
17851819
client
17861820
.cmd()
1787-
.args(compile_cmdline(name, exe, INPUT, OUTPUT, Vec::new()))
1821+
.args(compile_cmdline(
1822+
name,
1823+
exe,
1824+
INPUT,
1825+
OUTPUT,
1826+
extra_args.clone(),
1827+
))
17881828
.current_dir(tempdir)
17891829
.envs(env_vars.clone())
17901830
.assert()
@@ -1810,7 +1850,13 @@ fn test_clang_proper_lang_stat_tracking(
18101850
trace!("compile C++ A");
18111851
client
18121852
.cmd()
1813-
.args(compile_cmdline(name, exe, INPUT, OUTPUT, Vec::new()))
1853+
.args(compile_cmdline(
1854+
name,
1855+
exe,
1856+
INPUT,
1857+
OUTPUT,
1858+
extra_args.clone(),
1859+
))
18141860
.current_dir(tempdir)
18151861
.envs(env_vars.clone())
18161862
.assert()
@@ -1836,9 +1882,10 @@ fn run_sccache_clang_cuda_command_tests(
18361882
client: &SccacheClient,
18371883
compiler: Compiler,
18381884
tempdir: &Path,
1885+
with_debug_flags: bool,
18391886
) {
1840-
test_clang_cuda_compiles(client, &compiler, tempdir);
1841-
test_clang_proper_lang_stat_tracking(client, &compiler, tempdir);
1887+
test_clang_cuda_compiles(client, &compiler, tempdir, with_debug_flags);
1888+
test_clang_proper_lang_stat_tracking(client, &compiler, tempdir, with_debug_flags);
18421889
}
18431890

18441891
fn test_hip_compiles(client: &SccacheClient, compiler: &Compiler, tempdir: &Path) {
@@ -2303,10 +2350,12 @@ fn test_stats_no_server() {
23032350
);
23042351
}
23052352

2306-
#[test_case(true ; "with preprocessor cache")]
2307-
#[test_case(false ; "without preprocessor cache")]
2353+
#[test_case(true, false ; "preprocessor_cache=true, device_debug=false")]
2354+
#[test_case(false, false ; "preprocessor_cache=false, device_debug=false")]
2355+
#[test_case(true, true ; "preprocessor_cache=true, device_debug=true")]
2356+
#[test_case(false, true ; "preprocessor_cache=false, device_debug=true")]
23082357
#[cfg(any(unix, target_env = "msvc"))]
2309-
fn test_cuda_sccache_command(preprocessor_cache_mode: bool) {
2358+
fn test_cuda_sccache_command(preprocessor_cache_mode: bool, with_debug_flags: bool) {
23102359
let _ = env_logger::try_init();
23112360
let compilers = find_cuda_compilers();
23122361
println!(
@@ -2325,8 +2374,18 @@ fn test_cuda_sccache_command(preprocessor_cache_mode: bool) {
23252374

23262375
for compiler in compilers {
23272376
match compiler.name {
2328-
"nvcc" => run_sccache_nvcc_cuda_command_tests(&client, compiler, &tempdir_path),
2329-
"clang++" => run_sccache_clang_cuda_command_tests(&client, compiler, &tempdir_path),
2377+
"nvcc" => run_sccache_nvcc_cuda_command_tests(
2378+
&client,
2379+
compiler,
2380+
&tempdir_path,
2381+
with_debug_flags,
2382+
),
2383+
"clang++" => run_sccache_clang_cuda_command_tests(
2384+
&client,
2385+
compiler,
2386+
&tempdir_path,
2387+
with_debug_flags,
2388+
),
23302389
_ => {}
23312390
}
23322391
}

0 commit comments

Comments
 (0)