Add MicroCUDA backend, adaptive output wait, wider native K coverage (improve perf)

Shim
- Adaptive output-event wait: sleep to ~120 us before the predicted
  completion (smoothed per wait site), spin near it, back off when late.
  D4R_SHIM_OUTPUT_POLL_US restores a fixed interval.

- Defer the input-marker wait into the worker thread with VRAM interop
  (D4R_SHIM_DEFER_MARKER, default on), taking the host setup off the
  critical path.

MicroCUDA
- Experimental ZLUDA-free backend in wine_nvcuda_bridge, plus
  tools/microcuda and scripts/build_microcuda.sh. Serves accuracy, fast
  and native kernels; unregistered modules fall back to the reference
  path. Unclassified writes invalidate prepared weights.

M kernels
- SWIN_PREP_IDENTITY_AT: key weight prep by allocation identity
  (MicroCUDA); enc3 tube uses it with 8 slots. ZLUDA ignores it.

- dec2 (gfx1101): SWIN_PACKED_RESIDUAL, byte-identical, ~1.6% faster.

- Opt-in gfx12 hardware fp8 conversion (SWIN_FP8_HWCVT), unverified
  on hardware.

Native K translators
- ctile: handle variants that re-materialize the parameter base (mvlo).

- rewrite_output: check live-in registers, not just outputs.

- build.sh: native input covers all 8 flag variants, output the 4 HDR
  "max" variants; depth-tile skip stays mvhi-only.

Tools
- dump_runner and bench_dlss_kernel harness additions.
This commit is contained in:
ayo committed 2026-10-07 15:54:38 -04:00
1 parent 7c60d53cd0
commit a627439025
20 files changed
+2186 -44

No files matched your search

+74
View File
@@ -0,0 +1,74 @@
#!/usr/bin/env python3
"""Per-module compile tuning: build a pack from several variant packs of the same DLL, ZLUDA build and target.
merge_pack.py BASE_PACK OUT_PACK [--all VARIANT_PACK] [--choose CHOICES.json]
BASE_PACK fixes the header (switch set the process must run with) and supplies every module not chosen
otherwise. --all takes every module from one variant pack (to measure that variant); --choose takes a JSON
map {fatbin_fnv_hex: variant_pack_dir}. Variants must only differ in code-generation choices that keep
results bit-exact (scheduler strategy, wave size); the caller validates the merged pack's output against the
reference before using it. Each module line keeps its own SHA256, and a comment records its variant.
"""
import argparse
import json
from pathlib import Path
import shutil
import sys
def read(pack):
header, modules = [], {}
for line in (pack / 'microcuda-pack.txt').read_text().splitlines():
if line.startswith(('module ', 'empty ')):
modules[line.split()[1]] = line
else:
header.append(line)
return header, modules
def field(header, key):
return next((l.split(' ', 1)[1] if ' ' in l else '' for l in header if l.split(' ', 1)[0] == key), None)
def main():
p = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
p.add_argument('base', type=Path)
p.add_argument('out', type=Path)
p.add_argument('--all', type=Path)
p.add_argument('--choose', type=Path)
a = p.parse_args()
header, modules = read(a.base)
choice = {}
if a.all:
choice = {f: a.all for f in modules}
if a.choose:
choice.update({f: Path(v) for f, v in json.loads(a.choose.read_text()).items()})
variants = {}
if a.out.exists():
shutil.rmtree(a.out)
(a.out / 'modules').mkdir(parents=True)
lines, notes = [], []
for f, line in sorted(modules.items()):
source = a.base
if f in choice and line.startswith('module '):
v = choice[f]
if v not in variants:
vh, vm = read(v)
if field(vh, 'arch') != field(header, 'arch') or \
next(l for l in vh if l.startswith('# dll')) != next(l for l in header if l.startswith('# dll')):
sys.exit(f'{v}: different DLL or target')
variants[v] = (vh, vm)
vh, vm = variants[v]
if f in vm:
line, source = vm[f], v
notes.append(f'# variant {f} {field(vh, "switches")}')
if line.startswith('module '):
name = line.split()[6]
shutil.copyfile(source / 'modules' / name, a.out / 'modules' / name)
lines.append(line)
(a.out / 'microcuda-pack.txt').write_text('\n'.join(header + notes + lines) + '\n')
print(f'{len(lines)} entries, {len(notes)} from variant packs -> {a.out}')
if __name__ == '__main__':
main()