diff --git a/docs/envvars.rst b/docs/envvars.rst index c8780521293..f9ca4eca2f0 100644 --- a/docs/envvars.rst +++ b/docs/envvars.rst @@ -1119,6 +1119,8 @@ Rusticl environment variables - ``allow_invalid_spirv`` disables validation of any input SPIR-V - ``clc`` dumps all OpenCL C source being compiled + - ``perf`` prints a warning when hitting slow paths once + - ``perfspam`` same as perf, but doesn't skip same warnings - ``program`` dumps compilation logs to stderr - ``sync`` waits on the GPU to complete after every event - ``validate`` validates any internally generated SPIR-Vs, e.g. through compiling OpenCL C code diff --git a/src/gallium/frontends/rusticl/core/platform.rs b/src/gallium/frontends/rusticl/core/platform.rs index 305600a70cf..50fb82ef877 100644 --- a/src/gallium/frontends/rusticl/core/platform.rs +++ b/src/gallium/frontends/rusticl/core/platform.rs @@ -17,9 +17,16 @@ pub struct Platform { pub devs: Vec, } +pub enum PerfDebugLevel { + None, + Once, + Spam, +} + pub struct PlatformDebug { pub allow_invalid_spirv: bool, pub clc: bool, + pub perf: PerfDebugLevel, pub program: bool, pub max_grid_size: u64, pub sync_every_event: bool, @@ -66,6 +73,7 @@ static mut PLATFORM: Platform = Platform { static mut PLATFORM_DBG: PlatformDebug = PlatformDebug { allow_invalid_spirv: false, clc: false, + perf: PerfDebugLevel::None, program: false, max_grid_size: 0, sync_every_event: false, @@ -84,6 +92,8 @@ fn load_env() { match flag { "allow_invalid_spirv" => debug.allow_invalid_spirv = true, "clc" => debug.clc = true, + "perf" => debug.perf = PerfDebugLevel::Once, + "perfspam" => debug.perf = PerfDebugLevel::Spam, "program" => debug.program = true, "sync" => debug.sync_every_event = true, "validate" => debug.validate_spirv = true, @@ -169,3 +179,23 @@ impl GetPlatformRef for cl_platform_id { } } } + +#[macro_export] +macro_rules! perf_warning { + (@PRINT $format:tt, $($arg:tt)*) => { + eprintln!(std::concat!("=== Rusticl perf warning: ", $format, " ==="), $($arg)*) + }; + + ($format:tt $(, $arg:tt)*) => { + match $crate::core::platform::Platform::dbg().perf { + $crate::core::platform::PerfDebugLevel::Once => { + static PERF_WARN_ONCE: std::sync::Once = std::sync::Once::new(); + PERF_WARN_ONCE.call_once(|| { + perf_warning!(@PRINT $format, $($arg)*); + }) + }, + $crate::core::platform::PerfDebugLevel::Spam => perf_warning!(@PRINT $format, $($arg)*), + _ => (), + } + }; +}