sci_form/gpu/backend_report.rs
1//! Backend execution reporting for GPU/CPU compute dispatch.
2//!
3//! Every orbital grid or isosurface execution returns a report indicating
4//! which backend was actually used (GPU vs CPU) and why, enabling
5//! transparent benchmarking and fallback diagnostics.
6
7/// Coarse activation state for the GPU runtime.
8#[derive(Debug, Clone, PartialEq, Eq)]
9pub enum GpuActivationState {
10 /// GPU feature is not enabled at compile time.
11 FeatureDisabled,
12 /// GPU feature enabled but no hardware adapter found.
13 NoAdapter,
14 /// GPU runtime is fully available and ready for dispatch.
15 Ready,
16}
17
18/// Activation report describing the current GPU runtime state.
19#[derive(Debug, Clone)]
20pub struct GpuActivationReport {
21 /// Backend name visible to callers (e.g. "Vulkan", "Metal", "CPU-fallback").
22 pub backend: String,
23 /// Whether the build includes the `experimental-gpu` feature.
24 pub feature_enabled: bool,
25 /// Whether a real GPU adapter was found and device created.
26 pub gpu_available: bool,
27 /// Whether the orbital grid GPU pipeline is ready.
28 pub runtime_ready: bool,
29 /// Coarse activation state.
30 pub state: GpuActivationState,
31 /// Human-readable explanation.
32 pub reason: String,
33}
34
35/// Per-execution report for orbital grid evaluation.
36#[derive(Debug, Clone)]
37pub struct OrbitalGridReport {
38 /// Backend that actually executed the computation.
39 pub backend: String,
40 /// Whether GPU was used for this execution.
41 pub used_gpu: bool,
42 /// Whether GPU dispatch was attempted before falling back.
43 pub attempted_gpu: bool,
44 /// Number of grid points evaluated.
45 pub n_points: usize,
46 /// Human-readable note for logs.
47 pub note: String,
48}
49
50/// Per-execution report for isosurface extraction.
51#[derive(Debug, Clone)]
52pub struct IsosurfaceReport {
53 /// Backend used for grid evaluation.
54 pub grid_backend: String,
55 /// Whether GPU was used for the grid evaluation step.
56 pub grid_used_gpu: bool,
57 /// Number of triangles produced.
58 pub n_triangles: usize,
59 /// Isovalue used.
60 pub isovalue: f64,
61}
62
63#[cfg(test)]
64mod tests {
65 use super::*;
66
67 #[test]
68 fn test_activation_state_enum() {
69 let state = GpuActivationState::FeatureDisabled;
70 assert_eq!(state, GpuActivationState::FeatureDisabled);
71 assert_ne!(state, GpuActivationState::Ready);
72 }
73
74 #[test]
75 fn test_activation_report_cpu_fallback() {
76 let report = GpuActivationReport {
77 backend: "CPU-fallback".to_string(),
78 feature_enabled: false,
79 gpu_available: false,
80 runtime_ready: false,
81 state: GpuActivationState::FeatureDisabled,
82 reason: "Feature not enabled".to_string(),
83 };
84 assert!(!report.gpu_available);
85 assert!(!report.runtime_ready);
86 }
87
88 #[test]
89 fn test_orbital_grid_report() {
90 let report = OrbitalGridReport {
91 backend: "CPU".to_string(),
92 used_gpu: false,
93 attempted_gpu: false,
94 n_points: 1000,
95 note: "CPU evaluation".to_string(),
96 };
97 assert_eq!(report.n_points, 1000);
98 assert!(!report.used_gpu);
99 }
100}