diff --git a/README.md b/README.md
index 38434df..7302fdd 100644
--- a/README.md
+++ b/README.md
@@ -15,10 +15,11 @@
| Base | ROS2 C++ |
| --------------- | -------- |
-| TensorRT (CUDA) | ✅ |
-| OpenVINO | ✅ |
-| ONNX Runtime | ✅ |
-| TFLite | ✅ |
+| TensorRT | ✅ |
+| OpenVINO | ✅ |
+| ONNRuntime CUDA | ✅ |
+| ONNRuntime MIGraphX | ✅ |
+| TFLite | ✅ |
## Installation & Demo (C++)
@@ -45,7 +46,6 @@ Check [this URL](./yolox_ros_cpp/README.md).
-##
## Reference
diff --git a/yolox_ros_cpp/MIGraphX.md b/yolox_ros_cpp/MIGraphX.md
new file mode 100644
index 0000000..1d9b673
--- /dev/null
+++ b/yolox_ros_cpp/MIGraphX.md
@@ -0,0 +1,110 @@
+# MIGraphX + ONNX Runtime (ROCm) build notes
+
+This workspace uses ONNX Runtime built with the MIGraphX execution provider.
+ROCm EP is not present in `/opt/onnxruntime-migraphx`, so MIGraphX is used as the GPU backend.
+
+## Key findings
+
+- `libyolox_cpp.so` links against `/opt/onnxruntime-migraphx/lib/libonnxruntime.so.1`.
+- That onnxruntime build exposes `MIGraphXExecutionProvider` (not `ROCMExecutionProvider`).
+- MIGraphX tries to save compiled models; if a cache path is not set, it can fail with:
+ - `migraphx_save: ... Failure opening file: ""/....mxr`
+- To avoid this, ensure `ORT_MIGRAPHX_MODEL_CACHE_PATH` (and/or `ORT_MIGRAPHX_CACHE_PATH`) is set.
+
+## Prerequisites (Ubuntu 24.04 + ROCm)
+
+### Install Radeon driver + ROCm
+
+If you already installed `amdgpu-install_7.1.x`, install the ROCm usecase:
+
+```bash
+sudo amdgpu-install --list-usecase
+sudo amdgpu-install -y --usecase=graphics,rocm
+sudo reboot
+```
+
+After reboot, allow GPU compute access and reboot again:
+
+```bash
+sudo usermod -a -G render,video $USER
+sudo reboot
+```
+
+Verify ROCm is visible:
+
+```bash
+/opt/rocm/bin/rocminfo | less
+hipcc --version
+```
+
+### Install MIGraphX packages
+
+```bash
+sudo apt update
+sudo apt install -y migraphx migraphx-dev half
+dpkg -l | egrep 'migraphx|half'
+```
+
+Check the MIGraphX install path (used as `--migraphx_home` below):
+
+```bash
+dpkg -L migraphx-dev | head -n 50
+```
+
+## Build and install ONNX Runtime (MIGraphX EP)
+
+### Build
+
+ROCm EP was removed in onnxruntime 1.23+, so use MIGraphX EP.
+
+```bash
+git clone --recursive https://github.com/microsoft/onnxruntime
+cd onnxruntime
+./build.sh --config Release --build_shared_lib --parallel \
+ --use_migraphx --migraphx_home /opt/rocm \
+ --update --build --skip_tests
+```
+
+### Install
+
+```bash
+cd build/Linux/Release
+sudo cmake --install . --prefix /opt/onnxruntime-migraphx
+echo /opt/onnxruntime-migraphx/lib | sudo tee /etc/ld.so.conf.d/onnxruntime.conf
+sudo ldconfig
+ldconfig -p | grep onnxruntime
+```
+
+## Build (colcon)
+
+Example build command (matches local setup with `/opt/onnxruntime-migraphx`):
+
+```
+colcon build --symlink-install \
+ --cmake-args \
+ -DCMAKE_BUILD_TYPE=Release \
+ -DYOLOX_USE_ONNXRUNTIME=ON \
+ -DONNXRUNTIME_MIGRAPHX=ON \
+ -DCMAKE_CXX_FLAGS="-I/opt/onnxruntime-migraphx/include" \
+ -DCMAKE_EXE_LINKER_FLAGS="-L/opt/onnxruntime-migraphx/lib -lonnxruntime" \
+ -DCMAKE_SHARED_LINKER_FLAGS="-L/opt/onnxruntime-migraphx/lib -lonnxruntime"
+```
+
+## Runtime cache path
+
+Set a writable cache directory before running:
+
+```
+export ORT_MIGRAPHX_MODEL_CACHE_PATH=/tmp/onnxruntime-migraphx-cache
+export ORT_MIGRAPHX_CACHE_PATH=/tmp/onnxruntime-migraphx-cache
+```
+
+## Run example
+
+```
+source install/setup.bash
+ros2 run yolox_ros_cpp yolox_ros_cpp_node --ros-args \
+ -p model_path:=./src/YOLOX-ROS/weights/onnx/yolox_tiny.onnx \
+ -p model_type:=onnxruntime \
+ -p use_gpu:=true
+```
diff --git a/yolox_ros_cpp/README.md b/yolox_ros_cpp/README.md
index 11a0133..3858c85 100644
--- a/yolox_ros_cpp/README.md
+++ b/yolox_ros_cpp/README.md
@@ -232,7 +232,7 @@ ros2 launch yolox_ros_cpp yolox_tflite.launch.py
- `class_labels_path`: ""
- `num_classes`: 80
- `model_version`: 0.1.1rc0
-- `onnxruntime_use_cuda`: true
+- `onnxruntime_use_gpu`: true
- `onnxruntime_use_parallel`: false
- `onnxruntime_device_id`: 0
- `onnxruntime_inter_op_num_threads`: 1
diff --git a/yolox_ros_cpp/docker/onnxruntime-mIgraphx/docker-compose.yaml b/yolox_ros_cpp/docker/onnxruntime-mIgraphx/docker-compose.yaml
new file mode 100644
index 0000000..7f3c272
--- /dev/null
+++ b/yolox_ros_cpp/docker/onnxruntime-mIgraphx/docker-compose.yaml
@@ -0,0 +1,22 @@
+version: '3.4'
+services:
+ yolox_ros_onnxruntime_migraphx:
+ container_name: yolox_onnxruntime_migraphx
+ build:
+ context: .
+ args:
+ - BASE_TAB=latest
+ network_mode: host
+ devices:
+ - "/dev/kfd:/dev/kfd"
+ - "/dev/dri:/dev/dri"
+ # - "/dev/video0:/dev/video0"
+
+ environment:
+ - DISPLAY=$DISPLAY
+ volumes:
+ - $HOME/ros2_ws:/root/ros2_ws
+ - /tmp/.X11-unix:/tmp/.X11-unix
+ working_dir: /root/ros2_ws
+ tty: true
+ command: bash
diff --git a/yolox_ros_cpp/docker/onnxruntime-mIgraphx/dockerfile b/yolox_ros_cpp/docker/onnxruntime-mIgraphx/dockerfile
new file mode 100644
index 0000000..e26a5cb
--- /dev/null
+++ b/yolox_ros_cpp/docker/onnxruntime-mIgraphx/dockerfile
@@ -0,0 +1,46 @@
+ARG BASE_TAG=latest
+FROM rocm/dev-ubuntu-24.04:${BASE_TAG}
+
+ENV TZ=Asia/Tokyo
+RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
+ENV DEBIAN_FRONTEND=noninteractive
+
+RUN apt update && apt install -y locales git cmake wget curl gnupg2 lsb-release python3-numpy python3-setuptools python3-wheel && \
+ locale-gen en_US en_US.UTF-8 && \
+ update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
+ENV LANG=en_US.UTF-8
+
+
+RUN apt update && apt install -y build-essential ca-certificates python3-dev \
+ migraphx migraphx-dev half && \
+ rm -rf /var/lib/apt/lists/*
+
+RUN git clone --recursive https://github.com/microsoft/onnxruntime /tmp/onnxruntime && \
+ cd /tmp/onnxruntime && \
+ ./build.sh --config Release --build_shared_lib --parallel \
+ --use_migraphx --migraphx_home /opt/rocm \
+ --update --build --skip_tests --allow_running_as_root && \
+ cd build/Linux/Release && \
+ cmake --install . --prefix /opt/onnxruntime-migraphx && \
+ echo /opt/onnxruntime-migraphx/lib > /etc/ld.so.conf.d/onnxruntime.conf && \
+ ldconfig && \
+ rm -rf /tmp/onnxruntime
+
+RUN curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg && \
+ echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/ros2.list > /dev/null && \
+ sed -i -e 's/ubuntu .* main/ubuntu noble main/g' /etc/apt/sources.list.d/ros2.list && \
+ apt update && \
+ apt install -y ros-dev-tools \
+ ros-jazzy-cv-bridge \
+ ros-jazzy-generate-parameter-library \
+ ros-jazzy-parameter-traits \
+ ros-jazzy-ros-base \
+ ros-jazzy-rqt-image-view \
+ ros-jazzy-usb-cam \
+ ros-jazzy-vision-msgs && \
+ apt -y clean && \
+ rm -rf /var/lib/apt/lists/*
+
+WORKDIR /workspace
+COPY ./ros_entrypoint.sh /ros_entrypoint.sh
+RUN echo "source /ros_entrypoint.sh" >> /root/.bashrc
diff --git a/yolox_ros_cpp/docker/onnxruntime-mIgraphx/ros_entrypoint.sh b/yolox_ros_cpp/docker/onnxruntime-mIgraphx/ros_entrypoint.sh
new file mode 100755
index 0000000..aa7d4f2
--- /dev/null
+++ b/yolox_ros_cpp/docker/onnxruntime-mIgraphx/ros_entrypoint.sh
@@ -0,0 +1,2 @@
+#!/bin/bash
+source /opt/ros/jazzy/setup.bash
diff --git a/yolox_ros_cpp/docker/onnxruntime/dockerfile b/yolox_ros_cpp/docker/onnxruntime/dockerfile
index 643e2fe..e8574ec 100644
--- a/yolox_ros_cpp/docker/onnxruntime/dockerfile
+++ b/yolox_ros_cpp/docker/onnxruntime/dockerfile
@@ -18,7 +18,7 @@ RUN git clone --depth 1 --recursive https://github.com/microsoft/onnxruntime -b
cd onnxruntime && \
./build.sh --cudnn_home /usr/lib/x86_64-linux-gnu/ \
--cuda_home /usr/local/cuda \
- --use_cuda \
+ --use_gpu \
--config RelWithDebInfo \
--build_shared_lib \
--allow_running_as_root \
diff --git a/yolox_ros_cpp/yolox_cpp/CMakeLists.txt b/yolox_ros_cpp/yolox_cpp/CMakeLists.txt
index db849f4..93d1ead 100644
--- a/yolox_ros_cpp/yolox_cpp/CMakeLists.txt
+++ b/yolox_ros_cpp/yolox_cpp/CMakeLists.txt
@@ -17,6 +17,8 @@ ament_auto_find_build_dependencies()
option(YOLOX_USE_OPENVINO "Use OpenVINO" OFF)
option(YOLOX_USE_TENSORRT "Use TensorRT" OFF)
option(YOLOX_USE_ONNXRUNTIME "Use ONNXRuntime" OFF)
+option(ONNXRUNTIME_CUDA "Use ONNXRuntime CUDA Execution Provider" OFF)
+option(ONNXRUNTIME_MIGRAPHX "Use ONNXRuntime MIGraphX Execution Provider" OFF)
option(YOLOX_USE_TFLITE "Use tflite" OFF)
option(JETSON "Use Jetson" OFF)
@@ -33,6 +35,8 @@ endif()
set(ENABLE_OPENVINO OFF)
set(ENABLE_TENSORRT OFF)
set(ENABLE_ONNXRUNTIME OFF)
+set(ENABLE_ONNXRUNTIME_CUDA OFF)
+set(ENABLE_ONNXRUNTIME_MIGRAPHX OFF)
set(ENABLE_TFLITE OFF)
if(YOLOX_USE_OPENVINO)
@@ -74,7 +78,18 @@ endif()
# onnxruntime
if(YOLOX_USE_ONNXRUNTIME)
find_library(ONNXRUNTIME NAMES onnxruntime)
+ if(ONNXRUNTIME_CUDA AND ONNXRUNTIME_MIGRAPHX)
+ message(FATAL_ERROR "ONNXRUNTIME_CUDA and ONNXRUNTIME_MIGRAPHX cannot both be ON")
+ endif()
set(ENABLE_ONNXRUNTIME ON)
+ if(ONNXRUNTIME_CUDA)
+ set(ENABLE_ONNXRUNTIME_CUDA ON)
+ set(TARGET_DEFINITIONS ${TARGET_DEFINITIONS} ONNXRUNTIME_CUDA)
+ endif()
+ if(ONNXRUNTIME_MIGRAPHX)
+ set(ENABLE_ONNXRUNTIME_MIGRAPHX ON)
+ set(TARGET_DEFINITIONS ${TARGET_DEFINITIONS} ONNXRUNTIME_MIGRAPHX)
+ endif()
set(TARGET_SRC ${TARGET_SRC} src/yolox_onnxruntime.cpp)
set(TARGET_LIBS ${TARGET_LIBS} onnxruntime)
endif()
@@ -88,6 +103,7 @@ ament_auto_add_library(yolox_cpp SHARED ${TARGET_SRC})
ament_target_dependencies(yolox_cpp ${TARGET_DPENDENCIES})
ament_export_dependencies(${TARGET_DPENDENCIES})
target_link_libraries(yolox_cpp ${TARGET_LIBS})
+target_compile_definitions(yolox_cpp PUBLIC ${TARGET_DEFINITIONS})
if (YOLOX_USE_TFLITE)
target_include_directories(yolox_cpp PUBLIC ${TFLITE_INCLUDES})
diff --git a/yolox_ros_cpp/yolox_cpp/include/yolox_cpp/config.h.in b/yolox_ros_cpp/yolox_cpp/include/yolox_cpp/config.h.in
index 72f4411..2253e68 100644
--- a/yolox_ros_cpp/yolox_cpp/include/yolox_cpp/config.h.in
+++ b/yolox_ros_cpp/yolox_cpp/include/yolox_cpp/config.h.in
@@ -4,6 +4,8 @@
#cmakedefine ENABLE_OPENVINO
#cmakedefine ENABLE_TENSORRT
#cmakedefine ENABLE_ONNXRUNTIME
+#cmakedefine ENABLE_ONNXRUNTIME_CUDA
+#cmakedefine ENABLE_ONNXRUNTIME_MIGRAPHX
#cmakedefine ENABLE_TFLITE
#endif // _YOLOX_CPP_CONFIG_H_
diff --git a/yolox_ros_cpp/yolox_cpp/include/yolox_cpp/yolox_onnxruntime.hpp b/yolox_ros_cpp/yolox_cpp/include/yolox_cpp/yolox_onnxruntime.hpp
index 413356a..7fee97b 100644
--- a/yolox_ros_cpp/yolox_cpp/include/yolox_cpp/yolox_onnxruntime.hpp
+++ b/yolox_ros_cpp/yolox_cpp/include/yolox_cpp/yolox_onnxruntime.hpp
@@ -1,12 +1,16 @@
#ifndef _YOLOX_CPP_YOLOX_ONNX_HPP
#define _YOLOX_CPP_YOLOX_ONNX_HPP
+#include
+#include
+#include
+#include
#include
#include
+#include
+#include
#include
#include
-#include
-#include
#include
@@ -18,7 +22,7 @@ namespace yolox_cpp{
public:
YoloXONNXRuntime(const file_name_t &path_to_model,
int intra_op_num_threads, int inter_op_num_threads=1,
- bool use_cuda=true, int device_id=0, bool use_parallel=false,
+ bool use_gpu=true, int device_id=0, bool use_parallel=false,
float nms_th=0.45, float conf_th=0.3, const std::string &model_version="0.1.1rc0",
int num_classes=80, bool p6=false);
std::vector