Backport gfx1154 support into ZLUDA's Windows LLVM compiler
Adapt official LLVM 7a0829e41228 to the pinned LLVM 22 parser and ELF structures. Apply and audit the complete source delta before building, export its provenance, and package the source patch. Add 33 offline public PTX compilation checks across all eleven GPU targets without hardware execution. Preserve strict arithmetic and document RX9070XT K/M regressions.
This commit is contained in:
1 parent
b6b6d91ed9
commit
3d5f42865f
10 files changed
+307
-2
No files matched your search
@@ -12,6 +12,7 @@ if (!(Test-Path (Join-Path $SourceRoot 'ext/llvm-project/llvm/CMakeLists.txt')))
|
||||
throw 'Run git submodule update --init --depth 1 ext/llvm-project in the ZLUDA checkout.'
|
||||
}
|
||||
New-Item -ItemType Directory -Force $BuildRoot | Out-Null
|
||||
& (Join-Path $PSScriptRoot 'prepare-zluda-llvm-source.ps1') -LlvmSourceRoot (Join-Path $SourceRoot 'ext/llvm-project')
|
||||
$oldPath = $env:PATH
|
||||
try {
|
||||
$env:PATH = "$(Join-Path $toolchain 'bin');$oldPath"
|
||||
@@ -36,5 +37,9 @@ try {
|
||||
if ($LASTEXITCODE) { throw "LLVM build failed ($LASTEXITCODE)" }
|
||||
& (Join-Path $BuildRoot 'bin/llvm-config.exe') --version
|
||||
if ($LASTEXITCODE) { throw 'llvm-config verification failed' }
|
||||
@{sourceBase=(& git -C (Join-Path $SourceRoot 'ext/llvm-project') rev-parse HEAD).Trim(); fullSourceDeltaVerified=$true;
|
||||
sourcePatches=@(Get-ChildItem (Join-Path $repo 'patches/zluda-llvm') -Filter *.patch | ForEach-Object {
|
||||
@{name=$_.Name; sha256=(Get-FileHash -LiteralPath $_.FullName).Hash}})} |
|
||||
ConvertTo-Json -Depth 5 | Set-Content (Join-Path $BuildRoot 'd4r-llvm-build-info.json') -Encoding UTF8
|
||||
Write-Host "Native Windows LLVM: $BuildRoot"
|
||||
} finally { $env:PATH = $oldPath }
|
||||
@@ -84,6 +84,9 @@ try {
|
||||
@{base='ee2f25a180099fa42f36b2346732e1f2470a03ad'; target='x86_64-pc-windows-gnu';
|
||||
sourceCommit=(& git rev-parse HEAD); workingTreeDirty=[bool](& git status --porcelain);
|
||||
rust='1.98.1'; llvm=(& (Join-Path $LlvmBuildRoot 'bin/llvm-config.exe') --version);
|
||||
llvmSource=$(if (Test-Path (Join-Path $LlvmBuildRoot 'd4r-llvm-build-info.json')) {
|
||||
Get-Content (Join-Path $LlvmBuildRoot 'd4r-llvm-build-info.json') -Raw | ConvertFrom-Json
|
||||
} else { $null });
|
||||
files=@(Get-ChildItem -LiteralPath $InstallRoot -Filter '*.dll' | Get-FileHash -Algorithm SHA256)} |
|
||||
ConvertTo-Json -Depth 5 | Set-Content -LiteralPath (Join-Path $InstallRoot 'build-info.json') -Encoding UTF8
|
||||
Write-Host "Native Windows d4r ZLUDA runtime: $InstallRoot"
|
||||
|
||||
@@ -94,6 +94,7 @@ Stage (Join-Path $HipRoot 'share/doc/amd_comgr/LICENSE.txt') 'licenses/amd_comgr
|
||||
Stage (Join-Path $repo 'external/clr/LICENSE.md') 'licenses/HIP-CLR.txt'
|
||||
foreach ($patch in Get-ChildItem -LiteralPath (Join-Path $repo 'patches/optiscaler') -Filter '*.patch') { Stage $patch.FullName ('source-patches/optiscaler/' + $patch.Name) }
|
||||
foreach ($patch in Get-ChildItem -LiteralPath (Join-Path $repo 'patches/zluda') -Filter '*.patch') { Stage $patch.FullName ('source-patches/zluda/' + $patch.Name) }
|
||||
foreach ($patch in Get-ChildItem -LiteralPath (Join-Path $repo 'patches/zluda-llvm') -Filter '*.patch') { Stage $patch.FullName ('source-patches/zluda-llvm/' + $patch.Name) }
|
||||
$sourceArchive=Join-Path $repo 'build/d4r-windows-rdna4-source.zip'
|
||||
New-Item -ItemType Directory -Force (Split-Path $sourceArchive) | Out-Null
|
||||
& git -C $repo archive --format=zip --output $sourceArchive $sourceCommit
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
[CmdletBinding()]
|
||||
param([Parameter(Mandatory=$true)][string]$LlvmSourceRoot)
|
||||
$ErrorActionPreference='Stop'
|
||||
$repo=[IO.Path]::GetFullPath((Join-Path $PSScriptRoot '../..'))
|
||||
$expected='ff4dc1f7c9e1c64d4d69e40f4ed30c2280a96dfd'
|
||||
$actual=(& git -C $LlvmSourceRoot rev-parse HEAD).Trim()
|
||||
if ($LASTEXITCODE -or $actual -ne $expected) { throw "Expected audited ZLUDA LLVM source $expected, found $actual; review the patch against this revision." }
|
||||
$patches=@(Get-ChildItem (Join-Path $repo 'patches/zluda-llvm') -Filter *.patch | Sort-Object Name)
|
||||
foreach ($patch in $patches) {
|
||||
$oldPreference=$ErrorActionPreference
|
||||
try {
|
||||
$ErrorActionPreference='Continue'
|
||||
& git -C $LlvmSourceRoot apply --reverse --check $patch.FullName 2>$null
|
||||
$applied=($LASTEXITCODE -eq 0)
|
||||
} finally { $ErrorActionPreference=$oldPreference }
|
||||
if (!$applied) {
|
||||
& git -C $LlvmSourceRoot apply --check $patch.FullName
|
||||
if ($LASTEXITCODE) { throw "LLVM source patch conflicts: $($patch.Name)" }
|
||||
& git -C $LlvmSourceRoot apply $patch.FullName
|
||||
if ($LASTEXITCODE) { throw "LLVM source patch failed: $($patch.Name)" }
|
||||
}
|
||||
Write-Host "LLVM source patch present: $($patch.Name)"
|
||||
}
|
||||
# The pinned backport is the entire intended LLVM delta.
|
||||
if ($patches.Count -ne 1) { throw 'Review combined LLVM source provenance before adding more patches.' }
|
||||
$audit=Join-Path $repo ('build/llvm-source-audit-'+[Guid]::NewGuid().ToString('N')+'.patch')
|
||||
New-Item -ItemType Directory -Force (Split-Path $audit) | Out-Null
|
||||
try {
|
||||
& git -C $LlvmSourceRoot diff --binary --output=$audit
|
||||
if ($LASTEXITCODE) { throw 'Cannot audit LLVM source diff.' }
|
||||
$actualDiff=[IO.File]::ReadAllText($audit).Replace("`r`n","`n").TrimEnd()
|
||||
$expectedDiff=[IO.File]::ReadAllText($patches[0].FullName).Replace("`r`n","`n").TrimEnd()
|
||||
if ($actualDiff -cne $expectedDiff) { throw 'LLVM source contains changes outside the exported audited patch.' }
|
||||
} finally { if (Test-Path -LiteralPath $audit) { Remove-Item -LiteralPath $audit } }
|
||||
@@ -0,0 +1,67 @@
|
||||
[CmdletBinding()]
|
||||
param([string]$ZludaRoot, [string[]]$GpuArchitectures, [string]$OutputDirectory)
|
||||
$ErrorActionPreference='Stop'
|
||||
. (Join-Path $PSScriptRoot 'gpu-target.ps1')
|
||||
$repo=[IO.Path]::GetFullPath((Join-Path $PSScriptRoot '../..'))
|
||||
if (!$ZludaRoot) { $ZludaRoot=Join-Path $repo 'dist/zluda-windows-final' }
|
||||
if (!$OutputDirectory) { $OutputDirectory=Join-Path $repo 'test-results/zluda-target-compilation' }
|
||||
if (!$GpuArchitectures) { $GpuArchitectures=@(Get-D4RGpuTargets | ForEach-Object { $_.architecture }) }
|
||||
foreach ($arch in $GpuArchitectures) { [void](Get-D4RGpuTargetInfo $arch) }
|
||||
$emitter=Join-Path $ZludaRoot 'd4r_emit.exe'
|
||||
if (!(Test-Path -LiteralPath $emitter)) { throw "Rebuild ZLUDA and its offline emitter: $emitter" }
|
||||
New-Item -ItemType Directory -Force $OutputDirectory | Out-Null
|
||||
$settings=@{PATH="$ZludaRoot;$env:PATH"; D4R_ZLUDA_WMMA='1'; D4R_ZLUDA_WMMA_FP8='1';
|
||||
D4R_ZLUDA_WMMA_F16_REFERENCE='1'; D4R_ZLUDA_WMMA_FP8_NATIVE='0'; D4R_ZLUDA_WMMA_LAYOUT=$null;
|
||||
D4R_ZLUDA_WAVE64=$null; D4R_ZLUDA_FAST_MATH=$null; D4R_ZLUDA_IGNORE_DENORMAL=$null;
|
||||
D4R_ZLUDA_WMMA_F32ACC=$null; D4R_ZLUDA_EXTRA_BC=$null; D4R_ZLUDA_WGP=$null}
|
||||
$old=@{}; $rows=[Collections.Generic.List[object]]::new()
|
||||
try {
|
||||
foreach ($key in $settings.Keys) {
|
||||
$old[$key]=[Environment]::GetEnvironmentVariable($key,'Process')
|
||||
if ($null -eq $settings[$key]) { Remove-Item -LiteralPath "Env:$key" -ErrorAction SilentlyContinue }
|
||||
else { [Environment]::SetEnvironmentVariable($key,$settings[$key],'Process') }
|
||||
}
|
||||
foreach ($fixture in @(@{name='pattern'; source='cuda_driver_probe.cpp'; reference='1'},
|
||||
@{name='f16-mma-reference'; source='cuda_mma_probe.cpp'; reference='1'},
|
||||
@{name='f16-mma-wmma'; source='cuda_mma_probe.cpp'; reference='0'})) {
|
||||
$env:D4R_ZLUDA_WMMA_F16_REFERENCE=$fixture.reference
|
||||
# Reuse the public synthetic PTX exercised by the hardware diagnostics.
|
||||
# Reading source does not execute a probe or load HIP/NVIDIA libraries.
|
||||
$match=[regex]::Match((Get-Content (Join-Path $repo ('tools/windows/'+$fixture.source)) -Raw),'(?s)R"PTX\((.*?)\)PTX"')
|
||||
if (!$match.Success) { throw 'Public PTX fixture not found.' }
|
||||
$ptx=Join-Path $OutputDirectory ($fixture.name+'.ptx')
|
||||
$match.Groups[1].Value | Set-Content -LiteralPath $ptx -Encoding ASCII
|
||||
foreach ($arch in $GpuArchitectures) {
|
||||
$output=Join-Path $OutputDirectory ($arch+'/'+$fixture.name)
|
||||
New-Item -ItemType Directory -Force $output | Out-Null
|
||||
$log=Join-Path $output 'compile.log'
|
||||
$oldPreference=$ErrorActionPreference
|
||||
try { $ErrorActionPreference='Continue'; & $emitter $ptx $output $arch *> $log; $code=$LASTEXITCODE }
|
||||
finally { $ErrorActionPreference=$oldPreference }
|
||||
if ($code) { throw "Offline ZLUDA compilation failed: $arch $($fixture.name), exit=$code; see $log" }
|
||||
Assert-D4RCodeObjectTarget (Join-Path $output 'module.hsaco') $arch
|
||||
$text=Get-Content -LiteralPath $log -Raw
|
||||
if ($text -match 'not a recognized processor|ignoring processor|unsupported processor') { throw "Target rejected by compiler: $log" }
|
||||
$asm=Get-Content (Join-Path $output 'asm.s') -Raw
|
||||
if ($asm -notmatch '\.amdhsa_wavefront_size32\s+1') { throw "Missing wave32 code generation: $output" }
|
||||
$hasWmma=($asm -match 'v_wmma_')
|
||||
if (($fixture.name -eq 'f16-mma-wmma' -or ($fixture.name -eq 'f16-mma-reference' -and $arch.StartsWith('gfx11'))) -and !$hasWmma) {
|
||||
throw "WMMA lowering missing: $output"
|
||||
}
|
||||
# gfx12 strict F16 accumulation intentionally uses the existing
|
||||
# double-precision reference helper. Do not label it native WMMA.
|
||||
if ($fixture.name -eq 'f16-mma-reference' -and $arch.StartsWith('gfx12') -and
|
||||
($hasWmma -or $asm -notmatch 'v_fma_f64')) { throw "Strict gfx12 reference lowering changed: $output" }
|
||||
$rows.Add(@{architecture=$arch; fixture=$fixture.name; compiled=$true; elfTargetCorrect=$true;
|
||||
nativeWmma=$hasWmma; hardwareExecuted=$false})
|
||||
Write-Host "PASS ZLUDA_OFFLINE target=$arch fixture=$($fixture.name) wave=32 hardware_executed=0"
|
||||
}
|
||||
}
|
||||
@{passed=$true; fixtures=@($rows); emitterSha256=(Get-FileHash -LiteralPath $emitter).Hash; gpuWorkExecuted=$false} |
|
||||
ConvertTo-Json -Depth 6 | Set-Content (Join-Path $OutputDirectory 'summary.json') -Encoding UTF8
|
||||
} finally {
|
||||
foreach ($key in $old.Keys) {
|
||||
if ($null -eq $old[$key]) { Remove-Item -LiteralPath "Env:$key" -ErrorAction SilentlyContinue }
|
||||
else { [Environment]::SetEnvironmentVariable($key,$old[$key],'Process') }
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user