-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
onnxruntime: enable cuda provider #20392
Changes from 4 commits
0e355cd
b09d0e7
8416420
5cb32e7
cf8914e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,11 +27,13 @@ class OnnxRuntimeConan(ConanFile): | |
"shared": [True, False], | ||
"fPIC": [True, False], | ||
"with_xnnpack": [True, False], | ||
"use_cuda": [True, False], | ||
} | ||
default_options = { | ||
"shared": False, | ||
"fPIC": True, | ||
"with_xnnpack": False, | ||
"use_cuda": False, | ||
} | ||
short_paths = True | ||
|
||
|
@@ -117,8 +119,8 @@ def validate_build(self): | |
) | ||
|
||
def build_requirements(self): | ||
# Required by upstream https://github.com/microsoft/onnxruntime/blob/v1.14.1/cmake/CMakeLists.txt#L5 | ||
self.tool_requires("cmake/[>=3.24 <4]") | ||
# Required by upstream https://github.com/microsoft/onnxruntime/blob/v1.16.1/cmake/CMakeLists.txt#L5 | ||
self.tool_requires("cmake/[>=3.26 <4]") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a small oversight that should have been changed when adding 1.16.0. 1.14.1 is compatible with 3.24. I assume this is good enough and no disambiguation is required? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that's probably fine to just raise the minimum. |
||
|
||
def source(self): | ||
get(self, **self.conan_data["sources"][self.version], strip_root=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.use_cuda | ||
tc.variables["onnxruntime_BUILD_UNIT_TESTS"] = False | ||
tc.variables["onnxruntime_RUN_ONNX_TESTS"] = False | ||
tc.variables["onnxruntime_GENERATE_TEST_REPORTS"] = False | ||
|
@@ -159,7 +162,7 @@ def generate(self): | |
tc.variables["onnxruntime_TVM_CUDA_RUNTIME"] = False | ||
tc.variables["onnxruntime_TVM_USE_HASH"] = False | ||
tc.variables["onnxruntime_CROSS_COMPILING"] = False | ||
tc.variables["onnxruntime_DISABLE_CONTRIB_OPS"] = False | ||
tc.variables["onnxruntime_DISABLE_CONTRIB_OPS"] = self.options.use_cuda | ||
tc.variables["onnxruntime_DISABLE_ML_OPS"] = False | ||
tc.variables["onnxruntime_DISABLE_RTTI"] = False | ||
tc.variables["onnxruntime_DISABLE_EXCEPTIONS"] = False | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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( |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you submit this patch upstream? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks. I'm starting to wonder if we can go even further upstream. Would it be possible for the GSL to be updated with this path to support CUDA? That would be the ideal place to fix this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Possibly, I did not look at the specific patch onnxruntime applies. I do think it is up to onnxruntime to take this up and consider it out of scope for here. It would be a transparent change for this conan package. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, I'm concerned that the patch is applied to the GSL Conan package in the Conan cache. Modifying a package in the cache in this way could cause unexpected problems since the package won't correlate to its hash after the patch is applied. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bverhagen, looking into this, it appears that adding I recommend requesting that the ONNX developers upstream their patch to GSL. Ironically, they are both Microsoft projects... so I imagine this wouldn't be difficult if it is possible. In the meantime, you could instead modify the recipe to only require There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Per the docs you linked: FIND_PACKAGE_ARGS is trying to resolve the package from the system using find_package() with the arguments you give it. If it finds it, it uses it and does not call Hence when it finds the system or conan It would also be pretty insane for CMake trying to patch it, as find_package() is intended to find system packages, which are typically not writable. Even more insane it would be to rewrite these for the whole system. The patch is actually already merged upstream (see microsoft/GSL#1064), but not included in 4.0.0. Even though we don't seem to have problems using conan's ms-gsl 4.0.0, it seems advisable to apply the patch from onnxruntime until a new version of ms-gsl is out. I'll adapt the requirements and add a summary of the above as a comment. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jwillikers : I tried changing the PR so it does not depend on Conan's ms-gsl when CUDA is enabled. However, I got trapped in a situation where FetchContent_Declare in onnxruntime cmake does not download gsl when called from Conan while it works perfectly when called directly from the CLI. Since it is only a problem until the next GSL release, I decided to not dive in further but to go for the second best option and use Conan's ms-gsl in all cases. To resolve your worries, I'll delete the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at the conan file, I assume this is the culprit:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I created a follow-up PR #20619 that gets rid of the FetchContent calls entirely. Could you test that one with |
||
) | ||
else() | ||
FetchContent_Declare( |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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( |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
previous option is called
with_XX
, should we use the same naming across all the recipe?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. I see that a bunch of other recipes use the option
with_cuda
. It would be good to change it towith_cuda
so that it can easily be enabled across multiple recipes.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a recommendation for option names: https://github.com/conan-io/conan-center-index/blob/master/docs/adding_packages/conanfile_attributes.md#recommended-names