Skip to content

Commit

Permalink
Fixing CoreML in Java (microsoft#16231)
Browse files Browse the repository at this point in the history
### Description
The name of the flag we set when compiling the JNI binding to enable the CoreML EP changed at some point in the past. This PR fixes it by updating the flag in the JNI. I also added a quick smoke test for the CoreML provider to make sure it doesn't crash and can be enabled.

### Motivation and Context
All the EPs should work as expected in Java. Fixes microsoft#16230.
  • Loading branch information
Craigacp authored Jun 7, 2023
1 parent 1261d0b commit bca49d6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ test {
if (cmakeBuildDir != null) {
workingDir cmakeBuildDir
}
systemProperties System.getProperties().subMap(['USE_CUDA', 'USE_ROCM', 'USE_TENSORRT', 'USE_DNNL', 'USE_OPENVINO', 'JAVA_FULL_TEST', 'ENABLE_TRAINING_APIS'])
systemProperties System.getProperties().subMap(['USE_CUDA', 'USE_ROCM', 'USE_TENSORRT', 'USE_DNNL', 'USE_OPENVINO', 'USE_COREML', 'JAVA_FULL_TEST', 'ENABLE_TRAINING_APIS'])
testLogging {
events "passed", "skipped", "failed"
showStandardStreams = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ JNIEXPORT void JNICALL Java_ai_onnxruntime_OrtSession_00024SessionOptions_addArm
JNIEXPORT void JNICALL Java_ai_onnxruntime_OrtSession_00024SessionOptions_addCoreML
(JNIEnv * jniEnv, jobject jobj, jlong apiHandle, jlong handle, jint coreMLFlags) {
(void)jobj;
#ifdef USE_CORE_ML
#ifdef USE_COREML
checkOrtStatus(jniEnv,(const OrtApi*)apiHandle,OrtSessionOptionsAppendExecutionProvider_CoreML((OrtSessionOptions*) handle, (uint32_t) coreMLFlags));
#else
(void)apiHandle;(void)handle;(void)coreMLFlags; // Parameters used when CoreML is defined.
Expand Down
6 changes: 6 additions & 0 deletions java/src/test/java/ai/onnxruntime/InferenceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,12 @@ public void testXNNPACK() throws OrtException {
runProvider(OrtProvider.XNNPACK);
}

@Test
@EnabledIfSystemProperty(named = "USE_COREML", matches = "1")
public void testCoreML() throws OrtException {
runProvider(OrtProvider.CORE_ML);
}

private void runProvider(OrtProvider provider) throws OrtException {
EnumSet<OrtProvider> providers = OrtEnvironment.getAvailableProviders();
assertTrue(providers.size() > 1);
Expand Down

0 comments on commit bca49d6

Please sign in to comment.