Description
Context
OpenVINO Runtime supports inference in either synchronous or asynchronous mode. The key advantage of the Async API is that when a device is busy with inference, the application can perform other tasks in parallel (for example, populating inputs or scheduling other requests) rather than wait for the current inference to complete first.
What needs to be done?
We had async inference support and async demo for Java API 1.0 before, now the async mode should be supported for OV Java API 2.0.
It's necessary to:
- Add Face Detection Async Java Sample for OV API 2.0 based on the deprecated sample and Async Mode.
- If needed, implement missing Java bindings of C++ methods required for OV asynchronous demo via the Java Native Interface (JNI). Such methods as
start_async()
andwait()
have already been added for Java API, but you will probably find more unsupported OV Java methods while developing demo.
Here is an example of OV Java method implementation for infer()
method of InferRequest
class:
Java part of implementation:
// openvino_contrib/blob/master/modules/java_api/src/main/java/org/intel/openvino/InferRequest.java
package org.intel.openvino;
public class InferRequest extends Wrapper {
...
public void infer() {
Infer(nativeObj);
}
private static native void Infer(long addr);
}
CPP part of method implementation:
//openvino_contrib/blob/master/modules/java_api/src/main/cpp/openvino_java.hpp
...
JNIEXPORT void JNICALL Java_org_intel_openvino_InferRequest_Infer(JNIEnv *, jobject, jlong);
// openvino_contrib/blob/master/modules/java_api/src/main/cpp/infer_request.cpp
#include <jni.h>
#include "openvino/openvino.hpp"
#include "openvino_java.hpp"
#include "jni_common.hpp"
using namespace ov;
JNIEXPORT void JNICALL Java_org_intel_openvino_InferRequest_Infer(JNIEnv *env, jobject obj, jlong addr)
{
JNI_METHOD("Infer",
InferRequest *infer_request = (InferRequest *)addr;
infer_request->infer();)
}
...
Example Pull Requests
[JAVA_API][GSOC] Add Java API bindings
Resources
- What is OpenVINO toolkit?
- OpenVINO Contrib repo
- How to build OpenVINO with extra modules
- Java bindings for OpenVINO
- OV Java Samples
- Async Mode
- Java Programming Tutorial - Java Native Interface (JNI)
- Java async demo for depricated OV API 1.0
- OpenVINO™ API 2.0 Transition Guide
- Intel DevHub Discord channel - engage in discussions, ask questions and talk to OpenVINO developers
Contact points
Ticket
No response
Metadata
Metadata
Assignees
Type
Projects
Status
In Review