From dd915688bdee6cd3f9d1496a0639e280f488a570 Mon Sep 17 00:00:00 2001 From: Andrzej Janik Date: Mon, 6 Dec 2021 23:54:47 +0100 Subject: Dump function names and allow overriding result of cuDeviceComputeCapability --- zluda_dump/src/cuda.rs | 6 ++++-- zluda_dump/src/lib.rs | 54 ++++++++++++++++++++++++++++++++++++++++++++++++- zluda_dump/src/log.rs | 7 +++++++ zluda_dump/src/trace.rs | 2 ++ 4 files changed, 66 insertions(+), 3 deletions(-) diff --git a/zluda_dump/src/cuda.rs b/zluda_dump/src/cuda.rs index 8cdfde9..d9d57c4 100644 --- a/zluda_dump/src/cuda.rs +++ b/zluda_dump/src/cuda.rs @@ -2355,12 +2355,13 @@ extern_redirect! { dev: CUdevice, ) -> CUresult; } -extern_redirect! { +extern_redirect_with_post! { pub fn cuDeviceGetAttribute( pi: *mut ::std::os::raw::c_int, attrib: CUdevice_attribute, dev: CUdevice, ) -> CUresult; + super::cuDeviceGetAttribute_Post; } extern_redirect! { pub fn cuDeviceGetNvSciSyncAttributes( @@ -2372,12 +2373,13 @@ extern_redirect! { extern_redirect! { pub fn cuDeviceGetProperties(prop: *mut CUdevprop, dev: CUdevice) -> CUresult; } -extern_redirect! { +extern_redirect_with_post! { pub fn cuDeviceComputeCapability( major: *mut ::std::os::raw::c_int, minor: *mut ::std::os::raw::c_int, dev: CUdevice, ) -> CUresult; + super::cuDeviceComputeCapability_Post; } extern_redirect! { pub fn cuDevicePrimaryCtxRetain(pctx: *mut CUcontext, dev: CUdevice) -> CUresult; diff --git a/zluda_dump/src/lib.rs b/zluda_dump/src/lib.rs index d96e8c7..780b9e8 100644 --- a/zluda_dump/src/lib.rs +++ b/zluda_dump/src/lib.rs @@ -182,6 +182,7 @@ impl GlobalDelayedState { struct Settings { dump_dir: Option, libcuda_path: String, + override_cc_major: Option, } impl Settings { @@ -191,7 +192,7 @@ impl Settings { Ok(Some(dir)) => { logger.log(log::LogEntry::CreatedDumpDirectory(dir.clone())); Some(dir) - }, + } Ok(None) => None, Err(err) => { logger.log(log::LogEntry::ErrorBox(err)); @@ -206,9 +207,24 @@ impl Settings { } Ok(env_string) => env_string, }; + let override_cc_major = match env::var("ZLUDA_OVERRIDE_COMPUTE_CAPABILITY_MAJOR") { + Err(env::VarError::NotPresent) => None, + Err(e) => { + logger.log(log::LogEntry::ErrorBox(Box::new(e) as _)); + None + } + Ok(env_string) => match str::parse::(&*env_string) { + Err(e) => { + logger.log(log::LogEntry::ErrorBox(Box::new(e) as _)); + None + } + Ok(cc) => Some(cc), + }, + }; Settings { dump_dir, libcuda_path, + override_cc_major, } } @@ -1471,4 +1487,40 @@ pub(crate) fn cuModuleGetFunction_Post( if !state.module_exists(hmod) { fn_logger.log(log::LogEntry::UnknownModule(hmod)) } + match unsafe { CStr::from_ptr(name) }.to_str() { + Ok(str) => fn_logger.log(log::LogEntry::FunctionParameter { + name: "name", + value: str.to_string(), + }), + Err(e) => fn_logger.log(log::LogEntry::MalformedFunctionName(e)), + } +} + +#[allow(non_snake_case)] +pub(crate) fn cuDeviceGetAttribute_Post( + pi: *mut ::std::os::raw::c_int, + attrib: CUdevice_attribute, + dev: CUdevice, + fn_logger: &mut log::FunctionLogger, + state: &mut trace::StateTracker, + result: CUresult, +) { + fn_logger.log(log::LogEntry::FunctionParameter { + name: "attrib", + value: attrib.0.to_string(), + }); +} + +#[allow(non_snake_case)] +pub(crate) fn cuDeviceComputeCapability_Post( + major: *mut ::std::os::raw::c_int, + minor: *mut ::std::os::raw::c_int, + dev: CUdevice, + fn_logger: &mut log::FunctionLogger, + state: &mut trace::StateTracker, + result: CUresult, +) { + if let Some(major_ver_override) = state.override_cc_major { + unsafe { *major = major_ver_override as i32 }; + } } diff --git a/zluda_dump/src/log.rs b/zluda_dump/src/log.rs index 474912f..a7dc399 100644 --- a/zluda_dump/src/log.rs +++ b/zluda_dump/src/log.rs @@ -302,6 +302,11 @@ pub(crate) enum LogEntry { raw_image: *const c_void, kind: &'static str, }, + MalformedFunctionName(Utf8Error), + FunctionParameter { + name: &'static str, + value: String, + }, MalformedModulePath(Utf8Error), NonUtf8ModuleText(Utf8Error), NulInsideModuleText(NulError), @@ -377,6 +382,8 @@ impl Display for LogEntry { expected, observed, } => write!(f, "Unexected argument"), + LogEntry::MalformedFunctionName(e) => e.fmt(f), + LogEntry::FunctionParameter { name, value } => write!(f, "{}: {}", name, value), } } } diff --git a/zluda_dump/src/trace.rs b/zluda_dump/src/trace.rs index f93c360..3bdf807 100644 --- a/zluda_dump/src/trace.rs +++ b/zluda_dump/src/trace.rs @@ -21,6 +21,7 @@ pub(crate) struct StateTracker { submodule_counter: usize, last_module_version: Option, pub(crate) dark_api: dark_api::DarkApiState, + pub(crate) override_cc_major: Option, } impl StateTracker { @@ -32,6 +33,7 @@ impl StateTracker { submodule_counter: 0, last_module_version: None, dark_api: dark_api::DarkApiState::new(), + override_cc_major: settings.override_cc_major, } } -- cgit v1.2.3