diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e81f9a3..47ec99c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -402,6 +402,21 @@ if(STRATA_ENABLE_CUDA OR STRATA_ENABLE_HIP) src/ngram/ple_reader.cpp src/platform/direct_file.cpp) target_link_libraries(strata_kernels PUBLIC strata_core strata_artifact) + # Exact gfx1100 prompt scorer (PR1825 method port): optional standalone test, + # also available where the published source omits tests/. + option(STRATA_PARITY_GFX1100_QSA_SCORES "Build the exact gfx1100 QSA score/ID check" OFF) + if(STRATA_ENABLE_HIP AND (STRATA_BUILD_TESTS OR STRATA_PARITY_GFX1100_QSA_SCORES)) + set_source_files_properties(src/kernels/cuda/qsa_scores_gfx1100_test.cu + src/kernels/qsa_scores_gfx1100_parity.cpp PROPERTIES LANGUAGE HIP) + add_executable(qsa_scores_gfx1100_parity src/kernels/qsa_scores_gfx1100_parity.cpp + src/kernels/cuda/qsa_scores_gfx1100_test.cu) + target_include_directories(qsa_scores_gfx1100_parity PRIVATE ${_strata_gpu_include_directories}) + target_link_libraries(qsa_scores_gfx1100_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target}) + enable_testing() + add_test(NAME qsa_scores_gfx1100_parity COMMAND qsa_scores_gfx1100_parity --full) + set_tests_properties(qsa_scores_gfx1100_parity PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 180 + ENVIRONMENT "STRATA_SCORES_THREAD=1;STRATA_SCORES_THREAD_TRACE=1") + endif() # perf-review D-1: the tensor-core prompt attention vs the FP32 kernel and FP64 (GPU, synthetic, no model); with # the tests, or alone with -DSTRATA_PARITY_PROMPT_ATTN=ON. CUDA only: HIP compiles the tensor-core kernel out. if((STRATA_BUILD_TESTS OR STRATA_PARITY_PROMPT_ATTN) AND STRATA_ENABLE_CUDA) @@ -744,6 +759,12 @@ if(STRATA_ENABLE_CUDA OR STRATA_ENABLE_HIP) target_link_libraries(hip_gdn_rec_head PRIVATE strata_prefill strata_hip_runtime) add_test(NAME hip_gdn_rec_head COMMAND hip_gdn_rec_head) list(APPEND _strata_hip_tests hip_gdn_rec_head) + add_executable(hip_gdn_chunked tests/hip/gdn_chunked.cpp) + target_link_libraries(hip_gdn_chunked PRIVATE strata_prefill strata_hip_runtime) + add_test(NAME hip_gdn_chunked COMMAND hip_gdn_chunked) + add_test(NAME hip_gdn_chunked_off COMMAND hip_gdn_chunked --off) + add_test(NAME hip_gdn_chunked_default COMMAND hip_gdn_chunked --default) + list(APPEND _strata_hip_tests hip_gdn_chunked hip_gdn_chunked_off hip_gdn_chunked_default) # #313: the RDNA3 / RDNA3.5 WMMA dense GEMMs (opt-in STRATA_WMMA_GEMM=1) against a reference add_executable(hip_prefill_wmma_gemm_parity tests/hip/prefill_wmma_gemm_parity.cpp) target_include_directories(hip_prefill_wmma_gemm_parity PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src/prefill") @@ -1040,6 +1061,13 @@ if(STRATA_ENABLE_CUDA OR STRATA_ENABLE_HIP) target_include_directories(gr_multi_parity PRIVATE ${_strata_gpu_include_directories}) target_link_libraries(gr_multi_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target}) add_test(NAME gr_multi_parity COMMAND gr_multi_parity) + # STRATA_HC_PERSIST=1: the persistent hyper-connection read against the default multi read (bounded, two runs bitwise), + # and with the variable unset it never runs (a skip where the card cannot hold its 80 blocks, and on CUDA) + add_executable(hc_persist_parity src/kernels/hc_persist_parity.cpp) + target_include_directories(hc_persist_parity PRIVATE ${_strata_gpu_include_directories}) + target_link_libraries(hc_persist_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target}) + add_test(NAME hc_persist_parity COMMAND hc_persist_parity) + add_test(NAME hc_persist_default_off COMMAND hc_persist_parity --off) if(STRATA_HIP_GFX906) # the S6 router (STRATA_HIP_ROUTER_FAST=1 on gfx906) against the portable kernel, bitwise, on wave64 add_executable(hip_router_fast tests/hip/router_fast.cpp) @@ -1674,6 +1702,7 @@ if(STRATA_NATIVE_EXPERTS) src/prefill/moe_mmq.cu src/prefill/moe_fused.cu src/prefill/moe_fused_iq.cu + src/prefill/moe_f16_kq.cu src/prefill/ggml_cuda_host.cu "${_strata_mmq}/quantize.cu") if(STRATA_MMQ_KQUANTS) @@ -1686,7 +1715,7 @@ if(STRATA_NATIVE_EXPERTS) endforeach() set_source_files_properties(${_strata_mmq_sources} PROPERTIES LANGUAGE HIP) # moe_fused.cu is Strata's own CUDA-shaped source: it takes the HIP compat headers, ggml's MMQ sources do not - set_source_files_properties(src/prefill/moe_fused.cu src/prefill/moe_fused_iq.cu + set_source_files_properties(src/prefill/moe_fused.cu src/prefill/moe_fused_iq.cu src/prefill/moe_f16_kq.cu PROPERTIES INCLUDE_DIRECTORIES "${STRATA_HIP_COMPAT_INCLUDE_DIR}") add_library(strata_mmq STATIC ${_strata_mmq_sources}) target_include_directories(strata_mmq @@ -1714,6 +1743,9 @@ if(STRATA_NATIVE_EXPERTS) target_link_libraries(hip_prefill_fused_iq PRIVATE strata_mmq ggml-base strata_hip_runtime) add_test(NAME hip_prefill_fused_iq COMMAND hip_prefill_fused_iq) set_tests_properties(hip_prefill_fused_iq PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 600) + # the same binary on F16 weights (gfx11: the covered formats take moe_f16_kq.cu / native_f16_kernel; elsewhere it is the default run again) + add_test(NAME hip_prefill_fused_iq_f16 COMMAND hip_prefill_fused_iq) + set_tests_properties(hip_prefill_fused_iq_f16 PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 600 ENVIRONMENT "STRATA_PF_F16=1;STRATA_PF_F16_KQ=1") list(APPEND _strata_hip_tests hip_prefill_fused_iq) # Numerical diagnostic: synthetic layouts by default, optional first-expert IQ3_XXS/IQ4_NL check with a pack. diff --git a/bench/results/2026-10-11-gfx1100-qsa-scores/README.md b/bench/results/2026-10-11-gfx1100-qsa-scores/README.md new file mode 100644 index 00000000..82e31bf7 --- /dev/null +++ b/bench/results/2026-10-11-gfx1100-qsa-scores/README.md @@ -0,0 +1,216 @@ +# Exact gfx1100 QSA scorer: measured prefill benefit, opt-in only + +Measured on 2026-10-11 on one RX 7900 XTX. This accompanies the HIP port of the +four-lanes-per-query score kernel from [PR #1825](https://github.com/Niko1221/Strata/pull/1825) +by xrip, pinned to `14bf32150490bb9f5fc4d9c7c5dcfdc96dd98797`. That PR's code excludes +HIP; its algorithm and reduction order are the source of this port. This is an +AMD extension, not a claim to invent that method. + +The measured benefit is fresh long-prompt processing. The correction-inclusive +coding pilot was 3.3% slower overall. The new path is disabled by default and was +not promoted into the tested machine's production setup. + +## Dispatch and implementation + +Set `STRATA_SCORES_THREAD=1` **before starting the engine**. Dispatch also requires: + +- HIP on the exact `gfx1100` architecture (normal feature suffixes are accepted). +- At least 64 queries and a supplied live bound of at least 16,385 index blocks. +- A live bound no larger than the allocated score capacity. Allocating a 256K + context alone does not select the new kernel. +- The already supported indexer geometry: four heads, dimension 128, block size 4. + +Otherwise the existing scorer runs. Decode, top-k, weights, expert placement, +PLE storage, and sampling are not changed by this patch. CUDA does not compile +the HIP addition. No extra persistent weights or conversation state are allocated. + +The kernel uses four wave32 lanes per query and keeps all four heads in registers. +Each key tile in LDS serves 64 queries. The original FP32 per-lane expression and +xor reduction tree are preserved; the existing tail scorer handles the final block. +The retained layout is 64 queries by 32 key blocks, 512 key blocks per workgroup, +256 threads. Four layout variants were screened; none improved stage time by the +predeclared 10% threshold over this one, so the first layout was retained. + +`STRATA_SCORES_THREAD_TRACE=1` optionally prints one engagement line per host thread. +No trace output is enabled by default. + +## Machine and shared settings + +- RX 7900 XTX, 24 GiB nominal VRAM, gfx1100; PCIe 4.0 x16 observed; fixed 272 W cap. +- Ryzen 9 7950X3D; 64 GiB installed RAM, approximately 62 GiB reported by Linux. +- Nobara 44; kernel `7.2.9-200.nobara.fc44.x86_64`; ROCm SDK 10.0.0. +- [OrcaRouter Qwen3.8 Flash Next Uncensored](https://huggingface.co/orcarouter/Qwen3.8-Flash-Next-Uncensored-GGUF), + IQ3_S. Exact shard names, pack/profile hashes, and configuration are in + [provenance.json](provenance.json). The Hugging Face revision was not recorded. +- One GPU, one server, 15 CPU expert workers; logical context 262,144; int8 KV, + 32,768 resident KV cells; prefill chunk 16,384; spec/MTP 6, floor 0.70, maximum T 6. +- Same balanced expert profile in every arm; 8,144 actual GPU expert slots, + 16,622,003,200 blob bytes; 34 GiB resident budget and 1,024 MiB conversation cache. +- NVMe model storage; PLE lookup shard on a dedicated ext4 SSD partition with + direct I/O. The lookup was not moved into RAM. GPU vision was enabled but no + image prompt was used in these measurements. +- Private experiment cgroup: 56 GiB memory cap, swap limit zero; at least 8 GiB + available host memory required. This is not a claim that system-wide swap was disabled. +- Same local prefix-cache frontend and chat template for both arms. Its hashes + are recorded. The stock latest Python frontend was not benchmarked here. + +The repeated model tests used the reconstructed tuned 0.1.40.3 engine, including +PR #1107 prefix reuse and resident-budget loans in **both** arms. They compare the +installed control against its reconstructed candidate, not two official release +binaries. A separate comparison builds current main at +`61b3fb5dd3f1e8ec09cf7e4e05208bc6d3c46406` plus this patch and uses the **same binary** +with `STRATA_SCORES_THREAD=0` and `1`. Those families are never pooled. + +## Before and after + +The full per-request values, native prompt/decode timing, token counts, output +hashes, means, medians, and ranges are in [measurements.json](measurements.json). +These are **non-streaming request times with a one-token cap**. Model loading and +queueing were excluded; streaming time to first token and sustained generation +throughput were not measured by this screen. + +Each fresh case starts a new private model worker. Actual reused prefix tokens +were zero. The OS file cache was not flushed, so these are fresh model prompts, +not cold-boot storage benchmarks. Inputs are repeated numerical source code, +greedy sampling, seed 6300, reasoning disabled. They are a prefill screen, not a +quality evaluation or representative project-completion benchmark. + +| Engine family | Actual fresh tokens | Pairs | Before mean | After mean | Less elapsed time | +| --- | ---: | ---: | ---: | ---: | ---: | +| tuned-v0.1.40.3 | 130,978 | 3 | 66.741 s | 59.769 s | 10.45% | +| tuned-v0.1.40.3 | 239,906 | 3 | 142.718 s | 110.407 s | 22.64% | +| current-main-same-binary | 130,978 | 1 | 68.872 s | 60.020 s | 12.85% | +| current-main-same-binary | 239,906 | 1 | 142.843 s | 111.828 s | 21.71% | + +| Tuned build fresh tokens | Before median (range) | After median (range) | +| --- | ---: | ---: | +| 130,978 | 67.514 (64.257–68.451) s | 59.465 (58.863–60.979) s | +| 239,906 | 142.059 (141.660–144.436) s | 110.438 (109.549–111.232) s | + +**Cached follow-ups (2,085 new tokens):** + +| Engine family | Reused prefix | Pairs | Before mean | After mean | Less elapsed time | +| --- | ---: | ---: | ---: | ---: | ---: | +| tuned-v0.1.40.3 | 130,978 | 2 | 2.829 s | 2.658 s | 6.023% | +| tuned-v0.1.40.3 | 239,906 | 2 | 3.418 s | 3.417 s | 0.035% | +| current-main-same-binary | 130,978 | 1 | 2.896 s | 2.781 s | 3.965% | +| current-main-same-binary | 239,906 | 1 | 3.522 s | 2.958 s | 16.037% | + +The repeated near240K cached result is effectively flat (0.035%). The current-main +follow-ups are single pairs and do not establish a repeatable cached-prefix gain. + +**Submitted CMake scorer microbenchmark:** + +| Scorer-only live context | Queries | Before | After | Stage speedup | +| --- | ---: | ---: | ---: | ---: | +| 131,072 | 256 | 3.065300 ms | 0.742917 ms | 4.126x | +| 240,000 | 256 | 5.264949 ms | 1.389344 ms | 3.790x | + +The repeated family used orders off/on, on/off, off/on. All three fresh request +pairs at each length had the same input hash, output hash, and output count. +Cached continuations in trials 2 and 3 added 2,085 actually processed tokens and +reused the preceding 130,978 or 239,906 tokens. Trial 1's much smaller continuation +is retained in the raw data but excluded from the 2K continuation summary. +The follow-up inserts a fixed synthetic assistant message; it does not use the +one generated token as a complete conversational answer. This isolates prefix +reuse and incremental prompt processing. + +## Correctness and build checks + +The submitted HIP CMake target passed 35 cases comparing against the unchanged +warp scorer: **223,664,777 score values bitwise equal**, and **11,895,800 ID buffer +entries equal**, including padding. Allocation guards passed. Cases cover +query counts 1/6/8/9/63/64/65/127/128/129/256/1024; the 65,535–65,539 boundary, +128K and 256K; capacity versus live extent; absent/negative/oversized bounds; +random and wide-exponent floats, ties, signed zero, NaN/Inf and cancellation. + +The same compiled CMake test provides warmed, interleaved ABBA GPU-event timings +with four trials and ten calls per trial. See [correctness.json](correctness.json). +At the real 256-query batch size, this tests the scorer stage rather than making +a claim about whole-request or whole-task speed from a microbenchmark. + +On the tuned model, the 4K/131K prefill plus first generated token matched the +control's main state byte for byte. Separate 64-token continuations and +STOP/resend output checks matched. Full internal state after 64 speculative tokens +was not always byte-identical; the original binary also produced differing +speculative states across repeats. This does not establish the cause of the coding +pilot's different repair paths. No claim of universal bitwise model output is made. + +- Current-main full HIP engine and the standalone CMake test target built with + ROCm 10.0.0, Release, gfx1100, native experts and optional prefill MMQ enabled. +- The touched `qsa_select.cu` also compiled with CUDA 13.0 for sm_89. There was no + CUDA GPU test or full CUDA-engine build. No SYCL source was changed. +- Current-main off/on model requests completed with matching input/output hashes. +- Unsupported GPU architectures were not runtime-tested on hardware. + +Build and run the standalone check even from the published tree without `tests/`: + +```bash +cmake -S . -B build-qsa -G Ninja -DCMAKE_BUILD_TYPE=Release \ + -DSTRATA_ENABLE_HIP=ON -DCMAKE_HIP_ARCHITECTURES=gfx1100 \ + -DSTRATA_BUILD_TESTS=OFF -DSTRATA_PARITY_GFX1100_QSA_SCORES=ON +cmake --build build-qsa --target qsa_scores_gfx1100_parity -j 6 +ctest --test-dir build-qsa --output-on-failure -R '^qsa_scores_gfx1100_parity$' +``` + +Supply your normal ROCm compiler/package paths if they are not discoverable. +CTest sets the opt-in and engagement-trace variables and skips non-gfx1100 cards +with return code 77. + +## Coding pilot and limitations + +Two official Exercism/Aider Polyglot tasks, Go alphametics and Rust xorcism, were +embedded in a 196,608-token source archive, leaving 65,536 tokens within the 256K +window for tool results and repairs. xhigh, 8,192 reasoning tokens, 2,048 answer +reserve, temperature 0.3, top_p 0.95, top_k 20, min_p 0; one matched trial per task, +seeds 7830/7831. Tools and full-suite checks ran until the first pass, with no +post-pass requests. This is a long-context stress pilot, **not an official Aider +leaderboard score**. Its test and correction time is included. + +| Task | Original | New scorer | Original/new turns | Result | +| --- | ---: | ---: | ---: | --- | +| go/alphametics | 209.136 s | 400.318 s | 3 / 5 | Both full suites passed | +| rust/xorcism | 473.734 s | 304.906 s | 6 / 6 | Both full suites passed | +| Total | 682.870 s | 705.225 s | | New scorer **3.27% slower** | + +The different Go run generated more tokens and took extra repair turns despite +matching normalized inputs through the first three requests. The cause remains +unresolved. The combined pilot did not meet the predeclared promotion gate. More +coding repeats, the held-out extension, and the full 24-task suite were therefore +not run. No Luna, frontier-model, or overall agent-quality superiority is claimed. + +An earlier 240K-archive pilot ran out of continuation space: the Rust history +reached 262,714 tokens, beyond 262,144. Its partial attempt is listed separately +in the data and was not reused in the 192K score. It was a benchmark-protocol +failure, not evidence of a scorer crash. + +## Reproducing the request screen + +[benchmark.py](benchmark.py) generates the exact frozen fresh/continuation request +hashes used here from the included compressed numerical-source fixture. It reads +the model pack's tokenizer and uses only Python plus the existing tokenizer's +`regex` dependency. The supplied [hipBLASLt table](hipblaslt-gfx1100-100401.txt) is +specific to this SDK/device pair; do not assume its solution IDs transfer to another +version. The balanced expert profile is identified by hash, not included; use the +same profile and other settings in your two arms. + +Run a loaded private server with the same binary and settings, changing only +`STRATA_SCORES_THREAD=0` or `1` **at startup**. Restart that worker between every +length/arm invocation, preserve every observation, and repeat in both orders: + +```bash +python bench/results/2026-10-11-gfx1100-qsa-scores/benchmark.py \ + --url http://127.0.0.1:8080 --tokenizer /path/to/pack/tokenizer \ + --model strata-qwen38-iq3s-uncensored --length 131072 \ + --variant off --output off-128k-trial1.json +``` + +Then restart with the scorer enabled and use `--variant on` and a new output file. +Repeat with `--length 240000`, then reverse arm order. Use `--prepare-only` to +check request hashes without inference. `STRATA_API_KEY` can supply an API key; +it is never written to results. The script refuses to overwrite any attempt and +records a failure if a fresh prompt reused cached tokens. + +The label does not control the server's environment: confirm the startup setting +and, in the enabled arm, the engagement trace. Measure your model's full output +and correction-inclusive workload separately before adopting the feature. diff --git a/bench/results/2026-10-11-gfx1100-qsa-scores/benchmark.py b/bench/results/2026-10-11-gfx1100-qsa-scores/benchmark.py new file mode 100644 index 00000000..e22d547a --- /dev/null +++ b/bench/results/2026-10-11-gfx1100-qsa-scores/benchmark.py @@ -0,0 +1,137 @@ +"""One fresh prompt and one cached continuation; restart the server between invocations. + +Use the same engine/config with STRATA_SCORES_THREAD=0 or 1 at server startup. +Model loading is excluded. This measures request latency, not streaming TTFT or coding quality. +""" +import argparse +import gzip +import hashlib +import importlib.util +import json +import os +from pathlib import Path +import time +import urllib.error +import urllib.request + +HERE = Path(__file__).resolve().parent +REPO = HERE.parents[2] + + +def digest(data): + return hashlib.sha256(data).hexdigest() + + +def load_tokenizer(folder): + spec = importlib.util.spec_from_file_location('qsa_bench_tokenizer', REPO / 'tools/strata_tokenizer.py') + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + vocab = json.loads((folder / 'vocab.json').read_text()) + tokens = [None] * len(vocab) + for token, index in vocab.items(): + tokens[index] = token + return module.Tokenizer(tokens, (folder / 'merges.txt').read_text().split('\n'), + json.loads((folder / 'token_type.json').read_text())) + + +def make_requests(tokenizer, source, length, model, follow_tokens): + ids = tokenizer.encode(source) + if not ids or not 0 <= follow_tokens <= len(ids): + raise ValueError('Empty source or invalid continuation size') + text = tokenizer.decode((ids * (length // len(ids) + 1))[:length - 128]) + body = dict(model=model, temperature=0, top_p=1, top_k=1, seed=6300, + reasoning_effort='none', max_tokens=1, messages=[ + dict(role='system', content='You are a precise coding assistant.'), + dict(role='user', content=text + '\nReview the numerical implementation and synchronization in detail.')]) + follow = json.loads(json.dumps(body)) + follow['messages'].extend([ + dict(role='assistant', content='I will inspect the numerical implementation.'), + dict(role='user', content='Continue with a detailed review of synchronization and memory lifetime.')]) + if follow_tokens: + follow['messages'][-1]['content'] += '\nADDITIONAL_SOURCE\n' + tokenizer.decode(ids[-follow_tokens:]) + return [('fresh-' + str(length), body), ('follow-' + str(length), follow)] + + +def fetch(url, body=None): + headers = {'Content-Type': 'application/json'} + key = os.environ.get('STRATA_API_KEY') + if key: + headers['Authorization'] = 'Bearer ' + key + req = urllib.request.Request(url, data=json.dumps(body).encode() if body is not None else None, + headers=headers) + with urllib.request.urlopen(req, timeout=900) as response: + return json.load(response) + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('--url', default='http://127.0.0.1:8080') + parser.add_argument('--tokenizer', type=Path, required=True) + parser.add_argument('--model', default='strata-qwen38-iq3s-uncensored') + parser.add_argument('--length', type=int, choices=[131072, 240000], required=True) + parser.add_argument('--follow-tokens', type=int, default=2048) + parser.add_argument('--source', type=Path, default=HERE / 'prompt-source.txt.gz') + parser.add_argument('--variant', choices=['off', 'on'], required=True) + parser.add_argument('--output', type=Path, required=True) + parser.add_argument('--prepare-only', action='store_true') + args = parser.parse_args() + source = gzip.decompress(args.source.read_bytes()) if args.source.suffix == '.gz' else args.source.read_bytes() + requests = make_requests(load_tokenizer(args.tokenizer), source.decode(), args.length, + args.model, args.follow_tokens) + receipt = dict(variant=args.variant, length=args.length, output_cap=1, seed=6300, + temperature=0, reasoning_effort='none', follow_source_tokens=args.follow_tokens, + source_sha256=digest(source), script_sha256=digest(Path(__file__).read_bytes()), + prepare_only=args.prepare_only, rows=[], status='prepared') + # Refuse to overwrite previous observations, including failed attempts. + with args.output.open('x') as output: + def save(): + output.seek(0) + json.dump(receipt, output, indent=2) + output.write('\n') + output.truncate() + output.flush() + try: + save() + if args.prepare_only: + receipt['request_hashes'] = {case: digest(json.dumps(body).encode()) for case, body in requests} + save() + return + health = fetch(args.url.rstrip('/') + '/health') + if not health.get('loaded') or health.get('max_context') != 262144: + raise RuntimeError('Requires an already loaded 262144-context server') + for case, body in requests: + started = time.monotonic() + response = fetch(args.url.rstrip('/') + '/v1/chat/completions', body) + elapsed = time.monotonic() - started + metrics = fetch(args.url.rstrip('/') + '/metrics?requests=all') + native = max(metrics['requests'], key=lambda row: row['time']) + choice = response['choices'][0] + message = choice.get('message', {}) + row = dict(case=case, seconds=elapsed, usage=response.get('usage'), + finish_reason=choice['finish_reason'], + request_sha256=digest(json.dumps(body).encode()), + output_sha256=digest(((message.get('reasoning_content') or '') + '\n' + + (message.get('content') or '')).encode()), + native={k: native.get(k) for k in ( + 'prompt_tokens', 'reused', 'prompt_read', 'output_tokens', 'engine_generated', + 'prompt_ms', 'decode_ms', 'drafts_offered', 'drafts_accepted', + 'hit_rate', 'ram_blobs', 'file_blobs', 'file_mb')}) + receipt['rows'].append(row) + save() + if choice['finish_reason'] not in ('length', 'stop'): + raise RuntimeError('Request did not complete normally') + if case.startswith('fresh-') and native.get('reused') != 0: + raise RuntimeError('Fresh prompt reused a prefix: restart the server and use a NEW output file') + receipt['status'] = 'complete' + save() + except Exception as error: + receipt['status'] = 'failed' + receipt['error'] = str(error) + if isinstance(error, urllib.error.HTTPError): + receipt['http_status'] = error.code + save() + raise + + +if __name__ == '__main__': + main() diff --git a/bench/results/2026-10-11-gfx1100-qsa-scores/correctness.json b/bench/results/2026-10-11-gfx1100-qsa-scores/correctness.json new file mode 100644 index 00000000..0fc79c15 --- /dev/null +++ b/bench/results/2026-10-11-gfx1100-qsa-scores/correctness.json @@ -0,0 +1,19 @@ +{ + "returncode": 0, + "bitwise_qualification": "1: QUALIFIED cases=35 expected_thread_cases=26 scores=223664777 ids=11895800 bitwise_scores=true bitwise_ids=true guards=true", + "dispatch_observed": true, + "timings": [ + "1: TIMING ctx=131072 nq=256 baseline_ms=3.065300 candidate_ms=0.742917 speedup=4.126034 trials=4 repeats_per_trial=10", + "1: TIMING ctx=240000 nq=256 baseline_ms=5.264949 candidate_ms=1.389344 speedup=3.789521 trials=4 repeats_per_trial=10", + "1: TIMING ctx=140000 nq=1024 baseline_ms=13.833862 candidate_ms=3.112324 speedup=4.444866 trials=4 repeats_per_trial=10", + "1: TIMING ctx=240000 nq=1024 baseline_ms=25.035099 candidate_ms=4.841821 speedup=5.170596 trials=4 repeats_per_trial=10" + ], + "resource_pass": true, + "cases": 35, + "scores_checked": 223664777, + "id_entries_checked": 11895800, + "numeric_scope": "Synthetic scores/selected IDs, including padding and allocation guards", + "real_model_state_scope": "4K/131K prefill and first token byte-exact against tuned control; longer MTP sequences may have different internal speculative states even on original binary", + "continuation_scope": "64-token original/candidate output and STOP/resend output match; not full-state equality after64MTPtokens", + "unsupported_architecture_runtime_tested": false +} diff --git a/bench/results/2026-10-11-gfx1100-qsa-scores/hipblaslt-gfx1100-100401.txt b/bench/results/2026-10-11-gfx1100-qsa-scores/hipblaslt-gfx1100-100401.txt new file mode 100644 index 00000000..839434c5 --- /dev/null +++ b/bench/results/2026-10-11-gfx1100-qsa-scores/hipblaslt-gfx1100-100401.txt @@ -0,0 +1,34 @@ +# solution IDs are scoped to this hipBLASLt version and device architecture +STRATA_HIPBLASLT_TUNING_V1 gfx1100 100401 +bf16 1 2560 1 4096 1035 +bf16 4 10240 4 8192 1033 +bf16 48 2560 96 4096 1035 +bf16 48 2560 96 8192 1036 +bf16 128 2560 128 4096 1036 +bf16 128 2560 128 8192 1036 +bf16 320 10240 320 4096 1036 +bf16 320 10240 320 8192 1036 +bf16 512 2560 512 8192 1036 +bf16 2560 2560 2560 8192 1036 +bf16 10240 320 10240 4096 1036 +bf16 10240 320 10240 8192 1036 +f16 512 2560 512 4096 2106 +f16 512 2560 512 8192 2106 +f16 640 2560 640 4096 2106 +f16 640 2560 640 8192 2106 +f16 2560 640 2560 4096 2106 +f16 2560 640 2560 8192 2106 +f16 2560 6144 2560 4096 2106 +f16 2560 6144 2560 8192 2106 +f16 6144 2560 6144 4096 2106 +f16 6144 2560 6144 8192 2106 +f16 10240 2560 10240 4096 2106 +f16 10240 2560 10240 8192 2106 +f16 12288 2560 12288 4096 2106 +f16 12288 2560 12288 8192 2106 +bf16 1 2560 1 8192 1035 +bf16 10240 2560 10240 4096 1036 +bf16 10240 2560 10240 8192 1036 +bf16 2560 2560 2560 4096 1036 +bf16 4 10240 4 4096 1035 +bf16 512 2560 512 4096 1036 diff --git a/bench/results/2026-10-11-gfx1100-qsa-scores/measurements.json b/bench/results/2026-10-11-gfx1100-qsa-scores/measurements.json new file mode 100644 index 00000000..a191c647 --- /dev/null +++ b/bench/results/2026-10-11-gfx1100-qsa-scores/measurements.json @@ -0,0 +1,1091 @@ +{ + "units": { + "seconds": "client request elapsed seconds", + "native_prompt_ms": "engine prefill milliseconds", + "native_decode_ms": "engine generation milliseconds" + }, + "model_loading_included": false, + "streaming_ttft_measured": false, + "logical_context": 262144, + "settings": { + "temperature": 0, + "top_p": 1, + "top_k": 1, + "seed": 6300, + "reasoning_effort": "none", + "output_cap": 1 + }, + "fresh_os_cache_state": "uncontrolled; OS cache not flushed", + "source": { + "file": "prompt-source.txt.gz", + "uncompressed_sha256": "43caa800023d7e223629ab8c6a28bd10c50b56c2dd7232b2b5fa4c00144b2e98" + }, + "rows": [ + { + "family": "tuned-v0.1.40.3", + "trial": "qsa-exact-native1", + "arm": "0-A-131072", + "case": "fresh-131072", + "follow_source_tokens": 0, + "seconds": 64.25693084098748, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "029dc64c403bd9597b2a143399fa64555b40b8a4910c708fe3f7c3ddc5a1ad25", + "output_sha256": "d6fadeb81a0f0a9f23a6a06f4c0f266f0afe25f436a0aa575ac593e2d695c969", + "prompt_tokens": 130978, + "reused_tokens": 0, + "freshly_processed_tokens": 130978, + "native_prompt_ms": 64157.7, + "native_decode_ms": 27.1, + "hit_rate": 0.787, + "ram_blobs": 102, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "tuned-v0.1.40.3", + "trial": "qsa-exact-native1", + "arm": "0-A-131072", + "case": "follow-131072", + "follow_source_tokens": 0, + "seconds": 0.34837336000055075, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "04d4aba48d6b685765f804b257d6a2872758acf1c10c942ab83d93dd55649fde", + "output_sha256": "33462c6ad8d3c9823e7b43633ff1a94f7671c4d155888e47618b5f60027701e5", + "prompt_tokens": 131010, + "reused_tokens": 130978, + "freshly_processed_tokens": 32, + "native_prompt_ms": 303.6, + "native_decode_ms": 19.4, + "hit_rate": 0.769, + "ram_blobs": 111, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "tuned-v0.1.40.3", + "trial": "qsa-exact-native1", + "arm": "0-A-240000", + "case": "fresh-240000", + "follow_source_tokens": 0, + "seconds": 142.0591052029922, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "dbb6d4004af260501404a2674660c00523b1c455ba557d431395dab5cee7c4dd", + "output_sha256": "d6fadeb81a0f0a9f23a6a06f4c0f266f0afe25f436a0aa575ac593e2d695c969", + "prompt_tokens": 239906, + "reused_tokens": 0, + "freshly_processed_tokens": 239906, + "native_prompt_ms": 141910.0, + "native_decode_ms": 28.8, + "hit_rate": 0.779, + "ram_blobs": 106, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "tuned-v0.1.40.3", + "trial": "qsa-exact-native1", + "arm": "0-A-240000", + "case": "follow-240000", + "follow_source_tokens": 0, + "seconds": 0.3739995119976811, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "bd5c8f85d96ecd7db994611c323e1a644be0b8c66fd6ec2386ae2b23dbdafb34", + "output_sha256": "33462c6ad8d3c9823e7b43633ff1a94f7671c4d155888e47618b5f60027701e5", + "prompt_tokens": 239938, + "reused_tokens": 239906, + "freshly_processed_tokens": 32, + "native_prompt_ms": 302.6, + "native_decode_ms": 21.4, + "hit_rate": 0.756, + "ram_blobs": 117, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "tuned-v0.1.40.3", + "trial": "qsa-exact-native1", + "arm": "1-B-131072", + "case": "fresh-131072", + "follow_source_tokens": 0, + "seconds": 60.97881687400513, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "029dc64c403bd9597b2a143399fa64555b40b8a4910c708fe3f7c3ddc5a1ad25", + "output_sha256": "d6fadeb81a0f0a9f23a6a06f4c0f266f0afe25f436a0aa575ac593e2d695c969", + "prompt_tokens": 130978, + "reused_tokens": 0, + "freshly_processed_tokens": 130978, + "native_prompt_ms": 60863.3, + "native_decode_ms": 40.1, + "hit_rate": 0.787, + "ram_blobs": 102, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "tuned-v0.1.40.3", + "trial": "qsa-exact-native1", + "arm": "1-B-131072", + "case": "follow-131072", + "follow_source_tokens": 0, + "seconds": 0.36607142200227827, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "04d4aba48d6b685765f804b257d6a2872758acf1c10c942ab83d93dd55649fde", + "output_sha256": "33462c6ad8d3c9823e7b43633ff1a94f7671c4d155888e47618b5f60027701e5", + "prompt_tokens": 131010, + "reused_tokens": 130978, + "freshly_processed_tokens": 32, + "native_prompt_ms": 316.8, + "native_decode_ms": 20.0, + "hit_rate": 0.769, + "ram_blobs": 111, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "tuned-v0.1.40.3", + "trial": "qsa-exact-native1", + "arm": "1-B-240000", + "case": "fresh-240000", + "follow_source_tokens": 0, + "seconds": 109.54931649801438, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "dbb6d4004af260501404a2674660c00523b1c455ba557d431395dab5cee7c4dd", + "output_sha256": "d6fadeb81a0f0a9f23a6a06f4c0f266f0afe25f436a0aa575ac593e2d695c969", + "prompt_tokens": 239906, + "reused_tokens": 0, + "freshly_processed_tokens": 239906, + "native_prompt_ms": 109397.8, + "native_decode_ms": 29.1, + "hit_rate": 0.779, + "ram_blobs": 106, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "tuned-v0.1.40.3", + "trial": "qsa-exact-native1", + "arm": "1-B-240000", + "case": "follow-240000", + "follow_source_tokens": 0, + "seconds": 0.3701446990016848, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "bd5c8f85d96ecd7db994611c323e1a644be0b8c66fd6ec2386ae2b23dbdafb34", + "output_sha256": "33462c6ad8d3c9823e7b43633ff1a94f7671c4d155888e47618b5f60027701e5", + "prompt_tokens": 239938, + "reused_tokens": 239906, + "freshly_processed_tokens": 32, + "native_prompt_ms": 300.3, + "native_decode_ms": 21.4, + "hit_rate": 0.756, + "ram_blobs": 117, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "tuned-v0.1.40.3", + "trial": "qsa-exact-native2", + "arm": "0-B-131072", + "case": "fresh-131072", + "follow_source_tokens": 2048, + "seconds": 58.86296121100895, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "029dc64c403bd9597b2a143399fa64555b40b8a4910c708fe3f7c3ddc5a1ad25", + "output_sha256": "d6fadeb81a0f0a9f23a6a06f4c0f266f0afe25f436a0aa575ac593e2d695c969", + "prompt_tokens": 130978, + "reused_tokens": 0, + "freshly_processed_tokens": 130978, + "native_prompt_ms": 58764.6, + "native_decode_ms": 27.6, + "hit_rate": 0.787, + "ram_blobs": 102, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "tuned-v0.1.40.3", + "trial": "qsa-exact-native2", + "arm": "0-B-131072", + "case": "follow-131072", + "follow_source_tokens": 2048, + "seconds": 2.629391199006932, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "9f2979c0f702e087be57384d4b312a89f606961d08f0beaff64abd550b91b41d", + "output_sha256": "d6fadeb81a0f0a9f23a6a06f4c0f266f0afe25f436a0aa575ac593e2d695c969", + "prompt_tokens": 133063, + "reused_tokens": 130978, + "freshly_processed_tokens": 2085, + "native_prompt_ms": 2580.1, + "native_decode_ms": 20.5, + "hit_rate": 0.758, + "ram_blobs": 116, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "tuned-v0.1.40.3", + "trial": "qsa-exact-native2", + "arm": "0-B-240000", + "case": "fresh-240000", + "follow_source_tokens": 2048, + "seconds": 110.438449467998, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "dbb6d4004af260501404a2674660c00523b1c455ba557d431395dab5cee7c4dd", + "output_sha256": "d6fadeb81a0f0a9f23a6a06f4c0f266f0afe25f436a0aa575ac593e2d695c969", + "prompt_tokens": 239906, + "reused_tokens": 0, + "freshly_processed_tokens": 239906, + "native_prompt_ms": 110293.6, + "native_decode_ms": 29.2, + "hit_rate": 0.779, + "ram_blobs": 106, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "tuned-v0.1.40.3", + "trial": "qsa-exact-native2", + "arm": "0-B-240000", + "case": "follow-240000", + "follow_source_tokens": 2048, + "seconds": 3.935525797016453, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "523b45e7fa9be241cf0434f58ef29285c15a565df7779dae176d8f5a4df2626e", + "output_sha256": "33462c6ad8d3c9823e7b43633ff1a94f7671c4d155888e47618b5f60027701e5", + "prompt_tokens": 241991, + "reused_tokens": 239906, + "freshly_processed_tokens": 2085, + "native_prompt_ms": 3865.4, + "native_decode_ms": 22.2, + "hit_rate": 0.779, + "ram_blobs": 106, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "tuned-v0.1.40.3", + "trial": "qsa-exact-native2", + "arm": "1-A-131072", + "case": "fresh-131072", + "follow_source_tokens": 2048, + "seconds": 68.45079464002629, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "029dc64c403bd9597b2a143399fa64555b40b8a4910c708fe3f7c3ddc5a1ad25", + "output_sha256": "d6fadeb81a0f0a9f23a6a06f4c0f266f0afe25f436a0aa575ac593e2d695c969", + "prompt_tokens": 130978, + "reused_tokens": 0, + "freshly_processed_tokens": 130978, + "native_prompt_ms": 68353.8, + "native_decode_ms": 27.6, + "hit_rate": 0.787, + "ram_blobs": 102, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "tuned-v0.1.40.3", + "trial": "qsa-exact-native2", + "arm": "1-A-131072", + "case": "follow-131072", + "follow_source_tokens": 2048, + "seconds": 2.858728800987592, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "9f2979c0f702e087be57384d4b312a89f606961d08f0beaff64abd550b91b41d", + "output_sha256": "d6fadeb81a0f0a9f23a6a06f4c0f266f0afe25f436a0aa575ac593e2d695c969", + "prompt_tokens": 133063, + "reused_tokens": 130978, + "freshly_processed_tokens": 2085, + "native_prompt_ms": 2809.2, + "native_decode_ms": 20.2, + "hit_rate": 0.758, + "ram_blobs": 116, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "tuned-v0.1.40.3", + "trial": "qsa-exact-native2", + "arm": "1-A-240000", + "case": "fresh-240000", + "follow_source_tokens": 2048, + "seconds": 141.66012979499646, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "dbb6d4004af260501404a2674660c00523b1c455ba557d431395dab5cee7c4dd", + "output_sha256": "d6fadeb81a0f0a9f23a6a06f4c0f266f0afe25f436a0aa575ac593e2d695c969", + "prompt_tokens": 239906, + "reused_tokens": 0, + "freshly_processed_tokens": 239906, + "native_prompt_ms": 141512.5, + "native_decode_ms": 28.6, + "hit_rate": 0.779, + "ram_blobs": 106, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "tuned-v0.1.40.3", + "trial": "qsa-exact-native2", + "arm": "1-A-240000", + "case": "follow-240000", + "follow_source_tokens": 2048, + "seconds": 3.2768524099956267, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "523b45e7fa9be241cf0434f58ef29285c15a565df7779dae176d8f5a4df2626e", + "output_sha256": "33462c6ad8d3c9823e7b43633ff1a94f7671c4d155888e47618b5f60027701e5", + "prompt_tokens": 241991, + "reused_tokens": 239906, + "freshly_processed_tokens": 2085, + "native_prompt_ms": 3203.6, + "native_decode_ms": 21.5, + "hit_rate": 0.779, + "ram_blobs": 106, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "tuned-v0.1.40.3", + "trial": "qsa-exact-native3", + "arm": "0-A-131072", + "case": "fresh-131072", + "follow_source_tokens": 2048, + "seconds": 67.51405035398784, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "029dc64c403bd9597b2a143399fa64555b40b8a4910c708fe3f7c3ddc5a1ad25", + "output_sha256": "d6fadeb81a0f0a9f23a6a06f4c0f266f0afe25f436a0aa575ac593e2d695c969", + "prompt_tokens": 130978, + "reused_tokens": 0, + "freshly_processed_tokens": 130978, + "native_prompt_ms": 67406.7, + "native_decode_ms": 36.3, + "hit_rate": 0.792, + "ram_blobs": 100, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "tuned-v0.1.40.3", + "trial": "qsa-exact-native3", + "arm": "0-A-131072", + "case": "follow-131072", + "follow_source_tokens": 2048, + "seconds": 2.798884452000493, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "9f2979c0f702e087be57384d4b312a89f606961d08f0beaff64abd550b91b41d", + "output_sha256": "d6fadeb81a0f0a9f23a6a06f4c0f266f0afe25f436a0aa575ac593e2d695c969", + "prompt_tokens": 133063, + "reused_tokens": 130978, + "freshly_processed_tokens": 2085, + "native_prompt_ms": 2747.8, + "native_decode_ms": 20.4, + "hit_rate": 0.765, + "ram_blobs": 113, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "tuned-v0.1.40.3", + "trial": "qsa-exact-native3", + "arm": "0-A-240000", + "case": "fresh-240000", + "follow_source_tokens": 2048, + "seconds": 144.43555261398433, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "dbb6d4004af260501404a2674660c00523b1c455ba557d431395dab5cee7c4dd", + "output_sha256": "d6fadeb81a0f0a9f23a6a06f4c0f266f0afe25f436a0aa575ac593e2d695c969", + "prompt_tokens": 239906, + "reused_tokens": 0, + "freshly_processed_tokens": 239906, + "native_prompt_ms": 144288.4, + "native_decode_ms": 29.2, + "hit_rate": 0.779, + "ram_blobs": 106, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "tuned-v0.1.40.3", + "trial": "qsa-exact-native3", + "arm": "0-A-240000", + "case": "follow-240000", + "follow_source_tokens": 2048, + "seconds": 3.558641466021072, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "523b45e7fa9be241cf0434f58ef29285c15a565df7779dae176d8f5a4df2626e", + "output_sha256": "33462c6ad8d3c9823e7b43633ff1a94f7671c4d155888e47618b5f60027701e5", + "prompt_tokens": 241991, + "reused_tokens": 239906, + "freshly_processed_tokens": 2085, + "native_prompt_ms": 3486.1, + "native_decode_ms": 21.2, + "hit_rate": 0.775, + "ram_blobs": 108, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "tuned-v0.1.40.3", + "trial": "qsa-exact-native3", + "arm": "1-B-131072", + "case": "fresh-131072", + "follow_source_tokens": 2048, + "seconds": 59.46537054501823, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "029dc64c403bd9597b2a143399fa64555b40b8a4910c708fe3f7c3ddc5a1ad25", + "output_sha256": "d6fadeb81a0f0a9f23a6a06f4c0f266f0afe25f436a0aa575ac593e2d695c969", + "prompt_tokens": 130978, + "reused_tokens": 0, + "freshly_processed_tokens": 130978, + "native_prompt_ms": 59369.3, + "native_decode_ms": 27.0, + "hit_rate": 0.787, + "ram_blobs": 102, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "tuned-v0.1.40.3", + "trial": "qsa-exact-native3", + "arm": "1-B-131072", + "case": "follow-131072", + "follow_source_tokens": 2048, + "seconds": 2.687445471994579, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "9f2979c0f702e087be57384d4b312a89f606961d08f0beaff64abd550b91b41d", + "output_sha256": "d6fadeb81a0f0a9f23a6a06f4c0f266f0afe25f436a0aa575ac593e2d695c969", + "prompt_tokens": 133063, + "reused_tokens": 130978, + "freshly_processed_tokens": 2085, + "native_prompt_ms": 2634.6, + "native_decode_ms": 20.5, + "hit_rate": 0.758, + "ram_blobs": 116, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "tuned-v0.1.40.3", + "trial": "qsa-exact-native3", + "arm": "1-B-240000", + "case": "fresh-240000", + "follow_source_tokens": 2048, + "seconds": 111.23212432701257, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "dbb6d4004af260501404a2674660c00523b1c455ba557d431395dab5cee7c4dd", + "output_sha256": "d6fadeb81a0f0a9f23a6a06f4c0f266f0afe25f436a0aa575ac593e2d695c969", + "prompt_tokens": 239906, + "reused_tokens": 0, + "freshly_processed_tokens": 239906, + "native_prompt_ms": 111085.7, + "native_decode_ms": 31.8, + "hit_rate": 0.779, + "ram_blobs": 106, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "tuned-v0.1.40.3", + "trial": "qsa-exact-native3", + "arm": "1-B-240000", + "case": "follow-240000", + "follow_source_tokens": 2048, + "seconds": 2.8976090920041315, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "523b45e7fa9be241cf0434f58ef29285c15a565df7779dae176d8f5a4df2626e", + "output_sha256": "33462c6ad8d3c9823e7b43633ff1a94f7671c4d155888e47618b5f60027701e5", + "prompt_tokens": 241991, + "reused_tokens": 239906, + "freshly_processed_tokens": 2085, + "native_prompt_ms": 2821.8, + "native_decode_ms": 21.2, + "hit_rate": 0.779, + "ram_blobs": 106, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "current-main-same-binary", + "trial": "qsa-exact-current-main1", + "arm": "0-A-131072", + "case": "fresh-131072", + "follow_source_tokens": 2048, + "seconds": 68.87175908501376, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "029dc64c403bd9597b2a143399fa64555b40b8a4910c708fe3f7c3ddc5a1ad25", + "output_sha256": "d6fadeb81a0f0a9f23a6a06f4c0f266f0afe25f436a0aa575ac593e2d695c969", + "prompt_tokens": 130978, + "reused_tokens": 0, + "freshly_processed_tokens": 130978, + "native_prompt_ms": 68771.6, + "native_decode_ms": 28.8, + "hit_rate": 0.785, + "ram_blobs": 103, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "current-main-same-binary", + "trial": "qsa-exact-current-main1", + "arm": "0-A-131072", + "case": "follow-131072", + "follow_source_tokens": 2048, + "seconds": 2.8957397949998267, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "9f2979c0f702e087be57384d4b312a89f606961d08f0beaff64abd550b91b41d", + "output_sha256": "d6fadeb81a0f0a9f23a6a06f4c0f266f0afe25f436a0aa575ac593e2d695c969", + "prompt_tokens": 133063, + "reused_tokens": 130978, + "freshly_processed_tokens": 2085, + "native_prompt_ms": 2847.5, + "native_decode_ms": 20.1, + "hit_rate": 0.758, + "ram_blobs": 116, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "current-main-same-binary", + "trial": "qsa-exact-current-main1", + "arm": "0-A-240000", + "case": "fresh-240000", + "follow_source_tokens": 2048, + "seconds": 142.8425963030022, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "dbb6d4004af260501404a2674660c00523b1c455ba557d431395dab5cee7c4dd", + "output_sha256": "d6fadeb81a0f0a9f23a6a06f4c0f266f0afe25f436a0aa575ac593e2d695c969", + "prompt_tokens": 239906, + "reused_tokens": 0, + "freshly_processed_tokens": 239906, + "native_prompt_ms": 142694.7, + "native_decode_ms": 29.4, + "hit_rate": 0.779, + "ram_blobs": 106, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "current-main-same-binary", + "trial": "qsa-exact-current-main1", + "arm": "0-A-240000", + "case": "follow-240000", + "follow_source_tokens": 2048, + "seconds": 3.522451185999671, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "523b45e7fa9be241cf0434f58ef29285c15a565df7779dae176d8f5a4df2626e", + "output_sha256": "33462c6ad8d3c9823e7b43633ff1a94f7671c4d155888e47618b5f60027701e5", + "prompt_tokens": 241991, + "reused_tokens": 239906, + "freshly_processed_tokens": 2085, + "native_prompt_ms": 3445.8, + "native_decode_ms": 22.3, + "hit_rate": 0.779, + "ram_blobs": 106, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "current-main-same-binary", + "trial": "qsa-exact-current-main1", + "arm": "1-B-131072", + "case": "fresh-131072", + "follow_source_tokens": 2048, + "seconds": 60.01953978999518, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "029dc64c403bd9597b2a143399fa64555b40b8a4910c708fe3f7c3ddc5a1ad25", + "output_sha256": "d6fadeb81a0f0a9f23a6a06f4c0f266f0afe25f436a0aa575ac593e2d695c969", + "prompt_tokens": 130978, + "reused_tokens": 0, + "freshly_processed_tokens": 130978, + "native_prompt_ms": 59918.8, + "native_decode_ms": 27.0, + "hit_rate": 0.787, + "ram_blobs": 102, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "current-main-same-binary", + "trial": "qsa-exact-current-main1", + "arm": "1-B-131072", + "case": "follow-131072", + "follow_source_tokens": 2048, + "seconds": 2.780924443999538, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "9f2979c0f702e087be57384d4b312a89f606961d08f0beaff64abd550b91b41d", + "output_sha256": "d6fadeb81a0f0a9f23a6a06f4c0f266f0afe25f436a0aa575ac593e2d695c969", + "prompt_tokens": 133063, + "reused_tokens": 130978, + "freshly_processed_tokens": 2085, + "native_prompt_ms": 2730.0, + "native_decode_ms": 21.3, + "hit_rate": 0.758, + "ram_blobs": 116, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "current-main-same-binary", + "trial": "qsa-exact-current-main1", + "arm": "1-B-240000", + "case": "fresh-240000", + "follow_source_tokens": 2048, + "seconds": 111.82761004997883, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "dbb6d4004af260501404a2674660c00523b1c455ba557d431395dab5cee7c4dd", + "output_sha256": "d6fadeb81a0f0a9f23a6a06f4c0f266f0afe25f436a0aa575ac593e2d695c969", + "prompt_tokens": 239906, + "reused_tokens": 0, + "freshly_processed_tokens": 239906, + "native_prompt_ms": 111680.4, + "native_decode_ms": 28.7, + "hit_rate": 0.779, + "ram_blobs": 106, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "current-main-same-binary", + "trial": "qsa-exact-current-main1", + "arm": "1-B-240000", + "case": "follow-240000", + "follow_source_tokens": 2048, + "seconds": 2.957570611004485, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "523b45e7fa9be241cf0434f58ef29285c15a565df7779dae176d8f5a4df2626e", + "output_sha256": "33462c6ad8d3c9823e7b43633ff1a94f7671c4d155888e47618b5f60027701e5", + "prompt_tokens": 241991, + "reused_tokens": 239906, + "freshly_processed_tokens": 2085, + "native_prompt_ms": 2884.7, + "native_decode_ms": 21.3, + "hit_rate": 0.777, + "ram_blobs": 107, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + } + ], + "summaries": [ + { + "family": "tuned-v0.1.40.3", + "case": "fresh-131072", + "off": { + "n": 3, + "mean_seconds": 66.74059194500053, + "median_seconds": 67.51405035398784, + "min_seconds": 64.25693084098748, + "max_seconds": 68.45079464002629 + }, + "on": { + "n": 3, + "mean_seconds": 59.7690495433441, + "median_seconds": 59.46537054501823, + "min_seconds": 58.86296121100895, + "max_seconds": 60.97881687400513 + }, + "mean_elapsed_reduction": 0.10445730549410659, + "median_elapsed_reduction": 0.11921488589069962 + }, + { + "family": "tuned-v0.1.40.3", + "case": "fresh-240000", + "off": { + "n": 3, + "mean_seconds": 142.71826253732434, + "median_seconds": 142.0591052029922, + "min_seconds": 141.66012979499646, + "max_seconds": 144.43555261398433 + }, + "on": { + "n": 3, + "mean_seconds": 110.40663009767498, + "median_seconds": 110.438449467998, + "min_seconds": 109.54931649801438, + "max_seconds": 111.23212432701257 + }, + "mean_elapsed_reduction": 0.22640152609200292, + "median_elapsed_reduction": 0.22258802552508394 + }, + { + "family": "current-main-same-binary", + "case": "fresh-131072", + "off": { + "n": 1, + "mean_seconds": 68.87175908501376, + "median_seconds": 68.87175908501376, + "min_seconds": 68.87175908501376, + "max_seconds": 68.87175908501376 + }, + "on": { + "n": 1, + "mean_seconds": 60.01953978999518, + "median_seconds": 60.01953978999518, + "min_seconds": 60.01953978999518, + "max_seconds": 60.01953978999518 + }, + "mean_elapsed_reduction": 0.12853191805499842, + "median_elapsed_reduction": 0.12853191805499842 + }, + { + "family": "current-main-same-binary", + "case": "fresh-240000", + "off": { + "n": 1, + "mean_seconds": 142.8425963030022, + "median_seconds": 142.8425963030022, + "min_seconds": 142.8425963030022, + "max_seconds": 142.8425963030022 + }, + "on": { + "n": 1, + "mean_seconds": 111.82761004997883, + "median_seconds": 111.82761004997883, + "min_seconds": 111.82761004997883, + "max_seconds": 111.82761004997883 + }, + "mean_elapsed_reduction": 0.2171270129201055, + "median_elapsed_reduction": 0.2171270129201055 + }, + { + "family": "tuned-v0.1.40.3", + "case": "follow-131072", + "off": { + "n": 2, + "mean_seconds": 2.8288066264940426, + "median_seconds": 2.8288066264940426, + "min_seconds": 2.798884452000493, + "max_seconds": 2.858728800987592 + }, + "on": { + "n": 2, + "mean_seconds": 2.6584183355007553, + "median_seconds": 2.6584183355007553, + "min_seconds": 2.629391199006932, + "max_seconds": 2.687445471994579 + }, + "mean_elapsed_reduction": 0.06023327625065078, + "median_elapsed_reduction": 0.06023327625065078 + }, + { + "family": "tuned-v0.1.40.3", + "case": "follow-240000", + "off": { + "n": 2, + "mean_seconds": 3.4177469380083494, + "median_seconds": 3.4177469380083494, + "min_seconds": 3.2768524099956267, + "max_seconds": 3.558641466021072 + }, + "on": { + "n": 2, + "mean_seconds": 3.4165674445102923, + "median_seconds": 3.4165674445102923, + "min_seconds": 2.8976090920041315, + "max_seconds": 3.935525797016453 + }, + "mean_elapsed_reduction": 0.00034510849382674014, + "median_elapsed_reduction": 0.00034510849382674014 + }, + { + "family": "current-main-same-binary", + "case": "follow-131072", + "off": { + "n": 1, + "mean_seconds": 2.8957397949998267, + "median_seconds": 2.8957397949998267, + "min_seconds": 2.8957397949998267, + "max_seconds": 2.8957397949998267 + }, + "on": { + "n": 1, + "mean_seconds": 2.780924443999538, + "median_seconds": 2.780924443999538, + "min_seconds": 2.780924443999538, + "max_seconds": 2.780924443999538 + }, + "mean_elapsed_reduction": 0.039649747259247525, + "median_elapsed_reduction": 0.039649747259247525 + }, + { + "family": "current-main-same-binary", + "case": "follow-240000", + "off": { + "n": 1, + "mean_seconds": 3.522451185999671, + "median_seconds": 3.522451185999671, + "min_seconds": 3.522451185999671, + "max_seconds": 3.522451185999671 + }, + "on": { + "n": 1, + "mean_seconds": 2.957570611004485, + "median_seconds": 2.957570611004485, + "min_seconds": 2.957570611004485, + "max_seconds": 2.957570611004485 + }, + "mean_elapsed_reduction": 0.1603657638295627, + "median_elapsed_reduction": 0.1603657638295627 + } + ], + "coding_pilot": { + "scope": "Two official Exercism/Aider Polyglot tasks embedded in a192K source archive; not an official leaderboard run", + "seeds": [ + 7830, + 7831 + ], + "reasoning_effort": "xhigh", + "reasoning_budget_tokens": 8192, + "answer_reserve_tokens": 2048, + "temperature": 0.3, + "top_p": 0.95, + "top_k": 20, + "min_p": 0, + "archive_context": 196608, + "logical_context": 262144, + "paired_trials_per_task": 1, + "correction_time_included": true, + "completion_policy": "stop at first full-suite pass", + "rows": [ + { + "task": "go/alphametics", + "arm": "deployed", + "seconds": 209.1360279940127, + "turns": 3, + "success": true + }, + { + "task": "go/alphametics", + "arm": "candidate", + "seconds": 400.3182297559979, + "turns": 5, + "success": true + }, + { + "task": "rust/xorcism", + "arm": "candidate", + "seconds": 304.9063483380014, + "turns": 6, + "success": true + }, + { + "task": "rust/xorcism", + "arm": "deployed", + "seconds": 473.7341761919961, + "turns": 6, + "success": true + } + ], + "totals_seconds": { + "deployed": 682.8702041860088, + "candidate": 705.2245780939993 + }, + "elapsed_reduction": -0.03273590467259768, + "all_passed": true, + "minimum_available_gib": 8.621219635009766, + "resource_pass": true, + "general_promotion": false + }, + "abandoned_240k_archive_pilot": { + "status": "infrastructure_failure", + "reason": "Insufficient continuation headroom: Rust history reached262714tokens, exceeding262144", + "go_pair_seconds": { + "off": 325.555172590015, + "on": 323.6994908300112 + }, + "both_go_passed": true, + "rust_on_model_seconds_before_failure": 311, + "rust_off_not_attempted": true, + "pooled_with_192k_family": false + }, + "full24_run": false, + "cloud_comparison_run": false +} diff --git a/bench/results/2026-10-11-gfx1100-qsa-scores/prompt-source.txt.gz b/bench/results/2026-10-11-gfx1100-qsa-scores/prompt-source.txt.gz new file mode 100644 index 00000000..436f2a82 Binary files /dev/null and b/bench/results/2026-10-11-gfx1100-qsa-scores/prompt-source.txt.gz differ diff --git a/bench/results/2026-10-11-gfx1100-qsa-scores/provenance.json b/bench/results/2026-10-11-gfx1100-qsa-scores/provenance.json new file mode 100644 index 00000000..9632255e --- /dev/null +++ b/bench/results/2026-10-11-gfx1100-qsa-scores/provenance.json @@ -0,0 +1,168 @@ +{ + "hardware": { + "measured_date": "2026-10-11", + "cpu": "AMD Ryzen 9 7950X3D", + "gpu": "AMD Radeon RX 7900 XTX", + "architecture": "gfx1100", + "gpu_vram_gib": 24, + "installed_ram_gib": 64, + "kernel": "7.2.9-200.nobara.fc44.x86_64", + "rocm": "10.0.0", + "power_cap_w": 272, + "operating_system": { + "NAME": "Nobara Linux", + "VERSION": "44 (KDE Plasma Desktop Edition)", + "VERSION_ID": "44", + "PRETTY_NAME": "Nobara Linux 44 (KDE Plasma Desktop Edition)" + }, + "current_link_speed": "16.0 GT/s PCIe", + "current_link_width": "16", + "mem_info_vram_total": "25753026560", + "storage": { + "model": "NVMe SSD", + "ple": "dedicated ext4 SSD partition, direct I/O, remains on SSD" + } + }, + "upstream_base": "61b3fb5dd3f1e8ec09cf7e4e05208bc6d3c46406", + "original_method": { + "pr": 1825, + "commit": "14bf32150490bb9f5fc4d9c7c5dcfdc96dd98797", + "author": "xrip" + }, + "tuned_control": { + "source_base": "d5ea7133741e67743c0e886bb426c0ce8d69cf6c", + "local_changes": "PR1107 prefix reuse and resident-budget-loan implementation; same in both arms", + "native_sha256": "3bbaf98d7f83c91b0a40f369e5dee6ae4273284028b98d48dccde9e554f5c80c", + "candidate_sha256": "e0708d4fe0b0e096a36d793f47aebfdd3477e6157264b5739657977937381299" + }, + "current_main": { + "native_sha256": "1338d642a7d1d1e34a8f38932aef82619a6ac0e6f5195a7f1661dd55f916b8ad", + "sole_arm_difference": "STRATA_SCORES_THREAD=0 versus1 at process startup" + }, + "submitted_source_files": { + "CMakeLists.txt": "84048b34a1065672c9d3577053611fc33e3e63815d33ae502ee15e8deefd5d6a", + "src/kernels/cuda/qsa_select.cu": "fe051b86dfb349d09f0b576f9b9e710d20334acb534021a869763a7cb59836d8", + "src/kernels/cuda/qsa_scores_gfx1100_test.cu": "2a26063e9c5c58cb36f0973b36bb590db10762515f9eda5318314162fafda588", + "src/kernels/qsa_scores_gfx1100_parity.cpp": "9d0d88a2490d41d5e059e08db0907433b63321c98b53dceffc88883174aa3e15" + }, + "compiler_checks": { + "hip_full_engine": true, + "hip_cmake_test_target": true, + "cuda_touched_module": true, + "cuda_arch": "sm_89", + "cuda_toolkit": "13.0", + "cuda_full_engine": false, + "cuda_gpu_execution": false, + "sycl_source_touched": false + }, + "frontend": { + "version": "local prefix-cache frontend based on0.1.40.3; same for all arms", + "sha256": "5963c61106ee746673c43cb69df7b6bfeff2d2ec320a00f2435e1fd6e187f9dd", + "stock_latest_frontend_tested": false, + "chat_template_sha256": "a49e6e5da2cb6d114814c9ee5079677dfd1bdc4cf6b5c1519eb73d0bcf12f02b" + }, + "model": { + "repository": "https://huggingface.co/orcarouter/Qwen3.8-Flash-Next-Uncensored-GGUF", + "quantization": "IQ3_S", + "revision": "not recorded", + "gguf_shards": [ + "Qwen3.8-Flash-Next-GSQ-RCO-abliterated-IQ3_S-00001-of-00002.gguf", + "Qwen3.8-Flash-Next-GSQ-RCO-abliterated-IQ3_S-00002-of-00002.gguf" + ], + "expert_profile_sha256": "e93f33e1cad05fc31627295b1b9a253bfa99286ec2261c01e5c39366888e69f8", + "index_sha256": "02e228d5488792b1c2cb97b7021d099f47b198f5e13d0b9f9bc8716bb0592146", + "native_experts_sha256": "adba4968661f3d59f749a676a87948e29236c81997f649f5526daf71148edc24" + }, + "shared_config": { + "args": [ + "--pack", + "", + "--native", + "/IQ3_S/Qwen3.8-Flash-Next-GSQ-RCO-abliterated-IQ3_S-00001-of-00002.gguf", + "--ple-gguf", + "/Qwen3.8-Flash-Next-GSQ-RCO-abliterated-IQ3_S-00002-of-00002.gguf", + "--mmap-experts", + "--expert-profile", + "/flash-solo-balanced-20261004.bin", + "--expert-cache", + "8247", + "--prefill", + "16384", + "--spec", + "6", + "--spec-min-p", + "0.7", + "--mtp", + "/strata/rt", + "--max-context", + "262144", + "--kv", + "int8", + "--kv-resident", + "32768", + "--vision", + "--pool-workers", + "15", + "--adapt-every", + "0", + "--pcie-frac", + "0", + "--vram-reserve-mib", + "1024", + "--resident-budget-gib", + "34", + "--mtp-max-t", + "6", + "--ple-io", + "direct", + "--conversation-cache-mib", + "1024", + "--conversation-cache-slots", + "2", + "--conversation-cache-min-free-mib", + "8192", + "--native-dense-gguf", + "/IQ3_S/Qwen3.8-Flash-Next-GSQ-RCO-abliterated-IQ3_S-00001-of-00002.gguf", + "--native-dense-gguf", + "/Qwen3.8-Flash-Next-GSQ-RCO-abliterated-IQ3_S-00002-of-00002.gguf" + ], + "environment": { + "ROCR_VISIBLE_DEVICES": "0", + "HIP_VISIBLE_DEVICES": "0", + "CUDA_VISIBLE_DEVICES": "-1", + "STRATA_GPU_BACKEND": "hip", + "STRATA_PREFILL_MMQ": "1", + "STRATA_PREFILL_RING": "96", + "STRATA_DEC_BATCH": "1", + "STRATA_PREFILL_ISSUER": "1", + "STRATA_SCORES_MULTI": "2", + "STRATA_RESIDENT_PIN": "0", + "STRATA_RESIDENT_HEADROOM_GIB": "2", + "STRATA_MMAP_STAGE_PREFETCH": "1", + "STRATA_REFILL_BLOCKING": "1", + "STRATA_WMMA_GEMM": "0", + "STRATA_PA_WMMA": "1", + "STRATA_SELECT_WMMA": "0", + "STRATA_PREFILL_GROUP_GATHER": "1", + "STRATA_STAGER_DMA_FENCE": "1", + "STRATA_IO_THREADS": "32", + "STRATA_DECODE_TIMING": "1", + "STRATA_HIP_WMMA": "1", + "STRATA_HIPBLASLT_VERBOSE": "1", + "STRATA_SH_STREAM": "0", + "STRATA_RESIDENT_BUDGET_LOANS": "1", + "STRATA_SELECT_SIMT": "0", + "STRATA_STAGE_PIN": "0", + "STRATA_VISION_BACKEND_DIR": "", + "STRATA_HIPBLASLT_TUNING": "hipblaslt-gfx1100-100401.txt" + }, + "configured_expert_slots": 8247, + "actual_gpu_expert_slots": 8144, + "actual_gpu_expert_bytes": 16622003200, + "logical_context": 262144, + "vision": "GPU enabled; no image prompt in these measurements", + "cgroup_memory_limit_gib": 56, + "cgroup_swap_limit": 0, + "available_memory_floor_gib": 8 + } +} diff --git a/bench/results/2026-10-12-community-gfx1103/README.md b/bench/results/2026-10-12-community-gfx1103/README.md new file mode 100644 index 00000000..81758a53 --- /dev/null +++ b/bench/results/2026-10-12-community-gfx1103/README.md @@ -0,0 +1,165 @@ +# Radeon 780M (gfx1103) on ROCm 10.1: dot4 + WMMA + a hipBLASLt table (2026-10-12) + +The gfx1103 port of the code in this tree: the native dot4 path, the gfx11 WMMA kernels, a calibrated hipBLASLt +table and the gfx1103 exact speed switches (written into the config's `env` by setup, like gfx1150's). Measured on +one 780M with every cited configuration run interleaved against the base. Everything here is one machine; see +"Not tested". + +## Rig + +- Ryzen 7 8745HS (8 cores / 16 threads, Zen 4, AVX-512), Radeon 780M (gfx1103, RDNA3, 12 CUs), 60 GB DDR5, GTT + 50 GiB (`mem_info_gtt_total` 50 GiB), Ubuntu kernel 7.0.0-38, amdgpu CWSR disabled (`cwsr_enable=0`). +- ROCm 10.1 (`rocm/dev-ubuntu-24.04:10.1.0-full`, HIP 7.16.26385, hipBLASLt 1.4.1 = `100401`, clang 24), engine built + by hand into `build-780m`: + `cmake -B build-780m -G Ninja -DCMAKE_BUILD_TYPE=Release -DSTRATA_ENABLE_HIP=ON -DSTRATA_ENABLE_CUDA=OFF + -DSTRATA_PREFILL_MMQ=ON -DCMAKE_HIP_ARCHITECTURES=gfx1103`. +- Model: Qwen3.8-Flash-Next GSQ-RCO Q2_0 (ISTA-DASLab, revision `ed59f920`), a native pack with the experts read + from the GGUF in place (`--mmap-experts`), the PLE table on the SSD (`--ple-io direct`), Int8 KV, 32K context. + MTP draft layer built by `tools/mtp_fetch.py` + `mtp_pack.py` + `mtp_rt.py`. + +## Correctness gates + +- `ctest` (ROCm 10.1, gfx1103): 57 passed, 2 skipped (`hip_prefill_hcd_exact_parity`, + `hip_prefill_hipblaslt_gemm` — they run and pass with the table present, see below), 2 environmental failures + (`ple_parity` needs the `bench/micro` fixtures, `platform_memory_test` needs an 8 GiB+ memlock limit; this + host's hard limit is 8 MiB). +- The WMMA tests now **run and pass** on gfx1103 instead of skipping: `hip_intrinsics` (dot4 vs the byte loop), + `hip_prefill_wmma_gemm_parity`, `hip_prompt_attn_wmma`, `qsa_*`, `hip_prefill_fused_moe`, `hip_prefill_fused_iq`, + `hip_gemm_f16_io_parity`, `hip_prefill_mmq_parity`. +- The table: `hip_prefill_hipblaslt_gemm` passes with `launches=4 fallbacks=0`; the server's own log line says + `prefill gemm: hipBLASLt tuning enabled (143 rows, gfx1103, version 100401)`. +- **Token ids**: the ported engine with default flags prints the same greedy ids as the pre-port build at 4K and + 32K (the dot4 kernels are exact integer arithmetic). The 17 gfx1103 exact switches, with the table, also print + the same greedy ids as without them. The table itself changes the dense GEMMs' summation order (one 32-token + suffix differs, as on every other card), so identity is claimed for the exact paths, not the table. + +## Speed (bench_vs_llama.py, 256 tokens out, interleaved; medians of the shown samples) + +The 780M at 4K and 32K, one round, temperature 0 and 0.7: + +| arm | cell | prompt tok/s | decode tok/s | TTFT s | +| --- | --- | ---: | ---: | ---: | +| base (no table, no opt-ins) | 4K | 90 | 13.1 | 44.9 | +| base (no table, no opt-ins) | 32K | 90 | 13.1 | 351 | +| table + all opt-ins | 4K | 277 | 13.9 | 14.6 | +| table + WMMA set | 32K | 272 | 14.3 | 118 | + +Switch screening at 4K (medians of 4 requests; each arm is the arm above plus the named set; the screening ran with +the first calibration pass, and the merged table re-measured 187 tok/s at 4K, see "The table"): + +| arm | prompt tok/s | decode tok/s | +| --- | ---: | ---: | +| base (no table) | 91 | 13.1 | +| + hipBLASLt table | 186 | 13.9 | +| + the 17 exact switches | 211 | 13.4 | +| + WMMA set (`HIP_WMMA`, `PF_GEMM`, `PA_FAST`, `SELECT_WMMA`) | 248 | 13.4 | +| + `PF_FUSED` | 246 | 12.8 | +| + all of the above + `HC_UPMIX` | 277 | 13.7 | + +Decode (greedy, 640 tokens, 3 interleaved pairs, short prompt): the 11 decode exact switches 16.63 -> 17.17 tok/s +median (+3.2%, every pair). + +## Engine flags (Phase 4c) + +Draft-layer flags, `strata` in generate mode, 4K prompt, 256 greedy tokens, restarts per arm, 3 interleaved reps +(2 for `--mtp-window`, which used the 32K prompt): + +| arm | decode tok/s (reps) | +| --- | --- | +| `--spec 2` (default) | 15.93 / 15.65 / 15.65 | +| `--spec 3` | 15.38 / 15.89 / 15.69 | +| `--spec 4` (the gfx1150-style config) | 13.98 / 14.18 / 14.21 | +| `--spec 6` | 11.16 / 11.16 / 10.85 | +| `--spec 2 --spec-min-p 0.5` | 14.71 / 14.94 / 14.98 | +| `--spec 2 --mtp-q4 all` | 15.73 / 15.39 / 15.63 | +| `--spec 2 --mtp-q4 proj` | 15.71 / 15.88 / 15.74 | +| `--spec 2 --lookup-chain 4` | 16.01 / 16.37 / 15.72 | + +`--spec 2` is the best window on this chip (15.65 median against 14.18 at `--spec 4` and 11.16 at `--spec 6`); +`--spec-min-p 0.5` is 4.5% slower here than the engine default; `--mtp-q4` is neutral; `--lookup-chain 4` is +2.3% +(3 of 3 pairs) and byte-identical greedy answers. `--mtp-window 4096` against the default at 32K: 14.07/13.82 +against 13.72/13.63 (+2%, 2 pairs - weak). Raw: [phase4c-spec-results.txt](phase4c-spec-results.txt), +[phase4c-knobs-results.txt](phase4c-knobs-results.txt), [phase4c-window-results.txt](phase4c-window-results.txt). + +## Context ladder (the shipping configuration: 131K context, table + exact + WMMA opt-ins) + +Fresh prompts (a nonce first, so nothing is reused), 128 greedy tokens each, one sample per cell; the prompts come +from this checkout's own documentation (676K tokens of it). Prefill is the server's `prompt_per_second` for the +whole read, decode its `predicted_per_second`: + +| prompt tokens | prefill tok/s | decode tok/s | draft acceptance | +|---:|---:|---:|---:| +| 4,089 | 276.7 | 16.4 | 57/73 | +| 8,090 | 314.3 | 15.9 | 55/75 | +| 16,090 | 314.6 | 16.2 | 57/74 | +| 32,091 | 308.7 | 15.5 | 56/77 | +| 64,091 | 258.2 | 12.1 | 57/83 | +| 96,095 | 215.5 | 9.9 | 55/81 | +| 128,097 | 198.5 | 9.8 | 55/86 | + +So ~200 tok/s is the **average over the full 128K read**; the early-to-mid context reads faster (~310 tok/s to +32K). To see the rate at depth, a second request appended 256 tokens to the same prompt and let the server reuse +its cached prefix (the checkpoints are 16K apart, so the fresh part is 13-16K tokens ending at that depth): + +| depth | fresh tail tokens | tail prefill tok/s (cached prefix) | +|---:|---:|---:| +| 32K | 15,964 | 297.2 | +| 64K | 15,196 | 207.6 | +| 96K | 14,433 | 211.9 | +| 128K | 13,665 | 206.2 | + +The tail at 128K depth reads at ~206 tok/s, and a second full 128K run measured 221.4 (198.5 and 221.4 are two +samples), so ~200 tok/s holds both as the full-read average and as the local rate near the end. Decode falls with +depth because the attention reads the whole KV: 16 tok/s to 32K, ~12 at 64K, ~10 at 96-128K; draft acceptance is +steady (~70%), so it is context cost, not the drafter. Memory is flat across the ladder: GTT 38.1 of 50 GiB (11.9 +free), RAM 51 of 60 GB with the parked 128K conversation. The 4K cell here (276.7) matches the 277 in the Speed +table; the 32K cell is higher than the earlier 272 because the shipping configuration adds `--spec 2` and +`--lookup-chain 4`. Raw: [context-ladder.jsonl](context-ladder.jsonl), +[context-ladder-instant.jsonl](context-ladder-instant.jsonl). + +## Stability (Phase 5) + +- `STRATA_NO_ARENA_THP=1` (setup writes it for gfx1103): 6 engine starts with it and 6 without, alternating, all + clean (this config reads the experts through `--mmap-experts` and has no resident arena, so the flag is inert + here). Raw: [phase5a-results.txt](phase5a-results.txt). +- Memory pressure with the reset-prone combination from 7.10 - a partial expert cache (16,384 of 24,576 slots, + so file-tier reads), `STRATA_IO_PREFETCH=1`, 32K prompts, the adaptive tier on, then `--adapt-every 100000`: + 4 sessions, all clean, peak GTT 26.7 GiB. The 7.10 resets do not reproduce on ROCm 10.1 with `cwsr_enable=0` + (the fix reported in #1423). Raw: [phase5b-results.txt](phase5b-results.txt). +- Zero `amdgpu` resets or KFD evictions in the kernel log (`journalctl -k`) over the whole session. +- Soak: a 2 h 07 m `--serve` run through `tools/serve_load.py` (2 clients, 462 rounds, 924 requests, 64 tokens each, + fresh nonces): zero errors, zero resets, decode steady at 8.0-8.7 tok/s aggregate (two clients over a server that + serializes requests; 15-16 s per 128-token round). +- Memory: 65K context + Int8 KV + all 24,576 experts in GTT = 37.2 GiB of 50 GiB (12.8 GiB free); at 131K it is + 38.1 GiB (11.9 GiB free), the whole ladder above. + +## The table + +`tools/hip/gfx1103-hipblaslt-100401.txt`, calibrated with `tools/hip/tune_hipblaslt` over the gfx1150 table's 144 +GEMM cases at T = 64..16384 (the same case list the 890M run used), 32 MiB workspace. Two passes back to back; each +row keeps the solution with the lowest median of all six repetitions, and a row is left out when no candidate beats +plain hipBLAS: **143 rows**, 1.05-23.30x per GEMM, geometric mean 4.95x; the one shape left out is +`bf16 N=1 K=2560 T=64` (best 0.039 ms against 0.024 ms on plain hipBLAS - sub-100 us timings), where the engine +falls back to hipBLASEx by design. Per-row medians and candidate counts: +[tune-summary.csv](tune-summary.csv). `HCD_EXACT` is deliberately **not** in the gfx1103 switches: the table picks +no 1176 / 1177 for the HC down GEMM (`hip_prefill_hcd_exact_parity` skips on that, as it does on gfx1150). Startup +lines: [engine-log-excerpt.txt](engine-log-excerpt.txt). + +## The exact switches and the opt-ins + +- The 17 exact switches are written by setup into the config's `env` for `STRATA_EXPERIMENTAL_GFX1103=1` installs, + the same way the table is (the engine keeps gfx1103 out of its arch defaults: `arch_default_env("gfx1103")` stays + empty). `SETUP_ENV` carries them, so a re-run refreshes them and turning the opt-in off removes them. +- Opt-in, bit-changing: `STRATA_HIP_WMMA`, `STRATA_PF_GEMM`, `STRATA_PF_FUSED`, `STRATA_PA_FAST`, + `STRATA_SELECT_WMMA`, `STRATA_HC_UPMIX`. The measured wins are above; no KL was measured here. + +## Not tested + +- The TheRock-wheel route for gfx1103: the index (`gfx110X-all`) has no 10.x wheels, setup's pin is unchanged, and + a full `setup.sh` install was not run here - the numbers come from the hand build. +- CUDA and SYCL were not built here (no toolchains on this box). The changed files compile for HIP gfx1103 and for + gfx1100;gfx1103;gfx1201; the gfx1103 macros are undefined for CUDA/SYCL, as for the other gfx11 targets. +- The opt-in set beyond one round; KL of any bit-changing switch; other models, other quantizations; contexts past + 131K. +- `--adapt-every 100000` vs the default adaptive tier was run under a partial cache (Phase 5, both clean); the + default tier with the full cache was not A/B'd for resets, because none occurred. diff --git a/bench/results/2026-10-12-community-gfx1103/context-ladder-instant.jsonl b/bench/results/2026-10-12-community-gfx1103/context-ladder-instant.jsonl new file mode 100644 index 00000000..332ec22a --- /dev/null +++ b/bench/results/2026-10-12-community-gfx1103/context-ladder-instant.jsonl @@ -0,0 +1,4 @@ +{"depth": 32000, "full": {"prompt_n": 32091, "cache_n": 0, "prompt_ms": 105853.1, "prompt_tps": 303.2, "pred_n": 32, "pred_tps": 16.6, "draft_n": 18, "draft_acc": 16, "wall_s": 107.8}, "incr": {"prompt_n": 15964, "cache_n": 16384, "prompt_ms": 53719.1, "prompt_tps": 297.2, "pred_n": 32, "pred_tps": 16.9, "draft_n": 16, "draft_acc": 15, "wall_s": 55.6}} +{"depth": 64000, "full": {"prompt_n": 64091, "cache_n": 0, "prompt_ms": 276118.9, "prompt_tps": 232.1, "pred_n": 32, "pred_tps": 11.6, "draft_n": 21, "draft_acc": 16, "wall_s": 278.9}, "incr": {"prompt_n": 15196, "cache_n": 49152, "prompt_ms": 73201.0, "prompt_tps": 207.6, "pred_n": 32, "pred_tps": 10.7, "draft_n": 20, "draft_acc": 13, "wall_s": 76.3}} +{"depth": 96000, "full": {"prompt_n": 96096, "cache_n": 0, "prompt_ms": 426208.3, "prompt_tps": 225.5, "pred_n": 32, "pred_tps": 14.8, "draft_n": 20, "draft_acc": 13, "wall_s": 428.4}, "incr": {"prompt_n": 14433, "cache_n": 81920, "prompt_ms": 68127.8, "prompt_tps": 211.9, "pred_n": 32, "pred_tps": 11.7, "draft_n": 20, "draft_acc": 13, "wall_s": 71.0}} +{"depth": 128000, "full": {"prompt_n": 128096, "cache_n": 0, "prompt_ms": 578558.8, "prompt_tps": 221.4, "pred_n": 32, "pred_tps": 13.0, "draft_n": 18, "draft_acc": 15, "wall_s": 581.1}, "incr": {"prompt_n": 13665, "cache_n": 114688, "prompt_ms": 66258.3, "prompt_tps": 206.2, "pred_n": 32, "pred_tps": 13.3, "draft_n": 17, "draft_acc": 16, "wall_s": 68.8}} diff --git a/bench/results/2026-10-12-community-gfx1103/context-ladder.jsonl b/bench/results/2026-10-12-community-gfx1103/context-ladder.jsonl new file mode 100644 index 00000000..0a44542c --- /dev/null +++ b/bench/results/2026-10-12-community-gfx1103/context-ladder.jsonl @@ -0,0 +1,7 @@ +{"target": 4000, "prompt_n": 4089, "prompt_ms": 14776.4, "prompt_tps": 276.7, "pred_n": 128, "pred_tps": 16.4, "draft_n": 73, "draft_acc": 57, "wall_s": 22.6, "finish": "length"} +{"target": 8000, "prompt_n": 8090, "prompt_ms": 25738.6, "prompt_tps": 314.3, "pred_n": 128, "pred_tps": 15.9, "draft_n": 75, "draft_acc": 55, "wall_s": 33.8, "finish": "length"} +{"target": 16000, "prompt_n": 16090, "prompt_ms": 51137.1, "prompt_tps": 314.6, "pred_n": 128, "pred_tps": 16.2, "draft_n": 74, "draft_acc": 57, "wall_s": 59.0, "finish": "length"} +{"target": 32000, "prompt_n": 32091, "prompt_ms": 103969.5, "prompt_tps": 308.7, "pred_n": 128, "pred_tps": 15.5, "draft_n": 77, "draft_acc": 56, "wall_s": 112.3, "finish": "length"} +{"target": 64000, "prompt_n": 64091, "prompt_ms": 248265.4, "prompt_tps": 258.2, "pred_n": 128, "pred_tps": 12.1, "draft_n": 83, "draft_acc": 57, "wall_s": 258.9, "finish": "length"} +{"target": 96000, "prompt_n": 96095, "prompt_ms": 445909.7, "prompt_tps": 215.5, "pred_n": 128, "pred_tps": 9.9, "draft_n": 81, "draft_acc": 55, "wall_s": 459.0, "finish": "length"} +{"target": 128000, "prompt_n": 128097, "prompt_ms": 645432.8, "prompt_tps": 198.5, "pred_n": 128, "pred_tps": 9.8, "draft_n": 86, "draft_acc": 55, "wall_s": 658.5, "finish": "length"} diff --git a/bench/results/2026-10-12-community-gfx1103/engine-log-excerpt.txt b/bench/results/2026-10-12-community-gfx1103/engine-log-excerpt.txt new file mode 100644 index 00000000..122c28a6 --- /dev/null +++ b/bench/results/2026-10-12-community-gfx1103/engine-log-excerpt.txt @@ -0,0 +1,35 @@ +strata generate: PCIe probe: 29.4 GB/s host->device (best of 25.6 25.6 26.0 29.4) -> pcie_frac 0.55 (default 0.55) +strata generate: native pack: /data/packs/qwen-q2_0 experts (largest blob 1.38 MB), token embedding Q3_K in mapped host memory (260 MiB, 0.2 s) +strata generate: 1416 MiB of weights loaded from /data/packs/qwen-q2_0 in 0.6 s (303 canonical tensors skipped: served natively) +strata generate: 301 native projection matrices, 1376.20 MiB of weights, in 0.7 s +strata generate: PLE direct read probe: 67528 rows/s (fine) +strata generate: the SSD is kept awake while rows are read: one page of the table after 100 ms without a read, until 60 s after the last request (STRATA_SSD_KEEPALIVE=0 turns it off) +strata generate: profile /src/data/expert-profile.bin: 24576 ranked pairs, built for 24576 slots +strata generate: PLE on, table 320001536 rows of /models/flash-next/Q2_0/Qwen3.8-Flash-Next-GSQ-RCO-Q2_0-00002-of-00002.gguf +strata mtp: draft layer loaded, 799 MiB of VRAM (experts 675, dense 111), files read in 0.47 s (1654 MiB/s) +strata generate: experimental native Q5_K head, 437043200 bytes, in 0.2 s +strata generate: GPU 0: AMD Radeon 780M Graphics (gfx1103) +strata generate: experts via mmap (--mmap-experts; the GGUF shards in place, no experts.bin) +strata generate: GPU host-callback thread started before host-core pinning +strata generate: CPU pool tasks/phase: 24 (automatic), participating threads: 8 +strata generate: 7 pool workers on logical processors 1,2,3,4,5,6,7, the host thread on 0 (draining too) (--host-core first) +strata generate: expert cache 24576 slots, 31.64 GiB of VRAM; policy is +strata generate: the GPU computes the experts in the cache; it rounds differently from the CPU, +strata generate: the profile fill asks for 256 pairs ahead (STRATA_FILL_AHEAD) +strata generate: pre-filled 24576 of 24576 slots from the profile in 21.9 s (1550 MB/s); slot 0 verified +strata generate: routing-aware prefetch on (the next layer's router, file tier) +strata generate: R4 hit path ON - resident experts are computed on the GPU +strata generate: 7 expert-pool workers + the host thread +strata generate: session is up (engine 0.1.43.1) +strata generate: sampling greedy +strata generate: token graph hit path: 24576 resident experts, decided on the device +strata generate: prompt chunk auto: 256 tokens +strata generate: prompt path borrows 191 cache slots (0.25 GiB) +prefill gemm: hipBLASLt tuning enabled (143 rows, gfx1103, version 100401) +strata generate: 191 lent slots refilled in 23.4 ms +strata generate: prefill 1 tokens in 1 chunks, 729.8 ms (1.4 tok/s); experts streamed 0 (0 by DMA, host 0.0 ms), resident 480, on the CPU 0 (share 0.00); PLE 0.9 ms +strata verify: window up to 6 tokens, 54.8 MiB of device buffers (100% VRAM resident: zero-doorbell graph) +strata verify: capturing the 1-token window (14137 MiB of VRAM free) +strata verify: captured the 1-token window (upload no error, sync no error) +strata verify: capturing the 2-token window (14134 MiB of VRAM free) +strata verify: captured the 2-token window (upload no error, sync no error) diff --git a/bench/results/2026-10-12-community-gfx1103/phase4c-knobs-results.txt b/bench/results/2026-10-12-community-gfx1103/phase4c-knobs-results.txt new file mode 100644 index 00000000..42106f17 --- /dev/null +++ b/bench/results/2026-10-12-community-gfx1103/phase4c-knobs-results.txt @@ -0,0 +1,15 @@ +spec2-r1 15.93 tok/s +minp0.5-r1 14.71 tok/s +q4all-r1 15.73 tok/s +q4proj-r1 15.71 tok/s +chain4-r1 16.01 tok/s +spec2-r2 15.65 tok/s +minp0.5-r2 14.94 tok/s +q4all-r2 15.39 tok/s +q4proj-r2 15.88 tok/s +chain4-r2 16.37 tok/s +spec2-r3 15.65 tok/s +minp0.5-r3 14.98 tok/s +q4all-r3 15.63 tok/s +q4proj-r3 15.74 tok/s +chain4-r3 15.72 tok/s diff --git a/bench/results/2026-10-12-community-gfx1103/phase4c-spec-results.txt b/bench/results/2026-10-12-community-gfx1103/phase4c-spec-results.txt new file mode 100644 index 00000000..26ffa400 --- /dev/null +++ b/bench/results/2026-10-12-community-gfx1103/phase4c-spec-results.txt @@ -0,0 +1,12 @@ +spec2-r1 15.70 tok/s +spec3-r1 15.38 tok/s +spec4-r1 13.98 tok/s +spec6-r1 11.16 tok/s +spec2-r2 15.96 tok/s +spec3-r2 15.89 tok/s +spec4-r2 14.18 tok/s +spec6-r2 11.16 tok/s +spec2-r3 15.78 tok/s +spec3-r3 15.69 tok/s +spec4-r3 14.21 tok/s +spec6-r3 10.85 tok/s diff --git a/bench/results/2026-10-12-community-gfx1103/phase4c-window-results.txt b/bench/results/2026-10-12-community-gfx1103/phase4c-window-results.txt new file mode 100644 index 00000000..72a59fc9 --- /dev/null +++ b/bench/results/2026-10-12-community-gfx1103/phase4c-window-results.txt @@ -0,0 +1,6 @@ +window-default-r1 13.72 tok/s +window8192-r1 13.78 tok/s +window4096-r1 14.07 tok/s +window-default-r2 13.63 tok/s +window8192-r2 12.95 tok/s +window4096-r2 13.82 tok/s diff --git a/bench/results/2026-10-12-community-gfx1103/phase5a-results.txt b/bench/results/2026-10-12-community-gfx1103/phase5a-results.txt new file mode 100644 index 00000000..f7b28814 --- /dev/null +++ b/bench/results/2026-10-12-community-gfx1103/phase5a-results.txt @@ -0,0 +1,12 @@ +thp-off-1 RC=0 +thp-on-1 RC=0 +thp-off-2 RC=0 +thp-on-2 RC=0 +thp-off-3 RC=0 +thp-on-3 RC=0 +thp-off-4 RC=0 +thp-on-4 RC=0 +thp-off-5 RC=0 +thp-on-5 RC=0 +thp-off-6 RC=0 +thp-on-6 RC=0 diff --git a/bench/results/2026-10-12-community-gfx1103/phase5b-results.txt b/bench/results/2026-10-12-community-gfx1103/phase5b-results.txt new file mode 100644 index 00000000..f3f352ca --- /dev/null +++ b/bench/results/2026-10-12-community-gfx1103/phase5b-results.txt @@ -0,0 +1,7 @@ +== adaptive tier (default), IO prefetch on +adapt-a1 RC=0 GTT-peak=26,7 GiB +adapt-a2 RC=0 GTT-peak=26,7 GiB +== --adapt-every 100000, IO prefetch on +static-b1 RC=0 GTT-peak=26,7 GiB +static-b2 RC=0 GTT-peak=26,7 GiB +== resets: 0 diff --git a/bench/results/2026-10-12-community-gfx1103/runs.csv b/bench/results/2026-10-12-community-gfx1103/runs.csv new file mode 100644 index 00000000..d2756460 --- /dev/null +++ b/bench/results/2026-10-12-community-gfx1103/runs.csv @@ -0,0 +1,61 @@ +config,round,cell,temp,rep,prompt_tokens,prompt_ms,prompt_tok_s,generated,decode_tok_s,drafts_accepted,drafts +s1-base,0,4k,0.0,0,4052,44151.7,91.8,112,13.9,57,93 +s1-base,0,4k,0.0,1,4052,44017.5,92.1,94,13.7,45,69 +s1-base,0,4k,0.7,0,4052,45970.2,88.1,123,12.4,56,105 +s1-base,0,4k,0.7,1,4052,45067.9,89.9,96,12.3,35,64 +s2-table,0,4k,0.0,0,4052,21652.6,187.1,92,14.6,49,68 +s2-table,0,4k,0.0,1,4052,22051.3,183.8,88,14.3,44,60 +s2-table,0,4k,0.7,0,4052,21810.3,185.8,109,13.3,46,72 +s2-table,0,4k,0.7,1,4052,21868.0,185.3,121,13.8,61,93 +s2-table,0,32k,0.0,0,32058,180319.2,177.8,124,13.1,63,95 +s2-table,0,32k,0.7,0,32058,201403.1,159.2,124,11.7,63,114 +s2-table,0,4k,0.0,0,4052,22012.5,184.1,98,13.7,46,69 +s2-table,0,4k,0.0,1,4052,22095.3,183.4,112,14.6,58,79 +s2-table,0,4k,0.7,0,4052,22448.0,180.5,132,15.1,73,97 +s2-table,0,4k,0.7,1,4052,21947.0,184.6,121,15.3,70,95 +s3-table-exact,0,4k,0.0,0,4054,19361.2,209.4,108,13.5,51,89 +s3-table-exact,0,4k,0.0,1,4054,19106.1,212.2,104,13.2,45,80 +s3-table-exact,0,4k,0.7,0,4054,19202.9,211.1,116,13.0,53,98 +s3-table-exact,0,4k,0.7,1,4054,19185.6,211.3,107,13.9,54,90 +s3a-table-prompt5,0,4k,0.0,0,4056,21214.5,191.2,106,15.0,62,82 +s3a-table-prompt5,0,4k,0.0,1,4056,21304.9,190.4,84,13.0,40,72 +s3a-table-prompt5,0,4k,0.7,0,4056,21475.2,188.9,97,12.9,45,73 +s3a-table-prompt5,0,4k,0.7,1,4056,21127.9,192.0,93,12.2,34,68 +s3b-table-decode11,0,4k,0.0,0,4057,20671.5,196.3,94,15.4,48,63 +s3b-table-decode11,0,4k,0.0,1,4057,20289.8,200.0,93,15.2,49,64 +s3b-table-decode11,0,4k,0.7,0,4057,20932.3,193.8,106,12.8,45,85 +s3b-table-decode11,0,4k,0.7,1,4057,22806.7,177.9,113,11.1,53,80 +s4-table-wmma,0,4k,0.0,0,4054,16272.5,249.1,110,13.6,53,84 +s4-table-wmma,0,4k,0.0,1,4054,16446.1,246.5,113,13.3,55,94 +s4-table-wmma,0,4k,0.7,0,4054,16299.7,248.7,119,13.4,55,89 +s4-table-wmma,0,4k,0.7,1,4054,16397.2,247.2,107,13.5,53,84 +s4-table-wmma,0,32k,0.0,0,32060,117646.1,272.5,123,14.3,63,90 +s4-table-wmma,0,32k,0.7,0,32060,127975.8,250.5,134,11.5,63,113 +s5-table-wmma-fused,0,4k,0.0,0,4056,16434.3,246.8,102,14.3,52,74 +s5-table-wmma-fused,0,4k,0.0,1,4056,16579.7,244.6,101,13.3,45,74 +s5-table-wmma-fused,0,4k,0.7,0,4056,16383.0,247.6,129,11.3,55,129 +s5-table-wmma-fused,0,4k,0.7,1,4056,16552.3,245.0,123,12.6,61,117 +s6-table-all,0,4k,0.0,0,4053,14601.2,277.6,91,14.6,45,66 +s6-table-all,0,4k,0.0,1,4053,14716.2,275.4,93,15.0,47,64 +s6-table-all,0,4k,0.7,0,4053,14539.8,278.8,118,13.2,53,99 +s6-table-all,0,4k,0.7,1,4053,14641.3,276.8,109,14.2,53,82 +s6-table-all,0,32k,0.0,0,32059,110471.4,290.2,137,11.9,67,102 +s6-table-all,0,32k,0.7,0,32059,132319.7,242.3,115,12.0,59,100 +strata-base,0,4k,0.0,0,4052,43555.7,93.0,115,12.9,52,95 +strata-base,0,4k,0.0,1,4052,44875.6,90.3,103,12.9,42,74 +strata-base,0,4k,0.7,0,4052,43629.8,92.9,122,13.7,62,96 +strata-base,0,4k,0.7,1,4052,43422.6,93.3,135,14.7,71,97 +strata-base,0,32k,0.0,0,32058,351862.3,91.1,141,13.7,72,108 +strata-base,0,32k,0.7,0,32058,349500.1,91.7,122,13.3,63,97 +strata-table,0,4k,0.0,0,4052,43992.3,92.1,103,13.5,50,76 +strata-table,0,4k,0.0,1,4052,43282.1,93.6,99,13.0,45,78 +strata-table,0,4k,0.7,0,4052,44033.8,92.0,81,12.9,39,70 +strata-table,0,4k,0.7,1,4052,43881.7,92.3,125,14.6,68,99 +strata-table,0,32k,0.0,0,32058,351109.8,91.3,120,13.7,58,86 +strata-table,0,32k,0.7,0,32058,351360.7,91.2,123,12.8,55,96 +strata,0,4k,0.0,0,4051,45084.7,89.9,103,12.2,43,86 +strata,0,4k,0.0,1,4051,45181.7,89.7,104,13.7,49,79 +strata,0,4k,0.7,0,4051,44951.7,90.1,140,15.1,82,110 +strata,0,4k,0.7,1,4051,45055.6,89.9,101,13.3,48,78 +strata,0,32k,0.0,0,32057,356669.0,89.9,109,13.1,54,93 +strata,0,32k,0.7,0,32057,357066.0,89.8,104,13.1,52,85 diff --git a/bench/results/2026-10-12-community-gfx1103/s1-base.jsonl b/bench/results/2026-10-12-community-gfx1103/s1-base.jsonl new file mode 100644 index 00000000..3fa09a6e --- /dev/null +++ b/bench/results/2026-10-12-community-gfx1103/s1-base.jsonl @@ -0,0 +1,4 @@ +{"wall_s": 52.23, "prompt_n": 4052, "prompt_ms": 44151.7, "prompt_tps": 91.8, "pred_n": 112, "pred_tps": 13.9, "draft_n": 93, "draft_acc": 57, "text": "Strata is a local AI engine optimized for speed on specific hardware, achieving significant performance gains through fused int8 tensor-core kernels and speculative decoding on models like Q2_0 and IQ2_XS. The system offers advanced memory management features, such as KV streaming and hybrid K8V4 ca", "config": "s1-base", "round": 0, "cell": "4k", "temp": 0.0, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 38.98, "load_s": 28.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-s1-base.json --port 8190"} +{"wall_s": 50.9, "prompt_n": 4052, "prompt_ms": 44017.5, "prompt_tps": 92.1, "pred_n": 94, "pred_tps": 13.7, "draft_n": 69, "draft_acc": 45, "text": "Strata is a local AI engine optimized for speed on specific hardware, achieving significant performance gains through fused int8 tensor-core kernels and speculative decoding techniques. The documentation details various memory management strategies, such as KV streaming and hybrid 4-bit caches, whic", "config": "s1-base", "round": 0, "cell": "4k", "temp": 0.0, "rep": 1, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.25, "load_s": 28.0, "cmd": null} +{"wall_s": 55.93, "prompt_n": 4052, "prompt_ms": 45970.2, "prompt_tps": 88.1, "pred_n": 123, "pred_tps": 12.4, "draft_n": 105, "draft_acc": 56, "text": "Strata is a local AI engine that delivers high-speed inference by utilizing fused int8 tensor-core kernels and speculative decoding to optimize both prompt processing and output generation across various model quantizations. The documentation details specific performance benchmarks on hardware like ", "config": "s1-base", "round": 0, "cell": "4k", "temp": 0.7, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.46, "load_s": 28.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-s1-base.json --port 8190"} +{"wall_s": 52.9, "prompt_n": 4052, "prompt_ms": 45067.9, "prompt_tps": 89.9, "pred_n": 96, "pred_tps": 12.3, "draft_n": 64, "draft_acc": 35, "text": "Strata is a local AI engine that delivers high-speed inference performance on consumer hardware by utilizing specialized kernels for prompt processing and speculative decoding to optimize output speeds. The documentation details extensive technical features, including KV cache streaming, hybrid quan", "config": "s1-base", "round": 0, "cell": "4k", "temp": 0.7, "rep": 1, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.79, "load_s": 28.0, "cmd": null} diff --git a/bench/results/2026-10-12-community-gfx1103/s2-table.jsonl b/bench/results/2026-10-12-community-gfx1103/s2-table.jsonl new file mode 100644 index 00000000..18f9cdf5 --- /dev/null +++ b/bench/results/2026-10-12-community-gfx1103/s2-table.jsonl @@ -0,0 +1,10 @@ +{"wall_s": 27.96, "prompt_n": 4052, "prompt_ms": 21652.6, "prompt_tps": 187.1, "pred_n": 92, "pred_tps": 14.6, "draft_n": 68, "draft_acc": 49, "text": "Strata is a high-performance AI engine optimized for various GPUs, achieving significant speed improvements through fused int8 tensor-core kernels and speculative decoding techniques. The documentation details specific benchmark results for prompt processing and output generation across different mo", "config": "s2-table", "round": 0, "cell": "4k", "temp": 0.0, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.23, "sys_used_delta_gib": 38.9, "load_s": 30.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-s2-table.json --port 8190"} +{"wall_s": 28.23, "prompt_n": 4052, "prompt_ms": 22051.3, "prompt_tps": 183.8, "pred_n": 88, "pred_tps": 14.3, "draft_n": 60, "draft_acc": 44, "text": "Strata is a high-performance AI engine optimized for various GPUs, achieving significant speed improvements through fused int8 tensor-core kernels and speculative decoding techniques. The documentation details specific benchmark results for prompt processing and output generation across different mo", "config": "s2-table", "round": 0, "cell": "4k", "temp": 0.0, "rep": 1, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.19, "load_s": 30.0, "cmd": null} +{"wall_s": 30.02, "prompt_n": 4052, "prompt_ms": 21810.3, "prompt_tps": 185.8, "pred_n": 109, "pred_tps": 13.3, "draft_n": 72, "draft_acc": 46, "text": "Strata is a local AI engine that delivers high-speed inference by utilizing fused int8 tensor-core kernels and speculative decoding to significantly boost prompt processing and output speeds across various GPU hardware. The system supports advanced memory management features like KV streaming and hy", "config": "s2-table", "round": 0, "cell": "4k", "temp": 0.7, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.48, "load_s": 30.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-s2-table.json --port 8190"} +{"wall_s": 30.65, "prompt_n": 4052, "prompt_ms": 21868.0, "prompt_tps": 185.3, "pred_n": 121, "pred_tps": 13.8, "draft_n": 93, "draft_acc": 61, "text": "Strata is a local AI engine that delivers high-speed inference for various quantized models on GPUs like the RTX 5070 and AMD RX 7900 XTX, with performance improvements in version 0.1.36 driven by fused kernels and speculative decoding. The documentation details technical optimizations such as KV ca", "config": "s2-table", "round": 0, "cell": "4k", "temp": 0.7, "rep": 1, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.74, "load_s": 30.0, "cmd": null} +{"wall_s": 189.86, "prompt_n": 32058, "prompt_ms": 180319.2, "prompt_tps": 177.8, "pred_n": 124, "pred_tps": 13.1, "draft_n": 95, "draft_acc": 63, "text": "Strata is a local AI engine optimized for Qwen3.8-Flash-Next models that achieves high performance on consumer hardware by using speculative decoding, adaptive expert caching, and low-RAM modes to efficiently manage large model weights across GPU and system memory. It provides a comprehensive API co", "config": "s2-table", "round": 0, "cell": "32k", "temp": 0.0, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.02, "load_s": 30.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-s2-table.json --port 8190"} +{"wall_s": 212.05, "prompt_n": 32058, "prompt_ms": 201403.1, "prompt_tps": 159.2, "pred_n": 124, "pred_tps": 11.7, "draft_n": 114, "draft_acc": 63, "text": "Strata is a local AI engine optimized for Qwen3.8-Flash-Next models on consumer GPUs, featuring advanced memory management techniques like KV streaming, hybrid KV caches, and low-RAM modes to enable efficient execution on machines with limited hardware resources. The system provides a comprehensive ", "config": "s2-table", "round": 0, "cell": "32k", "temp": 0.7, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.84, "load_s": 30.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-s2-table.json --port 8190"} +{"wall_s": 29.2, "prompt_n": 4052, "prompt_ms": 22012.5, "prompt_tps": 184.1, "pred_n": 98, "pred_tps": 13.7, "draft_n": 69, "draft_acc": 46, "text": "Strata is a local AI engine optimized for speed on specific hardware, featuring advanced techniques like fused int8 kernels, KV streaming, and speculative decoding to significantly improve prompt processing and output rates. The documentation provides detailed benchmark data for various models and G", "config": "s2-table", "round": 0, "cell": "4k", "temp": 0.0, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.23, "sys_used_delta_gib": 38.86, "load_s": 30.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-s2-table.json --port 8190"} +{"wall_s": 29.78, "prompt_n": 4052, "prompt_ms": 22095.3, "prompt_tps": 183.4, "pred_n": 112, "pred_tps": 14.6, "draft_n": 79, "draft_acc": 58, "text": "Strata is a local AI engine optimized for speed on specific hardware, achieving significant performance gains through fused int8 tensor-core kernels and speculative decoding on models like Q2_0 and IQ2_XS. The documentation details various memory management techniques, such as KV streaming and hybri", "config": "s2-table", "round": 0, "cell": "4k", "temp": 0.0, "rep": 1, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.23, "sys_used_delta_gib": 39.17, "load_s": 30.0, "cmd": null} +{"wall_s": 31.18, "prompt_n": 4052, "prompt_ms": 22448.0, "prompt_tps": 180.5, "pred_n": 132, "pred_tps": 15.1, "draft_n": 97, "draft_acc": 73, "text": "Strata is a local AI engine that delivers high-speed inference for various quantized models on GPUs like the RTX 5070 and AMD RX 7900 XTX, with performance metrics detailed for both prompt processing and output generation across different context lengths. The engine employs advanced optimization tec", "config": "s2-table", "round": 0, "cell": "4k", "temp": 0.7, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.23, "sys_used_delta_gib": 39.43, "load_s": 30.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-s2-table.json --port 8190"} +{"wall_s": 29.88, "prompt_n": 4052, "prompt_ms": 21947.0, "prompt_tps": 184.6, "pred_n": 121, "pred_tps": 15.3, "draft_n": 95, "draft_acc": 70, "text": "Strata is a local AI engine that delivers high-speed inference for various quantized models on GPUs like the RTX 5070 and AMD RX 7900 XTX, with performance metrics detailed for both prompt processing and output generation. The engine employs advanced optimizations such as KV streaming, hybrid KV cac", "config": "s2-table", "round": 0, "cell": "4k", "temp": 0.7, "rep": 1, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.23, "sys_used_delta_gib": 39.71, "load_s": 30.0, "cmd": null} diff --git a/bench/results/2026-10-12-community-gfx1103/s3-table-exact.jsonl b/bench/results/2026-10-12-community-gfx1103/s3-table-exact.jsonl new file mode 100644 index 00000000..a75be13b --- /dev/null +++ b/bench/results/2026-10-12-community-gfx1103/s3-table-exact.jsonl @@ -0,0 +1,4 @@ +{"wall_s": 27.39, "prompt_n": 4054, "prompt_ms": 19361.2, "prompt_tps": 209.4, "pred_n": 108, "pred_tps": 13.5, "draft_n": 89, "draft_acc": 51, "text": "Strata is a local AI engine optimized for speed on specific hardware, featuring recent updates like fused int8 tensor-core kernels and thread-block clusters that significantly improve prompt processing and output speeds for models like Q2_0. The documentation details various memory management techni", "config": "s3-table-exact", "round": 0, "cell": "4k", "temp": 0.0, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 38.96, "load_s": 30.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-s3-table-exact.json --port 8190"} +{"wall_s": 26.98, "prompt_n": 4054, "prompt_ms": 19106.1, "prompt_tps": 212.2, "pred_n": 104, "pred_tps": 13.2, "draft_n": 80, "draft_acc": 45, "text": "Strata is a local AI engine optimized for speed on specific hardware, featuring recent updates like fused int8 tensor-core kernels and thread-block clusters that significantly improve prompt processing and output speeds. The documentation details various memory management techniques, such as KV stre", "config": "s3-table-exact", "round": 0, "cell": "4k", "temp": 0.0, "rep": 1, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.23, "load_s": 30.0, "cmd": null} +{"wall_s": 28.14, "prompt_n": 4054, "prompt_ms": 19202.9, "prompt_tps": 211.1, "pred_n": 116, "pred_tps": 13.0, "draft_n": 98, "draft_acc": 53, "text": "Strata is a high-performance AI engine optimized for long-context processing, achieving significant speed improvements through fused int8 tensor-core kernels and speculative decoding on modern GPUs like the RTX 5070. The system offers flexible memory management options, including KV streaming, 4-bit", "config": "s3-table-exact", "round": 0, "cell": "4k", "temp": 0.7, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.52, "load_s": 30.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-s3-table-exact.json --port 8190"} +{"wall_s": 26.89, "prompt_n": 4054, "prompt_ms": 19185.6, "prompt_tps": 211.3, "pred_n": 107, "pred_tps": 13.9, "draft_n": 90, "draft_acc": 54, "text": "Strata is a high-performance AI engine optimized for GPUs like the RTX 5070 and AMD RX 7900 XTX, achieving significant speed improvements through fused int8 tensor-core kernels and speculative decoding. The documentation details various configuration options for memory management, such as KV streami", "config": "s3-table-exact", "round": 0, "cell": "4k", "temp": 0.7, "rep": 1, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.8, "load_s": 30.0, "cmd": null} diff --git a/bench/results/2026-10-12-community-gfx1103/s3a-table-prompt5.jsonl b/bench/results/2026-10-12-community-gfx1103/s3a-table-prompt5.jsonl new file mode 100644 index 00000000..a29fc736 --- /dev/null +++ b/bench/results/2026-10-12-community-gfx1103/s3a-table-prompt5.jsonl @@ -0,0 +1,4 @@ +{"wall_s": 28.31, "prompt_n": 4056, "prompt_ms": 21214.5, "prompt_tps": 191.2, "pred_n": 106, "pred_tps": 15.0, "draft_n": 82, "draft_acc": 62, "text": "Strata is a high-performance AI engine optimized for various GPUs, featuring significant speed improvements in version 0.1.36 through fused int8 tensor-core kernels and thread-block clusters for both prompt processing and output generation. The engine offers advanced memory management options, such ", "config": "s3a-table-prompt5", "round": 0, "cell": "4k", "temp": 0.0, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.23, "sys_used_delta_gib": 38.84, "load_s": 32.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-s3a-table-prompt5.json --port 8190"} +{"wall_s": 27.77, "prompt_n": 4056, "prompt_ms": 21304.9, "prompt_tps": 190.4, "pred_n": 84, "pred_tps": 13.0, "draft_n": 72, "draft_acc": 40, "text": "Strata is a high-performance AI engine optimized for various GPUs, achieving significant speed improvements through fused int8 tensor-core kernels and speculative decoding techniques. The documentation details specific performance benchmarks for different model sizes and hardware configurations, hig", "config": "s3a-table-prompt5", "round": 0, "cell": "4k", "temp": 0.0, "rep": 1, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.23, "sys_used_delta_gib": 39.15, "load_s": 32.0, "cmd": null} +{"wall_s": 29.03, "prompt_n": 4056, "prompt_ms": 21475.2, "prompt_tps": 188.9, "pred_n": 97, "pred_tps": 12.9, "draft_n": 73, "draft_acc": 45, "text": "Strata is a local AI engine optimized for speed on consumer hardware, achieving high prompt processing and output throughput through techniques like speculative decoding, KV cache streaming, and fused tensor-core kernels. The documentation provides detailed performance benchmarks across various GPU ", "config": "s3a-table-prompt5", "round": 0, "cell": "4k", "temp": 0.7, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.23, "sys_used_delta_gib": 39.41, "load_s": 32.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-s3a-table-prompt5.json --port 8190"} +{"wall_s": 28.76, "prompt_n": 4056, "prompt_ms": 21127.9, "prompt_tps": 192.0, "pred_n": 93, "pred_tps": 12.2, "draft_n": 68, "draft_acc": 34, "text": "Strata is a high-performance local AI engine that achieves significant speed improvements through optimized fused kernels, speculative decoding, and advanced KV cache management techniques like streaming and hybrid quantization. The documentation provides detailed benchmark data for various models o", "config": "s3a-table-prompt5", "round": 0, "cell": "4k", "temp": 0.7, "rep": 1, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.23, "sys_used_delta_gib": 39.68, "load_s": 32.0, "cmd": null} diff --git a/bench/results/2026-10-12-community-gfx1103/s3b-table-decode11.jsonl b/bench/results/2026-10-12-community-gfx1103/s3b-table-decode11.jsonl new file mode 100644 index 00000000..ed427d3b --- /dev/null +++ b/bench/results/2026-10-12-community-gfx1103/s3b-table-decode11.jsonl @@ -0,0 +1,4 @@ +{"wall_s": 26.8, "prompt_n": 4057, "prompt_ms": 20671.5, "prompt_tps": 196.3, "pred_n": 94, "pred_tps": 15.4, "draft_n": 63, "draft_acc": 48, "text": "Strata is a high-performance AI engine optimized for various GPUs, achieving significant speed improvements through fused int8 tensor-core kernels and speculative decoding techniques. The documentation details specific performance benchmarks for different model sizes and context lengths, highlightin", "config": "s3b-table-decode11", "round": 0, "cell": "4k", "temp": 0.0, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.17, "load_s": 30.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-s3b-table-decode11.json --port 8190"} +{"wall_s": 26.41, "prompt_n": 4057, "prompt_ms": 20289.8, "prompt_tps": 200.0, "pred_n": 93, "pred_tps": 15.2, "draft_n": 64, "draft_acc": 49, "text": "Strata is a high-performance AI engine optimized for various GPUs, achieving significant speed improvements through fused int8 tensor-core kernels and speculative decoding techniques. The documentation details specific performance benchmarks for prompt processing and output generation across differe", "config": "s3b-table-decode11", "round": 0, "cell": "4k", "temp": 0.0, "rep": 1, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.25, "load_s": 30.0, "cmd": null} +{"wall_s": 29.21, "prompt_n": 4057, "prompt_ms": 20932.3, "prompt_tps": 193.8, "pred_n": 106, "pred_tps": 12.8, "draft_n": 85, "draft_acc": 45, "text": "Strata is a local AI engine that achieves high performance on consumer hardware by using speculative decoding, fused tensor-core kernels, and memory-efficient KV cache options like streaming and hybrid formats to maximize speed and context capacity. The documentation provides detailed benchmark data", "config": "s3b-table-decode11", "round": 0, "cell": "4k", "temp": 0.7, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.55, "load_s": 30.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-s3b-table-decode11.json --port 8190"} +{"wall_s": 32.99, "prompt_n": 4057, "prompt_ms": 22806.7, "prompt_tps": 177.9, "pred_n": 113, "pred_tps": 11.1, "draft_n": 80, "draft_acc": 53, "text": "Strata is a high-performance AI inference engine that achieves significant speed improvements through advanced techniques like fused int8 tensor-core kernels, speculative decoding, and dynamic KV cache streaming. The documentation provides detailed benchmark data for various models on different hard", "config": "s3b-table-decode11", "round": 0, "cell": "4k", "temp": 0.7, "rep": 1, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.84, "load_s": 30.0, "cmd": null} diff --git a/bench/results/2026-10-12-community-gfx1103/s4-table-wmma.jsonl b/bench/results/2026-10-12-community-gfx1103/s4-table-wmma.jsonl new file mode 100644 index 00000000..2dbf45a8 --- /dev/null +++ b/bench/results/2026-10-12-community-gfx1103/s4-table-wmma.jsonl @@ -0,0 +1,6 @@ +{"wall_s": 24.35, "prompt_n": 4054, "prompt_ms": 16272.5, "prompt_tps": 249.1, "pred_n": 110, "pred_tps": 13.6, "draft_n": 84, "draft_acc": 53, "text": "Strata is a local AI engine optimized for speed on specific hardware, achieving significant performance gains through fused int8 tensor-core kernels and speculative decoding on RTX 30 and newer GPUs. The documentation details various memory optimization techniques, such as KV streaming and hybrid K8", "config": "s4-table-wmma", "round": 0, "cell": "4k", "temp": 0.0, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 38.9, "load_s": 30.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-s4-table-wmma.json --port 8190"} +{"wall_s": 24.93, "prompt_n": 4054, "prompt_ms": 16446.1, "prompt_tps": 246.5, "pred_n": 113, "pred_tps": 13.3, "draft_n": 94, "draft_acc": 55, "text": "Strata is a local AI engine optimized for speed on specific hardware, achieving significant performance gains through fused int8 tensor-core kernels and speculative decoding on RTX 30 and newer GPUs. The documentation details various memory management techniques, such as KV streaming and hybrid K8V4", "config": "s4-table-wmma", "round": 0, "cell": "4k", "temp": 0.0, "rep": 1, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.18, "load_s": 30.0, "cmd": null} +{"wall_s": 25.19, "prompt_n": 4054, "prompt_ms": 16299.7, "prompt_tps": 248.7, "pred_n": 119, "pred_tps": 13.4, "draft_n": 89, "draft_acc": 55, "text": "Strata is a high-performance local AI engine that leverages advanced optimization techniques, such as fused int8 tensor-core kernels and KV streaming, to significantly improve prompt and output speeds across various model sizes and hardware configurations. The documentation details specific performa", "config": "s4-table-wmma", "round": 0, "cell": "4k", "temp": 0.7, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.47, "load_s": 30.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-s4-table-wmma.json --port 8190"} +{"wall_s": 24.31, "prompt_n": 4054, "prompt_ms": 16397.2, "prompt_tps": 247.2, "pred_n": 107, "pred_tps": 13.5, "draft_n": 84, "draft_acc": 53, "text": "Strata is a high-performance local AI engine that leverages advanced optimization techniques, such as fused int8 tensor-core kernels and KV streaming, to achieve significant speedups in prompt processing and output generation across various GPU architectures. The documentation provides detailed benc", "config": "s4-table-wmma", "round": 0, "cell": "4k", "temp": 0.7, "rep": 1, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.76, "load_s": 30.0, "cmd": null} +{"wall_s": 126.27, "prompt_n": 32060, "prompt_ms": 117646.1, "prompt_tps": 272.5, "pred_n": 123, "pred_tps": 14.3, "draft_n": 90, "draft_acc": 63, "text": "Strata is a local AI engine optimized for Qwen3.8-Flash-Next models that achieves high performance on consumer hardware by using speculative decoding, adaptive expert caching, and low-RAM modes to efficiently manage large model weights across GPU and system memory. It provides a comprehensive API co", "config": "s4-table-wmma", "round": 0, "cell": "32k", "temp": 0.0, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.0, "load_s": 30.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-s4-table-wmma.json --port 8190"} +{"wall_s": 139.7, "prompt_n": 32060, "prompt_ms": 127975.8, "prompt_tps": 250.5, "pred_n": 134, "pred_tps": 11.5, "draft_n": 113, "draft_acc": 63, "text": "Strata is a local AI engine optimized for Qwen3.8-Flash-Next models that delivers high-speed inference on NVIDIA and AMD GPUs by leveraging advanced techniques like speculative decoding, KV cache streaming, and adaptive expert tiering to balance CPU and VRAM resources. The system provides a comprehe", "config": "s4-table-wmma", "round": 0, "cell": "32k", "temp": 0.7, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.81, "load_s": 30.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-s4-table-wmma.json --port 8190"} diff --git a/bench/results/2026-10-12-community-gfx1103/s5-table-wmma-fused.jsonl b/bench/results/2026-10-12-community-gfx1103/s5-table-wmma-fused.jsonl new file mode 100644 index 00000000..ab66364c --- /dev/null +++ b/bench/results/2026-10-12-community-gfx1103/s5-table-wmma-fused.jsonl @@ -0,0 +1,4 @@ +{"wall_s": 23.56, "prompt_n": 4056, "prompt_ms": 16434.3, "prompt_tps": 246.8, "pred_n": 102, "pred_tps": 14.3, "draft_n": 74, "draft_acc": 52, "text": "Strata is a high-performance AI engine optimized for various GPUs, achieving significant speed improvements through fused int8 tensor-core kernels and speculative decoding techniques. The documentation details specific performance benchmarks for different models and context lengths, highlighting fea", "config": "s5-table-wmma-fused", "round": 0, "cell": "4k", "temp": 0.0, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.14, "load_s": 30.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-s5-table-wmma-fused.json --port 8190"} +{"wall_s": 24.2, "prompt_n": 4056, "prompt_ms": 16579.7, "prompt_tps": 244.6, "pred_n": 101, "pred_tps": 13.3, "draft_n": 74, "draft_acc": 45, "text": "Strata is a high-performance AI engine that achieves significant speed improvements through fused int8 tensor-core kernels and speculative decoding, with benchmark data showing substantial gains in prompt processing and output generation across various model sizes. The system offers advanced memory ", "config": "s5-table-wmma-fused", "round": 0, "cell": "4k", "temp": 0.0, "rep": 1, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.21, "load_s": 30.0, "cmd": null} +{"wall_s": 27.83, "prompt_n": 4056, "prompt_ms": 16383.0, "prompt_tps": 247.6, "pred_n": 129, "pred_tps": 11.3, "draft_n": 129, "draft_acc": 55, "text": "Strata is an AI engine optimized for RTX 5070 and AMD GPUs that achieves significant speed improvements through fused int8 tensor-core kernels, thread-block clusters, and speculative decoding. The documentation details various performance benchmarks for prompt processing and output tokens per second", "config": "s5-table-wmma-fused", "round": 0, "cell": "4k", "temp": 0.7, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.5, "load_s": 30.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-s5-table-wmma-fused.json --port 8190"} +{"wall_s": 26.29, "prompt_n": 4056, "prompt_ms": 16552.3, "prompt_tps": 245.0, "pred_n": 123, "pred_tps": 12.6, "draft_n": 117, "draft_acc": 61, "text": "Strata is an AI engine optimized for RTX 30 and newer GPUs, achieving significant speed improvements through fused int8 tensor-core kernels and speculative decoding for prompt processing and output generation. The documentation details various configuration options, such as KV cache streaming, hybri", "config": "s5-table-wmma-fused", "round": 0, "cell": "4k", "temp": 0.7, "rep": 1, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.77, "load_s": 30.0, "cmd": null} diff --git a/bench/results/2026-10-12-community-gfx1103/s6-table-all.jsonl b/bench/results/2026-10-12-community-gfx1103/s6-table-all.jsonl new file mode 100644 index 00000000..3e66c01f --- /dev/null +++ b/bench/results/2026-10-12-community-gfx1103/s6-table-all.jsonl @@ -0,0 +1,6 @@ +{"wall_s": 20.86, "prompt_n": 4053, "prompt_ms": 14601.2, "prompt_tps": 277.6, "pred_n": 91, "pred_tps": 14.6, "draft_n": 66, "draft_acc": 45, "text": "Strata is a high-performance AI engine optimized for various GPUs, achieving significant speed improvements through fused int8 tensor-core kernels and speculative decoding techniques. The documentation details specific performance benchmarks for different model sizes and hardware configurations, hig", "config": "s6-table-all", "round": 0, "cell": "4k", "temp": 0.0, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.12, "load_s": 30.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-s6-table-all.json --port 8190"} +{"wall_s": 20.94, "prompt_n": 4053, "prompt_ms": 14716.2, "prompt_tps": 275.4, "pred_n": 93, "pred_tps": 15.0, "draft_n": 64, "draft_acc": 47, "text": "Strata is a high-performance AI engine optimized for various GPUs, achieving significant speed improvements through fused int8 tensor-core kernels and speculative decoding techniques. The documentation details specific performance benchmarks for prompt processing and output generation across differe", "config": "s6-table-all", "round": 0, "cell": "4k", "temp": 0.0, "rep": 1, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.39, "load_s": 30.0, "cmd": null} +{"wall_s": 23.46, "prompt_n": 4053, "prompt_ms": 14539.8, "prompt_tps": 278.8, "pred_n": 118, "pred_tps": 13.2, "draft_n": 99, "draft_acc": 53, "text": "Strata is a local AI engine that achieves high performance through speculative decoding, KV cache streaming, and fused tensor-core kernels, with benchmark results demonstrating significant speed improvements across various model sizes and GPU configurations. The engine offers advanced memory managem", "config": "s6-table-all", "round": 0, "cell": "4k", "temp": 0.7, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.67, "load_s": 30.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-s6-table-all.json --port 8190"} +{"wall_s": 22.33, "prompt_n": 4053, "prompt_ms": 14641.3, "prompt_tps": 276.8, "pred_n": 109, "pred_tps": 14.2, "draft_n": 82, "draft_acc": 53, "text": "Strata is a high-performance AI engine optimized for various hardware configurations, featuring significant speed improvements in version 0.1.36 through fused int8 tensor-core kernels and specialized decode path optimizations. The documentation details extensive technical benchmarks for prompt proce", "config": "s6-table-all", "round": 0, "cell": "4k", "temp": 0.7, "rep": 1, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.95, "load_s": 30.0, "cmd": null} +{"wall_s": 122.05, "prompt_n": 32059, "prompt_ms": 110471.4, "prompt_tps": 290.2, "pred_n": 137, "pred_tps": 11.9, "draft_n": 102, "draft_acc": 67, "text": "Strata is a local AI engine optimized for Qwen3.8-Flash-Next models that achieves high performance on consumer hardware by using speculative decoding, expert caching, and low-RAM modes to efficiently manage large model weights across GPU and system memory. It provides a comprehensive API compatible ", "config": "s6-table-all", "round": 0, "cell": "32k", "temp": 0.0, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.11, "load_s": 30.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-s6-table-all.json --port 8190"} +{"wall_s": 141.96, "prompt_n": 32059, "prompt_ms": 132319.7, "prompt_tps": 242.3, "pred_n": 115, "pred_tps": 12.0, "draft_n": 100, "draft_acc": 59, "text": "Strata is a local LLM engine optimized for Qwen3.8-Flash-Next models that utilizes advanced techniques like speculative decoding, KV cache streaming, and low-RAM expert mapping to achieve high prompt processing and output speeds on consumer GPUs. The document details extensive technical configuratio", "config": "s6-table-all", "round": 0, "cell": "32k", "temp": 0.7, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.83, "load_s": 30.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-s6-table-all.json --port 8190"} diff --git a/bench/results/2026-10-12-community-gfx1103/strata-base.jsonl b/bench/results/2026-10-12-community-gfx1103/strata-base.jsonl new file mode 100644 index 00000000..bd483f86 --- /dev/null +++ b/bench/results/2026-10-12-community-gfx1103/strata-base.jsonl @@ -0,0 +1,6 @@ +{"wall_s": 52.49, "prompt_n": 4052, "prompt_ms": 43555.7, "prompt_tps": 93.0, "pred_n": 115, "pred_tps": 12.9, "draft_n": 95, "draft_acc": 52, "text": "Strata is a local AI engine optimized for speed on specific hardware configurations, featuring advanced techniques like KV streaming, speculative decoding, and fused tensor-core kernels to significantly improve prompt processing and output generation rates. The documentation provides detailed benchm", "config": "strata-base", "round": 0, "cell": "4k", "temp": 0.0, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 38.6, "load_s": 28.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-strata-base.json --port 8190"} +{"wall_s": 52.86, "prompt_n": 4052, "prompt_ms": 44875.6, "prompt_tps": 90.3, "pred_n": 103, "pred_tps": 12.9, "draft_n": 74, "draft_acc": 42, "text": "Strata is a local AI engine optimized for speed and memory efficiency, featuring recent updates like fused int8 tensor-core kernels and KV streaming that significantly improve prompt processing and output rates on various GPUs. The documentation details specific performance benchmarks for different ", "config": "strata-base", "round": 0, "cell": "4k", "temp": 0.0, "rep": 1, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 38.87, "load_s": 28.0, "cmd": null} +{"wall_s": 52.52, "prompt_n": 4052, "prompt_ms": 43629.8, "prompt_tps": 92.9, "pred_n": 122, "pred_tps": 13.7, "draft_n": 96, "draft_acc": 62, "text": "Strata is a local AI engine that delivers high-speed performance through optimized kernels and speculative decoding, achieving over 1,000 tokens per second in prompt processing and approximately 90 tokens per second in output on an RTX 5070. The document details various memory-saving features, such ", "config": "strata-base", "round": 0, "cell": "4k", "temp": 0.7, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.15, "load_s": 28.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-strata-base.json --port 8190"} +{"wall_s": 52.64, "prompt_n": 4052, "prompt_ms": 43422.6, "prompt_tps": 93.3, "pred_n": 135, "pred_tps": 14.7, "draft_n": 97, "draft_acc": 71, "text": "Strata is a local AI engine that delivers high-speed performance through optimized kernels and speculative decoding, achieving over 1,000 tokens per second in prompt processing and nearly 100 tokens per second in output on modern hardware like the RTX 5070. The engine features advanced memory manage", "config": "strata-base", "round": 0, "cell": "4k", "temp": 0.7, "rep": 1, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.46, "load_s": 28.0, "cmd": null} +{"wall_s": 362.21, "prompt_n": 32058, "prompt_ms": 351862.3, "prompt_tps": 91.1, "pred_n": 141, "pred_tps": 13.7, "draft_n": 108, "draft_acc": 72, "text": "Strata is a local AI engine optimized for Qwen3.8-Flash-Next models that achieves high performance on consumer hardware by using speculative decoding, adaptive expert caching, and low-RAM modes to efficiently manage large model weights across GPU and system memory. It provides a comprehensive API co", "config": "strata-base", "round": 0, "cell": "32k", "temp": 0.0, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.86, "load_s": 28.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-strata-base.json --port 8190"} +{"wall_s": 358.73, "prompt_n": 32058, "prompt_ms": 349500.1, "prompt_tps": 91.7, "pred_n": 122, "pred_tps": 13.3, "draft_n": 97, "draft_acc": 63, "text": "Strata is a local AI engine optimized for Qwen3.8-Flash-Next models on consumer hardware, offering detailed performance metrics for various GPU configurations and features like KV streaming, low-RAM modes, and speculative decoding to balance speed and quality. It supports multiple API interfaces (Op", "config": "strata-base", "round": 0, "cell": "32k", "temp": 0.7, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 40.64, "load_s": 28.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-strata-base.json --port 8190"} diff --git a/bench/results/2026-10-12-community-gfx1103/strata-gfx1103.json b/bench/results/2026-10-12-community-gfx1103/strata-gfx1103.json new file mode 100644 index 00000000..041888b6 --- /dev/null +++ b/bench/results/2026-10-12-community-gfx1103/strata-gfx1103.json @@ -0,0 +1,34 @@ +{ + "exe": "~/llm/Strata/build-780m/strata", + "args": [ + "--pack", "/data/packs/qwen-q2_0", + "--native", "/models/flash-next/Q2_0/Qwen3.8-Flash-Next-GSQ-RCO-Q2_0-00001-of-00002.gguf", + "--ple-gguf", "/models/flash-next/Q2_0/Qwen3.8-Flash-Next-GSQ-RCO-Q2_0-00002-of-00002.gguf", + "--expert-profile", "~/llm/Strata/data/expert-profile.bin", + "--expert-cache", "24576", + "--mmap-experts", + "--prefill", "auto", + "--spec", "2", + "--lookup-chain", "4", + "--mtp", "/data/mtp/rt", + "--max-context", "32768", + "--kv", "int8", + "--conversation-cache-mib", "12288", + "--conversation-cache-slots", "8", + "--vram-reserve-mib", "700" + ], + "cwd": "~/llm/Strata", + "tokenizer": "/data/packs/qwen-q2_0/tokenizer", + "model_name": "qwen3.8-flash-next", + "aliases": ["flash-next-q2"], + "port": 8080, + "backend": "hip", + "env": { + "STRATA_HIPBLASLT_TUNING": "~/llm/Strata/tools/hip/gfx1103-hipblaslt-100401.txt", + "STRATA_GDN_HEAD": "1", "STRATA_GDN_PP": "2", "STRATA_GDN_CONVL2": "1", "STRATA_GDN_NOY": "1", + "STRATA_CVEC_FUSE": "1", "STRATA_PF_PAD": "1", + "STRATA_Q8_PACKED": "1", "STRATA_Q6_PACKED": "1", "STRATA_MMVF_ROWS": "1", "STRATA_ATTN_LANECELL": "1", + "STRATA_EXPERT_V2": "1", "STRATA_TSUM": "1", "STRATA_LFUSE": "1", "STRATA_GDN_SPLIT": "1", + "STRATA_QFUSE": "1", "STRATA_PLE_BATCH": "1", "STRATA_SH_STREAM": "1" + } +} diff --git a/bench/results/2026-10-12-community-gfx1103/strata-table.jsonl b/bench/results/2026-10-12-community-gfx1103/strata-table.jsonl new file mode 100644 index 00000000..8eb02b7a --- /dev/null +++ b/bench/results/2026-10-12-community-gfx1103/strata-table.jsonl @@ -0,0 +1,6 @@ +{"wall_s": 51.65, "prompt_n": 4052, "prompt_ms": 43992.3, "prompt_tps": 92.1, "pred_n": 103, "pred_tps": 13.5, "draft_n": 76, "draft_acc": 50, "text": "Strata is a local AI engine optimized for speed on specific hardware, achieving high prompt and output token rates through techniques like fused int8 kernels, speculative decoding, and KV cache streaming. The documentation details performance benchmarks across various models and GPUs, highlighting s", "config": "strata-table", "round": 0, "cell": "4k", "temp": 0.0, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 38.87, "load_s": 28.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-strata-table.json --port 8190"} +{"wall_s": 50.89, "prompt_n": 4052, "prompt_ms": 43282.1, "prompt_tps": 93.6, "pred_n": 99, "pred_tps": 13.0, "draft_n": 78, "draft_acc": 45, "text": "Strata is a local AI engine optimized for speed on specific hardware, achieving significant performance gains through fused int8 tensor-core kernels and speculative decoding techniques. The documentation details various memory management strategies, such as KV streaming and hybrid K8V4 caches, which", "config": "strata-table", "round": 0, "cell": "4k", "temp": 0.0, "rep": 1, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.15, "load_s": 28.0, "cmd": null} +{"wall_s": 50.33, "prompt_n": 4052, "prompt_ms": 44033.8, "prompt_tps": 92.0, "pred_n": 81, "pred_tps": 12.9, "draft_n": 70, "draft_acc": 39, "text": "Strata is a local AI engine that delivers high-speed inference performance on consumer hardware, achieving significant speed improvements through optimized kernels and speculative decoding techniques. It offers flexible memory management features, such as KV streaming and hybrid 4-bit caches, to ena", "config": "strata-table", "round": 0, "cell": "4k", "temp": 0.7, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.44, "load_s": 28.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-strata-table.json --port 8190"} +{"wall_s": 52.46, "prompt_n": 4052, "prompt_ms": 43881.7, "prompt_tps": 92.3, "pred_n": 125, "pred_tps": 14.6, "draft_n": 99, "draft_acc": 68, "text": "Strata is a local AI engine that delivers high-speed inference performance on consumer hardware, achieving over 1,000 tokens per second for prompt processing and 50-90 tokens per second for output on models like Q2_0 and IQ3_XXS. The system utilizes advanced optimization techniques, including specul", "config": "strata-table", "round": 0, "cell": "4k", "temp": 0.7, "rep": 1, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.71, "load_s": 28.0, "cmd": null} +{"wall_s": 359.89, "prompt_n": 32058, "prompt_ms": 351109.8, "prompt_tps": 91.3, "pred_n": 120, "pred_tps": 13.7, "draft_n": 86, "draft_acc": 58, "text": "Strata is a local AI engine optimized for Qwen3.8-Flash-Next models that achieves high performance on consumer hardware by using speculative decoding, adaptive expert caching, and low-RAM modes to efficiently manage large model weights across GPU and system memory. It provides a comprehensive API co", "config": "strata-table", "round": 0, "cell": "32k", "temp": 0.0, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 40.26, "load_s": 28.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-strata-table.json --port 8190"} +{"wall_s": 361.01, "prompt_n": 32058, "prompt_ms": 351360.7, "prompt_tps": 91.2, "pred_n": 123, "pred_tps": 12.8, "draft_n": 96, "draft_acc": 55, "text": "Strata is a local AI engine optimized for Qwen3.8-Flash-Next models on consumer hardware, featuring advanced memory management techniques like KV streaming, hybrid KV caches, and low-RAM modes to enable 64-bit context windows on systems with 32-64 GB RAM. It supports a flexible API compatible with O", "config": "strata-table", "round": 0, "cell": "32k", "temp": 0.7, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 41.07, "load_s": 28.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-strata-table.json --port 8190"} diff --git a/bench/results/2026-10-12-community-gfx1103/strata.jsonl b/bench/results/2026-10-12-community-gfx1103/strata.jsonl new file mode 100644 index 00000000..79dac1dd --- /dev/null +++ b/bench/results/2026-10-12-community-gfx1103/strata.jsonl @@ -0,0 +1,6 @@ +{"wall_s": 53.56, "prompt_n": 4051, "prompt_ms": 45084.7, "prompt_tps": 89.9, "pred_n": 103, "pred_tps": 12.2, "draft_n": 86, "draft_acc": 43, "text": "Strata is a local AI engine optimized for speed on specific hardware, featuring recent updates like fused int8 kernels and thread-block clusters that significantly improve prompt processing and output speeds for models like Q2_0. The documentation details various memory management techniques, such a", "config": "strata", "round": 0, "cell": "4k", "temp": 0.0, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.23, "sys_used_delta_gib": 38.86, "load_s": 30.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-strata.json --port 8190"} +{"wall_s": 52.81, "prompt_n": 4051, "prompt_ms": 45181.7, "prompt_tps": 89.7, "pred_n": 104, "pred_tps": 13.7, "draft_n": 79, "draft_acc": 49, "text": "Strata is a local AI engine optimized for speed on specific hardware, featuring advanced techniques like fused int8 kernels, KV streaming, and speculative decoding to significantly improve prompt processing and output generation rates. The documentation provides detailed benchmark data for various m", "config": "strata", "round": 0, "cell": "4k", "temp": 0.0, "rep": 1, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.23, "sys_used_delta_gib": 39.14, "load_s": 30.0, "cmd": null} +{"wall_s": 54.22, "prompt_n": 4051, "prompt_ms": 44951.7, "prompt_tps": 90.1, "pred_n": 140, "pred_tps": 15.1, "draft_n": 110, "draft_acc": 82, "text": "The Strata engine achieves significant performance improvements in version 0.1.36 through fused int8 tensor-core kernels and thread-block clusters, resulting in 16\u201322% faster prompt processing and higher output speeds for models like Q2_0. To handle large context windows efficiently, the system supp", "config": "strata", "round": 0, "cell": "4k", "temp": 0.7, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.23, "sys_used_delta_gib": 39.41, "load_s": 30.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-strata.json --port 8190"} +{"wall_s": 52.64, "prompt_n": 4051, "prompt_ms": 45055.6, "prompt_tps": 89.9, "pred_n": 101, "pred_tps": 13.3, "draft_n": 78, "draft_acc": 48, "text": "The Strata engine delivers high performance on RTX 5070 hardware, achieving significant speed improvements in prompt processing and output generation through optimized fused kernels and speculative decoding. The technical documentation details various configuration options, such as KV cache streamin", "config": "strata", "round": 0, "cell": "4k", "temp": 0.7, "rep": 1, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.23, "sys_used_delta_gib": 39.72, "load_s": 30.0, "cmd": null} +{"wall_s": 365.07, "prompt_n": 32057, "prompt_ms": 356669.0, "prompt_tps": 89.9, "pred_n": 109, "pred_tps": 13.1, "draft_n": 93, "draft_acc": 54, "text": "Strata is a local AI engine optimized for Qwen3.8-Flash-Next models that achieves high performance on consumer hardware by using speculative decoding, KV cache streaming, and adaptive expert caching to manage memory efficiently. It provides a comprehensive API compatible with OpenAI, Anthropic, and ", "config": "strata", "round": 0, "cell": "32k", "temp": 0.0, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 40.11, "load_s": 30.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-strata.json --port 8190"} +{"wall_s": 365.03, "prompt_n": 32057, "prompt_ms": 357066.0, "prompt_tps": 89.8, "pred_n": 104, "pred_tps": 13.1, "draft_n": 85, "draft_acc": 52, "text": "Strata is a local AI engine for Qwen3.8-Flash-Next models that utilizes MTP speculative decoding and an adaptive expert caching system to optimize speed on consumer hardware. It offers a comprehensive API compatible with OpenAI, Anthropic, and MCP standards, featuring extensive configuration options", "config": "strata", "round": 0, "cell": "32k", "temp": 0.7, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 40.92, "load_s": 30.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-strata.json --port 8190"} diff --git a/bench/results/2026-10-12-community-gfx1103/tune-summary.csv b/bench/results/2026-10-12-community-gfx1103/tune-summary.csv new file mode 100644 index 00000000..12c6a314 --- /dev/null +++ b/bench/results/2026-10-12-community-gfx1103/tune-summary.csv @@ -0,0 +1,144 @@ +dtype,T,N,K,ldy,hipblas_ms,hipblaslt_ms,speedup,solution_id,candidates +f16,16384,12288,2560,12288,651.4479,197.0342,3.31,6137,7 +f16,16384,10240,2560,10240,542.8069,166.0204,3.27,6137,7 +f16,16384,6144,2560,6144,345.9530,96.6217,3.58,6137,7 +f16,16384,2560,6144,2560,390.0417,107.3124,3.63,6137,7 +f16,16384,2560,640,2560,33.6158,13.3609,2.52,6137,7 +f16,16384,640,2560,640,33.8896,10.0479,3.37,6137,7 +f16,16384,512,2560,512,29.6666,7.9387,3.74,6137,7 +bf16,16384,10240,2560,10240,631.0419,160.4246,3.93,5532,9 +bf16,16384,10240,320,10240,75.3301,19.1821,3.93,5532,9 +bf16,16384,320,10240,320,89.4026,21.8081,4.10,5532,9 +bf16,16384,2560,2560,2560,157.4283,39.5652,3.98,5532,9 +bf16,16384,512,2560,512,32.5609,7.6947,4.23,5532,9 +bf16,16384,128,2560,128,13.7590,2.2721,6.06,5532,9 +bf16,16384,48,2560,96,18.4464,1.3195,13.98,5532,9 +bf16,16384,4,10240,4,52.5905,4.1701,12.61,5529,9 +bf16,16384,1,2560,1,3.0841,1.1410,2.70,5529,9 +f16,8192,12288,2560,12288,323.5122,94.2652,3.43,6137,7 +f16,8192,10240,2560,10240,273.5645,77.9223,3.51,6137,7 +f16,8192,6144,2560,6144,167.4047,44.9688,3.72,6137,7 +f16,8192,2560,6144,2560,196.8117,50.2592,3.92,6137,7 +f16,8192,2560,640,2560,21.1493,8.6701,2.44,6137,7 +f16,8192,640,2560,640,20.6502,4.4961,4.59,6137,7 +f16,8192,512,2560,512,18.8066,3.2986,5.70,6137,7 +bf16,8192,10240,2560,10240,328.2333,77.4579,4.24,5532,9 +bf16,8192,10240,320,10240,36.8328,13.6604,2.70,5532,9 +bf16,8192,320,10240,320,42.6251,10.7526,3.96,5532,9 +bf16,8192,2560,2560,2560,76.3570,21.3682,3.57,5532,9 +bf16,8192,512,2560,512,18.9671,3.2273,5.88,5532,9 +bf16,8192,128,2560,128,8.8628,1.1204,7.91,5532,9 +bf16,8192,48,2560,96,13.5616,0.6895,19.67,5532,9 +bf16,8192,4,10240,4,27.3588,2.1101,12.97,5531,9 +bf16,8192,1,2560,1,1.5131,0.6191,2.44,5531,9 +f16,4096,12288,2560,12288,169.7946,44.4350,3.82,6137,7 +f16,4096,10240,2560,10240,147.1302,36.6967,4.01,6137,7 +f16,4096,6144,2560,6144,92.1636,23.4922,3.92,6137,7 +f16,4096,2560,6144,2560,97.8004,23.0363,4.25,6137,7 +f16,4096,2560,640,2560,13.9061,2.9316,4.74,6137,7 +f16,4096,640,2560,640,14.5406,2.2543,6.45,6137,7 +f16,4096,512,2560,512,13.3511,1.6140,8.27,6137,7 +bf16,4096,10240,2560,10240,153.4310,37.0421,4.14,5532,9 +bf16,4096,10240,320,10240,21.1589,9.1450,2.31,5532,9 +bf16,4096,320,10240,320,23.4575,4.9431,4.75,5532,9 +bf16,4096,2560,2560,2560,37.1116,9.1205,4.07,5532,9 +bf16,4096,512,2560,512,9.7326,1.5817,6.15,5532,9 +bf16,4096,128,2560,128,2.5324,0.5845,4.33,5532,9 +bf16,4096,48,2560,96,4.8128,0.3308,14.55,5532,9 +bf16,4096,4,10240,4,18.7145,1.0724,17.45,5529,9 +bf16,4096,1,2560,1,0.4450,0.2940,1.51,5531,9 +f16,2048,12288,2560,12288,82.5431,22.2695,3.71,6137,7 +f16,2048,10240,2560,10240,68.3010,19.7460,3.46,6137,7 +f16,2048,6144,2560,6144,40.8165,11.5715,3.53,6137,7 +f16,2048,2560,6144,2560,48.3422,10.4967,4.61,6137,7 +f16,2048,2560,640,2560,5.9756,1.0463,5.71,6137,7 +f16,2048,640,2560,640,10.7108,1.0926,9.80,6137,7 +f16,2048,512,2560,512,9.7222,0.8346,11.65,6137,7 +bf16,2048,10240,2560,10240,81.5673,19.6505,4.15,5532,9 +bf16,2048,10240,320,10240,14.3898,4.8025,3.00,5532,9 +bf16,2048,320,10240,320,16.2767,2.3612,6.89,5532,9 +bf16,2048,2560,2560,2560,19.4104,3.8451,5.05,5532,9 +bf16,2048,512,2560,512,4.1245,0.8258,4.99,5532,9 +bf16,2048,128,2560,128,1.0089,0.2817,3.58,5532,9 +bf16,2048,48,2560,96,1.9788,0.1633,12.12,5532,9 +bf16,2048,4,10240,4,13.6673,0.5865,23.30,5531,9 +bf16,2048,1,2560,1,0.2029,0.1502,1.35,5531,9 +f16,1024,12288,2560,12288,42.6525,11.6712,3.65,6137,7 +f16,1024,10240,2560,10240,32.8025,9.3415,3.51,6137,7 +f16,1024,6144,2560,6144,22.8920,5.3547,4.28,6137,7 +f16,1024,2560,6144,2560,24.7134,4.6159,5.35,6137,7 +f16,1024,2560,640,2560,2.9783,0.5994,4.97,6137,7 +f16,1024,640,2560,640,6.1688,0.6388,9.66,6137,7 +f16,1024,512,2560,512,4.4970,0.4833,9.30,6137,7 +bf16,1024,10240,2560,10240,36.5673,9.0905,4.02,5532,9 +bf16,1024,10240,320,10240,7.0192,2.4893,2.82,5532,9 +bf16,1024,320,10240,320,10.8369,1.2971,8.36,5532,9 +bf16,1024,2560,2560,2560,9.6968,2.0858,4.65,5532,9 +bf16,1024,512,2560,512,1.9058,0.4493,4.24,5532,9 +bf16,1024,128,2560,128,0.5103,0.1348,3.78,5532,9 +bf16,1024,48,2560,96,0.9148,0.1033,8.85,5531,9 +bf16,1024,4,10240,4,5.3652,0.3247,16.52,5529,9 +bf16,1024,1,2560,1,0.1859,0.0915,2.03,5530,9 +f16,512,12288,2560,12288,23.0393,4.8510,4.75,6137,7 +f16,512,10240,2560,10240,20.9931,4.0471,5.19,6137,7 +f16,512,6144,2560,6144,16.4222,2.3456,7.00,6137,7 +f16,512,2560,6144,2560,16.6570,2.2563,7.38,6137,7 +f16,512,2560,640,2560,1.1452,0.3358,3.41,6137,7 +f16,512,640,2560,640,2.7805,0.3833,7.25,6137,7 +f16,512,512,2560,512,2.3714,0.4154,5.71,6137,7 +bf16,512,10240,2560,10240,21.5507,4.0228,5.36,5532,9 +bf16,512,10240,320,10240,2.4796,0.8281,2.99,5532,9 +bf16,512,320,10240,320,7.0230,0.5453,12.88,5532,9 +bf16,512,2560,2560,2560,5.4400,1.0147,5.36,5532,9 +bf16,512,512,2560,512,1.0290,0.2863,3.59,5532,9 +bf16,512,128,2560,128,0.3998,0.0895,4.46,5531,9 +bf16,512,48,2560,96,0.4848,0.0623,7.78,5531,9 +bf16,512,4,10240,4,2.1638,0.1797,12.04,5529,9 +bf16,512,1,2560,1,0.1092,0.0493,2.22,5530,9 +f16,256,12288,2560,12288,16.0630,2.7367,5.87,6137,7 +f16,256,10240,2560,10240,15.1772,2.3952,6.34,6137,7 +f16,256,6144,2560,6144,11.4429,1.3735,8.33,6137,7 +f16,256,2560,6144,2560,12.2967,1.5591,7.89,6137,7 +f16,256,2560,640,2560,0.5889,0.2377,2.48,6136,7 +f16,256,640,2560,640,1.0700,0.2277,4.70,6137,7 +f16,256,512,2560,512,1.1540,0.2318,4.98,6137,7 +bf16,256,10240,2560,10240,15.0066,2.3144,6.48,5532,9 +bf16,256,10240,320,10240,1.1594,0.3223,3.60,5532,9 +bf16,256,320,10240,320,3.7195,0.3856,9.64,5532,9 +bf16,256,2560,2560,2560,3.5364,0.6533,5.41,5532,9 +bf16,256,512,2560,512,0.5690,0.1603,3.55,5532,9 +bf16,256,128,2560,128,0.2697,0.0586,4.60,5531,9 +bf16,256,48,2560,96,0.3158,0.0436,7.24,5530,9 +bf16,256,4,10240,4,1.1135,0.1344,8.28,5529,9 +bf16,256,1,2560,1,0.0581,0.0372,1.56,5529,9 +f16,128,12288,2560,12288,11.5691,1.8878,6.13,6137,7 +f16,128,10240,2560,10240,11.3427,1.6482,6.88,6137,7 +f16,128,6144,2560,6144,7.5798,1.0381,7.30,6137,7 +f16,128,2560,6144,2560,7.8253,1.0270,7.62,6136,7 +f16,128,2560,640,2560,0.4163,0.1356,3.07,6137,7 +f16,128,640,2560,640,0.5442,0.1987,2.74,6137,7 +f16,128,512,2560,512,0.6488,0.1887,3.44,6137,7 +bf16,128,10240,2560,10240,9.8758,1.4926,6.62,5532,9 +bf16,128,10240,320,10240,0.7429,0.3207,2.32,5532,9 +bf16,128,320,10240,320,1.4516,0.3780,3.84,5532,9 +bf16,128,2560,2560,2560,2.2319,0.5510,4.05,5532,9 +bf16,128,512,2560,512,0.4119,0.1255,3.28,5532,9 +bf16,128,128,2560,128,0.2702,0.0527,5.13,5530,9 +bf16,128,48,2560,96,0.2243,0.0408,5.51,5545,9 +bf16,128,4,10240,4,0.8669,0.1213,7.14,5529,9 +bf16,128,1,2560,1,0.0360,0.0344,1.05,5530,9 +f16,64,12288,2560,12288,11.8784,1.2125,9.80,6135,7 +f16,64,10240,2560,10240,10.8704,1.0699,10.16,6135,7 +f16,64,6144,2560,6144,7.5438,0.7642,9.87,6137,7 +f16,64,2560,6144,2560,7.5588,0.7730,9.78,6135,7 +f16,64,2560,640,2560,0.2777,0.1045,2.66,6137,7 +f16,64,640,2560,640,0.6969,0.1873,3.72,6136,7 +f16,64,512,2560,512,0.7157,0.1537,4.65,6136,7 +bf16,64,10240,2560,10240,10.9680,1.0273,10.68,5530,9 +bf16,64,10240,320,10240,0.3409,0.2038,1.67,5532,9 +bf16,64,320,10240,320,1.2132,0.2680,4.53,5530,9 +bf16,64,2560,2560,2560,2.3948,0.4248,5.64,5530,9 +bf16,64,512,2560,512,0.4768,0.1215,3.93,5530,9 +bf16,64,128,2560,128,0.2540,0.0539,4.71,5529,9 +bf16,64,48,2560,96,0.2186,0.0421,5.19,5533,9 +bf16,64,4,10240,4,0.7977,0.1389,5.74,5530,9 diff --git a/bench/results/2026-10-12-hc-persist-gfx1030/README.md b/bench/results/2026-10-12-hc-persist-gfx1030/README.md new file mode 100644 index 00000000..c12a4bc8 --- /dev/null +++ b/bench/results/2026-10-12-hc-persist-gfx1030/README.md @@ -0,0 +1,163 @@ +# STRATA_HC_PERSIST=1: the verifier's hyper-connection read as one persistent kernel (gfx1030) + +2x RX 6900 XT (gfx1030, 16 GB, PCIe 4.0 x8 each), Ryzen 5 5600X, 128 GB DDR4-3200, Ubuntu 26.04, kernel 7.0.0-38, +ROCm 10.0. Qwen3.8-Flash-Next IQ3_S (and Unsloth UD-Q4_K_XL), two-card layer split. + +## Result + +- The read itself: **1.35-2.10x faster** at 1-8 tokens on 40 WGPs (38.9 us against 55.1 us at 2 tokens). +- End to end, ms per verify window (`STRATA_DECODE_TIMING`, IQ3_S layer split, this branch, one binary with the + variable unset / set): **ten interleaved pairs on 0.1.43.1 with no other switch: -6.6 % at 4K and -4.4 % at 32K, + 10 of 10 pairs the same way**; with this machine's other gfx103x switches on, 6 rounds: -4.2 % / -2.8 %. Tokens + per window and prompt speed unchanged. +- Not bitwise (another summation order). Against a double-accumulation reference it is as close as the default read. +- Off by default; with the variable unset the engine's output is bitwise the same as without the change (checked below). + +## What the read does and why it was slow here + +Every layer the verifier reads the hyper-connection twice: RMS norm over 4 x 2560, a 320-row down projection (plus 4 +inject rows) and a 320 -> 10240 up projection. At 1-8 tokens this is three small launches with two global dependencies +between them; on gfx1030 the down kernel runs 41 blocks on 40 WGPs and the card idles between launches. + +The persistent kernel runs 80 blocks (two per WGP) and two grid barriers on an atomic counter: + +1. each block takes 128 columns of the 10240 (norm sum of squares + partial dots of the 324 down/inject rows), +2. barrier, each block reduces 4-5 of the 324 rows, +3. barrier, the up projection (a thread pair per row) and the same epilogue as `gr_up_kernel`. + +An ablation found only two parts that matter: the down projection split by columns over all 80 blocks, and one launch +instead of three. Prefetching the up weights (into registers, or touching them into L2 / Infinity Cache across the +barrier) and prefetching the epilogue inputs measured 0 and were removed - the 13 MB are read from VRAM once either way. + +| tokens | default read, us | persistent, us | | +|---|---|---|---| +| 1 | 51.6 | 38.1 | 1.35x | +| 2 | 55.1 | 38.9 | 1.41x | +| 3 | 60.0 | 40.5 | 1.48x | +| 4 | 63.9 | 43.6 | 1.46x | +| 5 | 67.6 | 43.1 | 1.57x | +| 6 | 71.5 | 46.1 | 1.55x | +| 7 | 96.4 | 46.3 | 2.08x | +| 8 | 104.4 | 49.7 | 2.10x | + +(`hc_persist_bench.cpp`, one card, a graph of 48 reads over 40 weight sets so the weights are cold, best of 3.) + +## Safety: what happens on a card it was not written for + +- `warpSize != 32` (wave64): off, the default read runs. +- Residency is decided by **running** every token count once at start-up with a 50 ms barrier timeout and comparing + the result with the default read; a timeout means "not resident" and that token count and larger ones keep the + default read. In a read the barrier gives up after 2 s (never seen in a working run). +- No occupancy API in front of the run: on 30 WGPs (HSA_CU_MASK) it promised more blocks than the card holds (a hang + before the timeout existed), and with the HIP 7.1 runtime (Ubuntu's `libamdhip64.so.7.1.52801`) it promised fewer + (1 per WGP on 40 WGPs), which turned the read off although it runs resident there. +- One line per card says what was decided: + +``` +strata hc: CUDA0: STRATA_HC_PERSIST=1: the verifier's hyper-connection read runs as one persistent kernel (80 blocks on +40 multiprocessors, up to 8 tokens; 0 token counts timed out in the check; checked against the default read, max +relative difference 1.8e-07) +``` + +Smaller cards, simulated on one 6900 XT with `HSA_CU_MASK` (`ROCR_VISIBLE_DEVICES=1`), both with ROCm 10.0 and with +the HIP 7.1 runtime (the same numbers within 0.2 us): + +| WGPs (CU mask) | like | tokens | persistent vs default | +|---|---|---|---| +| 40 | 6900 XT | 1-8 | 1.35-2.10x | +| 30 (`0:0-59`) | 6800 | 1-8 | 1.36-1.84x | +| 20 (`0:0-39`) | 6700 XT's CU count | 1-8 | 1.38-2.07x | +| 5 (`0:0-9`), 1 (`0:0-1`) | - | - | check timed out, default read, no hang | + +The mask keeps Navi 21's 256-bit bus and 128 MB Infinity Cache; a real 6700 XT / 6600 (narrower bus, smaller cache) +is not simulated by it. + +## End to end + +`strata-split.json`: `--layer-split`, IQ3_S, `--kv int8 --kv-resident 32768`, speculation 3 with min-p 0.7, +`--pipeline-windows 2`, `STRATA_SH_STREAM=1`, `STRATA_SPLIT_MTP_BATCH=1`. Main (a0116b27) with this change, one +binary, cold server per arm, the variable unset (default) and set alternating, 6 rounds, two 4K and two 32K requests +per arm (256 tokens out), ms per verify window from `STRATA_DECODE_TIMING`: + +| | default read | `STRATA_HC_PERSIST=1` | | rounds | +|---|---|---|---|---| +| 4K, ms per window | 25.81 | 24.73 | **-4.2 %** | -4.3 / -2.6 / -3.6 / -3.4 / -5.8 / -5.2 | +| 32K, ms per window | 24.40 | 23.72 | **-2.8 %** | -2.8 / -2.1 / -5.6 / -2.7 / -1.3 / -2.1 | +| tokens per window | 1.93 / 1.94 | 1.92 / 1.94 | | | +| prompt, tok/s (4K / 32K) | 848 / 1,636 | 850 / 1,632 | | | + +Run-to-run noise in ms per window is about +-3 % per round here, which is why the rounds alternate. An earlier version +of the kernel (the up weights prefetched into registers, since removed) measured -2.8 % / -2.0 % against the default read (two builds, 6 rounds) on +Unsloth UD-Q4_K_XL (`STRATA_MMQ_KQUANTS=ON`, 0.1.42); this version was not re-measured on it. + +### Ten interleaved pairs, no other switch + +0.1.43.1 (`a0116b27`) with this change, one binary, the engine's defaults (no environment variable at all) plus +`STRATA_DECODE_TIMING=1`, the variable unset / set. IQ3_S layer split, `--spec 3 --spec-min-p 0.7 +--pipeline-windows 2`, no vision. Ten pairs of cold servers, the order inside a pair alternating (off-on, on-off, +...), one 4K and one 32K request per server, 256 tokens out. Each server's log carries the `STRATA_HC_PERSIST=1` +line on both cards when set and not when unset (checked per arm). + +| ms per verify window | unset (median) | set (median) | per-pair median | pairs faster | the ten pairs | +|---|---|---|---|---|---| +| 4K | 27.08 | 25.26 | **-6.6 %** | **10 / 10** | -3.5 -8.5 -6.1 -7.1 -1.3 -8.0 -5.7 -4.2 -8.2 -10.3 | +| 32K | 26.37 | 25.15 | **-4.4 %** | **10 / 10** | -6.2 -5.8 -1.9 -2.9 -4.7 -2.1 -5.3 -9.2 -3.4 -4.1 | + +Without the other switches the default read is a larger share of the window, so the gain is larger than in the +6-round table above. + +## Quality + +`STRATA_LOGPOS` over three chats (9.4K, 34.7K, 105.8K tokens; ~500 scored positions each, top-256), pipeline windows +off, on **this PR's code on main (a0116b27)**. Only the 106K chat is reproducible run to run on this machine (the +first two differ in all positions between two runs of the same binary), so it is the one compared. +`STRATA_HC_PERSIST=3` is a reference that accumulates the same kernel in double. + +| 106K chat, against the double reference | KL mean | argmax same | +|---|---|---| +| default read | 0.0136 | 95.0 % | +| `STRATA_HC_PERSIST=1` | 0.0131 | 96.3 % | + +On 0.1.42 the same comparison gave 0.047 (default) and 0.038 (the earlier version of the kernel). + +Default path unchanged: main (a0116b27) built without and with this change, the same options, the variable unset: +the 106K chat's 481 scored positions are bitwise identical. With the variable unset `fused_gr_persist_init` and +`fused_gr_read_persist` return in their first line. + +0 stalls in every engine run with it (more than 30); three Strata slots on this machine use it daily since 2026-10-12. + +## Tried and dropped + +- Cooperative launch (`hipLaunchCooperativeKernel` + `grid.sync`): works and can be captured in a graph, but each + launch costs ~12 us more than a plain one here - more than the whole gain. +- `__builtin_amdgcn_global_load_lds` to stage the up weights: slower (4x the instructions, dword only on gfx1030), and + AMD clang 23 (ROCm 10.0) folds a constant address offset into the instruction offset, which the hardware also adds + to the LDS destination - the data lands shifted unless the pointer is laundered through an empty `asm`. +- Non-temporal loads for the weights: no effect. +- `STRATA_GR_V3=1` as a comparison: on gfx1030 it needs the two-half split, which fails its check (#375), so it falls + back to the default read. + +## Not tested + +- Any other card for real: RDNA 2 Navi 22/23 (6700 XT, 6600), RDNA 3 (7900), RDNA 4 (9070), NVIDIA. The kernel is + inside `#if defined(__HIPCC__)`; CUDA and SYCL get two empty stubs (`fused_gr_persist_init` does nothing, + `fused_gr_read_persist` returns false). CUDA and SYCL were not built here (no toolkit on this machine). +- Windows HIP. +- The drafter's reads (they run on their own stream and keep the default kernels) and the prompt path. + +## Help wanted + +On any RDNA card, with `STRATA_HC_PERSIST=1` in the engine's environment: + +1. the `strata hc:` line from the engine log (does it run, up to how many tokens, any timeouts?), and +2. two runs of the same prompt with `STRATA_DECODE_TIMING=1`, with and without the variable (ms per window). + +To time the read alone (from the repository root, after a HIP build in `build/`): + +``` +hipcc -O3 --offload-arch= -I include -c bench/results/2026-10-12-hc-persist-gfx1030/hc_persist_bench.cpp -o hcpb.o +hipcc --offload-arch= hcpb.o build/libstrata_kernels.a build/libstrata_core.a -lrocblas -o hc_persist_bench +STRATA_HC_PERSIST=1 ./hc_persist_bench +``` + +Developed with an AI coding assistant; every number above was measured on 2x RX 6900 XT (gfx1030, PCIe 4.0 x8 each) / Ryzen 5 5600X, ROCm 10.0. diff --git a/bench/results/2026-10-12-hc-persist-gfx1030/hc_persist_bench.cpp b/bench/results/2026-10-12-hc-persist-gfx1030/hc_persist_bench.cpp new file mode 100644 index 00000000..e7b20f8f --- /dev/null +++ b/bench/results/2026-10-12-hc-persist-gfx1030/hc_persist_bench.cpp @@ -0,0 +1,73 @@ +// The engine's STRATA_HC_PERSIST read (public API) against the default read, per token count: the largest relative +// difference from the default read, and the time per read in a graph of 48 cold reads. Run with STRATA_HC_PERSIST=1 +#include +#include "strata/kernels/fused_gr.hpp" +#include +#include +#include +#include +#include +#include +namespace K = strata::kernels; +#define CK(x) do { hipError_t e_ = (x); if (e_ != hipSuccess) { std::fprintf(stderr, "%s:%d %s\n", __FILE__, __LINE__, hipGetErrorString(e_)); std::exit(1); } } while (0) +constexpr int N = 2560, HC = 4, D = N * HC, LR = 320, TM = 8; +static uint16_t bf16(float x) { uint32_t u; std::memcpy(&u, &x, 4); return (uint16_t) ((u + 0x7fff + ((u >> 16) & 1)) >> 16); } +int main(int argc, char** argv) { + setvbuf(stdout, nullptr, _IONBF, 0); + const int W = argc > 1 ? std::atoi(argv[1]) : 40; + K::fused_gr_check(); + K::fused_gr_persist_init(); + std::mt19937 rng(5); std::normal_distribution nd(0.f, 1.f); + std::vector R((size_t) TM * D), bo((size_t) TM * N), inj((size_t) TM * HC), wn(D); + for (auto& x : R) x = nd(rng); for (auto& x : bo) x = 0.5f * nd(rng); for (auto& x : inj) x = nd(rng); for (auto& x : wn) x = 1.f + 0.3f * nd(rng); + const size_t WD = (size_t) LR * D, WU = WD, WI = (size_t) HC * D; + uint16_t *dwd, *dwu, *dwi; CK(hipMalloc(&dwd, WD * 2 * W)); CK(hipMalloc(&dwu, WU * 2 * W)); CK(hipMalloc(&dwi, WI * 2 * W)); + { std::vector b(WD); for (int s = 0; s < W; ++s) { + for (auto& x : b) x = bf16(0.02f * nd(rng)); CK(hipMemcpy(dwd + WD * s, b.data(), WD * 2, hipMemcpyHostToDevice)); + for (auto& x : b) x = bf16(0.05f * nd(rng)); CK(hipMemcpy(dwu + WU * s, b.data(), WU * 2, hipMemcpyHostToDevice)); + for (size_t i = 0; i < WI; ++i) b[i] = bf16(0.02f * nd(rng)); CK(hipMemcpy(dwi + WI * s, b.data(), WI * 2, hipMemcpyHostToDevice)); } } + float *dR, *dbo, *dinj, *dwn, *dxn, *dlo, *drs, *dio, *dmix; + CK(hipMalloc(&dR, R.size() * 4)); CK(hipMalloc(&dbo, bo.size() * 4)); CK(hipMalloc(&dinj, inj.size() * 4)); CK(hipMalloc(&dwn, D * 4)); + CK(hipMalloc(&dxn, (size_t) TM * D * 4)); CK(hipMalloc(&dlo, (size_t) TM * LR * 4)); CK(hipMalloc(&drs, TM * HC * 4)); + CK(hipMalloc(&dio, TM * HC * 4)); CK(hipMalloc(&dmix, (size_t) TM * N * 4)); + CK(hipMemcpy(dbo, bo.data(), bo.size() * 4, hipMemcpyHostToDevice)); CK(hipMemcpy(dinj, inj.data(), inj.size() * 4, hipMemcpyHostToDevice)); + CK(hipMemcpy(dwn, wn.data(), D * 4, hipMemcpyHostToDevice)); + hipStream_t st; CK(hipStreamCreateWithFlags(&st, hipStreamNonBlocking)); + hipEvent_t e0, e1; hipEventCreate(&e0); hipEventCreate(&e1); + auto args = [&](K::FusedGrArgs* a, int T, int set) { + for (int t = 0; t < T; ++t) { a[t] = K::FusedGrArgs{}; a[t].R = dR + (size_t) t * D; a[t].R_out = dR + (size_t) t * D; a[t].apply = true; + a[t].bo_prev = dbo + (size_t) t * N; a[t].inj_prev = dinj + t * HC; a[t].w_norm = dwn; a[t].w_down = dwd + WD * set; + a[t].w_up = dwu + WU * set; a[t].w_inject = dwi + WI * set; a[t].eps = 1e-6f; a[t].lo = dlo + t * LR; a[t].rs = drs + t * HC; + a[t].inject_out = dio + t * HC; a[t].mixed = dmix + (size_t) t * N; } }; + for (int T = 1; T <= TM; ++T) { + K::FusedGrArgs a[TM]; args(a, T, 0); + std::vector out[2]; + bool ran = true; + for (int w = 0; w < 2; ++w) { + CK(hipMemcpy(dR, R.data(), R.size() * 4, hipMemcpyHostToDevice)); CK(hipMemset(dmix, 0xff, (size_t) TM * N * 4)); CK(hipDeviceSynchronize()); + if (w == 0) K::fused_gr_read_multi(a, T, dxn, st); else ran = K::fused_gr_read_persist(a, T, st); + CK(hipStreamSynchronize(st)); + out[w].resize((size_t) T * N); CK(hipMemcpy(out[w].data(), dmix, out[w].size() * 4, hipMemcpyDeviceToHost)); + } + if (!ran) { std::printf("T %d: persistent read not used here (falls back)\n", T); continue; } + double mr = 0, md = 0; bool fin = true; + for (size_t i = 0; i < out[0].size(); ++i) { fin = fin && std::isfinite(out[1][i]); mr = std::fmax(mr, std::fabs(out[0][i])); md = std::fmax(md, std::fabs(out[1][i] - out[0][i])); } + double us[2]; + for (int w = 0; w < 2; ++w) { + double best = 1e30; + for (int r = 0; r < 3; ++r) { + hipGraph_t g; hipGraphExec_t ge; + CK(hipStreamBeginCapture(st, hipStreamCaptureModeGlobal)); + for (int i = 0; i < 48; ++i) { args(a, T, (i * 7) % W); if (w == 0) K::fused_gr_read_multi(a, T, dxn, st); else K::fused_gr_read_persist(a, T, st); } + CK(hipStreamEndCapture(st, &g)); CK(hipGraphInstantiate(&ge, g, nullptr, nullptr, 0)); + for (int i = 0; i < 2; ++i) CK(hipGraphLaunch(ge, st)); + CK(hipEventRecord(e0, st)); for (int i = 0; i < 10; ++i) CK(hipGraphLaunch(ge, st)); CK(hipEventRecord(e1, st)); CK(hipEventSynchronize(e1)); + float ms; hipEventElapsedTime(&ms, e0, e1); best = std::fmin(best, 1e3 * ms / 480); + hipGraphExecDestroy(ge); hipGraphDestroy(g); + } + us[w] = best; + } + std::printf("T %d: default %6.1f us persistent %6.1f us (%.2fx) max rel diff %.2e%s\n", T, us[0], us[1], us[0] / us[1], md / mr, fin ? "" : " NON-FINITE"); + } + return 0; +} diff --git a/bench/results/COMMUNITY.md b/bench/results/COMMUNITY.md index 63092c48..2ef57bf9 100644 --- a/bench/results/COMMUNITY.md +++ b/bench/results/COMMUNITY.md @@ -101,6 +101,7 @@ Notes: | [2026-10-08-community-rtx4090-iq3xxs-200k-ru](2026-10-08-community-rtx4090-iq3xxs-200k-ru/) | RTX 4090, Ryzen 9 7950X (same PC) | Flash-Next IQ3_XXS, 204,800, Russian prompts | see the README | see the README | 0.1.40.3 | #1467 | | [2026-10-08-community-2x-titan-rtx-0.1.40.3](2026-10-08-community-2x-titan-rtx-0.1.40.3/) | 2x TITAN RTX 24 GB (NVLink, unused), Xeon E5-2696 v4, source build | Flash-Next IQ3_S, 262K | 869 / 1,549 / 1,627 (4K / 32K / 128K) | 70.9 / 77.3 / 71.1 | 0.1.40.3 | #1429 | | [2026-10-07-community-gfx1150](2026-10-07-community-gfx1150/) | Radeon 890M (gfx1150), Ryzen AI 9 HX PRO 370, 96 GB unified memory | IQ3_XXS | 153 / 216 / 226 (1K / 3.6K / 7K) with the gfx1150 hipBLASLt table, 99 / 124 / 130 without | 15.2-17.6 | 0.1.40.2 | - | +| [2026-10-12-community-gfx1103](2026-10-12-community-gfx1103/) | Radeon 780M (gfx1103), Ryzen 7 8745HS, 60 GB, GTT 50 GiB, hand build on ROCm 10.1 | Flash-Next Q2_0 + MTP, 32K | 90 plain / 186 with the gfx1103 hipBLASLt table / 211 with the exact switches / 277 with the WMMA opt-ins (4K); 272 at 32K (WMMA arm) | 13.1 plain, 13.9-14.3 tuned | 0.1.43 + the gfx1103 port (branch) | - | | [2026-10-09-community-2x-rx-6900xt-0.1.41](2026-10-09-community-2x-rx-6900xt-0.1.41/) | 2x RX 6900 XT 16 GB (PCIe 4.0 x8 each), Ryzen 5 5600X, 128 GB | IQ3_S, 131K | one card stock 473 / 502 / 486, with the two gfx103x switches 850 / 1,102 / 1,027, with the PRs 976 / 1,174 / 1,147; layer split stock 464 / 767 / 869, switches 832 / 1,619 / 1,823, PRs 968 / 1,714 / 2,029; helper with the PRs 986 / 1,173 / 1,147 | one card 46-52; layer split stock 62.6 / 65.0 / 60.8, PRs 64.7 / 68.8 / 68.3, PRs + `--spec 3 --spec-min-p 0.7 --pipeline-windows 2` 77.2 / 82.3 / 75.7; helper PRs 72.5 / 75.2 / 75.1 | 0.1.41 (fb58e0db) | this PR; notes: [Vop3p/dual-6900xt-flash-next-tuning](https://github.com/Vop3p/dual-6900xt-flash-next-tuning) | | [2026-10-09-community-gfx1151-ud-iq4xs-0.1.41](2026-10-09-community-gfx1151-ud-iq4xs-0.1.41/) | EVO-X2, Radeon 8060S (gfx1151), Ryzen AI Max+ 395, 128 GB UMA | Unsloth UD-IQ4_XS | 627 / 687 / 617 default; 808 / 1,165 / 1,109 fast | 42.8 / 44.4 / 42.1 default; 40.1 / 49.6 / 47.5 fast | 0.1.41 (fb58e0d) | - | | [2026-10-08-community-2x-rtx3080-20gb-ud-q4-k-xl-512k-pool](2026-10-08-community-2x-rtx3080-20gb-ud-q4-k-xl-512k-pool/) | 2x RTX 3080 20 GB (220 W cap each, PCIe Gen3 x16), Xeon E5-2696 v4 (AVX2), 90 GiB RAM, Proxmox LXC | Unsloth UD-Q4_K_XL, two 262,144-token lanes in a 524,288-token shared KV pool, layer split, batch MTP | 718 / 2,219 / 2,585 / 2,996 / 3,080 (4K / 25K / 51K / 104K / 127K) | 81.2 / 84.0 / 90.6 / 86.3 / 80.7 (same lengths, one stream); 89.5 for two streams (my script) | fork build of 0.1.40.3, source branch `repro/w7` on noon-at-cgn/Strata (not upstream `main` plus the open PRs: it contains the code of my open PRs #1598, #1599, #1601, #1614 (shared KV pool), #1636 (batch MTP on a split), #1637 (`--adapt-async` beside slots), and of #1190, an open PR by another contributor that keeps the RAM copy of the split lend regions) | - | diff --git a/docs/AMD_HIP.md b/docs/AMD_HIP.md index a8fe8834..ce702054 100644 --- a/docs/AMD_HIP.md +++ b/docs/AMD_HIP.md @@ -66,7 +66,7 @@ On a PC with no NVIDIA card Strata can use, the AMD card is chosen by itself; wi Adrenalin Edition](https://www.amd.com/en/support/download/drivers.html)). Nothing else: no ROCm or HIP SDK install, no compiler, no admin rights. - **Detection:** setup reads the display adapters Windows lists (their PCI ids; the VRAM size from the display - driver's registry entry). An integrated Radeon is listed as not supported, except the Ryzen AI Max "Strix Halo" (Radeon 8060S / 8050S / 8040S, gfx1151: [STRIX_HALO.md](STRIX_HALO.md)); a Strix Point (890M / 880M, gfx1150), Krackan (860M / 840M, gfx1152) or Phoenix / Hawk Point (780M / 760M, gfx1103) Radeon is named as what it is and not supported. + driver's registry entry). An integrated Radeon is listed as not supported, except the Ryzen AI Max "Strix Halo" (Radeon 8060S / 8050S / 8040S, gfx1151: [STRIX_HALO.md](STRIX_HALO.md)); a Strix Point (890M / 880M, gfx1150), Krackan (860M / 840M, gfx1152) or Phoenix / Hawk Point (780M / 760M, gfx1103) Radeon is named as what it is and not supported (on Linux the 780M / 760M has an opt-in build: [RADEON_780M.md](RADEON_780M.md)). - **Engine:** the ready-made `strata-windows-x64-hip.zip` from the release (built by `tools\hip\build_windows.bat` for gfx1100, gfx1101, gfx1102, gfx1200, gfx1201, gfx1030 and, from 0.1.40, gfx1151 (Strix Halo, unvalidated on Windows)) goes into `engine\`. It carries the ROCm libraries the engine loads (`engine\rocm\bin`: the HIP runtime, hipBLAS / rocBLAS / hipBLASLt with their kernels for these cards, @@ -153,6 +153,64 @@ pinned by this repository. For an offline build, point `STRATA_GGML_DIR` at a checkout of that exact revision; using an arbitrary newer checkout changes the dependency being tested. +## Opt-in chunked prompt GDN on gfx11 + +`STRATA_GDN_CHUNKED=1` runs the prompt's gated DeltaNet recurrence in 16-token chunks on the gfx11 matrix cores, +with FP16 operands and FP32 accumulation, and fuses the output norm. It is off by default: rounding differs from +the token-by-token FP32 recurrence. The CUDA switch of the same name uses a separate FP32 implementation. + +The HIP path accepts gfx1100, gfx1101, gfx1102, gfx1150 and gfx1151, and prompt chunks of at least 64 tokens. +Other cards, shorter chunks, an output row stride not divisible by eight, and `STRATA_GDN_REC_HEADS` use the +existing recurrence. Runtime measurements and numerical checks were run on gfx1151 only; building for another +target does not validate its speed or answers. The synthetic test compares the FP16 output and carried FP32 state +against the existing recurrence, and short cases against a double-precision CPU calculation. It covers partial +chunks, padded rows, weak decay and a split request; the off/default tests require identical output and state bits. +It does not establish model answer equivalence. + +`STRATA_GDN_CHUNKED=2`, which on CUDA skips the SM-count test, is the same as 1 here. + +Measured on a Ryzen AI Max+ 395 (gfx1151, ROCm 7.14.1), UD-IQ4_XS. One layer's recurrence and norm take 1.60x less time than +gfx1151's default kernels at 16K and 32K tokens (`hip_gdn_chunked --bench` against `--bench-default`, three runs each: 20.92 -> +13.11 ms at 16K, 42.14 -> 26.30 ms at 32K). A whole prompt: the same binary with only this switch changed, a fresh engine per +side, 11 pairs in alternating order after a discarded one, the engine's `prompt_ms`, every prompt read in full (no reused +tokens). Each engine reads a discarded 4K prompt first, because the first prompt after a start varies more (on those first +prompts the same pairs gave 95% intervals of [1.004, 1.032] and [0.981, 1.015]); the prompts follow each other once +`/proc/vmstat`'s page-migration and direct-reclaim counters have stood still for 3 s, and a pair in which either prompt still +met page migration or direct reclaim was dropped and measured again (3 of the 69 pairs, all 32K with the switch on; kept in, 32K +gives 1.020 and 1.015). "Section 5" is the nine variables of `STRIX_HALO.md` section 5 (with `STRATA_PF_SWITCH_MIN_T=2048`); +"defaults" is the engine without them (section 4's gfx1151 defaults stay). Times are medians; the ratio is the geometric mean of +the 11 off / on ratios with a 95% bootstrap interval; "faster" counts the pairs in which the switch was faster: + +| tokens | arm | off -> on | off / on | faster | +|---:|---|---:|---:|---:| +| 4,096 | section 5 | 3.703 -> 3.641 s | 1.018 [1.016, 1.020] | 11 of 11 | +| 4,096 | defaults | 5.914 -> 5.829 s | 1.014 [1.010, 1.017] | 10 of 11 | +| 32,768 | section 5 | 26.157 -> 25.589 s | 1.021 [1.020, 1.023] | 11 of 11 | +| 32,768 | defaults | 44.082 -> 43.479 s | 1.015 [1.012, 1.017] | 11 of 11 | +| 128,000 | section 5 | 107.149 -> 104.866 s | 1.021 [1.020, 1.023] | 11 of 11 | +| 128,000 | defaults | 193.439 -> 191.055 s | 1.014 [1.012, 1.016] | 11 of 11 | + +So about 2% on top of section 5 and about 1.5% on the defaults. At 36 gated-DeltaNet layers the layer figures predict about +0.56 s for a 32K prompt; 0.57 s (section 5) and 0.60 s (defaults) were measured. + +First-token KL against the same run without the switch, 12 prompts of 1.5K-24K tokens: UD-IQ4_XS 0.0067 mean (0.044 max) on the +defaults and 0.0039 (0.027) on top of section 5; UD-Q4_K_XL 0.0063 (0.043) and 0.0040 (0.014); the same top token in all of +them (across the 12 prompts the first token takes only two distinct values). Section 5's switches alone are 0.0068 (IQ4_XS) and +0.0031 (Q4_K_XL) against the defaults, a different change that is listed for scale and not as a limit for this one. Only the +first generated token was compared: a long generation and perplexity were not measured. + +Build and run these checks in the HIP build directory: + +```sh +cmake --build build-hip --target hip_gdn_chunked hip_gdn_rec_head +ctest --test-dir build-hip -R 'hip_gdn_(chunked|rec_head)' --output-on-failure +for i in 1 2 3; do ./build-hip/hip_gdn_chunked --bench-default; ./build-hip/hip_gdn_chunked --bench; done +``` + +Each benchmark run reports the GPU-event median of seven runs after two warmups, the same nonzero initial state every run: +`--bench` this path, `--bench-default` gfx1151's default kernels (`STRATA_GDN_PP=2`, `STRATA_GDN_NOY=1`). The switch is read +once per process, so the two are separate runs. It times one layer's recurrence and norm, not a whole prompt. + ## Model and serving configuration Prepare a supported model pack and its MTP runtime using the existing tools. @@ -241,6 +299,28 @@ only when its version matches the installed library; otherwise it prefills on pl prompt), so keep the table and the library paired. Not worth trying (measured flat): `--kv-resident` changes, a prefill chunk above 32768, `--spec` above 4. +## Exact long-prompt QSA scorer (gfx1100 opt-in, gfx12 default) + +`STRATA_SCORES_THREAD=1` at engine startup enables a HIP port of #1825's score kernel on gfx1100, for batches of +at least 64 queries with at least 16,385 live index blocks. On gfx12 (RDNA4) it is on by default for those batches and +`STRATA_SCORES_THREAD=0` turns it off (0.1.45): on an R9700 `qsa_scores_gfx1100_parity --full` compares 223,664,777 scores and +11,895,800 ids bitwise equal to the warp scorer, the scorer stage with 256 queries is 3.6x faster at 131K and 4.0x at 240K, and a +fresh prompt of 131K tokens reads 8.7% faster (4 of 4 pairs) and one of 230K tokens 16.4% faster (3 of 3), with the same answer tokens and byte-identical `exact_pp` residual dumps at 70K and 131K tokens (prompts under 65K cells never reach the bound). The default, short-prompt and decode paths keep the +existing scorer. On one RX 7900 XTX / 7950X3D / ROCm 10.0.0, three paired runs of a tuned 0.1.40.3 engine reduced +fresh one-token request time by 10.45% at 130,978 prompt tokens and 22.64% at 239,906; one same-binary current-main +pair measured 12.85% and 21.71%. Cached follow-ups did not show a repeatable large gain, and a two-task coding pilot +was 3.27% slower overall. This is opt-in, not a general coding-speed recommendation. The +[report, per-run data and standalone score/ID check](../bench/results/2026-10-11-gfx1100-qsa-scores/README.md) +give the settings, exact-parity checks and limits. `STRATA_SCORES_THREAD_TRACE=1` prints an engagement line. + +## Deep contexts: the prompt's top-k selection (0.1.45, #1749) + +Past ~135K cells (and from ~90K cells on a prompt read) the prompt's top-k selection runs the wide kernel, as on CUDA, instead of the four-pass +reference radix that every deep context on HIP paid; the same ids (`qsa_select_bench` compares them with the reference). On an R9700 the +selection of a 256-query batch is 0.29 -> 0.21 ms at 98K, 1.16 -> 0.49 ms at 262K and 22.0 -> 0.93 ms at 524K; a fresh prompt reads 1.3% faster at +230K tokens and 34% faster at 500K (716 -> 962 tok/s; 1,284 tok/s with the exact scorer above, 79% in all), with the same answer tokens. +`STRATA_TOPK_OLD=1` runs the original kernel, `STRATA_TOPK_STREAM=0` the register kernel in the 90K-135K band. + ## Linux: verify timeouts while the kernel reclaims host memory (experimental workarounds) A `verify: timed out at layer N` or "no progress for 60 s" message does not by itself mean a kernel or handshake bug. Two @@ -448,6 +528,17 @@ run it; the report below is from a community machine: an RX 6900 XT 16 GB (gfx10 matrix cores; `hip_prefill_hipblaslt_gemm`, no hipBLASLt table) and 3 that fail for reasons outside the engine (`ple_parity` needs a Q2_0 PLE file that is not on that machine, `expert_multi_test` refuses the CPU without AVX-512, `platform_memory_test` cannot `mlock` at the shell's default `ulimit -l`). +- **The verifier's hyper-connection read as one persistent kernel:** `STRATA_HC_PERSIST=1` (opt-in, HIP, 32-lane + waves) runs the read of 1-8 tokens as one kernel of 80 blocks with two grid barriers instead of three launches; a + start-up run per token count with a barrier timeout decides where it is resident, and one `strata hc:` line per card + says so. On 2x RX 6900 XT (ROCm 10.0, layer split): the read 1.35-2.10x, ms per verify window -4.2 % / -2.8 % at + 4K / 32K (6 rounds), not bit-identical (as close to a double-accumulation reference as the default read): + [bench/results/2026-10-12-hc-persist-gfx1030](../bench/results/2026-10-12-hc-persist-gfx1030/README.md). Other + RDNA cards are untested; the `strata hc:` line and a `STRATA_DECODE_TIMING` run from one are welcome. Not offered on gfx11 and + gfx12 (RDNA3, RDNA4): the barrier timeout needs `s_memrealtime`, which gfx1100 and gfx1200 / gfx1201 do not have, and an R9700 (#2226 thread) measured the + read +0.7 % / +1.0 % per window slower than the default one; the start-up line says so. A barrier that times out at run time + (never seen in a working run) leaves the partial outputs of that read in place and every later persistent read of the + process aborts at once, without a log line; the opt-in is for measurement on gfx103x until that is closed. - **gfx1031** (RX 6700 XT, #524): setup knows it (the `gfx103X-all` wheels, unvalidated); its reporter runs it daily on one card. More reports: an RX 6700 XT 12 GB run as gfx1030 on ROCm 7.2.4 (#1027: IQ2_XS, decode 30-32 tok/s, prompt about 300 tok/s, 6 of 6 needles), and an RX 6800M 12 GB on Windows with a self-built engine (#915, #1078: Q2_0, decode 9-27 tok/s, prompt 50-114 tok/s; the @@ -603,6 +694,20 @@ Shipped tables: no fallbacks over prompts of 28-7,880 tokens. Setup does not use it (it does not install for gfx1150): point `STRATA_HIPBLASLT_TUNING` at it. Measurements and the per-row timings: [bench/results/2026-10-07-community-gfx1150](../bench/results/2026-10-07-community-gfx1150/README.md). +- `gfx1103-hipblaslt-100401.txt`: Radeon 780M (gfx1103, RDNA3, 12 CUs, unified memory), calibrated with ROCm 10.1 + (`rocm/dev-ubuntu-24.04:10.1.0-full`, hipBLASLt 1.4.1, version number 100401) and the engine's 32 MiB workspace. The + 16 dense GEMM geometries a Qwen3.8-Flash-Next prompt logs on the card at T = 64, 128, ..., 16384: 144 cases, two + `tune_hipblaslt` passes back to back, each row the solution with the lowest median of all six repetitions. One row + is left out (`bf16 N=1 K=2560 T=64`: no candidate beat plain hipBLAS at 0.04 ms), so the table has **143 rows**, + 1.05-23.30x per GEMM, geometric mean 4.95x. Without it the engine prefills on plain hipBLAS: a 4K prompt on Q2_0 + read 90 tok/s, 187 with the table and 277 with the WMMA opt-ins (one 780M; 32K context, MTP). The merged table + prefilled the 4K prompt at 187.2 tok/s. A context ladder to 131K (shipping configuration, fresh prompts) puts the + full 128K read at 198-221 tok/s, its last ~14K at ~206, and decode at ~10 tok/s at that depth; the numbers are in + the report folder. `hip_prefill_hipblaslt_gemm` reports `fallbacks=0`; + `hip_prefill_hcd_exact_parity` skips, because the table picks no 1176 / 1177 for the HC down GEMM (the skip the + gfx1150 table gets too). Setup installs for gfx1103 only with `STRATA_EXPERIMENTAL_GFX1103=1` and then uses the + table when the installed hipBLASLt reports 1.4.1. Measurements: + [bench/results/2026-10-12-community-gfx1103](../bench/results/2026-10-12-community-gfx1103/README.md). Calibrated on my PC and kept in this checkout, not shipped: `gfx1201-hipblaslt-100401.txt`, a Radeon AI PRO R9700 (gfx1201, 32 GB, 1002:7551) on a Ryzen 9 9950X3D with 62 GiB RAM, CachyOS (kernel 7.3.0-rc6-1-cachyos-rc, diff --git a/docs/COMMUNITY_BENCHMARKS.md b/docs/COMMUNITY_BENCHMARKS.md index 13d016c9..4c88ca28 100644 --- a/docs/COMMUNITY_BENCHMARKS.md +++ b/docs/COMMUNITY_BENCHMARKS.md @@ -64,6 +64,8 @@ and their limits. Report what you actually measured and label estimates separate Source builds of 0.1.40.4 and 0.1.41 on the distribution's ROCm 6.2 (host patches in BUILD.json), IQ2_XS at 131K with KV streaming; decode 24.2/24.0/23.7 tok/s, prompt 350/339/284 tok/s at 4K/32K/128K, two sweeps with telemetry. Build logs trimmed (TRIMMED.md). - [2026-10-08: RTX 4070 12 GB, Core i5-12600KF, 32 GB DDR4](../bench/results/2026-10-08-community-rtx4070-iq2-xs/README.md): IQ2_XS with adaptive cache E4/S24: 48.23 accepted-decode tok/s (median of 5) on a modified, locally built engine (not an official release; source commit and hashes in provenance.json, steps in REPRODUCE.md). +- [2026-10-12: Radeon 780M (gfx1103), Ryzen 7 8745HS, 60 GB RAM, GTT 50 GiB](../bench/results/2026-10-12-community-gfx1103/README.md): + the gfx1103 port (native dot4, the gfx11 WMMA kernels, the exact speed switches and a calibrated hipBLASLt table), hand-built on ROCm 10.1, Q2_0 + MTP at 32K: prompts 90 tok/s plain, 186 with the table, 277 with the WMMA opt-ins (4K), decode 13.1 -> 14.3 tok/s; zero GPU resets. ## Run the benchmark diff --git a/docs/DETAILS.md b/docs/DETAILS.md index 7fb8aa0e..83c956e1 100644 --- a/docs/DETAILS.md +++ b/docs/DETAILS.md @@ -1828,7 +1828,7 @@ already times: the wall time of the CPU pool per missed expert. With `R` = exper `L / (L + 1.85 R)`, rounded to 0.05 and kept between 0.10 and 0.60; it is changed at most three times (after 48, 96 and 96 more windows, about 10 s of decoding), and only by a full step. Each change prints one `PCIe share:` line. A request that sets its own `pcie_frac` is left alone. **`--pcie-frac N` always wins; `STRATA_PCIE_FRAC_DEFAULT=old` keeps the 0.1.41 rule.** Not used with a layer split, `--batch`, a peer GPU, when every -expert is in VRAM, or on SYCL or on HIP other than gfx1200 / gfx1201 (RDNA4, where the measured share is the default since 0.1.43; `STRATA_PCIE_FRAC_DEFAULT=old` opts out). The canonical Q2_0 pack uses it on CUDA since 0.1.43, on Linux by default and on Windows with `STRATA_PCIE_AUTO_CANON=1` (an RTX 5070 there: code +2.5%, a short answer -3.3%). The constant 1.85 is a fit to three machines, so it lands within a step of each machine's best, not on it. On HIP, `STRATA_PCIE_AUTO_SPLIT=1` (opt-in, 0.1.43) also refines a two-stage layer split: the pool speed is read once and each stage takes the share its own probed link gives (2x R9700 at 16 GB-eq, tail skip on: Q2_0 story +4.5%, code +9.9%, 4K +8.8%; IQ3_S story -2.1%, code +8.0%, 4K +23.3%; with three or more stages the pipelined loop does not run it). +expert is in VRAM, or on SYCL or on HIP other than gfx1200 / gfx1201 (RDNA4, where the measured share is the default since 0.1.43; `STRATA_PCIE_FRAC_DEFAULT=old` opts out; on the other HIP parts `STRATA_PCIE_FRAC_DEFAULT=auto` turns it on: an RX 7900 XTX showed no regression, no gain was claimed, #2224). The canonical Q2_0 pack uses it on CUDA since 0.1.43, on Linux by default and on Windows with `STRATA_PCIE_AUTO_CANON=1` (an RTX 5070 there: code +2.5%, a short answer -3.3%). The constant 1.85 is a fit to three machines, so it lands within a step of each machine's best, not on it. On HIP, `STRATA_PCIE_AUTO_SPLIT=1` (opt-in, 0.1.43) also refines a two-stage layer split: the pool speed is read once and each stage takes the share its own probed link gives (2x R9700 at 16 GB-eq, tail skip on: Q2_0 story +4.5%, code +9.9%, 4K +8.8%; IQ3_S story -2.1%, code +8.0%, 4K +23.3%; with three or more stages the pipelined loop does not run it). Measured (interleaved pairs of whole engine runs, new default against `STRATA_PCIE_FRAC_DEFAULT=old`, medians, route tail skip on): @@ -1854,12 +1854,17 @@ None of these changes the default answers; each was measured against the default engine runs (a fresh engine per side, warmed, 200-token greedy answers on three fixed prompts, medians; "pairs faster" counts the pairs in which the switched arm won). They are here so you can try them on your own card. -- **`STRATA_GDN_CHUNKED=1`: the DeltaNet recurrence of the prompt in chunks of 32 tokens** (sergiywith, #1372; WY form, FP32, +- **`STRATA_GDN_CHUNKED=1`: the DeltaNet recurrence of the prompt, opt-in**. On CUDA it runs in chunks of 32 tokens + (sergiywith, #1372; WY form, FP32, other bits than the default: first-token KL against the default was 0.002-0.009 nats on average, the same top token in every prompt tried). The kernel needs 128 SMs in one wave, so by itself it runs only on a card with 128 or more (RTX 5090: 1.8x on the recurrence). On smaller cards `STRATA_GDN_CHUNKED=2` forces it for a measurement, and it is slower there: 0.73x on an RTX 3060 (28 SMs) and 0.87x on an RTX 5070 (48 SMs) at 2K-32K tokens (`gdn_rec_parity --bench`), and the prompt time did not improve: RTX 5070 2K 1.01x, 8K 1.00x of the default's time; RTX 3060 2K, 8K, 16K 1.01x, no pair faster. + On HIP, gfx1100-gfx1102, gfx1150 and gfx1151 use 16-token WMMA chunks with FP16 operands and a fused output norm; other cards and short + chunks keep the existing path. It changes rounding too (first-token KL against the default 0.006-0.007 on average, the same top + token in 12 of 12 prompts); on a Radeon 8060S (gfx1151) the layer's recurrence is 1.6x faster and a 4K-128K prompt after a warm-up prompt 1.4-2.1%; see + [the HIP conditions and numerical checks](AMD_HIP.md#opt-in-chunked-prompt-gdn-on-gfx11). - **`STRATA_FS_SLOTS=N`: the Foresight swap space** (q8atnight, #1348): N VRAM slots per layer, refilled on a copy stream with the experts that just missed and with the ones the next layer's router predicts (`STRATA_FS_AHEAD=0` for the misses only), so that an expert the cache lacks can be computed on the GPU instead of by the CPU. The model's own router diff --git a/docs/RADEON_780M.md b/docs/RADEON_780M.md new file mode 100644 index 00000000..bc10836e --- /dev/null +++ b/docs/RADEON_780M.md @@ -0,0 +1,132 @@ +# Radeon 780M / 760M (Ryzen 7040 / 8040, gfx1103): build from source on Linux + +The Radeon 780M (Phoenix / Hawk Point, RDNA3, `gfx1103`) runs Strata through the same HIP backend as the Radeon +cards in [AMD_HIP.md](AMD_HIP.md). **Status: experimental and opt-in** (`STRATA_EXPERIMENTAL_GFX1103=1`): the port +is measured on one machine (the numbers below), the maintainers have not run one, and the chip is not Strix Halo. +Everything here was measured on a Ryzen 7 8745HS (8 cores, AVX-512), Radeon 780M (12 CUs), 60 GB DDR5, GTT at +50 GiB, Ubuntu kernel 7.0.0-38, `cwsr_enable=0`, engine 0.1.43 built from this tree by hand, Qwen3.8-Flash-Next +GSQ-RCO Q2_0 with the MTP draft layer, 32K context, Int8 KV. + +## 1. What the port changed + +- **Native dot4.** gfx1103 was outside the `dp4a` guard in `hip_compat/intrinsics.hpp`, so every quantized dot + product ran a four-step byte loop instead of `v_dot4_i32_iu8`. gfx1103 now compiles the native instruction + (decode +55% measured: 8.70 -> 13.44 tok/s at a 32K prompt, same greedy token ids as before). +- **gfx11 WMMA kernels.** gfx1103 was outside the `__gfx11xx__` list of the prompt attention, block scorer, + prompt GEMMs and prompt experts, so those fell back to hipBLAS / portable kernels. It is now in the list and + the parity tests run on it (`hip_prefill_wmma_gemm_parity`, `hip_prompt_attn_wmma`, `hip_prefill_fused_moe`, + `hip_prefill_fused_iq`, `qsa_*`, `hip_gemm_f16_io_parity`, `hip_prefill_mmq_parity`). +- **A hipBLASLt table** for gfx1103 + hipBLASLt `100401`: `tools/hip/gfx1103-hipblaslt-100401.txt` (section 3). +- **The gfx1103 exact speed switches** (section 4), written into the config's `env` by setup for the opt-in install + (the engine keeps gfx1103 out of its arch defaults, as it does for gfx1150). Whether the chip leaves the + `STRATA_EXPERIMENTAL_GFX1103=1` opt-in is the maintainers' call; the numbers here are what they need to make it. + +## 2. Toolchain and build + +ROCm 10.1 (`rocm/dev-ubuntu-24.04:10.1.0-full`) is what this build and the table were tested with: HIP +7.16.26385, hipBLASLt 1.4.1 (`100401`), clang 24. Its hipBLASLt carries gfx1103 kernels. setup's TheRock index +for `gfx110X-all` has no 10.x (its newest is 7.14.0a20260612); the gfx1103 opt-in keeps setup's nightly pin, and +the wheel route was not exercised by the numbers below - they come from a hand build. + +By hand, the steps of [STRIX_HALO.md](STRIX_HALO.md) with the architecture and the paths changed: + +```sh +cmake -S . -B build-780m -G Ninja -DCMAKE_BUILD_TYPE=Release \ + -DSTRATA_ENABLE_HIP=ON -DSTRATA_ENABLE_CUDA=OFF -DSTRATA_PREFILL_MMQ=ON \ + -DCMAKE_HIP_ARCHITECTURES=gfx1103 \ + -DCMAKE_HIP_COMPILER=/opt/rocm/lib/llvm/bin/clang++ -DCMAKE_HIP_COMPILER_ROCM_ROOT=/opt/rocm \ + -DCMAKE_PREFIX_PATH=/opt/rocm \ + "-DCMAKE_HIP_FLAGS=--rocm-path=/opt/rocm --rocm-device-lib-path=/opt/rocm/lib/llvm/amdgcn/bitcode" +cmake --build build-780m -j 12 +ctest --test-dir build-780m +``` + +`ctest` on this machine: 57 passed, 2 skipped (`hip_prefill_hcd_exact_parity`, `hip_prefill_hipblaslt_gemm` - +they run and pass with the table set), 2 environmental failures (`ple_parity` needs the `bench/micro` fixtures, +`platform_memory_test` needs a memlock limit above 8 MiB; this host's hard limit is 8 MiB). + +The model: a GSQ-RCO Q2_0 pack (`tools/iq_pack.py`, the experts read from the GGUF in place), the PLE table on +the SSD (`--ple-io direct`), `--mmap-experts --expert-cache 24576`, `--prefill auto`, MTP from +`tools/mtp_fetch.py` + `mtp_pack.py` + `mtp_rt.py`. GTT must be raised for this model (`ttm.pages_limit`; setup +changes no host setting). + +## 3. The hipBLASLt table + +```sh +export STRATA_HIPBLASLT_TUNING=$PWD/tools/hip/gfx1103-hipblaslt-100401.txt +``` + +setup hands it over automatically when the installed hipBLASLt reports 1.4.1. It was calibrated with +`tools/hip/tune_hipblaslt` over the gfx1150 table's 144 GEMM cases at T = 64..16384 (the same case list the 890M +run used), two passes, 32 MiB workspace, each row the solution with the lowest median of all six repetitions: 143 +rows (the `bf16 N=1 K=2560 T=64` shape has no candidate faster than plain hipBLAS and is left out), 1.05-23.30x per +GEMM, geometric mean 4.95x. `hip_prefill_hipblaslt_gemm` reports `fallbacks=0`; `hip_prefill_hcd_exact_parity` +skips because the table picks no 1176 / 1177 for the HC down GEMM (the gfx1150 table gets the same skip). + +## 4. The exact speed switches + +With `STRATA_EXPERIMENTAL_GFX1103=1` setup writes the 17 exact switches below into the config's `env`, the same way +it writes the hipBLASLt table; turning the opt-in off takes them out again. The engine keeps gfx1103 out of its +arch defaults (`arch_default_env("gfx1103")` stays empty, checked by `arch_defaults_test`). Measured on the 780M: ++13% to +15% prompt with the table (183-186 -> 211-212 tok/s at 4K) and +3.2% decode (16.63 -> 17.17 tok/s, 640 +greedy tokens, 3 of 3 pairs), with the greedy token ids unchanged. They are the gfx1151 table less +`STRATA_HCD_EXACT` (which needs hipBLASLt solutions 1176 / 1177; the gfx1103 table picks others). + +| Switch | What it does | +|---|---| +| `STRATA_GDN_HEAD`, `STRATA_GDN_PP=2`, `STRATA_GDN_CONVL2`, `STRATA_GDN_NOY`, `STRATA_CVEC_FUSE` | the prompt's gated-delta-net recurrence and the steered layer's fused write | +| `STRATA_PF_PAD` | padded GEMM row strides (acts with `STRATA_PF_GEMM`; inert without it) | +| `STRATA_Q8_PACKED`, `STRATA_Q6_PACKED`, `STRATA_MMVF_ROWS`, `STRATA_ATTN_LANECELL` | decode layouts and kernels (packed Q8_0 / Q6_K weights, 4-row BF16 GEMV, one-cell-per-thread attention scores) | +| `STRATA_EXPERT_V2`, `STRATA_TSUM`, `STRATA_LFUSE`, `STRATA_GDN_SPLIT`, `STRATA_QFUSE`, `STRATA_PLE_BATCH`, `STRATA_SH_STREAM` | grouped decode experts, butterfly warp sums, fewer launches, the GDN step over four blocks per head, producer-written activation images, batched PLE projections, the shared expert on its own stream | + +## 5. Opt-in switches (they change bits) + +Opt-in, and the measured wins are below. The prompt levers need the table to pay: with the table, the WMMA set +read 248 tok/s at 4K against 186 without it, and at 32K 272 against 178. No KL was measured on this chip. + +```sh +export STRATA_HIP_WMMA=1 # prompt attention on matrix cores +export STRATA_PF_GEMM=1 # the prompt's FP16 projections on the WMMA GEMM +export STRATA_PA_FAST=1 # prompt attention with single FP16 q and p +export STRATA_SELECT_WMMA=1 # the block scorer on matrix cores +export STRATA_PF_FUSED=1 # the prompt experts on matrix cores (neutral at 4K here: 246 vs 248) +export STRATA_HC_UPMIX=1 # the hyper-connection up projection with its epilogue +``` + +## 6. Engine flags + +`--spec 2` is the best MTP window on this chip: 15.65 tok/s decode at a 4K prompt against 14.18 at `--spec 4` and +11.16 at `--spec 6` (greedy, 256 tokens, medians of three interleaved restarts). `--lookup-chain 4` adds +2.3% (3 +of 3 pairs, byte-identical greedy answers) and setup's `--spec-min-p 0.5` is 4.5% slower here than the default; +`--mtp-q4` is neutral and `--mtp-window 4096` measured +2% at 32K in two pairs (weak). The raw runs are in the +results folder. + +## 7. Measured + +bench/bench_vs_llama.py, 256 tokens out, temperature 0 and 0.7, interleaved; each cell one round (medians need +more rounds - treat these as one-machine samples): + +| arm | cell | prompt tok/s | decode tok/s | TTFT s | +| --- | --- | ---: | ---: | ---: | +| plain (no table, no opt-ins) | 4K | 90 | 13.1 | 44.9 | +| plain (no table, no opt-ins) | 32K | 90 | 13.1 | 351 | +| table + all opt-ins | 4K | 277 | 13.9 | 14.6 | +| table + WMMA set | 32K | 272 | 14.3 | 118 | + +A context ladder on the shipping configuration (131K context, `--spec 2 --lookup-chain 4`) with fresh prompts from +this checkout's own documentation, 128 greedy tokens each: prefill holds ~310 tok/s to 32K (276.7 at 4K, 314.3 / +314.6 at 8K / 16K, 308.7 at 32K), then 258.2 at 64K, 215.5 at 96K and 198.5-221.4 at 128K across two runs - that is +the average over the full read, and the last ~14K tokens at 128K depth read at ~206 tok/s with the prefix cached. +Decode holds ~16 tok/s to 32K, then 12.1 at 64K and 9.8-9.9 at 96-128K (draft acceptance stays ~70%, so it is +context cost, not the drafter). Memory stays flat: 38.1 of 50 GiB GTT at 131K. Raw: +[bench/results/2026-10-12-community-gfx1103](../bench/results/2026-10-12-community-gfx1103/README.md). + +## 8. Not tested + +- The TheRock-wheel install for gfx1103 (the hand build above is what was measured). +- The opt-in set beyond one round; KL of any bit-changing switch; other models; contexts past 131K. +- CUDA and SYCL were not built here (no toolchains on this box); the added gfx1103 macros are undefined for them. +- Reset stability looks good but is one machine: a 2 h 07 m soak (`tools/serve_load.py`, 924 requests) and the + reset-prone combination from 7.10 (partial expert cache + `STRATA_IO_PREFETCH=1` + the adaptive tier) both ran + with zero `amdgpu` resets in the kernel log. The known 780M issue ([DETAILS.md](DETAILS.md)) was seen on ROCm + 7.10; with `cwsr_enable=0` and this stack it did not reproduce. diff --git a/docs/STRIX_HALO.md b/docs/STRIX_HALO.md index 75b642a2..de2ece3e 100644 --- a/docs/STRIX_HALO.md +++ b/docs/STRIX_HALO.md @@ -125,6 +125,16 @@ replay 3.4 -> 2.1 s per turn). Its output is the fused path's, which reads of 1, under `STRATA_PF_SWITCH_MIN_T`, which gates only the hyper-connection and padding switches. A UD-Q4_K_XL or other K-quant pack takes the fused experts only with `STRATA_PF_FUSED_KQ=1` as well. +`STRATA_PF_F16=1` (gfx11 only; add it to the list above) runs the covered prompt experts on the F16 matrix cores instead of +the int8 ones: K-quant gate/up and Q5_1 down (with `STRATA_PF_FUSED_KQ=1`), IQ2 / IQ3 / IQ4_XS gate/up, Q2_0 / IQ4_NL / Q8_0 +down. One layer, 16,384 tokens: Q4_K / Q5_1 85.3 -> 53.5 ms, IQ3_S / IQ4_NL gate/up 11.65 -> 9.87 and down 6.11 -> 4.71 ms. +It rounds differently from the int8 kernels. First-token KL against a run with no switches, 12 natural-text prompts of +1.5K-24K tokens (Strata's own docs and sources), top-1 the same in 12 of 12: UD-Q4_K_XL mean 0.0068 (median 0.0021) against +0.0031 (0.0024) for `STRATA_PF_FUSED=1 STRATA_PF_FUSED_KQ=1` without it; UD-IQ4_XS 0.0085 (0.0036) against 0.0068 (0.0032). One +1.5K prompt carries most of the Q4_K_XL mean (0.049). + +`STRATA_REFILL_PARTS=1` (opt-in, exact; HIP and CUDA, a GGUF read in place) refills the expert-cache slots a prompt borrowed straight from the GGUF mapping (an expert's gate, up and down tensors) instead of through an assembled 4 MB copy per expert: the same bytes in the slot (checked against the assembled blob on 162 slots), 0.1 to 0.3 s less at the end of a prompt; gfx1151, UD-Q4_K_XL and UD-IQ4_XS: a 4K-8K prompt +2.3% to +3.5%, 32K +1.1%. It is not in the table above because only gfx1151 has measured it. + Two engine flags help on long contexts and are not Strix-specific: `--mtp-window 8192` (the draft layer attends to the last 8,192 cells: 64K output +3.5%, 32K -0.4%) and `--spec`, `--lookup-chain`, `--mtp-q4` (see [DETAILS.md](DETAILS.md)). diff --git a/include/strata/core/expert_cache.hpp b/include/strata/core/expert_cache.hpp index 5262ce5f..9685aa4d 100644 --- a/include/strata/core/expert_cache.hpp +++ b/include/strata/core/expert_cache.hpp @@ -78,6 +78,9 @@ bool write_expert_profile(const std::string& path, int64_t n_layers, int64_t n_e /// and the engine's host side (STRATA_UMA_HEADROOM_GIB). Elsewhere it is cudaMemGetInfo's. size_t device_free_bytes(); +/// One piece of an expert blob that lives contiguously in a source's own memory: `n` bytes at `p`, to land `at` bytes into the blob. +struct BlobPart { const uint8_t* p; uint64_t n; uint64_t at; }; + class ExpertCache { public: ExpertCache() = default; @@ -201,6 +204,9 @@ public: /// perf-review D-4: `fill_slot_blocking`'s copy on the same (legacy) stream, but queued: many slots are refilled /// with one `sync_queued` at the end instead of a wait per slot. Same ordering against earlier work, same bytes. bool fill_slot_queued(int32_t slot, const uint8_t* host_blob, std::string& err, int64_t bytes = 0); + /// `fill_slot_queued` for a blob that is not in one piece: each `parts[i].n` bytes at `parts[i].p` go to byte `parts[i].at` + /// of the slot (the pieces tile the blob). Same queue, same `sync_queued`. + bool fill_slot_queued_parts(int32_t slot, const BlobPart* parts, int n, std::string& err); bool sync_queued(std::string& err); /// Reads `slot` back to the host and compares it to `host_blob`, byte for byte. **THE ONLY THING THAT SAYS diff --git a/include/strata/core/expert_source.hpp b/include/strata/core/expert_source.hpp index 90cf64b2..4850b8b6 100644 --- a/include/strata/core/expert_source.hpp +++ b/include/strata/core/expert_source.hpp @@ -172,6 +172,11 @@ public: /// A blob pointer that stays valid (not recycled) for as long as the source is open: for a copy that runs /// asynchronously long after the call (the adaptive tier's swap-ins). Defaults to `blob`. virtual const uint8_t* blob_stable(int64_t layer, int64_t expert) { return blob(layer, expert); } + /// The pieces (up to 3) a blob consists of when the source can hand them out where they already are - the GGUF + /// mapped in place keeps an expert's gate, up and down in three tensors - so the caller can copy each straight to + /// its destination instead of `blob_stable` assembling a staging copy first. 0: not available for this + /// (layer, expert) - take `blob_stable`. The pointers stay valid as long as the source is open. + virtual int blob_parts(int64_t layer, int64_t expert, BlobPart* out) { (void) layer; (void) expert; (void) out; return 0; } /// The caller has queued an asynchronous copy out of `blob` (a pointer this source handed out) on `stream` (a /// cudaStream_t): the source must not overwrite or recycle that memory until the copy has finished. A source whose /// pointers are never recycled ignores it. (#1237: a page-locked stage buffer is read by the DMA after the copy call @@ -810,6 +815,7 @@ public: const uint8_t* blob(int64_t layer, int64_t expert) override; /// With io prefetch in the experts.bin tier, the mapping itself (blob() may hand out a recycled staging buffer). const uint8_t* blob_stable(int64_t layer, int64_t expert) override; + int blob_parts(int64_t layer, int64_t expert, BlobPart* out) override; void note_async_read(const uint8_t* blob, void* stream) override; /// Windows, opt-in with STRATA_FILE_RELEASE=1: trim the file mapping's full pages after their expert reaches /// VRAM. Never touches the resident complement or staging buffers. Disabled by default. diff --git a/include/strata/core/remote_experts.hpp b/include/strata/core/remote_experts.hpp index d499c031..115d1dc8 100644 --- a/include/strata/core/remote_experts.hpp +++ b/include/strata/core/remote_experts.hpp @@ -128,6 +128,9 @@ public: const uint8_t* blob_stable(int64_t layer, int64_t expert) override { return fallback_.blob_stable(layer, expert); } + int blob_parts(int64_t layer, int64_t expert, BlobPart* out) override { + return from_helper(layer, expert) ? 0 : fallback_.blob_parts(layer, expert, out); + } int64_t reads() const override { return fallback_.reads(); } bool pinned(int64_t layer, int64_t expert) const override { return from_helper(layer, expert) ? false : fallback_.pinned(layer, expert); diff --git a/include/strata/kernels/fused_gr.hpp b/include/strata/kernels/fused_gr.hpp index 95b51016..64838027 100644 --- a/include/strata/kernels/fused_gr.hpp +++ b/include/strata/kernels/fused_gr.hpp @@ -85,4 +85,12 @@ void fused_gr_set_fast(int on); void fused_gr_check(); int fused_gr_variant(); +/// Opt-in STRATA_HC_PERSIST=1 (HIP): the multi read as one persistent kernel (80 resident blocks, the down projection +/// split by column slices, two grid barriers). Another summation order (not bitwise). +/// `fused_gr_persist_init` checks residency and the result against the default read once per card (Verifier::init); +/// `fused_gr_read_persist` returns false when it did not run (off, too many tokens, a Q8 / QFUSE read) - then the caller +/// runs `fused_gr_read_multi`. Only for reads on a stream no other persistent read runs on concurrently (the verifier's). +void fused_gr_persist_init(); +bool fused_gr_read_persist(const FusedGrArgs* a, int n_tok, void* stream); + } // namespace strata::kernels diff --git a/include/strata/prefill/kernels.hpp b/include/strata/prefill/kernels.hpp index c64d4c79..f4ea5e70 100644 --- a/include/strata/prefill/kernels.hpp +++ b/include/strata/prefill/kernels.hpp @@ -63,7 +63,8 @@ void gdn_recurrence(float* state, const float* h, const float* gate, const float int64_t ld16 = 0); // ld16: y16's row stride (0 = 6144; S23 STRATA_PF_PAD pads it) /// The kernels behind gdn_recurrence, for the parity test: 0 = the column-split kernels + the norm kernel (or the /// one-block-per-head kernel under STRATA_GDN_REC_HEADS), 1 = four lanes per column (no barrier per token) + the grid-stride norm, 2 = the -/// one-block-per-head kernel (its fused norm rounds differently). 0 and 1 give the same bits. +/// one-block-per-head kernel (its fused norm rounds differently). 0 and 1 give the same bits. On HIP, 0 and 1 run the opt-in +/// chunked WMMA recurrence instead (gfx11, STRATA_GDN_CHUNKED=1, 64 tokens and more: other bits, see docs/AMD_HIP.md). /// SYCL only: 6 = the Xe sub-group recurrence (16-lane sub-groups, one barrier per token) + the norm kernel, the same /// bits as 0 on an Arc A770; gdn_recurrence takes it by default on Alchemist (STRATA_GDN_XE=0 off, =1 any Intel GPU). void gdn_recurrence_variant(int variant, float* state, const float* h, const float* gate, const float* beta, diff --git a/setup.py b/setup.py index 623858fc..e7434577 100644 --- a/setup.py +++ b/setup.py @@ -2104,6 +2104,7 @@ ROCM_INDEXES = {"gfx1100": "https://rocm.nightlies.amd.com/v2/gfx110X-dgpu/", "gfx1030": "https://rocm.nightlies.amd.com/v2/gfx103X-all/", "gfx1031": "https://rocm.nightlies.amd.com/v2/gfx103X-all/", "gfx1151": "https://rocm.nightlies.amd.com/v2/gfx1151/", # Strix Halo (docs/STRIX_HALO.md) + "gfx1150": "https://rocm.nightlies.amd.com/v2/gfx1150/", # Strix Point: only with STRATA_EXPERIMENTAL_GFX1150=1 "gfx1103": "https://rocm.nightlies.amd.com/v2/gfx110X-all/"} # Radeon 780M: only with STRATA_EXPERIMENTAL_GFX1103=1 # The TheRock nightly indexes are pruned and move on, and each GPU family's index holds its own range (#1103: gfx103X-all # starts at 7.13.0a20260422 and has no 7.10; #1267: the 7.10 wheel segfaults on a Strix Halo with kernel 7.2.8), so one @@ -2118,9 +2119,38 @@ ROCM_VERSION_OVERRIDE = os.environ.get("STRATA_ROCM_VERSION") or None ROCM_VERSION = ROCM_VERSION_OVERRIDE or ROCM_VERSION_DEFAULT # kept for callers that read one version ROCM_SYSTEM_MIN = (7, 0) # an older system ROCm is passed over for the wheels (gfx1201 needs ROCm 6.4 or newer) # STRATA_EXPERIMENTAL_GFX1103=1 (opt-in, unsupported): the Radeon 780M / 760M / 740M iGPU (Ryzen 7040 / 8040, gfx1103) is taken -# as a unified-memory AMD card like Strix Halo, with the portable kernels (no WMMA) (measured on one machine: Ryzen 7 255). Unset: unchanged. +# as a unified-memory AMD card like Strix Halo, with the native dot4 and gfx11 WMMA kernels, the gfx1103 exact speed switches +# and a hipBLASLt table when one matches (measured on one machine: Ryzen 7 8745HS). Unset: unchanged. GFX1103_OPT_IN = os.environ.get("STRATA_EXPERIMENTAL_GFX1103") == "1" -AMD_ARCHS = ("gfx1100", "gfx1101", "gfx1102", "gfx1200", "gfx1201", "gfx1030", "gfx1031", "gfx1151") + (("gfx1103",) if GFX1103_OPT_IN else ()) +# STRATA_EXPERIMENTAL_GFX1150=1 (opt-in, unvalidated): the Radeon 890M / 880M iGPU (Ryzen AI 300, Strix Point, gfx1150) +# is taken as a unified-memory AMD card like Strix Halo. The engine builds and runs for gfx1150 from 0.1.40.2 (#1217; +# tools/hip/gfx1150-hipblaslt-100401.txt is calibrated on it), but no release ships a ready-made Windows engine for it: +# build one with `STRATA_HIP_ARCHS=gfx1150 tools\hip\build_windows.bat` and start setup with `--prebuilt dist\`. +# Unset: unchanged. +GFX1150_OPT_IN = os.environ.get("STRATA_EXPERIMENTAL_GFX1150") == "1" +AMD_ARCHS = ("gfx1100", "gfx1101", "gfx1102", "gfx1200", "gfx1201", "gfx1030", "gfx1031", "gfx1151") \ + + (("gfx1103",) if GFX1103_OPT_IN else ()) + (("gfx1150",) if GFX1150_OPT_IN else ()) +# The exact (bit-identical) speed switches the engine turns on by default on gfx1151 (src/core/arch_defaults.cpp), less +# STRATA_HCD_EXACT: that one copies the gfx1151 hipBLASLt table's solutions 1176 / 1177, and the gfx1103 table +# (tools/hip/gfx1103-hipblaslt-100401.txt) picks others, so it would only report that it cannot run. A gfx1103 install +# takes them from here (setup writes them into the config's "env"), the same way the table is written: one 780M measured +# the same greedy answers with all 17 on and with all 17 off, +13% to +15% prompt and decode +3.2% (the decode half +# alone). The engine keeps gfx1103 out of its own arch defaults (src/core/arch_defaults_test.cpp asserts it stays +# empty), so this keeps the default path byte-identical. +GFX1103_SWITCHES = { + # prompt + "STRATA_GDN_HEAD": "1", "STRATA_GDN_PP": "2", "STRATA_GDN_CONVL2": "1", "STRATA_GDN_NOY": "1", + "STRATA_CVEC_FUSE": "1", "STRATA_PF_PAD": "1", + # decode + "STRATA_Q8_PACKED": "1", "STRATA_Q6_PACKED": "1", "STRATA_MMVF_ROWS": "1", "STRATA_ATTN_LANECELL": "1", + "STRATA_EXPERT_V2": "1", "STRATA_TSUM": "1", "STRATA_LFUSE": "1", "STRATA_GDN_SPLIT": "1", + "STRATA_QFUSE": "1", "STRATA_PLE_BATCH": "1", "STRATA_SH_STREAM": "1", +} +# The same set for a gfx1150 install (Radeon 890M / 880M): less STRATA_HCD_EXACT as well, because a gfx1150 table picks other +# solutions than the gfx1151 one. The Radeon 890M report (docs/AMD_HIP.md; bench/results/2026-10-07-community-gfx1150) measured the +# same greedy answers with all 17 on and with all 17 off, decode +2% and prompts +3-6%. The engine's arch defaults are not used +# for gfx1150 (src/core/arch_defaults_test.cpp asserts gfx1150 stays empty), so this keeps the default path byte-identical. +GFX1150_SWITCHES = dict(GFX1103_SWITCHES) AMD_NAMES = {"gfx1100": "AMD Radeon RX 7900 series (gfx1100)", # when sysfs has no product name "gfx1101": "AMD Radeon RX 7800 XT / 7700 XT (gfx1101)", "gfx1102": "AMD Radeon RX 7600 / 7600 XT (gfx1102)", @@ -2226,6 +2256,15 @@ def is_strix_halo(g) -> bool: return isinstance(g, dict) and gfx_arch_is(g.get("arch"), STRIX_HALO_ARCH) +def is_uma_apu(g) -> bool: + """A unified-memory AMD APU whose "VRAM" is a BIOS carve-out plus shared system memory: Strix Halo (gfx1151), and + the opt-in gfx1150 (Strix Point) / gfx1103 (Phoenix / Hawk Point) iGPUs. Everything else is a discrete card.""" + arch = g.get("arch") if isinstance(g, dict) else None + return (is_strix_halo(g) + or (GFX1150_OPT_IN and gfx_arch_is(arch, "gfx1150")) + or (GFX1103_OPT_IN and gfx_arch_is(arch, "gfx1103"))) + + def amd_apply_uma(g: dict, gtt_gb: float = 0.0, ram: float | None = None) -> dict: """Strix Halo is an APU with unified memory. Its "dedicated VRAM" is a BIOS carve-out (512 MB to 96 GB; 2 GB on the maintainers' box) and the GPU also reaches shared system memory (Linux: the GTT pool, `mem_info_gtt_total`, half the @@ -2233,7 +2272,7 @@ def amd_apply_uma(g: dict, gtt_gb: float = 0.0, ram: float | None = None) -> dic the model's experts live in, so it is not extra room beside the RAM. g gets: uma, dedicated_gb (the carve-out: the only part that adds to the RAM, which the low-RAM mode counts) and vram_gb = the memory the GPU can use in all (the carve-out plus the shared pool less what the OS keeps), which sizes the context and the parallel slots.""" - if g.get("uma") or not (is_strix_halo(g) or (GFX1103_OPT_IN and gfx_arch_is(g.get("arch"), "gfx1103"))): + if g.get("uma") or not is_uma_apu(g): return g ram = ram_gb() if ram is None else ram carve = max(0.0, float(g.get("vram_gb") or 0.0)) @@ -2383,8 +2422,26 @@ def gfx1103_notes(gpu, ram) -> list[str]: f"seen by the OS + a {gpu.get('dedicated_gb', 0.0):.1f} GB BIOS carve-out), so the model's experts live in " "that pool and the expert cache is sized from the memory the OS can give back."] notes.append(" " + ("The engine is compiled here for gfx1103" if not WIN else "This GPU has no ready-made Windows engine") + + " with the native dot4 and WMMA kernels and the 780M's exact speed switches" + " (experimental opt-in, STRATA_EXPERIMENTAL_GFX1103=1; measured on one machine, not validated on a real " - "card): see docs/AMD_HIP.md. This is not a Strix Halo.") + "card): see docs/AMD_HIP.md and docs/RADEON_780M.md. This is not a Strix Halo.") + if not WIN and gpu.get("shared_gb", 0) < 0.75 * ram - 1: + notes.append(f"!the GPU can reach {gpu.get('shared_gb', 0):.0f} GB of shared memory (the GTT pool; the kernel's " + "default is about half of the RAM). The kernel option ttm.pages_limit raises it; setup changes no " + "host setting - a bigger model needs the room, a smaller one runs as it is") + return notes + + +def gfx1150_notes(gpu, ram) -> list[str]: + """What setup tells the owner of a Radeon 890M / 880M (Ryzen AI 300, Strix Point, gfx1150, unified memory): never + the Strix Halo text, which is about another chip (gfx1151). Opt-in only (STRATA_EXPERIMENTAL_GFX1150=1).""" + notes = [f" Radeon 890M / 880M class (gfx1150, Strix Point): the CPU and the GPU share one memory pool ({ram:.0f} GB " + f"seen by the OS + a {gpu.get('dedicated_gb', 0.0):.1f} GB BIOS carve-out), so the model's experts live in " + "that pool and the expert cache is sized from the memory the OS can give back."] + notes.append(" " + ("The engine is compiled here for gfx1150" if not WIN else + "Windows has no ready-made engine for gfx1150: build one with STRATA_HIP_ARCHS=gfx1150 " + "tools\\hip\\build_windows.bat and start setup with --prebuilt dist\\") + + " (experimental opt-in, STRATA_EXPERIMENTAL_GFX1150=1, unvalidated: docs/AMD_HIP.md).") if not WIN and gpu.get("shared_gb", 0) < 0.75 * ram - 1: notes.append(f"!the GPU can reach {gpu.get('shared_gb', 0):.0f} GB of shared memory (the GTT pool; the kernel's " "default is about half of the RAM). The kernel option ttm.pages_limit raises it; setup changes no " @@ -2393,9 +2450,11 @@ def gfx1103_notes(gpu, ram) -> list[str]: def igpu_notes(gpu, ram) -> list[str]: - """The unified-memory notes for exactly this chip: Strix Halo (gfx1151) or the gfx1103 opt-in, nothing else.""" + """The unified-memory notes for exactly this chip: Strix Halo (gfx1151) or the gfx1150 / gfx1103 opt-in, nothing else.""" if is_strix_halo(gpu): return strix_halo_notes(gpu, ram) + if GFX1150_OPT_IN and gfx_arch_is(gpu.get("arch"), "gfx1150"): + return gfx1150_notes(gpu, ram) if gfx_arch_is(gpu.get("arch"), "gfx1103"): return gfx1103_notes(gpu, ram) return [] @@ -2523,9 +2582,9 @@ def amd_gpus_win() -> list[dict]: hip = hip_devices() if not hip: return amd_gpus_windows() - halo = [g for g in hip if is_strix_halo(g)] + halo = [g for g in hip if is_uma_apu(g)] if halo: # an APU: the HIP runtime's figure is not the BIOS carve-out - reg = [r for r in amd_gpus_windows() if is_strix_halo(r)] + reg = [r for r in amd_gpus_windows() if is_uma_apu(r)] for k, g in enumerate(halo): reported = g["vram_gb"] g["vram_gb"] = reg[k]["dedicated_gb"] if k < len(reg) else 0.0 @@ -4464,7 +4523,7 @@ def write_config(path: Path, cfg: dict): SETUP_KEYS = frozenset({"exe", "args", "cwd", "tokenizer", "model_name", "log", "lib_dirs", "port", "backend", "env", "gpu", "gpus_asked", "layer_split", "host", "api_key", "draft_vocab", "vision"}) SETUP_ENV = frozenset({"STRATA_HIPBLASLT_TUNING", "STRATA_RESIDENT_PIN", "STRATA_NO_ARENA_THP", "STRATA_MMQ_KQ", "STRATA_HC_Q8", - "STRATA_ROUTE_TAIL_SKIP"}) # the "env" entries setup writes + "STRATA_ROUTE_TAIL_SKIP"}) | frozenset(GFX1103_SWITCHES) | frozenset(GFX1150_SWITCHES) # the "env" entries setup writes (the gfx1103 switches are setup's too: a re-run refreshes them, they do not linger) # 0.1.44 added these three, written for Unsloth's files only (unsloth_default_env). In any other model's config they are the # user's own (STRATA_ROUTE_TAIL_SKIP=0 to turn the tail skip off, STRATA_MMQ_KQ=1 ...): a setup run again keeps them there # (0.1.44 dropped them with the rest of SETUP_ENV). @@ -6965,6 +7024,15 @@ def main() -> int: if GFX1103_OPT_IN and gfx_arch_is(gpu["arch"], "gfx1103") and not WIN: # the 780M's KFD queues are evicted (a GPU reset) while transparent huge pages move the pinned expert arena cfg.setdefault("env", {})["STRATA_NO_ARENA_THP"] = "1" + # the exact gfx1151 speed switches measured on this chip (GFX1103_SWITCHES): the engine has no arch defaults + # for gfx1103, so setup writes them into the config. They are setup's own (SETUP_ENV), so a re-run refreshes + # them and turning the opt-in off takes them out again. + cfg.setdefault("env", {}).update(GFX1103_SWITCHES) + if GFX1150_OPT_IN and gfx_arch_is(gpu["arch"], "gfx1150"): + # the exact gfx1151 speed switches measured on this chip (GFX1150_SWITCHES): the engine has no arch defaults + # for gfx1150, so setup writes them into the config. They are setup's own (SETUP_ENV), so a re-run refreshes + # them and turning the opt-in off takes them out again. + cfg.setdefault("env", {}).update(GFX1150_SWITCHES) if resident: # ROCm: large page-locked host allocations can fail or be slow for the CPU; keep the copy pageable cfg.setdefault("env", {})["STRATA_RESIDENT_PIN"] = "0" if gpu["count"] > 1 or a.gpu is not None: diff --git a/src/core/expert_cache.cpp b/src/core/expert_cache.cpp index e113a7e6..bd98ad71 100644 --- a/src/core/expert_cache.cpp +++ b/src/core/expert_cache.cpp @@ -7,6 +7,8 @@ #define STRATA_EC_NO_VMM 1 #endif +#include +#include #include #if !defined(STRATA_EC_NO_VMM) #include // #533: the virtual memory management types (the functions come through the runtime's entry points) @@ -740,6 +742,30 @@ bool ExpertCache::fill_slot_queued(int32_t slot, const uint8_t* host_blob, std:: return true; } +bool ExpertCache::fill_slot_queued_parts(int32_t slot, const BlobPart* parts, int n, std::string& err) { + uint8_t* dst = device_slot(slot); + if (dst == nullptr || parts == nullptr || n <= 0) { + err = "ExpertCache::fill_slot_queued_parts: slot outside the arena or no pieces"; + return false; + } + uint64_t total = 0; + for (int i = 0; i < n; ++i) total += parts[i].n; + if (total > (uint64_t) blob_) { + err = "ExpertCache::fill_slot_queued_parts: the pieces are larger than a slot"; + return false; + } + for (int i = 0; i < n; ++i) { + const cudaError_t e = cudaMemcpyAsync(dst + parts[i].at, parts[i].p, (size_t) parts[i].n, cudaMemcpyHostToDevice, + (cudaStream_t) 0); + if (e != cudaSuccess) { + err = std::string("ExpertCache::fill_slot_queued_parts: ") + cudaGetErrorString(e); + return false; + } + } + ++fills_; + return true; +} + bool ExpertCache::sync_queued(std::string& err) { const cudaError_t e = cudaStreamSynchronize((cudaStream_t) 0); if (e != cudaSuccess) { diff --git a/src/core/expert_source.cpp b/src/core/expert_source.cpp index 4e116944..70822d1e 100644 --- a/src/core/expert_source.cpp +++ b/src/core/expert_source.cpp @@ -3533,6 +3533,25 @@ const uint8_t* FileExpertSource::blob_stable(int64_t layer, int64_t expert) { return blob(layer, expert); } +int FileExpertSource::blob_parts(int64_t layer, int64_t expert, BlobPart* out) { + // the GGUF mapped in place only (three tensors per expert); the RAM copy, an exchange override, the unbuffered + // reads, a closed mapping and the I/O prefetch (STRATA_IO_PREFETCH: it preads the ranges the page cache lacks, which a copy out + // of the mapping would fault in one page at a time) keep going through blob(), which knows them + if (role_ptr_.empty() || !direct_.empty() || io_pf_ || unmapped_ || base_ == nullptr || layer < 0 || expert < 0 || + layer >= n_layers_ || expert >= n_expert_) + return 0; + const size_t index = (size_t) layer * (size_t) n_expert_ + (size_t) expert; + if (complement_ready_ && (resident_blob(index) != nullptr || (!override_.empty() && override_[index] != nullptr))) return 0; + Span sp[3]; + const int ns = spans(layer, expert, sp); + for (int i = 0; i < ns; ++i) out[i] = {sp[i].p, sp[i].n, sp[i].at}; + if (ns > 0) { + file_read_bytes_.fetch_add(layer_blob_bytes_[(size_t) layer], std::memory_order_relaxed); + ++reads_; + } + return ns; +} + const uint8_t* FileExpertSource::blob(int64_t layer, int64_t expert) { if (base_ == nullptr || layer < 0 || expert < 0 || layer >= n_layers_ || expert >= n_expert_) return nullptr; const size_t index = (size_t) layer * (size_t) n_expert_ + (size_t) expert; diff --git a/src/core/verify.cpp b/src/core/verify.cpp index 24c29a0a..0847405e 100644 --- a/src/core/verify.cpp +++ b/src/core/verify.cpp @@ -609,6 +609,7 @@ bool Verifier::init(const WeightTable& wt, const ModelGeometry& g, SessionState& cudaGetDevice(&device_); // a layer split's stage on another GPU: its streams, graphs and buffers live there rr_stats_ = route_resident_cfg().stats_on(device_); // STRATA_ROUTE_RESIDENT: this GPU's counters, outside graph capture strata::kernels::fused_gr_check(); // once per card: which bitwise-equal hyper-connection read runs there + strata::kernels::fused_gr_persist_init(); // opt-in STRATA_HC_PERSIST=1 (HIP) wt_ = &wt; g_ = &g; ss_ = &ss; @@ -1209,6 +1210,7 @@ bool Verifier::record_window(int T, cudaStream_t cs, std::string& err) { else if (strata::kernels::cpu::expert_layout().native) a.q8_mixed = nat_xq_ + (size_t) t * (N / 32) * 36; } } + if (strata::kernels::fused_gr_read_persist(fa, n, cs)) return false; // STRATA_HC_PERSIST=1; q8_mixed is never set there return fused_gr_read_multi(fa, n, xn_ + (size_t) tb * HC * N, cs, (prof_on_ && grp == 0) ? prof_ : nullptr, (int) (l * kProfPer + (half == 0 ? 27 : 30))); }; diff --git a/src/kernels/cuda/fused_gr.cu b/src/kernels/cuda/fused_gr.cu index 8adc141e..38b7535b 100644 --- a/src/kernels/cuda/fused_gr.cu +++ b/src/kernels/cuda/fused_gr.cu @@ -12,6 +12,8 @@ #include #include +#include +#include #include #include #include @@ -2424,4 +2426,447 @@ void hc_q8_to_bf16(const void* codes, const float* scales, uint16_t* out, long l hc_q8_bf16_kernel<<<(unsigned) ((n + 255) / 256), 256, 0, (cudaStream_t) stream>>>((const int8_t*) codes, scales, out, n); } +// ===================================== the read as ONE persistent kernel (opt-in STRATA_HC_PERSIST=1, HIP) ============== +// 80 blocks that must all be resident (a start-up run per T decides; larger T keep the default read) and two grid +// barriers on an atomic counter. Block b: (A) stages R' * w_norm for columns [128 b, 128 b + 128) (one stream) and writes +// that slice's sum of squares and the UNSCALED partial dots of the 320 down + 4 inject rows (the v3 identity +// w . xn = sum_c rs[c] (w[:, c] . x'[c])); barrier; (B) rs per stream, then rows (k, r) = b + 80 j reduced to lo / inject; +// barrier; (C) the up projection read straight from VRAM, a thread pair per row, the epilogue as gr_up_kernel. +// ANOTHER SUMMATION ORDER than the default read (not bitwise; the init check bounds the difference). Only the verifier's hyper-connection reads use it: they run on one stream per card (both pipeline +// verifiers share it), so two of these kernels never wait on each other; the drafter's reads keep the default kernels. +#if defined(__HIPCC__) +namespace { +namespace hcp { +// Measured on gfx1030 (bench/results/2026-10-12-hc-persist-gfx1030): the gain over the three-kernel read is (1) the down +// projection split by column slices over all 80 blocks (the default read runs 41 blocks staging the activations through +// LDS) and (2) one launch with two grid barriers instead of three launches and the gaps between them. Prefetching the +// up weights (into registers or by touching them into L2 / Infinity Cache) and the epilogue inputs measured no gain on +// gfx1030 and is gone: the 13 MB are read once from VRAM whichever way. +constexpr int NB = 80, SL = D / NB, SPS = N / SL, UPC = N / NB, NR = LR + HC; +static_assert(UPC * HC * 2 == THREADS, "a thread pair per up row"); +struct PArgs { + FusedGrArgs a[kFusedGrMaxT]; + float* part; // [T][NR][NB] + float* ssp; // [T][NB] + unsigned* bar; // [0] count, [32] generation, [48] abort (a barrier that timed out) + unsigned long long timeout_ticks; // s_memrealtime ticks (100 MHz) a barrier waits before it aborts the read + double* partd; // STRATA_HC_PERSIST=3 (a reference only): the partial dots and sums of squares in double + double* sspd; +}; +// Returns false when the read was aborted: a block waited longer than `ticks` (the 80 blocks were not all resident - the +// start-up check finds that out by running every T with a short timeout) or another block aborted. Then every block +// leaves the kernel; the outputs are not written completely and bar[48] stays set until the host clears the words. +__device__ __forceinline__ bool grid_sync(unsigned* bar, unsigned long long ticks) { +#if defined(__GFX11__) || defined(__GFX12__) + // gfx11 and gfx12 have no s_memrealtime (clang: "needs target feature s-memrealtime"), so no barrier clock: this read is not + // offered there (fused_gr_persist_init refuses it; an R9700 measured it neutral to 1% slower in #2226), and a launch that gets + // here anyway aborts at once instead of waiting for a barrier it cannot time. + (void) ticks; + if (threadIdx.x == 0) __hip_atomic_store(&bar[48], 1u, __ATOMIC_RELAXED, __HIP_MEMORY_SCOPE_AGENT); + return false; +#else + __shared__ int s_abort; + __syncthreads(); + if (threadIdx.x == 0) { + int ab = 0; + const unsigned gen = __hip_atomic_load(&bar[32], __ATOMIC_RELAXED, __HIP_MEMORY_SCOPE_AGENT); + __threadfence(); + const unsigned arrived = __hip_atomic_fetch_add(&bar[0], 1u, __ATOMIC_ACQ_REL, __HIP_MEMORY_SCOPE_AGENT); + if (arrived == NB - 1) { + __hip_atomic_store(&bar[0], 0u, __ATOMIC_RELAXED, __HIP_MEMORY_SCOPE_AGENT); + __hip_atomic_fetch_add(&bar[32], 1u, __ATOMIC_RELEASE, __HIP_MEMORY_SCOPE_AGENT); + } else { + const unsigned long long t0 = __builtin_amdgcn_s_memrealtime(); + while (__hip_atomic_load(&bar[32], __ATOMIC_ACQUIRE, __HIP_MEMORY_SCOPE_AGENT) == gen) { + if (__hip_atomic_load(&bar[48], __ATOMIC_RELAXED, __HIP_MEMORY_SCOPE_AGENT) != 0u) { ab = 1; break; } + if (__builtin_amdgcn_s_memrealtime() - t0 > ticks) { + __hip_atomic_store(&bar[48], 1u, __ATOMIC_RELAXED, __HIP_MEMORY_SCOPE_AGENT); + ab = 1; + break; + } + __builtin_amdgcn_s_sleep(1); + } + } + if (__hip_atomic_load(&bar[48], __ATOMIC_RELAXED, __HIP_MEMORY_SCOPE_AGENT) != 0u) ab = 1; + s_abort = ab; + } + __syncthreads(); + __threadfence(); + return s_abort == 0; +#endif +} +// STRATA_HC_PERSIST=3 (a reference only, slow): every dot and sum accumulated in double +__device__ __forceinline__ double dot8d(const uint4 w, const float* x) { + double acc = 0.0; + const unsigned u[4] = {w.x, w.y, w.z, w.w}; +#pragma unroll + for (int q = 0; q < 4; ++q) { + acc += (double) __uint_as_float(u[q] << 16) * (double) x[2 * q]; + acc += (double) __uint_as_float(u[q] & 0xffff0000u) * (double) x[2 * q + 1]; + } + return acc; +} +template +__global__ void __launch_bounds__(THREADS) persist_kernel(PArgs f) { + using A = typename std::conditional::type; + __shared__ __align__(16) float xs[T][SL]; + __shared__ __align__(16) float lo[T][LR]; + __shared__ float s_rs[T][HC]; + __shared__ float g[T][HC][UPC]; + const int tid = threadIdx.x, lane = tid & 31, b = blockIdx.x; + const FusedGrArgs& a0 = f.a[0]; + // (A) block b: columns [128 b, 128 b + 128) of D (one stream): R' * w_norm into LDS, the slice's sum of squares, and + // the UNSCALED partial dots of the 320 down + 4 inject rows (w . xn = sum_c rs[c] (w[:, c] . x'[c])) + const int c_b = b / SPS, col0 = b * SL; + if (tid < T * (SL / 4)) { + const int k = tid / (SL / 4), o4 = tid - k * (SL / 4); + const FusedGrArgs& a = f.a[k]; + const int i = col0 + o4 * 4, d = i - c_b * N; + float4 r = *reinterpret_cast(a.R + i); + if (a.apply) { + const float gw = 2.0f * sigmoidf_(a.inj_prev[c_b] / (float) HC); + const float4 bo = *reinterpret_cast(a.bo_prev + d); + r.x = fmaf(bo.x, gw, r.x); r.y = fmaf(bo.y, gw, r.y); r.z = fmaf(bo.z, gw, r.z); r.w = fmaf(bo.w, gw, r.w); + } + const float4 gn = *reinterpret_cast(a.w_norm + i); + if constexpr (DP) { + double ss = (double) r.x * r.x + (double) r.y * r.y + (double) r.z * r.z + (double) r.w * r.w; +#pragma unroll + for (int o = 16; o > 0; o >>= 1) ss += __shfl_xor(ss, o); + if (lane == 0) f.sspd[k * NB + b] = ss; + } else { + const float ss = warp_sum(r.x * r.x + r.y * r.y + r.z * r.z + r.w * r.w); // warp k = token k + if (lane == 0) f.ssp[k * NB + b] = ss; + } + *reinterpret_cast(&xs[k][o4 * 4]) = make_float4(r.x * gn.x, r.y * gn.y, r.z * gn.z, r.w * gn.w); + } + __syncthreads(); + const int hw = tid >> 4, hl = tid & 15; + const bool inj = a0.w_inject != nullptr; + const int nrows = inj ? NR : LR; +#pragma unroll 3 + for (int r = hw; r < nrows; r += 16) { + const uint16_t* wrow = r < LR ? a0.w_down + (size_t) r * D : a0.w_inject + (size_t) (r - LR) * D; + const uint4 w = __ldg(reinterpret_cast(wrow + col0) + hl); + A acc[T]; +#pragma unroll + for (int k = 0; k < T; ++k) { + A v; + if constexpr (DP) v = dot8d(w, &xs[k][hl * 8]); else v = dot8(w, &xs[k][hl * 8]); +#pragma unroll + for (int o = 8; o > 0; o >>= 1) v += __shfl_xor(v, o); + acc[k] = v; + } +#pragma unroll + for (int k = 0; k < T; ++k) + if (hl == k) { + if constexpr (DP) f.partd[((size_t) k * NR + r) * NB + b] = acc[k]; + else f.part[((size_t) k * NR + r) * NB + b] = (float) acc[k]; + } + } + if (!grid_sync(f.bar, f.timeout_ticks)) return; + // (B) rs per stream (every block), then rows (k, r) = b + 80 j reduced to lo / inject by the blocks in turn + if (tid < T * HC) { + const int k = tid / HC, c = tid - k * HC; + float rr; + if constexpr (DP) { + double sd = 0.0; + for (int j = 0; j < SPS; ++j) sd += f.sspd[k * NB + c * SPS + j]; + rr = (float) (1.0 / sqrt(sd / (double) N + (double) f.a[k].eps)); + } else { + float s = 0.0f; + for (int j = 0; j < SPS; ++j) s += f.ssp[k * NB + c * SPS + j]; + rr = rsqrtf(s / (float) N + f.a[k].eps); + } + s_rs[k][c] = rr; + if (b == 0) f.a[k].rs[c] = rr; + } + __syncthreads(); + for (int idx = b + NB * tid; idx < T * nrows; idx += NB * THREADS) { + const int k = idx / nrows, r = idx - k * nrows; + A sum = 0; + if constexpr (DP) { + const double* p1 = f.partd + ((size_t) k * NR + r) * NB; + for (int c = 0; c < HC; ++c) { + double p = 0.0; + for (int j = 0; j < SPS; ++j) p += p1[c * SPS + j]; + sum += (double) s_rs[k][c] * p; + } + } else { + const float4* p4 = reinterpret_cast(f.part + ((size_t) k * NR + r) * NB); +#pragma unroll + for (int c = 0; c < HC; ++c) { + float p = 0.0f; +#pragma unroll + for (int j = 0; j < SPS / 4; ++j) { + const float4 v = p4[c * (SPS / 4) + j]; + p += (v.x + v.y) + (v.z + v.w); + } + sum = fmaf(s_rs[k][c], p, sum); + } + } + if (r < LR) { + const A x = sum / (A) HC; + f.a[k].lo[r] = (float) (x / ((A) 1 + (DP ? (A) exp((double) -x) : (A) __expf((float) -x)))); + } else { + f.a[k].inject_out[r - LR] = (float) sum; + } + } + if (!grid_sync(f.bar, f.timeout_ticks)) return; + for (int idx = tid; idx < T * LR; idx += THREADS) { + const int k = idx / LR, r = idx - k * LR; + lo[k][r] = f.a[k].lo[r]; + } + __syncthreads(); + // (C) the up projection, a thread pair per row (block b: columns 32 b .. 32 b + 31 of all four streams), then the + // epilogue as gr_up_kernel + { + const int d0 = b * UPC; + const int ur = tid >> 1, uh = tid & 1, uc = ur / UPC, udd = ur - uc * UPC, ui = uc * N + d0 + udd; + const uint4* w4u = reinterpret_cast(a0.w_up + (size_t) ui * LR) + uh * 20; + A v[T]; +#pragma unroll + for (int k = 0; k < T; ++k) v[k] = 0; +#pragma unroll 1 + for (int j0 = 0; j0 < 20; j0 += 5) { // five chunks a batch (all twenty at once costs registers) + uint4 w[5]; +#pragma unroll + for (int q = 0; q < 5; ++q) w[q] = __ldg(w4u + j0 + q); +#pragma unroll + for (int q = 0; q < 5; ++q) +#pragma unroll + for (int k = 0; k < T; ++k) { + if constexpr (DP) v[k] += dot8d(w[q], &lo[k][uh * 160] + (j0 + q) * 8); + else v[k] += dot8(w[q], &lo[k][uh * 160] + (j0 + q) * 8); + } + } + float acc[T]; +#pragma unroll + for (int k = 0; k < T; ++k) acc[k] = (float) (v[k] + __shfl_xor(v[k], 1)); + if (uh == 0) { + const float wn = a0.w_norm[ui]; +#pragma unroll + for (int k = 0; k < T; ++k) { + const FusedGrArgs& a = f.a[k]; + float rv = a.R[ui]; + if (a.apply) { + rv = fmaf(a.bo_prev[d0 + udd], 2.0f * sigmoidf_(a.inj_prev[uc] / (float) HC), rv); + a.R_out[ui] = rv; + } + g[k][uc][udd] = rv * wn * s_rs[k][uc] * sigmoidf_(acc[k]); + } + } + } + __syncthreads(); + for (int idx = tid; idx < T * UPC; idx += THREADS) { + const int k = idx / UPC, col = idx - k * UPC; + float s = 0.0f; +#pragma unroll + for (int c = 0; c < HC; ++c) s += g[k][c][col]; + f.a[k].mixed[b * UPC + col] = s / (float) HC; + } +} +struct DevState { + float* part = nullptr; + float* ssp = nullptr; + double* partd = nullptr; + double* sspd = nullptr; + unsigned* bar = nullptr; + int max_t = 0; // 0: off on this card + bool tried = false; +}; +DevState g_dev[64]; +using KFn = void (*)(PArgs); +template +KFn kernel_t(int T) { + switch (T) { + case 1: return persist_kernel<1, DP>; + case 2: return persist_kernel<2, DP>; + case 3: return persist_kernel<3, DP>; + case 4: return persist_kernel<4, DP>; + case 5: return persist_kernel<5, DP>; + case 6: return persist_kernel<6, DP>; + case 7: return persist_kernel<7, DP>; + case 8: return persist_kernel<8, DP>; + } + return nullptr; +} +bool dp_on() { + static const bool dp = [] { const char* v = std::getenv("STRATA_HC_PERSIST"); return v != nullptr && std::atoi(v) == 3; }(); + return dp; +} +KFn kernel_for(int T) { return dp_on() ? kernel_t(T) : kernel_t(T); } +// s_memrealtime runs at 100 MHz on RDNA: a barrier gives up after 2 s in a read (never in a working run; it only turns a +// hang into a wrong read) and after 50 ms in the start-up check (where a timeout means "not resident here") +constexpr unsigned long long kTicksRun = 200000000ULL, kTicksCheck = 5000000ULL; +void launch(const FusedGrArgs* a, int n_tok, const DevState& st, cudaStream_t s, unsigned long long ticks) { + PArgs f; + for (int t = 0; t < n_tok; ++t) f.a[t] = a[t]; + f.part = st.part; f.ssp = st.ssp; f.bar = st.bar; f.partd = st.partd; f.sspd = st.sspd; f.timeout_ticks = ticks; + kernel_for(n_tok)<<>>(f); +} +bool env_on() { + static const bool on = [] { const char* v = std::getenv("STRATA_HC_PERSIST"); return v != nullptr && std::atoi(v) != 0; }(); + return on; +} +} // namespace hcp +} // namespace + +void fused_gr_persist_init() { + if (!hcp::env_on()) return; + int dev = 0; + cudaGetDevice(&dev); + if (dev < 0 || dev >= 64 || hcp::g_dev[dev].tried) return; + hcp::DevState& st = hcp::g_dev[dev]; + st.tried = true; + cudaDeviceProp prop{}; + cudaGetDeviceProperties(&prop, dev); + if (prop.warpSize != 32) { + std::fprintf(stderr, "strata hc: CUDA%d: STRATA_HC_PERSIST=1 is off here: the kernel is written for 32-lane waves " + "(this card runs %d)\n", dev, prop.warpSize); + return; + } + if (strata::kernels::gfx_arch_is_gfx12(prop.gcnArchName) || strata::kernels::gfx_arch_is_gfx11_wmma(prop.gcnArchName)) { + std::fprintf(stderr, "strata hc: CUDA%d: STRATA_HC_PERSIST=1 is off here: gfx11 / gfx12 have no s_memrealtime for the barrier " + "timeout (written and measured for gfx1030; an R9700 saw no gain from it, #2226)\n", dev); + return; + } + const int mp = prop.multiProcessorCount; // only for the confirmation line (WGPs on RDNA) + bool ok = cudaMalloc((void**) &st.part, (size_t) kFusedGrMaxT * hcp::NR * hcp::NB * sizeof(float)) == cudaSuccess && + cudaMalloc((void**) &st.ssp, (size_t) kFusedGrMaxT * hcp::NB * sizeof(float)) == cudaSuccess && + cudaMalloc((void**) &st.bar, 64 * sizeof(unsigned)) == cudaSuccess && + cudaMalloc((void**) &st.partd, (size_t) kFusedGrMaxT * hcp::NR * hcp::NB * sizeof(double)) == cudaSuccess && + cudaMalloc((void**) &st.sspd, (size_t) kFusedGrMaxT * hcp::NB * sizeof(double)) == cudaSuccess && + cudaMemset(st.bar, 0, 64 * sizeof(unsigned)) == cudaSuccess; + if (!ok) { + cudaGetLastError(); + std::fprintf(stderr, "strata hc: CUDA%d: STRATA_HC_PERSIST=1 is off here: workspace allocation failed\n", dev); + return; + } + // the check: random weights and inputs with the pending write and the inject rows, against the default read; the + // persistent read sums in another order, so it is bounded, not bitwise. Every T is RUN with a 50 ms barrier timeout; a + // timeout means "not resident here" and larger T keep the default read. No occupancy API in front of it: it promised + // more than the card holds on 30 WGPs under HSA_CU_MASK (a hang without the timeout) and less than it holds with + // the HIP 7.1 runtime (1 block per WGP on 40 WGPs, which turned the read off although it runs resident). + std::mt19937 rng(11); + std::normal_distribution nd(0.f, 1.f); + auto bf = [](float x) { uint32_t u; std::memcpy(&u, &x, 4); return (uint16_t) ((u + 0x7fff + ((u >> 16) & 1)) >> 16); }; + const int TM = kFusedGrMaxT; + std::vector R((size_t) TM * D), bo((size_t) TM * N), inj((size_t) TM * HC), wn(D); + for (auto& x : R) x = nd(rng); + for (auto& x : bo) x = 0.5f * nd(rng); + for (auto& x : inj) x = nd(rng); + for (auto& x : wn) x = 1.0f + 0.3f * nd(rng); + std::vector wd((size_t) LR * D), wu((size_t) D * LR), wi((size_t) HC * D); + for (auto& x : wd) x = bf(0.02f * nd(rng)); + for (auto& x : wu) x = bf(0.05f * nd(rng)); + for (auto& x : wi) x = bf(0.02f * nd(rng)); + float *dR, *dbo, *dinj, *dwn, *dxn, *dlo, *drs, *dio, *dmix; + uint16_t *dwd, *dwu, *dwi; + cudaMalloc((void**) &dR, R.size() * 4); cudaMalloc((void**) &dbo, bo.size() * 4); + cudaMalloc((void**) &dinj, inj.size() * 4); cudaMalloc((void**) &dwn, wn.size() * 4); + cudaMalloc((void**) &dxn, (size_t) TM * D * 4); cudaMalloc((void**) &dlo, (size_t) TM * LR * 4); + cudaMalloc((void**) &drs, (size_t) TM * HC * 4); cudaMalloc((void**) &dio, (size_t) TM * HC * 4); + cudaMalloc((void**) &dmix, (size_t) TM * N * 4); + cudaMalloc((void**) &dwd, wd.size() * 2); cudaMalloc((void**) &dwu, wu.size() * 2); cudaMalloc((void**) &dwi, wi.size() * 2); + cudaMemcpy(dbo, bo.data(), bo.size() * 4, cudaMemcpyHostToDevice); + cudaMemcpy(dinj, inj.data(), inj.size() * 4, cudaMemcpyHostToDevice); + cudaMemcpy(dwn, wn.data(), wn.size() * 4, cudaMemcpyHostToDevice); + cudaMemcpy(dwd, wd.data(), wd.size() * 2, cudaMemcpyHostToDevice); + cudaMemcpy(dwu, wu.data(), wu.size() * 2, cudaMemcpyHostToDevice); + cudaMemcpy(dwi, wi.data(), wi.size() * 2, cudaMemcpyHostToDevice); + double worst = 0.0; + int bad_t = 0, timeouts = 0; + // 0: the read agrees with the default read; 1: a barrier timed out (not resident); 2: wrong or a device error + auto check = [&](int T) -> int { + FusedGrArgs a[kFusedGrMaxT]; + for (int t = 0; t < T; ++t) { + a[t] = FusedGrArgs{}; + a[t].R = dR + (size_t) t * D; a[t].R_out = dR + (size_t) t * D; a[t].apply = true; + a[t].bo_prev = dbo + (size_t) t * N; a[t].inj_prev = dinj + (size_t) t * HC; + a[t].w_norm = dwn; a[t].w_down = dwd; a[t].w_up = dwu; a[t].w_inject = dwi; a[t].eps = 1e-6f; + a[t].lo = dlo + (size_t) t * LR; a[t].rs = drs + (size_t) t * HC; + a[t].inject_out = dio + (size_t) t * HC; a[t].mixed = dmix + (size_t) t * N; + } + std::vector out[2]; + for (int which = 0; which < 2; ++which) { + cudaMemcpy(dR, R.data(), R.size() * 4, cudaMemcpyHostToDevice); + cudaMemset(dmix, 0xff, (size_t) TM * N * 4); + cudaMemset(dio, 0xff, (size_t) TM * HC * 4); + cudaDeviceSynchronize(); + if (which == 0) fused_gr_read_multi(a, T, dxn, nullptr); + else hcp::launch(a, T, st, nullptr, hcp::kTicksCheck); + if (cudaDeviceSynchronize() != cudaSuccess) { cudaGetLastError(); return 2; } + if (which == 1) { + unsigned abort_word = 0; + cudaMemcpy(&abort_word, st.bar + 48, sizeof abort_word, cudaMemcpyDeviceToHost); + if (abort_word != 0u) { + cudaMemset(st.bar, 0, 64 * sizeof(unsigned)); + cudaDeviceSynchronize(); + return 1; + } + } + out[which].resize((size_t) T * (N + HC + D)); + cudaMemcpy(out[which].data(), dmix, (size_t) T * N * 4, cudaMemcpyDeviceToHost); + cudaMemcpy(out[which].data() + (size_t) T * N, dio, (size_t) T * HC * 4, cudaMemcpyDeviceToHost); + cudaMemcpy(out[which].data() + (size_t) T * (N + HC), dR, (size_t) T * D * 4, cudaMemcpyDeviceToHost); + } + double mref = 0.0, md = 0.0; + bool finite = true; + for (size_t i = 0; i < out[0].size(); ++i) { + finite = finite && std::isfinite(out[1][i]); + mref = std::fmax(mref, std::fabs((double) out[0][i])); + md = std::fmax(md, std::fabs((double) out[1][i] - out[0][i])); + } + const double rel = md / (mref > 0 ? mref : 1.0); + worst = std::fmax(worst, rel); + return finite && rel < 1e-4 ? 0 : 2; + }; + int max_t = 0; + for (int T = 1; T <= kFusedGrMaxT && ok; ++T) { + const int r = check(T); + if (r == 1) ++timeouts; else if (r == 2) { bad_t = T; ok = false; } + if (r != 0) break; + max_t = T; + } + cudaFree(dR); cudaFree(dbo); cudaFree(dinj); cudaFree(dwn); cudaFree(dxn); cudaFree(dlo); cudaFree(drs); + cudaFree(dio); cudaFree(dmix); cudaFree(dwd); cudaFree(dwu); cudaFree(dwi); + cudaMemset(st.bar, 0, 64 * sizeof(unsigned)); + cudaDeviceSynchronize(); + cudaGetLastError(); + if (!ok) { + std::fprintf(stderr, "strata hc: CUDA%d: STRATA_HC_PERSIST=1 is off here: the check failed at %d tokens " + "(max relative difference %.3g)\n", dev, bad_t, worst); + return; + } + if (max_t == 0) { + std::fprintf(stderr, "strata hc: CUDA%d: STRATA_HC_PERSIST=1 is off here: 80 blocks are not resident at once on %d " + "multiprocessors (the check timed out)\n", dev, mp); + return; + } + st.max_t = max_t; + std::fprintf(stderr, "strata hc: CUDA%d: STRATA_HC_PERSIST=1: the verifier's hyper-connection read runs as one " + "persistent kernel (80 blocks on %d multiprocessors, up to %d tokens; %d token counts timed out in " + "the check; checked against the default read, max relative difference %.2g)\n", dev, mp, max_t, + timeouts, worst); +} + +bool fused_gr_read_persist(const FusedGrArgs* a, int n_tok, void* stream) { + if (!hcp::env_on() || n_tok < 1) return false; + int dev = 0; + cudaGetDevice(&dev); + if (dev < 0 || dev >= 64) return false; + const hcp::DevState& st = hcp::g_dev[dev]; + if (n_tok > st.max_t) return false; + if (a[0].q8_down != nullptr || a[0].q8_up != nullptr) return false; // STRATA_HC_Q8: the default read + for (int t = 0; t < n_tok; ++t) + if (a[t].q8_mixed != nullptr) return false; // STRATA_QFUSE: the default read + hcp::launch(a, n_tok, st, (cudaStream_t) stream, hcp::kTicksRun); + return true; +} +#else +void fused_gr_persist_init() {} +bool fused_gr_read_persist(const FusedGrArgs*, int, void*) { return false; } +#endif + } // namespace strata::kernels diff --git a/src/kernels/cuda/qsa_prompt_attn.cu b/src/kernels/cuda/qsa_prompt_attn.cu index 43bc917c..06ed48c9 100644 --- a/src/kernels/cuda/qsa_prompt_attn.cu +++ b/src/kernels/cuda/qsa_prompt_attn.cu @@ -1848,57 +1848,77 @@ __global__ void __launch_bounds__(THREADS) prompt_attn_wmma_kernel(const float* for (int j = 0; j < 4; ++j) acc[j] = wf8{0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f}; const int n_chunks = (n + WCH - 1) / WCH; - for (int ci = 0; ci < n_chunks; ++ci) { + // chunk ci's cell for this lane (lane = cell index): its pool row, or -1 (past the selection, or a block the KV + // streaming left non-resident: masked as in the decode kernel) + auto row_of = [&](int ci) -> long long { const int c0 = ci * WCH; - // this lane's cell of the chunk (lane = cell index): its pool row, or -1 (past the selection, or a block the - // KV streaming left non-resident: masked as in the decode kernel) - long long myrow = -1; + long long r = -1; if (c0 + lane < n) { const int cell = __ldg(ids + c0 + lane); const long long page = (long long) __ldg(p.page_table + cell / page_size); - if (page >= 0) myrow = (page * n_kv_heads + kvh) * page_size + (cell % page_size); + if (page >= 0) r = (page * n_kv_heads + kvh) * page_size + (cell % page_size); } - // stage this wave's V slice of the chunk (64 bytes of each row) and the V scale; the K fragments come straight - // from global memory (8 consecutive codes per lane) - { - uint4 v0 = make_uint4(0, 0, 0, 0), v1 = v0, v2 = v0, v3 = v0; - float vsc = 0.0f; - if (myrow >= 0) { - const uint4* src = reinterpret_cast(p.v_q + myrow * HD + dim0); - v0 = __ldg(src); v1 = __ldg(src + 1); v2 = __ldg(src + 2); v3 = __ldg(src + 3); - vsc = __half2float(__ushort_as_half(__ldg(p.v_scale + myrow * (HD / KV_Q8_GROUP) + warp))); - } - uint4* dst = reinterpret_cast(&S.v[warp][lane][0]); - dst[0] = v0; dst[1] = v1; dst[2] = v2; dst[3] = v3; - S.vs[warp][lane] = vsc; - if (warp == 0) S.valid[lane] = myrow >= 0; + return r; + }; + // a chunk's global reads: this wave's V slice (64 bytes of each row) and V scale, and the K fragments (8 or 16 + // consecutive codes per lane) and K scales of its two 16-cell tiles + struct Chunk { + long long row; + uint4 v[4]; + float vsc, ksc[2]; + uint32_t kx[2][4][PA_KL / 4]; + }; + auto fetch = [&](long long row, Chunk& d) { + d.row = row; + d.v[0] = d.v[1] = d.v[2] = d.v[3] = make_uint4(0, 0, 0, 0); + d.vsc = 0.0f; + if (row >= 0) { + const uint4* src = reinterpret_cast(p.v_q + row * HD + dim0); + d.v[0] = __ldg(src); d.v[1] = __ldg(src + 1); d.v[2] = __ldg(src + 2); d.v[3] = __ldg(src + 3); + d.vsc = __half2float(__ushort_as_half(__ldg(p.v_scale + row * (HD / KV_Q8_GROUP) + warp))); } - // q.k over this wave's 64 dims for two 16-cell tiles, times the cell's K scale for this group #pragma unroll for (int nt = 0; nt < 2; ++nt) { - const long long rr = __shfl(myrow, nt * 16 + col); - wf8 s = wf8{0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f}; - float ksc = 0.0f; - if (rr >= 0) ksc = __half2float(__ushort_as_half(__ldg(p.k_scale + rr * (HD / KV_Q8_GROUP) + warp))); + const long long rr = __shfl(row, nt * 16 + col); + d.ksc[nt] = 0.0f; + if (rr >= 0) d.ksc[nt] = __half2float(__ushort_as_half(__ldg(p.k_scale + rr * (HD / KV_Q8_GROUP) + warp))); #pragma unroll for (int kk = 0; kk < 4; ++kk) { - uint32_t kx[PA_KL / 4] = {}; +#pragma unroll + for (int i = 0; i < PA_KL / 4; ++i) d.kx[nt][kk][i] = 0; if (rr >= 0) { const uint32_t* src = reinterpret_cast(p.k_q + rr * HD + dim0 + kk * 16 + PA_KOFF(half)); #if STRATA_PA_GFX11 const uint4 v = __ldg(reinterpret_cast(src)); - kx[0] = v.x; kx[1] = v.y; kx[2] = v.z; kx[3] = v.w; + d.kx[nt][kk][0] = v.x; d.kx[nt][kk][1] = v.y; d.kx[nt][kk][2] = v.z; d.kx[nt][kk][3] = v.w; #else const uint2 v = __ldg(reinterpret_cast(src)); - kx[0] = v.x; kx[1] = v.y; + d.kx[nt][kk][0] = v.x; d.kx[nt][kk][1] = v.y; #endif } - const wh8 b = i8_to_h(kx); + } + } + }; + auto chunk = [&](const Chunk& cd) { + // stage this wave's V slice and scale + { + uint4* dst = reinterpret_cast(&S.v[warp][lane][0]); + dst[0] = cd.v[0]; dst[1] = cd.v[1]; dst[2] = cd.v[2]; dst[3] = cd.v[3]; + S.vs[warp][lane] = cd.vsc; + if (warp == 0) S.valid[lane] = cd.row >= 0; + } + // q.k over this wave's 64 dims for two 16-cell tiles, times the cell's K scale for this group +#pragma unroll + for (int nt = 0; nt < 2; ++nt) { + wf8 s = wf8{0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f}; +#pragma unroll + for (int kk = 0; kk < 4; ++kk) { + const wh8 b = i8_to_h(cd.kx[nt][kk]); s = wmma_f16(qh[kk], b, s); if constexpr (SPLIT) s = wmma_f16(ql[kk], b, s); } #pragma unroll - for (int i = 0; i < 8; ++i) S.part[warp][PA_ROW(i, half)][nt * 16 + col] = s[i] * ksc; + for (int i = 0; i < 8; ++i) S.part[warp][PA_ROW(i, half)][nt * 16 + col] = s[i] * cd.ksc[nt]; } __syncthreads(); // online softmax over the four groups' sum (fixed order): row t/8, 4 cells per thread @@ -1974,6 +1994,13 @@ __global__ void __launch_bounds__(THREADS) prompt_attn_wmma_kernel(const float* } // no barrier here: `v`/`vs` are this wave's own, and `p`/`alpha`/`valid` are rewritten only after the next // chunk's first barrier (which every wave reaches after its p.v) + }; + // all of a chunk's reads are issued before its compute (they were interleaved with the q.k WMMAs and the V + // staging): 32K context, 2,048 queries, gfx1151, STRATA_PA_FAST=1: 12.49 -> 11.27 ms; the same bits + for (int ci = 0; ci < n_chunks; ++ci) { + Chunk d; + fetch(row_of(ci), d); + chunk(d); } float inv[8]; #pragma unroll diff --git a/src/kernels/cuda/qsa_scores_gfx1100_test.cu b/src/kernels/cuda/qsa_scores_gfx1100_test.cu new file mode 100644 index 00000000..fdc56877 --- /dev/null +++ b/src/kernels/cuda/qsa_scores_gfx1100_test.cu @@ -0,0 +1,32 @@ +// Test-only translation unit: production scorer plus the unchanged warp dispatch. +// The production library does not compile this reference wrapper. +#include "qsa_select.cu" + +namespace strata::kernels { +void qsa_block_scores_reference(const float* pooled, const float* dead, const float* q_idx, const int32_t* steps, int64_t nq, + int64_t max_blocks, const QsaShapes& s, float* scores, void* stream, int64_t active_blocks) { + if (nq <= 0) return; + if (s.idx_dim != IDX_DIM || s.idx_n_head != IDX_HEADS || s.idx_block != R || nq > 65535) { + std::fprintf(stderr, "qsa_block_scores: unsupported indexer geometry\n"); + std::exit(1); + } + // a block past a query's n_bid returns at once: the grid need only reach the batch's largest n_bid (C-1) + static const bool multi = [] { const char* v = std::getenv("STRATA_SCORES_MULTI"); return v == nullptr || std::atoi(v) != 0; }(); + if (multi && nq <= MQ && active_blocks <= 0) { // no active count: decode (captured or not) and prefill's pooled16 + // STRATA_QSA_EARLY_EXIT=0 keeps the old staging (every CTA loads the queries first); the scores are the same bits + static const bool early = [] { const char* v = std::getenv("STRATA_QSA_EARLY_EXIT"); return v == nullptr || std::atoi(v) != 0; }(); + block_scores_multi_kernel<<<256, SCORE_WARPS * 32, 0, (cudaStream_t) stream>>>(pooled, dead, q_idx, steps, (int) nq, + max_blocks, scores, early); + const cudaError_t e = cudaGetLastError(); + if (e != cudaSuccess) { std::fprintf(stderr, "qsa_block_scores multi: %s\n", cudaGetErrorString(e)); std::exit(1); } + return; + } + const int64_t reach = active_blocks > 0 && active_blocks < max_blocks ? active_blocks : max_blocks; + const dim3 grid((unsigned) ((reach + SCORE_WARPS - 1) / SCORE_WARPS), (unsigned) nq); + block_scores_kernel<<>>(pooled, dead, q_idx, steps, max_blocks, + scores); + const cudaError_t e = cudaGetLastError(); + if (e != cudaSuccess) { std::fprintf(stderr, "qsa_block_scores: %s\n", cudaGetErrorString(e)); std::exit(1); } +} + +} diff --git a/src/kernels/cuda/qsa_select.cu b/src/kernels/cuda/qsa_select.cu index 02e6c750..75bd1fa6 100644 --- a/src/kernels/cuda/qsa_select.cu +++ b/src/kernels/cuda/qsa_select.cu @@ -705,13 +705,14 @@ __global__ void __launch_bounds__(TK_T) block_topk_reg_kernel(const float* __res } } -#if !defined(__HIPCC__) // ---- a query with more blocks than the register kernel holds (contexts past 4 * 1024 * TK_PER cells): the register // kernel's threads, per-warp histograms and warp scans, with each key read from memory again on every pass. A // histogram has no order, so on the four radix passes thread t reads blocks t, t + 1024, ...: a warp reads 32 // neighbours at a time. The cells are emitted ascending in the order (warp, row, lane): warp w holds the `per` rows // of 32 consecutive blocks from block w * 32 * per. block_topk_kernel's selection rule (radix threshold, ties to the // lowest index): identical ids. +// campaign3: also compiled on HIP (gfx11: plain shared/atomic code, no sm_90 features; the dispatch still needs +// reach > fit, i.e. the deep contexts where the ref radix was the only option on AMD). __global__ void __launch_bounds__(TK_T) block_topk_wide_kernel(const float* __restrict__ scores, const int32_t* __restrict__ steps, int64_t max_blocks, int64_t cap, int32_t* __restrict__ ids) { @@ -822,7 +823,6 @@ __global__ void __launch_bounds__(TK_T) block_topk_wide_kernel(const float* __re run_sel += __shfl_sync(0xffffffffu, ps, 31); } } -#endif // Block scores with every key block read ONCE for all of a call's queries (block_scores_kernel's grid is @@ -995,6 +995,106 @@ __global__ void __launch_bounds__(SCORE_WARPS * 32) block_scores_rows_kernel(con } } +#if defined(__HIPCC__) +// Optional gfx1100 port of PR1825 (14bf3215): same FP32 expression and reduction tree. +// Decode and the original top-k stay unchanged. No additional persistent weight/state allocation. +constexpr int TS_Q = 64; // queries per CTA (8 per wave, four lanes per query) +constexpr int TS_KB = 32; // key blocks per shared-memory tile +constexpr int TS_BR = 512; // key blocks per CTA + +__device__ __forceinline__ float ts_part(const float4 k4, const float4 q4) { + return k4.x * q4.x + k4.y * q4.y + k4.z * q4.z + k4.w * q4.w; // block_scores_kernel's per-lane expression +} + +__global__ void __launch_bounds__(256, 1) block_scores_thread_kernel(const float* __restrict__ pooled, + const float* __restrict__ q_idx, + const int32_t* __restrict__ steps, int64_t nq, + int64_t max_blocks, int64_t reach, + float* __restrict__ out) { + __shared__ __align__(16) float4 ks[TS_KB][IDX_DIM / 4]; + __shared__ float so[TS_Q][TS_KB + 1]; + __shared__ int64_t s_nbid[TS_Q]; + // Four lanes per query, lane j (0..3) one quarter of the tree for all four heads: the partials c[j] of lane 0's + // xor-shuffle sum combine groups j, j+16, j+8, j+24, j+4, j+20, j+12, j+28, and only then do the quarters meet + // (c0 + c2, c1 + c3, then their sum) - two shuffles here. A key load now feeds four heads: four times fewer + // shared-memory loads per FMA. The MIO-pipe motivation was measured by PR1825 on NVIDIA. + constexpr int QG[8] = {0, 16, 8, 24, 4, 20, 12, 28}; + const int t = threadIdx.x, lane = t & 31; + const int ql = (t >> 5) * 8 + (lane >> 2), j4 = lane & 3; // this lane's query (in the CTA) and quarter + const int64_t q0 = (int64_t) blockIdx.y * TS_Q, qi = q0 + ql; + if (t < TS_Q) s_nbid[t] = q0 + t < nq ? steps[(q0 + t) * kStepCount + kStepNBid] : -1; + float4 qv[IDX_HEADS][8]; + { + const float4* src = reinterpret_cast(q_idx + (qi < nq ? qi : 0) * IDX_HEADS * IDX_DIM); +#pragma unroll + for (int h = 0; h < IDX_HEADS; ++h) +#pragma unroll + for (int m = 0; m < 8; ++m) qv[h][m] = src[h * (IDX_DIM / 4) + j4 + QG[m]]; + } + __syncthreads(); + int64_t top = -1; // the largest n_bid of the CTA's queries: blocks at or past it are never written here + for (int i = 0; i < TS_Q; ++i) top = s_nbid[i] > top ? s_nbid[i] : top; + const int64_t b_lo = (int64_t) blockIdx.x * TS_BR; + int64_t b_hi = b_lo + TS_BR; + if (b_hi > reach) b_hi = reach; + if (b_hi > top) b_hi = top; + if (b_hi > max_blocks) b_hi = max_blocks; + for (int64_t b0 = b_lo; b0 < b_hi; b0 += TS_KB) { + const int nb = (int) (b_hi - b0 < TS_KB ? b_hi - b0 : TS_KB); + __syncthreads(); // the previous tile's reads of ks and so are done + for (int i = t; i < nb * (IDX_DIM / 4); i += blockDim.x) + ks[i / (IDX_DIM / 4)][i % (IDX_DIM / 4)] = reinterpret_cast(pooled + (b0 + i / (IDX_DIM / 4)) * IDX_DIM)[i % (IDX_DIM / 4)]; + __syncthreads(); + for (int j = 0; j < nb; ++j) { + float4 kk[8]; +#pragma unroll + for (int m = 0; m < 8; ++m) kk[m] = ks[j][j4 + QG[m]]; + float e[IDX_HEADS]; +#pragma unroll + for (int h = 0; h < IDX_HEADS; ++h) { + const float c = ((ts_part(kk[0], qv[h][0]) + ts_part(kk[1], qv[h][1])) + + (ts_part(kk[2], qv[h][2]) + ts_part(kk[3], qv[h][3]))) + + ((ts_part(kk[4], qv[h][4]) + ts_part(kk[5], qv[h][5])) + + (ts_part(kk[6], qv[h][6]) + ts_part(kk[7], qv[h][7]))); + const float d = c + __shfl_xor_sync(0xffffffffu, c, 2); // lane 0: c0 + c2, lane 1: c1 + c3 + e[h] = d + __shfl_xor_sync(0xffffffffu, d, 1); // lane 0: (c0 + c2) + (c1 + c3) + } + if (j4 == 0) { + float score = 0.0f; +#pragma unroll + for (int h = 0; h < IDX_HEADS; ++h) score += e[h] > 0.0f ? e[h] : 0.0f; + so[ql][j] = score; + } + } + __syncthreads(); + for (int i = t; i < TS_Q * nb; i += blockDim.x) { + const int q = i / nb, j = i % nb; + if (b0 + j < s_nbid[q]) out[(q0 + q) * max_blocks + b0 + j] = so[q][j]; + } + } +} + +// The exact scorer runs on gfx1100 (the PR's own card) when STRATA_SCORES_THREAD=1, and on gfx12 (RDNA4) unless STRATA_SCORES_THREAD=0: +// there it is bitwise equal to the warp scorer on an R9700 (qsa_scores_gfx1100_parity --full, 35 cases; exact_pp residual dumps at 70K and +// 131K tokens) and 3.6-4.4x faster in the scorer stage, +8% (131K) to +15% (230K) on a prompt read. Other wave32 parts have no measurement. +// Returns 0 (not offered), 1 (gfx1100: only on request), 2 (gfx12: the default). +int scores_thread_arch() { + int device = -1; + if (cudaGetDevice(&device) != cudaSuccess) { cudaGetLastError(); return 0; } + static thread_local int cached_device = -1; + static thread_local int arch = 0; + if (device != cached_device) { + cudaDeviceProp properties{}; + arch = 0; + if (cudaGetDeviceProperties(&properties, device) == cudaSuccess) + arch = gfx_arch_is_gfx12(properties.gcnArchName) ? 2 : gfx_arch_is(properties.gcnArchName, "gfx1100") ? 1 : 0; + cached_device = device; + cudaGetLastError(); + } + return arch; +} +#endif + #if !defined(__HIPCC__) // ---- the decode top-k on a thread-block cluster (sm_90+; S19). One CTA per query (block_topk_reg_kernel, or // block_topk_kernel above 33,792 blocks: a --max-context over ~135K) makes four radix passes and two scans over up to @@ -1268,6 +1368,35 @@ void qsa_block_scores(const float* pooled, const float* dead, const float* q_idx return; } const int64_t reach = active_blocks > 0 && active_blocks < max_blocks ? active_blocks : max_blocks; +#if defined(__HIPCC__) + // STRATA_SCORES_THREAD: 1 = on (gfx1100, gfx12), 0 = off, unset = on for gfx12 only (gfx1100: off, nothing measured here) + static const int thread_env = [] { + const char* value = std::getenv("STRATA_SCORES_THREAD"); + return value == nullptr ? -1 : (std::atoi(value) == 1 ? 1 : 0); + }(); + // The bound is the ACTUAL live extent. A reserved 256K context never enables this by itself. + if (thread_env != 0 && active_blocks >= 16385 && active_blocks <= max_blocks && nq >= 64 && + (scores_thread_arch() == 2 || (thread_env == 1 && scores_thread_arch() == 1))) { + static thread_local bool logged = false; + if (!logged && (thread_env == -1 || std::getenv("STRATA_SCORES_THREAD_TRACE"))) { + std::fprintf(stderr, "qsa exact thread: the prompt's block scorer runs as the four-lanes-per-query kernel (nq=%lld active_blocks=%lld " + "capacity=%lld; the same scores bit for bit; STRATA_SCORES_THREAD=0 turns it off)\n", + (long long)nq, (long long)active_blocks, (long long)max_blocks); + logged = true; + } + const dim3 tgrid((unsigned)((reach + TS_BR - 1) / TS_BR), (unsigned)((nq + TS_Q - 1) / TS_Q)); + block_scores_thread_kernel<<>>(pooled, q_idx, steps, nq, + max_blocks, reach, scores); + block_scores_tail_kernel<<<(unsigned)nq, 32, 0, (cudaStream_t)stream>>>(dead, q_idx, steps, + max_blocks, scores); + const cudaError_t error = cudaGetLastError(); + if (error != cudaSuccess) { + std::fprintf(stderr, "qsa exact thread: %s\n", cudaGetErrorString(error)); + std::exit(1); + } + return; + } +#endif const dim3 grid((unsigned) ((reach + SCORE_WARPS - 1) / SCORE_WARPS), (unsigned) nq); block_scores_kernel<<>>(pooled, dead, q_idx, steps, max_blocks, scores); @@ -1523,7 +1652,8 @@ void qsa_block_topk(const float* scores, const int32_t* steps, int64_t nq, int64 return v != nullptr ? (int64_t) std::atoll(v) : (int64_t) 7168; }(); const bool too_small = counted && reach < kRegMinBlocks; - if (old || too_small || reach > fit) { + // campaign3: `reach > fit` no longer forces the ref radix - the wide kernel below takes it (same ids). + if (old || too_small) { #else constexpr int64_t kWideMinBlocks = 4608; // RTX 3060: a prompt batch below ~18K cells is faster on the ref const bool too_small = reach > fit && active_blocks > 0 && active_blocks < kWideMinBlocks; @@ -1536,10 +1666,11 @@ void qsa_block_topk(const float* scores, const int32_t* steps, int64_t nq, int64 std::fprintf(stderr, "qsa_block_topk: unsupported geometry or cap\n"); std::exit(1); } -#if !defined(__HIPCC__) // Turing prefill (the `counted` bound) above ~90K cells (22,528 blocks): the wide kernel, which reads the keys // coalesced, instead of the register kernel's uncoalesced per-thread runs (PR #743: 131K, 1.03 -> 0.75 ms); the // same ids. STRATA_TOPK_STREAM=0 restores the register kernel there. + // campaign3: on HIP too (was CUDA-only; gfx11 has no sm_90 cluster path and fell to the ref radix past the + // register kernel's reach - the deep-decode top-k cost). Same ids as the ref kernel. static const bool turing_wide = [] { const char* v = std::getenv("STRATA_TOPK_STREAM"); return v == nullptr || v[0] != '0'; @@ -1547,7 +1678,6 @@ void qsa_block_topk(const float* scores, const int32_t* steps, int64_t nq, int64 if (reach > fit || (turing_wide && counted && reach > 22528)) // past the register kernel's reach, or Turing's band block_topk_wide_kernel<<<(unsigned) nq, TK_T, 0, (cudaStream_t) stream>>>(scores, steps, max_blocks, cap, ids); else -#endif if (reach <= (int64_t) TK_T * TK_PER) block_topk_reg_kernel<<<(unsigned) nq, TK_T, 0, (cudaStream_t) stream>>>(scores, steps, max_blocks, cap, ids); else diff --git a/src/kernels/hc_persist_parity.cpp b/src/kernels/hc_persist_parity.cpp new file mode 100644 index 00000000..0e630060 --- /dev/null +++ b/src/kernels/hc_persist_parity.cpp @@ -0,0 +1,151 @@ +// src/kernels/hc_persist_parity.cpp - the STRATA_HC_PERSIST=1 hyper-connection read (one persistent kernel) against the +// default multi read (fused_gr_read_multi). +// +// Real geometry (n_embd 2560, hc 4, hc_lr 320), every T = 1..8, the pending write applied and the inject rows on, as the +// verifier calls it. The persistent read sums in another order, so it is bounded, not bitwise: every output (the mixed +// row, the inject outputs, the written R) must be finite and within 1e-4 of the default read relative to its largest +// magnitude, and two runs of the persistent read must agree bit for bit. Where the card does not hold the 80 blocks at +// once (or on CUDA, where the read is not built) the read reports that it did not run and the test passes as a skip. +// `--off`: with STRATA_HC_PERSIST unset the persistent read must never run (the default path is untouched). +// GPU, synthetic, no model. +#include "strata/kernels/fused_gr.hpp" + +#include + +#include +#include +#include +#include +#include +#include +#include + +namespace k = strata::kernels; + +namespace { +constexpr int N = 2560, HC = 4, D = N * HC, LR = 320, TM = 8; +void ck(cudaError_t e, const char* w) { + if (e != cudaSuccess) { + std::fprintf(stderr, "%s: %s\n", w, cudaGetErrorString(e)); + std::exit(2); + } +} +uint16_t bf16(float x) { + uint32_t u; + std::memcpy(&u, &x, 4); + return (uint16_t) ((u + 0x7fff + ((u >> 16) & 1)) >> 16); +} +template +T* up(const std::vector& h) { + void* p = nullptr; + ck(cudaMalloc(&p, h.size() * sizeof(T)), "malloc"); + ck(cudaMemcpy(p, h.data(), h.size() * sizeof(T), cudaMemcpyHostToDevice), "h2d"); + return (T*) p; +} +template +T* dev(size_t n) { + void* p = nullptr; + ck(cudaMalloc(&p, n * sizeof(T)), "malloc"); + return (T*) p; +} +} // namespace + +int main(int argc, char** argv) { + const bool off = argc > 1 && std::strcmp(argv[1], "--off") == 0; + if (off) unsetenv("STRATA_HC_PERSIST"); + else setenv("STRATA_HC_PERSIST", "1", 1); + k::fused_gr_check(); + k::fused_gr_persist_init(); + + std::mt19937 rng(7); + std::normal_distribution nd(0.f, 1.f); + std::vector R((size_t) TM * D), bo((size_t) TM * N), inj((size_t) TM * HC), wn(D); + for (auto& x : R) x = nd(rng); + for (auto& x : bo) x = 0.5f * nd(rng); + for (auto& x : inj) x = nd(rng); + for (auto& x : wn) x = 1.f + 0.3f * nd(rng); + std::vector wd((size_t) LR * D), wu((size_t) D * LR), wi((size_t) HC * D); + for (auto& x : wd) x = bf16(0.02f * nd(rng)); + for (auto& x : wu) x = bf16(0.05f * nd(rng)); + for (auto& x : wi) x = bf16(0.02f * nd(rng)); + float* dR = dev(R.size()); + float* dbo = up(bo); + float* dinj = up(inj); + float* dwn = up(wn); + uint16_t* dwd = up(wd); + uint16_t* dwu = up(wu); + uint16_t* dwi = up(wi); + float* dxn = dev((size_t) TM * D); + float* dlo = dev((size_t) TM * LR); + float* drs = dev((size_t) TM * HC); + float* dio = dev((size_t) TM * HC); + float* dmix = dev((size_t) TM * N); + + int bad = 0, ran = 0; + for (int T = 1; T <= TM; ++T) { + k::FusedGrArgs a[TM]; + for (int t = 0; t < T; ++t) { + a[t] = k::FusedGrArgs{}; + a[t].R = dR + (size_t) t * D; + a[t].R_out = dR + (size_t) t * D; + a[t].apply = true; + a[t].bo_prev = dbo + (size_t) t * N; + a[t].inj_prev = dinj + (size_t) t * HC; + a[t].w_norm = dwn; + a[t].w_down = dwd; + a[t].w_up = dwu; + a[t].w_inject = dwi; + a[t].eps = 1e-6f; + a[t].lo = dlo + (size_t) t * LR; + a[t].rs = drs + (size_t) t * HC; + a[t].inject_out = dio + (size_t) t * HC; + a[t].mixed = dmix + (size_t) t * N; + } + // 0: the default read, 1 and 2: the persistent read twice; each output is mixed | inject | R + std::vector out[3]; + bool used = true; + for (int w = 0; w < 3; ++w) { + ck(cudaMemcpy(dR, R.data(), R.size() * 4, cudaMemcpyHostToDevice), "R"); + ck(cudaMemset(dmix, 0xff, (size_t) TM * N * 4), "mix"); + ck(cudaMemset(dio, 0xff, (size_t) TM * HC * 4), "io"); + ck(cudaDeviceSynchronize(), "sync"); + if (w == 0) k::fused_gr_read_multi(a, T, dxn, nullptr); + else used = k::fused_gr_read_persist(a, T, nullptr) && used; + ck(cudaDeviceSynchronize(), "read"); + out[w].resize((size_t) T * (N + HC + D)); + ck(cudaMemcpy(out[w].data(), dmix, (size_t) T * N * 4, cudaMemcpyDeviceToHost), "d2h mix"); + ck(cudaMemcpy(out[w].data() + (size_t) T * N, dio, (size_t) T * HC * 4, cudaMemcpyDeviceToHost), "d2h io"); + ck(cudaMemcpy(out[w].data() + (size_t) T * (N + HC), dR, (size_t) T * D * 4, cudaMemcpyDeviceToHost), "d2h R"); + if (w == 1 && !used) break; + } + if (off) { + if (used) { + std::printf("T=%d: the persistent read ran with STRATA_HC_PERSIST unset FAIL\n", T); + ++bad; + } + continue; + } + if (!used) { + std::printf("T=%d: the persistent read did not run on this card (skip)\n", T); + continue; + } + ++ran; + double mref = 0.0, md = 0.0; + bool finite = true; + for (size_t i = 0; i < out[0].size(); ++i) { + finite = finite && std::isfinite(out[1][i]); + mref = std::fmax(mref, std::fabs((double) out[0][i])); + md = std::fmax(md, std::fabs((double) out[1][i] - out[0][i])); + } + const double rel = md / (mref > 0 ? mref : 1.0); + const bool same = std::memcmp(out[1].data(), out[2].data(), out[1].size() * 4) == 0; + const bool ok = finite && rel < 1e-4 && same; + std::printf("T=%d: max relative difference %.3g against the default read, %s, two runs %s %s\n", T, rel, + finite ? "finite" : "NON-FINITE", same ? "bitwise equal" : "DIFFER", ok ? "ok" : "FAIL"); + if (!ok) ++bad; + } + if (off) std::printf("%s: STRATA_HC_PERSIST unset, the persistent read never ran\n", bad ? "FAIL" : "PASS"); + else if (ran == 0) std::printf("SKIP: the persistent read is not used on this card\n"); + else std::printf("%s: %d token counts checked\n", bad ? "FAIL" : "PASS", ran); + return bad ? 1 : 0; +} diff --git a/src/kernels/qsa_scores_gfx1100_parity.cpp b/src/kernels/qsa_scores_gfx1100_parity.cpp new file mode 100644 index 00000000..00832d97 --- /dev/null +++ b/src/kernels/qsa_scores_gfx1100_parity.cpp @@ -0,0 +1,185 @@ +// GPU contract test for the optional gfx1100 port of PR1825. Synthetic, no model or coding score. +#include "strata/kernels/qsa.hpp" +#include "strata/kernels/qsa_select.hpp" +#include "strata/kernels/gfx_arch.hpp" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace strata::kernels { +// Test-only host wrapper copied from the unchanged baseline; both arms receive the SAME active bound. +void qsa_block_scores_reference(const float*, const float*, const float*, const int32_t*, int64_t, + int64_t, const QsaShapes&, float*, void*, int64_t); +} +namespace k = strata::kernels; +namespace { +void ck(cudaError_t e) { + if (e != cudaSuccess) { std::fprintf(stderr, "HIP: %s\n", cudaGetErrorString(e)); std::exit(2); } +} +void require(bool ok, const char* why) { + if (!ok) { std::fprintf(stderr, "FAIL: %s\n", why); std::exit(1); } +} +struct Buffer { + void* p = nullptr; size_t bytes; + explicit Buffer(size_t n): bytes(n) { ck(cudaMalloc(&p, n + 64)); ck(cudaMemset(p, 0xd3, n + 64)); } + ~Buffer() { ck(cudaFree(p)); } + template T* as() { return static_cast(p); } + void guard() { + unsigned char v[64]; + ck(cudaMemcpy(v, static_cast(p) + bytes, 64, cudaMemcpyDeviceToHost)); + for (auto c: v) require(c == 0xd3, "allocation guard modified"); + } +}; +struct Case { int64_t context, queries, capacity; int mode; int bound; bool timing; }; +int cases_done = 0, engaged = 0; +uint64_t scores_checked = 0, ids_checked = 0; + +void check(Case c) { + const auto s = k::qsa_real_shapes(); + const int64_t nb = c.capacity / s.idx_block + 2, nq = c.queries; + const int64_t active = c.context / s.idx_block + 1; + const int64_t bound = c.bound == 0 ? active : c.bound == 1 ? 0 : c.bound == 2 ? -1 : nb + 1; + const int64_t cap = k::qsa_selection_width(k::kTopkMaxCells, s); + std::mt19937 rng(91731 + (unsigned)c.context + 7*(unsigned)nq + 101*c.mode); + std::normal_distribution nd(0, 1); + std::uniform_int_distribution expo(-20, 20), small(-3, 3); + uint64_t sequence = 0; + auto value = [&]() -> float { + ++sequence; + if (c.mode == 1) return sequence % 11 == 0 ? 0.f : std::ldexp(nd(rng), expo(rng)); + if (c.mode == 2) return (float)small(rng); + if (c.mode == 3) return sequence % 2 ? 0.f : -0.f; + if (c.mode == 4) { + if (sequence % 23 == 0) return std::numeric_limits::quiet_NaN(); + if (sequence % 29 == 0) return std::numeric_limits::infinity(); + if (sequence % 31 == 0) return -std::numeric_limits::infinity(); + } + if (c.mode == 5) return sequence % 4 < 2 ? std::ldexp(1.f, 20) : -std::ldexp(1.f, 20); + return nd(rng); + }; + std::vector pooled(nb*s.idx_dim), dead(s.idx_dim), q(nq*s.idx_n_head*s.idx_dim); + for (auto& v: pooled) v = value(); + for (auto& v: dead) v = value(); + for (auto& v: q) v = value(); + // Padding after the largest live block must never affect scores or selected IDs. + for (int64_t i = active * s.idx_dim; i < (int64_t)pooled.size(); ++i) + pooled[i] = std::numeric_limits::quiet_NaN(); + std::vector steps(nq*k::kStepCount); + for (int64_t i = 0; i < nq; ++i) { + auto* st = steps.data() + i*k::kStepCount; + const int64_t n = c.context - nq + i + 1; + st[k::kStepPos] = n-1; st[k::kStepNKv] = n; + st[k::kStepNBid] = n/s.idx_block; + st[k::kStepWidth] = k::qsa_selection_width(n, s); + } + Buffer p(pooled.size()*4), d(dead.size()*4), query(q.size()*4), step(steps.size()*4); + Buffer a(nq*nb*4), b(nq*nb*4), ia(nq*cap*4), ib(nq*cap*4); + ck(cudaMemcpy(p.p, pooled.data(), p.bytes, cudaMemcpyHostToDevice)); + ck(cudaMemcpy(d.p, dead.data(), d.bytes, cudaMemcpyHostToDevice)); + ck(cudaMemcpy(query.p, q.data(), query.bytes, cudaMemcpyHostToDevice)); + ck(cudaMemcpy(step.p, steps.data(), step.bytes, cudaMemcpyHostToDevice)); + auto reference = [&] { + k::qsa_block_scores_reference(p.as(), d.as(), query.as(), step.as(), + nq, nb, s, a.as(), nullptr, bound); + }; + auto candidate = [&] { + k::qsa_block_scores(p.as(), d.as(), query.as(), step.as(), + nq, nb, s, b.as(), nullptr, bound); + }; + ck(cudaMemset(a.p, 0xa5, a.bytes)); ck(cudaMemset(b.p, 0x5a, b.bytes)); + reference(); candidate(); ck(cudaDeviceSynchronize()); + std::vector av(nq*nb), bv(nq*nb); + ck(cudaMemcpy(av.data(), a.p, a.bytes, cudaMemcpyDeviceToHost)); + ck(cudaMemcpy(bv.data(), b.p, b.bytes, cudaMemcpyDeviceToHost)); + uint64_t checked = 0; + for (int64_t i = 0; i < nq; ++i) { + const int64_t last = steps[i*k::kStepCount+k::kStepNBid]; + for (int64_t j = 0; j < nb; ++j) { + const auto at = i*nb+j; + if (j <= last) { + if (av[at] != bv[at]) { + std::fprintf(stderr, "MISMATCH ctx=%lld nq=%lld mode=%d query=%lld block=%lld bits=%08x/%08x\n", + (long long)c.context, (long long)nq, c.mode, (long long)i, (long long)j, av[at], bv[at]); + require(false, "scores differ bitwise"); + } + ++checked; + } else { + require(av[at] == 0xa5a5a5a5 && bv[at] == 0x5a5a5a5a, "inactive score padding overwritten"); + } + } + } + ck(cudaMemset(ia.p, 0xff, ia.bytes)); ck(cudaMemset(ib.p, 0xff, ib.bytes)); + k::qsa_block_topk(a.as(), step.as(), nq, nb, cap, s, ia.as(), nullptr, bound); + k::qsa_block_topk(b.as(), step.as(), nq, nb, cap, s, ib.as(), nullptr, bound); + ck(cudaDeviceSynchronize()); + std::vector iav(nq*cap), ibv(nq*cap); + ck(cudaMemcpy(iav.data(), ia.p, ia.bytes, cudaMemcpyDeviceToHost)); + ck(cudaMemcpy(ibv.data(), ib.p, ib.bytes, cudaMemcpyDeviceToHost)); + require(iav == ibv, "selected IDs differ"); + for (int64_t i = 0; i < nq; ++i) + for (int64_t j = steps[i*k::kStepCount+k::kStepWidth]; j < cap; ++j) + require(iav[i*cap+j] == -1, "ID padding overwritten"); + for (auto* v: {&p, &d, &query, &step, &a, &b, &ia, &ib}) v->guard(); + const bool branch = std::getenv("STRATA_SCORES_THREAD") && + std::atoi(std::getenv("STRATA_SCORES_THREAD")) == 1 && bound >= 16385 && bound <= nb && nq >= 64; + std::printf("PASS ctx=%lld nq=%lld capacity=%lld mode=%d bound=%lld expected_thread=%d scores=%llu ids=%lld\n", + (long long)c.context, (long long)nq, (long long)c.capacity, c.mode, (long long)bound, + (int)branch, (unsigned long long)checked, (long long)(nq*cap)); + ++cases_done; engaged += branch; scores_checked += checked; ids_checked += nq*cap; + if (c.timing) { + // Same actual bound/capacity, warmed, interleaved ABBA. Events measure GPU execution, not host fixture setup. + for (int i = 0; i < 3; ++i) { reference(); candidate(); } + ck(cudaDeviceSynchronize()); + cudaEvent_t e0, e1; ck(cudaEventCreate(&e0)); ck(cudaEventCreate(&e1)); + float times[2][4]{}; + for (int batch = 0; batch < 4; ++batch) { + const int order[4] = {0,1,1,0}; + for (int v: order) { + ck(cudaEventRecord(e0)); + for (int rep = 0; rep < 5; ++rep) { if (v == 0) reference(); else candidate(); } + ck(cudaEventRecord(e1)); ck(cudaEventSynchronize(e1)); + float ms = 0; ck(cudaEventElapsedTime(&ms, e0, e1)); times[v][batch] += ms/10; + } + } + float ta=0, tb=0; + for (int i=0; i<4; ++i) { ta+=times[0][i]/4; tb+=times[1][i]/4; } + std::printf("TIMING ctx=%lld nq=%lld baseline_ms=%.6f candidate_ms=%.6f speedup=%.6f trials=4 repeats_per_trial=10\n", + (long long)c.context, (long long)nq, ta, tb, ta/tb); + ck(cudaEventDestroy(e0)); ck(cudaEventDestroy(e1)); + } +} +} // namespace + +int main(int argc, char** argv) { + int devices = 0; + if (cudaGetDeviceCount(&devices) != cudaSuccess || devices == 0) { std::puts("SKIP no GPU"); return 77; } + cudaDeviceProp properties{}; ck(cudaGetDeviceProperties(&properties, 0)); + if (!k::gfx_arch_is(properties.gcnArchName, "gfx1100") && !k::gfx_arch_is_gfx12(properties.gcnArchName)) { std::puts("SKIP requires gfx1100 or gfx12"); return 77; } + require(std::getenv("STRATA_SCORES_THREAD") && std::strcmp(std::getenv("STRATA_SCORES_THREAD"), "1") == 0, + "run with STRATA_SCORES_THREAD=1 so the candidate branch is tested"); + const bool full = argc > 1 && std::strcmp(argv[1], "--full") == 0; + for (int64_t n: {1,6,8,9,63,64,65,127,128,129,256}) + check({131075,n,262144,0,0,false}); + for (int64_t context: {65535,65536,65537,65538,65539,131072,262144}) + check({context,65,262144,0,0,false}); + for (int bound: {1,2,3}) check({131075,65,262144,0,bound,false}); + for (int mode: {1,2,3,4,5}) check({131075,129,262144,mode,0,false}); + check({131075,65,131075,0,0,false}); + if (full) { + for (int64_t context: {131072,131073,131074,131075}) check({context,256,262144,2,0,false}); + check({131072,256,262144,0,0,true}); + check({240000,256,262144,0,0,true}); + check({140000,1024,262144,0,0,true}); + check({240000,1024,262144,0,0,true}); + } + std::printf("QUALIFIED cases=%d expected_thread_cases=%d scores=%llu ids=%llu bitwise_scores=true bitwise_ids=true guards=true\n", + cases_done, engaged, (unsigned long long)scores_checked, (unsigned long long)ids_checked); + return 0; +} diff --git a/src/prefill/kernels.cu b/src/prefill/kernels.cu index 0fb72f3c..14b71b72 100644 --- a/src/prefill/kernels.cu +++ b/src/prefill/kernels.cu @@ -1469,6 +1469,340 @@ __global__ void __launch_bounds__(S) gdn_out_norm_loop_kernel(const float* __res } } } +// STRATA_GDN_CHUNKED=1 on the gfx11 matrix cores: the recurrence in chunks of 16 tokens (the WY form of the CUDA +// chunked path above), FP16 operands and FP32 accumulation, the output norm fused. Per value head, gamma_t the +// gate's sum from the chunk's start to t (inclusive; the code's sg) and S0 the state before the chunk: +// A[t][i] = beta_t exp(gamma_t - gamma_i) k_t.k_i (i < t), T = (I + A)^-1, P[t][i] = exp(gamma_t - gamma_i) q_t.k_i (i <= t), +// Y = beta (V - exp(gamma) K S0), D = T Y, o = exp(gamma) Q S0 + P D, +// S = exp(gamma_last) S0 + K^T (exp(gamma_last - gamma) D). +// gdn_wmma_prep_kernel computes T and P of every chunk at once (they do not depend on the state); gdn_wmma_scan_kernel +// walks the chunks, a block per value head and a wave per 16 value columns, the state in the waves' WMMA accumulators +// (FP32), each product a 16 x 16 x 16 WMMA: k, q, T, P, D and the state as an operand are rounded to FP16 (relative +// 2^-11), so the output differs from the FP32 kernels by more than their rounding (tests/hip/gdn_chunked.cpp holds it +// to the bounds of its Error::ok). The norm and the z gate run in the scan. +#if defined(__gfx1100__) || defined(__gfx1101__) || defined(__gfx1102__) || defined(__gfx1150__) || defined(__gfx1151__) +#define STRATA_GDN_WMMA 1 // device pass with the gfx11 WMMA intrinsic (the list of gfx_arch_is_gfx11_wmma) +#endif +constexpr int GW_CK = 16; // tokens per chunk (a WMMA tile) +constexpr int GW_NW = S / 16; // the scan's waves per block: one per 16 value columns +constexpr int GW_VPK = HV / HK; // value heads per key head: the prep's waves per block +constexpr int GW_KP = S + 8; // the scan's padded FP16 k / q rows +constexpr int GW_AHEAD = 3; // the scan warms the cache this many chunks ahead +constexpr int64_t kGdnWmmaMin = 64; // STRATA_GDN_CHUNKED=1 takes prompt chunks of this many tokens and more +typedef _Float16 gw_h16 __attribute__((ext_vector_type(16))); +typedef _Float16 gw_h8 __attribute__((ext_vector_type(8))); +typedef _Float16 gw_h2 __attribute__((ext_vector_type(2))); +typedef float gw_f8 __attribute__((ext_vector_type(8))); +typedef float gw_f4 __attribute__((ext_vector_type(4))); // (HIP's float4 copies through memcpy, which kept a staged + // copy in scratch: a store that waits for the load) +__device__ __forceinline__ gw_f8 gw_mma(gw_h16 a, gw_h16 b, gw_f8 c) { +#if defined(STRATA_GDN_WMMA) + return __builtin_amdgcn_wmma_f32_16x16x16_f16_w32(a, b, c); +#else + (void) a; (void) b; (void) c; + __builtin_trap(); // not a gfx11 device pass: the runtime gate never launches it +#endif +} +// An accumulator tile (lane l: rows 2v + (l >> 4) for v = 0..7, column l & 15) as a B operand (lane l: column l & 15, +// rows 0..15, both halves of the wave alike): pairs of rows rounded to FP16 and packed, the other half's pairs fetched +// across (permlanex16), then interleaved by a byte permute whose selector depends on the lane's half (gw_sel). +struct GwSel { unsigned even, odd; }; +__device__ __forceinline__ GwSel gw_sel(int hi) { return hi ? GwSel{0x01000504u, 0x03020706u} : GwSel{0x05040100u, 0x07060302u}; } +__device__ __forceinline__ gw_h16 gw_acc_to_b(gw_f8 x, GwSel ps) { + unsigned wd[8]; +#pragma unroll + for (int m = 0; m < 4; ++m) { + const gw_h2 p = {(_Float16) x[2 * m], (_Float16) x[2 * m + 1]}; + const unsigned own = __builtin_bit_cast(unsigned, p); +#if defined(STRATA_GDN_WMMA) + const unsigned other = __builtin_amdgcn_permlanex16(own, own, 0x76543210u, 0xfedcba98u, false, false); +#else + const unsigned other = own; +#endif + wd[2 * m] = __builtin_amdgcn_perm(other, own, ps.even); + wd[2 * m + 1] = __builtin_amdgcn_perm(other, own, ps.odd); + } + return __builtin_bit_cast(gw_h16, wd); +} +__device__ __forceinline__ gw_h16 gw_ld(const _Float16* p) { // 32 bytes of LDS, 16-byte aligned + const uint4 a = *reinterpret_cast(p), b = *reinterpret_cast(p + 8); + const uint4 ab[2] = {a, b}; + return __builtin_bit_cast(gw_h16, ab); +} +// The wave's own LDS writes complete (read back across its lanes). A gfx11 instruction: gfx12 device passes never run these kernels. +__device__ __forceinline__ void gw_lds_wait() { +#if defined(STRATA_GDN_WMMA) + __asm__ volatile("s_waitcnt lgkmcnt(0)" ::: "memory"); +#endif +} +// A barrier over LDS only. __syncthreads() is a workgroup fence over all memory, which on gfx11 also waits for every +// global load in flight: the scan's loads of the next chunk would have to land before each barrier. +__device__ __forceinline__ void gw_lds_barrier() { +#if defined(STRATA_GDN_WMMA) + __asm__ volatile("s_waitcnt lgkmcnt(0)\n\ts_barrier" ::: "memory"); +#else + __syncthreads(); // the gfx11-only instruction must not reach a gfx12 device pass +#endif +} + +// A block per (key head, chunk) - the grid's x the key head, so the blocks in flight read the same token rows (blocks +// that walked the key heads' slices of far-apart rows took 14 ms against 2.2 ms for 16K tokens on gfx1151) - and a wave per value head of the key head. +// T then P, FP16 row-major (1 KB), at tp[(chunk * HV + value head) * 512]. +__global__ void __launch_bounds__(32 * GW_VPK) gdn_wmma_prep_kernel(const float* __restrict__ h, const float* __restrict__ gate, + const float* __restrict__ beta, _Float16* __restrict__ tp, + int64_t T) { + __shared__ float sa[GW_VPK][GW_CK * GW_CK], sg[GW_VPK][GW_CK], sb[GW_VPK][GW_CK]; + const int qh = blockIdx.x, ch = blockIdx.y, w = threadIdx.x >> 5, l = threadIdx.x & 31, c = l & 15, hi = l >> 4; + const int vh = qh + w * HK; + const int64_t t0 = (int64_t) ch * GW_CK; + gw_f8 kk = {}, qk = {}; // k_t.k_i and q_t.k_i (lane: column i = c, rows t = 2v + hi) + { + const bool ok = t0 + c < T; // past the end: zero rows + const float* ht = h + (ok ? t0 + c : 0) * C; +#pragma unroll + for (int j = 0; j < S / 16; ++j) { + gw_h16 ka, qa; +#pragma unroll + for (int i = 0; i < 4; ++i) { + const gw_f4 k4 = *reinterpret_cast(ht + HK * S + qh * S + 16 * j + 4 * i); + const gw_f4 q4 = *reinterpret_cast(ht + qh * S + 16 * j + 4 * i); +#pragma unroll + for (int e = 0; e < 4; ++e) { + ka[4 * i + e] = (_Float16) (ok ? k4[e] : 0.0f); + qa[4 * i + e] = (_Float16) (ok ? q4[e] : 0.0f); + } + } + kk = gw_mma(ka, ka, kk); // B = K^T: lane i holds column i of K^T, row i of K - the A operand itself + qk = gw_mma(qa, ka, qk); + } + } + if (l < GW_CK) { // past the end: gate 0, beta 0 + const bool ok = t0 + l < T; + float g = ok ? gate[(t0 + l) * HV + vh] : 0.0f; +#pragma unroll + for (int o = 1; o < GW_CK; o <<= 1) { + const float u = __shfl_up(g, o, GW_CK); + if (l >= o) g += u; + } + sg[w][l] = g; + sb[w][l] = ok ? beta[(t0 + l) * HV + vh] : 0.0f; + } + gw_lds_wait(); // the wave's own LDS writes, read across its lanes + _Float16* out = tp + ((int64_t) ch * HV + vh) * (2 * GW_CK * GW_CK); +#pragma unroll + for (int v = 0; v < 8; ++v) { + const int t = 2 * v + hi; + sa[w][t * GW_CK + c] = c < t ? sb[w][t] * __expf(sg[w][t] - sg[w][c]) * kk[v] : 0.0f; + out[GW_CK * GW_CK + t * GW_CK + c] = (_Float16) (c <= t ? __expf(sg[w][t] - sg[w][c]) * qk[v] : 0.0f); + } + gw_lds_wait(); + if (l < GW_CK) { // lane c: column c of T = (I + A)^-1 by forward substitution + float tc[GW_CK]; +#pragma unroll + for (int t = 0; t < GW_CK; ++t) { + float v = t == c ? 1.0f : 0.0f; +#pragma unroll + for (int k = 0; k < t; ++k) v = fmaf(-sa[w][t * GW_CK + k], tc[k], v); + tc[t] = v; + out[t * GW_CK + c] = (_Float16) v; + } + } +} + +// A thread's slice of a chunk in the scan (token threadIdx / 16, columns (threadIdx % 16) * 8 .. + 7): k, q and v, +// loaded a chunk ahead, and one word of the chunk's T and P; lanes 0..15 of wave 0 also gate and beta of token l. +// Rows past the end read the last row (finite: their gate and beta become 0 at staging, which keeps them out of the +// state, of the real rows' products and of the output) - no select on the loaded values, which would wait for them. +struct GwChunk { + gw_f4 k0, k1, q0, q1, v0, v1; + float g, b; + unsigned tp; +}; +__device__ __forceinline__ void gw_load(GwChunk& in, const float* __restrict__ h, const float* __restrict__ gate, + const float* __restrict__ beta, const unsigned* __restrict__ tp, int64_t t0, + int64_t T, int vh, int qh) { + const int t = threadIdx.x >> 4, r = (threadIdx.x & 15) * 8; + const float* ht = h + std::min(t0 + t, T - 1) * C; + in.tp = tp[((t0 / GW_CK) * HV + vh) * (GW_CK * GW_CK) + threadIdx.x]; + in.k0 = *reinterpret_cast(ht + HK * S + qh * S + r); + in.k1 = *reinterpret_cast(ht + HK * S + qh * S + r + 4); + in.q0 = *reinterpret_cast(ht + qh * S + r); + in.q1 = *reinterpret_cast(ht + qh * S + r + 4); + in.v0 = *reinterpret_cast(ht + 2 * HK * S + vh * S + r); + in.v1 = *reinterpret_cast(ht + 2 * HK * S + vh * S + r + 4); + if (threadIdx.x < GW_CK) { + const int64_t tl = std::min(t0 + threadIdx.x, T - 1); + in.g = gate[tl * HV + vh]; + in.b = beta[tl * HV + vh]; + } +} +// Brings a later chunk's lines (this block's k, q, v and z rows: 256 lines of 128 bytes, one a thread) into the cache +// with a load whose result is not used, so the real loads of that chunk hit the cache. An ordinary load: the compiler +// tracks it, and the result is consumed (by an empty asm) one chunk later, after the store of the previous chunk's output +// rows, where the wait for the loads issued before that point also covers it. +__device__ __forceinline__ unsigned gw_touch(const float* __restrict__ h, const float* __restrict__ z, int64_t t0, + int64_t T, int vh, int qh) { + const int t = threadIdx.x >> 4, part = threadIdx.x & 15, kind = part >> 2; + if (t0 + t >= T) return 0u; + const float* p = kind == 0 ? h + (t0 + t) * C + HK * S + qh * S + : kind == 1 ? h + (t0 + t) * C + qh * S + : kind == 2 ? h + (t0 + t) * C + 2 * HK * S + vh * S + : z + (t0 + t) * HV * S + vh * S; + return __float_as_uint(p[32 * (part & 3)]); +} +// Per chunk: stage it (k / q FP16, k also transposed, v, the gate's running sum, beta, T and P); barrier (1); store +// the previous chunk's output rows (the z gate on its normed output, 16 bytes a thread); X = K S0, QS = Q S0; Y, D, +// o and the wave's sums of o^2; the state update; barrier (2); the norm. LDS is single-buffered: an array written in +// the staging of chunk c + 1 or after its barrier (2) was last read before that wave reached barrier (1) of c + 1. +__global__ void __launch_bounds__(GW_NW * 32) gdn_wmma_scan_kernel(float* __restrict__ state, const float* __restrict__ h, + const float* __restrict__ gate, const float* __restrict__ beta, + const float* __restrict__ z, const float* __restrict__ gamma, + const unsigned* __restrict__ tp, float eps, + uint16_t* __restrict__ y16, int64_t T, int64_t ld16) { + __shared__ __attribute__((aligned(16))) _Float16 sk[GW_CK * GW_KP], sq[GW_CK * GW_KP], skt[S * GW_CK], + stp[2 * GW_CK * GW_CK]; + __shared__ __attribute__((aligned(16))) float sv[GW_CK * S], so[GW_CK * S], sn[GW_CK * GW_NW]; + __shared__ float sg[GW_CK], sb[GW_CK], sgam[S]; + const _Float16 *st_ = stp, *sp_ = stp + GW_CK * GW_CK; // T, P + const int vh = blockIdx.x, qh = vh % HK, w = threadIdx.x >> 5, l = threadIdx.x & 31, c = l & 15, hi = l >> 4; + const int col = 16 * w + c; // this lane's column in the products + const int st = threadIdx.x >> 4, sr = (threadIdx.x & 15) * 8; // this thread's staging slice + const size_t rs = (size_t) HV * S; + const GwSel ps = gw_sel(hi); + gw_f8 s[S / 16]; // the state: rows 16j + 2v + hi, column col +#pragma unroll + for (int j = 0; j < S / 16; ++j) +#pragma unroll + for (int v = 0; v < 8; ++v) s[j][v] = state[(size_t) (16 * j + 2 * v + hi) * rs + (size_t) vh * S + col]; + if (threadIdx.x < S) sgam[threadIdx.x] = gamma[threadIdx.x]; + const float out_scale = rsqrtf((float) S); + GwChunk cur; + gw_load(cur, h, gate, beta, tp, 0, T, vh, qh); + unsigned touched = 0; + gw_f4 z0 = {}, z1 = {}; // the z slice of the chunk whose output rows are stored next + auto store_rows = [&](int64_t c0) { // the output rows of the chunk at c0 (its norm in so): z gate, FP16 + if (c0 + st >= T) return; + const float* o = &so[st * S + sr]; + gw_h8 r; +#pragma unroll + for (int i = 0; i < 8; ++i) r[i] = (_Float16) (o[i] * sigm(i < 4 ? z0[i] : z1[i - 4])); + *reinterpret_cast(y16 + (c0 + st) * ld16 + vh * S + sr) = __builtin_bit_cast(uint4, r); + }; + for (int64_t t0 = 0; t0 < T; t0 += GW_CK) { + { // stage this chunk + gw_h8 kh, qq; +#pragma unroll + for (int i = 0; i < 8; ++i) { + kh[i] = (_Float16) (i < 4 ? cur.k0[i] : cur.k1[i - 4]); + qq[i] = (_Float16) (i < 4 ? cur.q0[i] : cur.q1[i - 4]); + skt[(sr + i) * GW_CK + st] = kh[i]; + } + *reinterpret_cast(&sk[st * GW_KP + sr]) = __builtin_bit_cast(uint4, kh); + *reinterpret_cast(&sq[st * GW_KP + sr]) = __builtin_bit_cast(uint4, qq); + *reinterpret_cast(&sv[st * S + sr]) = cur.v0; + *reinterpret_cast(&sv[st * S + sr + 4]) = cur.v1; + reinterpret_cast(stp)[threadIdx.x] = cur.tp; + if (threadIdx.x < GW_CK) { // past the end: gate 0, beta 0 + const bool ok = t0 + l < T; + float g = ok ? cur.g : 0.0f; +#pragma unroll + for (int o = 1; o < GW_CK; o <<= 1) { + const float u = __shfl_up(g, o, GW_CK); + if (l >= o) g += u; + } + sg[l] = g; + sb[l] = ok ? cur.b : 0.0f; + } + } + if (t0 + GW_CK < T) gw_load(cur, h, gate, beta, tp, t0 + GW_CK, T, vh, qh); // lands during this chunk + const unsigned touch_now = gw_touch(h, z, t0 + GW_AHEAD * GW_CK, T, vh, qh); + gw_lds_barrier(); // (1) this chunk staged; the previous chunk's norm in so + if (t0 > 0) store_rows(t0 - GW_CK); + __asm__ volatile("" ::"v"(touched)); // the previous touch, consumed here + touched = touch_now; + { // this chunk's z slice, for its output rows after barrier (1) of the next chunk + const int64_t tz = std::min(t0 + st, T - 1); + z0 = *reinterpret_cast(z + tz * HV * S + vh * S + sr); + z1 = *reinterpret_cast(z + tz * HV * S + vh * S + sr + 4); + } + gw_f8 x = {}, qs = {}; // K S0 and Q S0, this wave's columns +#pragma unroll + for (int j = 0; j < S / 16; ++j) { + const gw_h16 b = gw_acc_to_b(s[j], ps); + x = gw_mma(gw_ld(sk + c * GW_KP + 16 * j), b, x); + qs = gw_mma(gw_ld(sq + c * GW_KP + 16 * j), b, qs); + } + gw_f8 y; +#pragma unroll + for (int v = 0; v < 8; ++v) { + const int t = 2 * v + hi; + y[v] = sb[t] * (sv[t * S + col] - __expf(sg[t]) * x[v]); + } + const gw_f8 d = gw_mma(gw_ld(st_ + c * GW_CK), gw_acc_to_b(y, ps), gw_f8{}); + gw_f8 o; +#pragma unroll + for (int v = 0; v < 8; ++v) o[v] = __expf(sg[2 * v + hi]) * qs[v]; + o = gw_mma(gw_ld(sp_ + c * GW_CK), gw_acc_to_b(d, ps), o); +#pragma unroll + for (int v = 0; v < 8; ++v) { // the wave's 16 columns of o^2 per token, then the 8 waves' through LDS + o[v] *= out_scale; + float p = o[v] * o[v]; +#pragma unroll + for (int m = 1; m < 16; m <<= 1) p += __shfl_xor(p, m); + if (c == 0) sn[(2 * v + hi) * GW_NW + w] = p; + } + const float gl = sg[GW_CK - 1]; + gw_f8 dd; +#pragma unroll + for (int v = 0; v < 8; ++v) dd[v] = __expf(gl - sg[2 * v + hi]) * d[v]; + const gw_h16 db = gw_acc_to_b(dd, ps); + const float eg = __expf(gl); +#pragma unroll + for (int j = 0; j < S / 16; ++j) s[j] = gw_mma(gw_ld(skt + (16 * j + c) * GW_CK), db, s[j] * eg); + gw_lds_barrier(); // (2) the sums of o^2 + const float g_col = sgam[col]; +#pragma unroll + for (int v = 0; v < 8; ++v) { + const int t = 2 * v + hi; + const gw_f4 n0 = *reinterpret_cast(&sn[t * GW_NW]), n1 = *reinterpret_cast(&sn[t * GW_NW + 4]); + const float ss = n0[0] + n0[1] + n0[2] + n0[3] + n1[0] + n1[1] + n1[2] + n1[3]; + so[t * S + col] = o[v] * rsqrtf(ss * (1.0f / S) + eps) * g_col; + } + } + __asm__ volatile("" ::"v"(touched)); + gw_lds_barrier(); + store_rows((T - 1) / GW_CK * GW_CK); + __asm__ volatile("" : "+s"(state)); // the state's addresses recomputed here, not kept (spilled) since the start +#pragma unroll + for (int j = 0; j < S / 16; ++j) +#pragma unroll + for (int v = 0; v < 8; ++v) state[(size_t) (16 * j + 2 * v + hi) * rs + (size_t) vh * S + col] = s[j][v]; +} +// The opt-in chunked recurrence on gfx11 (STRATA_GDN_CHUNKED=1): false (nothing launched) on another part. y, the +// FP32 scratch of the other kernels (T x 6144 floats), holds T and P (1 KB per chunk and value head: T x 3 KB). +bool gdn_rec_wmma(float* state, const float* h, const float* gate, const float* beta, const float* z, const float* gamma, + float eps, float* y, uint16_t* y16, int64_t T, cudaStream_t s, int64_t ld16) { + if (T < kGdnWmmaMin || ld16 % 8 != 0) return false; // the rows are stored 16 bytes at a time + // A layer-split worker can change devices: a process-wide answer for the first card can launch a trapping + // gfx11 kernel on a later gfx12 card. Cache only the current thread's last device, as properties are not cheap. + static thread_local int last_device = -1; + static thread_local bool gfx11 = false; + int dev = 0; + if (cudaGetDevice(&dev) != cudaSuccess) return false; + if (dev != last_device) { + cudaDeviceProp p{}; + if (cudaGetDeviceProperties(&p, dev) != cudaSuccess) return false; + gfx11 = strata::kernels::gfx_arch_is_gfx11_wmma(p.gcnArchName); + last_device = dev; + } + if (!gfx11) return false; + const int64_t nch = (T + GW_CK - 1) / GW_CK; + _Float16* tp = reinterpret_cast<_Float16*>(y); + gdn_wmma_prep_kernel<<>>(h, gate, beta, tp, T); + gdn_wmma_scan_kernel<<>>(state, h, gate, beta, z, gamma, reinterpret_cast(tp), + eps, y16, T, ld16); + return true; +} #endif // __HIPCC__ __global__ void __launch_bounds__(S) gdn_out_norm_kernel(const float* __restrict__ z, const float* __restrict__ gamma, float eps, float* __restrict__ y, uint16_t* __restrict__ y16, @@ -2082,7 +2416,17 @@ void gdn_recurrence_variant(int variant, float* state, const float* h, const flo const float* z, const float* gamma, float eps, float* y, uint16_t* y16, int64_t T, void* stream, int64_t ld16) { if (ld16 <= 0) ld16 = (int64_t) HV * S; + static const bool serial = std::getenv("STRATA_GDN_REC_HEADS") != nullptr; // the one-block-per-head kernel (A/B) #if defined(__HIPCC__) + if (variant == 0 || variant == 1) { + // STRATA_GDN_CHUNKED=1 (opt-in): the chunked recurrence on the gfx11 matrix cores, FP16 operands (other bits; + // a shorter chunk or another part takes the kernels below) + static const bool chunked = [] { const char* v = std::getenv("STRATA_GDN_CHUNKED"); return v != nullptr && std::atoi(v) != 0; }(); + if (chunked && !serial && gdn_rec_wmma(state, h, gate, beta, z, gamma, eps, y, y16, T, (cudaStream_t) stream, ld16)) { + check("gdn_recurrence (chunked, WMMA)"); + return; + } + } if (variant == 3) { // diagnostics: the quad recurrence + the old norm kernel if (T > 0) { gdn_rec_quad_kernel<<>>(state, h, gate, beta, y, T); @@ -2125,7 +2469,6 @@ void gdn_recurrence_variant(int variant, float* state, const float* h, const flo #else (void) variant; // the quad recurrence kernels are AMD-only #endif - static const bool serial = std::getenv("STRATA_GDN_REC_HEADS") != nullptr; // the one-block-per-head kernel (A/B) if (serial || T <= 0 || variant == 2) { gdn_rec_kernel<<>>(state, h, gate, beta, z, gamma, eps, y, y16, T, ld16); } else { diff --git a/src/prefill/moe_f16_common.cuh b/src/prefill/moe_f16_common.cuh new file mode 100644 index 00000000..cde99444 --- /dev/null +++ b/src/prefill/moe_f16_common.cuh @@ -0,0 +1,250 @@ +// src/prefill/moe_f16_common.cuh - the parts the gfx11 F16 prompt-expert kernels share (STRATA_PF_F16=1): the +// switch, the work item's width, the int8 activations staged as F16, the WMMA over the token tiles and the two +// epilogues. moe_f16_kq.cu (the K-quant kernels) and moe_fused_iq.cu (the other native formats) include it. +// +// A work item is 128 weight rows (gate/up: the 64 gate and 64 up rows of 64 features; down: 128 output rows) against +// one 64-row tile of fused::group or two consecutive tiles of one expert; each of the eight waves owns 16 of the +// weight rows. The F16 WMMA accumulates all of K in F32. The fragment loop and the epilogues' layouts follow gufo's +// RoutedF16GEMMKernel. +// +// Adapted from gufo 97b8645f: src/models/qwen38_flash_next/kernels/rocm/kernels.hip.cpp (RoutedF16GEMMKernel). +// MIT License +// Copyright (c) 2026 gufo contributors +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +#pragma once + +#include +#include + +#include +#include + +#include "strata/prefill/moe_fused.hpp" + +#if defined(__HIPCC__) && (defined(__gfx1100__) || defined(__gfx1101__) || defined(__gfx1102__) || \ + defined(__gfx1150__) || defined(__gfx1151__)) +#define STRATA_F16_DEVICE 1 +#else +#define STRATA_F16_DEVICE 0 +#endif + +namespace strata::prefill::fused::f16 { + +constexpr int AB = 80; // activation / H bytes per 64 values: 64 codes, {d0, d1}, {sum0, sum1} +constexpr int THREADS = 256; +constexpr int ROWS = 128; // weight rows per work item +constexpr int GU_NFB = 640 / 64, D_NFB = 2560 / ROWS; // work items per tile: 64 features, 128 output rows +constexpr int GU_ACT_LD = 2560 / 64 * AB, H_LD = 640 / 64 * AB; // bytes per activation / H row + +/// STRATA_PF_F16=1 (on top of STRATA_PF_FUSED=1): the covered formats take the F16 kernels on gfx11. +inline bool requested() { + static const bool on = [] { + const char* v = std::getenv("STRATA_PF_F16"); + return v != nullptr && v[0] == '1'; + }(); + return on; +} + +/// Two tiles a work item when an expert has a tile's rows or more on average. gfx1151, Q4_K, top 10 over 512 +/// experts, one 128-expert launch, ms (64 / 128): 1024 tokens 1.22 / 1.28, 2048 1.51 / 1.64, 4096 2.73 / 2.48, 8192 +/// 4.76 / 4.59, 16384 9.19 / 8.46; Q5_1 down 2048 1.02 / 1.04, 4096 1.61 / 1.48, 16384 5.29 / 4.83. +/// STRATA_PF_F16_BN=64|128 forces one. +inline int pick_bn(int64_t n, int n_expert) { + static const int forced = [] { + const char* v = std::getenv("STRATA_PF_F16_BN"); + const int t = v ? std::atoi(v) : 0; + return t == kTileRows || t == 2 * kTileRows ? t : 0; + }(); + if (forced) return forced; + return (double) n / (n_expert > 0 ? n_expert : 1) >= kTileRows ? 2 * kTileRows : kTileRows; +} + +using v16h = __attribute__((__vector_size__(16 * sizeof(_Float16)))) _Float16; +using v8f = __attribute__((__vector_size__(8 * sizeof(float)))) float; + +__device__ __forceinline__ v8f wmma_f16(v16h a, v16h b, v8f c) { +#if STRATA_F16_DEVICE + return __builtin_amdgcn_wmma_f32_16x16x16_f16_w32(a, b, c); +#else + __builtin_trap(); + return c; +#endif +} + +/// The work item of block `w`: its tile (fused::group's tables), whether it is the second tile of a pair (the first +/// takes it), and its rows. Returns false when the block has no work. +template +__device__ __forceinline__ bool work_item(const Batch& b, const int32_t* ts, const int2* tiles, const int32_t* off, int w, + int& fb, int& e, int& row0, int& nrows) { + static_assert(BN == kTileRows || BN == 2 * kTileRows, "one tile or a pair"); + const int t0 = ts[b.e0]; + if (w >= (ts[b.e1] - t0) * NFB) return false; + const int2 tl = tiles[t0 + w / NFB]; + fb = w % NFB; + e = tl.x; + row0 = tl.y; + if (BN > kTileRows && ((t0 + w / NFB - ts[e]) & 1)) return false; + nrows = min(BN, off[e + 1] - row0); + return true; +} + +/// The int8 activation (or H) rows of a work item, staged as F16 per stage: BN rows x 8 chunks of 8 values, chunk +/// sub = kb * 4 + quarter, into LDS [sub][row] (stride BN + 1) - the B fragments' layout of the F16 WMMA. A row past +/// the item's end is zero. +template struct ActStage { + static constexpr int FETCH = BN * 8 / THREADS, STRIDE = BN + 1, BYTES = 2 * 4 * STRIDE * 16; + const uint8_t* src[FETCH]; + int slot[FETCH], sub[FETCH]; + uint2 codes[FETCH]; + float d[FETCH]; + // rows[t]: the row of item row t in `base` (rows of `ld` bytes), or -1 + __device__ __forceinline__ void init(const uint8_t* base, size_t ld, const int* rows, int tid) { +#pragma unroll + for (int i = 0; i < FETCH; ++i) { + const int chunk = tid + i * THREADS, t = chunk >> 3, c = chunk & 7; + src[i] = rows[t] >= 0 ? base + (size_t) rows[t] * ld : nullptr; + slot[i] = c * STRIDE + t; + sub[i] = c; + } + } + __device__ __forceinline__ void fetch(int s) { +#pragma unroll + for (int i = 0; i < FETCH; ++i) { + if (src[i] != nullptr) { + const uint8_t* p = src[i] + (size_t) s * AB; + codes[i] = *reinterpret_cast(p + 8 * sub[i]); + d[i] = *reinterpret_cast(p + 64 + 4 * (sub[i] >> 2)); + } else { + codes[i] = make_uint2(0u, 0u); + d[i] = 0.0f; + } + } + } + __device__ __forceinline__ void commit(uint4* s_act) const { +#pragma unroll + for (int i = 0; i < FETCH; ++i) { + const uint32_t ws[2] = {codes[i].x, codes[i].y}; + __half2 h[4]; +#pragma unroll + for (int j = 0; j < 4; ++j) { + const uint32_t wd = ws[j >> 1] >> (16 * (j & 1)); + const float lo = (float) (int8_t) (wd & 0xFFu), hi = (float) (int8_t) ((wd >> 8) & 0xFFu); + h[j] = __floats2half2_rn(lo * d[i], hi * d[i]); + } + s_act[slot[i]] = make_uint4(__builtin_bit_cast(uint32_t, h[0]), __builtin_bit_cast(uint32_t, h[1]), + __builtin_bit_cast(uint32_t, h[2]), __builtin_bit_cast(uint32_t, h[3])); + } + } +}; + +/// Two F16 WMMAs (K 32) of a wave's 16 weight rows against each live 16-row tile of the staged activations. +template +__device__ __forceinline__ void mma_tiles(v8f (&acc)[BN / 16], v16h a_lo, v16h a_hi, const uint4* s_act, int kb, int sub_lane, + int live_tiles) { + constexpr int STRIDE = ActStage::STRIDE; +#pragma unroll + for (int j = 0; j < BN / 16; ++j) { + asm volatile("" ::: "memory"); // one token tile's fragments live at a time (gufo: hoisting spills) + if (j >= live_tiles) continue; + const uint4* frag = s_act + (kb * 4) * STRIDE + j * 16 + sub_lane; + uint4 bq[4]; +#pragma unroll + for (int q = 0; q < 4; ++q) bq[q] = frag[q * STRIDE]; + v16h b_lo, b_hi; + __builtin_memcpy(&b_lo, &bq[0], 32); + __builtin_memcpy(&b_hi, &bq[2], 32); + acc[j] = wmma_f16(a_lo, b_lo, acc[j]); + acc[j] = wmma_f16(a_hi, b_hi, acc[j]); + } +} + +constexpr int GU_EPI_STRIDE = 18, GU_EPI_PLANE = 16 * GU_EPI_STRIDE; +constexpr int GU_EPI_BYTES = 8 * GU_EPI_PLANE * 4, D_EPI_BYTES = 8 * 256 * 4; + +/// Gate/up epilogue (every wave; `lds` at least GU_EPI_BYTES, free): per token tile, each wave's 16 x 16 +/// accumulators as plane [token][row] (waves 0-3 the gate rows, 4-7 the up rows), then a thread per (token, half of +/// the 64 features): SwiGLU, H as int8 per 32 features with its scale and the codes' sum (native_w11_kernel's H). +template +__device__ __forceinline__ void gu_epilogue(const v8f (&acc)[BN / 16], uint8_t* lds, int tid, int live_tiles, int nrows, int row0, + int fb, uint8_t* __restrict__ out) { + const int wave = tid >> 5, lane = tid & 31, sub_lane = lane & 15, half_id = lane >> 4; + float* base = reinterpret_cast(lds); + float* scratch = base + wave * GU_EPI_PLANE; +#pragma unroll + for (int j = 0; j < BN / 16; ++j) { + if (j >= live_tiles) break; // uniform +#pragma unroll + for (int l = 0; l < 8; ++l) scratch[sub_lane * GU_EPI_STRIDE + 2 * l + half_id] = acc[j][l]; + __syncthreads(); + if (tid < 32) { + const int t = tid >> 1, hh = tid & 1, r = j * 16 + t; + if (r < nrows) { + float hv[32]; + float am = 0.0f; +#pragma unroll + for (int f = 0; f < 32; ++f) { + const int ft = 32 * hh + f; + const int idx = (ft >> 4) * GU_EPI_PLANE + t * GU_EPI_STRIDE + (ft & 15); + const float gt = base[idx], up = base[idx + 4 * GU_EPI_PLANE]; + hv[f] = gt / (1.0f + __expf(-gt)) * up; + am = fmaxf(am, fabsf(hv[f])); + } + const float inv = am > 0.0f ? 127.0f / am : 0.0f; + uint8_t* o = out + (size_t) (row0 + r) * H_LD + (size_t) fb * AB; + uint32_t wd[8] = {}; + int csum = 0; +#pragma unroll + for (int f = 0; f < 32; ++f) { + const int c = __float2int_rn(hv[f] * inv); + csum += c; + wd[f >> 2] |= (uint32_t) (uint8_t) (int8_t) c << (8 * (f & 3)); + } + uint4* o4 = reinterpret_cast(o + 32 * hh); + o4[0] = make_uint4(wd[0], wd[1], wd[2], wd[3]); + o4[1] = make_uint4(wd[4], wd[5], wd[6], wd[7]); + *reinterpret_cast(o + 64 + 4 * hh) = am / 127.0f; + *reinterpret_cast(o + 72 + 4 * hh) = (float) csum; + } + } + __syncthreads(); + } +} + +/// Down epilogue (`lds` at least D_EPI_BYTES, free): each wave's 16 x 16 tile through LDS ([token][row]), then 16 +/// consecutive FP32 rows per routed row into dm [routed row][2560]. +template +__device__ __forceinline__ void down_epilogue(const v8f (&acc)[BN / 16], uint8_t* lds, int tid, int live_tiles, int nrows, int row0, + int fb, float* __restrict__ dm) { + const int wave = tid >> 5, lane = tid & 31, sub_lane = lane & 15, half_id = lane >> 4; + float* tile = reinterpret_cast(lds) + wave * 256; + const int r0 = fb * ROWS + wave * 16; +#pragma unroll + for (int j = 0; j < BN / 16; ++j) { + if (j >= live_tiles) break; // uniform +#pragma unroll + for (int l = 0; l < 8; ++l) tile[sub_lane * 16 + 2 * l + half_id] = acc[j][l]; + __builtin_amdgcn_wave_barrier(); +#pragma unroll + for (int q = 0; q < 8; ++q) { + const int flat = q * 32 + lane, t = j * 16 + (flat >> 4); + if (t < nrows) dm[(size_t) (row0 + t) * 2560 + r0 + (flat & 15)] = tile[flat]; + } + __builtin_amdgcn_wave_barrier(); + } +} + +} // namespace strata::prefill::fused::f16 diff --git a/src/prefill/moe_f16_kq.cu b/src/prefill/moe_f16_kq.cu new file mode 100644 index 00000000..824b8cce --- /dev/null +++ b/src/prefill/moe_f16_kq.cu @@ -0,0 +1,334 @@ +// src/prefill/moe_f16_kq.cu - see moe_f16_kq.hpp. gfx11 only (opt-in STRATA_PF_F16=1 with STRATA_PF_FUSED_KQ=1). +// +// gufo's routed-expert kernels for the K-quants, on Strata's tables, int8 activations and H (the work item, the +// activation staging and the epilogues are moe_f16_common.cuh's): +// - gate/up (Q4_K, Q5_K): the weight codes stay packed in LDS (one 32-byte nibble group per row and stage) and +// each wave turns its own 16 rows into F16 right after the LDS read: w = q * (d sc) - dmin m as one packed FMA; +// - down (Q5_1): a K block's 16 code bytes and its high-bit word in LDS, w = q d + m per wave. +// The output differs from native_w11_kernel's (F16 weights instead of int8 sub-blocks), like STRATA_PF_FUSED_KQ's +// does from the MMQ path. +// +// Adapted from gufo 97b8645f: src/models/qwen38_flash_next/kernels/rocm/kernels.hip.cpp +// (RoutedF16GEMMKernel and its helpers). +// MIT License +// Copyright (c) 2026 gufo contributors +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +#include "moe_f16_kq.hpp" + +#include "moe_f16_common.cuh" + +#include "ggml.h" + +#include + +namespace strata::prefill::fused::f16kq { +namespace { + +using namespace f16; + +constexpr int T_Q4_K = GGML_TYPE_Q4_K, T_Q5_K = GGML_TYPE_Q5_K; +constexpr int GU_NS = 2560 / 64, D_NS = 640 / 64; // stages of 64 values +constexpr int FEAT = 64; // features (gate rows = up rows) per gate/up item + +// Byte i of the 16-byte K-quant block header (d, dmin, scales[12]). +__device__ __forceinline__ uint32_t header_byte(const uint4& h, uint32_t i) { + const uint32_t word = i < 4 ? h.x : i < 8 ? h.y : i < 12 ? h.z : h.w; + return (word >> (8U * (i & 3U))) & 0xFFU; +} +// Bit s of each of the four bytes of w, packed into bits 0-3. +__device__ __forceinline__ uint32_t gather_bit(uint32_t w, int s) { return (((w >> s) & 0x01010101U) * 0x01020408U) >> 24U; } +// Bits 0-3 of `bits` to bit 4 of each byte. +__device__ __forceinline__ uint32_t spread_high_bits(uint32_t bits) { return (__umul24(bits, 0x00204081U) & 0x01010101U) << 4U; } + +constexpr uint32_t HALF_MAGIC = 0x64646464U; // the high bytes of 1024.0 as F16 +// Four code bytes (< 32) to four halves: 1024 + q exactly, minus 1024, then q * scale + bias. +__device__ __forceinline__ void codes_to_halves(uint32_t codes, __half2 magic, __half2 scale2, __half2 bias2, __half2& lo, + __half2& hi) { +#if STRATA_F16_DEVICE + const uint32_t p0 = __builtin_amdgcn_perm(codes, HALF_MAGIC, 0x01050004U); + const uint32_t p1 = __builtin_amdgcn_perm(codes, HALF_MAGIC, 0x03070206U); + lo = __hfma2(__hadd2(__builtin_bit_cast(__half2, p0), magic), scale2, bias2); + hi = __hfma2(__hadd2(__builtin_bit_cast(__half2, p1), magic), scale2, bias2); +#else + (void) codes; (void) magic; (void) scale2; (void) bias2; lo = hi = __half2{}; +#endif +} + +// Gate/up (Q4_K / Q5_K): code rows 0..63 are the item's gate rows, 64..127 its up rows; a thread pair per row. +template +__global__ void __launch_bounds__(THREADS) gate_up_kernel(const Batch b, const NativeGeom geo, const int32_t* __restrict__ ts, + const int2* __restrict__ tiles, const int32_t* __restrict__ off, + const uint8_t* __restrict__ act, const int32_t* __restrict__ src, + uint8_t* __restrict__ out) { +#if STRATA_F16_DEVICE + constexpr bool Q5K = WT == T_Q5_K; + constexpr int BLOCK_CHUNKS = Q5K ? 11 : 9; // 16-byte chunks per 256-value block + constexpr int CODE_CHUNK = Q5K ? 3 : 1; // the first chunk of qs + // LDS (bytes): codes ROWS x 2 chunks (swizzled); Q5_K's high bits and the (scale, bias) half2 per row and K + // block; the activations. The epilogue reuses the front. + constexpr int CODE_BYTES = ROWS * 2 * 16; + constexpr int HIGH_BYTES = Q5K ? 2 * ROWS * 4 : 0; + constexpr int SCALE_BYTES = 2 * ROWS * 4; + constexpr int STAGE_BYTES = CODE_BYTES + HIGH_BYTES + SCALE_BYTES + ActStage::BYTES; + static_assert(GU_EPI_BYTES <= STAGE_BYTES, "the epilogue fits the stage"); + __shared__ __attribute__((aligned(16))) uint8_t lds[STAGE_BYTES]; + __shared__ int srow[BN]; + auto* s_codes = reinterpret_cast(lds); + auto* s_high = reinterpret_cast(lds + CODE_BYTES); + auto* s_scale = reinterpret_cast(lds + CODE_BYTES + HIGH_BYTES); + auto* s_act = reinterpret_cast(lds + CODE_BYTES + HIGH_BYTES + SCALE_BYTES); + + const int tid = threadIdx.x, wave = tid >> 5, sub_lane = tid & 15; + const int f_c = tid & 1; // this thread's chunk (and K block) of its weight row + const auto swizzle = [](int row, int c) { return row * 2 + (c ^ ((row >> 2) & 1)); }; + const __half2 magic = __floats2half2_rn(-1024.0f, -1024.0f); + + int fb, e, row0, nrows; + if (!work_item(b, ts, tiles, off, blockIdx.x, fb, e, row0, nrows)) return; + const int live_tiles = (nrows + 15) / 16; + const uint8_t* blob = b.blob[e - b.e0]; + if (tid < BN) srow[tid] = tid < nrows ? src[row0 + tid] : -1; + __syncthreads(); + + const uint8_t* f_ptr = blob + ((tid >> 1) >= FEAT ? geo.up_off : 0) + (size_t) (fb * FEAT + ((tid >> 1) & (FEAT - 1))) * geo.gu_row; + uint4 f_header = make_uint4(0u, 0u, 0u, 0u), f_codes, f_qh[2] = {}; + uint4 code_cache[4]; // the block's four nibble groups, this thread's chunk of each + uint32_t f_high = 0; + int f_sb32 = 0; + ActStage as; + as.init(act, GU_ACT_LD, srow, tid); // the tokens' activation rows + + const auto fetch_stage = [&](int s) { + const int kb0 = 2 * s; + const uint4* blk = reinterpret_cast(f_ptr) + (kb0 / 8) * BLOCK_CHUNKS; + if (kb0 % 8 == 0) { // a new 256-value block every four stages + f_header = blk[0]; +#pragma unroll + for (int group = 0; group < 4; ++group) code_cache[group] = blk[CODE_CHUNK + group * 2 + f_c]; + if constexpr (Q5K) { + f_qh[0] = blk[1]; + f_qh[1] = blk[2]; + } + } + const int sb32 = (kb0 % 8) + f_c; + { + const int group = sb32 / 2; // uniform across the wave + const uint32_t low = 0u - (group & 1u), high = 0u - ((group >> 1u) & 1u); + const auto select = [](uint32_t a, uint32_t bb, uint32_t mask) { + uint32_t value; + asm("v_cndmask_b32_e64 %0, %1, %2, %3" : "=v"(value) : "v"(a), "v"(bb), "s"(mask)); + return value; + }; + const uint4 &c0 = code_cache[0], &c1 = code_cache[1], &c2 = code_cache[2], &c3 = code_cache[3]; + f_codes = make_uint4(select(select(c0.x, c1.x, low), select(c2.x, c3.x, low), high), + select(select(c0.y, c1.y, low), select(c2.y, c3.y, low), high), + select(select(c0.z, c1.z, low), select(c2.z, c3.z, low), high), + select(select(c0.w, c1.w, low), select(c2.w, c3.w, low), high)); + } + f_sb32 = sb32; + if constexpr (Q5K) { + const uint32_t qh[8] = {f_qh[0].x, f_qh[0].y, f_qh[0].z, f_qh[0].w, f_qh[1].x, f_qh[1].y, f_qh[1].z, f_qh[1].w}; + uint32_t hb = 0; +#pragma unroll + for (int i = 0; i < 8; ++i) hb |= gather_bit(qh[i], sb32) << (4 * i); + f_high = hb; + } + as.fetch(s); + }; + + const auto commit_stage = [&]() { + const int row = tid >> 1; + s_codes[swizzle(row, f_c)] = f_codes; + if constexpr (Q5K) s_high[f_c * ROWS + row] = f_high; + const int sb32 = f_sb32; + uint32_t sc, mn; + if (sb32 < 4) { + sc = header_byte(f_header, 4 + sb32) & 0x3FU; + mn = header_byte(f_header, 8 + sb32) & 0x3FU; + } else { + sc = (header_byte(f_header, 8 + sb32) & 0x0FU) | ((header_byte(f_header, sb32) >> 6U) << 4U); + mn = (header_byte(f_header, 8 + sb32) >> 4U) | ((header_byte(f_header, 4 + sb32) >> 6U) << 4U); + } + const __half2 dm = __builtin_bit_cast(__half2, f_header.x); + const float scale = __low2float(dm) * (float) sc, offset = __high2float(dm) * (float) mn; + s_scale[f_c * ROWS + row] = __builtin_bit_cast(uint32_t, __floats2half2_rn(scale, -offset)); + as.commit(s_act); + }; + + v8f acc[BN / 16]; +#pragma unroll + for (int j = 0; j < BN / 16; ++j) acc[j] = v8f{0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}; + + const auto compute_stage = [&]() { + const int row = wave * 16 + sub_lane; // waves 0-3: gate rows, 4-7: the matching up rows + const uint4 raw0 = s_codes[swizzle(row, 0)], raw1 = s_codes[swizzle(row, 1)]; +#pragma unroll + for (int kb = 0; kb < 2; ++kb) { + const __half2 sb = __builtin_bit_cast(__half2, s_scale[kb * ROWS + row]); + const __half2 scale2 = __low2half2(sb), bias2 = __high2half2(sb); + // elements 0-15 of K block 2s + kb are the low (kb = 0) or high (kb = 1) nibbles of chunk 0, 16-31 of chunk 1 + const unsigned shift = 4U * (unsigned) kb; + const uint32_t words[8] = {raw0.x, raw0.y, raw0.z, raw0.w, raw1.x, raw1.y, raw1.z, raw1.w}; + const uint32_t hb = Q5K ? s_high[kb * ROWS + row] : 0U; + __half2 h[16]; +#pragma unroll + for (int i = 0; i < 8; ++i) { + uint32_t nib = (words[i] >> shift) & 0x0F0F0F0FU; + if constexpr (Q5K) nib |= spread_high_bits((hb >> (4 * i)) & 0xFU); + codes_to_halves(nib, magic, scale2, bias2, h[2 * i], h[2 * i + 1]); + } + v16h a_lo, a_hi; + __builtin_memcpy(&a_lo, &h[0], 32); + __builtin_memcpy(&a_hi, &h[8], 32); + mma_tiles(acc, a_lo, a_hi, s_act, kb, sub_lane, live_tiles); + } + }; + + fetch_stage(0); + for (int s = 0; s < GU_NS; ++s) { + commit_stage(); + __syncthreads(); + if (s + 1 < GU_NS) fetch_stage(s + 1); + compute_stage(); + __syncthreads(); + } + gu_epilogue(acc, lds, tid, live_tiles, nrows, row0, fb, out); +#else + (void) b; (void) geo; (void) ts; (void) tiles; (void) off; (void) act; (void) src; (void) out; + __builtin_trap(); +#endif +} + +// Q5_1 down: 128 of the 2560 output rows against a tile's (or pair's) H rows, K = 640 in 10 stages; the routed rows' +// FP32 outputs in `dm` (native_w11_kernel's). +template +__global__ void __launch_bounds__(THREADS) down_kernel(const Batch b, const NativeGeom geo, const int32_t* __restrict__ ts, + const int2* __restrict__ tiles, const int32_t* __restrict__ off, + const uint8_t* __restrict__ h, float* __restrict__ dm) { +#if STRATA_F16_DEVICE + constexpr int CODE_BYTES = ROWS * 2 * 16, HIGH_BYTES = 2 * ROWS * 4, SCALE_BYTES = 2 * ROWS * 4; + constexpr int STAGE_BYTES = CODE_BYTES + HIGH_BYTES + SCALE_BYTES + ActStage::BYTES; + static_assert(D_EPI_BYTES <= STAGE_BYTES, "the epilogue fits the stage"); + __shared__ __attribute__((aligned(16))) uint8_t lds[STAGE_BYTES]; + __shared__ int srow[BN]; + auto* s_codes = reinterpret_cast(lds); + auto* s_high = reinterpret_cast(lds + CODE_BYTES); + auto* s_scale = reinterpret_cast(lds + CODE_BYTES + HIGH_BYTES); + auto* s_act = reinterpret_cast(lds + CODE_BYTES + HIGH_BYTES + SCALE_BYTES); + + const int tid = threadIdx.x, wave = tid >> 5, sub_lane = tid & 15; + const int f_c = tid & 1; // this thread's K block of its weight row + const auto swizzle = [](int row, int c) { return row * 2 + (c ^ ((row >> 2) & 1)); }; + const __half2 magic = __floats2half2_rn(-1024.0f, -1024.0f); + + int fb, e, row0, nrows; + if (!work_item(b, ts, tiles, off, blockIdx.x, fb, e, row0, nrows)) return; + const int live_tiles = (nrows + 15) / 16; + if (tid < BN) srow[tid] = tid < nrows ? row0 + tid : -1; // H is indexed by the routed row + __syncthreads(); + + const uint2* f_ptr = reinterpret_cast(b.blob[e - b.e0] + geo.down_off + (size_t) (fb * ROWS + (tid >> 1)) * geo.d_row); + uint4 f_codes; + uint32_t f_high = 0, f_dm = 0; + ActStage as; + as.init(h, H_LD, srow, tid); + const auto fetch_stage = [&](int s) { + const uint2* words = f_ptr + (2 * s + f_c) * 3; // block_q5_1: {d, m}, qh, qs[16] + const uint2 w0 = words[0], w1 = words[1], w2 = words[2]; + f_codes = make_uint4(w1.x, w1.y, w2.x, w2.y); + f_high = w0.y; + f_dm = w0.x; + as.fetch(s); + }; + const auto commit_stage = [&]() { + const int row = tid >> 1; + s_codes[swizzle(row, f_c)] = f_codes; + s_high[f_c * ROWS + row] = f_high; + s_scale[f_c * ROWS + row] = f_dm; // the half2 (d, m): w = q d + m + as.commit(s_act); + }; + v8f acc[BN / 16]; +#pragma unroll + for (int j = 0; j < BN / 16; ++j) acc[j] = v8f{0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}; + const auto compute_stage = [&]() { + const int row = wave * 16 + sub_lane; + const uint4 raw[2] = {s_codes[swizzle(row, 0)], s_codes[swizzle(row, 1)]}; +#pragma unroll + for (int kb = 0; kb < 2; ++kb) { + const __half2 sb = __builtin_bit_cast(__half2, s_scale[kb * ROWS + row]); + const __half2 scale2 = __low2half2(sb), bias2 = __high2half2(sb); + // elements 0-15 are the low nibbles of the 16 code bytes, 16-31 the high, plus bit j of the high-bit word + const uint32_t words[4] = {raw[kb].x, raw[kb].y, raw[kb].z, raw[kb].w}; + const uint32_t hb = s_high[kb * ROWS + row]; + __half2 hh[16]; +#pragma unroll + for (int i = 0; i < 4; ++i) { + const uint32_t lo = (words[i] & 0x0F0F0F0FU) | spread_high_bits((hb >> (4 * i)) & 0xFU); + const uint32_t hi = ((words[i] >> 4U) & 0x0F0F0F0FU) | spread_high_bits((hb >> (16 + 4 * i)) & 0xFU); + codes_to_halves(lo, magic, scale2, bias2, hh[2 * i], hh[2 * i + 1]); + codes_to_halves(hi, magic, scale2, bias2, hh[8 + 2 * i], hh[8 + 2 * i + 1]); + } + v16h a_lo, a_hi; + __builtin_memcpy(&a_lo, &hh[0], 32); + __builtin_memcpy(&a_hi, &hh[8], 32); + mma_tiles(acc, a_lo, a_hi, s_act, kb, sub_lane, live_tiles); + } + }; + fetch_stage(0); + for (int s = 0; s < D_NS; ++s) { + commit_stage(); + __syncthreads(); + if (s + 1 < D_NS) fetch_stage(s + 1); + compute_stage(); + __syncthreads(); + } + down_epilogue(acc, lds, tid, live_tiles, nrows, row0, fb, dm); +#else + (void) b; (void) geo; (void) ts; (void) tiles; (void) off; (void) h; (void) dm; + __builtin_trap(); +#endif +} + +} // namespace + +bool covers(int gu_type) { return gu_type == T_Q4_K || gu_type == T_Q5_K; } + +bool covers_down(int d_type) { return d_type == GGML_TYPE_Q5_1; } + +void gate_up(const Batch& b, const NativeGeom& g, const int32_t* ts, const int2* tiles, const int32_t* off, int64_t n, + int n_expert, int64_t work_bound, const uint8_t* act, const int32_t* src, uint8_t* out, cudaStream_t s) { + // one block per work item, the grid the batch's bound (gufo's launch: the hardware balances the blocks; the items + // of a tile are consecutive, so they meet its activations in L2) + const unsigned grid = (unsigned) std::max(1, work_bound * GU_NFB); + const bool q5k = g.gu_type == T_Q5_K; + if (pick_bn(n, n_expert) == 2 * kTileRows) { + if (q5k) gate_up_kernel<<>>(b, g, ts, tiles, off, act, src, out); + else gate_up_kernel<<>>(b, g, ts, tiles, off, act, src, out); + } else { + if (q5k) gate_up_kernel<<>>(b, g, ts, tiles, off, act, src, out); + else gate_up_kernel<<>>(b, g, ts, tiles, off, act, src, out); + } +} + +void down(const Batch& b, const NativeGeom& g, const int32_t* ts, const int2* tiles, const int32_t* off, int64_t n, int n_expert, + int64_t work_bound, const uint8_t* h, float* dm, cudaStream_t s) { + const unsigned grid = (unsigned) std::max(1, work_bound * D_NFB); + if (pick_bn(n, n_expert) == 2 * kTileRows) down_kernel<2 * kTileRows><<>>(b, g, ts, tiles, off, h, dm); + else down_kernel<<>>(b, g, ts, tiles, off, h, dm); +} + +} // namespace strata::prefill::fused::f16kq diff --git a/src/prefill/moe_f16_kq.hpp b/src/prefill/moe_f16_kq.hpp new file mode 100644 index 00000000..c7f80eb1 --- /dev/null +++ b/src/prefill/moe_f16_kq.hpp @@ -0,0 +1,30 @@ +// src/prefill/moe_f16_kq.hpp - gfx11: the K-quant prompt experts on the F16 matrix cores (moe_f16_kq.cu; the switch, +// STRATA_PF_F16=1 with STRATA_PF_FUSED_KQ=1, is moe_f16_common.cuh's). +// Internal to moe_fused_iq.cu, which owns the native experts' tables and launches. +#pragma once + +#include + +#include + +#include "strata/prefill/moe_fused.hpp" +#include "strata/prefill/moe_fused_iq.hpp" + +namespace strata::prefill::fused::f16kq { + +/// The gate/up type has a kernel here (and this build has gfx11 device code). +bool covers(int gu_type); + +/// Gate/up, SwiGLU and H for experts [b.e0, b.e1): the same tiles, activations and H as native_w11_kernel. +/// `ts`, `tiles`, `off` are fused::group's tables (at most `work_bound` tiles); `n` the layer's routed rows over +/// `n_expert` experts; `act` the int8 activations (quantize_act_native); `out` H. +void gate_up(const Batch& b, const NativeGeom& g, const int32_t* ts, const int2* tiles, const int32_t* off, int64_t n, + int n_expert, int64_t work_bound, const uint8_t* act, const int32_t* src, uint8_t* out, cudaStream_t s); + +/// The down type has a kernel here (Q5_1). +bool covers_down(int d_type); +/// Down for the same experts and tiles: H (int8, `h`) to the routed rows' FP32 outputs in `dm`. +void down(const Batch& b, const NativeGeom& g, const int32_t* ts, const int2* tiles, const int32_t* off, int64_t n, int n_expert, + int64_t work_bound, const uint8_t* h, float* dm, cudaStream_t s); + +} // namespace strata::prefill::fused::f16kq diff --git a/src/prefill/moe_fused_iq.cu b/src/prefill/moe_fused_iq.cu index ce2ca76f..637f0ec3 100644 --- a/src/prefill/moe_fused_iq.cu +++ b/src/prefill/moe_fused_iq.cu @@ -22,6 +22,11 @@ #include "strata/prefill/moe_fused_iq.hpp" #include "strata/kernels/gfx_arch.hpp" +#if defined(__HIPCC__) +#include "moe_f16_common.cuh" +#include "moe_f16_kq.hpp" +#endif + #include #include @@ -678,15 +683,33 @@ native_kernel(const Batch b, const NativeGeom geo, const Tables tb, const uint8_ #else #define NW_DROW(i, hi) (2 * (i) + (hi)) #endif -// The VGPR cap of the occupancy variant (amdgpu_waves_per_eu). 8 was measured against ROCm 7's clang; clang 22 (ROCm 7.10) -// computes wrong results with it (#1180: gfx1100, every run), so there the cap is off. -DSTRATA_W_LB=N sets it. +// The VGPR cap of the occupancy variant (amdgpu_waves_per_eu). 8 was measured against a clang before 22; clang 22 +// (ROCm 7.10) computes wrong results with it (#1180: gfx1100, every run), so from clang 22 the cap is off - except for +// gfx1151 on clang 23, where the capped kernels give the same bits and take less time (measured with ROCm 7.14.1's +// clang 23, hip_prefill_fused_iq, one layer, 2048-8192 tokens: gate/up IQ2_XXS / IQ3_XXS / IQ3_S / IQ4_XS with down +// Q2_0 / IQ4_NL 8-15%; IQ2_S / Q2_0 2-4%, from its Q2_0 down: IQ2_S's LDS leaves room for 3 blocks per WGP, so the +// compiler keeps its 238 VGPRs). Two formats stay uncapped there: IQ2_XS gate/up spills 104 VGPRs under the cap and +// takes 61-66% more time, and Q8_0 down (18 spilled) took -1.9% to +1.9% time. The test is the clang major version: +// other clang 23 builds are not measured, and clang 24 and newer keep the clang 22 rule. NW_LB is the variant's +// template argument, the same in the host and every device pass (the launch names that instance); whether its cap +// applies is decided per architecture and format in the device pass (nw_capped). -DSTRATA_W_LB=N sets the cap on +// every architecture and format. #if defined(STRATA_W_LB) constexpr int NW_LB = STRATA_W_LB; -#elif defined(__clang_major__) && __clang_major__ >= 22 -constexpr int NW_LB = 1; #else constexpr int NW_LB = 8; #endif +constexpr bool nw_capped(int wt) { +#if defined(STRATA_W_LB) || !defined(__clang_major__) || __clang_major__ < 22 + (void) wt; + return true; +#elif defined(__gfx1151__) && __clang_major__ == 23 + return wt != T_IQ2_XS && wt != T_Q8_0; +#else + (void) wt; + return false; +#endif +} typedef int nw_i4 __attribute__((ext_vector_type(4))); typedef int nw_i2 __attribute__((ext_vector_type(2))); typedef int nw_i8 __attribute__((ext_vector_type(8))); @@ -714,10 +737,11 @@ __device__ __forceinline__ nw_i8 nw_wmma(nw_ab a, nw_ab b, nw_i8 c) { #endif } -// W (X1): ALIAS = the H tile lives on the weight buffers (one extra barrier); LB > 0 = amdgpu_waves_per_eu(LB) (VGPR cap). +// W (X1): ALIAS = the H tile lives on the weight buffers (one extra barrier); LB > 0 = amdgpu_waves_per_eu(LB) (VGPR cap) +// where nw_capped(WT) says the cap applies. // Disable both with -DSTRATA_W_NO_OCC (the launch sites then use and grid factor wgp_blocks). template -__global__ void __launch_bounds__(NW_THREADS) __attribute__((amdgpu_waves_per_eu(LB > 0 ? LB : 1))) +__global__ void __launch_bounds__(NW_THREADS) __attribute__((amdgpu_waves_per_eu(LB > 0 && nw_capped(WT) ? LB : 1))) native_w11_kernel(const Batch b, const NativeGeom geo, const Tables tb, const uint8_t* __restrict__ act, const int32_t* __restrict__ src, uint8_t* __restrict__ out, float* __restrict__ dm) { #if STRATA_NAT_WMMA @@ -955,6 +979,133 @@ native_w11_kernel(const Batch b, const NativeGeom geo, const Tables tb, const ui __builtin_trap(); #endif } + +// STRATA_PF_F16=1 (gfx11): the other native formats on the F16 matrix cores - moe_f16_common.cuh's work item, +// staged activations and epilogues. load_unit / convert decode each sub-block once into the weight tile in LDS (int8 +// codes, the scales as half2), and each wave turns its own 16 rows into F16 before its products. Gate/up rows 0..63 +// are the item's gate rows, 64..127 its up rows; down rows are output rows. The output differs from +// native_w11_kernel's (F16 products instead of int8 dots with float scales). +// gfx1151, IQ3_S / IQ4_NL, 16384 tokens x top 10 over 512 experts, one 128-expert launch (ms, native_w11_kernel -> +// this): gate/up 11.65 -> 9.87, down 6.11 -> 4.71; weights decoded to F16 in LDS (18 KB a block) were 9.83 and 5.71. +template +__global__ void __launch_bounds__(f16::THREADS) +native_f16_kernel(const Batch b, const NativeGeom geo, const Tables tb, const uint8_t* __restrict__ act, + const int32_t* __restrict__ src, uint8_t* __restrict__ out, float* __restrict__ dm) { +#if STRATA_F16_DEVICE + // (moe_fused_iq.cu has its own THREADS and AB: the f16 names are qualified where they collide) + using namespace f16; + constexpr int NS = (GU ? GU_ROWS_K : D_ROWS_K) / 64; // 64-value stages along K + constexpr int NFB = GU ? GU_NFB : D_NFB; + constexpr int RW = raw_words(WT); + constexpr int BS = block_bytes(WT); + constexpr bool K16 = per16(WT); + constexpr int GB = grid_bytes(WT) > 0 ? grid_bytes(WT) : 16; + constexpr int SGN = (WT == T_IQ2_XXS || WT == T_IQ2_XS || WT == T_IQ2_S || WT == T_IQ3_XXS || WT == T_IQ3_S) + ? sign_entries(WT) : 1; + constexpr int WLD8 = 80; // bytes per weight row: 64 int8 codes + 16 (rows 80 bytes apart spread a fragment read) + constexpr int W_BYTES = ROWS * WLD8 + 2 * ROWS * 4; // the codes, then the (s0, s1) half2 per row and sub-block + constexpr int STAGE_BYTES = W_BYTES + ActStage::BYTES; + static_assert(GU_EPI_BYTES <= STAGE_BYTES && D_EPI_BYTES <= STAGE_BYTES, "the epilogues fit the stage"); + __shared__ __align__(16) uint8_t lds[STAGE_BYTES]; + __shared__ __align__(16) uint8_t sgrid[GB]; + __shared__ __align__(16) uint4 ssign[SGN]; + __shared__ int srow[BN]; + uint8_t* s_w = lds; + auto* s_sc = reinterpret_cast(lds + ROWS * WLD8); + auto* s_act = reinterpret_cast(lds + W_BYTES); + const int tid = threadIdx.x, wave = tid >> 5, sub_lane = tid & 15; + + int fb, e, row0, nrows; + if (!work_item(b, tb.ts, tb.tiles, tb.off, blockIdx.x, fb, e, row0, nrows)) return; + if constexpr (grid_bytes(WT) > 0) { + const uint32_t* gs = (const uint32_t*) grid_src(); + for (int i = tid; i < grid_bytes(WT) / 4; i += f16::THREADS) ((uint32_t*) sgrid)[i] = gs[i]; + } + if constexpr (SGN > 1) { + for (int i = tid; i < SGN; i += f16::THREADS) ssign[i] = sign_entry(i, SGN == 128); + } + uint32_t kv[4] = {0, 0, 0, 0}; + if constexpr (WT == T_IQ4_XS || WT == T_IQ4_NL) { +#pragma unroll + for (int k = 0; k < 16; ++k) kv[k >> 2] |= (uint32_t) (uint8_t) kvalues_iq4nl[k] << (8 * (k & 3)); + } + const int live_tiles = (nrows + 15) / 16; + const uint8_t* blob = b.blob[e - b.e0]; + if (tid < BN) srow[tid] = tid < nrows ? (GU ? src[row0 + tid] : row0 + tid) : -1; // tokens; H by routed row + __syncthreads(); + + const int ur = tid >> 1, uj = tid & 1; // this thread's decode unit: weight-tile row ur, sub-block uj of a stage + const uint8_t* wrow = GU ? blob + (ur >= 64 ? geo.up_off : 0) + (size_t) (fb * 64 + (ur & 63)) * geo.gu_row + : blob + geo.down_off + (size_t) (fb * ROWS + ur) * geo.d_row; + const auto unit = [&](int s) -> const uint8_t* { + if (GU) return wrow + (s >> 2) * BS; + return (WT == T_IQ4_NL || WT == T_Q8_0) ? wrow + (2 * s + uj) * BS : wrow + s * BS; + }; + const auto sub = [&](int s) { return GU ? 2 * (s & 3) + uj : uj; }; + uint32_t raw[RW]; + ActStage as; + as.init(act, GU ? GU_ACT_LD : H_LD, srow, tid); + const auto fetch_stage = [&](int s) { + load_unit(unit(s), sub(s), raw); + as.fetch(s); + }; + // the sub-block as int8 codes and its scales into the weight tile + const auto commit_stage = [&]() { + uint32_t q[8]; + float s0, s1; + convert(raw, sgrid, kv, q, s0, s1, ssign); + uint4* d = reinterpret_cast(s_w + ur * WLD8 + 32 * uj); + d[0] = make_uint4(q[0], q[1], q[2], q[3]); + d[1] = make_uint4(q[4], q[5], q[6], q[7]); + s_sc[uj * ROWS + ur] = __builtin_bit_cast(uint32_t, __floats2half2_rn(s0, K16 ? s1 : s0)); + as.commit(s_act); + }; + v8f acc[BN / 16]; +#pragma unroll + for (int j = 0; j < BN / 16; ++j) acc[j] = v8f{0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}; + // int8 codes to F16 per wave (gufo's Q8_0 decode): the sign bit flipped carries q + 128, a byte permute makes it + // the mantissa of 1024 (exact), minus 1152 is q, then one packed multiply by the sub-block's scale + const __half2 magic = __floats2half2_rn(-1152.0f, -1152.0f), zero2 = __floats2half2_rn(0.0f, 0.0f); + const auto compute_stage = [&]() { + const int row = wave * 16 + sub_lane; + const uint4* wp = reinterpret_cast(s_w + row * WLD8); +#pragma unroll + for (int kb = 0; kb < 2; ++kb) { + const uint4 c0 = wp[2 * kb], c1 = wp[2 * kb + 1]; + const __half2 sc = __builtin_bit_cast(__half2, s_sc[kb * ROWS + row]); + const __half2 sc0 = __low2half2(sc), sc1 = __high2half2(sc); + const uint32_t words[8] = {c0.x, c0.y, c0.z, c0.w, c1.x, c1.y, c1.z, c1.w}; + uint32_t hw[16]; +#pragma unroll + for (int i = 0; i < 8; ++i) { // values 4i .. 4i + 3 (s0: values 0-15, s1: 16-31) + const uint32_t c = words[i] ^ 0x80808080u; + const uint32_t p0 = __builtin_amdgcn_perm(c, 0x64646464u, 0x01050004u); + const uint32_t p1 = __builtin_amdgcn_perm(c, 0x64646464u, 0x03070206u); + const __half2 s2 = i < 4 ? sc0 : sc1; + hw[2 * i] = __builtin_bit_cast(uint32_t, __hfma2(__hadd2(__builtin_bit_cast(__half2, p0), magic), s2, zero2)); + hw[2 * i + 1] = __builtin_bit_cast(uint32_t, __hfma2(__hadd2(__builtin_bit_cast(__half2, p1), magic), s2, zero2)); + } + v16h a_lo, a_hi; + __builtin_memcpy(&a_lo, &hw[0], 32); + __builtin_memcpy(&a_hi, &hw[8], 32); + mma_tiles(acc, a_lo, a_hi, s_act, kb, sub_lane, live_tiles); + } + }; + fetch_stage(0); + for (int s = 0; s < NS; ++s) { + commit_stage(); + __syncthreads(); + if (s + 1 < NS) fetch_stage(s + 1); + compute_stage(); + __syncthreads(); + } + if constexpr (GU) gu_epilogue(acc, lds, tid, live_tiles, nrows, row0, fb, out); + else down_epilogue(acc, lds, tid, live_tiles, nrows, row0, fb, dm); +#else + (void) b; (void) geo; (void) tb; (void) act; (void) src; (void) out; (void) dm; + __builtin_trap(); +#endif +} #endif // __HIPCC__ unsigned blocks(int64_t n, int per) { return (unsigned) ((n + per - 1) / per); } @@ -1073,6 +1224,11 @@ bool kq_on() { }(); return on; } +// STRATA_PF_F16=1 (gfx11): the formats native_f16_kernel takes (the K-quants are moe_f16_kq.cu's) +bool f16_gu(int t) { + return t == T_IQ2_XXS || t == T_IQ2_XS || t == T_IQ2_S || t == T_IQ3_XXS || t == T_IQ3_S || t == T_IQ4_XS; +} +bool f16_d(int t) { return t == T_Q2_0 || t == T_IQ4_NL || t == T_Q8_0; } bool gu_covered(int t) { return t == T_IQ2_XXS || t == T_IQ2_XS || t == T_IQ2_S || t == T_IQ3_XXS || t == T_IQ3_S || t == T_IQ4_XS #if defined(__HIPCC__) @@ -1087,6 +1243,16 @@ bool d_covered(int t) { #endif ; } +// d_covered on this device: STRATA_PF_F16=1 also takes Q8_0 down on gfx11 without STRATA_PF_FUSED_KQ - the F16 kernel +// has no minimum term, and its output already differs from the int8 kernels' (UD-IQ4_XS: the five Q8_0-down layers +// would otherwise leave the fused path for MMQ). +bool d_covered_on(int t, const DevInfo& d) { +#if defined(__HIPCC__) + if (t == T_Q8_0 && !d.w12 && f16::requested()) return true; +#endif + (void) d; + return d_covered(t); +} template void launch(int ww, unsigned grid, const Batch& b, const NativeGeom& g, const Tables& tb, const void* act, @@ -1128,14 +1294,15 @@ bool native_supported(int gu_type, int d_type) { const char* v = std::getenv("STRATA_PF_FUSED"); return v == nullptr || v[0] == '\0' ? -1 : (v[0] == '1' ? 1 : 0); }(); - if (off || env == 0 || !gu_covered(gu_type) || !d_covered(d_type)) return false; + if (off || env == 0 || !gu_covered(gu_type)) return false; #if !defined(__HIPCC__) if (env < 0) return false; // the default is gfx12 (HIP) only #endif if (env < 0 && gu_type != T_IQ3_S && gu_type != T_IQ3_XXS) return false; // default: only these two const DevInfo& d = dev_info(); - if (env < 0) return d.ok && d.w12; - return d.ok && (requested() || d.w12); + if (!d.ok || !d_covered_on(d_type, d)) return false; + if (env < 0) return d.w12; + return requested() || d.w12; } void quantize_act_native(const float* x, int64_t rows, int64_t cols, void* xa, void* stream) { @@ -1149,7 +1316,7 @@ void experts_native(const Batch& b, const NativeGeom& g, int n_expert, int64_t n const int32_t* src, void* ha, float* dm, void* stream) { if (b.e1 <= b.e0 || n <= 0) return; const DevInfo& d = dev_info(); - if (!d.ok || !gu_covered(g.gu_type) || !d_covered(g.d_type)) { + if (!d.ok || !gu_covered(g.gu_type) || !d_covered_on(g.d_type, d)) { std::fprintf(stderr, "prefill fused experts (native): types %d / %d are not covered here\n", g.gu_type, g.d_type); std::exit(1); } @@ -1161,6 +1328,8 @@ void experts_native(const Batch& b, const NativeGeom& g, int n_expert, int64_t n // W (X1): LDS alias of the H tile + waves_per_eu(8) (192 VGPRs) + 4 blocks per WGP, only for the types whose // kernels do not spill under the cap (measured: gate/up IQ2_*, IQ3_*, IQ4_XS 0-5 regs; down IQ4_NL 11, Q8_0 / Q2_0 0; // Q4_K / Q5_K gate/up and Q5_1 down spill 100+ and keep the old launch). + // Those counts are from a clang before 22; from clang 22 nw_capped decides which of these kernels get the cap + // (above NW_LB), and the launch is the same. #ifdef STRATA_W_NO_OCC const bool occ_gu = false, occ_d = false; #else @@ -1179,7 +1348,29 @@ void experts_native(const Batch& b, const NativeGeom& g, int n_expert, int64_t n const uint8_t* xa8 = (const uint8_t*) xa; uint8_t* ha8 = (uint8_t*) ha; #define STRATA_NW_GU(T) do { if (occ_gu) native_w11_kernel<<>>(b, g, tb, xa8, src, ha8, nullptr); else native_w11_kernel<<>>(b, g, tb, xa8, src, ha8, nullptr); } while (0) - switch (g.gu_type) { + // STRATA_PF_F16=1: gfx11's F16 matrix cores - the K-quants' kernels (moe_f16_kq.cu) and native_f16_kernel for + // f16_gu / f16_d (gfx12's WMMA layout differs, so it keeps the int8 kernels) + const bool f16 = !d.w12 && f16::requested(); + const bool f16_wide = f16::pick_bn(n, n_expert) == 2 * kTileRows; +#define STRATA_F16_LAUNCH(T, GU, NFB, ACT, OUT, DM) do { \ + const unsigned grid_f = (unsigned) std::max(1, tiles * (NFB)); \ + if (f16_wide) native_f16_kernel<<>>(b, g, tb, ACT, src, OUT, DM); \ + else native_f16_kernel<<>>(b, g, tb, ACT, src, OUT, DM); \ +} while (0) + if (f16 && f16kq::covers(g.gu_type)) f16kq::gate_up(b, g, tb.ts, tb.tiles, tb.off, n, n_expert, tiles, xa8, src, ha8, s); + else if (f16 && f16_gu(g.gu_type)) { +#define STRATA_F16_GU(T) STRATA_F16_LAUNCH(T, true, f16::GU_NFB, xa8, ha8, nullptr) + switch (g.gu_type) { + case T_IQ2_XXS: STRATA_F16_GU(T_IQ2_XXS); break; + case T_IQ2_XS: STRATA_F16_GU(T_IQ2_XS); break; + case T_IQ2_S: STRATA_F16_GU(T_IQ2_S); break; + case T_IQ3_XXS: STRATA_F16_GU(T_IQ3_XXS); break; + case T_IQ3_S: STRATA_F16_GU(T_IQ3_S); break; + default: STRATA_F16_GU(T_IQ4_XS); break; + } +#undef STRATA_F16_GU + } + else switch (g.gu_type) { case T_IQ2_XXS: STRATA_NW_GU(T_IQ2_XXS); break; case T_IQ2_XS: STRATA_NW_GU(T_IQ2_XS); break; case T_IQ2_S: STRATA_NW_GU(T_IQ2_S); break; @@ -1191,11 +1382,18 @@ void experts_native(const Batch& b, const NativeGeom& g, int n_expert, int64_t n } #undef STRATA_NW_GU #define STRATA_NW_D(T) do { if (occ_d) native_w11_kernel<<>>(b, g, tb, ha8, src, nullptr, dm); else native_w11_kernel<<>>(b, g, tb, ha8, src, nullptr, dm); } while (0) - if (g.d_type == T_Q2_0) STRATA_NW_D(T_Q2_0); + if (f16 && f16kq::covers_down(g.d_type)) f16kq::down(b, g, tb.ts, tb.tiles, tb.off, n, n_expert, tiles, ha8, dm, s); + else if (f16 && f16_d(g.d_type)) { + if (g.d_type == T_Q2_0) STRATA_F16_LAUNCH(T_Q2_0, false, f16::D_NFB, ha8, nullptr, dm); + else if (g.d_type == T_Q8_0) STRATA_F16_LAUNCH(T_Q8_0, false, f16::D_NFB, ha8, nullptr, dm); + else STRATA_F16_LAUNCH(T_IQ4_NL, false, f16::D_NFB, ha8, nullptr, dm); + } + else if (g.d_type == T_Q2_0) STRATA_NW_D(T_Q2_0); else if (g.d_type == T_Q5_1) STRATA_NW_D(T_Q5_1); else if (g.d_type == T_Q8_0) STRATA_NW_D(T_Q8_0); else STRATA_NW_D(T_IQ4_NL); #undef STRATA_NW_D +#undef STRATA_F16_LAUNCH ck(cudaGetLastError(), "experts_native"); return; } diff --git a/src/program/generate.cpp b/src/program/generate.cpp index a183866f..158f6785 100644 --- a/src/program/generate.cpp +++ b/src/program/generate.cpp @@ -669,7 +669,7 @@ struct Options { /// Plan v0.3 P6: the share (0..1) of each layer's distinct missed experts the GPU reads over PCIe from the /// pinned arena while the CPU computes the rest (verify windows). double pcie_frac = -1.0; ///< < 0: the model's default (0.2 direct for the Q2_0 pack, 0.55 DMA for native packs) - bool pcie_frac_auto = false; ///< CUDA single-GPU serve, no --pcie-frac: the share is refined in the first decode windows (PcieAuto) + bool pcie_frac_auto = false; ///< single-GPU serve (CUDA + HIP/gfx1100), no --pcie-frac: the share is refined in the first decode windows (PcieAuto) double pcie_probe_gbps = 0.0; ///< the start-up probe's reading (for PcieAuto) std::string pcie_mode = "auto"; ///< auto | dma | kernel | direct /// Plan v0.3 P6: every `adapt_every` rounds, swap up to `adapt_swaps` of the most-routed missing experts into @@ -1923,6 +1923,20 @@ static bool pcie_auto_split_ok() { #endif } +// HIP outside gfx12: the same refinement, opt-in with STRATA_PCIE_FRAC_DEFAULT=auto (#2224). Its author gate-measured it on an +// RX 7900 XTX (gfx1100) as "no regression" only (4 alternating starts at 64K, prefill 2189 base vs 2180 with it, decode 65.4 vs +// 65.4; under serve the share refines 0.55 -> 0.25 from the pool's 42-45 us/missed expert and the probed 28.4-28.5 GB/s link); +// a second report (2x RX 7900 GRE) found it never engages there (95-98% of the experts cached). The gain is measured only on +// gfx1201 (where it is the default, decode_defaults_arch_ok), so the other parts keep the fixed share unless asked. +[[maybe_unused]] static bool pcie_auto_fork_arch_ok() { +#if defined(STRATA_USE_HIP) + const char* pfd = std::getenv("STRATA_PCIE_FRAC_DEFAULT"); + return pfd != nullptr && std::strcmp(pfd, "auto") == 0; +#else + return false; +#endif +} + // The effective host->device bandwidth of the PCIe link: copies from pinned host memory, as the expert arena's // reads are. The native default share (0.55) was measured on x16 links (~26-28 GB/s); a x8 card in a x8 slot // carries about half of that. Returns < 0 when the probe cannot run (then the caller keeps the default). @@ -3274,7 +3288,11 @@ int main(int argc, char** argv) { o.pcie_frac = pcie_frac_for_gbps(bw, base); std::fprintf(stderr, "strata generate: PCIe probe: %.1f GB/s host->device (best of %s) -> pcie_frac %.2f " "(default %.2f)\n", bw, bursts.c_str(), o.pcie_frac, base); - o.pcie_frac_auto = (o.layer_split.empty() || pcie_auto_split_ok()) && decode_defaults_arch_ok() && !pf_old; + // 0.1.43: split opt-in + gfx12 default-on (decode_defaults_arch_ok). Other HIP parts: STRATA_PCIE_FRAC_DEFAULT=auto + // turns the refinement on (pcie_auto_fork_arch_ok); the pool timings and miss counts it reads are engine-generic. + // STRATA_PCIE_FRAC_DEFAULT=old keeps the start-up rule everywhere. + o.pcie_frac_auto = (o.layer_split.empty() || pcie_auto_split_ok()) && !pf_old && + (decode_defaults_arch_ok() || pcie_auto_fork_arch_ok()); o.pcie_probe_gbps = bw; } else { o.pcie_frac = base; @@ -12509,10 +12527,20 @@ int main(int argc, char** argv) { // through its own cache and its own device - a slot refilled into the wrong cache would leave that // stage's cache holding an expert it does not own, which is silent and produces plausible tokens. // (split in two halves so a layer split can queue every stage's copies before it waits for any: #340) + // STRATA_REFILL_PARTS=1 (gfx1151's table): a lent slot of a GGUF read in place is refilled from the pieces in the mapping. + // The default assembles the blob in a staging buffer first (a 4 MB copy on this thread), then copies that. + static const bool refill_parts = [] { const char* v = std::getenv("STRATA_REFILL_PARTS"); return v != nullptr && std::atoi(v) != 0; }(); auto refill_issue = [&](PfPart& p, std::string& e) -> bool { tr("refill start", (long long) p.lent.size()); const strata::core::OnDevice on(p.dev); for (const auto& [i, slot] : p.lent) { // D-4: queued, one wait (STRATA_REFILL_BLOCKING=1: each) + strata::core::BlobPart parts[3]; + const int np = refill_parts && !refill_blocking() ? srcp->blob_parts(i / g.n_expert, i % g.n_expert, parts) : 0; + if (np > 0) { // the GGUF read in place: the tensors' pieces go from the mapping to the slot, no assembled copy + if (!p.cache->fill_slot_queued_parts(slot, parts, np, e)) return false; + host_res[(size_t) i] = slot; + continue; + } const uint8_t* b = srcp->blob_stable(i / g.n_expert, i % g.n_expert); const int64_t nb = (int64_t) strata::kernels::cpu::expert_layout().blob_bytes(i / g.n_expert); if (b == nullptr || !(refill_blocking() ? p.cache->fill_slot_blocking(slot, b, e, nb) diff --git a/tests/cuda/prefill_fused_iq_test.cpp b/tests/cuda/prefill_fused_iq_test.cpp index ebab9b54..af6099c1 100644 --- a/tests/cuda/prefill_fused_iq_test.cpp +++ b/tests/cuda/prefill_fused_iq_test.cpp @@ -78,6 +78,12 @@ struct Geo { }; // random blocks with a sane fp16 scale `d` at each block's start (every format here begins with it): scales chosen so +// STRATA_PF_F16=1: the covered formats run on F16 weights (moe_f16_kq.cu, native_f16_kernel), not the int8 kernels +bool f16_on() { + const char* v = std::getenv("STRATA_PF_F16"); + return v != nullptr && v[0] == '1'; +} + // that the weights' typical size is that of a 2-3 bit expert (a few hundredths) void fill_matrix(uint8_t* m, ggml_type t, int64_t rows, int64_t cols, std::mt19937& rng) { const size_t bs = ggml_type_size(t), nb = (size_t) rows * (size_t) (cols / ggml_blck_size(t)); @@ -397,7 +403,9 @@ void reference_part(const Pair& p, cudaStream_t s) { const Err e2 = compare(y_f, frow, ref2, pair, (size_t) rows); std::printf(" fused vs the int8-rounded model (same activation / H rounding, double sums): rel RMS %.3e worst %.3e\n", e2.rms, e2.worst); - if (e2.rms > 2e-3 || e2.worst > 3e-2) + // STRATA_PF_F16=1: H's int8 rounding meets values a few F16 ulps from the int8 model's (f16_on); the FP32 reference + // checks below stay as they are + if (e2.rms > (f16_on() ? 5e-3 : 2e-3) || e2.worst > 3e-2) throw std::runtime_error(std::string(p.name) + ": the fused path differs from its own arithmetic's model"); if (mq) std::printf(" MMQ vs FP32 reference: rel RMS %.3e worst row max rel %.3e\n", em.rms, em.worst); std::printf(" fused vs FP32 reference: rel RMS %.3e worst row max rel %.3e\n", ef.rms, ef.worst); @@ -627,7 +635,8 @@ void timing_part(const Pair& p, int T, cudaStream_t s) { cudaEventDestroy(b); delete mbp; // the two int8 paths at the real shape, every tile of the layer: R9700 rel RMS 1.3-1.9e-4, worst row 2.9e-3-8.3e-3 - if (mq && !no_mmq && (efm.rms > 1e-3 || efm.worst > 2e-2)) + // (STRATA_PF_F16=1: F16 products against MMQ's int8, gfx1151 rel RMS 2.5-2.7e-3, worst row 6.4e-3-8.8e-3) + if (mq && !no_mmq && (efm.rms > (f16_on() ? 5e-3 : 1e-3) || efm.worst > 2e-2)) throw std::runtime_error(std::string(p.name) + ": the paths disagree at the real shape"); } } // namespace diff --git a/tests/hip/gdn_chunked.cpp b/tests/hip/gdn_chunked.cpp new file mode 100644 index 00000000..a0f29cf2 --- /dev/null +++ b/tests/hip/gdn_chunked.cpp @@ -0,0 +1,235 @@ +// Exercise the public opt-in dispatch, including tails, padded rows and a nonzero carried state. The FP32 +// recurrence is the all-head reference; short cases also use an independent double-precision CPU recurrence. +#include "strata/prefill/kernels.hpp" +#include "strata/kernels/gfx_arch.hpp" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace { +constexpr int S = 128, HK = 16, HV = 48, C = 10240, ROW = HV * S; +constexpr uint16_t SENTINEL = 0x7bff; +void ck(cudaError_t e, const char* where) { + if (e != cudaSuccess) { std::fprintf(stderr, "%s: %s\n", where, cudaGetErrorString(e)); std::exit(2); } +} +void setting(const char* key, const char* value) { +#ifdef _WIN32 + if (_putenv_s(key, value)) std::exit(2); +#else + if (setenv(key, value, 1)) std::exit(2); +#endif +} +template X* upload(const std::vector& v) { + X* p = nullptr; + ck(cudaMalloc(&p, v.size() * sizeof(X)), "malloc"); + ck(cudaMemcpy(p, v.data(), v.size() * sizeof(X), cudaMemcpyHostToDevice), "upload"); + return p; +} +template std::vector download(const X* p, size_t n) { + std::vector v(n); + ck(cudaMemcpy(v.data(), p, n * sizeof(X), cudaMemcpyDeviceToHost), "download"); + return v; +} +float half(uint16_t bits) { __half_raw x; x.x = bits; return __half2float(__half(x)); } +struct Error { + double square = 0, reference = 0, max_error = 0, max_reference = 0; + bool finite = true; + void add(double a, double b) { + finite &= std::isfinite(a) && std::isfinite(b); + square += (a - b) * (a - b); reference += a * a; + max_error = std::max(max_error, std::fabs(a - b)); max_reference = std::max(max_reference, std::fabs(a)); + } + double rms() const { return std::sqrt(square / std::max(reference, 1e-30)); } + bool ok() const { return finite && rms() <= 0.003 && max_error <= 0.02 * max_reference + 1e-5; } +}; +struct Input { + int64_t n; + std::vector h, gate, beta, z, gamma, state; + Input(int64_t t, float decay, float scale, bool no_update) : n(t), h(std::max(t, 1) * C), + gate(std::max(t, 1) * HV), beta(gate.size()), z(std::max(t, 1) * ROW), + gamma(S), state(S * ROW) { + std::mt19937 rng(11); + std::normal_distribution normal(0, 1); + std::uniform_real_distribution uniform(0, 1); + for (auto& x : h) x = normal(rng); + for (int64_t i = 0; i < t; ++i) { + float* row = h.data() + i * C; + for (int head = 0; head < 2 * HK; ++head) { + double norm = 0; + for (int d = 0; d < S; ++d) norm += double(row[head * S + d]) * row[head * S + d]; + for (int d = 0; d < S; ++d) row[head * S + d] /= std::sqrt(norm + 1e-6); + } + for (int d = 2 * HK * S; d < C; ++d) row[d] *= scale; + } + for (auto& x : gate) x = -decay * uniform(rng); + for (auto& x : beta) x = no_update ? 0 : uniform(rng); + for (auto& x : z) x = normal(rng); + for (auto& x : gamma) x = 0.5f + uniform(rng); + for (auto& x : state) x = 0.1f * scale * normal(rng); + } +}; +struct Output { std::vector y; std::vector state; }; +Output run(const Input& in, int ld, bool reference, int64_t split = 0) { + auto h = upload(in.h), g = upload(in.gate), b = upload(in.beta), z = upload(in.z), gm = upload(in.gamma); + auto state = upload(in.state); + auto y = upload(std::vector(std::max(in.n, 1) * ld + 8, SENTINEL)); + // The chunked path owns y as temporary storage; only y16 and state are observable outputs. + auto scratch = upload(std::vector(std::max(in.n, 1) * ROW)); + auto call = [&](int64_t start, int64_t n) { + if (reference) + strata::prefill::gdn_recurrence_variant(5, state, h + start * C, g + start * HV, b + start * HV, + z + start * ROW, gm, 1e-6f, scratch, y + start * ld, n, nullptr, ld); + else + strata::prefill::gdn_recurrence(state, h + start * C, g + start * HV, b + start * HV, + z + start * ROW, gm, 1e-6f, scratch, y + start * ld, n, nullptr, ld); + ck(cudaDeviceSynchronize(), "recurrence"); + }; + if (split) { call(0, split); call(split, in.n - split); } + else call(0, in.n); + Output out{download(y, std::max(in.n, 1) * ld + 8), download(state, in.state.size())}; + ck(cudaFree(h), "free"); ck(cudaFree(g), "free"); ck(cudaFree(b), "free"); ck(cudaFree(z), "free"); + ck(cudaFree(gm), "free"); ck(cudaFree(state), "free"); ck(cudaFree(y), "free"); ck(cudaFree(scratch), "free"); + return out; +} +bool compare(const Input& in, int ld, const Output& ref, const Output& got, bool exact, const char* label) { + Error y, state; + bool guards = true, bits = true; + for (int64_t t = 0; t < in.n; ++t) { + for (int d = 0; d < ROW; ++d) { + y.add(half(ref.y[t * ld + d]), half(got.y[t * ld + d])); + bits &= ref.y[t * ld + d] == got.y[t * ld + d]; + } + for (int d = ROW; d < ld; ++d) guards &= got.y[t * ld + d] == SENTINEL; + } + for (size_t i = in.n * ld; i < got.y.size(); ++i) guards &= got.y[i] == SENTINEL; + for (size_t i = 0; i < got.state.size(); ++i) { + state.add(ref.state[i], got.state[i]); + bits &= std::memcmp(&ref.state[i], &got.state[i], sizeof(float)) == 0; + } + const bool ok = guards && (exact ? bits : y.ok() && state.ok()); + std::printf("%s %s T=%lld ld=%d exact=%d y_rms=%.3e y_max=%.3e state_rms=%.3e guards=%d\n", + ok ? "PASS" : "FAIL", label, (long long) in.n, ld, exact, y.rms(), y.max_error, state.rms(), guards); + return ok; +} +bool cpu_check(const Input& in, int ld, const Output& got) { + Error y, state; + for (int vh : {0, 23, 47}) { + const int qh = vh % HK; + std::vector s(S * S), output(S), delta(S); + for (int r = 0; r < S; ++r) + for (int c = 0; c < S; ++c) s[r * S + c] = in.state[r * ROW + vh * S + c]; + for (int64_t t = 0; t < in.n; ++t) { + const float* row = in.h.data() + t * C; + const float* q = row + qh * S; + const float* k = row + HK * S + qh * S; + const float* v = row + 2 * HK * S + vh * S; + const double decay = std::exp(in.gate[t * HV + vh]), beta = in.beta[t * HV + vh]; + for (auto& x : s) x *= decay; + for (int c = 0; c < S; ++c) { + double prediction = 0; + for (int r = 0; r < S; ++r) prediction += k[r] * s[r * S + c]; + delta[c] = beta * (v[c] - prediction); + } + double norm = 0; + for (int c = 0; c < S; ++c) { + double o = 0; + for (int r = 0; r < S; ++r) { s[r * S + c] += k[r] * delta[c]; o += q[r] * s[r * S + c]; } + output[c] = o / std::sqrt(double(S)); norm += output[c] * output[c]; + } + for (int c = 0; c < S; ++c) { + const double value = output[c] / std::sqrt(norm / S + 1e-6) * in.gamma[c] + / (1 + std::exp(-in.z[t * ROW + vh * S + c])); + y.add(value, half(got.y[t * ld + vh * S + c])); + } + } + for (int r = 0; r < S; ++r) + for (int c = 0; c < S; ++c) state.add(s[r * S + c], got.state[r * ROW + vh * S + c]); + } + const bool ok = y.ok() && state.ok(); + std::printf("%s CPU T=%lld y_rms=%.3e state_rms=%.3e\n", ok ? "PASS" : "FAIL", (long long) in.n, y.rms(), state.rms()); + return ok; +} +// One path's time for one layer's recurrence + norm (GPU-event median of 7 runs after 2 warmups, the same start state each +// run). STRATA_GDN_CHUNKED is read once per process, so --bench (this path) and --bench-default (gfx1151's default: the +// existing kernels with STRATA_GDN_PP=2 and STRATA_GDN_NOY=1) are separate runs of this binary. +void bench(const char* path) { + for (int64_t t : {64, 256, 2048, 16384, 32768}) { + const Input in(t, 2, 1, false); + auto h = upload(in.h), g = upload(in.gate), b = upload(in.beta), z = upload(in.z), gm = upload(in.gamma); + auto state = upload(in.state); + auto y = upload(std::vector(t * (ROW + 8))); + auto scratch = upload(std::vector(t * ROW)); + cudaEvent_t start, end; + ck(cudaEventCreate(&start), "event"); ck(cudaEventCreate(&end), "event"); + std::vector times; + for (int round = -2; round < 7; ++round) { + ck(cudaMemcpy(state, in.state.data(), in.state.size() * sizeof(float), cudaMemcpyHostToDevice), "reset"); + ck(cudaEventRecord(start), "event"); + strata::prefill::gdn_recurrence(state, h, g, b, z, gm, 1e-6f, scratch, y, t, nullptr, ROW + 8); + ck(cudaEventRecord(end), "event"); ck(cudaEventSynchronize(end), "time"); + float ms = 0; + ck(cudaEventElapsedTime(&ms, start, end), "time"); + if (round >= 0) times.push_back(ms); + } + std::sort(times.begin(), times.end()); + std::printf("BENCH path=%s T=%lld ms=%.6f repeats=7\n", path, (long long) t, times[3]); + ck(cudaEventDestroy(start), "event"); ck(cudaEventDestroy(end), "event"); + ck(cudaFree(h), "free"); ck(cudaFree(g), "free"); ck(cudaFree(b), "free"); ck(cudaFree(z), "free"); + ck(cudaFree(gm), "free"); ck(cudaFree(state), "free"); ck(cudaFree(y), "free"); ck(cudaFree(scratch), "free"); + } +} +} +int main(int argc, char** argv) { + const bool bench_default = argc > 1 && std::strcmp(argv[1], "--bench-default") == 0; + const bool off = argc > 1 && (std::strcmp(argv[1], "--off") == 0 || std::strcmp(argv[1], "--default") == 0 || bench_default); + setting("STRATA_GDN_CHUNKED", off ? "0" : "1"); + setting("STRATA_GDN_HEAD", "1"); setting("STRATA_GDN_PP", "2"); + if (argc > 1 && std::strncmp(argv[1], "--bench", 7) == 0) setting("STRATA_GDN_NOY", "1"); // gfx1151's default +#ifdef _WIN32 + _putenv_s("STRATA_GDN_REC_HEADS", ""); + if (argc > 1 && std::strcmp(argv[1], "--default") == 0) _putenv_s("STRATA_GDN_CHUNKED", ""); +#else + unsetenv("STRATA_GDN_REC_HEADS"); + if (argc > 1 && std::strcmp(argv[1], "--default") == 0) unsetenv("STRATA_GDN_CHUNKED"); +#endif + int device = 0; + cudaDeviceProp props{}; + ck(cudaGetDevice(&device), "device"); ck(cudaGetDeviceProperties(&props, device), "properties"); + const bool wmma = strata::kernels::gfx_arch_is_gfx11_wmma(props.gcnArchName); + std::printf("device=%s chunked=%d wmma=%d\n", props.gcnArchName, !off, wmma); + if (argc > 1 && std::strcmp(argv[1], "--bench") == 0) { bench("chunked"); return 0; } + if (bench_default) { bench("default"); return 0; } + int failures = 0; + for (int64_t t : {0, 1, 15, 16, 17, 63, 64, 65, 79, 80, 81, 257, 2051, 16385}) { + if (off && t > 2051) continue; + const Input in(t, 2, 1, false); + for (int padding : {0, 8, 1}) { + if (t > 257 && padding != 8) continue; + const int ld = ROW + padding; + const auto ref = run(in, ld, true), got = run(in, ld, false); + const bool exact = off || !wmma || t < 64 || ld % 8; + failures += !compare(in, ld, ref, got, exact, "dispatch"); + if (t == 65 && padding == 8) failures += !cpu_check(in, ld, got); + if (t == 257 && padding == 8) failures += !compare(in, ld, got, run(in, ld, false, 129), false, "continuation"); + } + } + if (!off) { + for (const float decay : {0.f, 0.01f}) { + const Input in(2051, decay, 16, false); + failures += !compare(in, ROW + 8, run(in, ROW + 8, true), run(in, ROW + 8, false), !wmma, "weak-decay"); + } + const Input in(65, 0.01f, 1, true); + const auto got = run(in, ROW, false); + failures += !compare(in, ROW, run(in, ROW, true), got, !wmma, "beta-zero"); + failures += !cpu_check(in, ROW, got); + } + std::printf("FAILURES: %d\n", failures); + return failures ? 1 : 0; +} diff --git a/tests/hip/gdn_rec_head.cpp b/tests/hip/gdn_rec_head.cpp index 06af26bb..6249440e 100644 --- a/tests/hip/gdn_rec_head.cpp +++ b/tests/hip/gdn_rec_head.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -32,6 +33,13 @@ template std::vector host(const T* d, size_t n) { } // namespace int main() { + // variants 0 and 1 are the references here; STRATA_GDN_CHUNKED=1 would turn them into the opt-in chunked recurrence + // (tests/hip/gdn_chunked.cpp), whose bits differ +#ifdef _WIN32 + _putenv_s("STRATA_GDN_CHUNKED", ""); +#else + unsetenv("STRATA_GDN_CHUNKED"); +#endif std::mt19937 rng(11); std::normal_distribution nd(0.f, 1.f); std::uniform_real_distribution ud(0.f, 1.f); diff --git a/tools/hip/gfx1103-hipblaslt-100401.txt b/tools/hip/gfx1103-hipblaslt-100401.txt new file mode 100644 index 00000000..c6ff2895 --- /dev/null +++ b/tools/hip/gfx1103-hipblaslt-100401.txt @@ -0,0 +1,145 @@ +# solution IDs are scoped to this hipBLASLt version and device architecture +STRATA_HIPBLASLT_TUNING_V1 gfx1103 100401 +f16 12288 2560 12288 16384 6137 +f16 10240 2560 10240 16384 6137 +f16 6144 2560 6144 16384 6137 +f16 2560 6144 2560 16384 6137 +f16 2560 640 2560 16384 6137 +f16 640 2560 640 16384 6137 +f16 512 2560 512 16384 6137 +bf16 10240 2560 10240 16384 5532 +bf16 10240 320 10240 16384 5532 +bf16 320 10240 320 16384 5532 +bf16 2560 2560 2560 16384 5532 +bf16 512 2560 512 16384 5532 +bf16 128 2560 128 16384 5532 +bf16 48 2560 96 16384 5532 +bf16 4 10240 4 16384 5529 +bf16 1 2560 1 16384 5529 +f16 12288 2560 12288 8192 6137 +f16 10240 2560 10240 8192 6137 +f16 6144 2560 6144 8192 6137 +f16 2560 6144 2560 8192 6137 +f16 2560 640 2560 8192 6137 +f16 640 2560 640 8192 6137 +f16 512 2560 512 8192 6137 +bf16 10240 2560 10240 8192 5532 +bf16 10240 320 10240 8192 5532 +bf16 320 10240 320 8192 5532 +bf16 2560 2560 2560 8192 5532 +bf16 512 2560 512 8192 5532 +bf16 128 2560 128 8192 5532 +bf16 48 2560 96 8192 5532 +bf16 4 10240 4 8192 5531 +bf16 1 2560 1 8192 5531 +f16 12288 2560 12288 4096 6137 +f16 10240 2560 10240 4096 6137 +f16 6144 2560 6144 4096 6137 +f16 2560 6144 2560 4096 6137 +f16 2560 640 2560 4096 6137 +f16 640 2560 640 4096 6137 +f16 512 2560 512 4096 6137 +bf16 10240 2560 10240 4096 5532 +bf16 10240 320 10240 4096 5532 +bf16 320 10240 320 4096 5532 +bf16 2560 2560 2560 4096 5532 +bf16 512 2560 512 4096 5532 +bf16 128 2560 128 4096 5532 +bf16 48 2560 96 4096 5532 +bf16 4 10240 4 4096 5529 +bf16 1 2560 1 4096 5531 +f16 12288 2560 12288 2048 6137 +f16 10240 2560 10240 2048 6137 +f16 6144 2560 6144 2048 6137 +f16 2560 6144 2560 2048 6137 +f16 2560 640 2560 2048 6137 +f16 640 2560 640 2048 6137 +f16 512 2560 512 2048 6137 +bf16 10240 2560 10240 2048 5532 +bf16 10240 320 10240 2048 5532 +bf16 320 10240 320 2048 5532 +bf16 2560 2560 2560 2048 5532 +bf16 512 2560 512 2048 5532 +bf16 128 2560 128 2048 5532 +bf16 48 2560 96 2048 5532 +bf16 4 10240 4 2048 5531 +bf16 1 2560 1 2048 5531 +f16 12288 2560 12288 1024 6137 +f16 10240 2560 10240 1024 6137 +f16 6144 2560 6144 1024 6137 +f16 2560 6144 2560 1024 6137 +f16 2560 640 2560 1024 6137 +f16 640 2560 640 1024 6137 +f16 512 2560 512 1024 6137 +bf16 10240 2560 10240 1024 5532 +bf16 10240 320 10240 1024 5532 +bf16 320 10240 320 1024 5532 +bf16 2560 2560 2560 1024 5532 +bf16 512 2560 512 1024 5532 +bf16 128 2560 128 1024 5532 +bf16 48 2560 96 1024 5531 +bf16 4 10240 4 1024 5529 +bf16 1 2560 1 1024 5530 +f16 12288 2560 12288 512 6137 +f16 10240 2560 10240 512 6137 +f16 6144 2560 6144 512 6137 +f16 2560 6144 2560 512 6137 +f16 2560 640 2560 512 6137 +f16 640 2560 640 512 6137 +f16 512 2560 512 512 6137 +bf16 10240 2560 10240 512 5532 +bf16 10240 320 10240 512 5532 +bf16 320 10240 320 512 5532 +bf16 2560 2560 2560 512 5532 +bf16 512 2560 512 512 5532 +bf16 128 2560 128 512 5531 +bf16 48 2560 96 512 5531 +bf16 4 10240 4 512 5529 +bf16 1 2560 1 512 5530 +f16 12288 2560 12288 256 6137 +f16 10240 2560 10240 256 6137 +f16 6144 2560 6144 256 6137 +f16 2560 6144 2560 256 6137 +f16 2560 640 2560 256 6136 +f16 640 2560 640 256 6137 +f16 512 2560 512 256 6137 +bf16 10240 2560 10240 256 5532 +bf16 10240 320 10240 256 5532 +bf16 320 10240 320 256 5532 +bf16 2560 2560 2560 256 5532 +bf16 512 2560 512 256 5532 +bf16 128 2560 128 256 5531 +bf16 48 2560 96 256 5530 +bf16 4 10240 4 256 5529 +bf16 1 2560 1 256 5529 +f16 12288 2560 12288 128 6137 +f16 10240 2560 10240 128 6137 +f16 6144 2560 6144 128 6137 +f16 2560 6144 2560 128 6136 +f16 2560 640 2560 128 6137 +f16 640 2560 640 128 6137 +f16 512 2560 512 128 6137 +bf16 10240 2560 10240 128 5532 +bf16 10240 320 10240 128 5532 +bf16 320 10240 320 128 5532 +bf16 2560 2560 2560 128 5532 +bf16 512 2560 512 128 5532 +bf16 128 2560 128 128 5530 +bf16 48 2560 96 128 5545 +bf16 4 10240 4 128 5529 +bf16 1 2560 1 128 5530 +f16 12288 2560 12288 64 6135 +f16 10240 2560 10240 64 6135 +f16 6144 2560 6144 64 6137 +f16 2560 6144 2560 64 6135 +f16 2560 640 2560 64 6137 +f16 640 2560 640 64 6136 +f16 512 2560 512 64 6136 +bf16 10240 2560 10240 64 5530 +bf16 10240 320 10240 64 5532 +bf16 320 10240 320 64 5530 +bf16 2560 2560 2560 64 5530 +bf16 512 2560 512 64 5530 +bf16 128 2560 128 64 5529 +bf16 48 2560 96 64 5533 +bf16 4 10240 4 64 5530 diff --git a/tools/hip/gfx1150-hipblaslt-100500.txt b/tools/hip/gfx1150-hipblaslt-100500.txt new file mode 100644 index 00000000..7e4c498a --- /dev/null +++ b/tools/hip/gfx1150-hipblaslt-100500.txt @@ -0,0 +1,143 @@ +# solution IDs are scoped to this hipBLASLt version and device architecture +STRATA_HIPBLASLT_TUNING_V1 gfx1150 100500 +f16 12288 2560 12288 16384 1156 +f16 10240 2560 10240 16384 1156 +f16 6144 2560 6144 16384 1156 +f16 2560 6144 2560 16384 1155 +f16 2560 640 2560 16384 1156 +f16 640 2560 640 16384 1156 +f16 512 2560 512 16384 1156 +bf16 10240 2560 10240 16384 542 +bf16 10240 320 10240 16384 542 +bf16 320 10240 320 16384 542 +bf16 2560 2560 2560 16384 541 +bf16 512 2560 512 16384 542 +bf16 128 2560 128 16384 542 +bf16 48 2560 96 16384 542 +bf16 4 10240 4 16384 540 +bf16 1 2560 1 16384 541 +f16 12288 2560 12288 8192 1156 +f16 10240 2560 10240 8192 1156 +f16 6144 2560 6144 8192 1156 +f16 2560 6144 2560 8192 1156 +f16 2560 640 2560 8192 1156 +f16 640 2560 640 8192 1156 +f16 512 2560 512 8192 1156 +bf16 10240 2560 10240 8192 542 +bf16 10240 320 10240 8192 542 +bf16 320 10240 320 8192 542 +bf16 2560 2560 2560 8192 542 +bf16 512 2560 512 8192 542 +bf16 128 2560 128 8192 542 +bf16 48 2560 96 8192 542 +bf16 4 10240 4 8192 539 +bf16 1 2560 1 8192 540 +f16 12288 2560 12288 4096 1156 +f16 10240 2560 10240 4096 1156 +f16 6144 2560 6144 4096 1156 +f16 2560 6144 2560 4096 1156 +f16 2560 640 2560 4096 1156 +f16 640 2560 640 4096 1156 +f16 512 2560 512 4096 1156 +bf16 10240 2560 10240 4096 542 +bf16 10240 320 10240 4096 542 +bf16 320 10240 320 4096 542 +bf16 2560 2560 2560 4096 542 +bf16 512 2560 512 4096 542 +bf16 128 2560 128 4096 542 +bf16 48 2560 96 4096 539 +bf16 4 10240 4 4096 540 +bf16 1 2560 1 4096 539 +f16 12288 2560 12288 2048 1156 +f16 10240 2560 10240 2048 1156 +f16 6144 2560 6144 2048 1156 +f16 2560 6144 2560 2048 1156 +f16 2560 640 2560 2048 1156 +f16 640 2560 640 2048 1156 +f16 512 2560 512 2048 1156 +bf16 10240 2560 10240 2048 542 +bf16 10240 320 10240 2048 542 +bf16 320 10240 320 2048 542 +bf16 2560 2560 2560 2048 542 +bf16 512 2560 512 2048 542 +bf16 128 2560 128 2048 542 +bf16 48 2560 96 2048 540 +bf16 4 10240 4 2048 555 +bf16 1 2560 1 2048 542 +f16 12288 2560 12288 1024 1156 +f16 10240 2560 10240 1024 1156 +f16 6144 2560 6144 1024 1156 +f16 2560 6144 2560 1024 1156 +f16 2560 640 2560 1024 1156 +f16 640 2560 640 1024 1156 +f16 512 2560 512 1024 1156 +bf16 10240 2560 10240 1024 542 +bf16 10240 320 10240 1024 542 +bf16 320 10240 320 1024 542 +bf16 2560 2560 2560 1024 542 +bf16 512 2560 512 1024 542 +bf16 128 2560 128 1024 542 +bf16 48 2560 96 1024 540 +bf16 4 10240 4 1024 555 +bf16 1 2560 1 1024 540 +f16 12288 2560 12288 512 1156 +f16 10240 2560 10240 512 1156 +f16 6144 2560 6144 512 1156 +f16 2560 6144 2560 512 1156 +f16 2560 640 2560 512 1156 +f16 640 2560 640 512 1156 +f16 512 2560 512 512 1156 +bf16 10240 2560 10240 512 542 +bf16 10240 320 10240 512 542 +bf16 320 10240 320 512 542 +bf16 2560 2560 2560 512 542 +bf16 512 2560 512 512 542 +bf16 128 2560 128 512 539 +bf16 48 2560 96 512 540 +bf16 4 10240 4 512 554 +bf16 1 2560 1 512 553 +f16 12288 2560 12288 256 1156 +f16 10240 2560 10240 256 1156 +f16 6144 2560 6144 256 1156 +f16 2560 6144 2560 256 1156 +f16 2560 640 2560 256 1156 +f16 640 2560 640 256 1156 +f16 512 2560 512 256 1156 +bf16 10240 2560 10240 256 542 +bf16 10240 320 10240 256 542 +bf16 320 10240 320 256 541 +bf16 2560 2560 2560 256 542 +bf16 512 2560 512 256 542 +bf16 128 2560 128 256 541 +bf16 48 2560 96 256 539 +bf16 4 10240 4 256 554 +f16 12288 2560 12288 128 1156 +f16 10240 2560 10240 128 1156 +f16 6144 2560 6144 128 1156 +f16 2560 6144 2560 128 1156 +f16 2560 640 2560 128 1156 +f16 640 2560 640 128 1156 +f16 512 2560 512 128 1155 +bf16 10240 2560 10240 128 542 +bf16 10240 320 10240 128 542 +bf16 320 10240 320 128 541 +bf16 2560 2560 2560 128 542 +bf16 512 2560 512 128 541 +bf16 128 2560 128 128 543 +bf16 48 2560 96 128 543 +bf16 4 10240 4 128 543 +f16 12288 2560 12288 64 1156 +f16 10240 2560 10240 64 1154 +f16 6144 2560 6144 64 1154 +f16 2560 6144 2560 64 1154 +f16 2560 640 2560 64 1156 +f16 640 2560 640 64 1154 +f16 512 2560 512 64 1155 +bf16 10240 2560 10240 64 541 +bf16 10240 320 10240 64 541 +bf16 320 10240 320 64 543 +bf16 2560 2560 2560 64 542 +bf16 512 2560 512 64 541 +bf16 128 2560 128 64 543 +bf16 48 2560 96 64 555 +bf16 4 10240 4 64 543 diff --git a/tools/test_setup_rocm_pins.py b/tools/test_setup_rocm_pins.py index 4bf5c436..69f0d4ff 100644 --- a/tools/test_setup_rocm_pins.py +++ b/tools/test_setup_rocm_pins.py @@ -36,6 +36,8 @@ class RocmPick(unittest.TestCase): def test_every_family_gets_a_version_its_index_has(self): for arch in setup.ROCM_INDEXES: + if setup.rocm_family(setup.ROCM_INDEXES[arch]) not in LISTINGS: + continue # the gfx1150 opt-in (#2147): no saved version list for its index yet with self.subTest(arch=arch): version, note = self.want(arch) self.assertIn(version, LISTINGS[setup.rocm_family(setup.ROCM_INDEXES[arch])]) diff --git a/tools/test_setup_strix_halo.py b/tools/test_setup_strix_halo.py index 0fb83051..adb62d04 100644 --- a/tools/test_setup_strix_halo.py +++ b/tools/test_setup_strix_halo.py @@ -110,6 +110,42 @@ class ExactArch(unittest.TestCase): self.assertIn("docs/STRIX_HALO.md", setup.AMD_CARDS) +class Gfx1103Switches(unittest.TestCase): + def test_is_the_gfx1151_defaults_less_hcd_exact(self): + """GFX1103_SWITCHES is the gfx1151 arch-default set (src/core/arch_defaults.cpp) minus STRATA_HCD_EXACT, which + copies the gfx1151 hipBLASLt table's solutions 1176 / 1177 and so does not apply beside a gfx1103 table. The + engine keeps gfx1103 out of its own arch defaults, so setup writes this set.""" + src = (ROOT / "src/core/arch_defaults.cpp").read_text(encoding="utf-8") + tail = src.split("gfx_arch_is_gfx1151(gcn_arch)) return t;", 1)[1] + block = tail.rsplit("t = {", 1)[1].split("};", 1)[0] # the gfx1151 switch table + gfx1151 = dict(re.findall(r'\{"(STRATA_[A-Z0-9_]+)",\s*"([^"]+)"\}', block)) + self.assertIn("STRATA_HCD_EXACT", gfx1151) # the parse found the gfx1151 block + self.assertEqual(setup.GFX1103_SWITCHES, + {k: v for k, v in gfx1151.items() if k != "STRATA_HCD_EXACT"}) + self.assertNotIn("STRATA_HCD_EXACT", setup.GFX1103_SWITCHES) + for k in setup.GFX1103_SWITCHES: # setup's own: a re-run refreshes them + self.assertIn(k, setup.SETUP_ENV) + + +class Gfx1150Switches(unittest.TestCase): + def test_is_the_gfx1151_defaults_less_hcd_exact(self): + """GFX1150_SWITCHES is the gfx1151 arch-default set (src/core/arch_defaults.cpp) minus STRATA_HCD_EXACT, which + copies the gfx1151 hipBLASLt table's solutions 1176 / 1177 and so does not apply beside a gfx1150 table. The + engine keeps gfx1150 out of its own arch defaults (src/core/arch_defaults_test.cpp), so setup writes this set.""" + src = (ROOT / "src/core/arch_defaults.cpp").read_text(encoding="utf-8") + tail = src.split("gfx_arch_is_gfx1151(gcn_arch)) return t;", 1)[1] + block = tail.rsplit("t = {", 1)[1].split("};", 1)[0] # the gfx1151 switch table + gfx1151 = dict(re.findall(r'\{"(STRATA_[A-Z0-9_]+)",\s*"([^"]+)"\}', block)) + self.assertIn("STRATA_HCD_EXACT", gfx1151) # the parse found the gfx1151 block + self.assertEqual(setup.GFX1150_SWITCHES, + {k: v for k, v in gfx1151.items() if k != "STRATA_HCD_EXACT"}) + self.assertNotIn("STRATA_HCD_EXACT", setup.GFX1150_SWITCHES) + for k in setup.GFX1150_SWITCHES: # setup's own: a re-run refreshes them + self.assertIn(k, setup.SETUP_ENV) + self.assertIn('arch_default_env("gfx1150").empty()', + (ROOT / "src/core/arch_defaults_test.cpp").read_text(encoding="utf-8")) + + class PciIds(unittest.TestCase): def test_strix_halo_id(self): # pci.ids: one id for every Strix Halo part (8060S, 8050S, 8040S share it; they differ by CU count) @@ -486,6 +522,7 @@ class IgpuTextIsArchExact(unittest.TestCase): text = chr(10).join(setup.igpu_notes(self.gpu("gfx1103", "AMD Radeon 780M Graphics"), 61.0)) self.assertIn("gfx1103", text) self.assertIn("STRATA_EXPERIMENTAL_GFX1103=1", text) + self.assertIn("RADEON_780M.md", text) for bad in ("gfx1151", "Ryzen AI Max", "STRIX_HALO", "Recommended model"): self.assertNotIn(bad, text) self.assertNotIn("Strix Halo (gfx1151", text)