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

[Java] Support configuring CUDA and TensorRT execution providers #10697

Merged
merged 11 commits into from
Mar 30, 2022

Conversation

Craigacp
Copy link
Contributor

Description:
Adds support for configuring the CUDA and TensorRT execution providers using the new V2 options classes.

There are two abstract classes, OrtProviderOptions which provides the basic functionality for accessing the package private pointers used to call native methods, and StringConfigProviderOptions which provides specific functionality for working on the V2 style string configured options classes. OrtProviderOptions can be used as the basis for other non-string configured provider options classes, though I've not added implementations for any of those yet. The new provider options classes live in ai.onnxruntime.providers along with the previously defined NNAPIFlags and CoreMLFlags.

It may not apply cleanly over the top of some of the other PRs I have out, so I'll rebase it as those are merged if necessary.

Motivation and Context

  • Why is this change required? What problem does it solve? Adds support for configuring Nvidia GPU based providers.

@Craigacp
Copy link
Contributor Author

Craigacp commented Mar 1, 2022

Rebased after #10670.

}
}

protected final long nativeHandle;
Copy link
Member

@yuslepukhin yuslepukhin Mar 1, 2022

Choose a reason for hiding this comment

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

nativeHandle

I found that this handle may need to be accessible to other classes in the package (though not to the clients) so they can accept the instance of the class in its API and pass the native handle to ORT API. Assuming this is a pointer to the native ORT structure. #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, protected in Java means it's this package + subclasses, so it is visible to everything in ai.onnxruntime.

*
* @return The api handle.
*/
protected static long getApiHandle() {
Copy link
Member

@yuslepukhin yuslepukhin Mar 1, 2022

Choose a reason for hiding this comment

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

getApiHandle

This I do not understand. Why an instance of the options class needs to have an accessor to something global, already exposed by OnnxRuntime? #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because the provider implementations are in ai.onnxruntime.providers and OnnxRuntime.ortApiHandle has package level access in ai.onnxruntime so it's not visible. This allows it to be visible to subclasses of OrtProviderOptions no matter what package they are in.

I was trying to not add too many classes to the main package, but it's rather contorted here.

* @param apiHandle The api pointer.
* @param nativePointer The native options pointer.
*/
protected abstract void close(long apiHandle, long nativePointer);
Copy link
Member

@yuslepukhin yuslepukhin Mar 1, 2022

Choose a reason for hiding this comment

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

nativePointer

What is the difference between nativeHandle and nativePointer? #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I mean the same thing by nativePointer and nativeHandle, so that should be nativeHandle for consistency.

@Craigacp
Copy link
Contributor Author

Craigacp commented Mar 7, 2022

Is it possible to get this in for the 1.11 release? The same support for C# is slated to be in that release and it would be nice to keep parity with it.

@yuslepukhin
Copy link
Member

/azp run Linux CPU CI Pipeline, Linux CPU Minimal Build E2E CI Pipeline, Linux CPU x64 NoContribops CI Pipeline, Linux GPU CI Pipeline, Linux GPU TensorRT CI Pipeline, Linux Nuphar CI Pipeline, Linux OpenVINO CI Pipeline, MacOS CI Pipeline

@yuslepukhin
Copy link
Member

/azp run MacOS NoContribops CI Pipeline, Windows CPU CI Pipeline, Windows GPU CI Pipeline, Windows GPU TensorRT CI Pipeline, Windows WebAssembly CI Pipeline, orttraining-amd-gpu-ci-pipeline, orttraining-linux-ci-pipeline, orttraining-linux-gpu-ci-pipeline, orttraining-ortmodule-distributed

@azure-pipelines
Copy link

Azure Pipelines successfully started running 7 pipeline(s).

1 similar comment
@azure-pipelines
Copy link

Azure Pipelines successfully started running 7 pipeline(s).

@yuslepukhin
Copy link
Member

/azp run Linux CPU CI Pipeline, Linux CPU Minimal Build E2E CI Pipeline, Linux CPU x64 NoContribops CI Pipeline, Linux GPU CI Pipeline, Linux GPU TensorRT CI Pipeline, Linux Nuphar CI Pipeline, Linux OpenVINO CI Pipeline, MacOS CI Pipeline

@yuslepukhin
Copy link
Member

/azp run MacOS NoContribops CI Pipeline, Windows CPU CI Pipeline, Windows GPU CI Pipeline, Windows GPU TensorRT CI Pipeline, Windows WebAssembly CI Pipeline, orttraining-amd-gpu-ci-pipeline, orttraining-linux-ci-pipeline, orttraining-linux-gpu-ci-pipeline, orttraining-ortmodule-distributed

@azure-pipelines
Copy link

Azure Pipelines successfully started running 7 pipeline(s).

1 similar comment
@azure-pipelines
Copy link

Azure Pipelines successfully started running 7 pipeline(s).

Copy link
Member

@yuslepukhin yuslepukhin left a comment

Choose a reason for hiding this comment

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

ship it

@yuslepukhin yuslepukhin merged commit 9616ad4 into microsoft:master Mar 30, 2022
seddonm1 pushed a commit to seddonm1/onnxruntime that referenced this pull request May 15, 2022
…rosoft#10697)

 Java side parts for configuring CUDA and TensorRT.
Adding tests for CUDA and TensorRT. Refactoring library loading logic as provider options need to have their shared library loaded before they can be constructed.
@Craigacp Craigacp deleted the java-cuda-params branch July 25, 2022 19:27
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.

2 participants