Skip to main content

runmat_plot/gpu/
tuning.rs

1use std::sync::atomic::{AtomicU32, Ordering};
2
3/// Default workgroup size used by plotting compute shaders when no hint is
4/// provided by the acceleration stack. Matches the WGPU backend defaults so we
5/// stay within adapter limits even before calibration.
6const DEFAULT_WG_SIZE: u32 = 256;
7
8static WORKGROUP_OVERRIDE: AtomicU32 = AtomicU32::new(0);
9
10/// Returns the currently configured workgroup size for plot compute shaders.
11pub fn effective_workgroup_size() -> u32 {
12    let value = WORKGROUP_OVERRIDE.load(Ordering::Relaxed);
13    if value > 0 {
14        value
15    } else {
16        DEFAULT_WG_SIZE
17    }
18}
19
20/// Update the workgroup size hint using the acceleration provider's
21/// auto-calibrated value. Values of zero are ignored to avoid disabling the
22/// fallback default.
23pub fn set_effective_workgroup_size(value: u32) {
24    if value > 0 {
25        WORKGROUP_OVERRIDE.store(value, Ordering::Relaxed);
26    }
27}