-
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
Conversation
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 comment
The 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 comment
The 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 comment
The 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 comment
The 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
@bverhagen, looking into this, it appears that adding FIND_PACKAGE_ARGS
opts in to using find_package
to attempt to find the installed version. Refer to the section on FIND_PACKAGE_ARGS
here. Since the package requires ms-gsl, this should find the Conan installed version. It would then end up patching it. I think this would need to be fixed upstream in Microsoft.GSL in order to use the ms-gsl Conan package when CUDA is enabled.
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 ms-gsl
when use_cuda
is disabled.
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.
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 ExternalProject
with the remainder of the options (including PATCH_COMMAND).
Hence when it finds the system or conan ms-gsl
, it is not going to patch it but simply use it instead (I guess the patch is no longer necessary or conan sets the right things).
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 comment
The 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 PATCH_COMMAND
in the *-cuda-gsl.patch files. Is that a good enough solution for you?
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.
Looking at the conan file, I assume this is the culprit:
tc.variables["FETCHCONTENT_FULLY_DISCONNECTED"] = True
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.
I created a follow-up PR #20619 that gets rid of the FetchContent calls entirely. Could you test that one with use_cuda=True
, perhaps?
This comment has been minimized.
This comment has been minimized.
Hi reviewers, I rebased (rather than merged) master to get the new 1.16.0 recipe in too. Hence I had to force push it. Apologies for making the review harder this way. Since these are not too many changes, I hope this is not too much of an inconvenience. |
This comment has been minimized.
This comment has been minimized.
e453c8e
to
836299a
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
No worries :) |
I tested and patched onnxruntime 1.16.1 too. |
Conan v1 pipeline ✔️All green in build 10 (
Conan v2 pipeline ✔️
All green in build 10 ( |
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 comment
The reason will be displayed to describe this comment to others. Learn more.
@bverhagen, looking into this, it appears that adding FIND_PACKAGE_ARGS
opts in to using find_package
to attempt to find the installed version. Refer to the section on FIND_PACKAGE_ARGS
here. Since the package requires ms-gsl, this should find the Conan installed version. It would then end up patching it. I think this would need to be fixed upstream in Microsoft.GSL in order to use the ms-gsl Conan package when CUDA is enabled.
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 ms-gsl
when use_cuda
is disabled.
# 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's probably fine to just raise the minimum.
# 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 comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's probably fine to just raise the minimum.
} | ||
default_options = { | ||
"shared": False, | ||
"fPIC": True, | ||
"with_xnnpack": False, | ||
"use_cuda": False, |
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 to with_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
…ing cuda (#17843) ### Description Some CMake scripts reference Microsoft.GSL::GSL. Most of the time, the GSL package that is found on the system is used. However, when cuda is enabled, it is downloaded and patched. Most CMake scripts rely on the first case and forget about the second. This patch makes the second case behave like the first case. ### Motivation and Context This is an issue that occurs 'in the wild'. For example, I had to patch this to be able to enable the CUDA provider for the onnxruntime conan package (see conan-io/conan-center-index#20392).
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
…ing cuda (microsoft#17843) ### Description Some CMake scripts reference Microsoft.GSL::GSL. Most of the time, the GSL package that is found on the system is used. However, when cuda is enabled, it is downloaded and patched. Most CMake scripts rely on the first case and forget about the second. This patch makes the second case behave like the first case. ### Motivation and Context This is an issue that occurs 'in the wild'. For example, I had to patch this to be able to enable the CUDA provider for the onnxruntime conan package (see conan-io/conan-center-index#20392).
Closed by #22557 |
Specify library name and version: onnxruntime/1.15.1 and onnxruntime/1.14.1
We needed the GPU provider of onnxruntime, hence we share our changes to enable this for this conan package upstream.
We do not need features from contrib and since it does not build, it is disabled. Others who need it, can enable it in a next incremental step.