From e7725ee33b291fdc4ed06b4676060ff4f14a1d5b Mon Sep 17 00:00:00 2001 From: Kaito Udagawa Date: Thu, 11 Jan 2024 18:45:23 +0900 Subject: [PATCH 1/2] Add DISABLE_ONNXRUNTIME_GPU flag --- cmake/FetchOnnxruntime.cmake | 7 +++++++ src/ort-utils/ort-session-utils.cpp | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/cmake/FetchOnnxruntime.cmake b/cmake/FetchOnnxruntime.cmake index 78d27662..eefb17cb 100644 --- a/cmake/FetchOnnxruntime.cmake +++ b/cmake/FetchOnnxruntime.cmake @@ -8,6 +8,10 @@ set(CUSTOM_ONNXRUNTIME_HASH "" CACHE STRING "Hash of a downloaded ONNX Runtime tarball") +set(DISABLE_ONNXRUNTIME_GPU + OFF + CACHE STRING "Disables GPU support of ONNX Runtime (Only valid on Linux)") + set(Onnxruntime_VERSION "1.16.3") if(CUSTOM_ONNXRUNTIME_URL STREQUAL "") @@ -106,6 +110,9 @@ else() "${onnxruntime_SOURCE_DIR}/lib/libonnxruntime_providers_cuda.so" "${onnxruntime_SOURCE_DIR}/lib/libonnxruntime_providers_tensorrt.so") endif() + if(DISABLE_ONNXRUNTIME_GPU) + target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE DISABLE_ONNXRUNTIME_GPU) + endif() target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE ${Onnxruntime_LINK_LIBS}) target_include_directories(${CMAKE_PROJECT_NAME} SYSTEM PUBLIC "${onnxruntime_SOURCE_DIR}/include") install(FILES ${Onnxruntime_INSTALL_LIBS} DESTINATION "${CMAKE_INSTALL_LIBDIR}/obs-plugins/${CMAKE_PROJECT_NAME}") diff --git a/src/ort-utils/ort-session-utils.cpp b/src/ort-utils/ort-session-utils.cpp index 133f5a88..ffc93382 100644 --- a/src/ort-utils/ort-session-utils.cpp +++ b/src/ort-utils/ort-session-utils.cpp @@ -5,7 +5,7 @@ #include #endif -#if defined(__linux__) && defined(__x86_64__) +#if defined(__linux__) && defined(__x86_64__) && !defined(DISABLE_ONNXRUNTIME_GPU) #include #endif @@ -62,7 +62,7 @@ int createOrtSession(filter_data *tf) #endif try { -#if defined(__linux__) && defined(__x86_64__) +#if defined(__linux__) && defined(__x86_64__) && !defined(DISABLE_ONNXRUNTIME_GPU) if (tf->useGPU == USEGPU_TENSORRT) { Ort::ThrowOnError( OrtSessionOptionsAppendExecutionProvider_Tensorrt( From e5f04614c65417fc99dd5b8ad4ad23c3c8cc8631 Mon Sep 17 00:00:00 2001 From: Kaito Udagawa Date: Thu, 11 Jan 2024 18:45:58 +0900 Subject: [PATCH 2/2] Update ort-session-utils.cpp --- src/ort-utils/ort-session-utils.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ort-utils/ort-session-utils.cpp b/src/ort-utils/ort-session-utils.cpp index ffc93382..fd83aa39 100644 --- a/src/ort-utils/ort-session-utils.cpp +++ b/src/ort-utils/ort-session-utils.cpp @@ -5,7 +5,8 @@ #include #endif -#if defined(__linux__) && defined(__x86_64__) && !defined(DISABLE_ONNXRUNTIME_GPU) +#if defined(__linux__) && defined(__x86_64__) && \ + !defined(DISABLE_ONNXRUNTIME_GPU) #include #endif @@ -62,7 +63,8 @@ int createOrtSession(filter_data *tf) #endif try { -#if defined(__linux__) && defined(__x86_64__) && !defined(DISABLE_ONNXRUNTIME_GPU) +#if defined(__linux__) && defined(__x86_64__) && \ + !defined(DISABLE_ONNXRUNTIME_GPU) if (tf->useGPU == USEGPU_TENSORRT) { Ort::ThrowOnError( OrtSessionOptionsAppendExecutionProvider_Tensorrt(