|
| 1 | +# MIGraphX + ONNX Runtime (ROCm) build notes |
| 2 | + |
| 3 | +This workspace uses ONNX Runtime built with the MIGraphX execution provider. |
| 4 | +ROCm EP is not present in `/opt/onnxruntime-migraphx`, so MIGraphX is used as the GPU backend. |
| 5 | + |
| 6 | +## Key findings |
| 7 | + |
| 8 | +- `libyolox_cpp.so` links against `/opt/onnxruntime-migraphx/lib/libonnxruntime.so.1`. |
| 9 | +- That onnxruntime build exposes `MIGraphXExecutionProvider` (not `ROCMExecutionProvider`). |
| 10 | +- MIGraphX tries to save compiled models; if a cache path is not set, it can fail with: |
| 11 | + - `migraphx_save: ... Failure opening file: ""/....mxr` |
| 12 | +- To avoid this, ensure `ORT_MIGRAPHX_MODEL_CACHE_PATH` (and/or `ORT_MIGRAPHX_CACHE_PATH`) is set. |
| 13 | + |
| 14 | +## Prerequisites (Ubuntu 24.04 + ROCm) |
| 15 | + |
| 16 | +### Install Radeon driver + ROCm |
| 17 | + |
| 18 | +If you already installed `amdgpu-install_7.1.x`, install the ROCm usecase: |
| 19 | + |
| 20 | +```bash |
| 21 | +sudo amdgpu-install --list-usecase |
| 22 | +sudo amdgpu-install -y --usecase=graphics,rocm |
| 23 | +sudo reboot |
| 24 | +``` |
| 25 | + |
| 26 | +After reboot, allow GPU compute access and reboot again: |
| 27 | + |
| 28 | +```bash |
| 29 | +sudo usermod -a -G render,video $USER |
| 30 | +sudo reboot |
| 31 | +``` |
| 32 | + |
| 33 | +Verify ROCm is visible: |
| 34 | + |
| 35 | +```bash |
| 36 | +/opt/rocm/bin/rocminfo | less |
| 37 | +hipcc --version |
| 38 | +``` |
| 39 | + |
| 40 | +### Install MIGraphX packages |
| 41 | + |
| 42 | +```bash |
| 43 | +sudo apt update |
| 44 | +sudo apt install -y migraphx migraphx-dev half |
| 45 | +dpkg -l | egrep 'migraphx|half' |
| 46 | +``` |
| 47 | + |
| 48 | +Check the MIGraphX install path (used as `--migraphx_home` below): |
| 49 | + |
| 50 | +```bash |
| 51 | +dpkg -L migraphx-dev | head -n 50 |
| 52 | +``` |
| 53 | + |
| 54 | +## Build and install ONNX Runtime (MIGraphX EP) |
| 55 | + |
| 56 | +### Build |
| 57 | + |
| 58 | +ROCm EP was removed in onnxruntime 1.23+, so use MIGraphX EP. |
| 59 | + |
| 60 | +```bash |
| 61 | +git clone --recursive https://github.com/microsoft/onnxruntime |
| 62 | +cd onnxruntime |
| 63 | +./build.sh --config Release --build_shared_lib --parallel \ |
| 64 | + --use_migraphx --migraphx_home /opt/rocm \ |
| 65 | + --update --build --skip_tests |
| 66 | +``` |
| 67 | + |
| 68 | +### Install |
| 69 | + |
| 70 | +```bash |
| 71 | +cd build/Linux/Release |
| 72 | +sudo cmake --install . --prefix /opt/onnxruntime-migraphx |
| 73 | +echo /opt/onnxruntime-migraphx/lib | sudo tee /etc/ld.so.conf.d/onnxruntime.conf |
| 74 | +sudo ldconfig |
| 75 | +ldconfig -p | grep onnxruntime |
| 76 | +``` |
| 77 | + |
| 78 | +## Build (colcon) |
| 79 | + |
| 80 | +Example build command (matches local setup with `/opt/onnxruntime-migraphx`): |
| 81 | + |
| 82 | +``` |
| 83 | +colcon build --symlink-install \ |
| 84 | + --cmake-args \ |
| 85 | + -DCMAKE_BUILD_TYPE=Release \ |
| 86 | + -DYOLOX_USE_ONNXRUNTIME=ON \ |
| 87 | + -DONNXRUNTIME_MIGRAPHX=ON \ |
| 88 | + -DCMAKE_CXX_FLAGS="-I/opt/onnxruntime-migraphx/include" \ |
| 89 | + -DCMAKE_EXE_LINKER_FLAGS="-L/opt/onnxruntime-migraphx/lib -lonnxruntime" \ |
| 90 | + -DCMAKE_SHARED_LINKER_FLAGS="-L/opt/onnxruntime-migraphx/lib -lonnxruntime" |
| 91 | +``` |
| 92 | + |
| 93 | +## Runtime cache path |
| 94 | + |
| 95 | +Set a writable cache directory before running: |
| 96 | + |
| 97 | +``` |
| 98 | +export ORT_MIGRAPHX_MODEL_CACHE_PATH=/tmp/onnxruntime-migraphx-cache |
| 99 | +export ORT_MIGRAPHX_CACHE_PATH=/tmp/onnxruntime-migraphx-cache |
| 100 | +``` |
| 101 | + |
| 102 | +## Run example |
| 103 | + |
| 104 | +``` |
| 105 | +source install/setup.bash |
| 106 | +ros2 run yolox_ros_cpp yolox_ros_cpp_node --ros-args \ |
| 107 | + -p model_path:=./src/YOLOX-ROS/weights/onnx/yolox_tiny.onnx \ |
| 108 | + -p model_type:=onnxruntime \ |
| 109 | + -p use_gpu:=true |
| 110 | +``` |
0 commit comments