|
| 1 | +name: Prepare ONNX Runtime |
| 2 | +description: > |
| 3 | + Fetch or build an ONNX Runtime install tree carrying the requested execution provider, |
| 4 | + plus KataGo's own zlib/protobuf deps. Everything lands under deps/install/ and is |
| 5 | + cached, so only the first run pays for ORT acquisition (from-source ORT builds are the |
| 6 | + expensive case, 1-3h; prebuilt/nuget are minutes). |
| 7 | +inputs: |
| 8 | + ep: |
| 9 | + description: Execution provider to wire up (cpu, directml, openvino, ...) |
| 10 | + required: true |
| 11 | + mode: |
| 12 | + description: > |
| 13 | + How to obtain ORT. 'prebuilt' = official release zip (CPU EP ships inside it), |
| 14 | + 'nuget' = Microsoft.ML.OnnxRuntime.DirectML package, 'from-source' = build ORT |
| 15 | + ourselves with the EP. |
| 16 | + required: true |
| 17 | + ort_version: |
| 18 | + description: ORT release version for prebuilt/nuget modes |
| 19 | + required: false |
| 20 | + default: "1.28.0" |
| 21 | + ort_ref: |
| 22 | + description: ORT git ref (tag/SHA) for from-source mode |
| 23 | + required: false |
| 24 | + default: "" |
| 25 | + ov_version: |
| 26 | + description: OpenVINO toolkit version (from-source/openvino only) |
| 27 | + required: false |
| 28 | + default: "" |
| 29 | + ov_url: |
| 30 | + description: OpenVINO toolkit download URL (from-source/openvino only) |
| 31 | + required: false |
| 32 | + default: "" |
| 33 | + pb_version: |
| 34 | + description: protobuf version built for KataGo (3.x, no abseil dependency) |
| 35 | + required: false |
| 36 | + default: "3.21.12" |
| 37 | + pb_tag: |
| 38 | + description: > |
| 39 | + protobuf release tag for pb_version. protobuf 3.x tags drop the major (3.21.12 |
| 40 | + -> v21.12), so this cannot be derived from pb_version. |
| 41 | + required: false |
| 42 | + default: "21.12" |
| 43 | + zlib_version: |
| 44 | + description: zlib version built for KataGo |
| 45 | + required: false |
| 46 | + default: "1.3.1" |
| 47 | + |
| 48 | +outputs: |
| 49 | + ort_root: |
| 50 | + description: Path to the prepared ORT install tree |
| 51 | + value: ${{ github.workspace }}/deps/install/ort |
| 52 | + |
| 53 | +runs: |
| 54 | + using: composite |
| 55 | + steps: |
| 56 | + # --------------------------------------------------------------------------- |
| 57 | + # Common deps: zlib + protobuf, always built from source and cached separately |
| 58 | + # from the ORT tree so a from-source ORT cache miss does not rebuild them. |
| 59 | + # --------------------------------------------------------------------------- |
| 60 | + - name: Restore common-dep cache |
| 61 | + id: cache-common |
| 62 | + uses: actions/cache@v4 |
| 63 | + with: |
| 64 | + path: | |
| 65 | + deps/install/zlib |
| 66 | + deps/install/protobuf |
| 67 | + key: onnx-common-${{ runner.os }}-pb-${{ inputs.pb_version }}-zl-${{ inputs.zlib_version }} |
| 68 | + |
| 69 | + - name: Build zlib (static, Windows) |
| 70 | + if: steps.cache-common.outputs.cache-hit != 'true' && runner.os == 'Windows' |
| 71 | + shell: pwsh |
| 72 | + run: | |
| 73 | + curl.exe -L -o "$env:RUNNER_TEMP\zlib.tar.gz" "https://github.com/madler/zlib/releases/download/v${{ inputs.zlib_version }}/zlib-${{ inputs.zlib_version }}.tar.gz" |
| 74 | + tar -xzf "$env:RUNNER_TEMP\zlib.tar.gz" -C "$env:RUNNER_TEMP" |
| 75 | + cmake -S "$env:RUNNER_TEMP\zlib-${{ inputs.zlib_version }}" -B "$env:RUNNER_TEMP\zlib-build" -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${{ github.workspace }}\deps\install\zlib |
| 76 | + cmake --build "$env:RUNNER_TEMP\zlib-build" |
| 77 | + cmake --install "$env:RUNNER_TEMP\zlib-build" |
| 78 | +
|
| 79 | + - name: Build zlib (static, Linux) |
| 80 | + if: steps.cache-common.outputs.cache-hit != 'true' && runner.os == 'Linux' |
| 81 | + shell: bash |
| 82 | + run: | |
| 83 | + curl -L -o "$RUNNER_TEMP/zlib.tar.gz" "https://github.com/madler/zlib/releases/download/v${{ inputs.zlib_version }}/zlib-${{ inputs.zlib_version }}.tar.gz" |
| 84 | + tar -xzf "$RUNNER_TEMP/zlib.tar.gz" -C "$RUNNER_TEMP" |
| 85 | + cmake -S "$RUNNER_TEMP/zlib-${{ inputs.zlib_version }}" -B "$RUNNER_TEMP/zlib-build" -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="$GITHUB_WORKSPACE/deps/install/zlib" |
| 86 | + cmake --build "$RUNNER_TEMP/zlib-build" |
| 87 | + cmake --install "$RUNNER_TEMP/zlib-build" |
| 88 | +
|
| 89 | + - name: Build protobuf (static, /MD, Windows) |
| 90 | + if: steps.cache-common.outputs.cache-hit != 'true' && runner.os == 'Windows' |
| 91 | + shell: pwsh |
| 92 | + run: | |
| 93 | + curl.exe -L -o "$env:RUNNER_TEMP\pb.tar.gz" "https://github.com/protocolbuffers/protobuf/releases/download/v${{ inputs.pb_tag }}/protobuf-cpp-${{ inputs.pb_version }}.tar.gz" |
| 94 | + tar -xzf "$env:RUNNER_TEMP\pb.tar.gz" -C "$env:RUNNER_TEMP" |
| 95 | + # protobuf_MSVC_STATIC_RUNTIME=OFF is REQUIRED: the protobuf default (/MT) would |
| 96 | + # clash with KataGo's /MD Release build (LNK2038) when linking libprotobuf statically. |
| 97 | + cmake -S "$env:RUNNER_TEMP\protobuf-${{ inputs.pb_version }}" -B "$env:RUNNER_TEMP\pb-build" -G Ninja ` |
| 98 | + -DCMAKE_BUILD_TYPE=Release ` |
| 99 | + -Dprotobuf_BUILD_TESTS=OFF ` |
| 100 | + -Dprotobuf_BUILD_SHARED_LIBS=OFF ` |
| 101 | + -Dprotobuf_MSVC_STATIC_RUNTIME=OFF ` |
| 102 | + -DCMAKE_INSTALL_PREFIX=${{ github.workspace }}\deps\install\protobuf |
| 103 | + cmake --build "$env:RUNNER_TEMP\pb-build" |
| 104 | + cmake --install "$env:RUNNER_TEMP\pb-build" |
| 105 | +
|
| 106 | + - name: Build protobuf (static, Linux) |
| 107 | + if: steps.cache-common.outputs.cache-hit != 'true' && runner.os == 'Linux' |
| 108 | + shell: bash |
| 109 | + run: | |
| 110 | + curl -L -o "$RUNNER_TEMP/pb.tar.gz" "https://github.com/protocolbuffers/protobuf/releases/download/v${{ inputs.pb_tag }}/protobuf-cpp-${{ inputs.pb_version }}.tar.gz" |
| 111 | + tar -xzf "$RUNNER_TEMP/pb.tar.gz" -C "$RUNNER_TEMP" |
| 112 | + cmake -S "$RUNNER_TEMP/protobuf-${{ inputs.pb_version }}" -B "$RUNNER_TEMP/pb-build" -G Ninja \ |
| 113 | + -DCMAKE_BUILD_TYPE=Release \ |
| 114 | + -Dprotobuf_BUILD_TESTS=OFF \ |
| 115 | + -Dprotobuf_BUILD_SHARED_LIBS=OFF \ |
| 116 | + -DCMAKE_INSTALL_PREFIX="$GITHUB_WORKSPACE/deps/install/protobuf" |
| 117 | + cmake --build "$RUNNER_TEMP/pb-build" |
| 118 | + cmake --install "$RUNNER_TEMP/pb-build" |
| 119 | +
|
| 120 | + # --------------------------------------------------------------------------- |
| 121 | + # ONNX Runtime install tree, cached per (os, ep, version/ref). |
| 122 | + # --------------------------------------------------------------------------- |
| 123 | + - name: Restore ORT cache |
| 124 | + id: cache-ort |
| 125 | + uses: actions/cache@v4 |
| 126 | + with: |
| 127 | + path: deps/install/ort |
| 128 | + key: onnx-ort-${{ runner.os }}-${{ inputs.ep }}-${{ inputs.ort_version }}-${{ inputs.ort_ref }} |
| 129 | + |
| 130 | + # --- prebuilt: official ORT release zip (CPU EP) --- |
| 131 | + - name: Fetch prebuilt ORT (Windows) |
| 132 | + if: inputs.mode == 'prebuilt' && runner.os == 'Windows' && steps.cache-ort.outputs.cache-hit != 'true' |
| 133 | + shell: pwsh |
| 134 | + run: | |
| 135 | + New-Item -ItemType Directory -Force -Path "deps\install\ort" | Out-Null |
| 136 | + curl.exe -sfL -o "$env:RUNNER_TEMP\ort.zip" "https://github.com/microsoft/onnxruntime/releases/download/v${{ inputs.ort_version }}/onnxruntime-win-x64-${{ inputs.ort_version }}.zip" |
| 137 | + Expand-Archive -Path "$env:RUNNER_TEMP\ort.zip" -DestinationPath "$env:RUNNER_TEMP\ort" -Force |
| 138 | + $inner = Get-ChildItem "$env:RUNNER_TEMP\ort" -Directory | Select-Object -First 1 |
| 139 | + if ($inner) { |
| 140 | + Get-ChildItem $inner.FullName | Move-Item -Destination "deps\install\ort" -Force |
| 141 | + Remove-Item $inner.FullName -Recurse -Force |
| 142 | + } |
| 143 | + Remove-Item "$env:RUNNER_TEMP\ort.zip" -Force |
| 144 | + # Hoist lib/*.dll into bin/ too: the release-staging step globs bin/. |
| 145 | + New-Item -ItemType Directory -Force -Path "deps\install\ort\bin" | Out-Null |
| 146 | + Get-ChildItem "deps\install\ort\lib\*.dll" -ErrorAction SilentlyContinue | Copy-Item -Destination "deps\install\ort\bin" -Force |
| 147 | +
|
| 148 | + # --- nuget: Microsoft.ML.OnnxRuntime.DirectML package (DirectML EP) --- |
| 149 | + - name: Fetch DirectML NuGet package (Windows) |
| 150 | + if: inputs.mode == 'nuget' && runner.os == 'Windows' && steps.cache-ort.outputs.cache-hit != 'true' |
| 151 | + shell: pwsh |
| 152 | + run: | |
| 153 | + $src = "$env:RUNNER_TEMP\dml" |
| 154 | + New-Item -ItemType Directory -Force -Path "$src" | Out-Null |
| 155 | + curl.exe -sfL -o "$src\dml.nupkg" "https://api.nuget.org/v3-flatcontainer/microsoft.ml.onnxruntime.directml/${{ inputs.ort_version }}/microsoft.ml.onnxruntime.directml.${{ inputs.ort_version }}.nupkg" |
| 156 | + tar -xzf "$src\dml.nupkg" -C "$src" |
| 157 | + $root = "deps\install\ort" |
| 158 | + New-Item -ItemType Directory -Force -Path "$root\include","$root\lib","$root\bin" | Out-Null |
| 159 | + Copy-Item "$src\build\native\include\*" "$root\include" -Force |
| 160 | + Copy-Item "$src\runtimes\win-x64\native\onnxruntime.lib" "$root\lib" -Force |
| 161 | + Get-ChildItem "$src\runtimes\win-x64\native\*.dll" | Copy-Item -Destination "$root\lib" -Force |
| 162 | + Get-ChildItem "$root\lib\*.dll" | Copy-Item -Destination "$root\bin" -Force |
| 163 | +
|
| 164 | + # --- from-source: build ORT ourselves with the requested EP --- |
| 165 | + - name: Checkout ONNX Runtime source |
| 166 | + if: inputs.mode == 'from-source' && steps.cache-ort.outputs.cache-hit != 'true' |
| 167 | + uses: actions/checkout@v4 |
| 168 | + with: |
| 169 | + repository: microsoft/onnxruntime |
| 170 | + ref: ${{ inputs.ort_ref }} |
| 171 | + path: deps/onnxruntime |
| 172 | + submodules: recursive |
| 173 | + |
| 174 | + - name: Fetch OpenVINO toolkit (Windows) |
| 175 | + if: inputs.mode == 'from-source' && inputs.ep == 'openvino' && runner.os == 'Windows' && steps.cache-ort.outputs.cache-hit != 'true' |
| 176 | + shell: pwsh |
| 177 | + run: | |
| 178 | + $zip = "$env:RUNNER_TEMP\openvino.zip" |
| 179 | + $dest = "deps\openvino" |
| 180 | + Invoke-WebRequest -Uri "${{ inputs.ov_url }}" -OutFile $zip |
| 181 | + Expand-Archive -Path $zip -DestinationPath $dest |
| 182 | + # The zip contains a single top-level directory of the same name; hoist its contents up. |
| 183 | + $inner = Get-ChildItem -Path $dest -Directory | Select-Object -First 1 |
| 184 | + if ($inner) { |
| 185 | + Get-ChildItem -Path $inner.FullName | Move-Item -Destination $dest -Force |
| 186 | + Remove-Item -Path $inner.FullName -Recurse -Force |
| 187 | + } |
| 188 | + Remove-Item -Path $zip -Force |
| 189 | + $sv = Get-ChildItem "deps\openvino" -Recurse -Filter "setupvars.bat" | Select-Object -First 1 |
| 190 | + if (-not $sv) { throw "setupvars.bat not found under deps\openvino" } |
| 191 | + echo "OV_SETUPVARS=$($sv.FullName)" >> $env:GITHUB_ENV |
| 192 | +
|
| 193 | + - name: Build ONNX Runtime with OpenVINO EP |
| 194 | + if: inputs.mode == 'from-source' && inputs.ep == 'openvino' && steps.cache-ort.outputs.cache-hit != 'true' |
| 195 | + shell: cmd |
| 196 | + working-directory: deps/onnxruntime |
| 197 | + run: | |
| 198 | + call "%OV_SETUPVARS%" |
| 199 | + python tools\ci_build\build.py --build_dir build --config Release --use_openvino GPU --build_shared_lib --skip_tests --parallel --compile_no_warning_as_error --cmake_generator Ninja --cmake_extra_defines CMAKE_INSTALL_PREFIX=%CD%\..\install\ort |
| 200 | + if errorlevel 1 exit /b 1 |
| 201 | + cmake --install build\Release --config Release |
| 202 | + if errorlevel 1 exit /b 1 |
| 203 | +
|
| 204 | + # NOTE: TensorRT / MIGraphX from-source builds slot in here once validated. They need |
| 205 | + # CUDA+TensorRT SDK (ubuntu) / ROCm respectively, and github-hosted runners have no GPU, |
| 206 | + # so each should be smoke-validated on a GPU machine before being wired into the matrix. |
| 207 | + |
| 208 | + - name: Report ORT install tree |
| 209 | + shell: bash |
| 210 | + run: | |
| 211 | + ls -la deps/install/ort |
| 212 | + ls deps/install/ort/bin 2>/dev/null || ls deps/install/ort/lib 2>/dev/null || true |
0 commit comments