From 7c5443822e1f6eff2054706eaa1c8723488a9718 Mon Sep 17 00:00:00 2001 From: Florian de Gaulejac Date: Fri, 26 Jan 2024 11:43:51 +0100 Subject: [PATCH 01/16] Add with_cuda option --- recipes/onnxruntime/all/conandata.yml | 12 ++++++++++++ recipes/onnxruntime/all/conanfile.py | 14 ++++++++++++-- .../all/patches/1.14.1-0006-cuda-gsl.patch | 13 +++++++++++++ .../all/patches/1.15.1-0002-cuda-gsl.patch | 13 +++++++++++++ .../all/patches/1.16.0-0002-cuda-gsl.patch | 13 +++++++++++++ .../all/patches/1.16.1-0002-cuda-gsl.patch | 13 +++++++++++++ 6 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 recipes/onnxruntime/all/patches/1.14.1-0006-cuda-gsl.patch create mode 100644 recipes/onnxruntime/all/patches/1.15.1-0002-cuda-gsl.patch create mode 100644 recipes/onnxruntime/all/patches/1.16.0-0002-cuda-gsl.patch create mode 100644 recipes/onnxruntime/all/patches/1.16.1-0002-cuda-gsl.patch diff --git a/recipes/onnxruntime/all/conandata.yml b/recipes/onnxruntime/all/conandata.yml index b051b06768621..8340287a5ee7d 100644 --- a/recipes/onnxruntime/all/conandata.yml +++ b/recipes/onnxruntime/all/conandata.yml @@ -39,6 +39,9 @@ patches: - patch_file: "patches/1.14.1-0004-abseil-no-string-view.patch" patch_description: "allow to build with abseil built without c++17 support" patch_type: "portability" + - patch_file: "patches/1.16.1-0002-cuda-gsl.patch" + patch_description: "CMake: fix GSL and cuda" + patch_type: "conan" "1.16.0": - patch_file: "patches/1.16.0-0001-cmake-dependencies.patch" patch_description: "CMake: ensure conan dependencies are used" @@ -46,6 +49,9 @@ patches: - patch_file: "patches/1.14.1-0004-abseil-no-string-view.patch" patch_description: "allow to build with abseil built without c++17 support" patch_type: "portability" + - patch_file: "patches/1.16.0-0002-cuda-gsl.patch" + patch_description: "CMake: fix GSL and cuda" + patch_type: "conan" "1.15.1": - patch_file: "patches/1.15.1-0001-cmake-dependencies.patch" patch_description: "CMake: ensure conan dependencies are used" @@ -53,6 +59,9 @@ patches: - patch_file: "patches/1.14.1-0004-abseil-no-string-view.patch" patch_description: "allow to build with abseil built without c++17 support" patch_type: "portability" + - patch_file: "patches/1.15.1-0002-cuda-gsl.patch" + patch_description: "CMake: fix GSL and cuda" + patch_type: "conan" "1.14.1": - patch_file: "patches/1.14.1-0001-cmake-dependencies.patch" patch_description: "CMake: ensure conan dependencies are used (upstreamed future versions)" @@ -72,3 +81,6 @@ patches: patch_description: "Ensures the forward compatibility with the newest versions of re2 library." patch_type: "portability" patch_source: "/~https://github.com/microsoft/onnxruntime/commit/126e7bf15fa4af8621814b82a3f7bd0d786f0239.patch" + - patch_file: "patches/1.14.1-0006-cuda-gsl.patch" + patch_description: "CMake: fix GSL and cuda" + patch_type: "conan" diff --git a/recipes/onnxruntime/all/conanfile.py b/recipes/onnxruntime/all/conanfile.py index b91cf5d0a83f9..9ac6b35896c0a 100644 --- a/recipes/onnxruntime/all/conanfile.py +++ b/recipes/onnxruntime/all/conanfile.py @@ -2,7 +2,7 @@ from conan.errors import ConanInvalidConfiguration from conan.tools.apple import is_apple_os from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout -from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rmdir +from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rmdir, rm from conan.tools.build import check_min_cppstd from conan.tools.scm import Version from conan.tools.env import VirtualBuildEnv @@ -27,11 +27,13 @@ class OnnxRuntimeConan(ConanFile): "shared": [True, False], "fPIC": [True, False], "with_xnnpack": [True, False], + "with_cuda": [True, False], } default_options = { "shared": False, "fPIC": True, "with_xnnpack": False, + "with_cuda": False, } short_paths = True @@ -135,6 +137,7 @@ def generate(self): tc.variables["onnxruntime_USE_FULL_PROTOBUF"] = not self.dependencies["protobuf"].options.lite tc.variables["onnxruntime_USE_XNNPACK"] = self.options.with_xnnpack + tc.variables["onnxruntime_USE_CUDA"] = self.options.with_cuda tc.variables["onnxruntime_BUILD_UNIT_TESTS"] = False tc.variables["onnxruntime_RUN_ONNX_TESTS"] = False tc.variables["onnxruntime_GENERATE_TEST_REPORTS"] = False @@ -236,7 +239,14 @@ def package(self): copy(self, pattern="LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder) cmake = CMake(self) cmake.install() - pkg_config_dir = os.path.join(self.package_folder, "lib", "pkgconfig") + + # move the shared providers dll in the bin dir + lib_dir = os.path.join(self.package_folder, "lib") + bin_dir = os.path.join(self.package_folder, "bin") + copy(self, "*.dll", src=lib_dir, dst=bin_dir) + rm(self, "*.dll", lib_dir) + + pkg_config_dir = os.path.join(lib_dir, "pkgconfig") rmdir(self, pkg_config_dir) def package_info(self): diff --git a/recipes/onnxruntime/all/patches/1.14.1-0006-cuda-gsl.patch b/recipes/onnxruntime/all/patches/1.14.1-0006-cuda-gsl.patch new file mode 100644 index 0000000000000..de12d90d18497 --- /dev/null +++ b/recipes/onnxruntime/all/patches/1.14.1-0006-cuda-gsl.patch @@ -0,0 +1,13 @@ +diff --git a/cmake/external/onnxruntime_external_deps.cmake b/cmake/external/onnxruntime_external_deps.cmake +index 0c41945778..9bb5ffc63b 100644 +--- a/cmake/external/onnxruntime_external_deps.cmake ++++ b/cmake/external/onnxruntime_external_deps.cmake +@@ -250,7 +250,7 @@ if(onnxruntime_USE_CUDA) + GSL + URL ${DEP_URL_microsoft_gsl} + URL_HASH SHA1=${DEP_SHA1_microsoft_gsl} +- PATCH_COMMAND ${Patch_EXECUTABLE} --binary --ignore-whitespace -p1 < ${PROJECT_SOURCE_DIR}/patches/gsl/1064.patch ++ FIND_PACKAGE_ARGS 4.0 NAMES Microsoft.GSL + ) + else() + FetchContent_Declare( diff --git a/recipes/onnxruntime/all/patches/1.15.1-0002-cuda-gsl.patch b/recipes/onnxruntime/all/patches/1.15.1-0002-cuda-gsl.patch new file mode 100644 index 0000000000000..f8e107029bd12 --- /dev/null +++ b/recipes/onnxruntime/all/patches/1.15.1-0002-cuda-gsl.patch @@ -0,0 +1,13 @@ +diff --git a/cmake/external/onnxruntime_external_deps.cmake b/cmake/external/onnxruntime_external_deps.cmake +index 9effd1a2db..db30f7a0d4 100644 +--- a/cmake/external/onnxruntime_external_deps.cmake ++++ b/cmake/external/onnxruntime_external_deps.cmake +@@ -287,7 +287,7 @@ if(onnxruntime_USE_CUDA) + GSL + URL ${DEP_URL_microsoft_gsl} + URL_HASH SHA1=${DEP_SHA1_microsoft_gsl} +- PATCH_COMMAND ${Patch_EXECUTABLE} --binary --ignore-whitespace -p1 < ${PROJECT_SOURCE_DIR}/patches/gsl/1064.patch ++ FIND_PACKAGE_ARGS 4.0 NAMES Microsoft.GSL + ) + else() + FetchContent_Declare( diff --git a/recipes/onnxruntime/all/patches/1.16.0-0002-cuda-gsl.patch b/recipes/onnxruntime/all/patches/1.16.0-0002-cuda-gsl.patch new file mode 100644 index 0000000000000..d66ee9bb957f9 --- /dev/null +++ b/recipes/onnxruntime/all/patches/1.16.0-0002-cuda-gsl.patch @@ -0,0 +1,13 @@ +diff --git a/cmake/external/onnxruntime_external_deps.cmake b/cmake/external/onnxruntime_external_deps.cmake +index 8e412c7847..efd599e5b3 100644 +--- a/cmake/external/onnxruntime_external_deps.cmake ++++ b/cmake/external/onnxruntime_external_deps.cmake +@@ -301,7 +301,7 @@ if(onnxruntime_USE_CUDA) + GSL + URL ${DEP_URL_microsoft_gsl} + URL_HASH SHA1=${DEP_SHA1_microsoft_gsl} +- PATCH_COMMAND ${Patch_EXECUTABLE} --binary --ignore-whitespace -p1 < ${PROJECT_SOURCE_DIR}/patches/gsl/1064.patch ++ FIND_PACKAGE_ARGS 4.0 NAMES Microsoft.GSL + ) + else() + FetchContent_Declare( diff --git a/recipes/onnxruntime/all/patches/1.16.1-0002-cuda-gsl.patch b/recipes/onnxruntime/all/patches/1.16.1-0002-cuda-gsl.patch new file mode 100644 index 0000000000000..103e16e300545 --- /dev/null +++ b/recipes/onnxruntime/all/patches/1.16.1-0002-cuda-gsl.patch @@ -0,0 +1,13 @@ +diff --git a/cmake/external/onnxruntime_external_deps.cmake b/cmake/external/onnxruntime_external_deps.cmake +index 0e2482d7de..4210e0bc5c 100644 +--- a/cmake/external/onnxruntime_external_deps.cmake ++++ b/cmake/external/onnxruntime_external_deps.cmake +@@ -301,7 +301,7 @@ if(onnxruntime_USE_CUDA) + GSL + URL ${DEP_URL_microsoft_gsl} + URL_HASH SHA1=${DEP_SHA1_microsoft_gsl} +- PATCH_COMMAND ${Patch_EXECUTABLE} --binary --ignore-whitespace -p1 < ${PROJECT_SOURCE_DIR}/patches/gsl/1064.patch ++ FIND_PACKAGE_ARGS 4.0 NAMES Microsoft.GSL + ) + else() + FetchContent_Declare( From 2ebf89dd2909267c7afb93124a39309770651050 Mon Sep 17 00:00:00 2001 From: Florian de Gaulejac Date: Fri, 26 Jan 2024 14:31:07 +0100 Subject: [PATCH 02/16] Require static registration from onnx disabled --- recipes/onnxruntime/all/conanfile.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/recipes/onnxruntime/all/conanfile.py b/recipes/onnxruntime/all/conanfile.py index 9ac6b35896c0a..5c235736ac510 100644 --- a/recipes/onnxruntime/all/conanfile.py +++ b/recipes/onnxruntime/all/conanfile.py @@ -110,6 +110,10 @@ def validate(self): raise ConanInvalidConfiguration( f"{self.ref} requires minimum compiler version {minimum_version}." ) + if not self.dependencies["onnx"].options.disable_static_registration: + raise ConanInvalidConfiguration( + f"{self.ref} requires onnx compiled with `-o onnx:disable_static_registration=True`." + ) def validate_build(self): if self.version >= Version("1.15.0") and self.options.shared and sys.version_info[:2] < (3, 8): From f54fe204c4e2ff3f5c2d19d516b4528ce5e255eb Mon Sep 17 00:00:00 2001 From: Florian de Gaulejac Date: Fri, 26 Jan 2024 11:44:03 +0100 Subject: [PATCH 03/16] Add some transitive headers --- recipes/onnxruntime/all/conanfile.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/recipes/onnxruntime/all/conanfile.py b/recipes/onnxruntime/all/conanfile.py index 5c235736ac510..a86dc971ed3f7 100644 --- a/recipes/onnxruntime/all/conanfile.py +++ b/recipes/onnxruntime/all/conanfile.py @@ -87,13 +87,13 @@ def requirements(self): self.requires("protobuf/3.21.12") self.requires("date/3.0.1") self.requires("re2/20230901") - self.requires(f"onnx/{self._onnx_version}") + self.requires(f"onnx/{self._onnx_version}", transitive_headers=True) self.requires("flatbuffers/1.12.0") - self.requires("boost/1.83.0", headers=True, libs=False, run=False) # for mp11, header only, no need for libraries to link/run + self.requires("boost/1.83.0", headers=True, libs=False, run=False, transitive_headers=True) # for mp11, header only, no need for libraries to link/run self.requires("safeint/3.0.28") self.requires("nlohmann_json/3.11.3") self.requires("eigen/3.4.0") - self.requires("ms-gsl/4.0.0") + self.requires("ms-gsl/4.0.0", transitive_headers=True) self.requires("cpuinfo/cci.20220618") if self.settings.os != "Windows": self.requires("nsync/1.26.0") From 08f4f49f887d19e5a5d03a31b5b0d9071f2ce2aa Mon Sep 17 00:00:00 2001 From: Florian de Gaulejac Date: Fri, 26 Jan 2024 11:45:01 +0100 Subject: [PATCH 04/16] Test CUDA in the test_package --- .../onnxruntime/all/test_package/CMakeLists.txt | 3 +++ .../onnxruntime/all/test_package/conanfile.py | 14 ++++++++++++-- .../all/test_package/test_package.cpp | 16 +++++++++++++++- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/recipes/onnxruntime/all/test_package/CMakeLists.txt b/recipes/onnxruntime/all/test_package/CMakeLists.txt index b5d8ccbfcd52c..483ebf5ead1ee 100644 --- a/recipes/onnxruntime/all/test_package/CMakeLists.txt +++ b/recipes/onnxruntime/all/test_package/CMakeLists.txt @@ -5,5 +5,8 @@ project(test_package CXX) find_package(onnxruntime REQUIRED CONFIG) add_executable(${PROJECT_NAME} test_package.cpp) +if(WITH_CUDA) + target_compile_definitions(${PROJECT_NAME} PRIVATE WITH_CUDA) +endif() target_link_libraries(${PROJECT_NAME} PRIVATE onnxruntime::onnxruntime) target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17) diff --git a/recipes/onnxruntime/all/test_package/conanfile.py b/recipes/onnxruntime/all/test_package/conanfile.py index 18016812d8c7e..7706c2ea4e39b 100644 --- a/recipes/onnxruntime/all/test_package/conanfile.py +++ b/recipes/onnxruntime/all/test_package/conanfile.py @@ -1,13 +1,14 @@ from conan import ConanFile from conan.tools.build import can_run -from conan.tools.cmake import cmake_layout, CMake +from conan.tools.cmake import cmake_layout, CMake, CMakeToolchain +from conan.tools.files import copy import os # It will become the standard on Conan 2.x class TestPackageConan(ConanFile): settings = "os", "arch", "compiler", "build_type" - generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv" + generators = "CMakeDeps", "VirtualRunEnv" test_type = "explicit" def requirements(self): @@ -15,6 +16,15 @@ def requirements(self): def layout(self): cmake_layout(self, src_folder=".") + + def generate(self): + tc = CMakeToolchain(self) + tc.cache_variables["WITH_CUDA"] = self.dependencies["onnxruntime"].options.with_cuda + tc.generate() + + # on windows the system dll C:\WINDOWS\system32\onnxruntime.dll may be loaded instead even if the conan lib is first in the PATH, see https://learn.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order + for bindir in self.dependencies[self.tested_reference_str].cpp_info.bindirs: + copy(self, "*.dll", bindir, self.build_folder) def build(self): cmake = CMake(self) diff --git a/recipes/onnxruntime/all/test_package/test_package.cpp b/recipes/onnxruntime/all/test_package/test_package.cpp index a9cc6b11cef74..09281241c4ad8 100644 --- a/recipes/onnxruntime/all/test_package/test_package.cpp +++ b/recipes/onnxruntime/all/test_package/test_package.cpp @@ -2,8 +2,22 @@ #include #include +#ifdef WITH_CUDA +#include +#endif + int main() { const auto& api = Ort::GetApi(); - std::cout << OrtGetApiBase()->GetVersionString() << std::endl; + std::cout << "Version: " << OrtGetApiBase()->GetVersionString() << std::endl; + std::cout << "Providers: " << std::endl; + for(const auto& provider: Ort::GetAvailableProviders()) + std::cout << provider << ", " << std::endl; + +#ifdef WITH_CUDA + Ort::SessionOptions session_options; + OrtSessionOptionsAppendExecutionProvider_CUDA(session_options, 1); + std::cout << "with cuda!" << std::endl; +#endif + return 0; } From 20e32573600d654c0f9d3d3f747188d609863b32 Mon Sep 17 00:00:00 2001 From: Florian de Gaulejac Date: Tue, 6 Feb 2024 15:51:20 +0100 Subject: [PATCH 05/16] Add 1.15.1 patch --- recipes/onnxruntime/all/conandata.yml | 4 ++++ .../all/patches/1.15.1-0002-fix-attention-15983.patch | 11 +++++++++++ 2 files changed, 15 insertions(+) create mode 100644 recipes/onnxruntime/all/patches/1.15.1-0002-fix-attention-15983.patch diff --git a/recipes/onnxruntime/all/conandata.yml b/recipes/onnxruntime/all/conandata.yml index 8340287a5ee7d..9424531ccf54a 100644 --- a/recipes/onnxruntime/all/conandata.yml +++ b/recipes/onnxruntime/all/conandata.yml @@ -62,6 +62,10 @@ patches: - patch_file: "patches/1.15.1-0002-cuda-gsl.patch" patch_description: "CMake: fix GSL and cuda" patch_type: "conan" + - patch_file: "patches/1.15.1-0002-fix-attention-15983.patch" + patch_description: "Fix attention.cc" + patch_source: "/~https://github.com/microsoft/onnxruntime/pull/15983" + patch_type: "backport" "1.14.1": - patch_file: "patches/1.14.1-0001-cmake-dependencies.patch" patch_description: "CMake: ensure conan dependencies are used (upstreamed future versions)" diff --git a/recipes/onnxruntime/all/patches/1.15.1-0002-fix-attention-15983.patch b/recipes/onnxruntime/all/patches/1.15.1-0002-fix-attention-15983.patch new file mode 100644 index 0000000000000..512fe43577ad8 --- /dev/null +++ b/recipes/onnxruntime/all/patches/1.15.1-0002-fix-attention-15983.patch @@ -0,0 +1,11 @@ +--- a/onnxruntime/contrib_ops/cuda/bert/attention.cc ++++ b/onnxruntime/contrib_ops/cuda/bert/attention.cc +@@ -164,7 +164,7 @@ + has_memory_efficient_attention(sm, sizeof(T) == 2); + #else + constexpr bool use_memory_efficient_attention = false; +- ORT_UNUSED_VARIABLE(is_mask_1d_key_seq_len_start); ++ ORT_UNUSED_PARAMETER(is_mask_1d_key_seq_len_start); + #endif + + cublasHandle_t cublas = GetCublasHandle(context); From ef49a3c26ef42ec41910c930c864c30863e15c29 Mon Sep 17 00:00:00 2001 From: czoido Date: Thu, 29 Aug 2024 13:27:50 +0200 Subject: [PATCH 06/16] wip --- recipes/onnxruntime/all/conandata.yml | 7 ++++--- recipes/onnxruntime/all/conanfile.py | 10 ++-------- .../all/patches/1.16.0-0002-cuda-gsl.patch | 13 ------------- .../all/patches/1.16.1-0002-cuda-gsl.patch | 13 ------------- 4 files changed, 6 insertions(+), 37 deletions(-) delete mode 100644 recipes/onnxruntime/all/patches/1.16.0-0002-cuda-gsl.patch delete mode 100644 recipes/onnxruntime/all/patches/1.16.1-0002-cuda-gsl.patch diff --git a/recipes/onnxruntime/all/conandata.yml b/recipes/onnxruntime/all/conandata.yml index e97a2180234c3..f550ef0dc383d 100644 --- a/recipes/onnxruntime/all/conandata.yml +++ b/recipes/onnxruntime/all/conandata.yml @@ -37,9 +37,6 @@ patches: - patch_file: "patches/1.14.1-0004-abseil-no-string-view.patch" patch_description: "allow to build with abseil built without c++17 support" patch_type: "portability" - - patch_file: "patches/1.16.0-0002-cuda-gsl.patch" - patch_description: "CMake: fix GSL and cuda" - patch_type: "conan" "1.15.1": - patch_file: "patches/1.14.1-0004-abseil-no-string-view.patch" patch_description: "allow to build with abseil built without c++17 support" @@ -66,6 +63,10 @@ patches: patch_description: "Ensures the forward compatibility with the newest versions of re2 library." patch_type: "portability" patch_source: "/~https://github.com/microsoft/onnxruntime/commit/126e7bf15fa4af8621814b82a3f7bd0d786f0239.patch" + - patch_file: "patches/1.14.1-0006-cuda-gsl.patch" + patch_description: "CMake: fix GSL and cuda" + patch_type: "conan" + # ONNX versions are based on the minor version used at # /~https://github.com/microsoft/onnxruntime/tree/main/cmake/external onnx_version_map: diff --git a/recipes/onnxruntime/all/conanfile.py b/recipes/onnxruntime/all/conanfile.py index eb01e1d772cba..f21fbd87d2b87 100644 --- a/recipes/onnxruntime/all/conanfile.py +++ b/recipes/onnxruntime/all/conanfile.py @@ -72,6 +72,7 @@ def config_options(self): def configure(self): if self.options.shared: self.options.rm_safe("fPIC") + self.options["onnx"].disable_static_registration = True def layout(self): cmake_layout(self, src_folder="src") @@ -202,14 +203,7 @@ def package(self): copy(self, pattern="LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder) cmake = CMake(self) cmake.install() - - # move the shared providers dll in the bin dir - lib_dir = os.path.join(self.package_folder, "lib") - bin_dir = os.path.join(self.package_folder, "bin") - copy(self, "*.dll", src=lib_dir, dst=bin_dir) - rm(self, "*.dll", lib_dir) - - pkg_config_dir = os.path.join(lib_dir, "pkgconfig") + pkg_config_dir = os.path.join(self.package_folder, "lib", "pkgconfig") rmdir(self, pkg_config_dir) def package_info(self): diff --git a/recipes/onnxruntime/all/patches/1.16.0-0002-cuda-gsl.patch b/recipes/onnxruntime/all/patches/1.16.0-0002-cuda-gsl.patch deleted file mode 100644 index d66ee9bb957f9..0000000000000 --- a/recipes/onnxruntime/all/patches/1.16.0-0002-cuda-gsl.patch +++ /dev/null @@ -1,13 +0,0 @@ -diff --git a/cmake/external/onnxruntime_external_deps.cmake b/cmake/external/onnxruntime_external_deps.cmake -index 8e412c7847..efd599e5b3 100644 ---- a/cmake/external/onnxruntime_external_deps.cmake -+++ b/cmake/external/onnxruntime_external_deps.cmake -@@ -301,7 +301,7 @@ if(onnxruntime_USE_CUDA) - GSL - URL ${DEP_URL_microsoft_gsl} - URL_HASH SHA1=${DEP_SHA1_microsoft_gsl} -- PATCH_COMMAND ${Patch_EXECUTABLE} --binary --ignore-whitespace -p1 < ${PROJECT_SOURCE_DIR}/patches/gsl/1064.patch -+ FIND_PACKAGE_ARGS 4.0 NAMES Microsoft.GSL - ) - else() - FetchContent_Declare( diff --git a/recipes/onnxruntime/all/patches/1.16.1-0002-cuda-gsl.patch b/recipes/onnxruntime/all/patches/1.16.1-0002-cuda-gsl.patch deleted file mode 100644 index 103e16e300545..0000000000000 --- a/recipes/onnxruntime/all/patches/1.16.1-0002-cuda-gsl.patch +++ /dev/null @@ -1,13 +0,0 @@ -diff --git a/cmake/external/onnxruntime_external_deps.cmake b/cmake/external/onnxruntime_external_deps.cmake -index 0e2482d7de..4210e0bc5c 100644 ---- a/cmake/external/onnxruntime_external_deps.cmake -+++ b/cmake/external/onnxruntime_external_deps.cmake -@@ -301,7 +301,7 @@ if(onnxruntime_USE_CUDA) - GSL - URL ${DEP_URL_microsoft_gsl} - URL_HASH SHA1=${DEP_SHA1_microsoft_gsl} -- PATCH_COMMAND ${Patch_EXECUTABLE} --binary --ignore-whitespace -p1 < ${PROJECT_SOURCE_DIR}/patches/gsl/1064.patch -+ FIND_PACKAGE_ARGS 4.0 NAMES Microsoft.GSL - ) - else() - FetchContent_Declare( From be6f0602c510e555a07454fb5dd30b8ede306110 Mon Sep 17 00:00:00 2001 From: czoido Date: Fri, 30 Aug 2024 08:04:10 +0200 Subject: [PATCH 07/16] add comment --- recipes/onnxruntime/all/conanfile.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/recipes/onnxruntime/all/conanfile.py b/recipes/onnxruntime/all/conanfile.py index f21fbd87d2b87..cabbb6b48d1b0 100644 --- a/recipes/onnxruntime/all/conanfile.py +++ b/recipes/onnxruntime/all/conanfile.py @@ -72,6 +72,8 @@ def config_options(self): def configure(self): if self.options.shared: self.options.rm_safe("fPIC") + # onnxruntime forces this to be True + # /~https://github.com/microsoft/onnxruntime/blob/be76e1e1b8e2914e448d12a0cc683c00014c0490/cmake/external/onnxruntime_external_deps.cmake#L542 self.options["onnx"].disable_static_registration = True def layout(self): From ef0c7a26843fa76b5928852f46cfd06b5541543f Mon Sep 17 00:00:00 2001 From: czoido Date: Mon, 2 Sep 2024 08:21:29 +0200 Subject: [PATCH 08/16] wip --- recipes/onnxruntime/all/conanfile.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/recipes/onnxruntime/all/conanfile.py b/recipes/onnxruntime/all/conanfile.py index cabbb6b48d1b0..727cb231d14eb 100644 --- a/recipes/onnxruntime/all/conanfile.py +++ b/recipes/onnxruntime/all/conanfile.py @@ -110,6 +110,8 @@ def requirements(self): self.requires("xnnpack/cci.20230715") else: self.requires("xnnpack/cci.20220801") + if self.options.with_cuda: + self.requires("cutlass/3.5.0") def validate(self): if self.settings.compiler.get_safe("cppstd"): @@ -154,7 +156,8 @@ def generate(self): tc.variables["onnxruntime_USE_CUDA"] = self.options.with_cuda tc.variables["onnxruntime_BUILD_UNIT_TESTS"] = False - tc.variables["onnxruntime_DISABLE_CONTRIB_OPS"] = False + tc.variables["onnxruntime_DISABLE_CONTRIB_OPS"] = True + tc.variables["onnxruntime_USE_FLASH_ATTENTION"] = False tc.variables["onnxruntime_DISABLE_RTTI"] = False tc.variables["onnxruntime_DISABLE_EXCEPTIONS"] = False @@ -190,6 +193,13 @@ def _patch_sources(self): if Version(self.version) >= "15.0": replace_in_file(self, os.path.join(self.source_folder, "cmake", "CMakeLists.txt"), "if (Git_FOUND)", "if (FALSE)") + replace_in_file(self, os.path.join(self.source_folder, "cmake", "onnxruntime_providers_cuda.cmake"), + "include(cutlass)", "find_package(NvidiaCutlass)") + # /~https://github.com/microsoft/onnxruntime/commit/5bfca1dc576720627f3af8f65e25af408271079b + replace_in_file(self, os.path.join(self.source_folder, "cmake", "onnxruntime_providers_cuda.cmake"), + 'option(onnxruntime_NVCC_THREADS "Number of threads that NVCC can use for compilation." 1)', + 'set(onnxruntime_NVCC_THREADS "1" CACHE STRING "Number of threads that NVCC can use for compilation.")') + def build(self): self._patch_sources() From bb330db079067e0a576d95e432fb653290c75b72 Mon Sep 17 00:00:00 2001 From: czoido Date: Mon, 2 Sep 2024 15:05:24 +0200 Subject: [PATCH 09/16] wip --- recipes/onnxruntime/all/conanfile.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/recipes/onnxruntime/all/conanfile.py b/recipes/onnxruntime/all/conanfile.py index 727cb231d14eb..bb3036e40edba 100644 --- a/recipes/onnxruntime/all/conanfile.py +++ b/recipes/onnxruntime/all/conanfile.py @@ -156,7 +156,7 @@ def generate(self): tc.variables["onnxruntime_USE_CUDA"] = self.options.with_cuda tc.variables["onnxruntime_BUILD_UNIT_TESTS"] = False - tc.variables["onnxruntime_DISABLE_CONTRIB_OPS"] = True + tc.variables["onnxruntime_DISABLE_CONTRIB_OPS"] = False tc.variables["onnxruntime_USE_FLASH_ATTENTION"] = False tc.variables["onnxruntime_DISABLE_RTTI"] = False tc.variables["onnxruntime_DISABLE_EXCEPTIONS"] = False @@ -200,6 +200,9 @@ def _patch_sources(self): 'option(onnxruntime_NVCC_THREADS "Number of threads that NVCC can use for compilation." 1)', 'set(onnxruntime_NVCC_THREADS "1" CACHE STRING "Number of threads that NVCC can use for compilation.")') + replace_in_file(self, os.path.join(self.source_folder, "cmake", "onnxruntime_providers_cuda.cmake"), + r'target_include_directories(${target} PRIVATE ${cutlass_SOURCE_DIR}/include ${cutlass_SOURCE_DIR}/examples ${cutlass_SOURCE_DIR}/tools/util/include)', + r'target_link_libraries(${target} PRIVATE nvidia::cutlass::cutlass)') def build(self): self._patch_sources() From 8d6bd616cf719b177db9dc5449610b172d4eb151 Mon Sep 17 00:00:00 2001 From: czoido Date: Tue, 3 Sep 2024 09:14:25 +0200 Subject: [PATCH 10/16] wip --- recipes/onnxruntime/all/conanfile.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/recipes/onnxruntime/all/conanfile.py b/recipes/onnxruntime/all/conanfile.py index bb3036e40edba..a1c47d786d10b 100644 --- a/recipes/onnxruntime/all/conanfile.py +++ b/recipes/onnxruntime/all/conanfile.py @@ -170,7 +170,7 @@ def generate(self): if Version(self.version) >= "1.17": tc.variables["onnxruntime_ENABLE_CUDA_EP_INTERNAL_TESTS"] = False tc.variables["onnxruntime_USE_NEURAL_SPEED"] = False - tc.variables["onnxruntime_USE_MEMORY_EFFICIENT_ATTENTION"] = True + tc.variables["onnxruntime_USE_MEMORY_EFFICIENT_ATTENTION"] = False # Disable a warning that gets converted to an error tc.preprocessor_definitions["_SILENCE_ALL_CXX23_DEPRECATION_WARNINGS"] = "1" @@ -275,6 +275,8 @@ def package_info(self): self.cpp_info.requires.append("wil::wil") if self.options.with_xnnpack: self.cpp_info.requires.append("xnnpack::xnnpack") + if self.options.with_cuda: + self.cpp_info.requires.append("cutlass::cutlass") # /~https://github.com/microsoft/onnxruntime/blob/v1.16.0/cmake/CMakeLists.txt#L1759-L1763 self.cpp_info.set_property("cmake_file_name", "onnxruntime") From 4153eac1f0fbf8a0d8cb1c2a9a42052bbeadae86 Mon Sep 17 00:00:00 2001 From: czoido Date: Tue, 3 Sep 2024 17:05:14 +0200 Subject: [PATCH 11/16] remove unused patch --- .../all/patches/1.14.1-0006-cuda-gsl.patch | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 recipes/onnxruntime/all/patches/1.14.1-0006-cuda-gsl.patch diff --git a/recipes/onnxruntime/all/patches/1.14.1-0006-cuda-gsl.patch b/recipes/onnxruntime/all/patches/1.14.1-0006-cuda-gsl.patch deleted file mode 100644 index de12d90d18497..0000000000000 --- a/recipes/onnxruntime/all/patches/1.14.1-0006-cuda-gsl.patch +++ /dev/null @@ -1,13 +0,0 @@ -diff --git a/cmake/external/onnxruntime_external_deps.cmake b/cmake/external/onnxruntime_external_deps.cmake -index 0c41945778..9bb5ffc63b 100644 ---- a/cmake/external/onnxruntime_external_deps.cmake -+++ b/cmake/external/onnxruntime_external_deps.cmake -@@ -250,7 +250,7 @@ if(onnxruntime_USE_CUDA) - GSL - URL ${DEP_URL_microsoft_gsl} - URL_HASH SHA1=${DEP_SHA1_microsoft_gsl} -- PATCH_COMMAND ${Patch_EXECUTABLE} --binary --ignore-whitespace -p1 < ${PROJECT_SOURCE_DIR}/patches/gsl/1064.patch -+ FIND_PACKAGE_ARGS 4.0 NAMES Microsoft.GSL - ) - else() - FetchContent_Declare( From 66662839aeee2c42478cbeb3d42fc1cc3207ae48 Mon Sep 17 00:00:00 2001 From: czoido Date: Tue, 3 Sep 2024 17:05:29 +0200 Subject: [PATCH 12/16] better patching --- recipes/onnxruntime/all/conandata.yml | 9 ++++++--- recipes/onnxruntime/all/conanfile.py | 15 +++++---------- .../1.17.3-0003-fix-cutlass-cuda-provider.patch | 15 +++++++++++++++ .../1.18.1-0005-fix-cutlass-cuda-provider.patch | 15 +++++++++++++++ 4 files changed, 41 insertions(+), 13 deletions(-) create mode 100644 recipes/onnxruntime/all/patches/1.17.3-0003-fix-cutlass-cuda-provider.patch create mode 100644 recipes/onnxruntime/all/patches/1.18.1-0005-fix-cutlass-cuda-provider.patch diff --git a/recipes/onnxruntime/all/conandata.yml b/recipes/onnxruntime/all/conandata.yml index f550ef0dc383d..dd5a083284d73 100644 --- a/recipes/onnxruntime/all/conandata.yml +++ b/recipes/onnxruntime/all/conandata.yml @@ -22,6 +22,9 @@ patches: - patch_file: "patches/1.18.0-0004-abseil-no-string-view.patch" patch_description: "allow to build with abseil built without c++17 support" patch_type: "portability" + - patch_file: "patches/1.18.1-0005-fix-cutlass-cuda-provider.patch" + patch_description: "use cutlass from Conan" + patch_type: "portability" "1.17.3": - patch_file: "patches/1.17.3-0001-patch-macos-cpp20-date-compat.patch" patch_description: "allow to build with macos c++20 support" @@ -33,6 +36,9 @@ patches: - patch_file: "patches/1.14.1-0004-abseil-no-string-view.patch" patch_description: "allow to build with abseil built without c++17 support" patch_type: "portability" + - patch_file: "patches/1.17.3-0003-fix-cutlass-cuda-provider.patch" + patch_description: "use cutlass from Conan" + patch_type: "portability" "1.16.3": - patch_file: "patches/1.14.1-0004-abseil-no-string-view.patch" patch_description: "allow to build with abseil built without c++17 support" @@ -63,9 +69,6 @@ patches: patch_description: "Ensures the forward compatibility with the newest versions of re2 library." patch_type: "portability" patch_source: "/~https://github.com/microsoft/onnxruntime/commit/126e7bf15fa4af8621814b82a3f7bd0d786f0239.patch" - - patch_file: "patches/1.14.1-0006-cuda-gsl.patch" - patch_description: "CMake: fix GSL and cuda" - patch_type: "conan" # ONNX versions are based on the minor version used at # /~https://github.com/microsoft/onnxruntime/tree/main/cmake/external diff --git a/recipes/onnxruntime/all/conanfile.py b/recipes/onnxruntime/all/conanfile.py index a1c47d786d10b..ce3b31cb93581 100644 --- a/recipes/onnxruntime/all/conanfile.py +++ b/recipes/onnxruntime/all/conanfile.py @@ -193,16 +193,11 @@ def _patch_sources(self): if Version(self.version) >= "15.0": replace_in_file(self, os.path.join(self.source_folder, "cmake", "CMakeLists.txt"), "if (Git_FOUND)", "if (FALSE)") - replace_in_file(self, os.path.join(self.source_folder, "cmake", "onnxruntime_providers_cuda.cmake"), - "include(cutlass)", "find_package(NvidiaCutlass)") - # /~https://github.com/microsoft/onnxruntime/commit/5bfca1dc576720627f3af8f65e25af408271079b - replace_in_file(self, os.path.join(self.source_folder, "cmake", "onnxruntime_providers_cuda.cmake"), - 'option(onnxruntime_NVCC_THREADS "Number of threads that NVCC can use for compilation." 1)', - 'set(onnxruntime_NVCC_THREADS "1" CACHE STRING "Number of threads that NVCC can use for compilation.")') - - replace_in_file(self, os.path.join(self.source_folder, "cmake", "onnxruntime_providers_cuda.cmake"), - r'target_include_directories(${target} PRIVATE ${cutlass_SOURCE_DIR}/include ${cutlass_SOURCE_DIR}/examples ${cutlass_SOURCE_DIR}/tools/util/include)', - r'target_link_libraries(${target} PRIVATE nvidia::cutlass::cutlass)') + if Version(self.version) >= "1.17": + # /~https://github.com/microsoft/onnxruntime/commit/5bfca1dc576720627f3af8f65e25af408271079b + replace_in_file(self, os.path.join(self.source_folder, "cmake", "onnxruntime_providers_cuda.cmake"), + 'option(onnxruntime_NVCC_THREADS "Number of threads that NVCC can use for compilation." 1)', + 'set(onnxruntime_NVCC_THREADS "1" CACHE STRING "Number of threads that NVCC can use for compilation.")') def build(self): self._patch_sources() diff --git a/recipes/onnxruntime/all/patches/1.17.3-0003-fix-cutlass-cuda-provider.patch b/recipes/onnxruntime/all/patches/1.17.3-0003-fix-cutlass-cuda-provider.patch new file mode 100644 index 0000000000000..8ea3d51071e51 --- /dev/null +++ b/recipes/onnxruntime/all/patches/1.17.3-0003-fix-cutlass-cuda-provider.patch @@ -0,0 +1,15 @@ +diff --git a/cmake/onnxruntime_providers_cuda.cmake b/cmake/onnxruntime_providers_cuda.cmake +index b5c3100865..129c4f19f6 100644 +--- a/cmake/onnxruntime_providers_cuda.cmake ++++ b/cmake/onnxruntime_providers_cuda.cmake +@@ -180,8 +180,8 @@ + target_link_libraries(${target} PRIVATE CUDA::cuda_driver) + endif() + +- include(cutlass) +- target_include_directories(${target} PRIVATE ${cutlass_SOURCE_DIR}/include ${cutlass_SOURCE_DIR}/examples) ++ find_package(NvidiaCutlass) ++ target_link_libraries(${target} PRIVATE nvidia::cutlass::cutlass) + + target_include_directories(${target} PRIVATE ${ONNXRUNTIME_ROOT} ${CMAKE_CURRENT_BINARY_DIR} ${eigen_INCLUDE_DIRS} ${TVM_INCLUDES} + PUBLIC ${CUDAToolkit_INCLUDE_DIRS}) diff --git a/recipes/onnxruntime/all/patches/1.18.1-0005-fix-cutlass-cuda-provider.patch b/recipes/onnxruntime/all/patches/1.18.1-0005-fix-cutlass-cuda-provider.patch new file mode 100644 index 0000000000000..3024bfb1f7bb6 --- /dev/null +++ b/recipes/onnxruntime/all/patches/1.18.1-0005-fix-cutlass-cuda-provider.patch @@ -0,0 +1,15 @@ +diff --git a/cmake/onnxruntime_providers_cuda.cmake b/cmake/onnxruntime_providers_cuda.cmake +index 1346a9ce96..f40661d4bd 100644 +--- a/cmake/onnxruntime_providers_cuda.cmake ++++ b/cmake/onnxruntime_providers_cuda.cmake +@@ -211,8 +211,8 @@ + target_link_libraries(${target} PRIVATE CUDA::cuda_driver) + endif() + +- include(cutlass) +- target_include_directories(${target} PRIVATE ${cutlass_SOURCE_DIR}/include ${cutlass_SOURCE_DIR}/examples ${cutlass_SOURCE_DIR}/tools/util/include) ++ find_package(NvidiaCutlass) ++ target_link_libraries(${target} PRIVATE nvidia::cutlass::cutlass) + + target_include_directories(${target} PRIVATE ${ONNXRUNTIME_ROOT} ${CMAKE_CURRENT_BINARY_DIR} ${eigen_INCLUDE_DIRS} ${TVM_INCLUDES} + PUBLIC ${CUDAToolkit_INCLUDE_DIRS}) From 60eef1277d94bcfd7dc033574a2f688f5dda48f0 Mon Sep 17 00:00:00 2001 From: czoido Date: Tue, 3 Sep 2024 17:19:42 +0200 Subject: [PATCH 13/16] remove unused patch --- recipes/onnxruntime/all/conandata.yml | 3 --- .../all/patches/1.15.1-0002-cuda-gsl.patch | 13 ------------- 2 files changed, 16 deletions(-) delete mode 100644 recipes/onnxruntime/all/patches/1.15.1-0002-cuda-gsl.patch diff --git a/recipes/onnxruntime/all/conandata.yml b/recipes/onnxruntime/all/conandata.yml index dd5a083284d73..5ad665fd49f79 100644 --- a/recipes/onnxruntime/all/conandata.yml +++ b/recipes/onnxruntime/all/conandata.yml @@ -47,9 +47,6 @@ patches: - patch_file: "patches/1.14.1-0004-abseil-no-string-view.patch" patch_description: "allow to build with abseil built without c++17 support" patch_type: "portability" - - patch_file: "patches/1.15.1-0002-cuda-gsl.patch" - patch_description: "CMake: fix GSL and cuda" - patch_type: "conan" - patch_file: "patches/1.15.1-0002-fix-attention-15983.patch" patch_description: "Fix attention.cc" patch_source: "/~https://github.com/microsoft/onnxruntime/pull/15983" diff --git a/recipes/onnxruntime/all/patches/1.15.1-0002-cuda-gsl.patch b/recipes/onnxruntime/all/patches/1.15.1-0002-cuda-gsl.patch deleted file mode 100644 index f8e107029bd12..0000000000000 --- a/recipes/onnxruntime/all/patches/1.15.1-0002-cuda-gsl.patch +++ /dev/null @@ -1,13 +0,0 @@ -diff --git a/cmake/external/onnxruntime_external_deps.cmake b/cmake/external/onnxruntime_external_deps.cmake -index 9effd1a2db..db30f7a0d4 100644 ---- a/cmake/external/onnxruntime_external_deps.cmake -+++ b/cmake/external/onnxruntime_external_deps.cmake -@@ -287,7 +287,7 @@ if(onnxruntime_USE_CUDA) - GSL - URL ${DEP_URL_microsoft_gsl} - URL_HASH SHA1=${DEP_SHA1_microsoft_gsl} -- PATCH_COMMAND ${Patch_EXECUTABLE} --binary --ignore-whitespace -p1 < ${PROJECT_SOURCE_DIR}/patches/gsl/1064.patch -+ FIND_PACKAGE_ARGS 4.0 NAMES Microsoft.GSL - ) - else() - FetchContent_Declare( From 1b9788d8ba324cdbd08b7a9a73eb2a23fc1a1e0a Mon Sep 17 00:00:00 2001 From: czoido Date: Wed, 4 Sep 2024 08:39:43 +0200 Subject: [PATCH 14/16] fix --- recipes/onnxruntime/all/test_package/conanfile.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/recipes/onnxruntime/all/test_package/conanfile.py b/recipes/onnxruntime/all/test_package/conanfile.py index 7706c2ea4e39b..17284808fb050 100644 --- a/recipes/onnxruntime/all/test_package/conanfile.py +++ b/recipes/onnxruntime/all/test_package/conanfile.py @@ -21,10 +21,10 @@ def generate(self): tc = CMakeToolchain(self) tc.cache_variables["WITH_CUDA"] = self.dependencies["onnxruntime"].options.with_cuda tc.generate() - - # on windows the system dll C:\WINDOWS\system32\onnxruntime.dll may be loaded instead even if the conan lib is first in the PATH, see https://learn.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order - for bindir in self.dependencies[self.tested_reference_str].cpp_info.bindirs: - copy(self, "*.dll", bindir, self.build_folder) + if self.settings.os == "Windows": + # on windows the system dll C:\WINDOWS\system32\onnxruntime.dll may be loaded instead even if the conan lib is first in the PATH, see https://learn.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order + for bindir in self.dependencies[self.tested_reference_str].cpp_info.bindirs: + copy(self, "*.dll", bindir, os.path.join(self.build_folder, str(self.settings.build_type))) def build(self): cmake = CMake(self) @@ -33,5 +33,5 @@ def build(self): def test(self): if can_run(self): - bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package") + bin_path = os.path.join(self.cpp.build.bindir, "test_package") self.run(bin_path, env="conanrun") From fc1959e4f66180e608a8cb89339de7948becdee1 Mon Sep 17 00:00:00 2001 From: czoido Date: Wed, 4 Sep 2024 11:45:30 +0200 Subject: [PATCH 15/16] copy dlls via cmake in v1 --- .../all/test_v1_package/CMakeLists.txt | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/recipes/onnxruntime/all/test_v1_package/CMakeLists.txt b/recipes/onnxruntime/all/test_v1_package/CMakeLists.txt index 0d20897301b68..1d7451526fb18 100644 --- a/recipes/onnxruntime/all/test_v1_package/CMakeLists.txt +++ b/recipes/onnxruntime/all/test_v1_package/CMakeLists.txt @@ -4,5 +4,17 @@ project(test_package) include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) conan_basic_setup(TARGETS) -add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package - ${CMAKE_CURRENT_BINARY_DIR}/test_package) +find_package(onnxruntime REQUIRED CONFIG) +add_executable(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/../test_package/test_package.cpp) +if(WITH_CUDA) + target_compile_definitions(${PROJECT_NAME} PRIVATE WITH_CUDA) +endif() + +target_link_libraries(${PROJECT_NAME} PRIVATE onnxruntime::onnxruntime) +target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17) + +add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory + ${CONAN_BIN_DIRS_ONNXRUNTIME} + $ +) From 39e32ea14433ea5705d2fabfff0884630f48b954 Mon Sep 17 00:00:00 2001 From: czoido Date: Wed, 4 Sep 2024 13:01:35 +0200 Subject: [PATCH 16/16] check if win --- .../onnxruntime/all/test_v1_package/CMakeLists.txt | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/recipes/onnxruntime/all/test_v1_package/CMakeLists.txt b/recipes/onnxruntime/all/test_v1_package/CMakeLists.txt index 1d7451526fb18..691d35acd08dc 100644 --- a/recipes/onnxruntime/all/test_v1_package/CMakeLists.txt +++ b/recipes/onnxruntime/all/test_v1_package/CMakeLists.txt @@ -13,8 +13,10 @@ endif() target_link_libraries(${PROJECT_NAME} PRIVATE onnxruntime::onnxruntime) target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17) -add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_directory - ${CONAN_BIN_DIRS_ONNXRUNTIME} - $ -) +if(WIN32 AND DEFINED CONAN_BIN_DIRS_ONNXRUNTIME AND EXISTS ${CONAN_BIN_DIRS_ONNXRUNTIME}) + add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory + ${CONAN_BIN_DIRS_ONNXRUNTIME} + $ + ) +endif()