Skip to content

Commit 08747d7

Browse files
committed
map OpenVINO's C API
1 parent af38c16 commit 08747d7

3 files changed

Lines changed: 51 additions & 6 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import org.bytedeco.javacpp.BytePointer;
2+
import org.bytedeco.javacpp.Pointer;
3+
import org.bytedeco.openvino.ov_core_t;
4+
import org.bytedeco.openvino.ov_remote_context_t;
5+
import org.bytedeco.openvino.ov_shape_t;
6+
import org.bytedeco.openvino.ov_tensor_t;
7+
8+
import static org.bytedeco.openvino.global.openvino.*;
9+
10+
/** Compile-time smoke sample for the non-variadic OpenCL interop overloads. */
11+
public final class OpenVINORemoteTensor {
12+
private OpenVINORemoteTensor() {
13+
}
14+
15+
public static ov_remote_context_t createContext(ov_core_t core, Pointer clContext, Pointer clQueue) {
16+
ov_remote_context_t context = new ov_remote_context_t();
17+
check(ov_core_create_context(core, "GPU", 6, context,
18+
string(ov_property_key_intel_gpu_context_type()), "OCL",
19+
string(ov_property_key_intel_gpu_ocl_context()), clContext,
20+
string(ov_property_key_intel_gpu_ocl_queue()), clQueue));
21+
return context;
22+
}
23+
24+
public static ov_tensor_t wrapBuffer(ov_remote_context_t context, ov_shape_t shape, Pointer clMem) {
25+
ov_tensor_t tensor = new ov_tensor_t();
26+
check(ov_remote_context_create_tensor(context, U8, shape, 4, tensor,
27+
string(ov_property_key_intel_gpu_shared_mem_type()), "OCL_BUFFER",
28+
string(ov_property_key_intel_gpu_mem_handle()), clMem));
29+
return tensor;
30+
}
31+
32+
private static String string(BytePointer value) {
33+
return value.getString();
34+
}
35+
36+
private static void check(int status) {
37+
if (status != OK) {
38+
throw new IllegalStateException(ov_get_error_info(status).getString());
39+
}
40+
}
41+
}

openvino/src/gen/java/org/bytedeco/openvino/global/openvino.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,7 @@ public class openvino extends org.bytedeco.openvino.presets.openvino {
892892
*/
893893
public static native @Cast("ov_status_e") int ov_core_create_context(@Const ov_core_t core, String device_name, @Cast("const size_t") long context_args_size, @ByPtrPtr ov_remote_context_t context);
894894
public static native @Cast("ov_status_e") int ov_core_create_context(@Const ov_core_t core, String device_name, @Cast("const size_t") long context_args_size, @ByPtrPtr ov_remote_context_t context, String property_key, Pointer property_value);
895+
public static native @Cast("ov_status_e") int ov_core_create_context(@Const ov_core_t core, String device_name, @Cast("const size_t") long context_args_size, @ByPtrPtr ov_remote_context_t context, String property_key1, String property_value1, String property_key2, Pointer property_value2, String property_key3, Pointer property_value3);
895896

896897
/**
897898
* \brief Creates a compiled model from a source model within a specified remote context.
@@ -2621,6 +2622,7 @@ public class openvino extends org.bytedeco.openvino.presets.openvino {
26212622
*/
26222623
public static native @Cast("ov_status_e") int ov_remote_context_create_tensor(@Const ov_remote_context_t context, @Cast("const ov_element_type_e") int type, @Const @ByVal ov_shape_t shape, @Cast("const size_t") long object_args_size, @ByPtrPtr ov_tensor_t remote_tensor);
26232624
public static native @Cast("ov_status_e") int ov_remote_context_create_tensor(@Const ov_remote_context_t context, @Cast("const ov_element_type_e") int type, @Const @ByVal ov_shape_t shape, @Cast("const size_t") long object_args_size, @ByPtrPtr ov_tensor_t remote_tensor, String property_key, Pointer property_value);
2625+
public static native @Cast("ov_status_e") int ov_remote_context_create_tensor(@Const ov_remote_context_t context, @Cast("const ov_element_type_e") int type, @Const @ByVal ov_shape_t shape, @Cast("const size_t") long object_args_size, @ByPtrPtr ov_tensor_t remote_tensor, String property_key1, String property_value1, String property_key2, Pointer property_value2);
26242626

26252627
/**
26262628
* \brief Returns name of a device on which underlying object is allocated.

openvino/src/main/java/org/bytedeco/openvino/presets/openvino.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,12 @@
2727
import org.bytedeco.javacpp.annotation.Properties;
2828
import org.bytedeco.javacpp.tools.InfoMap;
2929
import org.bytedeco.javacpp.tools.InfoMapper;
30-
import org.bytedeco.opencl.presets.OpenCL;
3130

3231
/**
3332
*
3433
* @author Barry Pitman
3534
*/
3635
@Properties(
37-
inherit = OpenCL.class,
3836
value = {
3937
@Platform(
4038
value = {"linux-x86_64"},
@@ -152,6 +150,9 @@
152150
"runtime/3rdparty/tbb/bin/"
153151
},
154152
preload = {
153+
"tbb12",
154+
"openvino",
155+
"openvino_c",
155156
"openvino_auto_batch_plugin",
156157
"openvino_auto_plugin",
157158
"openvino_hetero_plugin",
@@ -163,8 +164,7 @@
163164
"openvino_paddle_frontend",
164165
"openvino_pytorch_frontend",
165166
"openvino_tensorflow_frontend",
166-
"openvino_tensorflow_lite_frontend",
167-
"tbb12"
167+
"openvino_tensorflow_lite_frontend"
168168
},
169169
resource = {"runtime"}
170170
),
@@ -190,13 +190,15 @@ public class openvino implements InfoMapper {
190190
+ "public static native @Cast(\"ov_status_e\") int ov_core_compile_model(@Const ov_core_t core, @Const ov_model_t model, String device_name, @Cast(\"const size_t\") long property_args_size, @ByPtrPtr ov_compiled_model_t compiled_model, String property_key, String property_value);\n"))
191191
.put(new org.bytedeco.javacpp.tools.Info("ov_core_create_context").javaText(
192192
"public static native @Cast(\"ov_status_e\") int ov_core_create_context(@Const ov_core_t core, String device_name, @Cast(\"const size_t\") long context_args_size, @ByPtrPtr ov_remote_context_t context);\n"
193-
+ "public static native @Cast(\"ov_status_e\") int ov_core_create_context(@Const ov_core_t core, String device_name, @Cast(\"const size_t\") long context_args_size, @ByPtrPtr ov_remote_context_t context, String property_key, Pointer property_value);\n"))
193+
+ "public static native @Cast(\"ov_status_e\") int ov_core_create_context(@Const ov_core_t core, String device_name, @Cast(\"const size_t\") long context_args_size, @ByPtrPtr ov_remote_context_t context, String property_key, Pointer property_value);\n"
194+
+ "public static native @Cast(\"ov_status_e\") int ov_core_create_context(@Const ov_core_t core, String device_name, @Cast(\"const size_t\") long context_args_size, @ByPtrPtr ov_remote_context_t context, String property_key1, String property_value1, String property_key2, Pointer property_value2, String property_key3, Pointer property_value3);\n"))
194195
.put(new org.bytedeco.javacpp.tools.Info("ov_core_compile_model_with_context").javaText(
195196
"public static native @Cast(\"ov_status_e\") int ov_core_compile_model_with_context(@Const ov_core_t core, @Const ov_model_t model, @Const ov_remote_context_t context, @Cast(\"const size_t\") long property_args_size, @ByPtrPtr ov_compiled_model_t compiled_model);\n"
196197
+ "public static native @Cast(\"ov_status_e\") int ov_core_compile_model_with_context(@Const ov_core_t core, @Const ov_model_t model, @Const ov_remote_context_t context, @Cast(\"const size_t\") long property_args_size, @ByPtrPtr ov_compiled_model_t compiled_model, String property_key, String property_value);\n"))
197198
.put(new org.bytedeco.javacpp.tools.Info("ov_remote_context_create_tensor").javaText(
198199
"public static native @Cast(\"ov_status_e\") int ov_remote_context_create_tensor(@Const ov_remote_context_t context, @Cast(\"const ov_element_type_e\") int type, @Const @ByVal ov_shape_t shape, @Cast(\"const size_t\") long object_args_size, @ByPtrPtr ov_tensor_t remote_tensor);\n"
199-
+ "public static native @Cast(\"ov_status_e\") int ov_remote_context_create_tensor(@Const ov_remote_context_t context, @Cast(\"const ov_element_type_e\") int type, @Const @ByVal ov_shape_t shape, @Cast(\"const size_t\") long object_args_size, @ByPtrPtr ov_tensor_t remote_tensor, String property_key, Pointer property_value);\n"))
200+
+ "public static native @Cast(\"ov_status_e\") int ov_remote_context_create_tensor(@Const ov_remote_context_t context, @Cast(\"const ov_element_type_e\") int type, @Const @ByVal ov_shape_t shape, @Cast(\"const size_t\") long object_args_size, @ByPtrPtr ov_tensor_t remote_tensor, String property_key, Pointer property_value);\n"
201+
+ "public static native @Cast(\"ov_status_e\") int ov_remote_context_create_tensor(@Const ov_remote_context_t context, @Cast(\"const ov_element_type_e\") int type, @Const @ByVal ov_shape_t shape, @Cast(\"const size_t\") long object_args_size, @ByPtrPtr ov_tensor_t remote_tensor, String property_key1, String property_value1, String property_key2, Pointer property_value2);\n"))
200202
.put(new org.bytedeco.javacpp.tools.Info("OV_BOOLEAN", "BOOLEAN").skip())
201203
.put(new org.bytedeco.javacpp.tools.Info("ov_dimension_t", "ov_rank_t").skip());
202204
}

0 commit comments

Comments
 (0)