291 lines
13 KiB
PowerShell
291 lines
13 KiB
PowerShell
<#
|
|
.SYNOPSIS
|
|
Reports versions and ABI compatibility of the inference runtime stack
|
|
(CUDA, cuDNN, TensorRT, OpenVINO, DirectML, ONNX Runtime per-EP) inside an
|
|
ANSCENTER "Shared" folder, and optionally diffs two such folders.
|
|
|
|
.DESCRIPTION
|
|
Rerun this after upgrading any DLL in SharedCore to confirm the pieces still
|
|
line up. It does three things:
|
|
1. Reads the version of every key library.
|
|
- ORT: FileVersion of ep\<x>\onnxruntime.dll
|
|
- OpenVINO / DirectML / cuDNN: FileVersion resource
|
|
- CUDA components: inferred from the versioned file name (cudart64_13 => CUDA 13)
|
|
- TensorRT: nvinfer_*.dll has NO version resource, so we p/invoke its
|
|
exported getInferLibVersion() (packed int, e.g. 101501 => 10.15.1).
|
|
2. Uses dumpbin /DEPENDENTS (if Visual Studio is installed) to list which
|
|
CUDA / cuDNN / TensorRT / OpenVINO / DirectML DLLs each EP actually
|
|
imports, and verifies every one exists in the root.
|
|
3. Flags gaps: empty ep\cpu with no flat fallback, missing dependencies,
|
|
ORT-version split across EP folders.
|
|
|
|
NOTE: the TensorRT probe uses a plain [DllImport] to nvinfer's exported
|
|
getInferLibVersion(). It deliberately avoids LoadLibrary+GetProcAddress+
|
|
GetDelegateForFunctionPointer, because that dynamic-resolution pattern trips
|
|
Windows Defender AMSI ("malicious content") and blocks the whole script.
|
|
|
|
.PARAMETER Root
|
|
The Shared folder to inspect. Default: C:\Projects\SharedCore
|
|
|
|
.PARAMETER CompareWith
|
|
Optional second Shared folder to diff against Root (e.g. the deployed
|
|
C:\ProgramData\ANSCENTER\Shared). Reports any version mismatches.
|
|
|
|
.PARAMETER SkipTensorRT
|
|
Skip the TensorRT p/invoke probe (useful if your AV still objects, or to run
|
|
purely on file-version metadata).
|
|
|
|
.EXAMPLE
|
|
.\Check-SharedCoreVersions.ps1
|
|
|
|
.EXAMPLE
|
|
.\Check-SharedCoreVersions.ps1 -Root C:\Projects\SharedCore `
|
|
-CompareWith C:\ProgramData\ANSCENTER\Shared
|
|
#>
|
|
[CmdletBinding()]
|
|
param(
|
|
[string] $Root = "C:\Projects\SharedCore",
|
|
[string] $CompareWith,
|
|
[switch] $SkipTensorRT
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
# ----------------------------------------------------------------------------
|
|
# Helpers
|
|
# ----------------------------------------------------------------------------
|
|
function Get-FileVer([string]$path) {
|
|
if (Test-Path -LiteralPath $path) { (Get-Item -LiteralPath $path).VersionInfo.FileVersion }
|
|
else { $null }
|
|
}
|
|
|
|
# Windows PowerShell 5.1 has no ?? operator - use this instead.
|
|
function Coalesce($value, $fallback) {
|
|
if ($value) { $value } else { $fallback }
|
|
}
|
|
|
|
function Find-Dumpbin {
|
|
$candidates = Get-ChildItem `
|
|
"C:\Program Files\Microsoft Visual Studio\*\*\VC\Tools\MSVC\*\bin\Hostx64\x64\dumpbin.exe", `
|
|
"C:\Program Files (x86)\Microsoft Visual Studio\*\*\VC\Tools\MSVC\*\bin\Hostx64\x64\dumpbin.exe" `
|
|
-ErrorAction SilentlyContinue | Sort-Object FullName -Descending
|
|
if ($candidates) { return $candidates[0].FullName }
|
|
return $null
|
|
}
|
|
|
|
# Declares plain DllImports to nvinfer's getInferLibVersion. Compiled once per
|
|
# session. The DLLs are resolved via PATH, so callers must put the root dir on
|
|
# PATH before invoking (Get-TensorRTVersion does this).
|
|
function Initialize-TrtProbe {
|
|
if ('AnsTrtProbe.Lib' -as [type]) { return }
|
|
Add-Type -Namespace AnsTrtProbe -Name Lib -MemberDefinition @'
|
|
[System.Runtime.InteropServices.DllImport("nvinfer_dispatch_10.dll", EntryPoint = "getInferLibVersion", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl)]
|
|
public static extern int Dispatch10();
|
|
[System.Runtime.InteropServices.DllImport("nvinfer_lean_10.dll", EntryPoint = "getInferLibVersion", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl)]
|
|
public static extern int Lean10();
|
|
[System.Runtime.InteropServices.DllImport("nvinfer_10.dll", EntryPoint = "getInferLibVersion", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl)]
|
|
public static extern int Full10();
|
|
'@
|
|
}
|
|
|
|
# Returns the packed TensorRT version int (e.g. 101501) or $null.
|
|
function Get-TensorRTVersion([string]$dir) {
|
|
if ($SkipTensorRT) { return $null }
|
|
if (-not (Get-ChildItem -LiteralPath $dir -Filter 'nvinfer*_10.dll' -ErrorAction SilentlyContinue)) {
|
|
return $null
|
|
}
|
|
$origPath = $env:Path
|
|
$env:Path = "$dir;$env:Path" # so the stub and its deps resolve
|
|
try {
|
|
Initialize-TrtProbe
|
|
foreach ($m in 'Dispatch10','Lean10','Full10') {
|
|
try {
|
|
$v = [AnsTrtProbe.Lib]::$m()
|
|
if ($v -gt 0) { return $v }
|
|
} catch { }
|
|
}
|
|
return $null
|
|
} finally {
|
|
$env:Path = $origPath
|
|
}
|
|
}
|
|
|
|
function Format-TensorRT($raw) {
|
|
if (-not $raw) { return "UNKNOWN (probe skipped or failed)" }
|
|
$maj = [math]::Floor($raw / 10000)
|
|
$min = [math]::Floor(($raw % 10000) / 100)
|
|
$pat = $raw % 100
|
|
return "$maj.$min.$pat (raw $raw)"
|
|
}
|
|
|
|
# Returns the lower-cased set of dependency DLLs (CUDA/TRT/OV/DML family) that
|
|
# $path imports, via dumpbin /DEPENDENTS. Empty array if dumpbin unavailable.
|
|
function Get-Deps([string]$dumpbin, [string]$path) {
|
|
if (-not $dumpbin -or -not (Test-Path -LiteralPath $path)) { return @() }
|
|
$rx = '(?i)cudart|cublas|cudnn|cufft|cusparse|cusolver|nvinfer|nvonnx|nvrtc|directml|openvino'
|
|
& $dumpbin /DEPENDENTS $path 2>$null |
|
|
Select-String -Pattern '^\s+\S+\.dll\s*$' |
|
|
ForEach-Object { $_.Line.Trim().ToLower() } |
|
|
Where-Object { $_ -match $rx } |
|
|
Sort-Object -Unique
|
|
}
|
|
|
|
$epMap = [ordered]@{
|
|
"cpu" = "CPU"
|
|
"cuda" = "NVIDIA_GPU (CUDA + TensorRT)"
|
|
"directml" = "AMD_GPU (DirectML)"
|
|
"openvino" = "OPENVINO_GPU (Intel)"
|
|
}
|
|
|
|
# ----------------------------------------------------------------------------
|
|
# Inspect one root
|
|
# ----------------------------------------------------------------------------
|
|
function Inspect-Root([string]$root) {
|
|
if (-not (Test-Path -LiteralPath $root)) {
|
|
Write-Host "ERROR: root not found: $root" -ForegroundColor Red
|
|
return $null
|
|
}
|
|
$dumpbin = Find-Dumpbin
|
|
|
|
Write-Host ""
|
|
Write-Host "=================================================================="
|
|
Write-Host " Shared root : $root"
|
|
Write-Host " dumpbin : $(if($dumpbin){$dumpbin}else{'NOT FOUND - dependency checks skipped'})"
|
|
Write-Host "=================================================================="
|
|
|
|
$result = [ordered]@{ Root = $root; Ort = [ordered]@{} }
|
|
|
|
# ---- Core libraries -----------------------------------------------------
|
|
$trtRaw = Get-TensorRTVersion $root
|
|
$result.TensorRT = $trtRaw
|
|
Write-Host ""
|
|
Write-Host "-- Core runtime libraries -----------------------------------------"
|
|
Write-Host ("{0,-14} {1}" -f "TensorRT:", (Format-TensorRT $trtRaw))
|
|
Write-Host ("{0,-14} {1}" -f "OpenVINO:", (Coalesce (Get-FileVer (Join-Path $root 'openvino.dll')) 'MISSING'))
|
|
Write-Host ("{0,-14} {1}" -f "DirectML:", (Coalesce (Get-FileVer (Join-Path $root 'DirectML.dll')) 'MISSING'))
|
|
Write-Host ("{0,-14} {1}" -f "cuDNN:", (Coalesce (Get-FileVer (Join-Path $root 'cudnn64_9.dll')) 'MISSING'))
|
|
# CUDA toolkit generation is encoded in the file name suffix.
|
|
$cudaFiles = Get-ChildItem -LiteralPath $root -Filter "cudart64_*.dll" -ErrorAction SilentlyContinue
|
|
if ($cudaFiles) {
|
|
$gen = ($cudaFiles[0].BaseName -replace 'cudart64_','')
|
|
Write-Host ("{0,-14} {1}" -f "CUDA:", "toolkit $gen.x (cudart64_$gen.dll present)")
|
|
} else {
|
|
Write-Host ("{0,-14} {1}" -f "CUDA:", "MISSING (no cudart64_*.dll)")
|
|
}
|
|
|
|
# ---- ORT per EP ---------------------------------------------------------
|
|
Write-Host ""
|
|
Write-Host "-- ONNX Runtime per EP --------------------------------------------"
|
|
foreach ($ep in $epMap.Keys) {
|
|
$epDir = Join-Path $root "ep\$ep"
|
|
$ortDll = Join-Path $epDir "onnxruntime.dll"
|
|
$ver = Get-FileVer $ortDll
|
|
$result.Ort[$ep] = $ver
|
|
if ($ver) {
|
|
Write-Host ("{0,-10} {1,-26} [{2}]" -f $ep, $ver, $epMap[$ep])
|
|
} elseif (Test-Path -LiteralPath $epDir) {
|
|
Write-Host ("{0,-10} {1,-26} [{2}]" -f $ep, "EMPTY / no onnxruntime.dll", $epMap[$ep])
|
|
} else {
|
|
Write-Host ("{0,-10} {1,-26} [{2}]" -f $ep, "FOLDER MISSING", $epMap[$ep])
|
|
}
|
|
}
|
|
|
|
# ---- Dependency / presence check ---------------------------------------
|
|
Write-Host ""
|
|
Write-Host "-- EP dependency resolution (imports must exist in root) ----------"
|
|
$missingDeps = @()
|
|
$epProviders = @{
|
|
"cuda" = @("onnxruntime_providers_cuda.dll","onnxruntime_providers_tensorrt.dll")
|
|
"directml" = @() # DML is built into onnxruntime.dll; needs DirectML.dll from root
|
|
"openvino" = @("onnxruntime_providers_openvino.dll")
|
|
"cpu" = @()
|
|
}
|
|
foreach ($ep in $epProviders.Keys) {
|
|
$epDir = Join-Path $root "ep\$ep"
|
|
if (-not (Test-Path -LiteralPath (Join-Path $epDir 'onnxruntime.dll'))) { continue }
|
|
$checkFiles = @("onnxruntime.dll") + $epProviders[$ep]
|
|
$deps = @()
|
|
foreach ($cf in $checkFiles) { $deps += Get-Deps $dumpbin (Join-Path $epDir $cf) }
|
|
$deps = $deps | Sort-Object -Unique
|
|
if (-not $deps) { continue }
|
|
Write-Host (" [{0}] imports: {1}" -f $ep, ($deps -join ', '))
|
|
foreach ($d in $deps) {
|
|
# provider DLLs live in the ep folder; everything else in root
|
|
$inEp = Test-Path -LiteralPath (Join-Path $epDir $d)
|
|
$inRoot = Test-Path -LiteralPath (Join-Path $root $d)
|
|
if (-not $inEp -and -not $inRoot) {
|
|
Write-Host (" MISSING: $d") -ForegroundColor Red
|
|
$missingDeps += "$ep -> $d"
|
|
}
|
|
}
|
|
}
|
|
if (-not $missingDeps) { Write-Host " All imported CUDA/TRT/OV/DML DLLs are present." -ForegroundColor Green }
|
|
$result.MissingDeps = $missingDeps
|
|
|
|
# ---- Gap checks ---------------------------------------------------------
|
|
Write-Host ""
|
|
Write-Host "-- Findings -------------------------------------------------------"
|
|
$findings = @()
|
|
|
|
# CPU reachability: EngineType::CPU needs ep\cpu\onnxruntime.dll OR a flat root onnxruntime.dll
|
|
$cpuDll = Test-Path -LiteralPath (Join-Path $root 'ep\cpu\onnxruntime.dll')
|
|
$flatDll = Test-Path -LiteralPath (Join-Path $root 'onnxruntime.dll')
|
|
if (-not $cpuDll -and -not $flatDll) {
|
|
$findings += "CPU branch UNREACHABLE: ep\cpu is empty and no flat onnxruntime.dll fallback. A CPU-only machine will fail to load ORT."
|
|
}
|
|
|
|
# ORT version split across EP folders
|
|
$distinct = $result.Ort.Values | Where-Object { $_ } | Sort-Object -Unique
|
|
if ($distinct.Count -gt 1) {
|
|
$findings += "ORT versions differ across EP folders ($($distinct -join ' / ')). Fine ONLY because EPLoader loads one EP per process - never mix DLLs across folders."
|
|
}
|
|
|
|
if ($missingDeps) { $findings += "Unresolved dependencies: $($missingDeps -join '; ')" }
|
|
|
|
if (-not $findings) {
|
|
Write-Host " No issues detected." -ForegroundColor Green
|
|
} else {
|
|
foreach ($f in $findings) { Write-Host " ! $f" -ForegroundColor Yellow }
|
|
}
|
|
|
|
return $result
|
|
}
|
|
|
|
# ----------------------------------------------------------------------------
|
|
# Main
|
|
# ----------------------------------------------------------------------------
|
|
$primary = Inspect-Root $Root
|
|
|
|
if ($CompareWith) {
|
|
$secondary = Inspect-Root $CompareWith
|
|
if ($primary -and $secondary) {
|
|
Write-Host ""
|
|
Write-Host "=================================================================="
|
|
Write-Host " DIFF: $Root vs $CompareWith"
|
|
Write-Host "=================================================================="
|
|
$mismatch = $false
|
|
|
|
if ($primary.TensorRT -ne $secondary.TensorRT) {
|
|
Write-Host (" TensorRT: {0} vs {1}" -f (Format-TensorRT $primary.TensorRT), (Format-TensorRT $secondary.TensorRT)) -ForegroundColor Yellow
|
|
$mismatch = $true
|
|
}
|
|
foreach ($ep in $epMap.Keys) {
|
|
$a = $primary.Ort[$ep]; $b = $secondary.Ort[$ep]
|
|
if ($a -ne $b) {
|
|
Write-Host (" ORT ep\{0}: {1} vs {2}" -f $ep, (Coalesce $a 'MISSING'), (Coalesce $b 'MISSING')) -ForegroundColor Yellow
|
|
$mismatch = $true
|
|
}
|
|
}
|
|
foreach ($lib in @('openvino.dll','DirectML.dll','cudnn64_9.dll')) {
|
|
$a = Get-FileVer (Join-Path $Root $lib); $b = Get-FileVer (Join-Path $CompareWith $lib)
|
|
if ($a -ne $b) {
|
|
Write-Host (" {0}: {1} vs {2}" -f $lib, (Coalesce $a 'MISSING'), (Coalesce $b 'MISSING')) -ForegroundColor Yellow
|
|
$mismatch = $true
|
|
}
|
|
}
|
|
if (-not $mismatch) { Write-Host " Identical across both roots." -ForegroundColor Green }
|
|
}
|
|
}
|
|
|
|
Write-Host ""
|