Skip to content

Commit 0c700db

Browse files
committed
Feat: add proper debug option to cuda_builder, run fmt
1 parent ab7a7e7 commit 0c700db

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

crates/cuda_builder/src/lib.rs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,25 @@ impl fmt::Display for CudaBuilderError {
3333
}
3434
}
3535

36+
#[derive(Debug, Clone, Copy, PartialEq)]
37+
pub enum DebugInfo {
38+
None,
39+
LineTables,
40+
// NOTE(RDambrosio016): currently unimplemented because it causes a segfault somewhere in LLVM
41+
// or libnvvm. Probably the latter.
42+
// Full,
43+
}
44+
45+
impl DebugInfo {
46+
fn into_nvvm_and_rustc_options(self) -> (String, String) {
47+
match self {
48+
DebugInfo::None => unreachable!(),
49+
DebugInfo::LineTables => ("-generate-line-info".into(), "-Cdebuginfo=1".into()),
50+
// DebugInfo::Full => ("-g".into(), "-Cdebuginfo=2".into()),
51+
}
52+
}
53+
}
54+
3655
pub enum EmitOption {
3756
LlvmIr,
3857
Bitcode,
@@ -117,7 +136,8 @@ pub struct CudaBuilder {
117136
///
118137
/// `true` by default.
119138
pub override_libm: bool,
120-
pub debug: bool,
139+
/// Whether to generate any debug info and what level of info to generate.
140+
pub debug: DebugInfo,
121141
}
122142

123143
impl CudaBuilder {
@@ -137,11 +157,12 @@ impl CudaBuilder {
137157
emit: None,
138158
optix: false,
139159
override_libm: true,
140-
debug: false,
160+
debug: DebugInfo::None,
141161
}
142162
}
143163

144-
pub fn debug(mut self, debug: bool) -> Self {
164+
/// Whether to generate any debug info and what level of info to generate.
165+
pub fn debug(mut self, debug: DebugInfo) -> Self {
145166
self.debug = debug;
146167
self
147168
}
@@ -385,9 +406,10 @@ fn invoke_rustc(builder: &CudaBuilder) -> Result<PathBuf, CudaBuilderError> {
385406
llvm_args.push("--override-libm".to_string());
386407
}
387408

388-
if builder.debug {
389-
rustflags.push("-Cdebuginfo=1".to_string());
390-
llvm_args.push("-generate-line-info".to_string());
409+
if builder.debug != DebugInfo::None {
410+
let (nvvm_flag, rustc_flag) = builder.debug.into_nvvm_and_rustc_options();
411+
llvm_args.push(nvvm_flag);
412+
rustflags.push(rustc_flag);
391413
}
392414

393415
let llvm_args = llvm_args.join(" ");

crates/gpu_rand/src/xoroshiro/common.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ macro_rules! deal_with_zero_seed {
223223
};
224224
}
225225

226+
#[allow(unused_macros)]
226227
macro_rules! impl_initialize_states {
227228
($seed:expr, $num_states:expr) => {{
228229
// there is unfortunately not a well-performant, clean, and safe way to do

examples/cuda/gpu/path_tracer_gpu/src/material.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ use crate::{
33
math::{random_in_unit_sphere, reflect},
44
Ray, Vec3,
55
};
6+
use cust_core::DeviceCopy;
67
use enum_dispatch::enum_dispatch;
78
use gpu_rand::DefaultRand;
8-
use cust_core::DeviceCopy;
99

1010
#[enum_dispatch]
1111
pub trait Material {

0 commit comments

Comments
 (0)