diff --git a/CMakeLists.txt b/CMakeLists.txt index adb613c45c..7c4bf753c9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -439,6 +439,11 @@ if(STRATA_BUILD_TESTS) target_include_directories(fp16_rows_rule_test PRIVATE include) add_test(NAME fp16_rows_rule_test COMMAND fp16_rows_rule_test) + # STRATA_SWITCH_POINT (on by default for NVIDIA sm_86, one GPU): the floor from the card's share of non-resident experts, a cost estimate of the staged and the streamed walk (header-only, no GPU) + add_executable(switch_point_rule_test tests/prefill/switch_point_rule_test.cpp) + target_include_directories(switch_point_rule_test PRIVATE include) + add_test(NAME switch_point_rule_test COMMAND switch_point_rule_test) + # whether the CUDA fused prompt kernels take the Gyro trellis experts by default (STRATA_PF_FUSED_TQ unset: the sm_86 cards with 80+ SMs; =1 any card; =0 off): the pure # rule, pinned for every card class (header-only, no GPU) add_executable(fused_tq_default_test tests/prefill/fused_tq_default_test.cpp) diff --git a/data/settings-register.json b/data/settings-register.json index e8d12dbd28..be83a7181a 100644 --- a/data/settings-register.json +++ b/data/settings-register.json @@ -169,7 +169,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 13967, + "line": 13977, "backend": "cuda-hip", "fn": "a_env" } @@ -202,7 +202,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 13966, + "line": 13976, "backend": "cuda-hip", "fn": "a_env" } @@ -271,13 +271,13 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 13630, + "line": 13640, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 21331, + "line": 21374, "backend": "cuda-hip", "fn": "getenv" } @@ -378,13 +378,13 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 13457, + "line": 13467, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 21320, + "line": 21363, "backend": "cuda-hip", "fn": "getenv" } @@ -419,13 +419,13 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 13456, + "line": 13466, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 21319, + "line": 21362, "backend": "cuda-hip", "fn": "getenv" } @@ -460,7 +460,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 21321, + "line": 21364, "backend": "cuda-hip", "fn": "getenv" } @@ -658,7 +658,7 @@ }, { "file": "src/program/generate.cpp", - "line": 13555, + "line": 13565, "backend": "cuda-hip", "fn": "getenv" } @@ -697,13 +697,13 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 13505, + "line": 13515, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 13506, + "line": 13516, "backend": "cuda-hip", "fn": "getenv" } @@ -736,7 +736,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 13800, + "line": 13810, "backend": "cuda-hip", "fn": "getenv" } @@ -769,7 +769,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 13965, + "line": 13975, "backend": "cuda-hip", "fn": "a_env" } @@ -802,7 +802,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 13521, + "line": 13531, "backend": "cuda-hip", "fn": "getenv" } @@ -1910,7 +1910,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 902, + "line": 956, "backend": "cuda-hip", "fn": "getenv" } @@ -2046,7 +2046,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 18016, + "line": 18057, "backend": "cuda-hip", "fn": "getenv" } @@ -2080,7 +2080,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 17860, + "line": 17901, "backend": "cuda-hip", "fn": "getenv" }, @@ -2159,7 +2159,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 14917, + "line": 14927, "backend": "cuda-hip", "fn": "getenv" } @@ -2192,7 +2192,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 14919, + "line": 14929, "backend": "cuda-hip", "fn": "getenv" } @@ -2225,7 +2225,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 14918, + "line": 14928, "backend": "cuda-hip", "fn": "getenv" } @@ -2552,7 +2552,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 14938, + "line": 14948, "backend": "cuda-hip", "fn": "getenv" } @@ -2604,7 +2604,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 18080, + "line": 18121, "backend": "cuda-hip", "fn": "getenv" } @@ -2791,7 +2791,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 18621, + "line": 18662, "backend": "cuda-hip", "fn": "getenv" }, @@ -3064,13 +3064,13 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 17333, + "line": 17343, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 17466, + "line": 17476, "backend": "cuda-hip", "fn": "getenv" }, @@ -3206,7 +3206,7 @@ }, { "file": "src/program/generate.cpp", - "line": 20696, + "line": 20737, "backend": "cuda-hip", "fn": "getenv" } @@ -3242,7 +3242,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 3280, + "line": 3368, "backend": "cuda-hip", "fn": "getenv" } @@ -3602,7 +3602,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 755, + "line": 809, "backend": "cuda-hip", "fn": "getenv" }, @@ -3666,7 +3666,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 6554, + "line": 6650, "backend": "cuda-hip", "fn": "getenv" }, @@ -3705,7 +3705,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 5225, + "line": 5321, "backend": "cuda-hip", "fn": "getenv" } @@ -3771,13 +3771,13 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 4881, + "line": 4977, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/prefill/prefill.cpp", - "line": 7027, + "line": 7123, "backend": "cuda-hip", "fn": "getenv" } @@ -3810,7 +3810,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 4887, + "line": 4983, "backend": "cuda-hip", "fn": "getenv" } @@ -3844,7 +3844,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 5006, + "line": 5102, "backend": "cuda-hip", "fn": "getenv" }, @@ -3938,19 +3938,19 @@ }, { "file": "src/prefill/prefill.cpp", - "line": 5586, + "line": 5682, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/prefill/prefill.cpp", - "line": 6507, + "line": 6603, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/prefill/prefill.cpp", - "line": 6731, + "line": 6827, "backend": "cuda-hip", "fn": "getenv" }, @@ -4010,19 +4010,19 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 4882, + "line": 4978, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/prefill/prefill.cpp", - "line": 4897, + "line": 4993, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/prefill/prefill.cpp", - "line": 7027, + "line": 7123, "backend": "cuda-hip", "fn": "getenv" } @@ -4047,6 +4047,39 @@ "retire_after": "", "retired_in": "" }, + { + "name": "STRATA_DBG_TAIL_NOREUSE", + "backends": [ + "cuda-hip" + ], + "reads": [ + { + "file": "src/program/generate.cpp", + "line": 10174, + "backend": "cuda-hip", + "fn": "getenv" + } + ], + "parse": "flag", + "default_state": "off", + "code_default": null, + "engine_sets": [], + "engine_defaults": [], + "launch_files": [], + "launch_sets": [], + "launch_reads": [], + "doc_mentions": [], + "first_commit": "dd404b382e", + "first_date": "2026-11-13", + "since": null, + "last_commit": "dd404b382e", + "last_date": "2026-11-13", + "status": "research", + "owner": "program", + "note": "[reviewed] a test of the backstop: a loan is reused by chunk alone, so a later short segment overruns the lent tail and Prefill::run_impl's chunk check ends the request with its error.", + "retire_after": "", + "retired_in": "" + }, { "name": "STRATA_DECODE_TIMING", "backends": [ @@ -4056,7 +4089,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 18868, + "line": 18909, "backend": "cuda-hip", "fn": "getenv" }, @@ -4626,13 +4659,13 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 20053, + "line": 20094, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 20053, + "line": 20094, "backend": "cuda-hip", "fn": "getenv" } @@ -5554,7 +5587,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 21683, + "line": 21726, "backend": "cuda-hip", "fn": "getenv" } @@ -6036,13 +6069,13 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 14681, + "line": 14691, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 14681, + "line": 14691, "backend": "cuda-hip", "fn": "getenv" } @@ -6075,7 +6108,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 14680, + "line": 14690, "backend": "cuda-hip", "fn": "getenv" } @@ -6115,7 +6148,7 @@ }, { "file": "src/prefill/prefill.cpp", - "line": 2560, + "line": 2627, "backend": "cuda-hip", "fn": "getenv" }, @@ -6188,13 +6221,13 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 19925, + "line": 19966, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 21900, + "line": 21943, "backend": "cuda-hip", "fn": "getenv" }, @@ -6235,7 +6268,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 5383, + "line": 5479, "backend": "cuda-hip", "fn": "getenv" } @@ -6271,13 +6304,13 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 5385, + "line": 5481, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/prefill/prefill.cpp", - "line": 5385, + "line": 5481, "backend": "cuda-hip", "fn": "getenv" } @@ -6451,7 +6484,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 554, + "line": 608, "backend": "cuda-hip", "fn": "getenv" } @@ -7376,13 +7409,13 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 2226, + "line": 2284, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/prefill/prefill.cpp", - "line": 6793, + "line": 6889, "backend": "cuda-hip", "fn": "getenv" } @@ -7758,7 +7791,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 18807, + "line": 18848, "backend": "cuda-hip", "fn": "getenv" }, @@ -7800,7 +7833,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 18822, + "line": 18863, "backend": "cuda-hip", "fn": "getenv" }, @@ -8095,7 +8128,7 @@ }, { "file": "src/program/generate.cpp", - "line": 18151, + "line": 18192, "backend": "cuda-hip", "fn": "env_on" } @@ -9834,7 +9867,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 583, + "line": 637, "backend": "hip", "fn": "getenv" } @@ -10160,7 +10193,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 2149, + "line": 2207, "backend": "cuda-hip", "fn": "getenv" }, @@ -10818,7 +10851,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 781, + "line": 835, "backend": "cuda-hip", "fn": "getenv" }, @@ -11216,7 +11249,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 633, + "line": 687, "backend": "cuda-hip", "fn": "getenv" } @@ -11251,7 +11284,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 650, + "line": 704, "backend": "cuda-hip", "fn": "getenv" } @@ -11285,7 +11318,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 737, + "line": 791, "backend": "cuda-hip", "fn": "getenv" }, @@ -11491,8 +11524,8 @@ "first_commit": "fe6c5260ec", "first_date": "2026-10-03", "since": "v0.1.40.1", - "last_commit": "567c46873f", - "last_date": "2026-11-07", + "last_commit": "0b3364d416", + "last_date": "2026-11-12", "status": "default", "owner": "core", "note": "on by default on CUDA when the GGUF carries the hyper-connection projections as Q8_0 (an Unsloth UD-* file; generate.cpp via NativeDense::gguf_carries_q8_hc; owner yes 2026-11-07); gfx12 and gfx1151 HIP keep their own rule; STRATA_HC_Q8=0 turns it off; the GSQ-RCO packs (BF16 projections) are unchanged", @@ -11564,8 +11597,8 @@ "first_commit": "58729711d9", "first_date": "2026-10-03", "since": "v0.1.40.1", - "last_commit": "23a38a0bb7", - "last_date": "2026-10-07", + "last_commit": "0b3364d416", + "last_date": "2026-11-12", "status": "research", "owner": "core", "note": "[auto] off unless set, not documented for users", @@ -11699,7 +11732,7 @@ }, { "file": "src/prefill/prefill.cpp", - "line": 710, + "line": 764, "backend": "cuda-hip", "fn": "getenv" }, @@ -11771,7 +11804,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 4420, + "line": 4516, "backend": "cuda-hip", "fn": "getenv" }, @@ -13017,7 +13050,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 4753, + "line": 4849, "backend": "cuda-hip", "fn": "getenv" }, @@ -13166,13 +13199,13 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 4618, + "line": 4714, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/prefill/prefill.cpp", - "line": 8159, + "line": 8255, "backend": "cuda-hip", "fn": "getenv" }, @@ -13805,7 +13838,7 @@ }, { "file": "src/program/generate.cpp", - "line": 20696, + "line": 20737, "backend": "cuda-hip", "fn": "getenv" } @@ -14432,7 +14465,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 11020, + "line": 11027, "backend": "cuda-hip", "fn": "getenv" } @@ -14796,7 +14829,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 4475, + "line": 4571, "backend": "cuda-hip", "fn": "getenv" } @@ -15224,7 +15257,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 10487, + "line": 10494, "backend": "cuda-hip", "fn": "getenv" }, @@ -15263,7 +15296,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 17307, + "line": 17317, "backend": "cuda-hip", "fn": "getenv" } @@ -15337,7 +15370,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 10485, + "line": 10492, "backend": "cuda-hip", "fn": "getenv" }, @@ -15377,13 +15410,13 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 4560, + "line": 4656, "backend": "hip", "fn": "getenv" }, { "file": "src/prefill/prefill.cpp", - "line": 8106, + "line": 8202, "backend": "hip", "fn": "getenv" }, @@ -15501,7 +15534,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 3590, + "line": 3678, "backend": "cuda-hip", "fn": "getenv" }, @@ -15622,7 +15655,7 @@ }, { "file": "src/program/generate.cpp", - "line": 12627, + "line": 12637, "backend": "cuda-hip", "fn": "getenv" }, @@ -15672,7 +15705,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 1464, + "line": 1519, "backend": "cuda-hip", "fn": "getenv" }, @@ -16057,7 +16090,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 6994, + "line": 7090, "backend": "hip", "fn": "getenv" } @@ -16090,7 +16123,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 7390, + "line": 7486, "backend": "cuda-hip", "fn": "getenv" } @@ -16168,19 +16201,19 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 17621, + "line": 17631, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 17661, + "line": 17671, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 18667, + "line": 18708, "backend": "cuda-hip", "fn": "getenv" }, @@ -16236,7 +16269,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 17665, + "line": 17675, "backend": "cuda-hip", "fn": "getenv" }, @@ -16441,13 +16474,13 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 18840, + "line": 18881, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 21797, + "line": 21840, "backend": "cuda-hip", "fn": "getenv" }, @@ -19058,7 +19091,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 8436, + "line": 8532, "backend": "cuda-hip", "fn": "getenv" } @@ -20321,7 +20354,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 2482, + "line": 2549, "backend": "cuda-hip", "fn": "getenv" }, @@ -20361,7 +20394,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 2526, + "line": 2593, "backend": "cuda-hip", "fn": "getenv" }, @@ -20401,7 +20434,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 2487, + "line": 2554, "backend": "cuda-hip", "fn": "getenv" }, @@ -20820,13 +20853,13 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 11518, + "line": 11528, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 11527, + "line": 11537, "backend": "cuda-hip", "fn": "getenv" } @@ -22926,18 +22959,6 @@ "backend": "cuda-hip", "fn": "getenv" }, - { - "file": "src/program/generate.cpp", - "line": 12562, - "backend": "cuda-hip", - "fn": "getenv" - }, - { - "file": "src/program/generate.cpp", - "line": 12566, - "backend": "cuda-hip", - "fn": "getenv" - }, { "file": "src/program/generate.cpp", "line": 12572, @@ -22946,7 +22967,19 @@ }, { "file": "src/program/generate.cpp", - "line": 12915, + "line": 12576, + "backend": "cuda-hip", + "fn": "getenv" + }, + { + "file": "src/program/generate.cpp", + "line": 12582, + "backend": "cuda-hip", + "fn": "getenv" + }, + { + "file": "src/program/generate.cpp", + "line": 12925, "backend": "cuda-hip", "fn": "getenv" } @@ -23646,7 +23679,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 13316, + "line": 13326, "backend": "cuda-hip", "fn": "getenv" } @@ -23828,7 +23861,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 18584, + "line": 18625, "backend": "cuda-hip", "fn": "getenv" }, @@ -23875,7 +23908,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 790, + "line": 844, "backend": "cuda-hip", "fn": "getenv" } @@ -23908,7 +23941,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 5054, + "line": 5150, "backend": "cuda-hip", "fn": "getenv" } @@ -23977,7 +24010,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 706, + "line": 760, "backend": "cuda-hip", "fn": "getenv" } @@ -24162,7 +24195,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 6096, + "line": 6192, "backend": "cuda-hip", "fn": "getenv" } @@ -24312,13 +24345,13 @@ }, { "file": "src/prefill/prefill.cpp", - "line": 284, + "line": 285, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 11297, + "line": 11307, "backend": "cuda-hip", "fn": "getenv" }, @@ -25103,7 +25136,7 @@ }, { "file": "src/prefill/prefill.cpp", - "line": 763, + "line": 817, "backend": "cuda-hip", "fn": "getenv" }, @@ -25180,7 +25213,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 1871, + "line": 1926, "backend": "cuda-hip", "fn": "getenv" } @@ -25213,7 +25246,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 1851, + "line": 1906, "backend": "cuda-hip", "fn": "getenv" } @@ -25282,7 +25315,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 729, + "line": 783, "backend": "cuda-hip", "fn": "getenv" }, @@ -25321,7 +25354,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 1887, + "line": 1942, "backend": "cuda-hip", "fn": "getenv" } @@ -25509,7 +25542,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 11736, + "line": 11746, "backend": "cuda-hip", "fn": "getenv" } @@ -25583,7 +25616,7 @@ }, { "file": "src/prefill/prefill.cpp", - "line": 763, + "line": 817, "backend": "cuda-hip", "fn": "getenv" }, @@ -25651,7 +25684,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 2864, + "line": 2931, "backend": "cuda-hip", "fn": "getenv" }, @@ -25690,7 +25723,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 451, + "line": 505, "backend": "cuda-hip", "fn": "getenv" } @@ -25723,7 +25756,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 2909, + "line": 2976, "backend": "cuda-hip", "fn": "getenv" } @@ -25756,7 +25789,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 2912, + "line": 2979, "backend": "cuda-hip", "fn": "getenv" } @@ -25789,7 +25822,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 2807, + "line": 2874, "backend": "cuda-hip", "fn": "getenv" } @@ -25823,7 +25856,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 2848, + "line": 2915, "backend": "cuda-hip", "fn": "getenv" }, @@ -25863,7 +25896,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 2882, + "line": 2949, "backend": "cuda-hip", "fn": "getenv" }, @@ -25903,7 +25936,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 2878, + "line": 2945, "backend": "cuda-hip", "fn": "getenv" }, @@ -25942,7 +25975,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 2905, + "line": 2972, "backend": "cuda-hip", "fn": "getenv" } @@ -25975,7 +26008,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 2833, + "line": 2900, "backend": "cuda-hip", "fn": "getenv" } @@ -26041,13 +26074,13 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 11291, + "line": 11301, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 11291, + "line": 11301, "backend": "cuda-hip", "fn": "getenv" } @@ -26080,7 +26113,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 11306, + "line": 11316, "backend": "cuda-hip", "fn": "getenv" } @@ -26113,7 +26146,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 384, + "line": 385, "backend": "cuda-hip", "fn": "getenv" } @@ -26149,7 +26182,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 4270, + "line": 4366, "backend": "cuda-hip", "fn": "getenv" }, @@ -26210,7 +26243,7 @@ }, { "file": "src/prefill/prefill.cpp", - "line": 701, + "line": 755, "backend": "cuda-hip", "fn": "getenv" }, @@ -26345,7 +26378,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 1663, + "line": 1718, "backend": "cuda-hip", "fn": "getenv" } @@ -26730,7 +26763,7 @@ }, { "file": "src/program/generate.cpp", - "line": 18142, + "line": 18183, "backend": "cuda-hip", "fn": "getenv" } @@ -26767,7 +26800,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 18168, + "line": 18209, "backend": "cuda-hip", "fn": "getenv" } @@ -26835,7 +26868,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 18188, + "line": 18229, "backend": "cuda-hip", "fn": "getenv" } @@ -26868,7 +26901,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 18406, + "line": 18447, "backend": "cuda-hip", "fn": "getenv" } @@ -26903,7 +26936,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 18410, + "line": 18451, "backend": "cuda-hip", "fn": "getenv" } @@ -26983,7 +27016,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 18402, + "line": 18443, "backend": "cuda-hip", "fn": "getenv" } @@ -27019,7 +27052,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 10718, + "line": 10725, "backend": "cuda-hip", "fn": "getenv" } @@ -27053,7 +27086,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 19182, + "line": 19223, "backend": "cuda-hip", "fn": "pipe_dbg_env" }, @@ -27210,7 +27243,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 19011, + "line": 19052, "backend": "cuda-hip", "fn": "pipe_dbg_env" }, @@ -27295,7 +27328,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 17490, + "line": 17500, "backend": "cuda-hip", "fn": "pipe_dbg_env" }, @@ -27335,7 +27368,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 18938, + "line": 18979, "backend": "cuda-hip", "fn": "pipe_dbg_env" }, @@ -27375,7 +27408,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 19131, + "line": 19172, "backend": "cuda-hip", "fn": "pipe_dbg_env" }, @@ -27415,7 +27448,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 19178, + "line": 19219, "backend": "cuda-hip", "fn": "pipe_dbg_env" }, @@ -27455,7 +27488,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 12347, + "line": 12357, "backend": "cuda-hip", "fn": "pipe_dbg_env" }, @@ -27494,7 +27527,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 19338, + "line": 19379, "backend": "cuda-hip", "fn": "pipe_dbg_env" } @@ -27528,7 +27561,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 17493, + "line": 17503, "backend": "cuda-hip", "fn": "pipe_dbg_env" }, @@ -27568,7 +27601,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 17486, + "line": 17496, "backend": "cuda-hip", "fn": "pipe_dbg_env" }, @@ -27608,7 +27641,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 18995, + "line": 19036, "backend": "cuda-hip", "fn": "pipe_dbg_env" }, @@ -27647,13 +27680,13 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 10736, + "line": 10743, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 15760, + "line": 15770, "backend": "cuda-hip", "fn": "getenv" } @@ -27850,7 +27883,7 @@ }, { "file": "src/prefill/prefill.cpp", - "line": 82, + "line": 83, "backend": "cuda-hip", "fn": "getenv" }, @@ -27955,7 +27988,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 244, + "line": 245, "backend": "cuda-hip", "fn": "getenv" } @@ -27990,7 +28023,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 250, + "line": 251, "backend": "cuda-hip", "fn": "getenv" } @@ -28418,7 +28451,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 617, + "line": 671, "backend": "cuda-hip", "fn": "getenv" }, @@ -28500,7 +28533,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 4075, + "line": 4171, "backend": "cuda-hip", "fn": "getenv" } @@ -28535,7 +28568,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 4079, + "line": 4175, "backend": "cuda-hip", "fn": "getenv" } @@ -28570,13 +28603,13 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 432, + "line": 486, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 11051, + "line": 11058, "backend": "cuda-hip", "fn": "getenv" } @@ -28617,13 +28650,13 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 11130, + "line": 11137, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 17880, + "line": 17921, "backend": "cuda-hip", "fn": "getenv" } @@ -28656,13 +28689,13 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 460, + "line": 514, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/prefill/prefill.cpp", - "line": 463, + "line": 517, "backend": "cuda-hip", "fn": "getenv" } @@ -28698,13 +28731,13 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 6673, + "line": 6769, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/prefill/prefill.cpp", - "line": 7918, + "line": 8014, "backend": "cuda-hip", "fn": "getenv" }, @@ -28744,13 +28777,13 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 6686, + "line": 6782, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/prefill/prefill.cpp", - "line": 7027, + "line": 7123, "backend": "cuda-hip", "fn": "getenv" }, @@ -28790,7 +28823,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 10179, + "line": 10186, "backend": "cuda-hip", "fn": "getenv" }, @@ -28868,13 +28901,13 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 292, + "line": 293, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/prefill/prefill.cpp", - "line": 5942, + "line": 6038, "backend": "cuda-hip", "fn": "getenv" }, @@ -28916,13 +28949,13 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 2658, + "line": 2725, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 18149, + "line": 18190, "backend": "cuda-hip", "fn": "env_on" }, @@ -28967,7 +29000,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 11084, + "line": 11091, "backend": "cuda-hip", "fn": "getenv" } @@ -29001,7 +29034,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 2670, + "line": 2737, "backend": "cuda-hip", "fn": "getenv" }, @@ -29042,7 +29075,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 10381, + "line": 10388, "backend": "cuda-hip", "fn": "getenv" } @@ -29080,7 +29113,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 4071, + "line": 4167, "backend": "cuda-hip", "fn": "getenv" }, @@ -29121,13 +29154,13 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 6907, + "line": 7003, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 11298, + "line": 11308, "backend": "cuda-hip", "fn": "getenv" } @@ -29136,14 +29169,6 @@ "default_state": null, "code_default": null, "engine_sets": [ - { - "file": "src/program/generate.cpp", - "line": 11309 - }, - { - "file": "src/program/generate.cpp", - "line": 11311 - }, { "file": "src/program/generate.cpp", "line": 11319 @@ -29151,6 +29176,14 @@ { "file": "src/program/generate.cpp", "line": 11321 + }, + { + "file": "src/program/generate.cpp", + "line": 11329 + }, + { + "file": "src/program/generate.cpp", + "line": 11331 } ], "engine_defaults": [], @@ -29192,7 +29225,7 @@ }, { "file": "src/program/generate.cpp", - "line": 10208, + "line": 10215, "backend": "cuda-hip", "fn": "getenv" }, @@ -29231,7 +29264,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 6918, + "line": 7014, "backend": "cuda-hip", "fn": "getenv" } @@ -29264,7 +29297,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 6913, + "line": 7009, "backend": "cuda-hip", "fn": "getenv" } @@ -29297,7 +29330,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 6939, + "line": 7035, "backend": "cuda-hip", "fn": "getenv" } @@ -29330,7 +29363,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 6928, + "line": 7024, "backend": "cuda-hip", "fn": "getenv" } @@ -29363,7 +29396,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 6923, + "line": 7019, "backend": "cuda-hip", "fn": "getenv" } @@ -29430,19 +29463,19 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 344, + "line": 345, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/prefill/prefill.cpp", - "line": 1718, + "line": 1773, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/prefill/prefill.cpp", - "line": 6096, + "line": 6192, "backend": "cuda-hip", "fn": "getenv" }, @@ -29563,7 +29596,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 3030, + "line": 3112, "backend": "cuda-hip", "fn": "getenv" } @@ -29598,7 +29631,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 10397, + "line": 10404, "backend": "cuda-hip", "fn": "getenv" } @@ -29632,7 +29665,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 568, + "line": 622, "backend": "cuda-hip", "fn": "getenv" }, @@ -29675,7 +29708,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 4090, + "line": 4186, "backend": "cuda-hip", "fn": "getenv" } @@ -29710,7 +29743,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 4091, + "line": 4187, "backend": "cuda-hip", "fn": "getenv" } @@ -29745,7 +29778,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 300, + "line": 301, "backend": "cuda-hip", "fn": "getenv" } @@ -29814,7 +29847,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 407, + "line": 461, "backend": "cuda-hip", "fn": "getenv" }, @@ -29884,6 +29917,39 @@ "retire_after": "", "retired_in": "" }, + { + "name": "STRATA_PREFILL_TAIL_LOAN", + "backends": [ + "cuda-hip" + ], + "reads": [ + { + "file": "src/program/generate.cpp", + "line": 10171, + "backend": "cuda-hip", + "fn": "getenv" + } + ], + "parse": "flag", + "default_state": null, + "code_default": null, + "engine_sets": [], + "engine_defaults": [], + "launch_files": [], + "launch_sets": [], + "launch_reads": [], + "doc_mentions": [], + "first_commit": "71f3c6db67", + "first_date": "2026-11-13", + "since": null, + "last_commit": "71f3c6db67", + "last_date": "2026-11-13", + "status": "rollback", + "owner": "program", + "note": "[reviewed] \"STRATA_PREFILL_TAIL_LOAN=0 keeps the stream floor's tail\"; the lent fused MoE buffers are sized for the segment's own short last chunk, not for stream floor - 1 tokens (default on; one GPU).", + "retire_after": "", + "retired_in": "" + }, { "name": "STRATA_PREFILL_TIMING", "backends": [ @@ -29893,13 +29959,13 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 3346, + "line": 3434, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/prefill/prefill.cpp", - "line": 3387, + "line": 3475, "backend": "cuda-hip", "fn": "getenv" }, @@ -29948,19 +30014,19 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 1953, + "line": 2011, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/prefill/prefill.cpp", - "line": 1967, + "line": 2025, "backend": "hip", "fn": "getenv" }, { "file": "src/prefill/prefill.cpp", - "line": 2132, + "line": 2190, "backend": "cuda-hip", "fn": "getenv" } @@ -30141,13 +30207,13 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 4829, + "line": 4925, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/prefill/prefill.cpp", - "line": 8190, + "line": 8286, "backend": "cuda-hip", "fn": "getenv" }, @@ -30349,7 +30415,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 11007, + "line": 11014, "backend": "cuda-hip", "fn": "getenv" } @@ -31866,7 +31932,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 4801, + "line": 4897, "backend": "cuda-hip", "fn": "getenv" }, @@ -31906,13 +31972,13 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 4802, + "line": 4898, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/prefill/prefill.cpp", - "line": 4803, + "line": 4899, "backend": "cuda-hip", "fn": "getenv" }, @@ -31957,13 +32023,13 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 4804, + "line": 4900, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/prefill/prefill.cpp", - "line": 4804, + "line": 4900, "backend": "cuda-hip", "fn": "getenv" } @@ -31996,7 +32062,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 4813, + "line": 4909, "backend": "cuda-hip", "fn": "getenv" } @@ -32087,7 +32153,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 747, + "line": 801, "backend": "cuda-hip", "fn": "getenv" } @@ -32120,7 +32186,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 751, + "line": 805, "backend": "cuda-hip", "fn": "getenv" } @@ -32453,7 +32519,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 19770, + "line": 19811, "backend": "cuda-hip", "fn": "getenv" } @@ -32492,7 +32558,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 11102, + "line": 11109, "backend": "cuda-hip", "fn": "getenv" } @@ -32525,7 +32591,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 11105, + "line": 11112, "backend": "cuda-hip", "fn": "getenv" } @@ -32558,7 +32624,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 11106, + "line": 11113, "backend": "cuda-hip", "fn": "getenv" } @@ -32591,7 +32657,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 11104, + "line": 11111, "backend": "cuda-hip", "fn": "getenv" } @@ -32657,7 +32723,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 11107, + "line": 11114, "backend": "cuda-hip", "fn": "getenv" } @@ -32842,7 +32908,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 17700, + "line": 17710, "backend": "cuda-hip", "fn": "getenv" } @@ -32879,7 +32945,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 17741, + "line": 17751, "backend": "cuda-hip", "fn": "getenv" }, @@ -33157,7 +33223,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 558, + "line": 612, "backend": "cuda-hip", "fn": "getenv" }, @@ -33581,13 +33647,13 @@ }, { "file": "src/program/generate.cpp", - "line": 11890, + "line": 11900, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 11892, + "line": 11902, "backend": "cuda-hip", "fn": "getenv" } @@ -33622,13 +33688,13 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 11891, + "line": 11901, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 11891, + "line": 11901, "backend": "cuda-hip", "fn": "getenv" } @@ -33669,7 +33735,7 @@ }, { "file": "src/program/generate.cpp", - "line": 11894, + "line": 11904, "backend": "cuda-hip", "fn": "getenv" } @@ -33741,31 +33807,31 @@ }, { "file": "src/program/generate.cpp", - "line": 13342, + "line": 13352, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 14588, + "line": 14598, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 14588, + "line": 14598, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 14589, + "line": 14599, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 14590, + "line": 14600, "backend": "cuda-hip", "fn": "getenv" } @@ -34366,13 +34432,13 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 4667, + "line": 4763, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/prefill/prefill.cpp", - "line": 8178, + "line": 8274, "backend": "cuda-hip", "fn": "getenv" }, @@ -34481,13 +34547,13 @@ }, { "file": "src/prefill/prefill.cpp", - "line": 8362, + "line": 8458, "backend": "metal", "fn": "getenv" }, { "file": "src/prefill/prefill.cpp", - "line": 8404, + "line": 8500, "backend": "cuda-hip", "fn": "getenv" }, @@ -34707,7 +34773,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 4731, + "line": 4827, "backend": "cuda-hip", "fn": "getenv" }, @@ -34746,7 +34812,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 18831, + "line": 18872, "backend": "cuda-hip", "fn": "getenv" } @@ -34779,7 +34845,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 18834, + "line": 18875, "backend": "cuda-hip", "fn": "getenv" } @@ -35254,7 +35320,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 14981, + "line": 14991, "backend": "cuda-hip", "fn": "getenv" } @@ -35610,7 +35676,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 17274, + "line": 17284, "backend": "cuda-hip", "fn": "getenv" }, @@ -35652,13 +35718,13 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 13208, + "line": 13218, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 17247, + "line": 17257, "backend": "cuda-hip", "fn": "getenv" }, @@ -35816,13 +35882,13 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 14683, + "line": 14693, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 21551, + "line": 21594, "backend": "cuda-hip", "fn": "getenv" } @@ -35866,7 +35932,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 21599, + "line": 21642, "backend": "cuda-hip", "fn": "getenv" } @@ -35936,7 +36002,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 20746, + "line": 20787, "backend": "cuda-hip", "fn": "getenv" } @@ -36215,13 +36281,13 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 18778, + "line": 18819, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 21554, + "line": 21597, "backend": "cuda-hip", "fn": "getenv" } @@ -36254,7 +36320,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 18779, + "line": 18820, "backend": "cuda-hip", "fn": "getenv" } @@ -36287,7 +36353,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 21539, + "line": 21582, "backend": "cuda-hip", "fn": "getenv" } @@ -36320,7 +36386,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 21641, + "line": 21684, "backend": "cuda-hip", "fn": "getenv" } @@ -36428,8 +36494,8 @@ "first_commit": "ecf7424b53", "first_date": "2026-11-02", "since": "v0.2.10", - "last_commit": "ee0b367fb7", - "last_date": "2026-11-03", + "last_commit": "4c39e8624e", + "last_date": "2026-11-12", "status": "default", "owner": "program", "note": "[auto] on unless set to 0 (src/program/generate.cpp:4077)", @@ -36444,7 +36510,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 10222, + "line": 10229, "backend": "cuda-hip", "fn": "getenv" } @@ -36737,13 +36803,13 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 13172, + "line": 13182, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 18150, + "line": 18191, "backend": "cuda-hip", "fn": "env_on" } @@ -36819,7 +36885,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 11975, + "line": 11985, "backend": "cuda-hip", "fn": "getenv" } @@ -36901,13 +36967,13 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 10803, + "line": 10810, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 11438, + "line": 11448, "backend": "cuda-hip", "fn": "getenv" }, @@ -36987,7 +37053,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 10753, + "line": 10760, "backend": "cuda-hip", "fn": "getenv" }, @@ -37029,7 +37095,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 11840, + "line": 11850, "backend": "cuda-hip", "fn": "getenv" }, @@ -37069,7 +37135,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 11838, + "line": 11848, "backend": "cuda-hip", "fn": "getenv" }, @@ -37142,7 +37208,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 20717, + "line": 20758, "backend": "cuda-hip", "fn": "getenv" }, @@ -37366,7 +37432,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 22331, + "line": 22374, "backend": "hip", "fn": "getenv" } @@ -37401,7 +37467,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 2123, + "line": 2181, "backend": "cuda-hip", "fn": "getenv" } @@ -37435,13 +37501,13 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 881, + "line": 935, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/prefill/prefill.cpp", - "line": 2119, + "line": 2177, "backend": "cuda-hip", "fn": "getenv" }, @@ -37488,7 +37554,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 320, + "line": 321, "backend": "cuda-hip", "fn": "getenv" } @@ -37524,7 +37590,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 2111, + "line": 2169, "backend": "cuda-hip", "fn": "getenv" } @@ -37560,7 +37626,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 2099, + "line": 2157, "backend": "cuda-hip", "fn": "getenv" }, @@ -37692,8 +37758,8 @@ "first_commit": "d95805c61a", "first_date": "2026-10-03", "since": "v0.1.40.1", - "last_commit": "ee0b367fb7", - "last_date": "2026-11-03", + "last_commit": "4c39e8624e", + "last_date": "2026-11-12", "status": "research", "owner": "program", "note": "[reviewed] Experimental split-stack flag; no change in report. [_issues_dump/2239.md:67]", @@ -37808,7 +37874,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 20304, + "line": 20345, "backend": "cuda-hip", "fn": "getenv" }, @@ -37883,13 +37949,13 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 6870, + "line": 6966, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 20342, + "line": 20383, "backend": "cuda-hip", "fn": "getenv" }, @@ -37926,6 +37992,39 @@ "retire_after": "", "retired_in": "" }, + { + "name": "STRATA_SWITCH_POINT", + "backends": [ + "cuda-hip" + ], + "reads": [ + { + "file": "src/prefill/prefill.cpp", + "line": 404, + "backend": "cuda-hip", + "fn": "getenv" + } + ], + "parse": "flag", + "default_state": null, + "code_default": null, + "engine_sets": [], + "engine_defaults": [], + "launch_files": [], + "launch_sets": [], + "launch_reads": [], + "doc_mentions": [], + "first_commit": "e84392acc0", + "first_date": "2026-11-13", + "since": null, + "last_commit": "9e59a89cc0", + "last_date": "2026-11-13", + "status": "rollback", + "owner": "prefill", + "note": "Default: on for one class of card, off for every other (CUDA builds only; HIP never): NVIDIA discrete on PCIe, one GPU, link probe ran, compute capability 8.6 (RTX A6000 / A4000 class). Values: 0 = off, 1 = on for any CUDA card (not measured outside the class). STRATA_SWITCH_POINT=0 keeps the fixed 1,024-token floor and the fixed 3,072 CPU-share limit; =1 asks for the rule on any other CUDA card (not measured there). The chunk size from which a prompt chunk streams every expert the card does not hold comes from a cost estimate of the staged and the streamed walk (include/strata/prefill/switch_point_rule.hpp), and the CPU share's limit is 1.6 times it; a card holding every expert keeps 1,024. STRATA_PREFILL_STREAM_MIN and STRATA_PREFILL_CPU_SHARE_MAX keep precedence.", + "retire_after": "", + "retired_in": "" + }, { "name": "STRATA_SYCL_BF16_DET", "backends": [ @@ -38042,7 +38141,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 13354, + "line": 13364, "backend": "cuda-hip", "fn": "getenv" } @@ -38143,7 +38242,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 18275, + "line": 18316, "backend": "cuda-hip", "fn": "getenv" } @@ -38263,7 +38362,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 18192, + "line": 18233, "backend": "cuda-hip", "fn": "getenv" } @@ -38363,7 +38462,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 311, + "line": 312, "backend": "cuda-hip", "fn": "getenv" }, @@ -39237,13 +39336,13 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 3716, + "line": 3804, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/prefill/prefill.cpp", - "line": 6610, + "line": 6706, "backend": "cuda-hip", "fn": "getenv" }, @@ -39261,25 +39360,25 @@ }, { "file": "src/program/generate.cpp", - "line": 10997, + "line": 11004, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 12989, + "line": 12999, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 14427, + "line": 14437, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 20887, + "line": 20930, "backend": "cuda-hip", "fn": "getenv" }, @@ -39335,13 +39434,13 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 21396, + "line": 21439, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 21433, + "line": 21476, "backend": "cuda-hip", "fn": "getenv" }, @@ -39492,13 +39591,13 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 11625, + "line": 11635, "backend": "cuda", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 11643, + "line": 11653, "backend": "cuda", "fn": "getenv" } @@ -39573,7 +39672,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 10863, + "line": 10870, "backend": "hip", "fn": "getenv" } @@ -40931,7 +41030,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 14605, + "line": 14615, "backend": "cuda-hip", "fn": "getenv" } @@ -40965,7 +41064,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 14601, + "line": 14611, "backend": "cuda-hip", "fn": "getenv" }, @@ -41208,7 +41307,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 2230, + "line": 2288, "backend": "cuda-hip", "fn": "getenv" } diff --git a/docs/SETTINGS.md b/docs/SETTINGS.md index 97b6ffc694..d0e6353746 100644 --- a/docs/SETTINGS.md +++ b/docs/SETTINGS.md @@ -289,7 +289,7 @@ Off unless you set them. The last column says where each one is described. | `STRATA_WDDM_BUDGET` | number | AMD, Intel Arc | [AMD_HIP.md](AMD_HIP.md) | | `STRATA_WS_FAST` | number | NVIDIA and AMD | [OLDER_GPUS.md](OLDER_GPUS.md) | -## Switches that go back to earlier behaviour (68) +## Switches that go back to earlier behaviour (70) These behaviours are on by default. Setting the switch returns the earlier behaviour; the notes in the register say which version made it the default. @@ -340,6 +340,7 @@ version made it the default. | `STRATA_PLE_AUTO_MMAP` | number | NVIDIA and AMD, Intel Arc | v0.1.43.1 | [DETAILS.md](DETAILS.md) | | `STRATA_PREFILL_LOAN_WALK` | on / off | NVIDIA and AMD | - | - | | `STRATA_PREFILL_STREAM_MIN` | number | NVIDIA and AMD, Intel Arc | v0.1.40.1 | [AMD_HIP.md](AMD_HIP.md), [STRIX_HALO.md](STRIX_HALO.md) | +| `STRATA_PREFILL_TAIL_LOAN` | on / off | NVIDIA and AMD | - | - | | `STRATA_PROMPT_ATTN_ESIMD` | number | Intel Arc | v0.2.9 | - | | `STRATA_PROMPT_ATTN_OLD` | on / off | NVIDIA and AMD, Intel Arc | v0.1.40.1 | [NVIDIA_V100.md](NVIDIA_V100.md), [OLDER_GPUS.md](OLDER_GPUS.md) | | `STRATA_Q2_WARP` | on / off | NVIDIA and AMD | v0.1.45 | [DETAILS.md](DETAILS.md) | @@ -356,6 +357,7 @@ version made it the default. | `STRATA_SM60_TABLE` | number | NVIDIA and AMD | v0.1.43 | [OLDER_GPUS.md](OLDER_GPUS.md) | | `STRATA_SPLIT_CHUNK16K` | number | NVIDIA and AMD | v0.1.44 | [MULTI_GPU.md](MULTI_GPU.md) | | `STRATA_SPLIT_OWN` | on / off | NVIDIA and AMD, Intel Arc | v0.1.40.1 | [MULTI_GPU.md](MULTI_GPU.md) | +| `STRATA_SWITCH_POINT` | on / off | NVIDIA and AMD | - | - | | `STRATA_SYCL_BF16_DET` | number | Intel Arc | v0.2.13 | - | | `STRATA_TOPK_SAMPLE` | number | NVIDIA and AMD | v0.1.45 | [DETAILS.md](DETAILS.md) | | `STRATA_TOPK_SPLIT` | number | NVIDIA and AMD | v0.1.45 | [DETAILS.md](DETAILS.md) | diff --git a/include/strata/prefill/loan_rules.hpp b/include/strata/prefill/loan_rules.hpp index 7bad80fba0..128f04dff2 100644 --- a/include/strata/prefill/loan_rules.hpp +++ b/include/strata/prefill/loan_rules.hpp @@ -24,4 +24,52 @@ constexpr int64_t walk_chunk(int64_t tokens, int64_t chunk, int64_t floor) { return (tokens > 0 && chunk > 0 && tokens < floor && chunk >= floor) ? floor - 1 : chunk; } +// The tail of a lent fused layout. A layout laid out for chunks at or above the floor (the fused MoE buffers) also +// holds MMQ's rows for a chunk BELOW the floor, which runs staged in the same buffers. Sizing that for floor - 1 +// tokens costs expert slots on every prompt, whatever its own chunks are (a floor of 3,584 against 1,024: about 289 MB, +// 92 slots of an RTX A6000). A segment of `tokens` read in chunks of `chunk` has a chunk below the floor only at its +// end, so that is all the tail it needs. + +/// The most MMQ rows (in tokens) a segment of `tokens` read in chunks of `chunk` puts into the fused layout's buffers: +/// the last chunk when it is below `floor`, else 0 (every other chunk is a full one, at or above the floor, and runs +/// the fused kernels). A layout whose chunk is itself below the floor is not a fused layout: min(chunk, tokens). +constexpr int64_t tail_need(int64_t tokens, int64_t chunk, int64_t floor) { + if (tokens <= 0 || chunk <= 0) return 0; + if (chunk < floor) return tokens < chunk ? tokens : chunk; + const int64_t last = tokens > chunk ? tokens - ((tokens - 1) / chunk) * chunk : tokens; + return last < floor ? last : 0; +} + +/// The tail a layout is carved with for that need: on the 256-token grid (so that two requests with nearly the same tail +/// keep one layout), at most floor - 1 (today's size), 0 for no need. +constexpr int64_t tail_layout(int64_t need, int64_t floor) { + if (need <= 0 || floor <= 1) return 0; + const int64_t grid = (need + 255) / 256 * 256; + return grid < floor - 1 ? grid : floor - 1; +} + +/// The tail a layout for a segment is carved with (what lend asks the layout for). +constexpr int64_t segment_tail(int64_t tokens, int64_t chunk, int64_t floor) { + return tail_layout(tail_need(tokens, chunk, floor), floor); +} + +/// The tail a lend carves a layout with, given the layout that is in place: GROW-ONLY while the layout's chunk stays. +/// `layout_chunk` / `layout_tail`: the layout now laid out (a tail of -1: carved with today's floor - 1, i.e. never sized +/// by a segment: the start-up layout, or the way-back switch); `want`: the chunk this segment's loan is for; `need`: its +/// segment_tail(). A layout of the same chunk that is tail-sized keeps its tail when it covers the need (no relayout +/// for a smaller follow-up) and otherwise goes straight to today's size: floor - 1, so a sequence of segments costs at +/// most ONE relayout more than today's sizing, then runs on today's bytes. Any other case (another chunk: a relayout +/// today as well; a start-up layout) starts again from the need of that moment. +constexpr int64_t next_tail(int64_t layout_chunk, int64_t layout_tail, int64_t want, int64_t need, int64_t floor) { + if (layout_tail >= 0 && layout_chunk == want) return layout_tail >= need ? layout_tail : (floor > 1 ? floor - 1 : 0); + return need; +} + +/// A loan carved for `lent_chunk` with room for `lent_tail` MMQ tokens serves a later segment of `tokens` (wanting +/// chunks of `want`) without a new layout only if its chunk covers `want` AND the segment, read in the loan's own +/// chunks (a layout always reads in its own chunk), needs no more tail than the loan holds. +constexpr bool reuse_ok(int64_t want, int64_t tokens, int64_t lent_chunk, int64_t lent_tail, int64_t floor) { + return want <= lent_chunk && tail_need(tokens, lent_chunk, floor) <= lent_tail; +} + } // namespace strata::prefill::loan_rules diff --git a/include/strata/prefill/prefill.hpp b/include/strata/prefill/prefill.hpp index ea62fa8697..dfcadaad04 100644 --- a/include/strata/prefill/prefill.hpp +++ b/include/strata/prefill/prefill.hpp @@ -85,8 +85,16 @@ public: /// With borrowed buffers: lay them out again for chunks of `chunk` tokens (at most `init`'s) in `borrow` - a /// request lends only the slots its prompt needs. The stream must be idle (between prompts). - bool relayout(int64_t chunk, void* borrow, uint64_t borrow_bytes, std::string& err); + /// `tail` (>= 0, a fused layout only): the MMQ rows, in tokens, the layout holds for a chunk below the stream floor + /// (loan_rules.hpp: a lent layout is sized for its segment's own short last chunk, not for floor - 1); -1: floor - 1. + bool relayout(int64_t chunk, void* borrow, uint64_t borrow_bytes, std::string& err, int64_t tail = -1); int64_t chunk() const; + /// The tail the layout in place was carved with (-1: the default, floor - 1), and the MMQ tokens a chunk below the + /// floor may bring into it (a layout that is not fused takes any chunk it has: INT64_MAX). + int64_t layout_tail() const; + int64_t tail_room() const; + /// True when a layout for `chunk` is the fused one, whose MoE buffers carry a tail (see relayout). + static bool tail_matters(int64_t chunk, bool src); /// The share of the streamed experts' bytes DMA-able straight from pinned RAM (1 = all). Sizes the streamed /// ring (a big one only pays when the copy engine, not the host copies, is the limit); set before bytes_needed. @@ -100,6 +108,9 @@ public: /// (staged_fo_rule.hpp: Windows gfx1151, every layer without an MMQ tile and on the fused kernels, entry on), the measured crossing of the verify windows and that entry. /// A `--short-read` given on the command line is not asked. Call once the expert layout is known. static int64_t short_read_default(int64_t base); + /// STRATA_SWITCH_POINT (on by default for the class in switch_point_rule.hpp, =0 off): the expert cache's live slots and layers x experts of the single card's own model, before the first lend; the floor above is then + /// chosen from the share of experts the card does not hold, scaled by the cache's mean blob (MB), the start-up link probe (GB/s) and the card's SM count (switch_point_rule.hpp; 0 = unknown: the default floor). With STRATA_SWITCH_POINT=0 this changes nothing. + static void set_card_expert_share(int64_t resident_slots, int64_t total_pairs, double blob_mb = 0.0, double link_gbps = 0.0); /// --prefill-pipe (opt-in): the chunk a layer split's first stage reads an `n`-token prompt in, for `stages` /// stages, chunks of at most `cap` (the buffers' size) and a stage-chunk cost of b + a C with b/a = `ratio` tokens /// (0: unknown - STRATA_PREFILL_EQUAL's rule: the same chunk count as `cap` gives, evened out when its last chunk @@ -168,7 +179,7 @@ public: /// Device bytes `init` needs for a chunk of `chunk` tokens (what a borrowed region must hold). `src`: init gets an /// ExpertSource (carve picks the fused MoE layout only then). static uint64_t bytes_needed(const core::ModelGeometry& g, const core::SessionState& ss, int64_t chunk, - bool src = true); + bool src = true, int64_t tail = -1); /// The same without the streamed ring: what the chunk's own buffers cost. The auto chunk scan sizes the chunk /// first and hands the ring what the chunk leaves over, so it needs the chunk priced on its own. @@ -331,7 +342,7 @@ public: private: static uint64_t bytes_needed_impl(const core::ModelGeometry& g, const core::SessionState& ss, int64_t chunk, - bool owned_pages, bool src); + bool owned_pages, bool src, int64_t tail = -1); kernels::cpu::ExpertPool* cpu_pool_ = nullptr; ///< set_cpu_pool // Layer-major prefill: the super-chunk's buffers for an n-token prompt (its size, 0 = not this prompt: `why`), // the run, and the buffers given back after it. `cap` (> 0): at most that many tokens (a layer split's stages diff --git a/include/strata/prefill/switch_point_rule.hpp b/include/strata/prefill/switch_point_rule.hpp new file mode 100644 index 0000000000..f62cd394aa --- /dev/null +++ b/include/strata/prefill/switch_point_rule.hpp @@ -0,0 +1,124 @@ +// include/strata/prefill/switch_point_rule.hpp - the chunk size below which a prompt chunk takes the STAGED walk and from which it takes the STREAMED walk +// (src/prefill/prefill.cpp stream_all_min()), chosen by estimated cost from the card's share of non-resident experts instead of the fixed 1,024. +// ON BY DEFAULT for one class of card (enabled() below): CUDA, NVIDIA discrete card on PCIe, one GPU, the start-up link probe ran, compute capability 8.6 (RTX A6000 and +// RTX A4000 measured). STRATA_SWITCH_POINT=0 is the way back; STRATA_SWITCH_POINT=1 asks for the rule on any other CUDA card (not measured there). +// Pure: no GPU, no environment read here. +// +// The two walks (prefill.cpp): +// streamed: every expert the card does not hold is copied through a ring in layer order, whatever the chunk routes; the copy runs through the attention +// halves, so the chunk costs about its copy time: P(T) = c_p * X + a_p * T (X = non-resident experts, T = chunk tokens). +// staged: the routing is read back per layer and only the routed non-resident experts are staged; the copy cannot overlap the layer's own compute: +// S(T) = s0 + c_s * Xs(T) + a_s * T, with Xs(T) = X * (1 - u(T)) the routed ones. u(T) is the share of the non-resident experts NOT routed by T tokens. +// Fitted on an RTX A6000 (48 GB, 12 GB/s link) with Qwen3.8-Flash-Next UD-Q4_K_XL (111 GB set, 55% of the expert slots resident), K-quant fused kernels, CPU share off +// (par/RESULTS-SWITCH-POINT.md, par/switchpt/fit1.py): c_p = 0.2612 ms, a_p = 0.0566 ms/token (at X = 12,097), c_s = 0.2278, a_s = 0.2294, s0 = 202 ms, +// u(T) = (T / 391)^-0.702 (measured routed shares 51 / 70 / 80 / 88 % at 1,100 / 2,049 / 4,097 / 8,193 tokens; the uniform-routing formula says 100% at all of them). +// Staged wins while advantage(T) = P(T) - S(T) = (c_p - c_s) * X - s0 + c_s * X * u(T) - (a_s - a_p) * T is positive. +// +// The floor is ONE scalar for the card, decided before the first lend (the lent cache slots, ring_slots(T), fused_layout(T) and moe_bufs() all read stream_all_min()), so it +// depends on the card's counts and never on the chunk in hand. X = 0 (every expert resident) gives exactly the default 1,024. +#pragma once + +#include +#include +#include + +namespace strata::prefill::switch_point { + +inline constexpr int64_t kFloorDefault = 1024; // = kStreamFloorDefault (stream_floor_rule.hpp): the floor of every card the rule does not move +inline constexpr int64_t kGrid = 256; // the prompt path's chunk grid +inline constexpr int64_t kFloorMax = 8192; // never past the auto chunk's usual top: above it the streamed walk's one pass is cheaper on every card measured + +struct Constants { + double c_p = 0.2612; // ms per non-resident expert, streamed walk (its copy-bound floor) + double c_s = 0.2278; // ms per streamed expert, staged walk + double a_p = 0.0566; // ms per token, streamed walk + double a_s = 0.2294; // ms per token, staged walk + double s0 = 201.75; // ms, staged walk's fixed part + double t0 = 391.0; // u(T) = (T / t0)^-gamma, 1 below t0 + double gamma = 0.702; + double x_inflate = 1.0; // the streamed walk's lend: X as streamed / X as counted from the cache before the lend +}; + +/// Share of the non-resident experts no token of a chunk of T tokens routes to. +inline double uncovered(int64_t T, const Constants& k) { + if (T <= 0) return 1.0; + return std::min(1.0, std::pow((double) T / k.t0, -k.gamma)); +} + +/// Milliseconds the staged walk saves over the streamed walk for a chunk of T tokens on a card with X non-resident experts (negative: it costs). +inline double advantage_ms(int64_t T, double X, const Constants& k) { + return (k.c_p - k.c_s) * X - k.s0 + k.c_s * X * uncovered(T, k) - (k.a_s - k.a_p) * (double) T; +} + +/// The floor for a card holding `resident_slots` of `total_pairs` (layers x experts): staged below it, streamed from it. +/// total_pairs <= 0 (unknown) or nothing non-resident: the default. A card that gains nothing at 1,024 keeps 1,024 (never lower). +inline int64_t floor_for(int64_t resident_slots, int64_t total_pairs, const Constants& k = Constants{}) { + if (total_pairs <= 0 || resident_slots < 0 || resident_slots >= total_pairs) return kFloorDefault; + const double X = (double) (total_pairs - resident_slots) * k.x_inflate; + int64_t T = kFloorDefault; + while (T < kFloorMax && advantage_ms(T, X, k) > 0.0) T += kGrid; // advantage falls with T: the first T where it is not positive is the floor + return T; +} + +// ---- per-card scaling (SWITCH-POINT-2) ---- +// The A6000 fit above does not transfer as it is (the A4000's crossing is about 1,930 tokens, the fit's 5,632), but its structure does: the copy terms scale with the cost of moving one expert +// (mean blob bytes / the link's GB/s) and the compute terms with 1 / the SM count (the A4000 streams at 0.63 ms a token against the A6000's 0.36: 84 / 48). s0 and u(T) stay as fitted. +// Measured crossings of the staged walk against the streamed one with the CPU share off (RTX A6000 3.8K, RTX A4000 1.9K) are matched to within one 256-token step by the real crossing +// rounded DOWN to the grid. The R9700 (HIP, 28.3 GB/s probe but 0.14 ms a streamed expert) is not matched (model 1.1K, measured 1.5K): CUDA builds only. +struct Card { + double blob_mb = 3.19; // mean expert blob of the cache (cache bytes / slots), MB: the A6000 fit's value + double link_gbps = 12.2; // the start-up host-to-device probe, GB/s + int sm = 84; // multiprocessor count +}; +inline bool card_known(const Card& c) { return c.blob_mb > 0.0 && c.link_gbps > 0.0 && c.sm > 0; } +inline Constants constants_for(const Card& c) { + Constants k; + const double copy = (c.blob_mb / c.link_gbps) / (3.19 / 12.2); + const double comp = 84.0 / (double) c.sm; + k.c_p *= copy; k.c_s *= copy; + k.a_p *= comp; k.a_s *= comp; + return k; +} +/// The floor for this card with the CPU share off: the largest grid size at which the staged walk still wins (the first size where it does not, one step back), never below 1,024. +inline int64_t floor_for_card(int64_t resident_slots, int64_t total_pairs, const Card& c) { + if (!card_known(c)) return kFloorDefault; + const int64_t first = floor_for(resident_slots, total_pairs, constants_for(c)); + return std::max(kFloorDefault, first - kGrid); +} +/// With the share on, the staged walk's limit is the floor times this ratio. Measured share-on break-even / share-off crossing: RTX A4000 2.9K / 1.93K = 1.50, RTX A6000 6.19K / 4.18K = 1.48, +/// R9700 2.5K / 1.5K = 1.67 (not covered by this rule). Against this rule's own floors as the engine printed them (A6000 3,584, A4000 2,048) the same break-evens are 1.73 and 1.42, so no single ratio +/// fits both: 1.6 gives limits 5,632 (A6000, 558 under its break-even: up to 6% left on the table at 5,633) and 3,072 (A4000, 172 over: up to 3% lost at 2,900-3,072); both are far better than the +/// fixed 3,072 on the A6000 (par/RESULTS-SWITCH-POINT.md, 06:12 block). +inline constexpr double kShareRatio = 1.6; +/// The share's limit for a card whose floor moved: floor x kShareRatio on the grid; 0 (the share's own default stays) when the floor is the default. +inline int64_t share_limit_for(int64_t floor) { + if (floor <= kFloorDefault) return 0; + return std::min(2 * kFloorMax, ((int64_t) ((double) floor * kShareRatio) / kGrid) * kGrid); +} + +// ---- the class the rule is on for by default ---- +// The device facts the engine reads once the card's expert cache is built (src/prefill/prefill.cpp, Prefill::set_card_expert_share). +struct DeviceClass { + bool cuda = false; // a CUDA build (HIP builds: never) + bool discrete = false; // a discrete card, not an integrated / shared-memory GPU + bool single_gpu = false; // the engine runs on one card: no layer split, no second card + bool link_probed = false; // the start-up host-to-device probe ran and gave a rate (the PCIe cost the rule scales with) + int cc_major = 0, cc_minor = 0; // compute capability +}; +/// Measured: RTX A6000 (Boston) and RTX A4000 (z440), both 8.6. Every other compute capability (6.0, 7.0, 7.5, 8.0, 8.9, 12.0, 12.1) is outside the class until it is measured. +inline constexpr int kClassCcMajor = 8, kClassCcMinor = 6; +inline bool in_default_class(const DeviceClass& d) { + return d.cuda && d.discrete && d.single_gpu && d.link_probed && d.cc_major == kClassCcMajor && d.cc_minor == kClassCcMinor; +} +/// STRATA_SWITCH_POINT as the engine reads it: -1 unset (or empty), 1 for exactly "1", 0 for any other value. +inline int env_state(const char* v) { + if (v == nullptr || v[0] == '\0') return -1; + return (v[0] == '1' && v[1] == '\0') ? 1 : 0; +} +/// Whether the rule runs: HIP never; STRATA_SWITCH_POINT=0 (or any value but 1) never; =1 on every CUDA card; unset: the class above. +inline bool enabled(const DeviceClass& d, int env) { + if (!d.cuda || env == 0) return false; + return env == 1 || in_default_class(d); +} + +} // namespace strata::prefill::switch_point diff --git a/src/prefill/prefill.cpp b/src/prefill/prefill.cpp index dcd3745b32..cde6da4065 100644 --- a/src/prefill/prefill.cpp +++ b/src/prefill/prefill.cpp @@ -12,6 +12,7 @@ #include "strata/prefill/fp16_rows_rule.hpp" #include "strata/prefill/own_only_line.hpp" #include "strata/prefill/stream_floor_rule.hpp" +#include "strata/prefill/switch_point_rule.hpp" #include "strata/kernels/gfx_arch.hpp" #include "strata/prefill/fewrows.hpp" #include "strata/prefill/gp100_prompt_default.hpp" @@ -403,6 +404,44 @@ inline bool staged_fo_on() { cached.store(v ? 1 : 0, std::memory_order_release); return v; } +// STRATA_SWITCH_POINT (CUDA builds only): the floor of a card that streams part of the experts comes from switch_point_rule.hpp's cost estimate. ON BY DEFAULT for the class +// in_default_class() names (NVIDIA discrete card on PCIe, one GPU, link probe ran, compute capability 8.6); STRATA_SWITCH_POINT=0 is the way back, =1 asks for it on any other CUDA card. +// The card's counts arrive from Prefill::set_card_expert_share (the cache's slots and layers x experts, known before the first lend); until then the default answers. +std::atomic g_sp_resident{-1}, g_sp_total{0}; +double g_sp_blob_mb = 0.0, g_sp_link_gbps = 0.0; // the cache's mean blob (MB) and the start-up probe (GB/s), from Prefill::set_card_expert_share +int g_sp_sm = 0; // the card's multiprocessor count +int g_sp_cc_major = 0, g_sp_cc_minor = 0; // the card's compute capability +bool g_sp_integrated = true; // not known as discrete until the card answered +// STRATA_SWITCH_POINT as set: -1 unset, 1 for "1", 0 for any other value (the way back) +inline int switch_point_env() { + static const int e = [] { + const char* v = std::getenv("STRATA_SWITCH_POINT"); + return v != nullptr && v[0] != '\0' ? strata::prefill::switch_point::env_state(v) : -1; + }(); + return e; +} +// the card's counts have arrived (set_card_expert_share ran: a single card, no batch slots) +inline bool switch_point_known() { return g_sp_resident.load(std::memory_order_acquire) >= 0; } +inline bool switch_point_on() { +#if defined(STRATA_USE_HIP) || defined(__HIPCC__) || defined(STRATA_HIP_GFX906) + return false; // measured on CUDA only +#else + if (!switch_point_known()) return false; + strata::prefill::switch_point::DeviceClass d; + d.cuda = true; + d.discrete = !g_sp_integrated; + d.single_gpu = true; // set_card_expert_share is called from the single-card, no-batch paths only + d.link_probed = g_sp_link_gbps > 0.0; + d.cc_major = g_sp_cc_major; d.cc_minor = g_sp_cc_minor; + return strata::prefill::switch_point::enabled(d, switch_point_env()); +#endif +} +// the card as the rule scales it; a field not set gives card_known() == false and the default floor +inline strata::prefill::switch_point::Card sp_card() { + strata::prefill::switch_point::Card c; + c.blob_mb = g_sp_blob_mb; c.link_gbps = g_sp_link_gbps; c.sm = g_sp_sm; + return c; +} // The floor without STRATA_PREFILL_STREAM_MIN and the CPU share: stream_floor_rule.hpp's answer, decided once when the expert layout is known (a call before that gets the default and is not cached). inline int64_t default_stream_floor() { static std::atomic cached{-1}; @@ -411,7 +450,22 @@ inline int64_t default_stream_floor() { const auto& lay = strata::kernels::cpu::expert_layout(); if (!lay.native || lay.fmt.empty()) return strata::prefill::kStreamFloorDefault; const bool cls = stream_floor_class_measured(); - const int64_t v = strata::prefill::stream_floor_default(cls, cls && layers_all_fused_only(), staged_fo_on()); + int64_t v = strata::prefill::stream_floor_default(cls, cls && layers_all_fused_only(), staged_fo_on()); +#if !defined(STRATA_USE_HIP) && !defined(__HIPCC__) && !defined(STRATA_HIP_GFX906) + // the card's counts are not known yet (set_card_expert_share has not run) and the rule is not switched off: the default, not cached + if (v == strata::prefill::kStreamFloorDefault && switch_point_env() != 0 && !switch_point_known()) return v; +#endif + if (v == strata::prefill::kStreamFloorDefault && switch_point_on()) { + const int64_t res = g_sp_resident.load(std::memory_order_acquire), tot = g_sp_total.load(std::memory_order_acquire); + const auto card = sp_card(); + if (!strata::prefill::switch_point::card_known(card)) return v; // the link or the card is not known: the default, not cached + v = strata::prefill::switch_point::floor_for_card(res, tot, card); + if (v != strata::prefill::kStreamFloorDefault) + std::fprintf(stderr, "prefill: prompt chunks of %lld tokens or more stream every expert the card does not hold (%lld of %lld experts resident; %.2f MB experts, %.1f GB/s link, %d SMs); a shorter chunk stages only the routed ones. STRATA_SWITCH_POINT=0 keeps the fixed 1,024.\n", + (long long) v, (long long) res, (long long) tot, card.blob_mb, card.link_gbps, card.sm); + cached.store(v, std::memory_order_release); + return v; + } cached.store(v, std::memory_order_release); if (v != strata::prefill::kStreamFloorDefault) std::fprintf(stderr, "prefill: prompt pieces of %lld tokens or more read on the fused kernels, as long prompts do. STRATA_PREFILL_STREAM_MIN=1024 keeps the old rule.\n", (long long) v); @@ -1401,7 +1455,8 @@ struct Prefill::Impl { // this layout's GU, H and Xq are the fused path's (moe_bufs' `fused`), so a layer that runs MMQ or the FP16 path may // only write stream_all_min() - 1 of its rows into them; fused_layout() keeps the two in step (#583, #954) bool fused_bufs = false; - std::unique_ptr stager; // the unpinned experts' host copies (step 4) + int64_t tail_req = -1; // the MMQ tail (tokens) the fused layout was carved for: -1 = stream_all_min() - 1 (start-up, the way back); relayout's `tail` + std::unique_ptr stager; // the unpinned experts' host copies (step 4) std::unique_ptr warmer; // STRATA_PREFILL_WARM=1: the per-layer walk's page warming std::vector> warm_prev; // per layer: the file-tier experts of the previous chunk cudaEvent_t copied[RING_MAX] = {}, used[RING_MAX] = {}; @@ -1971,21 +2026,24 @@ bool fused_layout(size_t T, bool src) { // The MoE buffers MMQ and the fused path share: GU and H in floats, Xq and Hq in bytes. Without `fused` (the // default): MMQ's, for T tokens. struct MoeBufs { size_t gu, h, xq, hq; }; -MoeBufs moe_bufs(size_t T, int64_t n_expert, bool fused) { +// `tail` (>= 0, fused only): the MMQ rows a chunk below the floor may bring, in tokens (a lent layout sized for its +// segment's own last chunk, loan_rules.hpp); -1: stream_all_min() - 1, as the start-up layout. +MoeBufs moe_bufs(size_t T, int64_t n_expert, bool fused, int64_t tail = -1) { if (!fused && pf_group_scratch()) { // GU, H, Hq: one group's rows (Xq keeps every row: gate/up reads the layer's) const size_t gc = (size_t) group_cap_rows(T, n_expert); return {gc * kFF2, gc * kFF, mmq::q8_bytes((int64_t) (T * K), N), mmq::q8_bytes((int64_t) gc, kFF)}; } if (!fused) return {T * K * kFF2, T * K * kFF, mmq::q8_bytes((int64_t) (T * K), N), mmq::q8_bytes((int64_t) (T * K), kFF)}; - const size_t ts = (size_t) std::min((int64_t) T, stream_all_min() - 1); // MMQ's last small chunk + const int64_t tail_tokens = tail >= 0 ? std::min(tail, std::max(stream_all_min() - 1, 0)) : stream_all_min() - 1; + const size_t ts = (size_t) std::min((int64_t) T, tail_tokens); // MMQ's last small chunk return {std::max(ts * K * kFF2, (fused::group_bytes((int64_t) (T * K), (int) n_expert) + 3) / 4), std::max(ts * K * kFF, (fused::act_bytes((int64_t) (T * K), kFF) + 3) / 4), std::max(mmq::q8_bytes((int64_t) (ts * K), N), fused::act_bytes((int64_t) T, N)), mmq::q8_bytes((int64_t) (ts * K), kFF)}; } -uint64_t moe_set_bytes(size_t T, int64_t n_expert, bool fused) { +uint64_t moe_set_bytes(size_t T, int64_t n_expert, bool fused, int64_t tail = -1) { const MmqPlan& mp = mmq_plan(); - const MoeBufs mb = moe_bufs(T, n_expert, fused); + const MoeBufs mb = moe_bufs(T, n_expert, fused, tail); Alloc a; a.count_only = true; bool ok = true; a.take(T * n_expert, ok); a.take(T * K, ok); a.take(T * K, ok); a.take(T * K, ok); a.take(T * K, ok); @@ -2349,9 +2407,9 @@ bool Prefill::carve(size_t T, void* alloc) { // one region for the attention half's and the MoE half's scratch (see gdn_set_bytes) const bool fz = fused_layout(T, m.src != nullptr); m.fused_bufs = fz; - const MoeBufs mb = moe_bufs(T, m.g->n_expert, fz); + const MoeBufs mb = moe_bufs(T, m.g->n_expert, fz, m.tail_req); const uint64_t region = std::max({gdn_set_bytes(T), qsa_set_bytes(T, m.cap, m.max_blocks, m.sel_batch, - m.attn_batch, s), moe_set_bytes(T, m.g->n_expert, fz), + m.attn_batch, s), moe_set_bytes(T, m.g->n_expert, fz, m.tail_req), hcr ? hc_set_bytes(T, m.f16_io) : (uint64_t) 0}); uint8_t* base = o.take((size_t) region, ok); // No region: the sub-allocators below would each cudaMalloc their share (hundreds of MiB) on a card that has just @@ -2482,8 +2540,9 @@ bool Prefill::carve(size_t T, void* alloc) { return ok; } -bool Prefill::relayout(int64_t chunk, void* borrow, uint64_t borrow_bytes, std::string& err) { +bool Prefill::relayout(int64_t chunk, void* borrow, uint64_t borrow_bytes, std::string& err, int64_t tail) { Impl& m = *impl_; + m.tail_req = tail; // read by carve (a failure leaves the layout unusable as before; the caller ends the request) if (m.borrow_spill) { err = "prefill: a hybrid borrowed/owned layout cannot be changed between requests"; return false; @@ -2521,6 +2580,14 @@ bool Prefill::relayout(int64_t chunk, void* borrow, uint64_t borrow_bytes, std:: } int64_t Prefill::chunk() const { return impl_->T; } +int64_t Prefill::layout_tail() const { return impl_->tail_req; } +int64_t Prefill::tail_room() const { + const Impl& m = *impl_; + if (!m.fused_bufs) return std::numeric_limits::max(); // MMQ-sized buffers: any chunk the layout has + const int64_t d = std::max(stream_all_min() - 1, 0); + return m.tail_req >= 0 ? std::min(m.tail_req, d) : d; +} +bool Prefill::tail_matters(int64_t chunk, bool src) { return chunk > 0 && fused_layout((size_t) chunk, src); } void Prefill::set_ring_room_active(bool on) { ring_room_active_ = on; @@ -3074,6 +3141,21 @@ int64_t Prefill::short_read_default(int64_t base) { const bool cls = stream_floor_class_measured(); return strata::prefill::short_read_default(base, cls, cls && layers_all_fused_only(), staged_fo_on()); } +void Prefill::set_card_expert_share(int64_t resident_slots, int64_t total_pairs, double blob_mb, double link_gbps) { +#if !defined(STRATA_USE_HIP) && !defined(STRATA_HIP_GFX906) + int dev = 0; + cudaDeviceProp prop; + const bool got = cudaGetDevice(&dev) == cudaSuccess && cudaGetDeviceProperties(&prop, dev) == cudaSuccess; + g_sp_sm = got ? prop.multiProcessorCount : 0; + g_sp_cc_major = got ? prop.major : 0; + g_sp_cc_minor = got ? prop.minor : 0; + g_sp_integrated = got ? prop.integrated != 0 : true; +#endif + g_sp_blob_mb = blob_mb; + g_sp_link_gbps = link_gbps; + g_sp_total.store(total_pairs, std::memory_order_release); + g_sp_resident.store(resident_slots, std::memory_order_release); +} // --prefill-pipe (opt-in; STRATA_PREFILL_PIPE): a layer split reads a prompt as a pipeline - stage s reads chunk c while // stage s+1 reads chunk c-1. A stage-chunk costs its layers x (b + a C): a fixed part per chunk (b: the pass over the @@ -3174,8 +3256,8 @@ int64_t Prefill::chain_experts_streamed() const { return sum; } -uint64_t Prefill::bytes_needed(const core::ModelGeometry& g, const core::SessionState& ss, int64_t chunk, bool src) { - return bytes_needed_impl(g, ss, chunk, false, src); +uint64_t Prefill::bytes_needed(const core::ModelGeometry& g, const core::SessionState& ss, int64_t chunk, bool src, int64_t tail) { + return bytes_needed_impl(g, ss, chunk, false, src, tail); } // What `init` really allocates when the prompt path owns its buffers (no loan): every cudaMalloc rounds up to a 2 MiB @@ -3186,7 +3268,7 @@ uint64_t Prefill::bytes_needed_owned(const core::ModelGeometry& g, const core::S } uint64_t Prefill::bytes_needed_impl(const core::ModelGeometry& g, const core::SessionState& ss, int64_t chunk, - bool owned_pages, bool src) { + bool owned_pages, bool src, int64_t tail) { // the same allocation sequence as `init` (`carve`), counted - with the MoE layout `carve` picks for the same source const size_t T = (size_t) chunk; bool ok = true; @@ -3221,7 +3303,7 @@ uint64_t Prefill::bytes_needed_impl(const core::ModelGeometry& g, const core::Se const int64_t cap = strata::kernels::qsa_selection_width(strata::kernels::kTopkMaxCells, s); const int64_t max_blocks = ss.qsa_states[ss.qsa_primary()].max_cells / s.idx_block + 2; o.take((size_t) std::max({gdn_set_bytes(T), qsa_set_bytes(T, cap, max_blocks, 256, 32, s), - moe_set_bytes(T, g.n_expert, fused_layout(T, src)), + moe_set_bytes(T, g.n_expert, fused_layout(T, src), tail), hcr ? hc_set_bytes(T, f16_io) : (uint64_t) 0}), ok); for (int i = 0; i < DQ; ++i) { o.take(kFF2 * kEmbd, ok); o.take(kEmbd * kFF, ok); } if (mmq_plan().any) { @@ -3283,6 +3365,12 @@ void Prefill::arm_cpu_share(bool applies, bool by_default) { #if !defined(STRATA_USE_HIP) && !defined(STRATA_HIP_GFX906) if (applies && by_default && cpu_share_explicit() == -2.0 && !g_share_default) { g_share_default = true; + if (switch_point_on() && g_sp_resident.load(std::memory_order_acquire) >= 0 && strata::prefill::switch_point::card_known(sp_card())) { + // STRATA_SWITCH_POINT (on by default for its class, 0 = off): the share's limit scales with the card's own floor (floor x kShareRatio), not the fixed 3,072 + const int64_t lim = strata::prefill::switch_point::share_limit_for(strata::prefill::switch_point::floor_for_card( + g_sp_resident.load(std::memory_order_acquire), g_sp_total.load(std::memory_order_acquire), sp_card())); + if (lim > 0) g_share_limit_arch = lim; + } std::fprintf(stderr, "prefill: the CPU share is ON by default for prompt chunks up to %lld tokens (the idle CPU " "takes some of the experts the GPU would stream; answers can differ slightly from 0.1.40.3, " "mean KL ~0.004 below 1024 tokens, ~0.011 at 1-3K). STRATA_PREFILL_CPU_SHARE=0 turns it off, " @@ -3799,6 +3887,14 @@ bool Prefill::run_impl(const int64_t* tokens, int64_t n, int64_t pos0, std::stri std::fflush(stderr); } const int64_t T = std::min(C, n - c0), p0 = pos0 + c0; + // A fused layout carved with a tail (relayout's `tail`, loan_rules.hpp) holds MMQ's rows for that many tokens of a + // chunk below the stream floor: a longer one would overrun GU / H / Xq / Hq (an illegal access, or a hang). The + // lend sizes the tail from the segment, so this is the clean error for anything that drifts from it. + if (m.fused_bufs && T < stream_all_min() && T > tail_room()) { + err = "prefill: a chunk of " + std::to_string((long long) T) + " tokens below the stream floor does not fit the fused layout's tail of " + + std::to_string((long long) tail_room()) + " tokens"; + return false; + } // STRATA_KVA: this chunk is approximated in the layers at and after the split when its last position is // before the request's full-computation suffix; a chunk in the suffix runs the ordinary path everywhere. const bool kva_approx = kva_run && (p0 + T <= kva_frontier); diff --git a/src/program/generate.cpp b/src/program/generate.cpp index 7b14b68d8a..52f809d2a7 100644 --- a/src/program/generate.cpp +++ b/src/program/generate.cpp @@ -10165,6 +10165,13 @@ int main(int argc, char** argv) { // tokens (RTX A6000). Applies to every piece within 255 tokens under the floor (769-1,023 at 1,024; 2,817-3,071 under the CPU // share's 3,072). STRATA_PREFILL_LOAN_WALK=0 keeps the rounded chunk. static const bool loan_by_walk = [] { const char* e = std::getenv("STRATA_PREFILL_LOAN_WALK"); return !(e != nullptr && e[0] == '0'); }(); + // The lent fused layout's MMQ tail is sized from the segment's own last chunk, not from the stream floor (a floor of 3,584 + // against 1,024 costs ~92 expert slots on an RTX A6000, streamed again by every chunk above the floor). One GPU, no peer, no + // --batch above one slot, no head alias; a layer split keeps the floor's tail. STRATA_PREFILL_TAIL_LOAN=0 keeps today's size. + static const bool tail_loan_on = [] { const char* e = std::getenv("STRATA_PREFILL_TAIL_LOAN"); return !(e != nullptr && e[0] == '0'); }(); + // STRATA_DBG_TAIL_NOREUSE=1 (a test of the backstop): a loan is reused by chunk alone, as before the tail rule - a later short segment then + // overruns the tail and the chunk check in Prefill::run_impl must end the request with its error + static const bool dbg_tail_noreuse = [] { const char* e = std::getenv("STRATA_DBG_TAIL_NOREUSE"); return e != nullptr && e[0] == '1'; }(); auto loan_chunk = [&](int64_t tokens, int64_t chunk) -> int64_t { return loan_by_walk ? strata::prefill::loan_rules::walk_chunk(tokens, chunk, strata::prefill::Prefill::stream_all_min_tokens()) : chunk; @@ -11139,6 +11146,8 @@ int main(int argc, char** argv) { "nothing to take, so it is not armed by default (STRATA_PREFILL_CPU_SHARE=auto forces it)\n", (long long) xcache.slots(), (long long) (g.n_layers * g.n_expert)); if (share_pool && stages.empty() && !multi_gpu && share_has_work && !share_default_ok()) share_has_work = false; // H11 + if (stages.empty() && !multi_gpu && o.batch <= 0) // STRATA_SWITCH_POINT: one card, no batch slots; before any bytes_needed, like the share + strata::prefill::Prefill::set_card_expert_share((int64_t) xcache.slots(), (int64_t) (g.n_layers * g.n_expert), xcache.slots() > 0 ? (double) xcache.bytes() / (double) xcache.slots() / 1e6 : 0.0, o.pcie_probe_gbps); strata::prefill::Prefill::arm_cpu_share(share_pool, share_pool && stages.empty() && !multi_gpu && share_has_work); void* borrow = nullptr; uint64_t borrow_bytes = 0; @@ -11171,9 +11180,10 @@ int main(int argc, char** argv) { (uint64_t) strata::kernels::cpu::expert_layout().max_blob, need); }; auto on_part_device = [](int dev) { return strata::core::OnDevice(dev); }; - auto part_slots = [&](const PfPart& p, int64_t c) -> int64_t { + // `tail` (>= 0): the lent fused layout's MMQ tail in tokens (loan_rules.hpp); -1: today's floor - 1 + auto part_slots = [&](const PfPart& p, int64_t c, int64_t tail = -1) -> int64_t { return cache_slots_for(*p.cache, strata::program::split_part_figure(on_part_device, p.dev, [&] { - return strata::prefill::Prefill::bytes_needed(g, *p.ses, c, srcp != nullptr); + return strata::prefill::Prefill::bytes_needed(g, *p.ses, c, srcp != nullptr, tail); })); }; auto part_bytes = [&](const PfPart& p, int32_t first) -> uint64_t { @@ -17802,10 +17812,18 @@ int main(int argc, char** argv) { return false; } bool any = false; + namespace lr = strata::prefill::loan_rules; + using strata::prefill::Prefill; + const int64_t floor_t = Prefill::stream_all_min_tokens(); + const bool tail_ok = tail_loan_on && pf_parts.size() == 1 && stages.empty() && !multi_gpu && !peer.valid() && + !o.prefill_head_alias && o.batch <= 1; for (PfPart& p : pf_parts) { if (p.first < 0) continue; if (!p.lent.empty()) { - if (want <= p.lent_chunk) continue; // its current loan already covers this + // its current loan already covers this: the chunk, and (a fused layout) the tail the segment's last + // chunk needs when it is read in the loan's own chunks + if (tail_ok && !dbg_tail_noreuse ? lr::reuse_ok(want, tokens, p.lent_chunk, p.sp->tail_room(), floor_t) + : want <= p.lent_chunk) continue; // ONLY this participant's loan goes back: `refill` would return the other participants' // loans too, and their buffers are still laid out in their caches - marking those slots // resident again would hand the next window a prompt buffer in place of an expert @@ -17813,6 +17831,7 @@ int main(int argc, char** argv) { } const strata::core::OnDevice on(p.dev); int64_t want_p = want; + int64_t tail_p = -1; // the tail the layout is laid out with (-1: floor - 1) int32_t first = p.first_now; // --prefill-head-alias: the loan laid out at start (slot 1 on) is kept; a hybrid layout cannot relayout. // (STRATA_MTP_ROOM_MIN's room is not one: its slots are the drafter's own bytes, so a roomed @@ -17823,10 +17842,18 @@ int main(int argc, char** argv) { // a request's smaller chunk can need MORE slots than the auto chunk's region (p.first) holds. The // loan starts where the chunk itself needs it (the 128-slot floor aside); a chunk that cannot be // lent even then is halved until it can, instead of ending the engine. - int64_t need_p = part_slots(p, want_p); + // the tail this layout is carved with for chunks of `w` (-1: today's floor - 1): grow-only while the layout's + // chunk stays (loan_rules::next_tail), the need of the moment otherwise + auto tail_for = [&](int64_t w) -> int64_t { + if (!tail_ok || !Prefill::tail_matters(w, srcp != nullptr)) return -1; + return lr::next_tail(p.sp->chunk(), p.sp->layout_tail(), w, lr::segment_tail(tokens, w, floor_t), floor_t); + }; + tail_p = tail_for(want_p); + int64_t need_p = part_slots(p, want_p, tail_p); while ((need_p <= 0 || need_p + g_lend_keep > p.cache->slots()) && want_p > 256) { want_p = std::max(256, want_p / 2 / 256 * 256); - need_p = part_slots(p, want_p); + tail_p = tail_for(want_p); + need_p = part_slots(p, want_p, tail_p); } if (need_p <= 0 || need_p + g_lend_keep > p.cache->slots()) { e = "prefill: no chunk of this request fits the slots that can be lent (#2090)"; @@ -17842,9 +17869,23 @@ int main(int argc, char** argv) { (long long) need_p, (long long) (p.cache->slots() - p.first)); first = (int32_t) (p.cache->slots() - need_p); } - if (want_p != p.sp->chunk() || first != p.first_now) { - if (!p.sp->relayout(want_p, p.cache->device_slot(first), part_bytes(p, first), e)) return false; + if (want_p != p.sp->chunk() || first != p.first_now || (tail_p >= 0 && tail_p != p.sp->layout_tail())) { + const auto t_rl = Clock::now(); + if (!p.sp->relayout(want_p, p.cache->device_slot(first), part_bytes(p, first), e, tail_p)) return false; p.first_now = first; + if (tail_p >= 0) { + static bool said = false; + if (!said) { + said = true; + std::fprintf(stderr, "strata serve: the lent prompt buffers are sized for the request's own short last chunk " + "(tail %lld tokens, not the stream floor's %lld); STRATA_PREFILL_TAIL_LOAN=0 keeps the floor's\n", + (long long) tail_p, (long long) (floor_t - 1)); + } + if (trace) + std::fprintf(stderr, "strata trace: relayout for %lld tokens, tail %lld, first slot %d: %.1f ms\n", (long long) want_p, + (long long) tail_p, (int) first, + std::chrono::duration(Clock::now() - t_rl).count()); + } } for (int64_t l = p.lb; l < p.le; ++l) // THIS participant's layers only for (int64_t ex = 0; ex < g.n_expert; ++ex) { @@ -20810,6 +20851,8 @@ int main(int argc, char** argv) { int64_t pos_start = 0; int64_t spec_pos = strata::spec::kSpecNotStarted; // plan v0.3 P6: where the speculative loop starts (0 is a real position: a 1-token prompt on a native pack) strata::prefill::Prefill prefill; + if (!multi_gpu && o.batch <= 0) // STRATA_SWITCH_POINT: before any bytes_needed, like the share + strata::prefill::Prefill::set_card_expert_share((int64_t) xcache.slots(), (int64_t) (g.n_layers * g.n_expert), xcache.slots() > 0 ? (double) xcache.bytes() / (double) xcache.slots() / 1e6 : 0.0, o.pcie_probe_gbps); // #1595: not by default when the cache holds every expert (nothing to take) strata::prefill::Prefill::arm_cpu_share(!multi_gpu && !o.no_pool, !multi_gpu && !o.no_pool && o.batch <= 0 && diff --git a/tests/prefill/loan_rules_test.cpp b/tests/prefill/loan_rules_test.cpp index 7a2eafd617..a1410b14e1 100644 --- a/tests/prefill/loan_rules_test.cpp +++ b/tests/prefill/loan_rules_test.cpp @@ -6,6 +6,11 @@ #include "strata/prefill/loan_rules.hpp" using strata::prefill::loan_rules::walk_chunk; +using strata::prefill::loan_rules::tail_need; +using strata::prefill::loan_rules::tail_layout; +using strata::prefill::loan_rules::segment_tail; +using strata::prefill::loan_rules::reuse_ok; +using strata::prefill::loan_rules::next_tail; static int failed = 0; #define CHECK(x) do { if (!(x)) { std::fprintf(stderr, "FAIL %s:%d: %s\n", __FILE__, __LINE__, #x); ++failed; } } while (0) @@ -52,6 +57,90 @@ int main() { // empty or negative requests are passed through CHECK(walk_chunk(0, 256, 1024) == 256 && walk_chunk(10, 0, 1024) == 0); static_assert(walk_chunk(999, 1024, 1024) == 1023, "constexpr"); + + // ---- the tail of a lent fused layout (tail_need / tail_layout / segment_tail / reuse_ok) + // one chunk at or above the floor: no MMQ rows at all + CHECK(tail_need(1024, 1024, 1024) == 0); + CHECK(tail_need(8192, 8192, 1024) == 0); + CHECK(tail_need(4096, 2048, 1024) == 0); // two full chunks + // a short last chunk is the whole need + CHECK(tail_need(4097, 2048, 1024) == 1); + CHECK(tail_need(5000, 2048, 1024) == 904); + CHECK(tail_need(5120 + 1023, 5120, 1024) == 1023); + CHECK(tail_need(5120 + 1024, 5120, 1024) == 0); // a last chunk at the floor streams: fused + // a floor of 3,584 (the rule on an RTX A6000): the same segments now have a tail up to 3,583 + CHECK(tail_need(8193, 8192, 3584) == 1); + CHECK(tail_need(4097, 2048, 3584) == 2048); // a layout of 2,048-token chunks is below the floor: not fused, every chunk is MMQ's + CHECK(tail_need(8193 + 2000, 8192, 3584) == 2001); + CHECK(tail_need(8192 + 3584, 8192, 3584) == 0); + // a segment read in one chunk below the floor, in a layout whose chunk reaches it (a reused big loan) + CHECK(tail_need(2000, 8192, 3584) == 2000); + CHECK(tail_need(2000, 8192, 1024) == 0); + // a layout whose own chunk is below the floor is not fused: every chunk is MMQ's + CHECK(tail_need(5000, 1023, 1024) == 1023 && tail_need(500, 1023, 1024) == 500); + CHECK(tail_need(0, 4096, 1024) == 0 && tail_need(10, 0, 1024) == 0); + // never above floor - 1, never negative, last chunk exact for every size + for (int64_t floor : std::initializer_list{1, 64, 1024, 3072, 3584}) + for (int64_t c : std::initializer_list{256, 1023, 1024, 2048, 4096, 8192}) + for (int64_t t = 1; t <= 20000; t += 37) { + const int64_t need = tail_need(t, c, floor); + CHECK(need >= 0 && need <= (floor > 1 ? floor - 1 : 0)); + int64_t worst = 0; // walk the chunks one by one + for (int64_t at = 0; at < t; at += c) { + const int64_t len = t - at < c ? t - at : c; + if (len < floor && len > worst) worst = len; + } + CHECK(need == worst); + const int64_t lay = tail_layout(need, floor); + CHECK(lay >= need && (need == 0 ? lay == 0 : lay % 256 == 0 || lay == floor - 1)); + CHECK(lay <= (floor > 1 ? floor - 1 : 0)); + CHECK(segment_tail(t, c, floor) == lay); + } + // the grid: 904 -> 1,024; clamped to today's floor - 1 + CHECK(tail_layout(904, 3584) == 1024 && tail_layout(1, 3584) == 256 && tail_layout(1023, 1024) == 1023); + CHECK(tail_layout(0, 3584) == 0 && tail_layout(5, 1) == 0); + // the overflow case: a loan made for an 8,193+ segment whose last chunk is 1 token, then a 2,000-token segment + // (the 2,000 tokens read as ONE chunk of the loan's layout, staged under a 3,584 floor) + { + const int64_t floor = 3584, lent_chunk = 8192; + const int64_t lent_tail = segment_tail(8193, lent_chunk, floor); // 256: the last chunk is 1 token + CHECK(lent_tail == 256); + CHECK(!reuse_ok(2048, 2000, lent_chunk, lent_tail, floor)); // needs 2,000 (grid 2,048): relayout + CHECK(tail_need(2000, lent_chunk, floor) > lent_tail); + CHECK(reuse_ok(256, 100, lent_chunk, lent_tail, floor)); // 100 <= 256: reuse + CHECK(tail_need(4196, lent_chunk, floor) == 0); // one chunk of 4,196 >= floor: fused, no tail + CHECK(reuse_ok(2048, 4196, lent_chunk, lent_tail, floor)); // so it reuses + } + // a smaller want never reuses a smaller loan, a bigger tail never reuses a smaller one + CHECK(!reuse_ok(4096, 4096, 2048, 4095, 1024)); + CHECK(reuse_ok(2048, 4096, 2048, 0, 1024)); + CHECK(reuse_ok(2048, 4096, 4096, 0, 1024) && !reuse_ok(2048, 4097 + 4096, 4096, 0, 8192)); + // ---- grow-only (next_tail): need grows, need shrinks, chunk grows + { + const int64_t floor = 3584; + CHECK(next_tail(8192, -1, 8192, 256, floor) == 256); // a start-up layout (default-sized): the need of the moment + CHECK(next_tail(8192, 1024, 8192, 256, floor) == 1024); // need shrinks: the tail stays (no relayout) + CHECK(next_tail(8192, 1024, 8192, 0, floor) == 1024); + CHECK(next_tail(8192, 1024, 8192, 1024, floor) == 1024); // equal: stays + CHECK(next_tail(8192, 1024, 8192, 1280, floor) == 3583); // need grows: today's size, once + CHECK(next_tail(8192, 3583, 8192, 3000, floor) == 3583); // and then it is today's: nothing grows past it + CHECK(next_tail(8192, 1024, 4096, 256, floor) == 256); // chunk shrinks: another layout, from its own need + CHECK(next_tail(4096, 1024, 8192, 2048, floor) == 2048); // chunk grows: from the need of that moment + CHECK(next_tail(8192, 0, 8192, 0, floor) == 0); // no tail needed, none carved + CHECK(next_tail(8192, 0, 8192, 256, floor) == 3583); + CHECK(next_tail(8192, 256, 8192, 256, 1) == 256 && next_tail(8192, 0, 8192, 5, 1) == 0); + // a sequence of needs on one chunk: at most one growth, every layout tail covers its segment, never shrinks + int64_t cap = -1, grown = 0; + for (int64_t need : std::initializer_list{256, 0, 1024, 256, 2048, 3583, 0, 512, 3000}) { + const int64_t t = next_tail(8192, cap, 8192, need, floor); + CHECK(t >= need); + if (cap >= 0) CHECK(t >= cap); + if (t != cap) ++grown; + cap = t; + } + CHECK(grown == 2); // the first carve (256), one growth (1024 > 256 -> today's 3583), then it stays + } + static_assert(tail_need(5000, 2048, 1024) == 904 && segment_tail(5000, 2048, 1024) == 1023, "constexpr"); if (failed != 0) return 1; std::printf("loan_rules_test: all checks passed\n"); return 0; diff --git a/tests/prefill/switch_point_rule_test.cpp b/tests/prefill/switch_point_rule_test.cpp new file mode 100644 index 0000000000..bcdb3d0413 --- /dev/null +++ b/tests/prefill/switch_point_rule_test.cpp @@ -0,0 +1,140 @@ +// switch_point_rule.hpp: the floor from which a prompt chunk takes the streamed walk, from the card's share of non-resident experts. No GPU, no model. +#include +#include + +#include "strata/prefill/switch_point_rule.hpp" + +namespace sp = strata::prefill::switch_point; + +static int failed = 0; +#define CHECK(x) do { if (!(x)) { std::fprintf(stderr, "FAIL %s:%d: %s\n", __FILE__, __LINE__, #x); ++failed; } } while (0) + +int main() { + static_assert(sp::kFloorDefault == 1024, "the default floor is 1,024"); + const sp::Constants k; + const int64_t total = 24576; // 48 layers x 512 experts (Flash-Next) + + // every expert resident (or an unknown card): exactly the default + CHECK(sp::floor_for(total, total) == 1024); + CHECK(sp::floor_for(total + 5, total) == 1024); + CHECK(sp::floor_for(0, 0) == 1024); + CHECK(sp::floor_for(-1, total) == 1024); + CHECK(sp::floor_for(5000, 0) == 1024); + + // the floor is a multiple of the chunk grid, within [1024, kFloorMax], for every resident count + int64_t prev = 0; + bool seen_move = false; + for (int64_t res = 0; res <= total; res += 64) { + const int64_t f = sp::floor_for(res, total); + CHECK(f >= 1024 && f <= sp::kFloorMax); + CHECK((f - 1024) % sp::kGrid == 0); + if (f != 1024) seen_move = true; + (void) prev; + prev = f; + } + CHECK(seen_move); + + // the A6000 / UD-Q4_K_XL card (55% resident): between the measured 2,049 (staged 1.28x faster) and 8,193 (staged 26% slower), about the measured crossing at 4,097 + { + const int64_t res = (int64_t) (0.55 * (double) total); + const int64_t f = sp::floor_for(res, total); + CHECK(f > 2049 && f < 8193); + } + // the same card with the measured X (about 12,097 non-resident): the model's own crossing is 4,0xx + { + const int64_t f = sp::floor_for(total - 12097, total); + CHECK(f >= 3584 && f <= 4608); + CHECK(sp::advantage_ms(1100, 12097, k) > 1000.0); // measured 1,390 ms (3,236 against 1,838) + CHECK(sp::advantage_ms(2049, 12097, k) > 500.0); // measured 710 ms + CHECK(std::fabs(sp::advantage_ms(4097, 12097, k)) < 120.0); // measured 18 ms + CHECK(sp::advantage_ms(8193, 12097, k) < -700.0); // measured -950 ms + } + // a card with fewer non-resident experts stages less often: the floor does not rise as more experts are resident + { + int64_t last = sp::kFloorMax + 1; + for (int64_t res = total / 8; res <= total; res += 256) { + const int64_t f = sp::floor_for(res, total); + CHECK(f <= last); + last = f; + } + } + // the uncovered share: 1 below t0, falling, never above 1 + CHECK(sp::uncovered(100, k) == 1.0); + CHECK(sp::uncovered(1100, k) > sp::uncovered(4097, k)); + CHECK(sp::uncovered(8193, k) < 0.2); + CHECK(sp::uncovered(0, k) == 1.0); + + // per-card scaling: the A6000 (3.19 MB experts, 12.2 GB/s, 84 SMs, 13,580 of 24,576 resident) and the A4000 (1.44 MB, 10.5 GB/s, 48 SMs, 7,836 resident), CPU share off: + // measured crossings about 3,840 and 1,930 tokens, the rule's floors are within one grid step of them + { + const sp::Card a6000{3.19, 12.2, 84}, a4000{1.44, 10.5, 48}; + const int64_t f6 = sp::floor_for_card(13580, total, a6000); + const int64_t f4 = sp::floor_for_card(7836, total, a4000); + CHECK(f6 >= 3584 && f6 <= 4096); + CHECK(f4 >= 1792 && f4 <= 2048); + CHECK(f4 < f6); // the slower card of the two crosses earlier, as measured + CHECK((f6 - 1024) % sp::kGrid == 0 && (f4 - 1024) % sp::kGrid == 0); + // an unknown card (no probe, no SM count): the default + CHECK(sp::floor_for_card(13580, total, sp::Card{0.0, 12.2, 84}) == 1024); + CHECK(sp::floor_for_card(13580, total, sp::Card{3.19, 0.0, 84}) == 1024); + CHECK(sp::floor_for_card(13580, total, sp::Card{3.19, 12.2, 0}) == 1024); + // every expert resident: the default whatever the card + CHECK(sp::floor_for_card(total, total, a6000) == 1024); + // the A6000-class card's constants are the fit's own + const sp::Constants kc = sp::constants_for(sp::Card{}); + CHECK(std::fabs(kc.c_p - 0.2612) < 1e-9 && std::fabs(kc.a_s - 0.2294) < 1e-9); + // faster link, same card: a smaller floor; more SMs, same link: a higher one + CHECK(sp::floor_for_card(13580, total, sp::Card{3.19, 24.0, 84}) <= f6); + CHECK(sp::floor_for_card(13580, total, sp::Card{3.19, 12.2, 120}) >= f6); + } + // the share's limit: the floor times the measured ratio on the grid, 0 (the share's own default stays) when the floor did not move + CHECK(sp::share_limit_for(1024) == 0); + CHECK(sp::share_limit_for(2048) == 3072); // A4000: measured break-even about 2,900 + CHECK(sp::share_limit_for(3840) % sp::kGrid == 0 && sp::share_limit_for(3840) > 3840); + + // the class the rule is on for by default: CUDA, discrete, one GPU, link probe ran, compute capability 8.6; STRATA_SWITCH_POINT=0 is the way back, =1 asks for it elsewhere + { + sp::DeviceClass in; + in.cuda = true; in.discrete = true; in.single_gpu = true; in.link_probed = true; in.cc_major = 8; in.cc_minor = 6; + CHECK(sp::in_default_class(in)); + CHECK(sp::enabled(in, -1)); // nothing set: on + CHECK(!sp::enabled(in, 0)); // STRATA_SWITCH_POINT=0 (or any value but 1): the way back + CHECK(sp::enabled(in, 1)); // STRATA_SWITCH_POINT=1: on + // every other compute capability is out of the class with nothing set + const int other[][2] = {{6, 0}, {6, 1}, {7, 0}, {7, 5}, {8, 0}, {8, 7}, {8, 9}, {9, 0}, {10, 0}, {12, 0}, {12, 1}, {0, 0}}; + for (const auto& cc : other) { + sp::DeviceClass d = in; + d.cc_major = cc[0]; d.cc_minor = cc[1]; + CHECK(!sp::in_default_class(d)); + CHECK(!sp::enabled(d, -1)); + CHECK(sp::enabled(d, 1)); // the explicit opt-in still works on another CUDA card + CHECK(!sp::enabled(d, 0)); + } + // each other condition on its own takes a card out of the class + { sp::DeviceClass d = in; d.single_gpu = false; CHECK(!sp::enabled(d, -1)); CHECK(!sp::enabled(d, 0)); } // two cards / a layer split + { sp::DeviceClass d = in; d.link_probed = false; CHECK(!sp::enabled(d, -1)); } // no probe + { sp::DeviceClass d = in; d.discrete = false; CHECK(!sp::enabled(d, -1)); } // integrated / shared memory + { sp::DeviceClass d = in; d.cuda = false; CHECK(!sp::enabled(d, -1)); CHECK(!sp::enabled(d, 1)); CHECK(!sp::enabled(d, 0)); } // HIP: never, whatever the cc says + { sp::DeviceClass d; CHECK(!sp::enabled(d, -1)); CHECK(!sp::enabled(d, 1)); } // nothing known + // the variable: unset or empty = default, exactly "1" = on, anything else = off + CHECK(sp::env_state(nullptr) == -1); + CHECK(sp::env_state("") == -1); + CHECK(sp::env_state("1") == 1); + CHECK(sp::env_state("0") == 0); + CHECK(sp::env_state("off") == 0); + CHECK(sp::env_state("11") == 0); + // the class gives the measured floors: the A6000 and the A4000 are both 8.6 + CHECK(sp::kClassCcMajor == 8 && sp::kClassCcMinor == 6); + CHECK(sp::floor_for_card(13580, total, sp::Card{3.14, 12.2, 84}) == 3584); + CHECK(sp::share_limit_for(3584) == 5632); + CHECK(sp::floor_for_card(7836, total, sp::Card{1.44, 11.0, 48}) == 2048); + CHECK(sp::share_limit_for(2048) == 3072); + } + + if (failed) { + std::fprintf(stderr, "switch_point_rule_test: %d check(s) failed\n", failed); + return 1; + } + std::printf("switch_point_rule_test: OK\n"); + return 0; +}