Prevent OOM
This commit is contained in:
@@ -0,0 +1,115 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Assemble a complete link-time ONNX Runtime C/C++ SDK (include\ + lib\) by
|
||||
downloading the public headers at a given source commit and pairing them with
|
||||
an existing import lib. Output feeds straight into tools\bump_ort_sdk.ps1.
|
||||
|
||||
.DESCRIPTION
|
||||
ORT nightly builds (e.g. 1.24.YYYYMMDD.N.<hash>) ship DLLs + import libs but
|
||||
the matching C/C++ headers are only the public source files in the GitHub repo
|
||||
at the build's commit. ANSCORE compiles against ORT_API_VERSION via these
|
||||
headers, so this script pulls the exact header set for -Commit and copies in a
|
||||
matching onnxruntime.lib, producing a ready-to-install SDK folder.
|
||||
|
||||
Default -Commit 058787c matches SharedCore\ep\cuda (1.24.20260218) AND the
|
||||
onnxruntime.lib already on disk under LabellingTool\vendor (same build).
|
||||
|
||||
.PARAMETER Commit
|
||||
ORT source commit/branch/tag to fetch headers from. Default: 058787c (API 24).
|
||||
|
||||
.PARAMETER OutDir
|
||||
Where to assemble the SDK. Default: %TEMP%\ort_sdk_<commit>.
|
||||
|
||||
.PARAMETER LibSource
|
||||
Folder containing onnxruntime.lib (+ onnxruntime_providers_shared.lib) of the
|
||||
SAME build. Default: the LabellingTool vendor folder found on this machine.
|
||||
|
||||
.EXAMPLE
|
||||
.\fetch_ort_headers.ps1
|
||||
.\bump_ort_sdk.ps1 -SdkPath $env:TEMP\ort_sdk_058787c -Marker runtime1.24.0_openvino2025.3.0.txt -WhatIf
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[string] $Commit = "058787c",
|
||||
[string] $OutDir,
|
||||
[string] $LibSource = "C:\Projects\CLionProjects\LabellingTool\vendor\onnxruntime-win\lib"
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
$ProgressPreference = "SilentlyContinue"
|
||||
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
||||
|
||||
if (-not $OutDir) { $OutDir = Join-Path $env:TEMP "ort_sdk_$Commit" }
|
||||
$incDir = Join-Path $OutDir 'include'
|
||||
$libDir = Join-Path $OutDir 'lib'
|
||||
New-Item -ItemType Directory -Force -Path $incDir, $libDir | Out-Null
|
||||
|
||||
$base = "https://raw.githubusercontent.com/microsoft/onnxruntime/$Commit/include/onnxruntime/core"
|
||||
|
||||
# Header set ANSCORE links against (mirrors ANSLibs, minus unused training headers).
|
||||
# Each entry: subpath under .../core/ -> flattened into include\
|
||||
$headers = @(
|
||||
"session/onnxruntime_c_api.h",
|
||||
"session/onnxruntime_cxx_api.h",
|
||||
"session/onnxruntime_cxx_inline.h",
|
||||
"session/onnxruntime_float16.h",
|
||||
"session/onnxruntime_lite_custom_op.h",
|
||||
"session/onnxruntime_run_options_config_keys.h",
|
||||
"session/onnxruntime_session_options_config_keys.h",
|
||||
"session/onnxruntime_ep_c_api.h",
|
||||
"session/onnxruntime_ep_device_ep_metadata_keys.h",
|
||||
"providers/cpu/cpu_provider_factory.h",
|
||||
"framework/provider_options.h"
|
||||
)
|
||||
|
||||
Write-Host "== Fetching ORT headers @ $Commit -> $incDir =="
|
||||
$ok = 0; $fail = @()
|
||||
foreach ($h in $headers) {
|
||||
$name = Split-Path $h -Leaf
|
||||
$url = "$base/$h"
|
||||
try {
|
||||
Invoke-WebRequest -Uri $url -OutFile (Join-Path $incDir $name) -UseBasicParsing
|
||||
# Guard against a 200-with-HTML (GitHub 404 page) sneaking through
|
||||
$first = Get-Content -LiteralPath (Join-Path $incDir $name) -TotalCount 1 -ErrorAction SilentlyContinue
|
||||
if ($first -match '^\s*<!DOCTYPE|^\s*<html') { throw "got HTML, not a header" }
|
||||
Write-Host (" OK {0}" -f $name) -ForegroundColor Green
|
||||
$ok++
|
||||
} catch {
|
||||
Write-Host (" FAIL {0} ({1})" -f $name, $_.Exception.Message) -ForegroundColor Red
|
||||
$fail += $name
|
||||
}
|
||||
}
|
||||
|
||||
# Verify the new API version actually parsed
|
||||
$apiLine = Select-String -LiteralPath (Join-Path $incDir 'onnxruntime_c_api.h') `
|
||||
-Pattern 'define\s+ORT_API_VERSION\s+(\d+)' -ErrorAction SilentlyContinue | Select-Object -First 1
|
||||
$api = if ($apiLine) { $apiLine.Matches[0].Groups[1].Value } else { '??' }
|
||||
Write-Host (" ORT_API_VERSION in fetched headers: {0}" -f $api)
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "== Copying import libs from: $LibSource =="
|
||||
$libsOk = $true
|
||||
foreach ($l in @('onnxruntime.lib','onnxruntime_providers_shared.lib')) {
|
||||
$src = Join-Path $LibSource $l
|
||||
if (Test-Path -LiteralPath $src) {
|
||||
Copy-Item -LiteralPath $src -Destination (Join-Path $libDir $l) -Force
|
||||
Write-Host (" OK {0}" -f $l) -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host (" MISSING {0} in {1}" -f $l, $LibSource) -ForegroundColor Yellow
|
||||
if ($l -eq 'onnxruntime.lib') { $libsOk = $false }
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
if ($fail.Count -eq 0 -and $libsOk) {
|
||||
Write-Host "== SDK assembled OK ==" -ForegroundColor Green
|
||||
Write-Host (" $OutDir (include\ = {0} headers @ API {1}, lib\ = import libs)" -f $ok, $api)
|
||||
Write-Host " Next:" -ForegroundColor Cyan
|
||||
Write-Host (" .\bump_ort_sdk.ps1 -SdkPath `"$OutDir`" -Marker runtime1.24.0_openvino2025.3.0.txt -WhatIf")
|
||||
exit 0
|
||||
} else {
|
||||
Write-Host "== INCOMPLETE ==" -ForegroundColor Red
|
||||
if ($fail.Count) { Write-Host (" headers failed: {0}" -f ($fail -join ', ')) -ForegroundColor Red }
|
||||
if (-not $libsOk) { Write-Host " onnxruntime.lib not found - set -LibSource to a folder that has it." -ForegroundColor Red }
|
||||
exit 1
|
||||
}
|
||||
Reference in New Issue
Block a user