[java] Adding native library loader to SessionOptions and RunOptions static init#16435
Conversation
…e the native library is loaded before any methods are called.
|
/azp run Linux CPU CI Pipeline,Linux CPU x64 NoContribops CI Pipeline,Linux GPU CI Pipeline,Linux GPU TensorRT CI Pipeline,MacOS CI Pipeline,MacOS NoContribops CI Pipeline,Windows CPU CI Pipeline,Windows GPU CI Pipeline, Windows GPU TensorRT CI Pipeline, Windows WebAssembly CI Pipeline |
|
/azp run Linux CPU Minimal Build E2E CI Pipeline, Linux Nuphar CI Pipeline, Linux OpenVINO CI Pipeline, orttraining-amd-gpu-ci-pipeline, orttraining-linux-ci-pipeline, orttraining-linux-gpu-ci-pipeline, orttraining-ortmodule-distributed |
|
Azure Pipelines successfully started running 6 pipeline(s). |
|
Azure Pipelines successfully started running 7 pipeline(s). |
|
/azp run Linux QNN CI Pipeline, ONNX Runtime Web CI Pipeline, Windows ARM64 QNN CI Pipeline, onnxruntime-binary-size-checks-ci-pipeline |
|
Azure Pipelines successfully started running 4 pipeline(s). |
|
/azp run orttraining-amd-gpu-ci-pipeline |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
I think it's safe to squash and merge, the 1 failing test doesn't have anything to do with your changes. |
|
Sounds good. Would you mind having a look at #16198 as well? That one is a bit more involved, but we'd really like to have better support for loading in large models without the filesystem from Java so I needed to add a few new native accessors. |
Yep, will take a look |
Description
Unlike most ORT classes
SessionOptionsandRunOptionsdon't trigger native library loading of the JNI binding and ORT when the classes are initialized (after class loading). This was initially because I thought that loading an inner class would trigger the static initialization of the outer class, but this is not true. So if you create aSessionOptionsinstance before referencingOrtEnvironmentthen you won't trigger library loading and you'll get an error saying it couldn't link the native method that creates aSessionOptionsobject.Note this doesn't prevent users from creating a
SessionOptionsand modifying it before theOrtEnvironmentis created, which can still cause issues. It would be a breaking API change to modify theSessionOptionsconstructor to take an environment, and it wouldn't mirror the way it works in the C API which requires this by convention rather than API design, but we can discuss making that modification later.Motivation and Context
Reduces the occurrence of mysterious Java library loading errors. Helps with #16434.