-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Enable CUDA provider option configuration for C# #7315
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
base: main
Are you sure you want to change the base?
Changes from all commits
b64d982
f6b6d78
149d90f
4e47045
f2cd0e7
5b14e86
f416f17
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 |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Runtime.InteropServices; | ||
|
|
||
| namespace Microsoft.ML.OnnxRuntime | ||
| { | ||
| /// <summary> | ||
| /// Search Algorithm for Cudnn Conv. | ||
| /// </summary> | ||
| public enum OrtCudnnConvAlgoSearch | ||
| { | ||
| EXHAUSTIVE, //!< expensive exhaustive benchmarking using cudnnFindConvolutionForwardAlgorithmEx | ||
| HEURISTIC, //!< lightweight heuristic based search using cudnnGetConvolutionForwardAlgorithm_v7 | ||
| DEFAULT, //!< default algorithm using CUDNN_CONVOLUTION_FWD_ALGO_IMPLICIT_PRECOMP_GEMM | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Holds provider options configuration for creating an InferenceSession. | ||
| /// </summary> | ||
| public static class ProviderOptions | ||
| { | ||
| #region Public Methods | ||
|
|
||
| /// <summary> | ||
| /// Get CUDA provider options with default setting. | ||
| /// </summary> | ||
| /// <returns> CUDA provider options instance. </returns> | ||
| public static OrtCUDAProviderOptions GetDefaultCUDAProviderOptions() | ||
| { | ||
| OrtCUDAProviderOptions cuda_options; | ||
| cuda_options.device_id = 0; | ||
| cuda_options.cudnn_conv_algo_search = OrtCudnnConvAlgoSearch.EXHAUSTIVE; | ||
| if (IntPtr.Size == 8) | ||
| { | ||
| cuda_options.gpu_mem_limit = (UIntPtr)UInt64.MaxValue; | ||
| } | ||
| else | ||
| { | ||
| cuda_options.gpu_mem_limit = (UIntPtr)UInt32.MaxValue; | ||
| } | ||
| cuda_options.arena_extend_strategy = 0; | ||
| cuda_options.do_copy_in_default_stream = 1; | ||
| cuda_options.has_user_compute_stream = 0; | ||
| cuda_options.user_compute_stream = IntPtr.Zero; | ||
|
|
||
| return cuda_options; | ||
| } | ||
|
|
||
| #endregion | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -226,6 +226,18 @@ public void CanCreateAndDisposeSessionWithModelPath() | |
| } | ||
| } | ||
| } | ||
| #if USE_CUDA | ||
| [Fact] | ||
| private void TestCUDAProviderOptions() | ||
| { | ||
|
|
||
| OrtCUDAProviderOptions cuda_options = ProviderOptions.GetDefaultCUDAProviderOptions(); | ||
| using (var sessionOptions = new SessionOptions()) | ||
|
Member
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 does not test anything. Let's find a way to verify that this indeed happened
Contributor
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. BTW, currently I forgot to pass USE_CUDA in.
Contributor
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. You can see "Microsoft.ML.OnnxRuntime.Tests.InferenceTest.TestGpu" was skipped in your test run. |
||
| { | ||
| sessionOptions.AppendExecutionProvider_CUDA(cuda_options); | ||
| } | ||
| } | ||
| #endif | ||
|
|
||
| [Theory] | ||
| [InlineData(GraphOptimizationLevel.ORT_DISABLE_ALL, 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 would want to verify that this is being marshalled correctly. In C# int is always 4 bytes. In the native code on Windows it is 4 bytes but on Linux it is 8 bytes. So it might work OK on windows but we need it work everywhere.
Uh oh!
There was an error while loading. Please reload this page.
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.
No. Even on Linux int is still 4 bytes. You were talking 'long' #Resolved
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.
You are correct.
In reply to: 613471164 [](ancestors = 613471164)
Uh oh!
There was an error while loading. Please reload this page.
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.
We may have an issue here. The new C API was added without giving a though how this is going to interact with other languages even though the purpose of having C API is language binding. So you will need to verify the fact in the native debugger that the marshalling occurs correctly and make the test test.
In reply to: 613468046 [](ancestors = 613468046)