97 lines
7.9 KiB
PowerShell
97 lines
7.9 KiB
PowerShell
# Counter ASIC 3.0 item 6 (6 October 2026): the step cost of every reserve candidate family of spec 1.13.2 on PC 2's
|
|
# RTX 5090 (docs/plans/counter-asic-3-reserve.md). A signed `run` job published with --stop-miners: the app stops its
|
|
# miners before this script starts and restarts them when it ends (app/igneum-app/src/jobrun.rs, stop_miners_first);
|
|
# the script also switches the NVIDIA card off through POST api/cards with the settings.json key in both forms (with and
|
|
# without the device index; 6 October 2026: the index-less form switched nothing on 5 October) and restores it, and
|
|
# switches the prover off for the run and back on, both in a finally block; it never quits, restarts or updates the
|
|
# app and never writes settings.json. The card is confirmed quiet by nvidia-smi's compute-apps list and the process
|
|
# list (never api/state, which answers {} on this machine), writes proto-cuda/family-probe.cu (inlined below by
|
|
# make-pc2-playbook.sh, sha256 printed on both sides) into the job dir, compiles it with nvcc inside WSL2
|
|
# Ubuntu-24.04 (/usr/local/cuda-12.*) and runs it three times. Every number is a RESULT line; the probe's own
|
|
# "RESULT FAMILY ..." lines carry kernel, best ms, G steps/s, ns per step, the ratio to the alu chain and ok=1 for
|
|
# bit-exact against the CPU reference on two whole warps. Read back with `node tools/jobs.mjs <job id>`.
|
|
$ErrorActionPreference = 'Continue'
|
|
$appDir = if ($env:IGNEUM_APP_DIR) { $env:IGNEUM_APP_DIR } else { Join-Path $env:LOCALAPPDATA 'igneum\app' }
|
|
$urlFile = Join-Path $appDir 'app.url'
|
|
if (-not (Test-Path $urlFile)) { $urlFile = Join-Path $env:LOCALAPPDATA 'igneum\app\app.url' }
|
|
$base = (Get-Content $urlFile -Raw).Trim().TrimEnd('/')
|
|
function Stamp { (Get-Date).ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ssZ') }
|
|
function Prove($on) { try { (Invoke-RestMethod -Method Post -Uri "$base/api/prove" -ContentType 'application/json' -Body (@{on=$on} | ConvertTo-Json -Compress) -TimeoutSec 10) | ConvertTo-Json -Compress } catch { "error: $_" } }
|
|
function Smi($q) { try { (& nvidia-smi --query-gpu=$q --format=csv,noheader,nounits 2>$null) -join ' | ' } catch { 'nvidia-smi failed' } }
|
|
function CudaApps { @(& nvidia-smi --query-compute-apps=pid,process_name,used_memory --format=csv,noheader 2>$null | ForEach-Object { "$_" } | Where-Object { $_ -match 'igneum|sp1|prove' }) }
|
|
function WorkerProcs { @(Get-Process -ErrorAction SilentlyContinue | Where-Object { $_.ProcessName -match 'igneum-worker|igneum-miner' } | ForEach-Object { $_.ProcessName + ':' + $_.Id }) }
|
|
# the app's NVIDIA cards from its settings.json (READ ONLY; key = vendor:device:name), never api/state (it answers {} here).
|
|
# 6 October 2026 (coordinator): the 5 October scripts posted the key without the device index and switched nothing, so
|
|
# both forms are posted: the settings key as written and vendor:device.
|
|
$nvCards = @()
|
|
try {
|
|
$sj = Get-Content -LiteralPath (Join-Path $appDir 'settings.json') -Raw | ConvertFrom-Json
|
|
foreach ($prop in $sj.cards.PSObject.Properties) {
|
|
if ($prop.Name -like 'nvidia:*') {
|
|
$v = $prop.Value; $pp = [int] $v.power_pct; if ($pp -lt 50) { $pp = 80 }
|
|
$parts = $prop.Name -split ':'
|
|
$nvCards += @{ key = $prop.Name; short = ($parts[0] + ':' + $parts[1]); enabled = [bool] $v.enabled; identities = [int] $v.identities; power_pct = $pp }
|
|
}
|
|
}
|
|
} catch { "RESULT settings_read_failed $_" }
|
|
function SetCards([bool] $enabled) {
|
|
foreach ($c in $nvCards) {
|
|
foreach ($k in @($c.key, $c.short)) {
|
|
$body = @{ cards = @(@{ key = $k; enabled = $enabled; identities = $c.identities; power_pct = $c.power_pct }) } | ConvertTo-Json -Depth 5
|
|
try { Invoke-RestMethod -Uri "$base/api/cards" -Method POST -Body $body -ContentType 'application/json' -TimeoutSec 10 | Out-Null; "RESULT cards key=$k enabled=$enabled posted" } catch { "RESULT cards key=$k enabled=$enabled error: $_" }
|
|
}
|
|
}
|
|
}
|
|
"RESULT start $(Stamp) nvidia cards in settings.json: $(($nvCards | ForEach-Object { $_.key + ' enabled=' + $_.enabled + ' identities=' + $_.identities + ' power_pct=' + $_.power_pct }) -join ' | ')"
|
|
"RESULT workers_before $(Stamp) $((WorkerProcs) -join ' ') cuda_apps=[$((CudaApps) -join '; ')]"
|
|
try {
|
|
"RESULT prover_off $(Stamp) $(Prove $false)"
|
|
SetCards $false
|
|
Start-Sleep -Seconds 30
|
|
$t = 30; $apps = @(CudaApps); $procs = @(WorkerProcs | Where-Object { $_ -match 'cuda' })
|
|
while ($t -lt 150 -and ($apps.Count -gt 0 -or $procs.Count -gt 0)) { Start-Sleep -Seconds 10; $t += 10; $apps = @(CudaApps); $procs = @(WorkerProcs | Where-Object { $_ -match 'cuda' }) }
|
|
if ($apps.Count -eq 0 -and $procs.Count -eq 0) { "RESULT card $(Stamp) quiet after $t s (no igneum, sp1 or prove compute app; no igneum-worker-cuda process): the card to itself" } else { "RESULT card $(Stamp) UNCONFIRMED after $t s: the rows below are beside compute apps [" + ($apps -join '; ') + "] procs [" + ($procs -join ' ') + "]" }
|
|
"RESULT gpus $(Stamp) $(Smi 'index,name,driver_version,memory.used,clocks.sm,clocks.mem,power.draw,temperature.gpu')"
|
|
$job = $env:IGNEUM_JOB_DIR; if (-not $job) { $job = Join-Path $env:TEMP 'igneum-ca3-family' }; New-Item -ItemType Directory -Force -Path $job | Out-Null
|
|
$cu = @'
|
|
CU_PLACEHOLDER
|
|
'@
|
|
$cuFile = Join-Path $job 'family-probe.cu'
|
|
[IO.File]::WriteAllText($cuFile, (($cu -replace "`r`n", "`n") + "`n"), (New-Object System.Text.UTF8Encoding $false))
|
|
"RESULT source family-probe.cu sha256 $((Get-FileHash -Algorithm SHA256 $cuFile).Hash.ToLower()) bytes $((Get-Item $cuFile).Length)"
|
|
function WslPath($p) { $w = (& wsl.exe -d Ubuntu-24.04 -u root -- wslpath -a ($p -replace '\\', '/') 2>$null); if ($w) { ($w -replace "`0", '').Trim() } else { '/mnt/c' + ($p.Substring(2) -replace '\\', '/') } }
|
|
$bash = @'
|
|
set -uo pipefail
|
|
CUDA_DIR="$(ls -d /usr/local/cuda-12.* 2>/dev/null | sort -V | tail -1 || true)"
|
|
[ -n "$CUDA_DIR" ] || { echo "RESULT build_failed no /usr/local/cuda-12.*"; exit 2; }
|
|
export PATH="$CUDA_DIR/bin:$PATH" LD_LIBRARY_PATH="$CUDA_DIR/lib64:/usr/lib/wsl/lib:${LD_LIBRARY_PATH:-}"
|
|
stamp() { date -u +%Y-%m-%dT%H:%M:%SZ; }
|
|
SRC='SRC_PLACEHOLDER'
|
|
W=/tmp/igneum-ca3-family; rm -rf "$W"; mkdir -p "$W"; cp "$SRC" "$W/family-probe.cu"; cd "$W"
|
|
echo "RESULT nvcc $(nvcc --version | grep -o 'release [0-9.]*' | head -1) cuda_dir=$CUDA_DIR"
|
|
echo "RESULT source_wsl sha256=$(sha256sum family-probe.cu | cut -c1-64) bytes=$(stat -c %s family-probe.cu)"
|
|
if nvcc -O2 -arch=sm_120 -o family-probe family-probe.cu > build.log 2>&1; then echo "RESULT build ok arch=sm_120"
|
|
else
|
|
echo "RESULT build sm_120 failed: $(grep -m1 -i 'error' build.log | cut -c1-200)"
|
|
if nvcc -O2 -gencode arch=compute_89,code=compute_89 -o family-probe family-probe.cu > build2.log 2>&1; then echo "RESULT build ok arch=compute_89 (PTX, driver JIT)"
|
|
else echo "RESULT build_failed $(grep -m1 -i 'error' build2.log | cut -c1-200)"; exit 2; fi
|
|
fi
|
|
echo "RESULT binary sha256=$(sha256sum family-probe | cut -c1-16)"
|
|
for i in 1 2 3; do
|
|
echo "RESULT run $i start $(stamp) gpu_before $(nvidia-smi --query-gpu=clocks.sm,clocks.mem,power.draw,temperature.gpu --format=csv,noheader,nounits 2>/dev/null | head -1)"
|
|
./family-probe --reps 3 2>&1 | sed "s/^RESULT /RESULT run=$i /; t; s/^/RESULT run=$i text /"
|
|
echo "RESULT run $i end $(stamp) exit=${PIPESTATUS[0]} gpu_after $(nvidia-smi --query-gpu=clocks.sm,clocks.mem,power.draw,temperature.gpu --format=csv,noheader,nounits 2>/dev/null | head -1)"
|
|
done
|
|
echo "RESULT measure_end $(stamp)"
|
|
'@
|
|
$bash = $bash.Replace('SRC_PLACEHOLDER', (WslPath $cuFile))
|
|
$bashFile = Join-Path $job 'measure.sh'
|
|
[IO.File]::WriteAllText($bashFile, ($bash -replace "`r`n", "`n"), (New-Object System.Text.UTF8Encoding $false))
|
|
& wsl.exe -d Ubuntu-24.04 -u root -- bash (WslPath $bashFile) 2>&1 | ForEach-Object { ($_ -replace "`0", '') }
|
|
"RESULT gpus_after $(Stamp) $(Smi 'clocks.sm,clocks.mem,power.draw,temperature.gpu')"
|
|
} finally {
|
|
# whatever happened above: the cards back to their settings.json state and the prover ON (the clear file's rule)
|
|
foreach ($c in $nvCards) { if ($c.enabled) { SetCards $true } }
|
|
"RESULT end $(Stamp) prover back on: $(Prove $true)"
|
|
}
|
|
exit 0
|