settings.hh
Go to the documentation of this file.
1#pragma once
2
3/// @file
4/// @brief Every `BATCHLAS_*` environment variable the library reads, captured once into
5/// batchlas::Settings, plus the programmatic override configure().
6///
7/// The environment is read once, on the first call to settings(). A knob whose call site uses
8/// one of the shared parsers in `<batchlas/util/env.hh>` is a typed field parsed by that same
9/// parser; a knob with a bespoke parser is an EnvValue (the raw string) and its parser stays at
10/// the call site, so every variable means exactly what it meant before this header existed.
11/// The user guide, with a field/variable/default table per group, is the "Configuration"
12/// section of @ref md_docs_2cpp-api.
13/// @see @ref design_environment
14/// @ingroup api_config
15// Move where the STRING comes from, never how it is parsed (seven boolean dialects coexist).
16// evidence: docs/design/environment.md#environment-move-the-string-not-the-parser
17
18#include <batchlas/export.hh>
19#include <array>
20#include <cstddef>
21#include <optional>
22#include <stdexcept>
23#include <string>
24#include <string_view>
25
26namespace batchlas {
27
28/// @brief A raw captured environment value, shaped like the `std::getenv` call it replaces.
29///
30/// Distinguishes "unset" from "set to the empty string", and hands back a `const char*` so a
31/// migrated call site keeps the parser it already has.
32/// @ingroup api_config
33// Unset vs empty is load-bearing: the TRACE_PATH fall-through, and the route pin reader treats
34// a set-but-empty BATCHLAS_<OP>_ROUTE as unset.
35class EnvValue {
36public:
37 /// @brief An unset value.
38 EnvValue() = default;
39
40 /// @brief Construct from what `std::getenv` returned.
41 /// @param raw the variable's value, or `nullptr` for an unset variable
42 explicit EnvValue(const char* raw) {
43 if (raw) {
44 set_ = true;
45 value_ = raw;
46 }
47 }
48
49 /// @brief An unset value.
50 static EnvValue unset() { return EnvValue(); }
51
52 /// @brief A value that is set to `v` (which may be empty).
53 static EnvValue of(std::string v) {
54 EnvValue e;
55 e.set_ = true;
56 e.value_ = std::move(v);
57 return e;
58 }
59
60 /// @brief True when the variable was set, including set to the empty string.
61 bool is_set() const noexcept { return set_; }
62
63 /// @brief The value, or `nullptr` when unset: the drop-in for `std::getenv("...")`.
64 const char* get() const noexcept { return set_ ? value_.c_str() : nullptr; }
65
66 /// @brief The value as text; empty when unset.
67 const std::string& value() const noexcept { return value_; }
68
69private:
70 bool set_ = false;
71 std::string value_;
72};
73
74/// @brief The route pins: `BATCHLAS_<OP>_ROUTE`, one raw string per op that selects a kernel.
75///
76/// Raw strings on purpose: `src/select` parses them for every op (`auto` | `native` | `vendor` |
77/// a choice spelling such as `lpanel:panel=8`). Values are trimmed and case-folded; a set-but-empty
78/// value means `auto`. A value the op does not understand throws `std::invalid_argument`; only
79/// `native` and `vendor` warn and fall back to `auto` when nothing in that class can run the call.
80/// The selection layer is described in docs/design/flat-kernel-selection.md.
81/// @ingroup api_config
83 /// @brief The ops that read a route variable, by their `<op>` spelling.
84 static constexpr std::array<std::string_view, 19> ops{
85 "gemm", "gemv", "trsm", "trmm", "symm", "syrk", "syr2k", "potrf", "posv", "getrf",
86 "getrs", "getri", "gesv", "geqrf", "orgqr", "ormqr", "syev", "gesvd", "spmm"};
87
88 /// @brief `BATCHLAS_<OP>_ROUTE`, in `ops` order.
89 std::array<EnvValue, ops.size()> values{};
90
91 /// @brief Position of `op` in `ops`, or `ops.size()` when `op` reads no route variable.
92 static constexpr std::size_t index_of(std::string_view op) {
93 for (std::size_t i = 0; i < ops.size(); ++i)
94 if (ops[i] == op) return i;
95 return ops.size();
96 }
97
98 /// @brief The captured `BATCHLAS_<OP>_ROUTE` for `op`.
99 /// @throws std::invalid_argument for an op not in `ops`
100 const EnvValue& route(std::string_view op) const { return values[checked(op)]; }
101 /// @brief Mutable access to the captured `BATCHLAS_<OP>_ROUTE` for `op`, as configure() needs.
102 EnvValue& route(std::string_view op) { return values[checked(op)]; }
103
104private:
105 static std::size_t checked(std::string_view op) {
106 const std::size_t i = index_of(op);
107 if (i == ops.size())
108 throw std::invalid_argument("batchlas: no BATCHLAS_<OP>_ROUTE for op '" + std::string(op) + "'");
109 return i;
110 }
111};
112
113/// @brief Which kernel or algorithm runs, for the knobs outside the route pins.
114///
115/// Every field changes which code path executes. `syevx_algorithm` and `syevx_preconditioner`
116/// override an explicit SyevxParams field, and `gesvd_bidiag` changes numerics.
117/// @ingroup api_config
118// evidence: docs/design/environment.md#environment-knobs-that-override-an-explicit-argument
120 /// `BATCHLAS_EXPAND_ROUTE` = `expand` | `loop`: pins the scratch-expansion route of hemm, herk
121 /// and her2k, so a test can reach the arm the shape would not have picked (symm and trmm pin
122 /// `expand` through their `BATCHLAS_<OP>_ROUTE`). Not op-keyed, so RoutingSettings does not
123 /// hold it.
124 // Read at two sites (src/expansion_budget.hh, src/kernels/common/triangular_expand.hh) by two
125 // independent parsers that currently agree; both read this one field.
127
128 /// `BATCHLAS_GEMV_SEGT` = `off` | `auto` | `2` | `4` | `8`: segmented-tail width of the
129 /// native gemv.
130 // Never latch it in a static: a later setenv goes unseen and tests pass on the default arm.
131 // That prohibition is why detail::reload_settings() exists.
133
134 /// `BATCHLAS_GESVD_BIDIAG` = `bdsdc` | `normal` | `bdsqr`.
135 /// @warning Changes numerics: `normal` squares the condition number. The thin-tall-U rule at
136 /// the call site overrides it so a buffer-size query and its solve agree.
137 // evidence: docs/perf/gesvd.md#gesvd-tier-3-bdsdc-as-the-bidiagonal-solver
139
140 /// `BATCHLAS_GETRF_LEAF` = `slm` | `reg` (default: the register-resident panel leaf wherever
141 /// the panel fits). Re-read per call.
143
144 /// `BATCHLAS_GEQRF_LEAF` = `auto` (default) | `reg` (the register panel leaf wherever it
145 /// fits). Re-read per call.
146 // evidence: docs/perf/qr.md#qr-the-register-leaf-ab
148
149 /// `BATCHLAS_GETRF_LASWP` = `inloop` | `defer_walk` | `defer_gather` (default). Presence is
150 /// latched at the call site, the value re-read per call.
152
153 /// `BATCHLAS_GETRF_RIGHT_LASWP` = `walk` | `gather`; unset takes the measured crossover.
155
156 /// `BATCHLAS_GETRS_LASWP` = `walk` | `gather`. Deliberately not latched (as gemv_segt).
158
159 /// `BATCHLAS_ILUK_DEVICE`: only a first character of `0` or `1` is inspected; `true`, `on`
160 /// and `yes` fall through to the shape default (batch_size >= 32).
162
163 /// `BATCHLAS_LATRD_IMPL` = `legacy` | `device` | `grid`. Re-read per call.
165
166 /// `BATCHLAS_ORMQR_IMPL`: only the exact value `device` has an effect.
168
169 /// `BATCHLAS_ORMQR_WY` = `gemm` | `trmm` | `measured`: overrides the measured gate.
171
172 /// `BATCHLAS_ORTHO_GRAM`: only the exact value `gemm` has an effect (forces the GEMM gram
173 /// route in place of the syrk one).
175
176 /// `BATCHLAS_SB2ST_BACK_WAVE`: the wave-parallel back-transform is on unless disabled with one
177 /// of `0`, `false`, `off`, `no`, `n`, `disable`, `disabled` (case-insensitive).
178 // Fails OPEN, with a disable set deliberately WIDER than env_falsy. Must stay raw: never
179 // route it through env_falsy. evidence: docs/design/environment.md#environment-sb2st-back-wave-fails-open
181
182 /// `BATCHLAS_SB2ST_SUBGROUP` = `auto` | `on` | `off` (case-folded). `on` throws when kd > 32
183 /// or the device lacks sub-group size 32.
185
186 /// `BATCHLAS_SYEV_TWO_STAGE_CHASE`: only the exact value `givens` has an effect.
187 /// @warning Read by both the solve and its `*_buffer_size` query; do not let a ScopedEnvVar
188 /// straddle a sizing/solve pair.
190
191 /// `BATCHLAS_SYEVX_ALGORITHM`: overrides an explicit `SyevxParams::method`. An env-supplied
192 /// algorithm degrades where an explicit request throws, and an unrecognised value still wins
193 /// (it parses to Auto).
195
196 /// `BATCHLAS_SYEVX_PRECONDITIONER`: overrides the SyevxParams default; loses to an explicit
197 /// request and to a configured ILU(k) factor.
199
200 /// `BATCHLAS_SYEVX_FILTER_DEGREE_AUTO`: derive the Chebyshev filter degree automatically.
201 /// Off by default because it wins only at batch 1. Parsed with `atoi != 0`.
202 // evidence: docs/perf/syevx.md#syevx-automatic-chebyshev-filter-degree
204
205 /// `BATCHLAS_SYEVX_INSTR_HOST`: forces the host instrumentation path. First-character parser
206 /// `{1,t,T,y,Y}`: `true` works, `on` does not.
208
209 /// `BATCHLAS_SYEVX_PROJECTED_VENDOR`: same first-character dialect.
210 /// @warning Changes the workspace size: do not change it between a buffer-size query and its
211 /// call.
213
214 /// `BATCHLAS_SYEVX_SOFT_LOCK`.
215 /// @warning The parser is inverted: it enables unless the first character is one of
216 /// `{0,n,N,f,F}`, so `=off` and an empty export both read as on.
217 // Recorded, not fixed. evidence: docs/design/environment.md#environment-parser-defects-recorded-not-fixed
219
220 /// `BATCHLAS_SYTRD_FORCE_LOCAL_SMALL` (env_truthy): forces the local-memory small-n path past
221 /// the tuning heuristic. It cannot force an unschedulable launch; the device gate still applies.
223
224 /// `BATCHLAS_SYTRD_FUSE_PANEL_UPDATE`: forced on (env_truthy), forced off (env_falsy), or
225 /// `std::nullopt` to let the tuned default decide. A value that is neither reads as nullopt.
226 std::optional<bool> sytrd_fuse_panel_update{};
227
228 /// `BATCHLAS_SYTRD_IMPL`: only the exact value `device` has an effect.
230
231 /// `BATCHLAS_SYTRD_TRAILING_UPDATE` = `gemm` | `syr2k` | `her2k` | `rank2k`, either case;
232 /// `syr2k` and `her2k` select one route.
234
235 /// `BATCHLAS_TUNED_DIR`: a directory of select tables (`src/select/select.hh`); a
236 /// file there replaces the built-in table of the same name.
238};
239
240/// @brief Launch geometry, block widths, iteration counts and tuning thresholds.
241///
242/// Where the call site's default is a function of n, the scalar type, an argument or a device
243/// property, the field is a sentinel (0, `std::nullopt` or an unset EnvValue) and the default
244/// stays at the call site. Fields with a constant default carry it.
245/// @ingroup api_config
246// Never materialise a function-valued default here: it pins a tuned curve at one point.
247// evidence: docs/design/environment.md#environment-geometry-defaults-stay-at-the-call-site
249 /// `BATCHLAS_LATRD_GRID_GROUPS` (env_positive_int_or). 0 = auto,
250 /// `min(residency cap, ceil((n-1)/32))`. A forced value is still clamped by the residency cap
251 /// unless UnsafeSettings::latrd_grid_force_unsafe lifts it.
253
254 /// `BATCHLAS_LATRD_GRID_MIN_N` (env_positive_int_or): the n at which the grid latrd path
255 /// becomes eligible.
256 // evidence: docs/perf/syev.md#syev-latrd-grid-gate-confirmed-in-eigenvector-mode
258
259 /// `BATCHLAS_LATRD_GRID_WG` (env_positive_int_or). 0 = computed. Only 32, 64, 128 and 256 are
260 /// honoured; any other value is silently ignored.
262
263 /// `BATCHLAS_LATRD_LOWER_PANEL_WG_HINT`. 0 = unset; only 64, 128 and 256 take effect, and only
264 /// on the device path. Wins over `BATCHLAS_TUNE_LATRD_WG_HINT`.
265 // Deliberately not unified. evidence: docs/design/environment.md#environment-two-variables-for-one-quantity
267
268 /// `BATCHLAS_SB2ST_BACK_SUBS` (env_positive_int_or). 0 = the call site's default chain.
269 /// @note Force together with sb2st_back_tile_w; only tile {1,2,4,8} x subs {4,8,16} are
270 /// instantiated.
272
273 /// `BATCHLAS_SB2ST_BACK_TILE_W` (env_positive_int_or): column tile of the wave kernel.
274 /// 0 = the tuned heuristic.
276
277 /// `BATCHLAS_SB2ST_BACK_TILE`: tile of the tiled back-transform kernel (a different kernel
278 /// from sb2st_back_tile_w). `0` selects the streaming kernel.
279 // RAW: env_positive_int_or would silently turn =0 (streaming kernel) into "unset".
281
282 /// `BATCHLAS_POTRF_NB`. 0 = unset; the default is type-dependent
283 /// (128/96/96/64 for float/double/cfloat/cdouble).
284 int potrf_nb = 0;
285 /// `BATCHLAS_POTRF_W`. 0 = unset; the default is type-dependent (128/32/32/16).
286 int potrf_w = 0;
287
288 /// `BATCHLAS_SYEV_TWO_STAGE_KD` (env_positive_int_or): the band width, clamped to `[1, n-1]`
289 /// at the call site.
291
292 /// `BATCHLAS_SYEV_TWO_STAGE_SB2ST_BLOCK` (env_positive_int_or). Read by four solve/sizing
293 /// pairs.
295
296 /// `BATCHLAS_SY2SB_ORMQR_NB`: unset, `off` or `0` (never hint), or a positive forced value
297 /// (clamped to kd at the call site). A value that does not parse, is negative or is above 1024
298 /// reads as unset. Wins over `BATCHLAS_TUNE_SY2SB_ORMQR_NB`.
300
301 /// `BATCHLAS_SYTRD_BLOCK_SIZE`. 0 = unset; the default is n-bucketed and type-dependent.
302 /// Wins over `BATCHLAS_TUNE_SYTRD_BLOCK_SIZE`.
304
305 /// `BATCHLAS_TRMM_TILE_M`. 0 = unset (a function of m); bucketed to 16, 32, 64 or 128.
306 int trmm_tile_m = 0;
307
308 /// `BATCHLAS_TRSM_OUTER_NB`. 0 = unset: 128 for Side::Left, the CTA nb for Side::Right.
310
311 /// `BATCHLAS_EXPAND_MAX_BYTES` (`strtoull`): only ever lowers the expansion ceiling, whose
312 /// default is `GLOBAL_MEM_SIZE / 4`.
314
315 /// `BATCHLAS_GESVD_BLOCKED_GEBRD_MIN` (bare `atoi`, default 1).
316 /// @warning An unparseable value reads as 0, which widens the blocked gebrd path to every n.
317 // Recorded, not changed. evidence: docs/design/environment.md#environment-parser-defects-recorded-not-fixed
319
320 /// `BATCHLAS_SYEVX_CHECK_EVERY`: iterations between convergence checks; each check is a full
321 /// pipeline drain.
323
324 /// `BATCHLAS_SYEVX_EXTRA_DIRECTIONS`: 0 means "no guard block"; nullopt means the default
325 /// `max(2, k/4)`. A negative value reads as unset.
326 std::optional<int> syevx_extra_directions{};
327
328 /// `BATCHLAS_SYEVX_FILTER_DEGREE`. 0 = unset (only > 0 is accepted). Top of a four-level
329 /// precedence chain; setting it also disables the automatic degree.
331
332 /// `BATCHLAS_SYEVX_INIT_POWER`: 0 means "no power iterations"; nullopt means 4 unless
333 /// SyevxParams supplied a value.
334 std::optional<int> syevx_init_power{};
335
336 /// `BATCHLAS_SYEVX_LOCK_FACTOR` (`atof`, > 0 only): a column is masked once its residual is
337 /// this multiple of the tolerance. An unparseable value yields the default.
338 // Locking exactly at tol oscillates: a masked column is not frozen and drifts back above tol.
339 double syevx_lock_factor = 0.1;
340
341 /// @brief The runtime overrides of include/batchlas/tuning_params.hh (`BATCHLAS_TUNE_*`).
342 ///
343 /// Parsed by `tuning::detail::tuning_env_override`, which rejects trailing garbage and
344 /// values <= 0 or above INT32_MAX; each default is the n-bucketed compiled constant.
345 /// @see @ref perf_tuning
346 // A settings() read added to tuning_params.hh must be mirrored in the generator's template.
347 // evidence: docs/perf/tuning.md#tuning-regenerating-the-header
349 EnvValue ormqr_block_size{}; ///< `BATCHLAS_TUNE_ORMQR_BLOCK_SIZE`
350 EnvValue gebrd_block_size{}; ///< `BATCHLAS_TUNE_GEBRD_BLOCK_SIZE`
351 EnvValue sb2st_back_tile{}; ///< `BATCHLAS_TUNE_SB2ST_BACK_TILE`
352 EnvValue sb2st_back_subs{}; ///< `BATCHLAS_TUNE_SB2ST_BACK_SUBS`
353 EnvValue sy2sb_ormqr_nb{}; ///< `BATCHLAS_TUNE_SY2SB_ORMQR_NB`
354 EnvValue sytrd_block_size{}; ///< `BATCHLAS_TUNE_SYTRD_BLOCK_SIZE`
355 EnvValue latrd_wg_hint{}; ///< `BATCHLAS_TUNE_LATRD_WG_HINT`
356 EnvValue stedc_recursion_threshold{}; ///< `BATCHLAS_TUNE_STEDC_RECURSION_THRESHOLD`
357
358 /// `BATCHLAS_TUNE_STEDC_MERGE_VARIANT`: a StedcMergeVariant value; 0 (Auto) is unreachable.
359 // An enum smuggled through an int, cast with no range check; one variant is known to
360 // deadlock on some hardware. evidence: docs/design/environment.md#environment-parser-defects-recorded-not-fixed
362
363 EnvValue stedc_threads_per_root{}; ///< `BATCHLAS_TUNE_STEDC_THREADS_PER_ROOT`
364 EnvValue stedc_wg_multiplier{}; ///< `BATCHLAS_TUNE_STEDC_WG_MULTIPLIER`
365 } tune{}; ///< The eleven `BATCHLAS_TUNE_*` overrides.
366};
367
368/// @brief Tracing, dumping, profiling and the opt-in checks. None changes a numeric result.
369///
370/// Three of these name a filesystem path the library opens for writing (the kernel trace and
371/// the coverage output from `atexit` handlers, the band-reduction dump via
372/// `create_directories()`); an embedding application can clear them with configure().
373/// @ingroup api_config
374// evidence: docs/design/environment.md#environment-files-written-from-the-environment
376 /// `BATCHLAS_QUEUE_PROFILING` or `BATCHLAS_BENCH_PROFILING` (env_truthy, ORed): enable SYCL
377 /// queue profiling. Opt-in because it costs on every submit; the kernel trace implies it.
378 bool profiling = false;
379
380 /// `BATCHLAS_KERNEL_TRACE` or `BATCHLAS_TRACE_KERNELS` (env_truthy, ORed).
381 bool kernel_trace = false;
382
383 /// `BATCHLAS_METAL_FLUSH_EACH_OP` (env_truthy): Metal queues created afterwards commit one
384 /// command buffer per operation instead of batching them (AdaptiveCpp coarse-grained
385 /// events), so a GPU fault names the operation that raised it. Profiling implies it.
387
388 /// The first non-empty of `BATCHLAS_KERNEL_TRACE_PATH` and `BATCHLAS_TRACE_PATH`. Written
389 /// from an `atexit` handler.
390 std::string kernel_trace_path = "batchlas_kernels.trace.json";
391
392 /// `BATCHLAS_COVERAGE_OUT`: dispatch coverage is written to `<value>.<pid>` at exit.
394
395 /// `BATCHLAS_SELECT_TRACE` (env_truthy): one stderr line per `select::choose` decision
396 /// (`src/select/select.hh`).
397 bool select_trace = false;
398
399 /// `BATCHLAS_DEBUG_FILTER_DEGREE`: presence only, so any value including the empty string
400 /// enables it. Prints one line per batch item per iteration.
402
403 /// `BATCHLAS_DEBUG_SYTRD_SMALL` (env_truthy). Prints once.
404 bool debug_sytrd_small = false;
405
406 /// `BATCHLAS_GESVD_PROFILE` (env_truthy): forces a `wait_and_throw()` per stage, serialising
407 /// the pipeline, and prints CSV rows to stderr.
408 bool gesvd_profile = false;
409
410 /// `BATCHLAS_SYEVX_TRACE` (env_truthy).
411 bool syevx_trace = false;
412
413 /// `BATCHLAS_CTA_DEBUG_SYNC` (env_truthy): prints `[cta-debug] <stage>` and drains the
414 /// pipeline at each stage, so an async error surfaces at a named stage.
415 // Not "unsafe": it removes no check. evidence: docs/design/environment.md#environment-two-knobs-that-look-unsafe-and-are-not
416 bool cta_debug_sync = false;
417
418 /// `BATCHLAS_STEQR_CTA_CHECK` (first character `{1,t,T,y,Y}`): steqr_cta scans its per-item
419 /// status and throws if any item did not converge.
420 /// @warning Unset, non-convergence in steqr_cta is silent.
421 // ADDS a check, so it is not "unsafe"; forcing it to its default would entrench the silence.
423
424 /// @brief The `BATCHLAS_DUMP_BANDR1_*` band-reduction dump family. The four index selectors
425 /// (env_int_or) default to -1, "no filter"; a non-negative value dumps only that index.
427 /// `BATCHLAS_DUMP_BANDR1_DIR`: created with `create_directories()`; files are written
428 /// under it while `step` is on.
429 std::string dir = "output/bandr1_dumps";
430
431 /// `BATCHLAS_DUMP_BANDR1_STEP` (env_truthy): the master enable.
432 bool step = false;
433
434 /// `BATCHLAS_DUMP_BANDR1_ABW_ONLY` (env_truthy): suppress every dump except ABw.
435 bool abw_only = false;
436
437 int step_index = -1; ///< `BATCHLAS_DUMP_BANDR1_STEP_INDEX`
438 int sweep_index = -1; ///< `BATCHLAS_DUMP_BANDR1_SWEEP_INDEX`
439 int step_in_sweep = -1; ///< `BATCHLAS_DUMP_BANDR1_STEP_IN_SWEEP`
440 int batch = -1; ///< `BATCHLAS_DUMP_BANDR1_BATCH`; -1 dumps every item
441 } dump_bandr1{}; ///< The band-reduction dump family.
442};
443
444/// @brief The overrides that remove a guarantee: setting one can make a correct program crash,
445/// hang or silently compute wrong numbers.
446///
447/// Unless the library was built with the CMake option `BATCHLAS_ALLOW_UNSAFE_ENV=ON` (default
448/// OFF), the environment cannot move these fields in their unsafe direction: they keep their safe
449/// values and each such variable produces one warning on stderr. configure() is not gated.
450/// @ingroup api_config
451// evidence: docs/design/environment.md#environment-the-unsafe-group-and-its-gate
453 /// `BATCHLAS_SKIP_POINTER_CHECKS`: disables the per-argument USM reachability check that turns
454 /// host memory passed to a device call into an invalid_argument. Without it such a call dies
455 /// in the CUDA runtime with no catchable error.
456 /// @warning Any non-empty value whose first character is not `0` disables the checks, so
457 /// `=false`, `=off` and `=no` all turn them off.
458 // Parser !(v && *v && *v != '0') preserved character for character on purpose.
460
461 /// `BATCHLAS_LATRD_GRID_FORCE_UNSAFE` (env_truthy): lets `BATCHLAS_LATRD_GRID_GROUPS` exceed
462 /// the co-residency cap.
463 /// @warning The grid barrier is a spin barrier that relies on co-residency: the kernel can
464 /// hang (it looks like slow JIT). Run forced measurements under `timeout`.
466
467 /// @brief Behaviour of the host-dgemm health probe (`BATCHLAS_BLAS_HEALTH`).
468 enum class BlasHealth {
469 Off, ///< `off`: skip the probe; a broken host BLAS then gives silently wrong double results. Gated.
470 Warn, ///< `warn` (default): warn when the probe fails.
471 Error ///< `error`: throw when the probe fails. Stricter than the default, so not gated.
472 };
473 /// `BATCHLAS_BLAS_HEALTH` = `off` | `warn` | `error`.
475};
476
477/// @brief Everything BatchLAS reads from its environment, in one value.
478///
479/// Copyable on purpose; to change one field programmatically:
480/// @code
481/// auto s = batchlas::settings();
482/// s.diagnostics.dump_bandr1.step = false;
483/// batchlas::configure(s);
484/// @endcode
485/// @ingroup api_config
486struct Settings {
487 RoutingSettings routing{}; ///< Route pins (`BATCHLAS_<OP>_ROUTE`).
488 SelectionSettings selection{}; ///< Kernel and algorithm selection.
489 GeometrySettings geometry{}; ///< Launch geometry and tuning thresholds.
490 DiagnosticsSettings diagnostics{}; ///< Tracing, dumping, profiling, opt-in checks.
491 UnsafeSettings unsafe{}; ///< Overrides that remove a guarantee.
492};
493
494/// @brief The process-wide settings.
495///
496/// The environment is read once, under `std::call_once`, on the first call. Thread-safe, and
497/// safe to call from a static initialiser.
498/// @return a reference valid for the life of the process. Its contents change under configure()
499/// and detail::reload_settings(), so do not cache fields across a call that could do
500/// either, and never hoist a field into a function-local static.
501/// @ingroup api_config
502BATCHLAS_API const Settings& settings();
503
504/// @brief Install `s` as the settings, for an embedding application that wants to stop
505/// inheriting ambient process state.
506///
507/// What is installed is the base, not a lock: a later detail::reload_settings() (every
508/// ScopedEnvVar triggers one) re-reads the environment on top of it, so a knob set here and not
509/// exported holds for the life of the process, and a knob something explicitly exports still
510/// wins. The unsafe group is not gated here.
511/// @param s the complete settings to install
512/// @pre No batchlas::Queue has been constructed yet in this process.
513/// @throws batchlas::api_misuse (a `std::runtime_error`) if a Queue already exists; nothing is
514/// changed.
515/// @ingroup api_config
516// evidence: docs/design/environment.md#environment-configure-sets-the-base-not-a-lock
517BATCHLAS_API void configure(const Settings& s);
518
519namespace detail {
520
521/// @brief Re-read the environment on top of the last configure() (or the defaults).
522///
523/// ScopedEnvVar calls this from its constructor and destructor, which is how a test's pinned
524/// knob takes effect and then stops leaking into later tests.
525/// @warning A raw `::setenv` does not reach it. A reload between a `*_buffer_size()` query and
526/// its solve can under-size the workspace. Not thread-safe with respect to concurrent
527/// settings() readers: call it from a test body or benchmark setup only.
528/// @ingroup api_config
529// evidence: docs/design/environment.md#environment-what-a-settings-reload-does-not-cover
530BATCHLAS_API void reload_settings();
531
532/// @brief Latch recording that a Queue exists, which closes configure(). Called only by Queue's
533/// constructors.
534/// @ingroup api_config_lowlevel
535BATCHLAS_API void note_queue_constructed() noexcept;
536
537/// @brief True once note_queue_constructed() has been called.
538/// @ingroup api_config_lowlevel
539BATCHLAS_API bool queue_constructed() noexcept;
540
541} // namespace detail
542
543} // namespace batchlas
A raw captured environment value, shaped like the std::getenv call it replaces.
Definition settings.hh:35
const char * get() const noexcept
The value, or nullptr when unset: the drop-in for std::getenv("...").
Definition settings.hh:64
static EnvValue unset()
An unset value.
Definition settings.hh:50
EnvValue(const char *raw)
Construct from what std::getenv returned.
Definition settings.hh:42
bool is_set() const noexcept
True when the variable was set, including set to the empty string.
Definition settings.hh:61
EnvValue()=default
An unset value.
const std::string & value() const noexcept
The value as text; empty when unset.
Definition settings.hh:67
static EnvValue of(std::string v)
A value that is set to v (which may be empty).
Definition settings.hh:53
bool queue_constructed() noexcept
True once note_queue_constructed() has been called.
void note_queue_constructed() noexcept
Latch recording that a Queue exists, which closes configure().
void configure(const Settings &s)
Install s as the settings, for an embedding application that wants to stop inheriting ambient process...
const Settings & settings()
The process-wide settings.
void reload_settings()
Re-read the environment on top of the last configure() (or the defaults).
The BATCHLAS_DUMP_BANDR1_* band-reduction dump family.
Definition settings.hh:426
int sweep_index
BATCHLAS_DUMP_BANDR1_SWEEP_INDEX
Definition settings.hh:438
std::string dir
BATCHLAS_DUMP_BANDR1_DIR: created with create_directories(); files are written under it while step is...
Definition settings.hh:429
int batch
BATCHLAS_DUMP_BANDR1_BATCH; -1 dumps every item
Definition settings.hh:440
bool abw_only
BATCHLAS_DUMP_BANDR1_ABW_ONLY (env_truthy): suppress every dump except ABw.
Definition settings.hh:435
int step_index
BATCHLAS_DUMP_BANDR1_STEP_INDEX
Definition settings.hh:437
int step_in_sweep
BATCHLAS_DUMP_BANDR1_STEP_IN_SWEEP
Definition settings.hh:439
bool step
BATCHLAS_DUMP_BANDR1_STEP (env_truthy): the master enable.
Definition settings.hh:432
Tracing, dumping, profiling and the opt-in checks.
Definition settings.hh:375
bool debug_filter_degree
BATCHLAS_DEBUG_FILTER_DEGREE: presence only, so any value including the empty string enables it.
Definition settings.hh:401
bool profiling
BATCHLAS_QUEUE_PROFILING or BATCHLAS_BENCH_PROFILING (env_truthy, ORed): enable SYCL queue profiling.
Definition settings.hh:378
bool syevx_trace
BATCHLAS_SYEVX_TRACE (env_truthy).
Definition settings.hh:411
bool cta_debug_sync
BATCHLAS_CTA_DEBUG_SYNC (env_truthy): prints [cta-debug] <stage> and drains the pipeline at each stag...
Definition settings.hh:416
bool metal_flush_each_op
BATCHLAS_METAL_FLUSH_EACH_OP (env_truthy): Metal queues created afterwards commit one command buffer ...
Definition settings.hh:386
bool gesvd_profile
BATCHLAS_GESVD_PROFILE (env_truthy): forces a wait_and_throw() per stage, serialising the pipeline,...
Definition settings.hh:408
EnvValue coverage_out
BATCHLAS_COVERAGE_OUT: dispatch coverage is written to <value>.<pid> at exit.
Definition settings.hh:393
bool select_trace
BATCHLAS_SELECT_TRACE (env_truthy): one stderr line per select::choose decision (src/select/select....
Definition settings.hh:397
bool debug_sytrd_small
BATCHLAS_DEBUG_SYTRD_SMALL (env_truthy). Prints once.
Definition settings.hh:404
struct batchlas::DiagnosticsSettings::DumpBandR1Settings dump_bandr1
The band-reduction dump family.
bool kernel_trace
BATCHLAS_KERNEL_TRACE or BATCHLAS_TRACE_KERNELS (env_truthy, ORed).
Definition settings.hh:381
EnvValue steqr_cta_check
BATCHLAS_STEQR_CTA_CHECK (first character {1,t,T,y,Y}): steqr_cta scans its per-item status and throw...
Definition settings.hh:422
std::string kernel_trace_path
The first non-empty of BATCHLAS_KERNEL_TRACE_PATH and BATCHLAS_TRACE_PATH.
Definition settings.hh:390
The runtime overrides of include/batchlas/tuning_params.hh (BATCHLAS_TUNE_*).
Definition settings.hh:348
EnvValue stedc_merge_variant
BATCHLAS_TUNE_STEDC_MERGE_VARIANT: a StedcMergeVariant value; 0 (Auto) is unreachable.
Definition settings.hh:361
EnvValue stedc_wg_multiplier
BATCHLAS_TUNE_STEDC_WG_MULTIPLIER
Definition settings.hh:364
EnvValue stedc_recursion_threshold
BATCHLAS_TUNE_STEDC_RECURSION_THRESHOLD
Definition settings.hh:356
EnvValue gebrd_block_size
BATCHLAS_TUNE_GEBRD_BLOCK_SIZE
Definition settings.hh:350
EnvValue sb2st_back_tile
BATCHLAS_TUNE_SB2ST_BACK_TILE
Definition settings.hh:351
EnvValue sytrd_block_size
BATCHLAS_TUNE_SYTRD_BLOCK_SIZE
Definition settings.hh:354
EnvValue sb2st_back_subs
BATCHLAS_TUNE_SB2ST_BACK_SUBS
Definition settings.hh:352
EnvValue stedc_threads_per_root
BATCHLAS_TUNE_STEDC_THREADS_PER_ROOT
Definition settings.hh:363
EnvValue latrd_wg_hint
BATCHLAS_TUNE_LATRD_WG_HINT
Definition settings.hh:355
EnvValue ormqr_block_size
BATCHLAS_TUNE_ORMQR_BLOCK_SIZE
Definition settings.hh:349
EnvValue sy2sb_ormqr_nb
BATCHLAS_TUNE_SY2SB_ORMQR_NB
Definition settings.hh:353
Launch geometry, block widths, iteration counts and tuning thresholds.
Definition settings.hh:248
int latrd_lower_panel_wg_hint
BATCHLAS_LATRD_LOWER_PANEL_WG_HINT.
Definition settings.hh:266
int syevx_check_every
BATCHLAS_SYEVX_CHECK_EVERY: iterations between convergence checks; each check is a full pipeline drai...
Definition settings.hh:322
int potrf_nb
BATCHLAS_POTRF_NB.
Definition settings.hh:284
EnvValue sb2st_back_tile
BATCHLAS_SB2ST_BACK_TILE: tile of the tiled back-transform kernel (a different kernel from sb2st_back...
Definition settings.hh:280
double syevx_lock_factor
BATCHLAS_SYEVX_LOCK_FACTOR (atof, > 0 only): a column is masked once its residual is this multiple of...
Definition settings.hh:339
int potrf_w
BATCHLAS_POTRF_W. 0 = unset; the default is type-dependent (128/32/32/16).
Definition settings.hh:286
int syev_two_stage_sb2st_block
BATCHLAS_SYEV_TWO_STAGE_SB2ST_BLOCK (env_positive_int_or).
Definition settings.hh:294
int syevx_filter_degree
BATCHLAS_SYEVX_FILTER_DEGREE.
Definition settings.hh:330
EnvValue sy2sb_ormqr_nb
BATCHLAS_SY2SB_ORMQR_NB: unset, off or 0 (never hint), or a positive forced value (clamped to kd at t...
Definition settings.hh:299
int latrd_grid_wg
BATCHLAS_LATRD_GRID_WG (env_positive_int_or).
Definition settings.hh:261
int latrd_grid_groups
BATCHLAS_LATRD_GRID_GROUPS (env_positive_int_or).
Definition settings.hh:252
int syev_two_stage_kd
BATCHLAS_SYEV_TWO_STAGE_KD (env_positive_int_or): the band width, clamped to [1, n-1] at the call sit...
Definition settings.hh:290
int trsm_outer_nb
BATCHLAS_TRSM_OUTER_NB. 0 = unset: 128 for Side::Left, the CTA nb for Side::Right.
Definition settings.hh:309
int sb2st_back_tile_w
BATCHLAS_SB2ST_BACK_TILE_W (env_positive_int_or): column tile of the wave kernel.
Definition settings.hh:275
std::optional< int > syevx_init_power
BATCHLAS_SYEVX_INIT_POWER: 0 means "no power iterations"; nullopt means 4 unless SyevxParams supplied...
Definition settings.hh:334
int latrd_grid_min_n
BATCHLAS_LATRD_GRID_MIN_N (env_positive_int_or): the n at which the grid latrd path becomes eligible.
Definition settings.hh:257
EnvValue expand_max_bytes
BATCHLAS_EXPAND_MAX_BYTES (strtoull): only ever lowers the expansion ceiling, whose default is GLOBAL...
Definition settings.hh:313
int trmm_tile_m
BATCHLAS_TRMM_TILE_M. 0 = unset (a function of m); bucketed to 16, 32, 64 or 128.
Definition settings.hh:306
struct batchlas::GeometrySettings::TuneSettings tune
The eleven BATCHLAS_TUNE_* overrides.
EnvValue gesvd_blocked_gebrd_min
BATCHLAS_GESVD_BLOCKED_GEBRD_MIN (bare atoi, default 1).
Definition settings.hh:318
int sb2st_back_subs
BATCHLAS_SB2ST_BACK_SUBS (env_positive_int_or).
Definition settings.hh:271
std::optional< int > syevx_extra_directions
BATCHLAS_SYEVX_EXTRA_DIRECTIONS: 0 means "no guard block"; nullopt means the default max(2,...
Definition settings.hh:326
int sytrd_block_size
BATCHLAS_SYTRD_BLOCK_SIZE.
Definition settings.hh:303
The route pins: BATCHLAS_<OP>_ROUTE, one raw string per op that selects a kernel.
Definition settings.hh:82
std::array< EnvValue, ops.size()> values
BATCHLAS_<OP>_ROUTE, in ops order.
Definition settings.hh:89
EnvValue & route(std::string_view op)
Mutable access to the captured BATCHLAS_<OP>_ROUTE for op, as configure() needs.
Definition settings.hh:102
const EnvValue & route(std::string_view op) const
The captured BATCHLAS_<OP>_ROUTE for op.
Definition settings.hh:100
static constexpr std::array< std::string_view, 19 > ops
The ops that read a route variable, by their <op> spelling.
Definition settings.hh:84
static constexpr std::size_t index_of(std::string_view op)
Position of op in ops, or ops.size() when op reads no route variable.
Definition settings.hh:92
Which kernel or algorithm runs, for the knobs outside the route pins.
Definition settings.hh:119
EnvValue tuned_dir
BATCHLAS_TUNED_DIR: a directory of select tables (src/select/select.hh); a file there replaces the bu...
Definition settings.hh:237
EnvValue getrf_leaf
BATCHLAS_GETRF_LEAF = slm | reg (default: the register-resident panel leaf wherever the panel fits).
Definition settings.hh:142
EnvValue gemv_segt
BATCHLAS_GEMV_SEGT = off | auto | 2 | 4 | 8: segmented-tail width of the native gemv.
Definition settings.hh:132
EnvValue syevx_soft_lock
BATCHLAS_SYEVX_SOFT_LOCK.
Definition settings.hh:218
EnvValue syevx_projected_vendor
BATCHLAS_SYEVX_PROJECTED_VENDOR: same first-character dialect.
Definition settings.hh:212
EnvValue ormqr_wy
BATCHLAS_ORMQR_WY = gemm | trmm | measured: overrides the measured gate.
Definition settings.hh:170
std::optional< bool > sytrd_fuse_panel_update
BATCHLAS_SYTRD_FUSE_PANEL_UPDATE: forced on (env_truthy), forced off (env_falsy), or std::nullopt to ...
Definition settings.hh:226
EnvValue sytrd_impl
BATCHLAS_SYTRD_IMPL: only the exact value device has an effect.
Definition settings.hh:229
EnvValue sytrd_trailing_update
BATCHLAS_SYTRD_TRAILING_UPDATE = gemm | syr2k | her2k | rank2k, either case; syr2k and her2k select o...
Definition settings.hh:233
EnvValue sb2st_back_wave
BATCHLAS_SB2ST_BACK_WAVE: the wave-parallel back-transform is on unless disabled with one of 0,...
Definition settings.hh:180
EnvValue syev_two_stage_chase
BATCHLAS_SYEV_TWO_STAGE_CHASE: only the exact value givens has an effect.
Definition settings.hh:189
bool sytrd_force_local_small
BATCHLAS_SYTRD_FORCE_LOCAL_SMALL (env_truthy): forces the local-memory small-n path past the tuning h...
Definition settings.hh:222
EnvValue ormqr_impl
BATCHLAS_ORMQR_IMPL: only the exact value device has an effect.
Definition settings.hh:167
EnvValue getrs_laswp
BATCHLAS_GETRS_LASWP = walk | gather. Deliberately not latched (as gemv_segt).
Definition settings.hh:157
EnvValue syevx_algorithm
BATCHLAS_SYEVX_ALGORITHM: overrides an explicit SyevxParams::method.
Definition settings.hh:194
EnvValue expand_route
BATCHLAS_EXPAND_ROUTE = expand | loop: pins the scratch-expansion route of hemm, herk and her2k,...
Definition settings.hh:126
EnvValue ortho_gram
BATCHLAS_ORTHO_GRAM: only the exact value gemm has an effect (forces the GEMM gram route in place of ...
Definition settings.hh:174
EnvValue getrf_laswp
BATCHLAS_GETRF_LASWP = inloop | defer_walk | defer_gather (default).
Definition settings.hh:151
EnvValue getrf_right_laswp
BATCHLAS_GETRF_RIGHT_LASWP = walk | gather; unset takes the measured crossover.
Definition settings.hh:154
EnvValue geqrf_leaf
BATCHLAS_GEQRF_LEAF = auto (default) | reg (the register panel leaf wherever it fits).
Definition settings.hh:147
EnvValue syevx_preconditioner
BATCHLAS_SYEVX_PRECONDITIONER: overrides the SyevxParams default; loses to an explicit request and to...
Definition settings.hh:198
EnvValue syevx_filter_degree_auto
BATCHLAS_SYEVX_FILTER_DEGREE_AUTO: derive the Chebyshev filter degree automatically.
Definition settings.hh:203
EnvValue gesvd_bidiag
BATCHLAS_GESVD_BIDIAG = bdsdc | normal | bdsqr.
Definition settings.hh:138
EnvValue syevx_instr_host
BATCHLAS_SYEVX_INSTR_HOST: forces the host instrumentation path.
Definition settings.hh:207
EnvValue iluk_device
BATCHLAS_ILUK_DEVICE: only a first character of 0 or 1 is inspected; true, on and yes fall through to...
Definition settings.hh:161
EnvValue sb2st_subgroup
BATCHLAS_SB2ST_SUBGROUP = auto | on | off (case-folded).
Definition settings.hh:184
EnvValue latrd_impl
BATCHLAS_LATRD_IMPL = legacy | device | grid. Re-read per call.
Definition settings.hh:164
Everything BatchLAS reads from its environment, in one value.
Definition settings.hh:486
DiagnosticsSettings diagnostics
Tracing, dumping, profiling, opt-in checks.
Definition settings.hh:490
UnsafeSettings unsafe
Overrides that remove a guarantee.
Definition settings.hh:491
SelectionSettings selection
Kernel and algorithm selection.
Definition settings.hh:488
GeometrySettings geometry
Launch geometry and tuning thresholds.
Definition settings.hh:489
RoutingSettings routing
Route pins (BATCHLAS_<OP>_ROUTE).
Definition settings.hh:487
The overrides that remove a guarantee: setting one can make a correct program crash,...
Definition settings.hh:452
BlasHealth blas_health
BATCHLAS_BLAS_HEALTH = off | warn | error.
Definition settings.hh:474
bool skip_pointer_checks
BATCHLAS_SKIP_POINTER_CHECKS: disables the per-argument USM reachability check that turns host memory...
Definition settings.hh:459
bool latrd_grid_force_unsafe
BATCHLAS_LATRD_GRID_FORCE_UNSAFE (env_truthy): lets BATCHLAS_LATRD_GRID_GROUPS exceed the co-residenc...
Definition settings.hh:465
BlasHealth
Behaviour of the host-dgemm health probe (BATCHLAS_BLAS_HEALTH).
Definition settings.hh:468
@ Warn
warn (default): warn when the probe fails.
Definition settings.hh:470