diff --git a/messung/farm/geteilt/geteilt-lauf.ps1 b/messung/farm/geteilt/geteilt-lauf.ps1 new file mode 100644 index 00000000..6ff34798 --- /dev/null +++ b/messung/farm/geteilt/geteilt-lauf.ps1 @@ -0,0 +1,37 @@ +# Geteilte Tafeln (05.12., main): MOTOR_TAFEL_MMAP=1 laesst die Motor-Tafeln als geteiltes Dateiabbild laden. +# 1) Bau beider Arme nativ (.cargo): Kandidat c3a036da0 (von 86911151, Loeser temp-86911151), Basis 1f004aef0 (von 2a0b655f, Loeser temp-2a0b655f). +# 2) Bitgleich je Arm: alte Exe zweimal (Grundrauschen), neue ohne und mit Schalter, 300 Anfragen basis-rein; private Speicherspitze je Prozess. +# 3) Duplikat 15 min wie Tempolauf 3 (Cache, MinFreiGB 14, 24 Tische), beide Arme neue Exe + MOTOR_TAFEL_MMAP=1. +$ErrorActionPreference = 'Continue' +if ((Test-Path 'D:\Projects\pokerfreak\scratch\laeufer.pid') -or (Test-Path 'D:\Projects\pokerfreak\.claude\worktrees\engine-lecks-angreifen-de7b88\betrieb\scratch\laeufer.pid')) { 'SPIELT'; exit 2 } +$z = 'C:\pf-arbeit\geteilt'; New-Item -ItemType Directory -Force $z | Out-Null +$bauten = [ordered]@{ kandidat = @('c3a036da0', '86911151'); basis = @('1f004aef0', '2a0b655f') } +$exe = @{} +foreach ($arm in $bauten.Keys) { + $c, $loeser = $bauten[$arm]; $baum = "C:\pf-arbeit\pf-geteilt-$c" + if (-not (Test-Path "$baum\entscheiden\motor\Cargo.toml")) { New-Item -ItemType Directory -Force $baum | Out-Null; tar -xf "$baum.tar" -C $baum } + $toml = "$baum\entscheiden\motor\Cargo.toml"; (Get-Content $toml) -replace 'postflop-solver-temp"', "postflop-solver-temp-$loeser`"" | Set-Content $toml -Encoding utf8 + "-- $arm $c Loeser temp-$loeser, .cargo " + (Test-Path "$baum\.cargo\config.toml") + Push-Location "$baum\entscheiden\motor"; cargo build --release -j 16 --bin motor 2>&1 | Select-Object -Last 2; $rc = $LASTEXITCODE; Pop-Location + if ($rc -ne 0) { "BAU $arm fehlgeschlagen $rc"; exit 1 } + $exe[$arm] = "$z\pokerbench-geteilt-$arm-$c.exe" + if (-not (Test-Path $exe[$arm])) { Copy-Item "$baum\entscheiden\motor\target\release\motor.exe" $exe[$arm] } + "EXE $($exe[$arm]) " + (Get-FileHash $exe[$arm]).Hash +} +$D = 'D:/Projects/pokerfreak-daten/grundstrategie-mitzaehler'; $ein = 'D:\Projects\pokerfreak-daten\pruefstand\basis-rein\ein.jsonl' +$pruef = @{ kandidat = @('D:\Projects\pokerfreak-daten\pruefstand\temperatur-uhr-86911151\kern_schalter.txt', 'D:\Projects\pf-temperatur\pokerbench-temperatur-rein-86911151.exe'); + basis = @('D:\Projects\pokerfreak\scratch\basis-rein-temperatur\kern_schalter.txt', 'D:\Projects\pf-temperatur\pokerbench-temperatur-rein-2a0b655f.exe') } +$bitRc = 0 +foreach ($arm in 'kandidat', 'basis') { + "=================== Bitgleich $arm" + python -X utf8 "$z\geteilt_bit.py" $pruef[$arm][0] $pruef[$arm][1] $exe[$arm] $ein 300 "$z\bit-$arm" $D 2>&1 | % { "$_" } + "RUECKGABE bit-$arm $LASTEXITCODE"; if ($LASTEXITCODE -ne 0) { $bitRc = 1 } +} +"=================== Duplikat 15 min, geteilte Tafeln" +$messer = "while (`$true) { `$o = Get-CimInstance Win32_OperatingSystem; `$m = @(Get-Process pokerbench-geteilt-* -EA 0); '{0:HH:mm:ss}`t{1:N1}`t{2:N1}`t{3}`t{4:N2}' -f (Get-Date), (`$o.FreePhysicalMemory/1MB), (`$o.FreeVirtualMemory/1MB), `$m.Count, ((`$m | Measure-Object PrivateMemorySize64 -Sum).Sum/1GB) | Add-Content $z\speicher.tsv; Start-Sleep 30 }" +Set-Content "$z\speicher.tsv" "zeit`tfrei_phys_gb`tfrei_zusage_gb`tmotoren`tmotor_privat_gb" +$mp = Start-Process powershell -ArgumentList '-NoProfile', '-Command', $messer -WindowStyle Hidden -PassThru +& D:\Projects\pf-batterie\messung\farm\pokerbench-temperatur-duplikat.ps1 -Kandidat 86911151 -Etikett -geteilt -Minuten 15 -Tischliste '1,1,1,3,3,3,5,5,5,1,3,5' -Cache -MinFreiGB 14 -OhneBeleg -ExeBasis $exe.basis -ExeKandidat $exe.kandidat -ZusatzZeile 'MOTOR_TAFEL_MMAP=1' +$dupRc = $LASTEXITCODE; Stop-Process -Id $mp.Id -Force -EA 0 +"RUECKGABE duplikat $dupRc (Bitgleich $bitRc)" +exit $bitRc diff --git a/messung/farm/geteilt/geteilt_bit.py b/messung/farm/geteilt/geteilt_bit.py new file mode 100644 index 00000000..0a363ece --- /dev/null +++ b/messung/farm/geteilt/geteilt_bit.py @@ -0,0 +1,115 @@ +"""Bitgleich-Probe geteilte Tafeln (MOTOR_TAFEL_MMAP): alte Exe zweimal (Grundrauschen, z. B. Uhr), neue Exe ohne und mit Schalter. + +Je Variante laeuft `motor dienst sechs100 ...` ueber die ersten N Zeilen einer Anfragedatei, mit der Umgebung des Arms +(MOTOR_ZEILE aus dem Schalter, ohne Gedaechtnis-Schichten, MOTOR_NL2=0 wie im Duplikat). Verglichen werden die Antworten +ohne Zeitangaben (Zahlen vor "ms", Felder *_ms/timing). Gemessen: Spitze des privaten Speichers je Prozess +(PeakPagefileUsage, Windows) und Wanduhr. + + python geteilt_bit.py +Exit 0: alle gleich. Exit 1: Abweichung (Liste in /abweichungen.txt). +""" +import ctypes +import json +import os +import re +import subprocess +import sys +import time + +WEG = re.compile(r"^(MOTOR_GEDAECHTNIS2|MOTOR_SPIELER_LINIE.*|MOTOR_POOL_UNSERE)$") +MS = re.compile(r"\d+(\.\d+)?\s?ms") + + +def zeile(schalter): + roh = [z for z in open(schalter, encoding="utf-8").read().splitlines() if z.startswith("MOTOR_ZEILE=")][-1][12:] + env = {} + for teil in roh.split(";"): + if "=" in teil: + k, v = teil.split("=", 1) + if not WEG.match(k): + env[k] = v + env["MOTOR_NL2"] = "0" + return env + + +class PMC(ctypes.Structure): + _fields_ = [("cb", ctypes.c_ulong), ("PageFaultCount", ctypes.c_ulong), ("PeakWorkingSetSize", ctypes.c_size_t), + ("WorkingSetSize", ctypes.c_size_t), ("QuotaPeakPagedPoolUsage", ctypes.c_size_t), + ("QuotaPagedPoolUsage", ctypes.c_size_t), ("QuotaPeakNonPagedPoolUsage", ctypes.c_size_t), + ("QuotaNonPagedPoolUsage", ctypes.c_size_t), ("PagefileUsage", ctypes.c_size_t), + ("PeakPagefileUsage", ctypes.c_size_t)] + + +def spitzen(pid): + """(privat_spitze_gb, arbeitssatz_spitze_gb) des laufenden Prozesses.""" + h = ctypes.windll.kernel32.OpenProcess(0x1000 | 0x0010, False, pid) + m = PMC() + m.cb = ctypes.sizeof(PMC) + ok = ctypes.windll.psapi.GetProcessMemoryInfo(h, ctypes.byref(m), m.cb) + ctypes.windll.kernel32.CloseHandle(h) + return (m.PeakPagefileUsage / 2**30, m.PeakWorkingSetSize / 2**30) if ok else (None, None) + + +def lauf(exe, env, ein, aus, daten): + args = [exe, "dienst", "sechs100", daten, "2000-600-400", "200", daten + "/sechs100-v2.bin", "genau", + "hu=%s/hu100-v1.bin,%s/hu200-v2.bin" % (daten, daten)] + t0 = time.time() + with open(ein, "rb") as fe, open(aus, "wb") as fa, open(aus + ".err", "wb") as ff: + p = subprocess.Popen(args, stdin=fe, stdout=fa, stderr=ff, env=env, creationflags=0x08000000 | 0x4000) + spitze = (0.0, 0.0) + while p.poll() is None: + s = spitzen(p.pid) + if s[0] is not None: + spitze = (max(spitze[0], s[0]), max(spitze[1], s[1])) + time.sleep(0.5) + return p.returncode, time.time() - t0, spitze + + +def ohne_zeit(o): + if isinstance(o, dict): + return {k: ohne_zeit(v) for k, v in o.items() if k != "timing" and not k.endswith("_ms")} + if isinstance(o, list): + return [ohne_zeit(v) for v in o] + if isinstance(o, str): + return MS.sub("", o) + return o + + +def main(): + schalter, alt, neu, anfragen, n, ordner, daten = sys.argv[1:8] + os.makedirs(ordner, exist_ok=True) + ein = os.path.join(ordner, "ein.jsonl") + if not os.path.exists(ein): + with open(anfragen, encoding="utf-8") as f, open(ein + ".tmp", "w", encoding="utf-8") as g: + for i, z in enumerate(f): + if i >= int(n): + break + g.write(z) + os.replace(ein + ".tmp", ein) + basis = dict(os.environ, **zeile(schalter), RAYON_NUM_THREADS="8") + basis.pop("MOTOR_TAFEL_MMAP", None) + varianten = [("alt", alt, {}), ("alt2", alt, {}), ("neu-aus", neu, {}), ("neu-an", neu, {"MOTOR_TAFEL_MMAP": "1"})] + zeilen = {} + for name, exe, extra in varianten: + aus = os.path.join(ordner, "aus-%s.jsonl" % name) + if os.path.exists(aus) and os.path.getsize(aus) > 0: + print("ROT: %s existiert, nicht ueberschreiben" % aus) + sys.exit(3) + rc, dauer, (priv, ws) = lauf(exe, dict(basis, **extra), ein, aus, daten) + print("%-8s rc=%s %.0f s privat_spitze=%.2f GB arbeitssatz_spitze=%.2f GB" % (name, rc, dauer, priv, ws), flush=True) + zeilen[name] = [ohne_zeit(json.loads(z)) for z in open(aus, encoding="utf-8") if z.strip()] + ab = [] + for name in ("alt2", "neu-aus", "neu-an"): + if len(zeilen[name]) != len(zeilen["alt"]): + ab.append("%s: %d Zeilen gegen %d" % (name, len(zeilen[name]), len(zeilen["alt"]))) + for i, (a, b) in enumerate(zip(zeilen["alt"], zeilen[name])): + if a != b: + ab.append("%s Zeile %d" % (name, i + 1)) + with open(os.path.join(ordner, "abweichungen.txt"), "w", encoding="utf-8") as f: + f.write("\n".join(ab) + "\n") + print("Zeilen %d, Abweichungen %d (ohne Zeitangaben)" % (len(zeilen["alt"]), len(ab))) + sys.exit(1 if ab else 0) + + +if __name__ == "__main__": + main() diff --git a/messung/farm/pokerbench-temperatur-duplikat.ps1 b/messung/farm/pokerbench-temperatur-duplikat.ps1 index 218f2bd3..76e4c726 100644 --- a/messung/farm/pokerbench-temperatur-duplikat.ps1 +++ b/messung/farm/pokerbench-temperatur-duplikat.ps1 @@ -5,7 +5,7 @@ # MOTOR_POOL_UNSERE: Wissen ueber echte Gegner; ausserdem schreibt so kein Simlauf in die Live-Gedaechtnisse). Alles andere der Zeile bleibt. # Beide Arme mit normalen Tafeln (grundstrategie-mitzaehler, ~9,5 GB je Motor), dieselben Tische und Saaten (32 Bit), Aufstellungen 1v5/3v3/5v1. # pokerbench-temperatur-duplikat.ps1 -Minuten 15 -Tischliste 1,1,1,3,3,3,5,5,5 (Hauptsession 05.12.: alle Tore zusammen hoechstens 15 min; fenster_min im Beleg) -param([string]$Kandidat = '86911151', [string]$Etikett = '', [int]$Minuten = 15, [string]$Tischliste = '1,1,3,5', [int]$Saat = 2026120400, [int]$Blaetter = 5000, [switch]$Fortsetzen, [int]$Ziel = 0, [switch]$Cache, [int]$MinFreiGB = 25, [int]$Abstand = 15, [switch]$OhneBeleg) +param([string]$Kandidat = '86911151', [string]$Etikett = '', [int]$Minuten = 15, [string]$Tischliste = '1,1,3,5', [int]$Saat = 2026120400, [int]$Blaetter = 5000, [switch]$Fortsetzen, [int]$Ziel = 0, [switch]$Cache, [int]$MinFreiGB = 25, [int]$Abstand = 15, [switch]$OhneBeleg, [string]$ExeBasis = '', [string]$ExeKandidat = '', [string]$ZusatzZeile = '') $f = 'D:\Projects\pf-batterie\messung\farm'; $o = "$f\temperatur-$Kandidat-tor3$Etikett"; New-Item -ItemType Directory -Force $o | Out-Null; $log = "$o\kette.log" Set-Content "$o\STARTER.pid" $PID function Log($t) { Add-Content -Path $log -Value ((Get-Date -Format 'HH:mm:ss') + ' ' + $t) -Encoding UTF8 } @@ -25,9 +25,10 @@ function Zeile([string]$datei) { (($roh -split ';' | ? { $_ -match '=' } | ? { ($_ -split '=', 2)[0] -notmatch $weg }) -join ' ') } function ExeAus([string]$datei) { ((Get-Content $datei | ? { $_ -like 'MOTOR_EXE=*' }) | Select-Object -Last 1).Substring(10) } -$basisExe = ExeAus $basisSchalter; $kandExe = ExeAus $kandSchalter +$basisExe = $(if ($ExeBasis) { $ExeBasis } else { ExeAus $basisSchalter }); $kandExe = $(if ($ExeKandidat) { $ExeKandidat } else { ExeAus $kandSchalter }) # 05.12.: -ExeBasis/-ExeKandidat fuer Bauten gleicher Quelle (geteilte Tafeln) Log ("Schalter basis {0} {1} | kandidat {2} {3}" -f $basisSchalter, (Get-FileHash $basisSchalter).Hash, $kandSchalter, (Get-FileHash $kandSchalter).Hash) -$arme = [ordered]@{ 'basis' = @($basisExe, ("MOTOR_NL2=0 " + (Zeile $basisSchalter))); 'kandidat' = @($kandExe, ("MOTOR_NL2=0 " + (Zeile $kandSchalter))) } +$zusatz = $(if ($ZusatzZeile) { " $ZusatzZeile" } else { '' }) # z. B. MOTOR_TAFEL_MMAP=1 in beiden Armen +$arme = [ordered]@{ 'basis' = @($basisExe, ("MOTOR_NL2=0 " + (Zeile $basisSchalter) + $zusatz)); 'kandidat' = @($kandExe, ("MOTOR_NL2=0 " + (Zeile $kandSchalter) + $zusatz)) } foreach ($a in $arme.Keys) { Log ("Arm {0}: {1} {2} | {3}" -f $a, $arme[$a][0], (Get-FileHash $arme[$a][0]).Hash, $arme[$a][1]) } Log "SHARINGAN: $sh"; Log "Optionen: Cache=$Cache MinFreiGB=$MinFreiGB Abstand=$Abstand Tischliste=$Tischliste OhneBeleg=$OhneBeleg" Add-Type -Namespace FarmR -Name Sp -MemberDefinition @'