Skip to content

[Good First Issue]: [JAVA API] Async demo for Java API 2.0 #834

@likholat

Description

@likholat

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() and wait() 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

Contact points

@likholat

Ticket

No response

Metadata

Metadata

Assignees

Type

Projects

Status

In Review

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions