Skip to content
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

Closed
wants to merge 5 commits into from
Closed

Conversation

bverhagen
Copy link
Contributor

@bverhagen bverhagen commented Oct 6, 2023

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.


@CLAassistant
Copy link

CLAassistant commented Oct 6, 2023

CLA assistant check
All committers have signed the CLA.

recipes/onnxruntime/all/conanfile.py Outdated Show resolved Hide resolved
recipes/onnxruntime/all/conanfile.py Outdated Show resolved Hide resolved
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
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor

@jwillikers jwillikers Oct 16, 2023

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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?

Copy link
Contributor Author

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

Copy link
Contributor

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?

@conan-center-bot

This comment has been minimized.

@bverhagen
Copy link
Contributor Author

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.

@conan-center-bot

This comment has been minimized.

@conan-center-bot

This comment has been minimized.

@conan-center-bot

This comment has been minimized.

@conan-center-bot

This comment has been minimized.

@AbrilRBS
Copy link
Member

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.

No worries :)

@AbrilRBS AbrilRBS self-assigned this Oct 11, 2023
@ghost ghost mentioned this pull request Oct 11, 2023
3 tasks
@bverhagen
Copy link
Contributor Author

I tested and patched onnxruntime 1.16.1 too.

@conan-center-bot
Copy link
Collaborator

Conan v1 pipeline ✔️

All green in build 10 (8416420aa3eb76a0c10430355d649dba216ab96e):

  • onnxruntime/1.16.0:
    All packages built successfully! (All logs)

  • onnxruntime/1.15.1:
    All packages built successfully! (All logs)

  • onnxruntime/1.14.1:
    All packages built successfully! (All logs)

  • onnxruntime/1.16.1:
    All packages built successfully! (All logs)


Conan v2 pipeline ✔️

Note: Conan v2 builds are now mandatory. Please read our discussion about it.

All green in build 10 (8416420aa3eb76a0c10430355d649dba216ab96e):

  • onnxruntime/1.16.0:
    All packages built successfully! (All logs)

  • onnxruntime/1.15.1:
    All packages built successfully! (All logs)

  • onnxruntime/1.14.1:
    All packages built successfully! (All logs)

  • onnxruntime/1.16.1:
    All packages built successfully! (All logs)

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
Copy link
Contributor

@jwillikers jwillikers Oct 16, 2023

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]")
Copy link
Contributor Author

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?

Copy link
Contributor

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]")
Copy link
Contributor

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,
Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

snnn pushed a commit to microsoft/onnxruntime that referenced this pull request Nov 10, 2023
…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).
@ghost ghost mentioned this pull request Nov 11, 2023
3 tasks
Copy link

stale bot commented Dec 15, 2023

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.

@ghost ghost mentioned this pull request Dec 24, 2023
3 tasks
@ghost ghost mentioned this pull request Jan 15, 2024
3 tasks
@ghost ghost mentioned this pull request Jan 26, 2024
3 tasks
kleiti pushed a commit to kleiti/onnxruntime that referenced this pull request Mar 22, 2024
…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).
@czoido czoido assigned czoido and unassigned AbrilRBS Sep 2, 2024
@czoido
Copy link
Contributor

czoido commented Sep 4, 2024

Closed by #22557

@czoido czoido closed this Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants