Validate native Windows M against real PTX and correct patch-merge bounds

This commit is contained in:
Codex committed 2026-09-30 19:01:18 +03:00
1 parent 5592b7a921
commit 2db93adb1a
13 files changed
+611 -17

No files matched your search

+24
View File
@@ -0,0 +1,24 @@
[CmdletBinding()]
param([Parameter(Mandatory=$true)][string]$DlssDll, [string]$PackageRoot, [string]$OutputDirectory)
$ErrorActionPreference = 'Stop'
$repo = [IO.Path]::GetFullPath((Join-Path $PSScriptRoot '../..'))
if (!$PackageRoot) { $PackageRoot = Join-Path $repo 'dist/windows-rdna4-therock' }
if (!$OutputDirectory) { $OutputDirectory = Join-Path $repo 'build/native-m-gfx1201' }
if (![IO.Path]::IsPathRooted($DlssDll) -or !(Test-Path -LiteralPath $DlssDll)) {
throw 'Supply the absolute path to your local nvngx_dlss.dll.'
}
New-Item -ItemType Directory -Force $OutputDirectory | Out-Null
foreach ($layer in @('enc1','enc2','enc3_tube','dec2','dec1')) {
$name = "rrlite_${layer}_4x4"
$source = Join-Path $PackageRoot "experimental/m/${name}_gfx1201.hsaco"
if (!(Test-Path -LiteralPath $source)) { throw "Native M module missing: $source" }
Copy-Item -LiteralPath $source -Destination (Join-Path $OutputDirectory "$name.hsaco") -Force
}
& python (Join-Path $repo 'kernels/tools/kernel_manifest.py') $OutputDirectory $DlssDll
if ($LASTEXITCODE) { throw "Native manifest generation failed ($LASTEXITCODE)" }
@{architecture='gfx1201'; family='M'; numerics='SWIN_EXACT; FP16 widening; native FP8 disabled';
dlssSha256=(Get-FileHash -LiteralPath $DlssDll -Algorithm SHA256).Hash;
validation='synthetic layers passed; actual DLSS capture/reference validation required';
modules=@(Get-ChildItem -LiteralPath $OutputDirectory -Filter '*.hsaco' | Get-FileHash -Algorithm SHA256)} |
ConvertTo-Json -Depth 5 | Set-Content -LiteralPath (Join-Path $OutputDirectory 'build-info.json') -Encoding UTF8
Write-Host "Experimental native M directory: $OutputDirectory"
+49
View File
@@ -0,0 +1,49 @@
[CmdletBinding()]
param([Parameter(Mandatory=$true)][string]$CaptureDirectory, [string]$HipRoot,
[string]$PackageRoot, [string]$OutputDirectory, [int]$Blocks = 12,
[Parameter(Mandatory=$true)][string]$DlssDll, [int]$PtxBlocks = 2)
$ErrorActionPreference = 'Stop'
$repo = [IO.Path]::GetFullPath((Join-Path $PSScriptRoot '../..'))
if (!$HipRoot) { $HipRoot = Join-Path $repo '.tools/therock-10.2.0a20260929/_rocm_sdk_core' }
if (!$PackageRoot) { $PackageRoot = Join-Path $repo 'dist/windows-rdna4-therock' }
if (!$OutputDirectory) { $OutputDirectory = Join-Path $repo ('test-results/m-real-reference-' + (Get-Date -Format 'yyyyMMdd-HHmmss')) }
New-Item -ItemType Directory -Force $OutputDirectory | Out-Null
$previousPython=$env:PYTHONPATH; $previousDiag=$env:D4R_DIAG_DIR
$env:PYTHONPATH = "$(Join-Path $repo '.tools/python/vendor');$previousPython"
$summary = [ordered]@{utc=[DateTime]::UtcNow.ToString('o'); captureDirectory=$CaptureDirectory; layers=@(); passed=$false}
try {
foreach ($layer in @('enc1','enc2','enc3_tube','dec2','dec1')) {
$name = "rrlite_${layer}_4x4"
$captures = @(Get-ChildItem -LiteralPath $CaptureDirectory -Directory | Where-Object Name -Match ("^replay-[0-9]+-" + $name + '$'))
if (!$captures.Count) { throw "Missing actual M capture: $name" }
$capture = $captures | Sort-Object Name | Select-Object -First 1
$folder = Join-Path $OutputDirectory $layer
$output = Join-Path $folder 'output'
New-Item -ItemType Directory -Force $folder | Out-Null
$env:D4R_DIAG_DIR = $folder
& (Join-Path $PackageRoot 'bin/d4r_native_replay_probe.exe') --hip-root $HipRoot `
--module (Join-Path $PackageRoot "experimental/m/${name}_gfx1201.hsaco") `
--fixture-dir $capture.FullName --output-dir $output --iterations 1 `
> (Join-Path $folder 'gpu.stdout.log') 2> (Join-Path $folder 'gpu.stderr.log')
if ($LASTEXITCODE) { throw "M $layer actual GPU replay failed: $folder" }
& python (Join-Path $PackageRoot 'm_replay_validate.py') validate --layer $layer `
--fixture-dir $capture.FullName --output-dir $output --blocks $Blocks --real-capture `
> (Join-Path $folder 'reference.stdout.log') 2> (Join-Path $folder 'reference.stderr.log')
if ($LASTEXITCODE) { throw "M $layer mismatch; stopping before the next layer: $folder" }
Get-Content -LiteralPath (Join-Path $folder 'reference.stdout.log') | Write-Host
& python -u (Join-Path $PackageRoot 'm_ptx_validate.py') --layer $layer `
--capture-dir $capture.FullName --native-dir $output --dlss-dll $DlssDll `
--output-dir (Join-Path $folder 'private-ptx') --blocks $PtxBlocks `
> (Join-Path $folder 'ptx-reference.stdout.log') 2> (Join-Path $folder 'ptx-reference.stderr.log')
if ($LASTEXITCODE) { throw "M $layer independent PTX mismatch; stopping: $folder" }
Get-Content -LiteralPath (Join-Path $folder 'ptx-reference.stdout.log') | Write-Host
$summary.layers += @{layer=$layer; passed=$true}
}
$summary.passed=$true
} catch { $summary.error=$_.Exception.Message; Write-Warning $summary.error }
finally {
$env:PYTHONPATH=$previousPython; $env:D4R_DIAG_DIR=$previousDiag
$summary | ConvertTo-Json -Depth 5 | Set-Content -LiteralPath (Join-Path $OutputDirectory 'summary.json') -Encoding UTF8
Write-Host "Private real-weight replay results: $OutputDirectory (do not redistribute captures/allocations)"
}
if (!$summary.passed) { exit 1 }
+45
View File
@@ -0,0 +1,45 @@
[CmdletBinding()]
param([string]$HipRoot, [string]$PackageRoot, [string]$OutputDirectory,
[string[]]$Layers = @('enc1','enc2','enc3_tube','dec2','dec1'),
[ValidateRange(1,10000)][int]$Iterations = 32)
$ErrorActionPreference = 'Stop'
$repo = [IO.Path]::GetFullPath((Join-Path $PSScriptRoot '../..'))
if (!$HipRoot) { $HipRoot = Join-Path $repo '.tools/therock-10.2.0a20260929/_rocm_sdk_core' }
if (!$PackageRoot) { $PackageRoot = Join-Path $repo 'dist/windows-rdna4-therock' }
if (!$OutputDirectory) { $OutputDirectory = Join-Path $repo ('test-results/m-replay-' + (Get-Date -Format 'yyyyMMdd-HHmmss')) }
New-Item -ItemType Directory -Force $OutputDirectory | Out-Null
$previousPython = $env:PYTHONPATH
$previousDiag = $env:D4R_DIAG_DIR
$env:PYTHONPATH = "$(Join-Path $repo '.tools/python/vendor');$previousPython"
$summary = [ordered]@{utc=[DateTime]::UtcNow.ToString('o'); hipRoot=$HipRoot; layers=@(); passed=$false}
try {
foreach ($layer in $Layers) {
if ($layer -notmatch '^(enc[12]|enc3_tube|dec[12])$') { throw "Invalid M layer $layer" }
$folder = Join-Path $OutputDirectory $layer
$fixture = Join-Path $folder 'fixture'
$output = Join-Path $folder 'output'
New-Item -ItemType Directory -Force $folder | Out-Null
$env:D4R_DIAG_DIR = $folder
& python (Join-Path $PackageRoot 'm_replay_validate.py') generate --layer $layer --fixture-dir $fixture `
> (Join-Path $folder 'fixture.stdout.log') 2> (Join-Path $folder 'fixture.stderr.log')
if ($LASTEXITCODE) { throw "M $layer fixture generation failed: $folder" }
& (Join-Path $PackageRoot 'bin/d4r_native_replay_probe.exe') --hip-root $HipRoot `
--module (Join-Path $PackageRoot "experimental/m/rrlite_${layer}_4x4_gfx1201.hsaco") `
--fixture-dir $fixture --output-dir $output --iterations $Iterations `
> (Join-Path $folder 'gpu.stdout.log') 2> (Join-Path $folder 'gpu.stderr.log')
if ($LASTEXITCODE) { throw "M $layer GPU replay failed: $folder" }
& python (Join-Path $PackageRoot 'm_replay_validate.py') validate --layer $layer --fixture-dir $fixture --output-dir $output `
> (Join-Path $folder 'reference.stdout.log') 2> (Join-Path $folder 'reference.stderr.log')
if ($LASTEXITCODE) { throw "M $layer reference mismatch; stopping before the next layer: $folder" }
Get-Content -LiteralPath (Join-Path $folder 'reference.stdout.log') | Write-Host
$summary.layers += @{layer=$layer; passed=$true; iterations=$Iterations}
}
$summary.passed = $true
} catch { $summary.error=$_.Exception.Message; Write-Warning $summary.error }
finally {
$env:PYTHONPATH=$previousPython; $env:D4R_DIAG_DIR=$previousDiag
$summary | ConvertTo-Json -Depth 5 | Set-Content -LiteralPath (Join-Path $OutputDirectory 'summary.json') -Encoding UTF8
Compress-Archive -LiteralPath $OutputDirectory -DestinationPath "$OutputDirectory.zip" -Force
Write-Host "M replay bundle: $OutputDirectory.zip"
}
if (!$summary.passed) { exit 1 }
+8 -5
View File
@@ -98,8 +98,8 @@ function Invoke-Probe([string]$Name, [string]$Exe, [string[]]$Arguments) {
try {
if ($NgxOnly -and (!$NgxCore -or !$DlssDll)) { throw '-NgxOnly requires both locally supplied NVIDIA DLL paths.' }
if ($RequireNativeNetwork) {
if ($NgxMode -ne 'evaluate' -or $Preset -ne 11 -or !$env:D4R_ZLUDA_NATIVE_DIR) {
throw '-RequireNativeNetwork currently requires K Evaluate and D4R_ZLUDA_NATIVE_DIR.'
if ($NgxMode -ne 'evaluate' -or $Preset -notin @(11,13) -or !$env:D4R_ZLUDA_NATIVE_DIR) {
throw '-RequireNativeNetwork requires K/M Evaluate and D4R_ZLUDA_NATIVE_DIR.'
}
$env:D4R_ZLUDA_VERBOSE = '1'
}
@@ -223,15 +223,18 @@ try {
$ngxOk = Invoke-Probe $ngxName $ngxExe $ngxArguments
if ($ngxOk -and $RequireNativeNetwork) {
$hits = @()
foreach ($layer in @('enc0','enc1','enc2','enc3','enc4','dec5','dec4','dec3','dec2','dec1','dec0')) {
$pattern = '\[d4r-launch\] kernel="dltss_pwin_' + $layer + '_layer" backend=native'
$nativeLayers = if ($Preset -eq 11) { @('enc0','enc1','enc2','enc3','enc4','dec5','dec4','dec3','dec2','dec1','dec0') }
else { @('enc1','enc2','enc3_tube','dec2','dec1') }
foreach ($layer in $nativeLayers) {
$name = if ($Preset -eq 11) { "dltss_pwin_${layer}_layer" } else { "rrlite_${layer}_4x4" }
$pattern = '\[d4r-launch\] kernel="' + $name + '" backend=native'
$count = @(Select-String -LiteralPath (Join-Path $OutputDirectory "$ngxName.stderr.log") -Pattern $pattern).Count
$hits += @{layer=$layer; nativeLaunches=$count; expectedFrames=$Iterations}
if ($count -lt $Iterations) { $ngxOk=$false }
}
$summary.nativeTransformer = $hits
$summary.nativeTransformerPassed = $ngxOk
Write-Host "Native K transformer launches validated=$ngxOk"
Write-Host "Native preset $Preset transformer launches validated=$ngxOk"
}
if (!$ngxOk) {
$exitStatus = 1