159 lines
6.3 KiB
PowerShell
159 lines
6.3 KiB
PowerShell
<#
|
||
.SYNOPSIS
|
||
VDE Phase4-GPU:CUDA / HIP 后端构建与一致性验证脚本。
|
||
|
||
.DESCRIPTION
|
||
检测宿主 nvcc / hipcc:
|
||
- 两者都缺失:输出诚实的"环境缺失、GPU 后端未验证"结论(默认 CPU 构建不受影响),exit 0;
|
||
- 存在 nvcc:configure -DVDE_USE_CUDA=ON → build → 运行 test_lbvh / test_gpu_consistency;
|
||
- 存在 hipcc:configure -DVDE_USE_HIP=ON → build → 运行同套件;
|
||
任一步失败 exit 1。设备不可用时测试会 GTEST_SKIP(构建验证仍算通过)。
|
||
|
||
CUDA/HIP 后端代码(cuda_compute.cu / hip_compute.hip)镜像实现;默认构建
|
||
(两个选项 OFF)不编译任何 GPU 源码、不引入 nvcc/hipcc 依赖。
|
||
#>
|
||
[CmdletBinding()]
|
||
param(
|
||
[string]$RepoRoot = '',
|
||
[switch]$Clean
|
||
)
|
||
|
||
# NOTE: Windows PowerShell 5.1 leaves $PSScriptRoot empty inside *parameter default
|
||
# expressions* when the script is launched with -File, so resolve RepoRoot here.
|
||
if (-not $RepoRoot) {
|
||
$here = if ($PSScriptRoot) { $PSScriptRoot } else {
|
||
Split-Path -Parent $MyInvocation.MyCommand.Path
|
||
}
|
||
$RepoRoot = (Resolve-Path (Join-Path $here '..\..')).Path
|
||
}
|
||
|
||
$ErrorActionPreference = 'Stop'
|
||
$script:failed = $false
|
||
|
||
function Write-Section([string]$text) {
|
||
Write-Host ''
|
||
Write-Host ('=' * 72)
|
||
Write-Host $text
|
||
Write-Host ('=' * 72)
|
||
}
|
||
|
||
function Get-ToolPath([string]$name) {
|
||
$cmd = Get-Command $name -ErrorAction SilentlyContinue
|
||
if ($null -eq $cmd) { return $null }
|
||
return $cmd.Source
|
||
}
|
||
|
||
function Invoke-GpuBackend {
|
||
param(
|
||
[string]$Name,
|
||
[string]$Option,
|
||
[string]$BuildDir,
|
||
[string]$CompilerVar,
|
||
[string]$CompilerPath
|
||
)
|
||
Write-Section "$Name backend verification (build dir: $BuildDir)"
|
||
$cmakeArgs = @(
|
||
'-S', $RepoRoot, '-B', $BuildDir, '-G', 'Ninja',
|
||
'-DCMAKE_BUILD_TYPE=Release',
|
||
'-DBUILD_TESTS=ON', '-DBUILD_EXAMPLES=OFF', '-DBUILD_BENCHMARKS=OFF',
|
||
"-D$Option=ON",
|
||
'-DFETCHCONTENT_FULLY_DISCONNECTED=ON',
|
||
"-DFETCHCONTENT_SOURCE_DIR_EIGEN3=$(Join-Path $RepoRoot 'eigen3')",
|
||
"-DFETCHCONTENT_SOURCE_DIR_GOOGLETEST=$(Join-Path $RepoRoot 'googletest')"
|
||
)
|
||
if ($Clean -and (Test-Path $BuildDir)) { Remove-Item -Recurse -Force $BuildDir }
|
||
if ($CompilerPath) { $cmakeArgs += "-D$CompilerVar=$CompilerPath" }
|
||
& cmake @cmakeArgs 2>&1 | ForEach-Object { Write-Host $_ }
|
||
if ($LASTEXITCODE -ne 0) {
|
||
Write-Host "[FAIL] $Name configure failed (exit $LASTEXITCODE)"
|
||
$script:failed = $true
|
||
return
|
||
}
|
||
& cmake --build $BuildDir --target test_lbvh test_gpu_consistency test_compute_backend -j 4 2>&1 |
|
||
ForEach-Object { Write-Host $_ }
|
||
if ($LASTEXITCODE -ne 0) {
|
||
Write-Host "[FAIL] $Name build failed (exit $LASTEXITCODE)"
|
||
$script:failed = $true
|
||
return
|
||
}
|
||
$tests = @(
|
||
(Join-Path $BuildDir 'tests\compute\test_lbvh.exe'),
|
||
(Join-Path $BuildDir 'tests\compute\test_gpu_consistency.exe'),
|
||
(Join-Path $BuildDir 'tests\compute\test_compute_backend.exe')
|
||
)
|
||
foreach ($exe in $tests) {
|
||
if (-not (Test-Path $exe)) {
|
||
Write-Host "[FAIL] $Name missing test executable: $exe"
|
||
$script:failed = $true
|
||
continue
|
||
}
|
||
Write-Host "-- running $exe"
|
||
& $exe 2>&1 | ForEach-Object { Write-Host $_ }
|
||
if ($LASTEXITCODE -ne 0) {
|
||
Write-Host "[FAIL] $Name test failed: $exe (exit $LASTEXITCODE)"
|
||
$script:failed = $true
|
||
}
|
||
}
|
||
}
|
||
|
||
Write-Section 'VDE Phase4-GPU build verification (CUDA / HIP)'
|
||
Write-Host "RepoRoot : $RepoRoot"
|
||
$nvcc = Get-ToolPath 'nvcc'
|
||
$hipcc = Get-ToolPath 'hipcc'
|
||
if ($nvcc) { Write-Host "nvcc : $nvcc" } else { Write-Host 'nvcc : <not found>' }
|
||
if ($hipcc) { Write-Host "hipcc : $hipcc" } else { Write-Host 'hipcc : <not found>' }
|
||
|
||
$cpuOnly = (-not $nvcc) -and (-not $hipcc)
|
||
if ($cpuOnly) {
|
||
Write-Section 'Environment missing (no nvcc/hipcc) — trying NVRTC runtime-GPU fallback'
|
||
Write-Host 'CPU backend : available (default build: VDE_USE_CUDA=OFF, VDE_USE_HIP=OFF)'
|
||
Write-Host 'CUDA backend: NOT compiled (no nvcc / CUDA Toolkit on this host)'
|
||
Write-Host 'HIP backend: NOT compiled (no hipcc / ROCm on this host)'
|
||
Write-Host ''
|
||
Write-Host 'Fallback: GPU compute can be verified without the CUDA Toolkit by compiling'
|
||
Write-Host 'CUDA kernels at runtime with NVRTC (user-level pip wheels) + the installed'
|
||
Write-Host 'NVIDIA driver. Running tools/gpu/gpu_nvrtc_probe.py ...'
|
||
|
||
$python = Get-Command python -ErrorAction SilentlyContinue
|
||
$probe = Join-Path $RepoRoot 'tools\gpu\gpu_nvrtc_probe.py'
|
||
$report = Join-Path $RepoRoot 'build\gpu_nvrtc_report.json'
|
||
if (-not $python -or -not (Test-Path $probe)) {
|
||
Write-Host ''
|
||
Write-Host 'CHECK RESULT: PARSE OK / CPU-ONLY (GPU 未验证:无 nvcc/hipcc,且无 python/NVRTC 探针)'
|
||
exit 0
|
||
}
|
||
New-Item -ItemType Directory -Force -Path (Split-Path $report) | Out-Null
|
||
& $python.Source $probe --json $report 2>&1 | ForEach-Object { Write-Host $_ }
|
||
$probeExit = $LASTEXITCODE
|
||
Write-Host ''
|
||
if ($probeExit -eq 0) {
|
||
Write-Host 'DEVICE RESULT: GPU compute verified via NVRTC (see report below);'
|
||
Write-Host 'production CUDA build (nvcc -> .cu -> CMake target) still NOT compiled on this host.'
|
||
Write-Host "Report: $report"
|
||
Write-Host ''
|
||
Write-Host 'CHECK RESULT: PARSE OK / GPU COMPUTE VERIFIED via NVRTC (production nvcc build unverified)'
|
||
} elseif ($probeExit -eq 2) {
|
||
Write-Host 'CHECK RESULT: PARSE OK / CPU-ONLY (no GPU driver or NVRTC; see probe report)'
|
||
} else {
|
||
Write-Host 'CHECK RESULT: FAILED (NVRTC GPU probe failed; see output above)'
|
||
$script:failed = $true
|
||
}
|
||
if ($script:failed) { exit 1 }
|
||
exit 0
|
||
}
|
||
|
||
if ($nvcc) {
|
||
Invoke-GpuBackend -Name 'CUDA' -Option 'VDE_USE_CUDA' -BuildDir (Join-Path $RepoRoot 'build-gpu-cuda') -CompilerVar 'CMAKE_CUDA_COMPILER' -CompilerPath $nvcc
|
||
}
|
||
if ($hipcc) {
|
||
Invoke-GpuBackend -Name 'HIP' -Option 'VDE_USE_HIP' -BuildDir (Join-Path $RepoRoot 'build-gpu-hip') -CompilerVar 'CMAKE_HIP_COMPILER' -CompilerPath $hipcc
|
||
}
|
||
|
||
Write-Section 'Summary'
|
||
if ($script:failed) {
|
||
Write-Host 'CHECK RESULT: FAILED (见上方 [FAIL] 行)'
|
||
exit 1
|
||
}
|
||
Write-Host 'CHECK RESULT: OK(本机可用 GPU 后端均已 configure/build/test;无设备时设备用例诚实 SKIP)'
|
||
exit 0
|