diff --git a/changelog.d/243-inkling-2-mini-runs-on-net-s-rtx-spark-l.md b/changelog.d/243-inkling-2-mini-runs-on-net-s-rtx-spark-l.md new file mode 100644 index 00000000000..26a6ed2ff96 --- /dev/null +++ b/changelog.d/243-inkling-2-mini-runs-on-net-s-rtx-spark-l.md @@ -0,0 +1,18 @@ +# Inkling 2 Mini on the RTX Spark N1X laptop (native Windows ARM64): the Windows fixes and its run steps + +- Brings 189's Windows ARM64 fixes onto 188's Inkling 2 Mini engine: `__noinline__` in `glm_index_rope.cuh` and + `/wd4819` for nvcc with cl.exe, POSIX file modes and COM `@alignCast` in the server, no `tf-muse` on Windows, and + `compile-native-cuda-windows` checking the sm_121 aarch64 product. +- `docs/recipes/inkling-2-mini-cuda/n1x-run.ps1` runs Mini on the laptop through `codync@rtx-spark` in steps of under + 10 minutes (nvcc's kernel images, the contract images `tf-cuda-test` embeds, `tf-cuda-test` alone through the new + `zig build tf-cuda-test` step, the server, 188's exactness checks, the reference's planted control, 1/4-stream + serving timed by the server's own `done` lines with the WDDM pool's peak), with no Python, installs or downloads; each + build step logs zig's output; it queries the N1X by name, as the laptop's + `nvidia-smi` also lists an NPU. Run 6 on the laptop: all seven steps exit 0, every check passes (32 of 32 greedy + tokens equal the float64 reference), 32.3 tok/s at one stream and 115.8 total at four, first token 0.099 s, pool + peak 23,324 MiB. +- `tf-cuda-test inkling2-mini-ref` exits non-zero when its planted control differs, as every other failure does; the + GB10 and N1X scripts require that exit and the plant's differing tokens, so a load or CUDA failure cannot pass it. + The kernel contract says the MLP128 tile is served only on sm_120 instead of blaming the cluster path on sm_121. +- CUDA kernel images are keyed by nvcc's own bytes instead of a side-effect `nvcc --version` capture, which was + rewritten every build and so missed every image's cache: each warm build ran nvcc on all of them again. diff --git a/docs/recipes/inkling-2-mini-cuda/README.md b/docs/recipes/inkling-2-mini-cuda/README.md index 9b5f4af5711..f841ee66a10 100644 --- a/docs/recipes/inkling-2-mini-cuda/README.md +++ b/docs/recipes/inkling-2-mini-cuda/README.md @@ -41,19 +41,99 @@ Bandwidth limit: a decoded token reads about 5.55 GB of weights (core layers 3 p whole unembedding), so 273 GB/s caps one stream near 49 tok/s; 32.9 tok/s is 67% of it. #4387's own engine, removed here, gave 5.7 tok/s at one stream and 9.4 at four on the same GB10 (job `top-0759755a0515`). -## RTX Spark (N1X): what differs and what must change - -I see the same chip and memory model as the GB10: sm_121 and one unified pool, so the `-Dsm=121` kernel images are -the same. What differs is the host. RTX Spark runs Windows on Arm, with WSL2 as the -Linux route. From #1010 (`5b1f10812`) and #2107: - -- Native Windows builds as `aarch64-windows` with VS 2022 Build Tools' ARM64 C++ tools (`vcvarsall arm64`) as nvcc's - host compiler and the CUDA 13.4 `windows-arm64` redistributables (winget has no arm64 installer). Admission reads the - WDDM pool through `cuMemGetInfo_v2`, and `nvidia-smi`'s NPU row is filtered out. -- Under WSL2 `/proc/meminfo` is WSL's RAM (about 30 GiB of 128 GB), not the GPU's 96 GB WDDM pool; with - `WSL_DISTRO_NAME` set, admission reads the CUDA pool instead (`TENSORFOLD_UNIFIED_HOST_COUNTS` overrides it). -- For Mini on native Windows, I need the Inkling CUDA kernels compiled with MSVC as nvcc's host front end (only gcc 14 - has built them so far) and one load of the 18.2 GiB text shard (`model-00001-of-00001.safetensors`) through Windows' - threaded reads. -- For Mini under WSL2, I need neither: it is the Linux build with gcc 14. Only the pool reading above differs. -- Either way, the GB10's exactness checks must be repeated on the N1X. No N1X run of Mini exists yet. +Job `top-9defa53c0bfc` at `2a37918af` reran it with the planted control's new exit: the control's 6 of 32 differing +tokens exit non-zero and the script goes on, ending 0 with 33.8 tok/s at one stream and 121.4 at four (3.59x). + +Job `top-3546b0a66f9b` at `abc67b2d` ran the planted control after the reference instead of beside it: 0 and 6 of 32 +differed as before (154.9 s and 150.8 s), 32.9 tok/s at one stream, then the 600 s window closed in the 4-stream +bench. The script runs its one planted control beside the reference. + +## RTX Spark (N1X): native Windows ARM64 on Net's laptop + +`n1x-run.ps1` runs the same checkpoint (`C:\models\Inkling-2-Mini-ed40e7da62`) on the laptop through its Codync bot +`codync@rtx-spark`, relayed by the Desk, one step a run. It installs and downloads nothing; the laptop has PowerShell +but no Python or WSL, so the 1/4-stream client is the script's own, not `bench_concurrent.py`. + +1. `-Step fatbins`, `-Step images`, `-Step runner`, then `-Step server`: `zig build fatbins`, `zig build + kernel-contract-fatbins`, `zig build tf-cuda-test`, then `zig build native`, each `-Dsm=121 -Doptimize=ReleaseFast` + with the CUDA 13.5 `windows-arm64` nvcc and `cl.exe` arm64 (`vcvarsall arm64`). 189's Windows fixes are on this + branch (`__noinline__` in `glm_index_rope.cuh`, `/wd4819`, POSIX file modes and COM `@alignCast` in the server, no + `tf-muse`). Each stops at 9 min and prints its log's tail and the images installed; a cut-off step resumes from + the zig cache. +2. `-Step check`: 188's GB10 checks unchanged, so the laptop's output is held to the host reference the same way: + `kernel-contract "inkling2 loop"`, `inkling2-serving` and `inkling2-mini-ref` (32 greedy tokens equal to the float64 + reference). +3. `-Step control`: the reference's planted control, which must exit non-zero with its tokens differing. +4. `-Step serve`: one server at `--parallel 4 --context 8192`, greedy 256-token replies at 1 and 4 streams; first token + and decode per stream come from the server's own `done` lines, with the ready time, the WDDM pool's peak + (`nvidia-smi -lms 500` in its own process) and the server's peak working set. + +Steps 2-4 share the builds' 9-minute deadline: each `tf-cuda-test` call, the 240 s server-load wait and each request +is bounded by the step's remaining time, and a killed call prints its log's tail like a build step's. + +What differs from the GB10 and is not copied from it: + +- `nvidia-smi` there also lists an NVIDIA NPU, so the script finds the N1X by name and queries only its index; + `memory.used` over every device gave an array and stopped run 1's serve step. +- A cold build took 647 s (run 1) and 901 s (run 2) in one piece, over a run's 10 minutes, so nvcc's kernel images are + their own step; `install` also builds a dozen products this card never runs (run 4 below), so the runner and the + server are a step each, and the 37 images only `tf-cuda-test` embeds (DeepSeek's EXL3 units, the contract's + controls, H3) are a step before the runner (run 5 below). The host float64 reference takes 226 s on the laptop, so + the planted control is its own step: run 2 ran both in one step for 11 min 10 s. +- The serve step times replies from the server's log, not the client: run 2's client read the stream line by line and + spawned `nvidia-smi` per line, which put it at 6.7 tok/s at one stream while the server decoded at 32.2. +- Memory is the WDDM pool the firmware gives CUDA (51,816 MiB on this laptop), not `/proc/meminfo`; admission reads it + through `cuMemGetInfo_v2`. The 20 GB checkpoint leaves about 20 GiB of it for the cache and four streams. +- The power cap (42-49 W at about 2.1 GHz in HP Performance mode, near 1.4 GHz in power saving, from the 2026-11-04 + receipt in [WINDOWS.md](../../WINDOWS.md)) bounds decode, so each run prints the power plan, limit and SM clock. + +Run 1 at `b2ddc3de` (clean tree): build exit 0; check passed as in run 2; serve was ready in 55.3 s, then the NPU row +above stopped the script before any tok/s. + +Run 2 at `2a37918a` (request `bb869e9b`, clean tree): one 15-minute `build` and one `check` with the control (11 min +10 s), both exit 0 with run 6's results; serve 32.2 tok/s at one stream, 117.0 total at four, pool peak 23,335 MiB. + +Run 3 at `a86ccbd1` (request `39062c42`, clean tree): `-Step fatbins` exited 1 in 20 s with `no such step: +fatbins-Dsm=121`, as PowerShell unrolled the one-element target list to a string that `+` then appended to; the +script now keeps it an array. + +Run 4 at `26de8309` (request `407e1d7b`, clean tree): `-Step fatbins` exited 0 in 83 s with 143 images; `-Step build` +(`install native`) stopped at 9 min twice without a compile error, building `tf-drama-quant`, `tf-qwen35-learn` and +the rest of `install` beside the two binaries the checks and serving run. Cold aarch64-windows ReleaseFast +cross-compiles on a Mac took 104 s for `tf-cuda-test` and 129 s for `tensorfold-native`, each on one core. + +Run 5 at `2ce7e54c` (request `4fbd4d3b`, clean tree): `-Step fatbins` exited 0 in 122 s with nothing changed since +run 4's, and `-Step runner` stopped at 9 min twice with no output, while `-Step server` exited 0 in 449 s. Every +warm build had run nvcc on every image again: each image's cache key held a side-effect `nvcc --version` capture, +rewritten each build, so no step resumed. Images are now keyed by nvcc's own bytes (a second `fatbins +kernel-contract-fatbins` with a stand-in nvcc makes 0 of its 180 calls), the runner's 37 nvcc-only images are their +own step, and each build step logs zig's output. Serve passed again: ready in 55.2 s, 32.2 tok/s at one stream (first +token 0.098 s), 115.4 total at four, pool peak 23,119 MiB; check and control did not run without `tf-cuda-test`. + +### Receipt: run 6 at `2c9228a8`, one capped run + +Desk run on `codync@rtx-spark`, relayed by Capri, 24 Nov 13:56:50-14:27:27, warm folder `tf243-a86c`, clean tree. +`vcvarsall arm64` 0, cl 14.44.35207 HostARM64, nvcc 13.5 V13.5.37, zig 0.17.0; N1X sm_121, 48 SMs, 51,816 MiB, +driver 621.01, power plan Balanced. Each step is +`powershell -ExecutionPolicy Bypass -File docs\recipes\inkling-2-mini-cuda\n1x-run.ps1 -Step `. This is one run +with these settings, not a benchmark. + +| Step | Exit | Time | Result | +|---|---|---|---| +| `fatbins` | 0 | 84 s | 143 images | +| `images` | 0 | 151 s | 180 images | +| `runner` | 0 | 493 s | `tf-cuda-test` | +| `server` | 0 | 347 s | `tensorfold-native` | +| `check` | 0 | | `kernel-contract "inkling2 loop"` 5/5 pass gates 1-4, 2/2 controls red, 0 limit problems (101,376 B shared, 1024 threads; MLP128 sm_120 only); `inkling2-serving` PASS (CUDA equals the host reference token for token, fresh equals resumed, 2 lanes share rounds and a 3rd waits at 17.60 GiB weights); `inkling2-mini-ref` 0 of 32 greedy tokens differ (smallest margin 0.110) | +| `control` | 0 | | planted control 6 of 32 differ (positions 15, 18, 19, 38, 39, 42), its exit non-zero as required | +| `serve` | 0 | | ready in 58.5 s | + +| Streams | First token | Decode a stream | Total decode | Failed | +|---|---|---|---|---| +| 1 | 0.099 s | 32.3 tok/s | 32.3 tok/s | 0 | +| 4 | 0.087-0.356 s | 28.5 / 28.8 / 29.1 / 29.4 tok/s | 115.8 tok/s (3.59x) | 0 | + +Times are the server's `done` lines (256 tokens each). Peak GPU memory: the WDDM pool went from 2,714 MiB before the +server to 23,315 MiB after load and peaked at 23,324 MiB; the server's working set peaked at 3,973 MiB. The server +warned that `tfgrammar.dll` is missing (a source build). As deployments, not chips: this laptop decoded one stream at +32.3 tok/s against GB10's 32.5, and four at 115.8 against 117.8. diff --git a/docs/recipes/inkling-2-mini-cuda/n1x-run.ps1 b/docs/recipes/inkling-2-mini-cuda/n1x-run.ps1 new file mode 100644 index 00000000000..76ccc5bfb06 --- /dev/null +++ b/docs/recipes/inkling-2-mini-cuda/n1x-run.ps1 @@ -0,0 +1,155 @@ +# Inkling 2 Mini (revision ed40e7da62) whole on an RTX Spark N1X laptop, native Windows ARM64, run by its Codync bot: +# powershell -ExecutionPolicy Bypass -File docs\recipes\inkling-2-mini-cuda\n1x-run.ps1 -Step fatbins|images|runner|server|check|control|serve +# From a clean checkout with `vcvarsall arm64` set up and CUDA_PATH naming the windows-arm64 toolkit. Installs, downloads +# and deletes nothing outside .\zig-out and $env:TEMP\inkling2-n1x. Each step stops itself inside 10 minutes. +param( + [Parameter(Mandatory)][ValidateSet('fatbins', 'images', 'runner', 'server', 'check', 'control', 'serve')][string]$Step, + [string]$Model = 'C:\models\Inkling-2-Mini-ed40e7da62' +) +$ErrorActionPreference = 'Stop' +$out = Join-Path $env:TEMP 'inkling2-n1x' +New-Item -ItemType Directory -Force $out | Out-Null + +function Run([string]$exe, [string[]]$argv) { + Write-Output "> $exe $argv" + & $exe @argv + Write-Output "EXIT=$LASTEXITCODE" + if ($LASTEXITCODE) { exit $LASTEXITCODE } +} + +# nvidia-smi on the laptop also lists an NVIDIA NPU, so every query names the N1X by its index, found by name +$gpus = nvidia-smi --query-gpu=index,name --format=csv,noheader +$gpu = @($gpus | Where-Object { $_ -match 'N1X' }) +if ($gpu.Count -ne 1) { throw "want one N1X in nvidia-smi, got: $($gpus -join '; ')" } +$gpu = $gpu[0].Split(',')[0].Trim() + +# The WDDM device pool the driver gives CUDA (the N1X shares it with the CPU; firmware sets its size), MiB +function Pool([string]$label) { + Write-Output "$label`: $(nvidia-smi -i $gpu --query-gpu=memory.used,memory.total --format=csv,noheader)" +} + +Run (Join-Path $env:CUDA_PATH 'bin\nvcc.exe') @('--version') +nvidia-smi -i $gpu --query-gpu=name,driver_version,power.limit,clocks.max.sm --format=csv,noheader +Write-Output "power plan: $(powercfg /getactivescheme)" +$test = 'zig-out\bin\tf-cuda-test.exe' +$server = 'zig-out\native\bin\tensorfold-native.exe' + +# A cold build ran 15 min in one piece (run 2) and `install native` twice ran past 9 min (run 4), building a dozen +# products this card does not run, so each step builds one thing: nvcc's 143 kernel images, the 37 contract images +# tf-cuda-test embeds (DeepSeek's EXL3 units, controls, H3: run 5's runner step ran nvcc on them and stopped twice), +# then tf-cuda-test, then tensorfold-native. Each stops at 9 min; a step cut off resumes from the cache when it runs +# again, and its log's tail and the images installed so far show how far it got. +$targets = @{ fatbins = 'fatbins'; images = 'kernel-contract-fatbins'; runner = 'tf-cuda-test'; server = 'native' } +if ($targets.ContainsKey($Step)) { + $argv = @($targets[$Step], '-Dsm=121', "`"-Dnvcc=$env:CUDA_PATH\bin\nvcc.exe`"", '-Doptimize=ReleaseFast') + Write-Output "> zig build $argv" + $clock = [Diagnostics.Stopwatch]::StartNew() + $zig = Start-Process -FilePath zig -ArgumentList (@('build') + $argv) -PassThru -NoNewWindow ` + -RedirectStandardOutput "$out\$Step.out" -RedirectStandardError "$out\$Step.log" + $null = $zig.Handle # without a handle taken now, .NET Framework loses the exit code once the process ends + $done = $zig.WaitForExit(540000) + if (-not $done) { & taskkill /T /F /PID $zig.Id | Out-Null; $zig.WaitForExit() } + Get-Content "$out\$Step.out", "$out\$Step.log" -Tail 30 + Write-Output "zig-out\fatbin: $(@(Get-ChildItem zig-out\fatbin -Filter *.fatbin -ErrorAction SilentlyContinue).Count) images" + if (-not $done) { + Write-Output "EXIT=timeout after 9 min: run -Step $Step again to resume from the cache" + exit 1 + } + Write-Output ("EXIT={0} in {1:N0} s" -f $zig.ExitCode, $clock.Elapsed.TotalSeconds) + exit $zig.ExitCode +} + +# check, control and serve share the same 9-minute deadline the build steps enforce, so a stalled check, reference +# or request cannot run past the step's stated 10-minute bound +$clock = [Diagnostics.Stopwatch]::StartNew() +function Left() { [Math]::Max(1, 540000 - [int]$clock.ElapsedMilliseconds) } +# One tf-cuda-test call under the deadline, its output and error logged like a build step's. -FailOk hands the exit +# code back in $script:last instead of stopping, for the control that must exit non-zero. +function Timed([string[]]$argv, [string]$log, [switch]$FailOk) { + Write-Output "> $test $argv" + $p = Start-Process -FilePath $test -PassThru -NoNewWindow -RedirectStandardOutput "$out\$log.out" ` + -RedirectStandardError "$out\$log.err" ` + -ArgumentList @(($argv | ForEach-Object { if ($_ -match ' ') { "`"$_`"" } else { $_ } })) + $null = $p.Handle # as with the build steps, the handle must be taken for the exit code + $done = $p.WaitForExit((Left)) + if (-not $done) { & taskkill /T /F /PID $p.Id | Out-Null; $p.WaitForExit() } + Get-Content "$out\$log.out", "$out\$log.err" -Tail 30 -ErrorAction SilentlyContinue + $script:last = if ($done) { $p.ExitCode } else { 124 } + Write-Output "EXIT=$script:last$(if (-not $done) { ' (timeout: the step deadline passed)' })" + if ($script:last -and -not $FailOk) { exit $script:last } +} + +$text = 'The three laws of thermodynamics, explained for a curious student:' +if ($Step -eq 'check') { + # 188's GB10 checks as they are: the served kernels, #4387's serving checks, the float64 reference + Timed @('info') 'info' + Timed @('kernel-contract', 'inkling2 loop') 'contract' + $r = New-Object System.Random 4387 + (1..4200 | ForEach-Object { $r.Next(1000, 199000) }) -join ' ' | Set-Content -Encoding ascii "$out\ids.txt" + Timed @('inkling2-serving', $Model, "$out\ids.txt") 'serving' + Timed @('inkling2-mini-ref', $Model, '32', $text) 'ref' + exit 0 +} + +# The reference's planted control is its own step: the float64 reference takes 226 s on the N1X, twice is over 10 min. +# Alone, any non-zero exit (a bad path, no GPU) would pass it, so it also needs the plant's own differing tokens. +if ($Step -eq 'control') { + $env:INKLING2_REF_PLANT = '1' + Timed @('inkling2-mini-ref', $Model, '32', $text) 'control' -FailOk + Write-Output "planted control EXIT=$script:last (must be non-zero)" + $planted = Select-String -Path "$out\control.err" -Pattern '\(PLANTED: no messages\): [1-9]\d* of 32 greedy tokens differ' + if (-not $script:last -or -not $planted) { exit 1 } + exit 0 +} + +# serve: one server, 1 then 4 greedy 256-token replies, timed by the server's own `done` lines (first token, decode): +# run 2's client timed itself, as PowerShell's line reads fell 4x behind the server's output +Pool 'before the server' +$port = 8188 +$proc = Start-Process -FilePath $server -PassThru -NoNewWindow -RedirectStandardOutput "$out\server.log" ` + -RedirectStandardError "$out\server.err" -ArgumentList @('serve', "`"$Model`"", '--backend', 'cuda', + '--host', '127.0.0.1', '--port', $port, '--name', 'inkling-2-mini', '--parallel', '4', '--context', '8192', + '--no-update-check') +try { + while ($true) { + try { Invoke-RestMethod "http://127.0.0.1:$port/v1/models" -TimeoutSec 5 | Out-Null; break } catch {} + if ($proc.HasExited -or $clock.Elapsed.TotalSeconds -gt 240) { throw 'server did not answer /v1/models' } + Start-Sleep 1 + } + Write-Output ("RESULT n1x server ready in {0:N1} s" -f $clock.Elapsed.TotalSeconds) + Pool 'server loaded' + # nvidia-smi samples the pool every 500 ms in its own process for the whole run; its largest sample is the peak + $smi = Start-Process -FilePath nvidia-smi -PassThru -NoNewWindow -RedirectStandardOutput "$out\pool.csv" ` + -ArgumentList @('-i', $gpu, '--query-gpu=memory.used', '--format=csv,noheader,nounits', '-lms', '500') + Add-Type -AssemblyName System.Net.Http + # a request gets the step's remaining budget (run 6 used under 40 s of it), not a free 4 minutes + $http = New-Object System.Net.Http.HttpClient + $body = '{"model":"inkling-2-mini","prompt":"Write a short Python function that computes the Fibonacci ' + + 'sequence and explain it.","max_tokens":256,"temperature":0,"ignore_eos":true}' + foreach ($n in 1, 4) { + $http.Timeout = [TimeSpan]::FromMilliseconds((Left)) + $before = @(Select-String -Path "$out\server.log" -Pattern '\] done ').Count + $calls = foreach ($i in 1..$n) { + $http.PostAsync("http://127.0.0.1:$port/v1/completions", + (New-Object System.Net.Http.StringContent $body, ([Text.Encoding]::UTF8), 'application/json')) + } + foreach ($c in $calls) { if (-not $c.Result.IsSuccessStatusCode) { throw "$n streams: $($c.Result.StatusCode)" } } + $done = @(Select-String -Path "$out\server.log" -Pattern '\] done ' | Select-Object -Skip $before) + if ($done.Count -ne $n) { throw "$n streams: want $n done lines, got $($done.Count)" } + $total = 0 + foreach ($d in $done) { + if ($d.Line -notmatch 'tokens=256 .*ttft=([\d.]+) .*tok/s=([\d.]+)') { throw "not a 256-token reply: $($d.Line)" } + $total += [double]$Matches[2] + Write-Output "RESULT n1x $n stream(s): first token $($Matches[1]) s, decode $($Matches[2]) tok/s" + } + Write-Output ("RESULT n1x {0} stream(s) total decode {1:N1} tok/s" -f $n, $total) + } + $smi.Kill(); $smi.WaitForExit() + $peak = (Get-Content "$out\pool.csv" | ForEach-Object { [int]$_ } | Measure-Object -Maximum).Maximum + if (-not $peak) { throw "no samples in $out\pool.csv" } + Write-Output "RESULT n1x peak GPU memory sampled every 500 ms: $peak MiB" + Write-Output "RESULT n1x server process peak working set $([int]($proc.PeakWorkingSet64 / 1MB)) MiB" +} finally { + foreach ($p in $proc, $smi) { if ($p -and -not $p.HasExited) { $p.Kill() } } + Get-Content "$out\server.err" -Tail 20 +} diff --git a/docs/recipes/inkling-2-mini-cuda/run-script.sh b/docs/recipes/inkling-2-mini-cuda/run-script.sh index ce07595f5c4..1905b7375cf 100755 --- a/docs/recipes/inkling-2-mini-cuda/run-script.sh +++ b/docs/recipes/inkling-2-mini-cuda/run-script.sh @@ -44,13 +44,20 @@ mkdir -p "$out" python3 -c 'import random; r = random.Random(4387); print(" ".join(str(r.randrange(1000, 199000)) for _ in range(4200)))' >"$out/ids.txt" "$bin/tf-cuda-test" inkling2-serving "$model" "$out/ids.txt" text="The three laws of thermodynamics, explained for a curious student:" -# the float64 reference runs on one host core: its planted control runs beside it, and each must exit 0 -INKLING2_REF_PLANT=1 "$bin/tf-cuda-test" inkling2-mini-ref "$model" 32 "$text" >"$out/planted.log" 2>&1 & +# the float64 reference runs on one host core, so its one planted control runs beside it: one after the other left +# the 600 s window in the 4-stream bench (job top-3546b0a66f9b). The reference must exit 0, the control non-zero. +INKLING2_REF_PLANT=1 "$bin/tf-cuda-test" inkling2-mini-ref "$model" 32 "$text" >"$out/control.log" 2>&1 & planted=$! trap 'kill $planted 2>/dev/null || :' EXIT "$bin/tf-cuda-test" inkling2-mini-ref "$model" 32 "$text" -wait $planted || { cat "$out/planted.log"; exit 1; } -cat "$out/planted.log" +if wait $planted; then + echo "planted control stayed green" >&2 + exit 1 +fi +cat "$out/control.log" >&2 +# a load or CUDA failure also exits non-zero, so the control must show its own differing tokens +grep -Eq '\(PLANTED: no messages\): [1-9][0-9]* of 32 greedy tokens differ' "$out/control.log" || + { echo "planted control failed before comparing tokens" >&2; exit 1; } mem() { echo "$1: host $(awk '/^MemTotal:/ {t = $2} /^MemAvailable:/ {a = $2} END {printf "used %d MiB, available %d MiB", (t - a) / 1024, a / 1024}' /proc/meminfo); GPU $(nvidia-smi --query-compute-apps=pid,used_memory --format=csv,noheader | tr '\n' ' ')"; } mem "before the server" /work/sm121/native/bin/tensorfold-native serve "$model" --backend cuda --host 127.0.0.1 --port 8188 \ diff --git a/zig/build/cuda.zig b/zig/build/cuda.zig index 672632eb411..f9d3464856b 100644 --- a/zig/build/cuda.zig +++ b/zig/build/cuda.zig @@ -59,19 +59,13 @@ pub fn targets(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.bu const prebuilt = opts.fatbins; const sms = opts.sms; const strip = opts.strip; - // the compiler's version text is an input of every fatbin, so a new nvcc rebuilds them all - const version: ?std.Build.LazyPath = if (prebuilt == null and nvcc != null) blk: { - const run = b.addSystemCommand(&.{ nvcc.?, "--version" }); - run.has_side_effects = true; - break :blk run.captureStdOut(.{}); - } else null; var images: [kernels.len]?std.Build.LazyPath = @splat(null); const fatbin_step = b.step("fatbins", "Build and install the CUDA kernel fatbins alone"); for (kernels, &images) |k, *image| { if (prebuilt) |dir| { image.* = b.graph.cwdRelativePath(b.pathJoin(&.{ dir, b.fmt("{s}.fatbin", .{k.name}) })); } else if (nvcc) |tool| { - image.* = fatbin(b, tool, version.?, catalog.nativeFp(b.allocator, k, opts.native_fp_decode), sms); + image.* = fatbin(b, tool, catalog.nativeFp(b.allocator, k, opts.native_fp_decode), sms); } if (image.*) |file| fatbin_step.dependOn(&b.addInstallFile(file, b.fmt("fatbin/{s}.fatbin", .{k.name})).step); } @@ -82,17 +76,13 @@ pub fn targets(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.bu b.step("check-pdl-loads", "No global read before a dependent launch's wait in the GLM images, qwen35 glue and qmmf (needs -Dnvcc)").dependOn(&check.step); } // MiniMax H3's kernel image: its library and the contract's runner take it - const h3_image = if (nvcc) |tool| fatbin(b, tool, version orelse blk: { - const run = b.addSystemCommand(&.{ tool, "--version" }); - run.has_side_effects = true; - break :blk run.captureStdOut(.{}); - }, .{ .name = "h3", .flags = &.{"-O3"} }, sms) else null; + const h3_image = if (nvcc) |tool| fatbin(b, tool, .{ .name = "h3", .flags = &.{"-O3"} }, sms) else null; @import("h3_host.zig").library(b, target, optimize, h3_image); // MiniMax-H3-Image's decoder, prompt and modulation kernel images, built to the served flags, for the contract const h3_image_fatbins: [3]?std.Build.LazyPath = if (nvcc) |tool| .{ - fatbin(b, tool, version.?, .{ .name = "h3_image_decoder", .flags = &.{ "-O3", "--fmad=false" }, .min_sm = 80 }, sms), - fatbin(b, tool, version.?, .{ .name = "h3_image_prompt", .flags = &.{"-O3"}, .min_sm = 80 }, sms), - fatbin(b, tool, version.?, .{ .name = "h3_image_modulation", .flags = &.{ "-O3", "--fmad=false" } }, sms), + fatbin(b, tool, .{ .name = "h3_image_decoder", .flags = &.{ "-O3", "--fmad=false" }, .min_sm = 80 }, sms), + fatbin(b, tool, .{ .name = "h3_image_prompt", .flags = &.{"-O3"}, .min_sm = 80 }, sms), + fatbin(b, tool, .{ .name = "h3_image_modulation", .flags = &.{ "-O3", "--fmad=false" } }, sms), } else .{ null, null, null }; const cuda = @import("cuda_runtime.zig").runtimeWithTargets(b, target, optimize, if (nvcc != null or prebuilt != null) &images else &.{}, null, if (nvcc != null and prebuilt == null) sms else ""); const mods = family(b, target, optimize, cuda, draft_ids); @@ -138,7 +128,9 @@ pub fn targets(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.bu runner.addImport("moss_image_cuda", b.createModule(.{ .root_source_file = b.path("zig/src/families/moss_image/cuda_kernels.zig"), .target = target, .optimize = optimize, .link_libc = true, .imports = &.{.{ .name = "cuda", .module = cuda }} })); runner.addImport("prompt_pages", b.createModule(.{ .root_source_file = b.path("zig/src/native/cuda_prompt_pages.zig"), .target = target, .optimize = optimize, .link_libc = true, .imports = &.{ .{ .name = "engine_api", .module = mods.api }, .{ .name = "core", .module = mods.core } } })); // TF_KV_SHARE's store, for the pages checks const runner_exe = b.addExecutable(.{ .name = "tf-cuda-test", .root_module = runner }); - b.installArtifact(runner_exe); + const runner_install = b.addInstallArtifact(runner_exe, .{}); + b.getInstallStep().dependOn(&runner_install.step); + b.step("tf-cuda-test", "Build and install tf-cuda-test alone").dependOn(&runner_install.step); // tf-cuda-limits: kernel-contract-limits alone, built without the contracts' test sources const limits_exe = b.addExecutable(.{ .name = "tf-cuda-limits", .root_module = b.createModule(.{ .root_source_file = b.path("zig/tests/cuda/limits_main.zig"), .target = target, .optimize = optimize, .link_libc = true, .strip = strip, .imports = &.{ .{ .name = "cuda", .module = cuda }, .{ .name = "core", .module = mods.core } } }) }); b.step("tf-cuda-limits", "Build kernel-contract-limits alone: the fatbins' launches against their records, no GPU").dependOn(&b.addInstallArtifact(limits_exe, .{}).step); @@ -152,10 +144,10 @@ pub fn targets(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.bu _ = startup.getEmittedBin(); b.step("compile-modelopt-startup", "Compile actual native startup with test-only absent GPU images").dependOn(&startup.step); const controls_file = opts.contract_controls; - const controls = if (controls_file) |file| b.graph.cwdRelativePath(file) else if (nvcc) |tool| fatbin(b, tool, version.?, .{ .name = "contract_controls", .src = "contract_controls_set", .flags = &.{"-O3"} }, sms) else null; + const controls = if (controls_file) |file| b.graph.cwdRelativePath(file) else if (nvcc) |tool| fatbin(b, tool, .{ .name = "contract_controls", .src = "contract_controls_set", .flags = &.{"-O3"} }, sms) else null; const contract_images = @import("qwen_contract.zig").images(b, runner_exe, controls, h3_image, h3_image_fatbins, kernels, &images); contract_images.dependOn(fatbin_step); - @import("cuda_contract_deepseek.zig").images(b, runner_exe, contract_images, kernels, &images, prebuilt, nvcc, version, sms, opts.cuobjdump); + @import("cuda_contract_deepseek.zig").images(b, runner_exe, contract_images, kernels, &images, prebuilt, nvcc, sms, opts.cuobjdump); @import("dsv41_serve.zig").install(b, target, optimize, cuda, nvcc != null or prebuilt != null); @import("hy4_cuda.zig").install(b, target, optimize, cuda, mods.core); const server_exe = nativeServer(b, target, optimize, cuda, mods.core, mods.lanes, mods.nemotron, mods.heat, mods.qwen35, mods.qwen_vision, mods.tokenizer, mods.living, build_options, true, strip); diff --git a/zig/build/cuda_contract_deepseek.zig b/zig/build/cuda_contract_deepseek.zig index 612f29bb0da..d4b0e6020ed 100644 --- a/zig/build/cuda_contract_deepseek.zig +++ b/zig/build/cuda_contract_deepseek.zig @@ -1,7 +1,7 @@ //! DeepSeek contract images use the same built artifacts as their named installs. const std = @import("std"); const list = @import("dsv41_units.zig"); -pub fn images(b: *std.Build, runner: *std.Build.Step.Compile, install: *std.Build.Step, kernels: anytype, files: []const ?std.Build.LazyPath, prebuilt: ?[]const u8, nvcc: ?[]const u8, version: ?std.Build.LazyPath, sms: []const u8, cuobjdump: ?[]const u8) void { +pub fn images(b: *std.Build, runner: *std.Build.Step.Compile, install: *std.Build.Step, kernels: anytype, files: []const ?std.Build.LazyPath, prebuilt: ?[]const u8, nvcc: ?[]const u8, sms: []const u8, cuobjdump: ?[]const u8) void { const empty = b.addWriteFiles().add("empty-contract-deepseek.fatbin", ""); for (list.units ++ list.optional) |k| { const common = for (kernels, 0..) |known, i| { @@ -10,7 +10,7 @@ pub fn images(b: *std.Build, runner: *std.Build.Step.Compile, install: *std.Buil const file = if (common) |i| files[i] else if (prebuilt) |dir| b.graph.cwdRelativePath(b.pathJoin(&.{ dir, b.fmt("{s}.fatbin", .{k.name}) })) else if (nvcc) |tool| - @import("cuda.zig").fatbin(b, tool, version.?, k, sms) + @import("cuda.zig").fatbin(b, tool, k, sms) else null; runner.root_module.addAnonymousImport(b.fmt("contract_fatbin_{s}", .{k.name}), .{ .root_source_file = file orelse empty }); diff --git a/zig/build/cuda_fatbin.zig b/zig/build/cuda_fatbin.zig index 302a152cd45..74930b171bc 100644 --- a/zig/build/cuda_fatbin.zig +++ b/zig/build/cuda_fatbin.zig @@ -9,7 +9,7 @@ pub const Target = catalog.Target; pub const Profile = catalog.Profile; pub const profile = catalog.profile; -pub fn fatbin(b: *std.Build, nvcc: []const u8, version: std.Build.LazyPath, k: Kernel, sms: []const u8) std.Build.LazyPath { +pub fn fatbin(b: *std.Build, nvcc: []const u8, k: Kernel, sms: []const u8) std.Build.LazyPath { var choices = std.mem.tokenizeScalar(u8, sms, ','); var any = false; while (choices.next()) |sm| { @@ -17,10 +17,13 @@ pub fn fatbin(b: *std.Build, nvcc: []const u8, version: std.Build.LazyPath, k: K } if (!any) return b.addWriteFiles().add(b.fmt("unsupported-{s}.fatbin", .{k.name}), ""); const run = b.addSystemCommand(&.{ nvcc, "-fatbin" }); - run.addFileInput(version); + // nvcc's own bytes key every image, so a new compiler rebuilds them; a side-effect `nvcc --version` capture is + // rewritten each build and missed every image's cache + run.addFileInput(.{ .cwd_relative = nvcc }); run.addArgs(&torch_flags); - // CUDA 13's headers with cl.exe need MSVC's conforming preprocessor and M_SQRT2's math define. - if (b.graph.host.result.os.tag == .windows) run.addArgs(&.{ "-Xcompiler=/Zc:preprocessor", "-D_USE_MATH_DEFINES" }); + // CUDA 13's headers with cl.exe need MSVC's conforming preprocessor and M_SQRT2's math define; under a CJK system + // code page, C4819 (a header character it cannot represent) buries the real errors in thousands of warnings. + if (b.graph.host.result.os.tag == .windows) run.addArgs(&.{ "-Xcompiler=/Zc:preprocessor", "-Xcompiler=/wd4819", "-D_USE_MATH_DEFINES" }); run.addArgs(k.flags); // Generated CUDA sources resolve the same maintained headers as checked-in units. run.addDirectoryArg2(b.path("zig/kernels/cuda"), .{ .prefix = "-I" }); diff --git a/zig/build/dsv41_images.zig b/zig/build/dsv41_images.zig index 6ebcc7dd8d3..7d38e9d3e39 100644 --- a/zig/build/dsv41_images.zig +++ b/zig/build/dsv41_images.zig @@ -22,9 +22,8 @@ pub fn images(b: *std.Build, nvcc: ?[]const u8, prebuilt: ?[]const u8) ?*const I path.* = if (std.Io.Dir.cwd().access(b.graph.io, file, .{})) |_| b.graph.cwdRelativePath(file) else |_| null; } } else if (nvcc) |compiler| { - const version = b.addSystemCommand(&.{ compiler, "--version" }).captureStdOut(.{}); - for (list.units, &result.units) |unit, *path| path.* = cuda_build.fatbin(b, compiler, version, unit, "121"); - for (list.optional, &result.optional) |unit, *path| path.* = cuda_build.fatbin(b, compiler, version, unit, "121"); + for (list.units, &result.units) |unit, *path| path.* = cuda_build.fatbin(b, compiler, unit, "121"); + for (list.optional, &result.optional) |unit, *path| path.* = cuda_build.fatbin(b, compiler, unit, "121"); } else { step.dependOn(&b.addFail("fatbins-dsv41 needs -Ddsv41-nvcc=PATH or -Ddsv41-fatbins=DIR").step); return null; diff --git a/zig/build/h3_image_cuda.zig b/zig/build/h3_image_cuda.zig index 6129407dc54..f2efe59124c 100644 --- a/zig/build/h3_image_cuda.zig +++ b/zig/build/h3_image_cuda.zig @@ -3,12 +3,12 @@ const std = @import("std"); pub fn steps(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, opts: @import("options.zig").Cuda, test_step: *std.Build.Step) void { - const image = if (opts.nvcc) |nvcc| @import("cuda_fatbin.zig").fatbin(b, nvcc, b.addSystemCommand(&.{ nvcc, "--version" }).captureStdOut(.{}), .{ .name = "h3", .flags = &.{"-O3"} }, opts.sms) else b.addWriteFiles().add("h3-compile-only.fatbin", ""); + const image = if (opts.nvcc) |nvcc| @import("cuda_fatbin.zig").fatbin(b, nvcc, .{ .name = "h3", .flags = &.{"-O3"} }, opts.sms) else b.addWriteFiles().add("h3-compile-only.fatbin", ""); const cuda = @import("cuda.zig").runtime(b, target, optimize, &.{}); const core = @import("h3_host.zig").coreModule(b, target); const h3 = b.createModule(.{ .root_source_file = b.path("zig/src/families/h3/cuda.zig"), .target = target, .optimize = optimize, .link_libc = true, .imports = &.{ .{ .name = "cuda", .module = cuda }, .{ .name = "core", .module = core } } }); h3.addAnonymousImport("fatbin_h3", .{ .root_source_file = image }); - const modulation = if (opts.nvcc) |nvcc| @import("cuda_fatbin.zig").fatbin(b, nvcc, b.addSystemCommand(&.{ nvcc, "--version" }).captureStdOut(.{}), .{ .name = "h3_image_modulation", .flags = &.{ "-O3", "--fmad=false" } }, opts.sms) else b.addWriteFiles().add("h3-modulation-compile-only.fatbin", ""); + const modulation = if (opts.nvcc) |nvcc| @import("cuda_fatbin.zig").fatbin(b, nvcc, .{ .name = "h3_image_modulation", .flags = &.{ "-O3", "--fmad=false" } }, opts.sms) else b.addWriteFiles().add("h3-modulation-compile-only.fatbin", ""); h3.addAnonymousImport("fatbin_h3_modulation", .{ .root_source_file = modulation }); const exe = b.addExecutable(.{ .name = "tf-h3-image-cuda", .root_module = b.createModule(.{ .root_source_file = b.path("zig/tests/h3_image_cuda.zig"), .target = target, .optimize = optimize, .link_libc = true, .imports = &.{ .{ .name = "h3cuda", .module = h3 }, diff --git a/zig/build/h3_image_decoder_cuda.zig b/zig/build/h3_image_decoder_cuda.zig index 3c59229649a..863c4cdba89 100644 --- a/zig/build/h3_image_decoder_cuda.zig +++ b/zig/build/h3_image_decoder_cuda.zig @@ -3,7 +3,7 @@ const std = @import("std"); pub fn steps(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, opts: @import("options.zig").Cuda, test_step: *std.Build.Step) void { // no FMA contraction: the norms', attention's and SwiGLU's fp32 multiply-adds round as the host reference's do - const image = if (opts.nvcc) |nvcc| @import("cuda_fatbin.zig").fatbin(b, nvcc, b.addSystemCommand(&.{ nvcc, "--version" }).captureStdOut(.{}), .{ .name = "h3_image_decoder", .flags = &.{ "-O3", "--fmad=false" }, .min_sm = 80 }, opts.sms) else b.addWriteFiles().add("h3-image-decoder-compile-only.fatbin", ""); + const image = if (opts.nvcc) |nvcc| @import("cuda_fatbin.zig").fatbin(b, nvcc, .{ .name = "h3_image_decoder", .flags = &.{ "-O3", "--fmad=false" }, .min_sm = 80 }, opts.sms) else b.addWriteFiles().add("h3-image-decoder-compile-only.fatbin", ""); const cuda = @import("cuda.zig").runtime(b, target, optimize, &.{}); const core = @import("h3_host.zig").coreModule(b, target); const writer = b.createModule(.{ .root_source_file = b.path("zig/src/picture_writer.zig"), .target = target, .optimize = optimize }); diff --git a/zig/build/h3_image_prompt_cuda.zig b/zig/build/h3_image_prompt_cuda.zig index cd4593d26d6..720577fb72b 100644 --- a/zig/build/h3_image_prompt_cuda.zig +++ b/zig/build/h3_image_prompt_cuda.zig @@ -6,7 +6,7 @@ const std = @import("std"); /// selftest against the float64 host reference. pub fn steps(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, opts: @import("options.zig").Cuda, test_step: *std.Build.Step) void { const image = if (opts.nvcc) |nvcc| - @import("cuda_fatbin.zig").fatbin(b, nvcc, b.addSystemCommand(&.{ nvcc, "--version" }).captureStdOut(.{}), .{ .name = "h3_image_prompt", .flags = &.{"-O3"}, .min_sm = 80 }, opts.sms) + @import("cuda_fatbin.zig").fatbin(b, nvcc, .{ .name = "h3_image_prompt", .flags = &.{"-O3"}, .min_sm = 80 }, opts.sms) else b.addWriteFiles().add("h3-image-prompt-compile-only.fatbin", ""); const cuda = @import("cuda.zig").runtime(b, target, optimize, &.{}); diff --git a/zig/build/muse.zig b/zig/build/muse.zig index 82446e5f55d..c85fda00e4a 100644 --- a/zig/build/muse.zig +++ b/zig/build/muse.zig @@ -18,7 +18,9 @@ pub fn moduleOver(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std } /// tf-muse: rank 1 behind the server (`follow`) and the family's device checks; installed, and its own step. +/// Not on Windows: rank 1 follows over the POSIX TP session (tp.zig skips it there too). pub fn tool(b: *std.Build, m: *std.Build.Module, strip: ?bool) void { + if (m.resolved_target.?.result.os.tag == .windows) return; const root = b.createModule(.{ .root_source_file = b.path("zig/src/families/muse_spark/m1_main.zig"), .target = m.resolved_target, .optimize = m.optimize, .link_libc = true, .strip = strip }); for ([_][]const u8{ "cuda", "core", "tp", "tp_kernel" }) |name| root.addImport(name, m.import_table.get(name).?); root.addImport("muse_spark", m); diff --git a/zig/build/product.zig b/zig/build/product.zig index 29031dd1e1e..f11e4aee9aa 100644 --- a/zig/build/product.zig +++ b/zig/build/product.zig @@ -132,18 +132,13 @@ fn cudaServer(b: *std.Build, o: Options, build_options: *std.Build.Step.Options, /// The CUDA server; with neither nvcc nor prebuilt images, every image is an empty file, for a compile-only check. fn cudaProduct(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, nvcc: ?[]const u8, prebuilt: ?[]const u8, build_options: *std.Build.Step.Options, sm: []const u8) *std.Build.Step.Compile { const cuda_build = @import("cuda.zig"); - const version: ?std.Build.LazyPath = if (nvcc) |tool| blk: { - const run = b.addSystemCommand(&.{ tool, "--version" }); - run.has_side_effects = true; - break :blk run.captureStdOut(.{}); - } else null; const target_sm = catalog.Target.parse(sm); var images: [catalog.kernels.len]?std.Build.LazyPath = @splat(null); const check = b.addRunArtifact(b.addExecutable(.{ .name = "check-product-fatbins", .root_module = b.createModule(.{ .root_source_file = b.path("zig/build/check_product_fatbins.zig"), .target = b.graph.host }) })); const empty = b.addWriteFiles(); for (catalog.kernels, &images) |k, *image| { if (nvcc) |tool| { - image.* = @import("cuda_fatbin.zig").fatbin(b, tool, version.?, k, sm); + image.* = @import("cuda_fatbin.zig").fatbin(b, tool, k, sm); } else if (prebuilt == null) { image.* = empty.add(b.fmt("{s}.fatbin", .{k.name}), ""); } else { @@ -166,16 +161,18 @@ fn cudaProduct(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.bu return exe; } -/// `compile-native-cuda-windows`: the Windows CUDA product checked by the compiler from any host, emitting nothing. +/// `compile-native-cuda-windows`: the Windows CUDA products checked by the compiler from any host, emitting nothing. pub fn windowsCompile(b: *std.Build) *std.Build.Step { - const target = b.resolveTargetQuery(.{ .cpu_arch = .x86_64, .os_tag = .windows, .abi = .gnu, .cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64_v4 } }); const options = b.addOptions(); options.addOption([]const u8, "version", @import("../../build.zig.zon").version); options.addOption(bool, "is_release", false); options.addOption(bool, "slide_test_hooks", false); - const exe = cudaProduct(b, target, .ReleaseSafe, null, null, options, "120"); - const step = b.step("compile-native-cuda-windows", "Type-check the sm_120 Windows CUDA product (x86_64-windows-gnu), with empty kernel images"); - step.dependOn(&exe.step); // nothing asks for the binary, so the compiler checks without emitting or linking + const step = b.step("compile-native-cuda-windows", "Type-check the Windows CUDA products (sm_120 x86_64, sm_121 N1X aarch64), with empty kernel images"); + const x86 = b.resolveTargetQuery(.{ .cpu_arch = .x86_64, .os_tag = .windows, .abi = .gnu, .cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64_v4 } }); + const arm = b.resolveTargetQuery(.{ .cpu_arch = .aarch64, .os_tag = .windows, .abi = .gnu }); + // nothing asks for the binaries, so the compiler checks without emitting or linking + step.dependOn(&cudaProduct(b, x86, .ReleaseSafe, null, null, options, "120").step); + step.dependOn(&cudaProduct(b, arm, .ReleaseSafe, null, null, options, "121").step); return step; } diff --git a/zig/kernels/cuda/glm_index_rope.cuh b/zig/kernels/cuda/glm_index_rope.cuh index 7fd5c82882d..b05d782b5b8 100644 --- a/zig/kernels/cuda/glm_index_rope.cuh +++ b/zig/kernels/cuda/glm_index_rope.cuh @@ -9,7 +9,7 @@ namespace glm_rope { // Sine and cosine of pair i's angle pos inv[i], out of line: one copy of sincosf's large-angle path, not one a site. -static __device__ __attribute__((noinline)) void turn(int64_t pos, const float* inv, int i, float* s, float* c) { +static __device__ __noinline__ void turn(int64_t pos, const float* inv, int i, float* s, float* c) { sincosf(__fmul_rn((float)pos, inv[i]), s, c); } diff --git a/zig/src/server/device/read.zig b/zig/src/server/device/read.zig index f8c72fcf99e..9592e330b5d 100644 --- a/zig/src/server/device/read.zig +++ b/zig/src/server/device/read.zig @@ -126,6 +126,10 @@ const win = struct { const Release = *const fn (*Com) callconv(.winapi) u32; const EnumAdapters1 = *const fn (*Com, u32, *?*Com) callconv(.winapi) i32; const GetDesc1 = *const fn (*Com, *Desc) callconv(.winapi) i32; + /// Entry `i` of `com`'s vtable as `F`; aarch64 code pointers are 4-aligned, the vtable's slots untyped. + fn method(comptime F: type, com: *Com, i: usize) F { + return @ptrCast(@alignCast(com.vtable[i])); + } fn regString(a: Allocator, comptime sub: []const u8, comptime value: []const u8) []const u8 { var buf: [256]u16 = undefined; @@ -145,16 +149,16 @@ const win = struct { var raw: ?*anyopaque = null; if (create(&iid_factory1, &raw) < 0) return &.{}; const factory: *Com = @ptrCast(@alignCast(raw orelse return &.{})); - defer _ = @as(Release, @ptrCast(factory.vtable[2]))(factory); + defer _ = method(Release, factory, 2)(factory); var out: std.ArrayList(parse.Adapter) = .empty; var i: u32 = 0; while (i < 16) : (i += 1) { var adapter: ?*Com = null; - if (@as(EnumAdapters1, @ptrCast(factory.vtable[12]))(factory, i, &adapter) < 0) break; + if (method(EnumAdapters1, factory, 12)(factory, i, &adapter) < 0) break; const ad = adapter orelse break; - defer _ = @as(Release, @ptrCast(ad.vtable[2]))(ad); + defer _ = method(Release, ad, 2)(ad); var d: Desc = undefined; - if (@as(GetDesc1, @ptrCast(ad.vtable[10]))(ad, &d) < 0) continue; + if (method(GetDesc1, ad, 10)(ad, &d) < 0) continue; const name = std.unicode.utf16LeToUtf8Alloc(a, std.mem.sliceTo(&d.description, 0)) catch ""; try out.append(a, .{ .name = name, .vendor = d.vendor, .device = d.device, .memory = d.dedicated_video, .software = (d.flags & 2) != 0 }); } diff --git a/zig/src/server/gpu_turn.zig b/zig/src/server/gpu_turn.zig index f16b328c398..f5a717499df 100644 --- a/zig/src/server/gpu_turn.zig +++ b/zig/src/server/gpu_turn.zig @@ -1,5 +1,6 @@ //! Speech holds a shared flock; batch work yields between short command buffers and tracks speech generations. const std = @import("std"); +const windows = @import("builtin").os.tag == .windows; pub const path = "/tmp/tensorfold-speech.lock"; @@ -48,7 +49,8 @@ fn open(io: std.Io, at: []const u8) !std.Io.File { return dir.openFile(io, at, .{}) catch |e| switch (e) { error.FileNotFound => { const file = try dir.createFile(io, at, .{ .read = true, .truncate = false }); - file.setPermissions(io, .fromMode(0o644)) catch {}; // past the creator's umask, so the other user opens it + // past the creator's umask, so the other user opens it; Windows has no mode bits + if (!windows) file.setPermissions(io, .fromMode(0o644)) catch {}; return file; }, else => e, @@ -62,7 +64,7 @@ pub fn mark(io: std.Io, at: []const u8) ?Mark { const file = marker(io, at) catch return null; defer file.close(io); const stat = file.stat(io) catch return null; - if (stat.kind != .file or stat.permissions.toMode() & 0o666 != 0o666) return null; + if (stat.kind != .file or (!windows and stat.permissions.toMode() & 0o666 != 0o666)) return null; var result: Mark = .{ .inode = stat.inode, .bytes = undefined }; if ((file.readPositionalAll(io, &result.bytes, 0) catch return null) != result.bytes.len) return null; const lock = open(io, at) catch return null; @@ -101,7 +103,7 @@ fn marker(io: std.Io, at: []const u8) !std.Io.File { return create_err; }; errdefer file.close(io); - try file.setPermissions(io, .fromMode(0o666)); + if (!windows) try file.setPermissions(io, .fromMode(0o666)); var bytes: [16]u8 = undefined; io.random(&bytes); try file.writePositionalAll(io, &bytes, 0); diff --git a/zig/tests/cuda/contract_tests.zig b/zig/tests/cuda/contract_tests.zig index 60a71223219..b7bc2522dee 100644 --- a/zig/tests/cuda/contract_tests.zig +++ b/zig/tests/cuda/contract_tests.zig @@ -216,7 +216,8 @@ fn registered(gpu: check.Gpu, only: []const []const u8, t0: *i96) !g.Tally { defer for (&mm) |*m| m.deinit(); for (&mm) |*m| { const k = m.kernel() orelse { - std.debug.print("N/A {s}: cluster path needs sm_90 or newer, this GPU is sm_{d}\n", .{ mm_k.spec(m.kind).name, cap }); + const why = if (m.kind == .mlp128_bits or m.kind == .mlp128_fp64) "the MLP128 tile is served only on sm_120" else "cluster path needs sm_90 or newer"; + std.debug.print("N/A {s}: {s}, this GPU is sm_{d}\n", .{ mm_k.spec(m.kind).name, why, cap }); continue; }; if (cap < 90 and (m.kind == .lane_gemv or m.kind == .lane_gemv_split)) diff --git a/zig/tests/cuda/inkling2_mini_tests.zig b/zig/tests/cuda/inkling2_mini_tests.zig index 43bb5fdfb34..a56cb42c38b 100644 --- a/zig/tests/cuda/inkling2_mini_tests.zig +++ b/zig/tests/cuda/inkling2_mini_tests.zig @@ -274,6 +274,5 @@ pub fn reference(gpu: Gpu, model: []const u8, count_text: []const u8, text: []co const said = try tok.decode(gpa, all[ids.len..], false); defer gpa.free(said); std.debug.print("RESULT inkling2 mini vs float64 reference{s}: {d} of {d} greedy tokens differ, smallest reference margin {d:.4}: \"{s}\"\n", .{ if (plant) " (PLANTED: no messages)" else "", differ, count, smallest, said }); - if (plant) return check.expect(differ > 0, "inkling2 mini planted control: the reference without messages still agrees", .{}); try check.expect(differ == 0, "inkling2 mini greedy == reference: {d} of {d} tokens differ", .{ differ, count }); }