qualia_cli/
benchmark_env.rs1use serde_json::json;
4
5const MEMORY_CEILING_MB: u16 = 512;
6
7fn gpu_manifest() -> serde_json::Value {
8 let availability =
12 std::env::var("QUALIA_BENCH_GPU_STATUS").unwrap_or_else(|_| "not_probed".to_owned());
13 let has_gpu = match availability.as_str() {
14 "available" => Some(true),
15 "not_detected" => Some(false),
16 _ => None,
17 };
18 let details = std::env::var("QUALIA_BENCH_GPU_DETAILS").ok();
19
20 json!({
21 "availability": availability,
22 "has_gpu": has_gpu,
23 "details": details,
24 "accelerator_used_for_this_suite": false,
25 "note": "This CLI suite is CPU-native. GPU presence is recorded for interpretation, not used by these measurements."
26 })
27}
28
29fn host_class() -> &'static str {
30 #[cfg(all(target_arch = "aarch64", target_os = "macos"))]
31 {
32 return "APPLE_SILICON";
33 }
34 #[cfg(all(target_arch = "aarch64", any(target_os = "android", target_os = "ios")))]
35 {
36 return "ARM64_MOBILE";
37 }
38 #[cfg(all(
39 target_arch = "aarch64",
40 not(any(target_os = "macos", target_os = "android", target_os = "ios"))
41 ))]
42 {
43 return "ARM64_SERVER";
44 }
45 #[cfg(target_arch = "x86_64")]
46 {
47 return "X86_64_SERVER";
48 }
49 #[cfg(target_arch = "wasm32")]
50 {
51 return "WASM_BROWSER";
52 }
53 #[cfg(not(any(
54 all(target_arch = "aarch64", target_os = "macos"),
55 all(target_arch = "aarch64", any(target_os = "android", target_os = "ios")),
56 all(
57 target_arch = "aarch64",
58 not(any(target_os = "macos", target_os = "android", target_os = "ios"))
59 ),
60 target_arch = "x86_64",
61 target_arch = "wasm32",
62 )))]
63 {
64 return "UNKNOWN";
65 }
66}
67
68pub fn collect_device_manifest() -> serde_json::Value {
70 let mut sys = sysinfo::System::new_all();
71 sys.refresh_memory();
72 let ram_gb = (sys.total_memory() as f64) / (1024.0 * 1024.0 * 1024.0);
73
74 json!({
75 "host_class": host_class(),
76 "cpu_arch": std::env::consts::ARCH,
77 "os": std::env::consts::OS,
78 "cpu_logical_cores": sys.cpus().len(),
79 "cpu_physical_cores": sysinfo::System::physical_core_count(),
80 "ram_reported_gb": (ram_gb * 10.0).round() / 10.0,
81 "has_simd_wasm": false,
82 "has_npu": false,
83 "gpu": gpu_manifest(),
84 "ci": {
85 "github_actions": std::env::var("GITHUB_ACTIONS").ok().as_deref() == Some("true"),
86 "runner_os": std::env::var("RUNNER_OS").ok(),
87 "runner_arch": std::env::var("RUNNER_ARCH").ok()
88 }
89 })
90}
91
92pub fn bench_execution_environment() -> serde_json::Value {
94 json!({
95 "runner": "qualia-cli bench",
96 "engine_version": env!("CARGO_PKG_VERSION"),
97 "memory_ceiling_mb": MEMORY_CEILING_MB,
98 "measurement_path": "in_process_microbench",
99 "topology": {
100 "mode": "single_process",
101 "worker_cells_configured": 1,
102 "worker_cells_active_during_run": 1,
103 "compute_swarm_enabled": false,
104 "gpu_acceleration_used": false,
105 "cell_memory_floor_mb": MEMORY_CEILING_MB,
106 "scheduling": "serial"
107 },
108 "device_manifest": collect_device_manifest()
109 })
110}