531 字
3 分钟
1,045 次阅读
Jetson Orin Nano编译ONNX Runtime GPU
本机实验配置 (Release中有编译好的whl)
编译环境准备
最新版ONNX需要 CMake > 3.28, GCC 11
升级 CMake
sudo apt purge cmake -ysudo apt install -y apt-transport-https ca-certificates gnupg software-properties-common wgetwget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | \ gpg --dearmor - | sudo tee /usr/share/keyrings/kitware-archive-keyring.gpg >/dev/nullecho 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ jammy main' | \ sudo tee /etc/apt/sources.list.d/kitware.list >/dev/nullsudo apt updatesudo apt install -y cmakecmake --version
升级 GCC 到 11
sudo apt updatesudo apt install -y gcc-11 g++-11sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 100sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 110sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 100sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 110gcc --version
编译ONNX
git clone --recursive https://github.com/microsoft/onnxruntimecd onnxruntime./build.sh --config Release \ --update --build --parallel --build_wheel \ --use_tensorrt --use_cuda \ --cuda_home /usr/local/cuda \ --cudnn_home /usr/lib/aarch64-linux-gnu \ --tensorrt_home /usr/lib/aarch64-linux-gnu \ --cmake_extra_defines CMAKE_CUDA_ARCHITECTURES=87编译到90%+会失败,不用担心,只是测试失败了,删除测试就好了(
rm -f onnxruntime/test/providers/cpu/nn/conv_fp16_test.cccmake --build build/Linux/Release --config Release -j$(nproc)./build.sh --config Release \ --update --build --parallel --build_wheel --skip_tests \ --use_tensorrt --use_cuda \ --cuda_home /usr/local/cuda \ --cudnn_home /usr/lib/aarch64-linux-gnu \ --tensorrt_home /usr/lib/aarch64-linux-gnu![]()
安装并测试ONNXruntime-GPU
我这里使用的是UV管理环境
uv pip install ~/onnxruntime/build/Linux/Release/dist/onnxruntime_gpu-*
测试代码
python3 - <<'EOF'import onnxruntime as ortprint("ONNX Runtime:", ort.__version__)print("Available providers:", ort.get_available_providers())print("Default device:", ort.get_device())EOF恭喜 TensorRT 和 CUDA 都已启用加速(在Jetson平台上这条 W:警告⚠️可以忽略)

推理immich-machine-learning
安装UV
curl -LsSf https://astral.sh/uv/install.sh | sh拉取代码
git clone https://github.com/immich-app/immich.gitcd immich/machine-learning找到pyproject.toml修改依赖文件,将 cuda = [“onnxruntime-gpu>=1.17.0,<2”] 中的 -gpu 删掉,以及注释掉以下代码
#name = "cuda12"#url = "https://aiinfra.pkgs.visualstudio.com/PublicPackages/_packaging/#onnxruntime-cuda-12/pypi/simple/"#explicit = true##[tool.uv.sources]#onnxruntime-gpu = { index = "cuda12" }然后执行代码安装CPU版本的onnxruntime,目的是马上替换我们上面编译好的GPU版本
uv sync --extra cudasource .venv/bin/activateuv pip uninstall onnxruntimeuv pip install ~/onnxruntime/build/Linux/Release/dist/onnxruntime_gpu-*在目录下新建一个.env就可以开始跑了
export MACHINE_LEARNING_GPU_ACCELERATION=cudaexport NVIDIA_VISIBLE_DEVICES=allexport IMMICH_PORT=3003启动项目
python3 -m immich_ml
Jetson Orin Nano编译ONNX Runtime GPU
https://nvcc-v.com/2025/11/03/jetson-orin-onnx-gpu/ KEEP EXPLORING