1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
//! Environment-variable knobs for OA runtime configuration.
//!
//! Port provenance: `oa/core/envFlag.h`.
//!
//! [`EnvFlag`] is the single-source convention for reading OA env knobs.
//! [`NumericMode`] and [`apply_numeric_mode`] translate a process-wide numeric
//! execution policy into the equivalent env-knob state, called once from
//! `Engine::create`.
//!
//! # Reading pattern
//!
//! ```rust,ignore
//! use oa::EnvFlag;
//!
//! // bool toggle — true when set to anything other than 0/false/no/off
//! if EnvFlag::is_set("OA_DISABLE_COOPMAT") { ... }
//!
//! // string override — returns default when var is unset or empty
//! let prec = EnvFlag::get_string("OA_FORCE_PRECISION", "FP32");
//!
//! // integer override — returns default when unset or unparseable
//! let workers = EnvFlag::get_int("OA_SHADER_LOAD_THREADS", 0);
//! ```
//!
//! # Canonical OA env knobs
//!
//! ## Disable toggles
//! - `OA_DISABLE_COOPMAT` — skip CoopMat extension; route to scalar
//! - `OA_DISABLE_COOPMAT2` — skip VK_NV_cooperative_matrix2
//! - `OA_DISABLE_BF16` — force FP32; skip VK_KHR_shader_bfloat16
//! - `OA_DISABLE_PERSISTENT_LOOP` — force single-step submission
//! - `OA_DISABLE_INTEGER_DOT_PRODUCT` — skip VK_KHR_shader_integer_dot_product
//! - `OA_DISABLE_GRU_SCAN` — use decomposed GRU cells instead of fused scan
//! - `OA_DISABLE_GEMM_ROUTE_CACHE` — skip measured GEMM route-cache replay
//! - `OA_DISABLE_NARROW_ROW_KERNELS` — skip narrow LayerNorm/softmax schedules
//! - `OA_DISABLE_TILED_BMM` — skip the shared-memory BMM schedule
//! - `OA_DISABLE_LINEAR_PARAM_ROWS32` — skip narrow Linear parameter-adjoint schedule
//!
//! ## Force overrides
//! - `OA_FORCE_PRECISION=FP32|BF16|FP16`
//! - `OA_FORCE_COOPMAT=1` — bypass vendor-trust blocklist
//! - `OA_FORCE_COOPVEC=1` — bypass CoopVec NVIDIA-only routing gate
//! - `OA_FORCE_DEVICE_INDEX=N` — override device pick
//! - `OA_SHADER_LOAD_THREADS=0|1|N` — shader preload workers
//!
//! ## Diagnostic / opt-in logging
//! - `OA_VK_VALIDATION=1`
//! - `OA_LOG_GEMM_ROUTER=1`
//! - `OA_LOG_PIPELINE_LOAD=1`
//! - `OA_LOG_BARRIERS=1`
//! - `OA_LOG_CONTEXT_GRAPH=N`
//! - `OA_GRAPH_REPORT=path|1`
//! - `OA_LOG_COOPMAT_SHAPES=1`
//! - `OA_LOG_NUMERIC_DEVIATIONS=1`
use env;
// ─── EnvFlag ─────────────────────────────────────────────────────────────────
/// Single-source environment-variable reader for OA runtime knobs.
;
// ─── NumericMode ──────────────────────────────────────────────────────────────
/// Process-wide numerical execution policy.
///
/// Core owns the vocabulary and its environment mapping; the runtime engine
/// consumes it through `EngineConfig`.
///
/// | Mode | Effect |
/// |-----------------|--------|
/// | `Fast` | vendor math, non-deterministic reductions |
/// | `Stable` | FP32 accumulators, CoopMat disabled |
/// | `Deterministic` | fixed reduction order, no race-dependent atomics |
///
/// Port provenance: `oa::NumericMode` in `oa/core/envFlag.h`.
// ─── apply_numeric_mode ───────────────────────────────────────────────────────
/// Translate a [`NumericMode`] into the equivalent env-knob state.
///
/// Called **once** at engine init. User-set env vars always win
/// ([`EnvFlag::set_if_unset`] checks before writing).
///
/// | Mode | Env vars touched |
/// |-----------------|-----------------|
/// | `Fast` | none |
/// | `Stable` | `OA_FORCE_PRECISION=FP32`, `OA_DISABLE_COOPMAT=1` |
/// | `Deterministic` | above + `OA_DISABLE_PERSISTENT_LOOP=1` |
///
/// Port provenance: `oa::applyNumericMode` in `oa/core/envFlag.h`.