[CmdletBinding()] param([ValidateSet('enc0','enc1','enc2','enc3','enc4','dec5','dec4','dec3','dec2','dec1','dec0')] [string]$Layer='enc1', [ValidateSet('source','cu','wgp')][string]$Mode='source', [ValidateSet('baseline','load','store','both')][string]$NonTemporal='baseline', [ValidateSet(0,1,2,4)][int]$PosTiles=0, [switch]$ShareValues, [switch]$PrivateValues, [switch]$PackedAccumulator, [switch]$F16Wmma, [ValidateSet('lds','ds','native')][string]$LaneExchange='lds', [ValidateSet('gfx1100','gfx1101','gfx1102','gfx1103','gfx1150','gfx1151','gfx1152','gfx1153','gfx1154','gfx1200','gfx1201')] [string]$GpuArch='gfx1201', [string]$HipRoot, [string]$OutputDirectory) $ErrorActionPreference='Stop' $repo=[IO.Path]::GetFullPath((Join-Path $PSScriptRoot '../..')) if (!$HipRoot) { $HipRoot=Join-Path $repo '.tools/therock-10.2.0a20260929/_rocm_sdk_core' } if ($ShareValues -and $PrivateValues) { throw 'Choose shared or private V storage.' } if ($GpuArch -notmatch '^gfx12' -and ($PackedAccumulator -or $F16Wmma)) { throw 'Packed accumulator and F16 WMMA experiments require gfx12.' } if ($PackedAccumulator -and $F16Wmma) { throw 'Packed accumulator storage requires F32 WMMA.' } if (!$OutputDirectory) { $OutputDirectory=Join-Path $repo "build/native-k-experiment-$GpuArch-$Layer-$Mode-$NonTemporal-pos$PosTiles-share$([int][bool]$ShareValues)-private$([int][bool]$PrivateValues)-packed$([int][bool]$PackedAccumulator)" } if ($F16Wmma -and !$PSBoundParameters.ContainsKey('OutputDirectory')) { $OutputDirectory+='-f16-wmma' } $OutputDirectory=[IO.Path]::GetFullPath($OutputDirectory) foreach ($baseline in @('build/native-k-gfx1201','build/windows-rdna4-therock','dist/windows-rdna4-command-list')) { if ($OutputDirectory.StartsWith([IO.Path]::GetFullPath((Join-Path $repo $baseline)), [StringComparison]::OrdinalIgnoreCase)) { throw 'Keep experimental objects outside the validated baseline/package.' } } $compiler=Join-Path $HipRoot 'lib/llvm/bin/clang++.exe' if (!(Test-Path -LiteralPath $compiler)) { $compiler=Join-Path $HipRoot 'bin/clang++.exe' } $name="dltss_pwin_${Layer}_layer" $source=Join-Path $repo "kernels/k/$name.hip" $flags=@() if ((Get-Content -LiteralPath $source -Raw) -match '// d4r-build-flags: ([^\r\n]+)') { $flags=$Matches[1].Trim().Split(' ') } if ($Mode -ne 'source') { $flags=@($flags | Where-Object { $_ -ne '-mcumode' -and $_ -ne '-mno-cumode' }) $flags+=if ($Mode -eq 'cu') { '-mcumode' } else { '-mno-cumode' } } if ($NonTemporal -in @('load','both')) { $flags+='-DPWIN_NT_LOAD' } if ($NonTemporal -in @('store','both')) { $flags+='-DPWIN_NT_STORE' } if ($PosTiles) { if ($Layer -notin @('enc0','enc1','dec0')) { throw 'Token tiling is audited for position-only layers only.' } $flags+=if ($Layer -eq 'enc1') { "-DD4R_K_ENC1_POS_MT=$PosTiles" } else { "-DD4R_K_POS_MT=$PosTiles" } } if ($ShareValues) { if ($Layer -notin @('enc0','dec0') -and !($Layer -eq 'enc1' -and $PosTiles)) { throw 'ShareValues requires a position-only template.' } $flags+='-DPOS_VSHARE' } if ($PackedAccumulator) { $flags+='-DD4R_K_PACKED_ACC' } if ($F16Wmma) { $flags+='-DD4R_K_F16_WMMA' } if ($PrivateValues) { $flags+='-DD4R_K_PRIVATE_V' } if ($GpuArch -match '^gfx11' -and $LaneExchange -ne 'native') { $flags+='-DD4R_WINDOWS_GFX11_LANE_EXCHANGE' } if ($LaneExchange -eq 'ds') { if ($GpuArch -notmatch '^gfx11') { throw 'DS lane exchange experiment requires gfx11.' } $flags+='-DD4R_WINDOWS_GFX11_DS_EXCHANGE' } New-Item -ItemType Directory -Force $OutputDirectory | Out-Null $object=Join-Path $OutputDirectory "$name.hsaco" $arguments=@('-x','hip','-std=c++17',"--offload-arch=$GpuArch",'--offload-device-only', '--no-gpu-bundle-output','-mno-wavefrontsize64','-nogpuinc','-nogpulib','-O3', '-DD4R_DEVICE_ONLY_MINIMAL','-DD4R_K_FP16_BASELINE')+$flags+@($source,'-o',$object) $ErrorActionPreference='Continue' & $compiler @arguments > (Join-Path $OutputDirectory "$name.build.stdout.log") 2> (Join-Path $OutputDirectory "$name.build.stderr.log") $ErrorActionPreference='Stop' if ($LASTEXITCODE) { throw "Experimental K compile failed: $Layer" } & (Join-Path (Split-Path $compiler) 'llvm-objdump.exe') --disassemble "--mcpu=$GpuArch" $object ` > (Join-Path $OutputDirectory "$name.isa.txt") if ($LASTEXITCODE) { throw 'Native object ISA extraction failed.' } & (Join-Path (Split-Path $compiler) 'llvm-readobj.exe') --notes $object ` > (Join-Path $OutputDirectory "$name.metadata.txt") if ($LASTEXITCODE) { throw 'Native object metadata extraction failed.' } @{layer=$Layer; architecture=$GpuArch; experimental=$true; numericalValidation='pending'; mode=$Mode; nonTemporal=$NonTemporal; tokenTilesPerWave=$PosTiles; shareValues=[bool]$ShareValues; privateValues=[bool]$PrivateValues; packedAccumulator=[bool]$PackedAccumulator; laneExchange=$LaneExchange; f16Wmma=[bool]$F16Wmma; compiler=$compiler; arguments=$arguments; sourceCommit=(git -C $repo rev-parse HEAD); workingTreeDirty=[bool](& git -C $repo status --porcelain); compilerVersion=(& $compiler --version | Out-String).Trim(); sha256=(Get-FileHash -LiteralPath $object -Algorithm SHA256).Hash} | ConvertTo-Json -Depth 4 | Set-Content -LiteralPath (Join-Path $OutputDirectory "$name.build-info.json") -Encoding UTF8 Write-Host "Compiled $GpuArch K experiment: $Layer mode=$Mode nonTemporal=$NonTemporal posTiles=$PosTiles shareValues=$([bool]$ShareValues). Validate before installing." # No override manifest or game installation is produced by this script.