mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-29 20:14:01 +00:00
[Java] Exposing SessionOptions.SetDeterministicCompute (#18998)
### Description Exposes `SetDeterministicCompute` in Java, added to the C API by #18944. ### Motivation and Context Parity between C and Java APIs.
This commit is contained in:
parent
02e00dc023
commit
6d7235ba5a
3 changed files with 31 additions and 0 deletions
|
|
@ -942,6 +942,20 @@ public class OrtSession implements AutoCloseable {
|
|||
OnnxRuntime.ortApiHandle, nativeHandle, dimensionName, dimensionValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether to use deterministic compute.
|
||||
*
|
||||
* <p>Default is false. If set to true, this will enable deterministic compute for GPU kernels
|
||||
* where possible. Note that this most likely will have a performance cost.
|
||||
*
|
||||
* @param value Should the compute be deterministic?
|
||||
* @throws OrtException If there was an error in native code.
|
||||
*/
|
||||
public void setDeterministicCompute(boolean value) throws OrtException {
|
||||
checkClosed();
|
||||
setDeterministicCompute(OnnxRuntime.ortApiHandle, nativeHandle, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables the per session thread pools. Must be used in conjunction with an environment
|
||||
* containing global thread pools.
|
||||
|
|
@ -1327,6 +1341,9 @@ public class OrtSession implements AutoCloseable {
|
|||
|
||||
private native void closeOptions(long apiHandle, long nativeHandle);
|
||||
|
||||
private native void setDeterministicCompute(
|
||||
long apiHandle, long nativeHandle, boolean isDeterministic) throws OrtException;
|
||||
|
||||
private native void addFreeDimensionOverrideByName(
|
||||
long apiHandle, long nativeHandle, String dimensionName, long dimensionValue)
|
||||
throws OrtException;
|
||||
|
|
|
|||
|
|
@ -259,6 +259,19 @@ JNIEXPORT void JNICALL Java_ai_onnxruntime_OrtSession_00024SessionOptions_setSes
|
|||
checkOrtStatus(jniEnv,api,api->SetSessionLogVerbosityLevel(options,logLevel));
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: ai_onnxruntime_OrtSession_SessionOptions
|
||||
* Method: setDeterministicCompute
|
||||
* Signature: (JJZ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_ai_onnxruntime_OrtSession_00024SessionOptions_setDeterministicCompute
|
||||
(JNIEnv * jniEnv, jobject jobj, jlong apiHandle, jlong optionsHandle, jboolean isDeterministic) {
|
||||
(void) jobj; // Required JNI parameters not needed by functions which don't need to access their host object.
|
||||
const OrtApi* api = (const OrtApi*)apiHandle;
|
||||
OrtSessionOptions* options = (OrtSessionOptions*) optionsHandle;
|
||||
checkOrtStatus(jniEnv,api,api->SetDeterministicCompute(options, isDeterministic));
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: ai_onnxruntime_OrtSession_SessionOptions
|
||||
* Method: registerCustomOpLibrary
|
||||
|
|
|
|||
|
|
@ -1263,6 +1263,7 @@ public class InferenceTest {
|
|||
options.setLoggerId("monkeys");
|
||||
options.setSessionLogLevel(OrtLoggingLevel.ORT_LOGGING_LEVEL_FATAL);
|
||||
options.setSessionLogVerbosityLevel(5);
|
||||
options.setDeterministicCompute(true);
|
||||
Map<String, String> configEntries = options.getConfigEntries();
|
||||
assertTrue(configEntries.isEmpty());
|
||||
options.addConfigEntry("key", "value");
|
||||
|
|
|
|||
Loading…
Reference in a new issue