Files
Strata/include/strata/core/arch_defaults.hpp
T
Niko1221 27cf035e5c Merge f-amd-f16 8d7f997d4 into f-p4-int (the Radeon 780M on Linux reads its 16-bit prompt GEMMs FP16 in and out by default; the hyper-connection up-mix kernel has an FP16 path)
Three commits on 662e72ac2. With STRATA_HIP_PROMPT_F16=1 the fused hyper-connection up-mix (STRATA_HC_UPMIX, on by default on the 780M under Linux and in the Windows Strix Halo set) read the
FP16 activation images as BF16: forced-token KL 166 times that of the MMQ path, top-1 68.7%. The up-mix kernel now has an FP16 variant (new test hip_gr_upmix_parity: 20 BF16 and 6 FP16-io
sizes up to 8,192 tokens, error against FP64 1.6e-7 to 3.6e-7 of the largest value for the fused kernel, 6.2e-5 to 1.2e-4 for the FP16 pair), and a Radeon 780M (gfx1103, integrated, Linux)
now runs the prompt's 16-bit GEMMs FP16 in and out with nothing set. STRATA_HIP_PROMPT_F16=0 is the way back; =1 still works on any card. Every other chip, every discrete card and
Windows are unchanged, and nothing is printed for the default.

Measured on a Radeon 780M (Q2_0, 24 prompts of 2K tokens, 64 forced tokens each, the draft-cost table fixed): forced-token KL against the FP16 path, ratio to the MMQ path 1.091 [0.968, 1.231]
with FP16 io, top-1 97.5%; prompt speed ratio to nothing set 1.11 / 1.15 / 1.19 / 1.25 at 300 / 1,000 / 2,048 / 8,192 tokens (with the fused prompt kernels on top: 1.11 / 1.15 / 1.63 / 1.45).

The branch changes include/strata/core/arch_defaults.hpp and src/core/arch_defaults_test.cpp, which the earlier fused-default merge also changed at the same place; both sides are kept (the
fused-default declaration and test block first, the FP16-io ones after). The settings register is regenerated by its tool on the merged tree, with the hand-kept status (default) and note
of STRATA_HIP_PROMPT_F16 from the branch.
2026-11-13 00:08:40 +01:00

147 lines
14 KiB
C++

// include/strata/core/arch_defaults.hpp - the per-architecture defaults of switches that are exact everywhere.
//
// Every gfx1151 (Strix Halo, RDNA3.5, unified memory) switch in the table was measured on Aurora (experiments/s23 .. s26,
// the c-best3-v4.2 config) with BYTE-IDENTICAL output against the same engine with the switch off: the same token ids at
// 4K / 32K / 64K and on four models, and a bitwise harness per kernel. They are therefore on by default on that
// architecture and nowhere else: a CUDA build and every other HIP architecture run the code they always ran.
// Switches that change bits (STRATA_PF_GEMM, STRATA_PF_FUSED, STRATA_HC_UPMIX, STRATA_PA_FAST, STRATA_HIP_WMMA,
// STRATA_SELECT_WMMA, STRATA_HC_Q8: rounding-level, KL-gated) stay opt-in in THIS table; docs/STRIX_HALO.md lists them. Five of them
// (HIP_WMMA, PF_GEMM, PA_FAST, SELECT_WMMA, HC_UPMIX) are an opt-in set on an integrated Radeon (igpu_default_env() below).
//
// A switch the user set (to anything) is never overridden; STRATA_GFX1151_DEFAULTS=0 turns the whole table off.
#pragma once
#include "strata/kernels/gfx_arch.hpp"
#include <string>
#include <utility>
#include <vector>
namespace strata::core {
/// The environment settings that are the defaults of `gcn_arch` (hipDeviceProp_t::gcnArchName; "gfx1151" or
/// "gfx1151:sramecc-:xnack-"): empty for every other architecture. `defaults026` (STRATA_DEFAULTS=026, defaults_026.hpp): the gfx12 table of
/// v0.2.6 (the five prompt switches only, without the four 0.2.7 decode switches); the one-argument form asks the environment.
std::vector<std::pair<std::string, std::string>> arch_default_env(const char* gcn_arch, bool defaults026);
/// The same with the platform given instead of read from the build (a pure rule, so a test can check both). 0.2.7: on Windows the gfx1151
/// table leaves STRATA_SH_STREAM out (the fork is off, +6.9% decode on a Strix Halo Windows PC, same ids); Linux gfx1151 and every
/// other architecture are unchanged; `defaults026` keeps it in on both. An explicit STRATA_SH_STREAM=1 turns the fork on anywhere.
std::vector<std::pair<std::string, std::string>> arch_default_env(const char* gcn_arch, bool defaults026, bool windows);
std::vector<std::pair<std::string, std::string>> arch_default_env(const char* gcn_arch);
/// AMD-Q (owner decision 10-31): the CPU prefill share (prefill.cpp, STRATA_PREFILL_CPU_SHARE) is armed by default for single-card serve on gfx12
/// (R9700 / RX 9070 / RX 9060, gfx1200 / gfx1201), with the CUDA change's limit (share_rules::default_share_limit: staged chunks up to 3,072 tokens).
/// Measured on an R9700 (p620, IQ3_S, 13,325 of 24,576 experts resident, 30 pool workers): prompt 500 +18.3%, 1K +30.6%, 2K -0.19%, 4K and 8K unchanged;
/// first-token KL 0.022 at 1K, top-1 29 of 29. Pure architecture rule: false for gfx11 (Strix Halo gfx1151, 780M gfx1103, RX 7000), every other
/// family and a CUDA build; STRATA_GFX12_DEFAULTS=0 and STRATA_DEFAULTS=026 (`defaults026`) turn it off, and STRATA_PREFILL_CPU_SHARE=0 / auto /
/// a number still decide before it. The caller adds the single-card, no-batch-slot and "experts are missing" conditions.
bool gfx12_prefill_share_default(const char* gcn_arch, bool defaults026);
bool gfx12_prefill_share_default(const char* gcn_arch);
/// The integrated Radeons (Phoenix / Hawk Point 780M gfx1103, Strix Point 890M / 880M gfx1150, Strix Halo gfx1151) whose
/// matrix-core prompt set is offered (opt-in; 021-minipc). Pure architecture-name test; the caller adds the UMA test.
bool igpu_prompt_defaults_arch(const char* gcn_arch);
/// 021-minipc: the matrix-core prompt set changes bits. The owner approved it as the DEFAULT of the Radeon 780M only (gfx1103,
/// integrated, Linux): prompts 1.60x (1K) / 2.03x (4K), decode within 0.1%, greedy ids identical in 6 of 6 pairs (notes-021-minipc.md).
/// gfx1150 / gfx1151 (no hardware) and Windows keep it off by default. STRATA_IGPU_PROMPT_SET=1 turns it on for any integrated
/// arch of igpu_prompt_defaults_arch, STRATA_IGPU_PROMPT_SET=0 (or STRATA_IGPU_DEFAULTS=0) turns it off.
inline constexpr bool kIgpuPromptSetDefaultOn = true;
bool igpu_prompt_set_enabled(const char* gcn_arch, bool windows);
/// 021-minipc: UMA mode (the expert arena stays unregistered). Exact (no bit changes) but NOT a default: measured on the 780M it was
/// 1-4% slower and did not stop the resets (4 of 20 runs against 1 of 10), so kIgpuUmaArenaDefaultOn is false. When true it applies
/// to the Radeon 780M only (gfx1103, integrated, Linux). EXCEPT a Strix Halo on Windows (gfx1151, integrated): there it is always on (0.2.1.2,
/// registering the arena used up all free VRAM and the engine did not start). STRATA_UMA_REGISTER=1
/// registers the arena as before; STRATA_ARENA_PIN_GIB=none selects UMA mode per run.
inline constexpr bool kIgpuUmaArenaDefaultOn = false;
bool igpu_uma_arena_default(const char* gcn_arch, bool integrated, bool windows, bool on = kIgpuUmaArenaDefaultOn);
/// the registered expert arena asks for no transparent huge pages on an integrated gfx11 GPU under Linux (gfx1103 Radeon
/// 780M, gfx1150 880M / 890M, gfx1151 Strix Halo; detected from the device: `integrated` and the arch name). MADV_HUGEPAGE on a registered
/// range adds direct compaction and khugepaged collapse in it; each move invalidates the range, KFD evicts the process's queues, and the
/// gc 11 MES firmware resets the GPU when a dispatch sits in a barrier (notes-minipc.md). Radeon 780M, Q2_0 pack, registered 31.6 GiB arena,
/// one engine at a time: huge pages requested 9 starts, 8 ended in "unspecified launch failure" in the first prompt; not requested 3 of 3 ran.
/// Setup already wrote STRATA_NO_ARENA_THP=1 for its 780M opt-in; this makes it the engine's own rule.
/// STRATA_NO_ARENA_THP=0 asks for them (unset = this rule; =1 = never, as before). Windows and discrete cards: unchanged.
bool igpu_arena_no_thp_default(const char* gcn_arch, bool integrated, bool windows);
/// the wait before READY (strata/core/kfd_settle.hpp) applies to the same class: an integrated gfx11 GPU under Linux (gfx1103,
/// gfx1150, gfx1151), where the registered expert arena is a KFD userptr and the kernel's page moves right after the load evict the
/// process's queues. Never Windows, never a discrete card. STRATA_NO_KFD_SETTLE=1 turns the wait off.
bool igpu_kfd_settle_default(const char* gcn_arch, bool integrated, bool windows);
/// the file-cache give-back during and after the expert load (strata/core/page_cache_drop.hpp) applies to the same class: an integrated
/// gfx11 GPU under Linux (gfx1103, gfx1150, gfx1151). Never Windows, never a discrete card. STRATA_NO_ARENA_CACHE_DROP=1 turns it off.
bool igpu_cache_drop_default(const char* gcn_arch, bool integrated, bool windows);
/// the prompt experts on Strata's own fused int8 kernels (STRATA_PF_FUSED=1) instead of llama.cpp's MMQ, for the same class: an integrated gfx11 GPU
/// under Linux (gfx1103, gfx1150, gfx1151). Never Windows (gfx1151 there has it in igpu_default_env), never a discrete card. apply_arch_defaults sets
/// STRATA_PF_FUSED=1 where the user has not set the variable; STRATA_PF_FUSED=0 is the way back to MMQ.
bool igpu_fused_prompt_default(const char* gcn_arch, bool integrated, bool windows);
/// The 16-bit prompt GEMMs FP16 in and out (STRATA_HIP_PROMPT_F16, gemm.cu prompt_f16()): `env` is the variable's text (nullptr = unset). "1" = on, any other set
/// value = off (as before); unset = the device rule: on for a Radeon 780M (gfx1103, integrated, Linux), off everywhere else (every other gfx11, gfx12, gfx103x,
/// Windows and discrete cards are unchanged). Inline: src/prefill/gemm.cu uses it without linking arch_defaults.cpp.
inline bool prompt_f16_resolve(const char* env, const char* gcn_arch, bool integrated, bool windows) {
if (env != nullptr) return env[0] == '1';
return integrated && !windows && strata::kernels::gfx_arch_is(gcn_arch, "gfx1103");
}
/// Whether the expert arena skips its MADV_HUGEPAGE request: `no_arena_thp` is STRATA_NO_ARENA_THP (nullptr when unset): "0" asks for the huge
/// pages, any other value skips the request; unset leaves it to `igpu_rule` (igpu_arena_no_thp_default for this device). `thp_always`: the
/// kernel's THP mode is "always" (the request would add nothing, #771). Inline: src/core/pinned.cu (strata_core) uses it without
/// linking arch_defaults.cpp.
inline bool arena_skip_thp_request(const char* no_arena_thp, bool thp_always, bool igpu_rule) {
if (no_arena_thp != nullptr) return no_arena_thp[0] != '0' || thp_always; // the user's own value: 0 = ask for them, else skip
return thp_always || igpu_rule;
}
/// The matrix-core prompt set an integrated GPU takes when `igpu_prompt_set_enabled()`: STRATA_HIP_WMMA, STRATA_PF_GEMM, STRATA_PA_FAST,
/// STRATA_SELECT_WMMA, STRATA_HC_UPMIX, all "1". Empty unless `integrated` (hipDeviceProp_t::integrated: the device
/// shares the host's memory) AND the architecture is one of `igpu_prompt_defaults_arch`: a discrete card of the same
/// architecture family (RX 7900 XTX gfx1100, R9700 gfx1201, ...) and every CUDA / SYCL build get nothing. These change
/// bits (KL-gated, notes-153-igpu.md); every switch keeps =0 as its off switch and STRATA_IGPU_DEFAULTS=0 turns the set off.
std::vector<std::pair<std::string, std::string>> igpu_default_env(const char* gcn_arch, bool integrated);
/// 0.2.10 (STRIX-2Q): the exact parallel-request stack (checkpoint pool, device slot copies, one-launch slot windows) for a Windows
/// Strix Halo (gfx1151) that runs batch slots (`--batch` / `--slots` of 2 or more). Interleaved on the strix box (serve/server.py,
/// 4 clients, 3 rounds, IQ3_S): 51.7 / 50.7 tok/s without, 55.1 / 54.9 with, TTFT p50 2.55 -> 2.45 s, max chunk gap p95 1.36 -> 1.27 s,
/// no errors. Every switch is bit-exact against the plain slots (QUAL-PAR on the Linux CUDA stack). Not STRATA_BATCH_CONCURRENT_READ.
/// Empty for every other architecture / platform, below 2 slots, and with STRATA_GFX1151_DEFAULTS=0. A switch the user set is kept.
std::vector<std::pair<std::string, std::string>> parallel_default_env(const char* gcn_arch, bool windows, int batch_slots);
/// The same nine switches for Linux CUDA (the Qwen engine of generate.cpp) with 2 or more batch slots: what serve/server.py's
/// PARALLEL_STACK_ENV set for a managed start, now the engine's own so a plain start is the same. QUAL-PAR: bit-exact against the plain
/// slots (greedy identity at c=1, first-token KL 0). `linux_cuda` is false on HIP, Windows, Metal and SYCL builds (empty then). Each
/// switch keeps =0 as its off switch; a value the user set is kept. Silent: the launcher printed nothing for these either.
std::vector<std::pair<std::string, std::string>> parallel_default_env_cuda(bool linux_cuda, int batch_slots);
/// Sets `parallel_default_env_cuda` in this process's environment where the user has not set the variable; returns the names it set.
/// Call once, before any engine code reads its switches.
std::vector<std::string> apply_parallel_defaults_cuda(bool linux_cuda, int batch_slots);
/// The tensor-core GDN prompt scan and the one-pass conv (QUAL-GDN, l620: prompt +4.4% at 4K, +5.5% at 16K, +5.7% at 32K; first-token KL mean
/// 0.0019, max 0.0125; owner yes 2026-11-07): STRATA_GDN_TC=1 and STRATA_GDN_CONVL2=2 on Linux CUDA, what serve/server.py's GDN_STACK_CUDA set.
/// The engine still gates the scan at run time (compute capability 8 or more, one SM per value head, shared memory) and falls back to the old
/// kernels. Empty when `linux_cuda` is false (HIP, Windows, Metal, SYCL). =0 turns each off; a value the user set is kept. Silent.
std::vector<std::pair<std::string, std::string>> gdn_default_env_cuda(bool linux_cuda);
std::vector<std::string> apply_gdn_defaults_cuda(bool linux_cuda);
/// gfx12 (RDNA4, R9700 / RX 9000) on Linux, when EVERY visible card is gfx12 (the same rule as serve/server.py's GDN_STACK_GFX12): the chunked GDN scan
/// from the first 64-token chunk instead of from 30,000 tokens (owner yes 2026-11-07). R9700: +3.5% prompt speed at 4K, +5.5% at 16K, first-token KL mean
/// 0.0025, 61-task suite 55 vs 56. STRATA_GDN_CHUNKED=0 turns it off; a value the user set is kept. Empty elsewhere. Silent: the engine's own
/// "prompt chunks of 30,000+ tokens" line is not printed when the variable is set, as with a launcher start.
std::vector<std::pair<std::string, std::string>> gdn_chunked_default_env(bool linux_host, bool all_gfx12);
std::vector<std::string> apply_gdn_chunked_default(bool linux_host, bool all_gfx12);
/// 0.2.10 (STRIX-TDR): a Windows Strix Halo (gfx1151) launches the verify window's graph from a helper thread, so the main thread can
/// serve the GPU's doorbells while the launch call is still running. On the strix box the launch call of the first window sometimes never
/// returned (host in the driver, GPU already past layer 0, "GPU rang 1, flags served 0": the Q4_K_XL start stall); the helper thread
/// removed it (see STRIX-2Q-RESULTS.md). The value is STRATA_VERIFY_ASYNC_LAUNCH=1 (same switch as the CUDA instrumented-launch path).
/// Empty for every other architecture / platform and with STRATA_GFX1151_DEFAULTS=0. A switch the user set is kept.
std::vector<std::pair<std::string, std::string>> launch_default_env(const char* gcn_arch, bool windows);
/// Sets `arch_default_env(gcn_arch)` and, when `integrated`, `igpu_default_env(gcn_arch, true)` in this process's
/// environment where the user has not set the variable, prints one line to stderr per table when it set anything, and
/// returns the names it set. `integrated` is true when every visible GPU is an integrated one. Call once, before any
/// engine code reads its switches (they are read lazily, at first use).
std::vector<std::string> apply_arch_defaults(const char* gcn_arch, bool integrated = false, int batch_slots = 0);
} // namespace strata::core