From 718b2e7f215e74a6ef43a91fc39b960611d558e0 Mon Sep 17 00:00:00 2001 From: Andrii Ryzhkov Date: Fri, 1 May 2026 13:08:09 +0200 Subject: [PATCH 1/3] Add ONNX Runtime GPU install scripts and manifest --- data/CMakeLists.txt | 2 + data/ort_gpu.json | 155 +++++++++ tools/ai/README.md | 107 ++++++ tools/ai/install-ort-amd-build.sh | 251 ++++++++++++++ tools/ai/install-ort-gpu.ps1 | 460 +++++++++++++++++++++++++ tools/ai/install-ort-gpu.sh | 537 ++++++++++++++++++++++++++++++ 6 files changed, 1512 insertions(+) create mode 100644 data/ort_gpu.json create mode 100644 tools/ai/README.md create mode 100755 tools/ai/install-ort-amd-build.sh create mode 100644 tools/ai/install-ort-gpu.ps1 create mode 100755 tools/ai/install-ort-gpu.sh diff --git a/data/CMakeLists.txt b/data/CMakeLists.txt index 08aa89aad91b..87fb18b89b53 100644 --- a/data/CMakeLists.txt +++ b/data/CMakeLists.txt @@ -171,6 +171,8 @@ if(USE_AI) # FILE(COPY ai_models.json DESTINATION "${DARKTABLE_DATADIR}") install(FILES ai_models.json DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/darktable COMPONENT DTApplication) + FILE(COPY ort_gpu.json DESTINATION "${DARKTABLE_DATADIR}") + install(FILES ort_gpu.json DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/darktable COMPONENT DTApplication) endif(USE_AI) # diff --git a/data/ort_gpu.json b/data/ort_gpu.json new file mode 100644 index 000000000000..fb7b1747973f --- /dev/null +++ b/data/ort_gpu.json @@ -0,0 +1,155 @@ +{ + "version": 1, + "install_docs": { + "nvidia": "https://developer.nvidia.com/cudnn-downloads", + "amd": "https://rocm.docs.amd.com/projects/install-on-linux/en/latest/" + }, + "packages": [ + { + "vendor": "nvidia", + "platform": "linux", + "arch": "x86_64", + "cuda_min": "12.0", + "cuda_max": "12.99", + "ort_version": "1.25.1", + "url": "https://github.com/microsoft/onnxruntime/releases/download/v1.25.1/onnxruntime-linux-x64-gpu-1.25.1.tgz", + "sha256": "c5f804ff5d239b436fa59e9f2fb288a39f7eb9552f6a636c8b71e792e91a8808", + "format": "tgz", + "lib_pattern": "libonnxruntime", + "install_subdir": "onnxruntime-cuda", + "size_mb": 200, + "requirements": "CUDA 12.x, cuDNN 9.x" + }, + { + "vendor": "nvidia", + "platform": "linux", + "arch": "x86_64", + "cuda_min": "13.0", + "cuda_max": "13.99", + "ort_version": "1.25.1", + "url": "https://github.com/microsoft/onnxruntime/releases/download/v1.25.1/onnxruntime-linux-x64-gpu_cuda13-1.25.1.tgz", + "sha256": "fdc6eb18317b4eaeda8b3b86595e5da7e853f72bac67ccac9b04ffc20c9f7fe0", + "format": "tgz", + "lib_pattern": "libonnxruntime", + "install_subdir": "onnxruntime-cuda", + "size_mb": 200, + "requirements": "CUDA 13.x, cuDNN 9.x" + }, + { + "vendor": "nvidia", + "platform": "windows", + "arch": "x86_64", + "cuda_min": "12.0", + "cuda_max": "12.99", + "ort_version": "1.25.1", + "url": "https://github.com/microsoft/onnxruntime/releases/download/v1.25.1/onnxruntime-win-x64-gpu-1.25.1.zip", + "sha256": "ef3337a0b8184eb8beec310f7c83bd50376b3eefc43aab84ac8e452f6987df0a", + "format": "zip", + "lib_pattern": "onnxruntime", + "install_subdir": "onnxruntime-cuda", + "size_mb": 200, + "requirements": "CUDA 12.x, cuDNN 9.x" + }, + { + "vendor": "nvidia", + "platform": "windows", + "arch": "x86_64", + "cuda_min": "13.0", + "cuda_max": "13.99", + "ort_version": "1.25.1", + "url": "https://github.com/microsoft/onnxruntime/releases/download/v1.25.1/onnxruntime-win-x64-gpu_cuda13-1.25.1.zip", + "sha256": "971be8cf984950672934a3173669590a8ece10b44746883420da8066ba836707", + "format": "zip", + "lib_pattern": "onnxruntime", + "install_subdir": "onnxruntime-cuda", + "size_mb": 200, + "requirements": "CUDA 13.x, cuDNN 9.x" + }, + { + "vendor": "amd", + "platform": "linux", + "arch": "x86_64", + "rocm_min": "7.0", + "rocm_max": "7.0", + "ort_version": "1.22.1", + "url": "https://repo.radeon.com/rocm/manylinux/rocm-rel-7.0.2/onnxruntime_rocm-1.22.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", + "sha256": "953a4e152f944391798880d88ea3d887c1109cfdc622815d81c07e2e1abc080e", + "format": "whl", + "lib_pattern": "libonnxruntime", + "install_subdir": "onnxruntime-migraphx", + "size_mb": 300, + "requirements": "ROCm 7.0, MIGraphX", + "required_libs": [ + "libmigraphx_c.so.3", + "librocm_smi64.so.7" + ] + }, + { + "vendor": "amd", + "platform": "linux", + "arch": "x86_64", + "rocm_min": "7.1", + "rocm_max": "7.1", + "ort_version": "1.23.1", + "url": "https://repo.radeon.com/rocm/manylinux/rocm-rel-7.1.1/onnxruntime_migraphx-1.23.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", + "sha256": "0bb62f7c2b326b2435396ef90a5f3ad030fe779aa9d0da7013d8b514c27de08f", + "format": "whl", + "lib_pattern": "libonnxruntime", + "install_subdir": "onnxruntime-migraphx", + "size_mb": 100, + "requirements": "ROCm 7.1, MIGraphX" + }, + { + "vendor": "amd", + "platform": "linux", + "arch": "x86_64", + "rocm_min": "7.2", + "rocm_max": "7.2", + "ort_version": "1.23.2", + "url": "https://repo.radeon.com/rocm/manylinux/rocm-rel-7.2.2/onnxruntime_migraphx-1.23.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", + "sha256": "45d556a6c261383f3e1f1469764a6ce94dc9daaa65fc3d494406d9cd357a3656", + "format": "whl", + "lib_pattern": "libonnxruntime", + "install_subdir": "onnxruntime-migraphx", + "size_mb": 300, + "requirements": "ROCm 7.2, MIGraphX" + }, + { + "vendor": "intel", + "platform": "linux", + "arch": "x86_64", + "ort_version": "1.24.1", + "url": "https://files.pythonhosted.org/packages/50/cf/17ba72de2df0fcba349937d2788f154397bbc2d1a2d67772a97e26f6bc5f/onnxruntime_openvino-1.24.1-cp312-cp312-manylinux_2_28_x86_64.whl", + "sha256": "d617fac2f59a6ab5ea59a788c3e1592240a129642519aaeaa774761dfe35150e", + "format": "whl", + "lib_pattern": "libonnxruntime", + "lib_extra_patterns": [ + "libopenvino", + "libtbb" + ], + "install_subdir": "onnxruntime-openvino", + "size_mb": 80, + "requirements": "Intel GPU driver (OpenCL)" + }, + { + "vendor": "intel", + "platform": "windows", + "arch": "x86_64", + "ort_version": "1.24.1", + "url": "https://files.pythonhosted.org/packages/59/37/d301f2c68b19a9485ed5db3047e0fb52478f3e73eb08c7d2a7c61be7cc1c/onnxruntime_openvino-1.24.1-cp312-cp312-win_amd64.whl", + "sha256": "f186335a9c9b255633275290da7521d3d4d14c7773fee3127bfa040234d3fa5a", + "format": "whl", + "lib_pattern": "onnxruntime", + "install_subdir": "onnxruntime-openvino", + "size_mb": 20, + "requirements": "Intel GPU driver", + "runtime_url": "https://files.pythonhosted.org/packages/73/cb/07035dcbf60347c0706c4f8d3ffb003c34fe8205e4041699a6655cc858c3/openvino-2026.1.0-21367-cp312-cp312-win_amd64.whl", + "runtime_sha256": "21fbc8f9aa765d9ded024311f4e48e38118643cda0f0139dcfa5422c0c457eb6", + "runtime_lib_pattern": "openvino", + "runtime_extra_patterns": [ + "tbb" + ], + "runtime_size_mb": 70 + } + ] +} diff --git a/tools/ai/README.md b/tools/ai/README.md new file mode 100644 index 000000000000..2633537b1c7f --- /dev/null +++ b/tools/ai/README.md @@ -0,0 +1,107 @@ +# GPU-Accelerated ONNX Runtime for darktable + +darktable bundles a CPU-only ONNX Runtime on Linux, DirectML on Windows, +and CoreML on macOS. To enable GPU acceleration for AI features (denoise, +upscale, segmentation), install a GPU-enabled ORT build using the +preferences UI or one of the install scripts in this directory. + +## What's bundled by default + +| Platform | Bundled ORT | GPU support | +|----------|------------|-------------| +| Linux | CPU only | None – install GPU ORT below | +| Windows | DirectML | AMD, NVIDIA, Intel via DirectX 12 | +| macOS | CoreML | Apple Neural Engine | + +## Easiest: install from darktable preferences + +1. Open darktable preferences (Ctrl+,) +2. Go to the **AI** tab +3. Click **install** – darktable detects your GPU and downloads + the correct ORT package automatically +4. Restart darktable + +Click **detect** instead to find a previously installed or +system-packaged ORT library. + +## Installing via script + +Linux: +```bash +./tools/ai/install-ort-gpu.sh --help # see all flags +./tools/ai/install-ort-gpu.sh +``` + +Windows (PowerShell): +```powershell +.\tools\ai\install-ort-gpu.ps1 -Help # see all flags +.\tools\ai\install-ort-gpu.ps1 +``` + +If Windows blocks the script ("running scripts is disabled on this +system"), bypass once: + +```powershell +powershell -ExecutionPolicy Bypass -File .\tools\ai\install-ort-gpu.ps1 +``` + +### Requirements + +**NVIDIA (CUDA)** – Pascal-or-newer GPU (compute 6.0+), driver 525+, +CUDA 12.x or 13.x toolkit, cuDNN 9.x. + +**AMD (MIGraphX)** – ROCm-supported GPU (Radeon RX 6000+ / Instinct +MI100+), ROCm 7.x with MIGraphX. Wheels are manylinux-repaired and +bundle their own ROCm runtime. + +**Intel (OpenVINO)** – Intel iGPU (HD/UHD/Iris Xe) or Arc discrete, +GPU driver with OpenCL (`intel-opencl-icd`) and/or Level Zero. The +OpenVINO runtime ships in the package. + +### AMD: building from source + +If the prebuilt package doesn't work (ABI mismatch, unsupported ROCm +version), build ORT against your installed ROCm: + +```bash +./tools/ai/install-ort-amd-build.sh +``` + +Requires cmake 3.26+, gcc/g++, python3, git. Takes 10–20 minutes. + +## Enabling the custom ORT in darktable + +After running the script or built-in installer: + +1. Open darktable preferences (Ctrl+,) +2. Go to the **AI** tab +3. Click **detect**, or use the browse button to select the library + manually +4. Restart darktable + +Or set `DT_ORT_LIBRARY` in the environment: + +```bash +# Linux +DT_ORT_LIBRARY=~/.local/lib/onnxruntime-cuda/libonnxruntime.so.1.24.4 darktable +``` +```powershell +# Windows +$env:DT_ORT_LIBRARY="$env:LOCALAPPDATA\onnxruntime-cuda\onnxruntime.dll"; darktable +``` + +If neither preference nor env var is set, darktable uses the bundled +ORT (CPU on Linux, DirectML on Windows, CoreML on macOS). + +## Verifying + +```bash +darktable -d ai +``` + +Look for: +``` +[darktable_ai] loaded ORT 1.24.4 from '/home/user/.local/lib/onnxruntime-cuda/libonnxruntime.so.1.24.4' +[darktable_ai] execution provider: CUDA +[darktable_ai] NVIDIA CUDA enabled successfully on device 0: NVIDIA GeForce RTX 4090 +``` diff --git a/tools/ai/install-ort-amd-build.sh b/tools/ai/install-ort-amd-build.sh new file mode 100755 index 000000000000..975536802fe0 --- /dev/null +++ b/tools/ai/install-ort-amd-build.sh @@ -0,0 +1,251 @@ +#!/bin/bash +# +# Build and install ONNX Runtime with MIGraphX ExecutionProvider +# for darktable AI acceleration on AMD GPUs. +# +# Unlike NVIDIA (which has pre-built packages), MIGraphX EP must be +# built from source to match the installed ROCm version. +# +# Requirements: +# - AMD GPU supported by ROCm (RDNA2+, CDNA+) +# - ROCm 7.x with MIGraphX installed +# - Build tools: cmake 3.26+, gcc/g++, python3 +# +# Usage: install-ort-amd-build.sh [-y|--yes] [install-dir] + +set -euo pipefail + +YES=false +FORCE=false +while [ $# -gt 0 ]; do + case "$1" in + -y|--yes) YES=true; shift ;; + -f|--force) FORCE=true; shift ;; + *) break ;; + esac +done + +INSTALL_DIR="${1:-$HOME/.local/lib/onnxruntime-migraphx}" +ROCM_HOME="${ROCM_HOME:-/opt/rocm}" +BUILD_DIR="${TMPDIR:-/tmp}/ort-migraphx-build" + +# --- Platform checks (before user prompt) --- +if [ "$(uname -s)" != "Linux" ]; then + echo "Error: this script is for Linux only." >&2 + exit 1 +fi + +if [ "$(uname -m)" != "x86_64" ]; then + echo "Error: MIGraphX EP is only available for x86_64 (got $(uname -m))." >&2 + exit 1 +fi + +# --- Info & confirmation --- +echo "" +echo "ONNX Runtime - MIGraphX ExecutionProvider builder" +echo "===================================================" +echo "" +echo "This will build ONNX Runtime from source with AMD MIGraphX support" +echo "to enable GPU acceleration for darktable AI features" +echo "(denoise, upscale, segmentation)." +echo "" +echo "Unlike NVIDIA, there is no pre-built package - ORT must be compiled" +echo "against the ROCm version installed on your system." +echo "" +echo "Requirements:" +echo " - AMD GPU supported by ROCm (Radeon RX 6000+, Instinct MI100+)" +echo " - ROCm 7.x with MIGraphX" +echo " - cmake 3.26+, gcc/g++, python3, git" +echo "" +echo "Actions:" +echo " - Clone ORT source (~300 MB)" +echo " - Build with MIGraphX EP (10-20 min depending on hardware)" +echo " - Install shared libraries to: $INSTALL_DIR" +echo "" + +if [ "$YES" = false ]; then + read -rp "Continue? [y/N] " answer + if [[ ! "$answer" =~ ^[Yy] ]]; then + echo "Aborted." + exit 0 + fi + echo "" +fi + +# --- Helper: distro-specific install hint --- +distro_hint() { + local pkg_deb="$1" pkg_rpm="$2" pkg_arch="$3" pkg_suse="$4" fallback_url="$5" + if [ -f /etc/os-release ]; then + . /etc/os-release + case "$ID" in + ubuntu|debian|linuxmint|pop) + echo " Install on $NAME:" + echo " $pkg_deb" + ;; + fedora|rhel|centos|rocky|alma) + echo " Install on $NAME:" + echo " $pkg_rpm" + ;; + arch|manjaro|endeavouros) + echo " Install on $NAME:" + echo " $pkg_arch" + ;; + opensuse*|sles) + echo " Install on $NAME:" + echo " $pkg_suse" + ;; + *) + echo " Download from: $fallback_url" + return + ;; + esac + else + echo " Download from: $fallback_url" + fi +} + +if [ "$FORCE" = false ]; then + # --- Check ROCm --- + if ! command -v rocminfo &>/dev/null || [ ! -d "$ROCM_HOME" ]; then + echo "Error: ROCm not found at $ROCM_HOME" + echo "" + distro_hint \ + "sudo apt install rocm (add AMD repo first: https://rocm.docs.amd.com/projects/install-on-linux/en/latest/)" \ + "sudo dnf install rocm (add AMD repo first: https://rocm.docs.amd.com/projects/install-on-linux/en/latest/)" \ + "sudo pacman -S rocm-hip-sdk" \ + "sudo zypper install rocm (add AMD repo first: https://rocm.docs.amd.com/projects/install-on-linux/en/latest/)" \ + "https://rocm.docs.amd.com/projects/install-on-linux/en/latest/" + echo "" + exit 1 + fi +else + echo "Skipping dependency checks (--force)" +fi + +ROCM_VERSION="unknown" +if [ -f "$ROCM_HOME/.info/version" ]; then + ROCM_VERSION=$(cat "$ROCM_HOME/.info/version") +fi +echo "ROCm: $ROCM_VERSION ($ROCM_HOME)" + +# --- Select ORT version matching ROCm --- +ROCM_MAJOR_MINOR=$(echo "$ROCM_VERSION" | grep -oP '^\d+\.\d+') +case "$ROCM_MAJOR_MINOR" in + # 7.3+) ORT_VERSION="1.24.4" ;; # TODO: confirm when docs are updated + 7.2*) ORT_VERSION="1.23.2" ;; + 7.1*) ORT_VERSION="1.23.1" ;; + 7.0*) ORT_VERSION="1.22.1" ;; + 6.4*) ORT_VERSION="1.21.0" ;; + 6.3*) ORT_VERSION="1.19.0" ;; + 6.2*) ORT_VERSION="1.18.0" ;; + 6.1*) ORT_VERSION="1.17.0" ;; + 6.0*) ORT_VERSION="1.16.0" ;; + *) + echo "" + echo "Error: unsupported ROCm version $ROCM_VERSION" + echo " Supported: ROCm 6.0 - 7.2" + echo " Update ROCm or set ORT_VERSION manually and re-run." + echo "" + exit 1 + ;; +esac +echo "ORT version: $ORT_VERSION (matched to ROCm $ROCM_MAJOR_MINOR)" + +if [ "$FORCE" = false ]; then + # --- Check MIGraphX --- + if ! command -v migraphx-driver &>/dev/null \ + && [ ! -f "$ROCM_HOME/lib/libmigraphx.so" ] \ + && [ ! -f "$ROCM_HOME/lib64/libmigraphx.so" ]; then + echo "" + echo "Error: MIGraphX not found in $ROCM_HOME" + echo "" + distro_hint \ + "sudo apt install migraphx migraphx-dev" \ + "sudo dnf install migraphx migraphx-devel" \ + "sudo pacman -S migraphx" \ + "sudo zypper install migraphx migraphx-devel" \ + "https://rocm.docs.amd.com/projects/install-on-linux/en/latest/" + echo "" + exit 1 + fi + echo "MIGraphX: found" + + # --- Check build tools --- + MISSING="" + command -v cmake &>/dev/null || MISSING="$MISSING cmake" + command -v g++ &>/dev/null || MISSING="$MISSING g++" + command -v git &>/dev/null || MISSING="$MISSING git" + command -v python3 &>/dev/null || MISSING="$MISSING python3" + + if [ -n "$MISSING" ]; then + echo "" + echo "Error: missing build tools:$MISSING" + echo "" + distro_hint \ + "sudo apt install$MISSING" \ + "sudo dnf install$MISSING" \ + "sudo pacman -S$MISSING" \ + "sudo zypper install$MISSING" \ + "" + echo "" + exit 1 + fi +fi + +CMAKE_VERSION=$(cmake --version 2>/dev/null | head -1 | grep -oP '[0-9]+\.[0-9]+' || echo "unknown") +echo "cmake: $CMAKE_VERSION" + +# --- Clone & build --- +echo "" +echo "Cloning ONNX Runtime v${ORT_VERSION}..." + +rm -rf "$BUILD_DIR" +mkdir -p "$BUILD_DIR" + +git clone --depth 1 --branch "v${ORT_VERSION}" \ + https://github.com/microsoft/onnxruntime.git "$BUILD_DIR/onnxruntime" + +cd "$BUILD_DIR/onnxruntime" + +# Patch Eigen hash mismatch - GitLab regenerates zip archives, breaking the +# hardcoded SHA1 in older ORT releases. Remove the URL_HASH line from +# eigen.cmake so FetchContent downloads without verification. +if [ -f "cmake/external/eigen.cmake" ]; then + sed -i '/URL_HASH/d' cmake/external/eigen.cmake + echo "Patched Eigen: removed URL_HASH check (GitLab zip archive mismatch)" +fi + +echo "" +echo "Building with MIGraphX EP (this will take 30-60 minutes)..." +echo "" + +./build.sh \ + --config Release \ + --build_shared_lib \ + --parallel \ + --skip_tests \ + --use_migraphx \ + --migraphx_home "$ROCM_HOME" + +# --- Install --- +BUILD_LIB_DIR="$BUILD_DIR/onnxruntime/build/Linux/Release" + +mkdir -p "$INSTALL_DIR" +cp "$BUILD_LIB_DIR/"libonnxruntime*.so* "$INSTALL_DIR/" + +# Clean up build tree (~2 GB) +rm -rf "$BUILD_DIR" + +ORT_SO=$(ls "$INSTALL_DIR/libonnxruntime.so."* 2>/dev/null | head -1) + +echo "" +echo "Done. Installed to: $INSTALL_DIR" +ls -lh "$INSTALL_DIR/"*.so* 2>/dev/null +echo "" +echo "To use with darktable:" +echo "" +echo " DT_ORT_LIBRARY=$ORT_SO darktable" +echo "" +echo "Or add to ~/.bashrc:" +echo "" +echo " export DT_ORT_LIBRARY=$ORT_SO" diff --git a/tools/ai/install-ort-gpu.ps1 b/tools/ai/install-ort-gpu.ps1 new file mode 100644 index 000000000000..629f0c542e00 --- /dev/null +++ b/tools/ai/install-ort-gpu.ps1 @@ -0,0 +1,460 @@ +<# +.SYNOPSIS + Install GPU-accelerated ONNX Runtime for darktable. + +.DESCRIPTION + Reads the package manifest (data/ort_gpu.json) to determine the + correct download URL for the detected GPU, downloads the ORT + package, and installs the libraries to + %LOCALAPPDATA%\onnxruntime-\. + + For NVIDIA, additionally bundles cuDNN and the required CUDA + toolkit DLLs (cublas, cublasLt, cudart, cufft, curand) from the + user's installed CUDA toolkit so the resulting directory is + self-contained. + + Supported vendors on Windows: + - NVIDIA via CUDA EP (requires CUDA 12.x or 13.x + cuDNN 9.x) + - Intel via OpenVINO (requires Intel GPU driver) + + GPU auto-detection uses: + - nvidia-smi (NVIDIA) + - Get-CimInstance Win32_VideoController (Intel) + + After installing, point darktable at the new library: + Preferences -> AI -> ONNX Runtime library -> "detect" or "browse" + Restart darktable to apply. Or set DT_ORT_LIBRARY= in the + environment. + +.PARAMETER Yes + Skip the interactive "Continue?" prompt. + +.PARAMETER Force + Skip the vendor-specific dependency check (CUDA toolkit, cuDNN). + The download proceeds regardless; if dependencies are missing at + runtime, ORT will fall back to CPU. + +.PARAMETER Vendor + Force a specific GPU vendor and skip auto-detection. + Valid values: "nvidia", "intel". + +.PARAMETER Manifest + Use a custom ort_gpu.json manifest. Default search order: +