Skip to content

Add ONNX Runtime backend support (OpenVINO / DirectML / TensorRT / CPU, Windows & Linux) #3

Add ONNX Runtime backend support (OpenVINO / DirectML / TensorRT / CPU, Windows & Linux)

Add ONNX Runtime backend support (OpenVINO / DirectML / TensorRT / CPU, Windows & Linux) #3

Workflow file for this run

# ONNX backend CI. Builds KataGo (USE_BACKEND=ONNX) against an ONNX Runtime carrying the
# requested execution provider, runs `katago runtests`, and uploads a self-contained
# runnable directory as an artifact for easy download.
#
# Execution providers differ only in how ONNX Runtime is obtained; that difference lives
# in .github/actions/onnx-prepare-ort/action.yml (one row in the matrix below per EP):
# - prebuilt : official ORT release package (zip on Windows, tgz on Linux; the CPU
# EP ships inside it)
# - nuget : Microsoft.ML.OnnxRuntime.DirectML package (DirectML EP)
# - from-source : ORT built from source with the EP (OpenVINO on Windows, TensorRT in an
# NGC container)
#
# Trigger policy by tier:
# - fast EPs (prebuilt/nuget, a few minutes) run on PR + master push + manual dispatch,
# so the ONNX backend keeps a cheap always-on regression guard.
# - slow EPs (from-source ORT builds, 1-3h) run only on manual dispatch, so they never
# burn upstream CI minutes on every PR/commit.
# GitHub-hosted runners have no GPU, so from-source jobs only verify build + EP wiring;
# real GPU inference must be validated on a GPU machine.
#
# Adding a backend = add one matrix row + teach onnx-prepare-ort to fetch/build its ORT
# (and extend the release-staging step in onnx-build-katago if it ships extra runtimes).
name: ONNX backend build & test
on:
pull_request:
branches: [ master ]
paths:
- 'cpp/**'
- '.github/workflows/onnx-backend.yml'
- '.github/actions/**'
push:
# ci/onnx-windows is a TEMPORARY trigger so this workflow can be exercised before it
# exists on the default branch (workflow_dispatch requires the file on the default
# branch). Remove it once the branch is validated / merged to master.
branches: [ master, ci/onnx-windows ]
paths:
- 'cpp/**'
- '.github/workflows/onnx-backend.yml'
- '.github/actions/**'
workflow_dispatch:
concurrency:
group: onnx-backend-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
env:
# from-source ORT pin. 1.29.0 has no release tag (VERSION_NUMBER is 1.29.0 but no
# v1.29.0 tag exists), so pin to the exact commit the ONNX backend was verified against
# locally instead of master, which would drift. Update to re-validate a newer snapshot.
ORT_REF: 7e76a52398ebf966bcbe4a10e552f438059edfce
OV_URL: https://storage.openvinotoolkit.org/repositories/openvino/packages/2026.2.1/windows/openvino_toolkit_windows_2026.2.1.21919.ede283a88e3_x86_64.zip
OV_VERSION: 2026.2.1
jobs:
build-fast:
name: ${{ matrix.ep }} (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- { ep: cpu, os: windows-latest, mode: prebuilt, ort_version: "1.28.0" }
- { ep: cpu, os: ubuntu-latest, mode: prebuilt, ort_version: "1.28.0" }
- { ep: directml, os: windows-latest, mode: nuget, ort_version: "1.24.4" }
steps:
- uses: actions/checkout@v4
- name: Setup MSVC environment
if: runner.os == 'Windows'
uses: ilammy/msvc-dev-cmd@v1
with:
arch: x64
- name: Install Ninja (Windows)
if: runner.os == 'Windows'
run: choco install ninja -y --no-progress
- name: Install Ninja (Linux)
if: runner.os == 'Linux'
run: sudo apt-get update && sudo apt-get install -y ninja-build
- name: Prepare ONNX Runtime (${{ matrix.ep }})
uses: ./.github/actions/onnx-prepare-ort
with:
ep: ${{ matrix.ep }}
mode: ${{ matrix.mode }}
ort_version: ${{ matrix.ort_version }}
- name: Build & test KataGo
uses: ./.github/actions/onnx-build-katago
with:
ort_root: ${{ github.workspace }}/deps/install/ort
ep: ${{ matrix.ep }}
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: katago-${{ runner.os }}-onnx-${{ matrix.ep }}
path: release/
build-slow:
# from-source ORT builds (1-3h) only on manual dispatch.
if: github.event_name == 'workflow_dispatch'
name: ${{ matrix.ep }} (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- { ep: openvino, os: windows-latest, mode: from-source }
# - { ep: migraphx, os: ubuntu-latest, mode: from-source } # needs ROCm; deferred (no ROCm on hosted runners)
steps:
- uses: actions/checkout@v4
- name: Setup MSVC environment
if: runner.os == 'Windows'
uses: ilammy/msvc-dev-cmd@v1
with:
arch: x64
- name: Install Ninja (Windows)
if: runner.os == 'Windows'
run: choco install ninja -y --no-progress
- name: Install Ninja (Linux)
if: runner.os == 'Linux'
run: sudo apt-get update && sudo apt-get install -y ninja-build
- name: Prepare ONNX Runtime (${{ matrix.ep }})
uses: ./.github/actions/onnx-prepare-ort
with:
ep: ${{ matrix.ep }}
mode: ${{ matrix.mode }}
ort_ref: ${{ env.ORT_REF }}
ov_version: ${{ env.OV_VERSION }}
ov_url: ${{ env.OV_URL }}
- name: Build & test KataGo
uses: ./.github/actions/onnx-build-katago
with:
ort_root: ${{ github.workspace }}/deps/install/ort
ep: ${{ matrix.ep }}
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: katago-${{ runner.os }}-onnx-${{ matrix.ep }}
path: release/
build-tensorrt:
# ORT from-source TensorRT build (1-2h), dispatch-only. Runs inside the official NGC
# TensorRT container (nvcr.io/nvidia/tensorrt:25.03-py3 = CUDA 12.8 + TensorRT 10.9, the
# combo ORT is built/tested against), so the CUDA/cuDNN/TensorRT SDKs are preinstalled
# and no SDK install step is needed. github-hosted runners have no GPU, so this job
# verifies build + EP wiring only; real GPU inference is validated on a GPU machine.
if: github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
container:
image: nvcr.io/nvidia/tensorrt:25.03-py3
options: --user root
steps:
# The NGC image ships neither git nor node, and later steps are GitHub JS actions
# (cache, checkout, upload-artifact) that need node. Bootstrap both plus ninja first,
# then clone the repo by hand (checkout@v4 would run before node existed).
- name: Bootstrap container (git, node20, ninja) and checkout
run: |
apt-get update -qq
apt-get install -y -qq git ninja-build curl >/dev/null
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
apt-get install -y -qq nodejs >/dev/null
node --version
# ORT 1.28 needs CMake >= 3.28; the NGC image ships 3.27. pip cmake lands in
# /usr/local/bin ahead of the bundled one.
pip3 install cmake >/dev/null
cmake --version | head -1
# The workspace is a docker mount owned by a different uid, so git refuses it
# ("dubious ownership") when KataGo regenerates gitinfo.h during the build.
git config --global --add safe.directory '*'
git clone --depth 1 --branch "${GITHUB_REF_NAME}" "https://github.com/${GITHUB_REPOSITORY}.git" .
- name: Prepare ONNX Runtime (tensorrt)
uses: ./.github/actions/onnx-prepare-ort
with:
ep: tensorrt
mode: from-source
ort_ref: ${{ env.ORT_REF }}
- name: Build & test KataGo
uses: ./.github/actions/onnx-build-katago
with:
ort_root: ${{ github.workspace }}/deps/install/ort
ep: tensorrt
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: katago-Linux-onnx-tensorrt
path: release/