Skip to content

Commit 1a8c04f

Browse files
committed
adding vendor packages for onnxruntime and onnxruntime-gpu
1 parent f5db5e8 commit 1a8c04f

File tree

6 files changed

+282
-0
lines changed

6 files changed

+282
-0
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Copyright (c) 2025-present WATonomous. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
cmake_minimum_required(VERSION 3.8)
15+
project(onnxruntime_gpu_vendor VERSION 1.22.0)
16+
17+
find_package(ament_cmake REQUIRED)
18+
19+
set(ONNXRUNTIME_VERSION "${PROJECT_VERSION}")
20+
set(ONNXRUNTIME_URL
21+
"https://github.com/microsoft/onnxruntime/releases/download/v${ONNXRUNTIME_VERSION}/onnxruntime-linux-x64-gpu-${ONNXRUNTIME_VERSION}.tgz"
22+
)
23+
set(ONNXRUNTIME_DOWNLOAD_DIR "${CMAKE_CURRENT_BINARY_DIR}/onnxruntime-download")
24+
set(ONNXRUNTIME_EXTRACT_DIR "${CMAKE_CURRENT_BINARY_DIR}/onnxruntime-linux-x64-gpu-${ONNXRUNTIME_VERSION}")
25+
26+
# Download and extract ONNX Runtime GPU
27+
if(NOT EXISTS "${ONNXRUNTIME_EXTRACT_DIR}")
28+
message(STATUS "Downloading ONNX Runtime GPU ${ONNXRUNTIME_VERSION}...")
29+
file(DOWNLOAD
30+
${ONNXRUNTIME_URL}
31+
"${ONNXRUNTIME_DOWNLOAD_DIR}/onnxruntime-gpu.tgz"
32+
SHOW_PROGRESS
33+
STATUS DOWNLOAD_STATUS
34+
)
35+
36+
list(GET DOWNLOAD_STATUS 0 DOWNLOAD_RESULT)
37+
if(NOT DOWNLOAD_RESULT EQUAL 0)
38+
message(FATAL_ERROR "Failed to download ONNX Runtime GPU")
39+
endif()
40+
41+
message(STATUS "Extracting ONNX Runtime GPU...")
42+
execute_process(
43+
COMMAND ${CMAKE_COMMAND} -E tar xzf "${ONNXRUNTIME_DOWNLOAD_DIR}/onnxruntime-gpu.tgz"
44+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
45+
RESULT_VARIABLE EXTRACT_RESULT
46+
)
47+
48+
if(NOT EXTRACT_RESULT EQUAL 0)
49+
message(FATAL_ERROR "Failed to extract ONNX Runtime GPU")
50+
endif()
51+
endif()
52+
53+
# Install headers
54+
install(
55+
DIRECTORY "${ONNXRUNTIME_EXTRACT_DIR}/include/"
56+
DESTINATION include
57+
)
58+
59+
# Install libraries
60+
install(
61+
DIRECTORY "${ONNXRUNTIME_EXTRACT_DIR}/lib/"
62+
DESTINATION lib
63+
PATTERN "*.a" EXCLUDE
64+
)
65+
66+
# Create an interface library for users to link against
67+
add_library(onnxruntime_gpu_lib INTERFACE)
68+
target_include_directories(onnxruntime_gpu_lib INTERFACE
69+
$<BUILD_INTERFACE:${ONNXRUNTIME_EXTRACT_DIR}/include>
70+
$<INSTALL_INTERFACE:include>
71+
)
72+
target_link_libraries(onnxruntime_gpu_lib INTERFACE
73+
$<BUILD_INTERFACE:${ONNXRUNTIME_EXTRACT_DIR}/lib/libonnxruntime.so>
74+
$<BUILD_INTERFACE:${ONNXRUNTIME_EXTRACT_DIR}/lib/libonnxruntime_providers_cuda.so>
75+
$<BUILD_INTERFACE:${ONNXRUNTIME_EXTRACT_DIR}/lib/libonnxruntime_providers_shared.so>
76+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/lib/libonnxruntime.so>
77+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/lib/libonnxruntime_providers_cuda.so>
78+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/lib/libonnxruntime_providers_shared.so>
79+
)
80+
81+
# Export the target
82+
install(
83+
TARGETS onnxruntime_gpu_lib
84+
EXPORT ${PROJECT_NAME}
85+
LIBRARY DESTINATION lib
86+
ARCHIVE DESTINATION lib
87+
RUNTIME DESTINATION bin
88+
INCLUDES DESTINATION include
89+
)
90+
91+
ament_export_targets(${PROJECT_NAME} HAS_LIBRARY_TARGET)
92+
ament_export_dependencies()
93+
94+
ament_package()

onnxruntime_gpu_vendor/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# onnxruntime_gpu_vendor
2+
3+
ROS2 vendor package for ONNX Runtime (GPU/CUDA/TensorRT)
4+
5+
## Usage
6+
7+
### Package.xml
8+
9+
```xml
10+
<depend>onnxruntime_gpu_vendor</depend>
11+
```
12+
13+
### CMakeLists.txt
14+
15+
```cmake
16+
find_package(onnxruntime_gpu_vendor REQUIRED)
17+
18+
add_executable(my_node src/my_node.cpp)
19+
target_link_libraries(my_node
20+
onnxruntime_gpu_vendor::onnxruntime_gpu_lib
21+
)
22+
```
23+
24+
### C++ Code
25+
26+
```cpp
27+
#include <onnxruntime_cxx_api.h>
28+
29+
Ort::Env env(ORT_LOGGING_LEVEL_WARNING, "my_app");
30+
Ort::SessionOptions session_options;
31+
32+
// Optional: Enable CUDA
33+
OrtCUDAProviderOptions cuda_options;
34+
cuda_options.device_id = 0;
35+
session_options.AppendExecutionProvider_CUDA(cuda_options);
36+
```

onnxruntime_gpu_vendor/package.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0"?>
2+
<package format="3">
3+
<name>onnxruntime_gpu_vendor</name>
4+
<version>1.22.0</version>
5+
<description>Vendor package for ONNX Runtime (GPU/CUDA)</description>
6+
<maintainer email="hello@watonomous.ca">WATonomous</maintainer>
7+
<license>MIT</license> <!-- ORT License -->
8+
<license>Apache 2.0</license>
9+
10+
<buildtool_depend>ament_cmake</buildtool_depend>
11+
12+
<export>
13+
<build_type>ament_cmake</build_type>
14+
</export>
15+
</package>

onnxruntime_vendor/CMakeLists.txt

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Copyright (c) 2025-present WATonomous. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
cmake_minimum_required(VERSION 3.8)
15+
project(onnxruntime_vendor VERSION 1.22.0)
16+
17+
find_package(ament_cmake REQUIRED)
18+
19+
set(ONNXRUNTIME_VERSION "${PROJECT_VERSION}")
20+
set(ONNXRUNTIME_URL
21+
"https://github.com/microsoft/onnxruntime/releases/download/v${ONNXRUNTIME_VERSION}/onnxruntime-linux-x64-${ONNXRUNTIME_VERSION}.tgz"
22+
)
23+
set(ONNXRUNTIME_DOWNLOAD_DIR "${CMAKE_CURRENT_BINARY_DIR}/onnxruntime-download")
24+
set(ONNXRUNTIME_EXTRACT_DIR "${CMAKE_CURRENT_BINARY_DIR}/onnxruntime-linux-x64-${ONNXRUNTIME_VERSION}")
25+
26+
# Download and extract ONNX Runtime
27+
if(NOT EXISTS "${ONNXRUNTIME_EXTRACT_DIR}")
28+
message(STATUS "Downloading ONNX Runtime ${ONNXRUNTIME_VERSION}...")
29+
file(DOWNLOAD
30+
${ONNXRUNTIME_URL}
31+
"${ONNXRUNTIME_DOWNLOAD_DIR}/onnxruntime.tgz"
32+
SHOW_PROGRESS
33+
STATUS DOWNLOAD_STATUS
34+
)
35+
36+
list(GET DOWNLOAD_STATUS 0 DOWNLOAD_RESULT)
37+
if(NOT DOWNLOAD_RESULT EQUAL 0)
38+
message(FATAL_ERROR "Failed to download ONNX Runtime")
39+
endif()
40+
41+
message(STATUS "Extracting ONNX Runtime...")
42+
execute_process(
43+
COMMAND ${CMAKE_COMMAND} -E tar xzf "${ONNXRUNTIME_DOWNLOAD_DIR}/onnxruntime.tgz"
44+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
45+
RESULT_VARIABLE EXTRACT_RESULT
46+
)
47+
48+
if(NOT EXTRACT_RESULT EQUAL 0)
49+
message(FATAL_ERROR "Failed to extract ONNX Runtime")
50+
endif()
51+
endif()
52+
53+
# Install headers
54+
install(
55+
DIRECTORY "${ONNXRUNTIME_EXTRACT_DIR}/include/"
56+
DESTINATION include
57+
)
58+
59+
# Install libraries
60+
install(
61+
DIRECTORY "${ONNXRUNTIME_EXTRACT_DIR}/lib/"
62+
DESTINATION lib
63+
PATTERN "*.a" EXCLUDE
64+
)
65+
66+
# Create an interface library for users to link against
67+
add_library(onnxruntime_lib INTERFACE)
68+
target_include_directories(onnxruntime_lib INTERFACE
69+
$<BUILD_INTERFACE:${ONNXRUNTIME_EXTRACT_DIR}/include>
70+
$<INSTALL_INTERFACE:include>
71+
)
72+
target_link_libraries(onnxruntime_lib INTERFACE
73+
$<BUILD_INTERFACE:${ONNXRUNTIME_EXTRACT_DIR}/lib/libonnxruntime.so>
74+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/lib/libonnxruntime.so>
75+
)
76+
77+
# Export the target
78+
install(
79+
TARGETS onnxruntime_lib
80+
EXPORT ${PROJECT_NAME}
81+
LIBRARY DESTINATION lib
82+
ARCHIVE DESTINATION lib
83+
RUNTIME DESTINATION bin
84+
INCLUDES DESTINATION include
85+
)
86+
87+
ament_export_targets(${PROJECT_NAME} HAS_LIBRARY_TARGET)
88+
ament_export_dependencies()
89+
90+
ament_package()

onnxruntime_vendor/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# onnxruntime_vendor
2+
3+
ROS2 vendor package for ONNX Runtime (CPU)
4+
5+
## Usage
6+
7+
### Package.xml
8+
9+
```xml
10+
<depend>onnxruntime_vendor</depend>
11+
```
12+
13+
### CMakeLists.txt
14+
15+
```cmake
16+
find_package(onnxruntime_vendor REQUIRED)
17+
18+
add_executable(my_node src/my_node.cpp)
19+
target_link_libraries(my_node
20+
onnxruntime_vendor::onnxruntime_lib
21+
)
22+
```
23+
24+
### C++ Code
25+
26+
```cpp
27+
#include <onnxruntime_cxx_api.h>
28+
29+
Ort::Env env(ORT_LOGGING_LEVEL_WARNING, "my_app");
30+
Ort::SessionOptions session_options;
31+
// Load model, run inference...
32+
```

onnxruntime_vendor/package.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0"?>
2+
<package format="3">
3+
<name>onnxruntime_vendor</name>
4+
<version>1.22.0</version>
5+
<description>Vendor package for ONNX Runtime (CPU)</description>
6+
<maintainer email="hello@watonomous.ca">WATonomous</maintainer>
7+
<license>MIT</license> <!-- ORT License -->
8+
<license>Apache 2.0</license>
9+
10+
<buildtool_depend>ament_cmake</buildtool_depend>
11+
12+
<export>
13+
<build_type>ament_cmake</build_type>
14+
</export>
15+
</package>

0 commit comments

Comments
 (0)