Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,3 @@ USER $USERNAME

# Source ROS in user's bashrc
RUN echo "source /opt/ros/${ROS_DISTRO}/setup.bash" >> /home/$USERNAME/.bashrc

94 changes: 94 additions & 0 deletions onnxruntime_gpu_vendor/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Copyright (c) 2025-present WATonomous. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
cmake_minimum_required(VERSION 3.8)
project(onnxruntime_gpu_vendor VERSION 1.22.0)

find_package(ament_cmake REQUIRED)

set(ONNXRUNTIME_VERSION "${PROJECT_VERSION}")
set(ONNXRUNTIME_URL
"https://github.com/microsoft/onnxruntime/releases/download/v${ONNXRUNTIME_VERSION}/onnxruntime-linux-x64-gpu-${ONNXRUNTIME_VERSION}.tgz"
)
set(ONNXRUNTIME_DOWNLOAD_DIR "${CMAKE_CURRENT_BINARY_DIR}/onnxruntime-download")
set(ONNXRUNTIME_EXTRACT_DIR "${CMAKE_CURRENT_BINARY_DIR}/onnxruntime-linux-x64-gpu-${ONNXRUNTIME_VERSION}")

# Download and extract ONNX Runtime GPU
if(NOT EXISTS "${ONNXRUNTIME_EXTRACT_DIR}")
message(STATUS "Downloading ONNX Runtime GPU ${ONNXRUNTIME_VERSION}...")
file(DOWNLOAD
${ONNXRUNTIME_URL}
"${ONNXRUNTIME_DOWNLOAD_DIR}/onnxruntime-gpu.tgz"
SHOW_PROGRESS
STATUS DOWNLOAD_STATUS
)

list(GET DOWNLOAD_STATUS 0 DOWNLOAD_RESULT)
if(NOT DOWNLOAD_RESULT EQUAL 0)
message(FATAL_ERROR "Failed to download ONNX Runtime GPU")
endif()

message(STATUS "Extracting ONNX Runtime GPU...")
execute_process(
COMMAND ${CMAKE_COMMAND} -E tar xzf "${ONNXRUNTIME_DOWNLOAD_DIR}/onnxruntime-gpu.tgz"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
RESULT_VARIABLE EXTRACT_RESULT
)

if(NOT EXTRACT_RESULT EQUAL 0)
message(FATAL_ERROR "Failed to extract ONNX Runtime GPU")
endif()
endif()

# Install headers
install(
DIRECTORY "${ONNXRUNTIME_EXTRACT_DIR}/include/"
DESTINATION include
)

# Install libraries
install(
DIRECTORY "${ONNXRUNTIME_EXTRACT_DIR}/lib/"
DESTINATION lib
PATTERN "*.a" EXCLUDE
)

# Create an interface library for users to link against
add_library(onnxruntime_gpu_lib INTERFACE)
target_include_directories(onnxruntime_gpu_lib INTERFACE
$<BUILD_INTERFACE:${ONNXRUNTIME_EXTRACT_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(onnxruntime_gpu_lib INTERFACE
$<BUILD_INTERFACE:${ONNXRUNTIME_EXTRACT_DIR}/lib/libonnxruntime.so>
$<BUILD_INTERFACE:${ONNXRUNTIME_EXTRACT_DIR}/lib/libonnxruntime_providers_cuda.so>
$<BUILD_INTERFACE:${ONNXRUNTIME_EXTRACT_DIR}/lib/libonnxruntime_providers_shared.so>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/lib/libonnxruntime.so>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/lib/libonnxruntime_providers_cuda.so>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/lib/libonnxruntime_providers_shared.so>
)

# Export the target
install(
TARGETS onnxruntime_gpu_lib
EXPORT ${PROJECT_NAME}
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
INCLUDES DESTINATION include
)

ament_export_targets(${PROJECT_NAME} HAS_LIBRARY_TARGET)
ament_export_dependencies()

ament_package()
36 changes: 36 additions & 0 deletions onnxruntime_gpu_vendor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# onnxruntime_gpu_vendor

ROS2 vendor package for ONNX Runtime (GPU/CUDA/TensorRT)

## Usage

### Package.xml

```xml
<depend>onnxruntime_gpu_vendor</depend>
```

### CMakeLists.txt

```cmake
find_package(onnxruntime_gpu_vendor REQUIRED)

add_executable(my_node src/my_node.cpp)
target_link_libraries(my_node
onnxruntime_gpu_vendor::onnxruntime_gpu_lib
)
```

### C++ Code

```cpp
#include <onnxruntime_cxx_api.h>

Ort::Env env(ORT_LOGGING_LEVEL_WARNING, "my_app");
Ort::SessionOptions session_options;

// Optional: Enable CUDA
OrtCUDAProviderOptions cuda_options;
cuda_options.device_id = 0;
session_options.AppendExecutionProvider_CUDA(cuda_options);
```
15 changes: 15 additions & 0 deletions onnxruntime_gpu_vendor/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<package format="3">
<name>onnxruntime_gpu_vendor</name>
<version>1.22.0</version>
<description>Vendor package for ONNX Runtime (GPU/CUDA)</description>
<maintainer email="hello@watonomous.ca">WATonomous</maintainer>
<license>MIT</license> <!-- ORT License -->
<license>Apache 2.0</license>

<buildtool_depend>ament_cmake</buildtool_depend>

<export>
<build_type>ament_cmake</build_type>
</export>
</package>
90 changes: 90 additions & 0 deletions onnxruntime_vendor/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Copyright (c) 2025-present WATonomous. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
cmake_minimum_required(VERSION 3.8)
project(onnxruntime_vendor VERSION 1.22.0)

find_package(ament_cmake REQUIRED)

set(ONNXRUNTIME_VERSION "${PROJECT_VERSION}")
set(ONNXRUNTIME_URL
"https://github.com/microsoft/onnxruntime/releases/download/v${ONNXRUNTIME_VERSION}/onnxruntime-linux-x64-${ONNXRUNTIME_VERSION}.tgz"
)
set(ONNXRUNTIME_DOWNLOAD_DIR "${CMAKE_CURRENT_BINARY_DIR}/onnxruntime-download")
set(ONNXRUNTIME_EXTRACT_DIR "${CMAKE_CURRENT_BINARY_DIR}/onnxruntime-linux-x64-${ONNXRUNTIME_VERSION}")

# Download and extract ONNX Runtime
if(NOT EXISTS "${ONNXRUNTIME_EXTRACT_DIR}")
message(STATUS "Downloading ONNX Runtime ${ONNXRUNTIME_VERSION}...")
file(DOWNLOAD
${ONNXRUNTIME_URL}
"${ONNXRUNTIME_DOWNLOAD_DIR}/onnxruntime.tgz"
SHOW_PROGRESS
STATUS DOWNLOAD_STATUS
)

list(GET DOWNLOAD_STATUS 0 DOWNLOAD_RESULT)
if(NOT DOWNLOAD_RESULT EQUAL 0)
message(FATAL_ERROR "Failed to download ONNX Runtime")
endif()

message(STATUS "Extracting ONNX Runtime...")
execute_process(
COMMAND ${CMAKE_COMMAND} -E tar xzf "${ONNXRUNTIME_DOWNLOAD_DIR}/onnxruntime.tgz"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
RESULT_VARIABLE EXTRACT_RESULT
)

if(NOT EXTRACT_RESULT EQUAL 0)
message(FATAL_ERROR "Failed to extract ONNX Runtime")
endif()
endif()

# Install headers
install(
DIRECTORY "${ONNXRUNTIME_EXTRACT_DIR}/include/"
DESTINATION include
)

# Install libraries
install(
DIRECTORY "${ONNXRUNTIME_EXTRACT_DIR}/lib/"
DESTINATION lib
PATTERN "*.a" EXCLUDE
)

# Create an interface library for users to link against
add_library(onnxruntime_lib INTERFACE)
target_include_directories(onnxruntime_lib INTERFACE
$<BUILD_INTERFACE:${ONNXRUNTIME_EXTRACT_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(onnxruntime_lib INTERFACE
$<BUILD_INTERFACE:${ONNXRUNTIME_EXTRACT_DIR}/lib/libonnxruntime.so>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/lib/libonnxruntime.so>
)

# Export the target
install(
TARGETS onnxruntime_lib
EXPORT ${PROJECT_NAME}
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
INCLUDES DESTINATION include
)

ament_export_targets(${PROJECT_NAME} HAS_LIBRARY_TARGET)
ament_export_dependencies()

ament_package()
32 changes: 32 additions & 0 deletions onnxruntime_vendor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# onnxruntime_vendor

ROS2 vendor package for ONNX Runtime (CPU)

## Usage

### Package.xml

```xml
<depend>onnxruntime_vendor</depend>
```

### CMakeLists.txt

```cmake
find_package(onnxruntime_vendor REQUIRED)

add_executable(my_node src/my_node.cpp)
target_link_libraries(my_node
onnxruntime_vendor::onnxruntime_lib
)
```

### C++ Code

```cpp
#include <onnxruntime_cxx_api.h>

Ort::Env env(ORT_LOGGING_LEVEL_WARNING, "my_app");
Ort::SessionOptions session_options;
// Load model, run inference...
```
15 changes: 15 additions & 0 deletions onnxruntime_vendor/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<package format="3">
<name>onnxruntime_vendor</name>
<version>1.22.0</version>
<description>Vendor package for ONNX Runtime (CPU)</description>
<maintainer email="hello@watonomous.ca">WATonomous</maintainer>
<license>MIT</license> <!-- ORT License -->
<license>Apache 2.0</license>

<buildtool_depend>ament_cmake</buildtool_depend>

<export>
<build_type>ament_cmake</build_type>
</export>
</package>