Skip to content

Commit b04513c

Browse files
[C API] remote tensor support (openvinotoolkit#13719)
* [C API] remote tensor support Provide C interface for remote context and remote tensor: 1. OCL and VA context and buffer support 2. unite test for remote context and remote tensor Change-Id: I2c449aef21cbe928ca470b4e3bcf1e03a1d1ca43 * Fix clang issue Change-Id: I83c9592d21ff9cb8aeb85148277d96db74b455c7 * [CAPI] Add ocl nv12 input inference test case 1. Add fully nv12(2 ocl remote tensor) as input plus preprocess do csc+resize, then do inference 2. Add get_device_name for remote tensor 3. Add test case for preprocess to set mem type Change-Id: Ieaab50c8de20e5c7258697030672e0b010627a81 * Update documentation Change-Id: Ia7dbaea48d38f5534aba60fbb25cd0a1f2f9eab0 * Remove debug code Change-Id: Ic5c5a24d3c40bb258b7007dcea44594af2d92344 * Fix issues brought by rebase Change-Id: I2520c5ccf3620349e202ea40c08bb1c437d5af88 * Resolve document issue Change-Id: Ia14500f8623147f481dda286a0afaa8ecfffa7c9 * Resolve some comments 1. Add specific header file for gpu plugin 2. clang-format issue 3. interface compatible issue Change-Id: Icc4723af071af30f0422ac9a107e57ddeec94aac * fix clang issue Change-Id: I46e1fed3dd9a4e51260b695dc3fb194b9571ed58 * Add gpu header file directory Change-Id: I8c15d9da58a46c070dcc68530cb2beea8cd4bba9 * Remove HAVE_OCL_SUPPORT macro Change-Id: I10093a99c1858649f1c5502248729704fcec34ef * Address some comments Change-Id: I72830288d063623641e8946c8470631e81fdeb34 * Printov:AnyMmap with the help of ov::Any Change-Id: I8abd3a8d94ba8116974c59a489cda2af15f225d7
1 parent e003bf3 commit b04513c

15 files changed

+1307
-11
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright (C) 2018-2022 Intel Corporation
2+
// SPDX-License-Identifier: Apache-2.0
3+
//
4+
5+
/**
6+
* @brief This is a specified header file for gpu plugin's properties
7+
*
8+
* @file gpu_plugin_properties.h
9+
*/
10+
11+
#pragma once
12+
#include "openvino/c/ov_common.h"
13+
14+
/**
15+
* @brief gpu plugin properties key for remote context/tensor
16+
*/
17+
18+
//!< Read-write property: shared device context type, can be either pure OpenCL (OCL) or
19+
//!< shared video decoder (VA_SHARED) context.
20+
//!< Value is string, it can be one of below strings:
21+
//!< "OCL" - Pure OpenCL context
22+
//!< "VA_SHARED" - Context shared with a video decoding device
23+
OPENVINO_C_VAR(const char*) ov_property_key_intel_gpu_context_type;
24+
25+
//!< Read-write property<void *>: identifies OpenCL context handle in a shared context or shared memory blob
26+
//!< parameter map.
27+
OPENVINO_C_VAR(const char*) ov_property_key_intel_gpu_ocl_context;
28+
29+
//!< Read-write property<int string>: ID of device in OpenCL context if multiple devices are present in the context.
30+
OPENVINO_C_VAR(const char*) ov_property_key_intel_gpu_ocl_context_device_id;
31+
32+
//!< Read-write property<int string>: In case of multi-tile system, this key identifies tile within given context.
33+
OPENVINO_C_VAR(const char*) ov_property_key_intel_gpu_tile_id;
34+
35+
//!< Read-write property<void *>: OpenCL queue handle in a shared context
36+
OPENVINO_C_VAR(const char*) ov_property_key_intel_gpu_ocl_queue;
37+
38+
//!< Read-write property<void *>: video acceleration device/display handle in a shared context or shared
39+
//!< memory blob parameter map.
40+
OPENVINO_C_VAR(const char*) ov_property_key_intel_gpu_va_device;
41+
42+
//!< Read-write property: type of internal shared memory in a shared memory blob
43+
//!< parameter map.
44+
//!< Value is string, it can be one of below strings:
45+
//!< "OCL_BUFFER" - Shared OpenCL buffer blob
46+
//!< "OCL_IMAGE2D" - Shared OpenCL 2D image blob
47+
//!< "USM_USER_BUFFER" - Shared USM pointer allocated by user
48+
//!< "USM_HOST_BUFFER" - Shared USM pointer type with host allocation type allocated by plugin
49+
//!< "USM_DEVICE_BUFFER" - Shared USM pointer type with device allocation type allocated by plugin
50+
//!< "VA_SURFACE" - Shared video decoder surface or D3D 2D texture blob
51+
//!< "DX_BUFFER" - Shared D3D buffer blob
52+
OPENVINO_C_VAR(const char*) ov_property_key_intel_gpu_shared_mem_type;
53+
54+
//!< Read-write property<void *>: OpenCL memory handle in a shared memory blob parameter map.
55+
OPENVINO_C_VAR(const char*) ov_property_key_intel_gpu_mem_handle;
56+
57+
//!< Read-write property<uint32_t string>: video decoder surface handle in a shared memory blob parameter map.
58+
OPENVINO_C_VAR(const char*) ov_property_key_intel_gpu_dev_object_handle;
59+
60+
//!< Read-write property<uint32_t string>: video decoder surface plane in a shared memory blob parameter map.
61+
OPENVINO_C_VAR(const char*) ov_property_key_intel_gpu_va_plane;

src/bindings/c/include/openvino/c/openvino.h

+1
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@
2929
#include "openvino/c/ov_rank.h"
3030
#include "openvino/c/ov_shape.h"
3131
#include "openvino/c/ov_tensor.h"
32+
#include "openvino/c/ov_remote_context.h"

src/bindings/c/include/openvino/c/ov_common.h

+4
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@
120120
* @defgroup ov_tensor_c_api Tensor
121121
* @ingroup ov_c_api
122122
* @brief The definitions & operations about tensor
123+
*
124+
* @defgroup ov_remote_context_c_api ov_remote_context
125+
* @ingroup ov_c_api
126+
* @brief Set of functions representing of RemoteContext
123127
*/
124128

125129
/**

src/bindings/c/include/openvino/c/ov_compiled_model.h

+13
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "openvino/c/ov_model.h"
1717
#include "openvino/c/ov_node.h"
1818
#include "openvino/c/ov_property.h"
19+
#include "openvino/c/ov_remote_context.h"
1920

2021
/**
2122
* @struct ov_compiled_model_t
@@ -183,3 +184,15 @@ ov_compiled_model_export_model(const ov_compiled_model_t* compiled_model,
183184
*/
184185
OPENVINO_C_API(void)
185186
ov_compiled_model_free(ov_compiled_model_t* compiled_model);
187+
188+
/**
189+
* @brief Returns pointer to device-specific shared context
190+
* on a remote accelerator device that was used to create this CompiledModel.
191+
* @ingroup ov_compiled_model_c_api
192+
* @param compiled_model A pointer to the ov_compiled_model_t.
193+
* @param context Return context.
194+
* @return Status code of the operation: OK(0) for success.
195+
*
196+
*/
197+
OPENVINO_C_API(ov_status_e)
198+
ov_compiled_model_get_context(const ov_compiled_model_t* compiled_model, ov_remote_context_t** context);

src/bindings/c/include/openvino/c/ov_core.h

+51-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "openvino/c/ov_model.h"
1616
#include "openvino/c/ov_node.h"
1717
#include "openvino/c/ov_property.h"
18+
#include "openvino/c/ov_remote_context.h"
1819
#include "openvino/c/ov_tensor.h"
1920

2021
/**
@@ -341,7 +342,54 @@ ov_core_get_versions_by_device_name(const ov_core_t* core,
341342
/**
342343
* @brief Releases memory occupied by ov_core_version_list_t.
343344
* @ingroup ov_core_c_api
344-
* @param vers A pointer to the ie_core_versions to free memory.
345+
* @param versions A pointer to the ie_core_versions to free memory.
345346
*/
346-
OPENVINO_C_API(void)
347-
ov_core_versions_free(ov_core_version_list_t* versions);
347+
OPENVINO_C_API(void) ov_core_versions_free(ov_core_version_list_t* versions);
348+
349+
/**
350+
* @brief Creates a new remote shared context object on the specified accelerator device
351+
* using specified plugin-specific low-level device API parameters (device handle, pointer, context, etc.).
352+
* @ingroup ov_core_c_api
353+
* @param core A pointer to the ov_core_t instance.
354+
* @param device_name Device name to identify a plugin.
355+
* @param context_args_size How many property args will be for this remote context creation.
356+
* @param context A pointer to the newly created remote context.
357+
* @param variadic parmameters Actual context property parameter for remote context
358+
* @return Status code of the operation: OK(0) for success.
359+
*/
360+
OPENVINO_C_API(ov_status_e)
361+
ov_core_create_context(const ov_core_t* core,
362+
const char* device_name,
363+
const size_t context_args_size,
364+
ov_remote_context_t** context,
365+
...);
366+
367+
/**
368+
* @brief Creates a compiled model from a source model within a specified remote context.
369+
* @ingroup ov_core_c_api
370+
* @param core A pointer to the ov_core_t instance.
371+
* @param model Model object acquired from ov_core_read_model.
372+
* @param context A pointer to the newly created remote context.
373+
* @param property_args_size How many args will be for this compiled model.
374+
* @param compiled_model A pointer to the newly created compiled_model.
375+
* @param variadic parmameters Actual property parameter for remote context
376+
* @return Status code of the operation: OK(0) for success.
377+
*/
378+
OPENVINO_C_API(ov_status_e)
379+
ov_core_compile_model_with_context(const ov_core_t* core,
380+
const ov_model_t* model,
381+
const ov_remote_context_t* context,
382+
const size_t property_args_size,
383+
ov_compiled_model_t** compiled_model,
384+
...);
385+
386+
/**
387+
* @brief Gets a pointer to default (plugin-supplied) shared context object for the specified accelerator device.
388+
* @ingroup ov_core_c_api
389+
* @param core A pointer to the ov_core_t instance.
390+
* @param device_name Name of a device to get a default shared context from.
391+
* @param context A pointer to the referenced remote context.
392+
* @return Status code of the operation: OK(0) for success.
393+
*/
394+
OPENVINO_C_API(ov_status_e)
395+
ov_core_get_default_context(const ov_core_t* core, const char* device_name, ov_remote_context_t** context);

src/bindings/c/include/openvino/c/ov_prepostprocess.h

+38-3
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ ov_preprocess_preprocess_steps_reverse_channels(ov_preprocess_preprocess_steps_t
274274
* @ingroup ov_prepostprocess_c_api
275275
* @param preprocess_input_tensor_info A pointer to the ov_preprocess_input_tensor_info_t.
276276
* @param element_type A point to element_type
277+
* @return Status code of the operation: OK(0) for success.
277278
*/
278279
OPENVINO_C_API(ov_status_e)
279280
ov_preprocess_input_tensor_info_set_element_type(
@@ -285,30 +286,59 @@ ov_preprocess_input_tensor_info_set_element_type(
285286
* @ingroup ov_prepostprocess_c_api
286287
* @param preprocess_input_tensor_info A pointer to the ov_preprocess_input_tensor_info_t.
287288
* @param colorFormat The enumerate of colorFormat
289+
* @return Status code of the operation: OK(0) for success.
288290
*/
289291
OPENVINO_C_API(ov_status_e)
290-
ov_preprocess_input_tensor_info_set_color_format(
291-
ov_preprocess_input_tensor_info_t* preprocess_input_tensor_info,
292-
const ov_color_format_e colorFormat);
292+
ov_preprocess_input_tensor_info_set_color_format(ov_preprocess_input_tensor_info_t* preprocess_input_tensor_info,
293+
const ov_color_format_e colorFormat);
294+
295+
/**
296+
* @brief Set ov_preprocess_input_tensor_info_t color format with subname.
297+
* @ingroup ov_prepostprocess_c_api
298+
* @param preprocess_input_tensor_info A pointer to the ov_preprocess_input_tensor_info_t.
299+
* @param colorFormat The enumerate of colorFormat
300+
* @param sub_names_size The size of sub_names
301+
* @param variadic params sub_names Optional list of sub-names assigned for each plane (e.g. "Y", "UV").
302+
* @return Status code of the operation: OK(0) for success.
303+
*/
304+
OPENVINO_C_API(ov_status_e)
305+
ov_preprocess_input_tensor_info_set_color_format_with_subname(
306+
ov_preprocess_input_tensor_info_t* preprocess_input_tensor_info,
307+
const ov_color_format_e colorFormat,
308+
const size_t sub_names_size,
309+
...);
293310

294311
/**
295312
* @brief Set ov_preprocess_input_tensor_info_t spatial_static_shape.
296313
* @ingroup ov_prepostprocess_c_api
297314
* @param preprocess_input_tensor_info A pointer to the ov_preprocess_input_tensor_info_t.
298315
* @param input_height The height of input
299316
* @param input_width The width of input
317+
* @return Status code of the operation: OK(0) for success.
300318
*/
301319
OPENVINO_C_API(ov_status_e)
302320
ov_preprocess_input_tensor_info_set_spatial_static_shape(
303321
ov_preprocess_input_tensor_info_t* preprocess_input_tensor_info,
304322
const size_t input_height,
305323
const size_t input_width);
306324

325+
/**
326+
* @brief Set ov_preprocess_input_tensor_info_t memory type.
327+
* @ingroup prepostprocess
328+
* @param preprocess_input_tensor_info A pointer to the ov_preprocess_input_tensor_info_t.
329+
* @param mem_type Memory type. Refer to ov_remote_context.h to get memory type string info.
330+
* @return Status code of the operation: OK(0) for success.
331+
*/
332+
OPENVINO_C_API(ov_status_e)
333+
ov_preprocess_input_tensor_info_set_memory_type(ov_preprocess_input_tensor_info_t* preprocess_input_tensor_info,
334+
const char* mem_type);
335+
307336
/**
308337
* @brief Convert ov_preprocess_preprocess_steps_t element type.
309338
* @ingroup ov_prepostprocess_c_api
310339
* @param preprocess_input_steps A pointer to the ov_preprocess_preprocess_steps_t.
311340
* @param element_type preprocess input element type.
341+
* @return Status code of the operation: OK(0) for success.
312342
*/
313343
OPENVINO_C_API(ov_status_e)
314344
ov_preprocess_preprocess_steps_convert_element_type(
@@ -320,6 +350,7 @@ ov_preprocess_preprocess_steps_convert_element_type(
320350
* @ingroup ov_prepostprocess_c_api
321351
* @param preprocess_input_steps A pointer to the ov_preprocess_preprocess_steps_t.
322352
* @param colorFormat The enumerate of colorFormat.
353+
* @return Status code of the operation: OK(0) for success.
323354
*/
324355
OPENVINO_C_API(ov_status_e)
325356
ov_preprocess_preprocess_steps_convert_color(
@@ -331,6 +362,7 @@ ov_preprocess_preprocess_steps_convert_color(
331362
* @ingroup ov_prepostprocess_c_api
332363
* @param preprocess_input_tensor_info A pointer to the ov_preprocess_input_tensor_info_t.
333364
* @param tensor A point to ov_tensor_t
365+
* @return Status code of the operation: OK(0) for success.
334366
*/
335367
OPENVINO_C_API(ov_status_e)
336368
ov_preprocess_input_tensor_info_set_from(
@@ -342,6 +374,7 @@ ov_preprocess_input_tensor_info_set_from(
342374
* @ingroup ov_prepostprocess_c_api
343375
* @param preprocess_input_tensor_info A pointer to the ov_preprocess_input_tensor_info_t.
344376
* @param layout A point to ov_layout_t
377+
* @return Status code of the operation: OK(0) for success.
345378
*/
346379
OPENVINO_C_API(ov_status_e)
347380
ov_preprocess_input_tensor_info_set_layout(
@@ -422,6 +455,7 @@ ov_preprocess_output_tensor_info_free(
422455
* @ingroup ov_prepostprocess_c_api
423456
* @param preprocess_output_tensor_info A pointer to the ov_preprocess_output_tensor_info_t.
424457
* @param element_type A point to element_type
458+
* @return Status code of the operation: OK(0) for success.
425459
*/
426460
OPENVINO_C_API(ov_status_e)
427461
ov_preprocess_output_set_element_type(
@@ -453,6 +487,7 @@ ov_preprocess_input_model_info_free(ov_preprocess_input_model_info_t* preprocess
453487
* @ingroup ov_prepostprocess_c_api
454488
* @param preprocess_input_model_info A pointer to the ov_preprocess_input_model_info_t
455489
* @param layout A point to ov_layout_t
490+
* @return Status code of the operation: OK(0) for success.
456491
*/
457492
OPENVINO_C_API(ov_status_e)
458493
ov_preprocess_input_model_info_set_layout(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
// Copyright (C) 2018-2022 Intel Corporation
2+
// SPDX-License-Identifier: Apache-2.0
3+
//
4+
5+
/**
6+
* @brief This is a header file for ov_remote_context C API
7+
*
8+
* @file ov_remote_context.h
9+
*/
10+
#pragma once
11+
#include "openvino/c/ov_common.h"
12+
#include "openvino/c/ov_shape.h"
13+
#include "openvino/c/ov_tensor.h"
14+
#include "openvino/c/gpu/gpu_plugin_properties.h"
15+
16+
typedef struct ov_remote_context ov_remote_context_t;
17+
18+
/**
19+
* @brief Allocates memory tensor in device memory or wraps user-supplied memory handle
20+
* using the specified tensor description and low-level device-specific parameters.
21+
* Returns a pointer to the object that implements the RemoteTensor interface.
22+
* @ingroup ov_remote_context_c_api
23+
* @param context A pointer to the ov_remote_context_t instance.
24+
* @param type Defines the element type of the tensor.
25+
* @param shape Defines the shape of the tensor.
26+
* @param object_args_size Size of the low-level tensor object parameters.
27+
* @param remote_tensor Pointer to returned ov_tensor_t that contains remote tensor instance.
28+
* @param variadic params Contains low-level tensor object parameters.
29+
* @return Status code of the operation: OK(0) for success.
30+
*/
31+
OPENVINO_C_API(ov_status_e)
32+
ov_remote_context_create_tensor(const ov_remote_context_t* context,
33+
const ov_element_type_e type,
34+
const ov_shape_t shape,
35+
const size_t object_args_size,
36+
ov_tensor_t** remote_tensor,
37+
...);
38+
39+
/**
40+
* @brief Returns name of a device on which underlying object is allocated.
41+
* @ingroup ov_remote_context_c_api
42+
* @param context A pointer to the ov_remote_context_t instance.
43+
* @param device_name Device name will be returned.
44+
* @return Status code of the operation: OK(0) for success.
45+
*/
46+
OPENVINO_C_API(ov_status_e)
47+
ov_remote_context_get_device_name(const ov_remote_context_t* context, char** device_name);
48+
49+
/**
50+
* @brief Returns a string contains device-specific parameters required for low-level
51+
* operations with the underlying object.
52+
* Parameters include device/context handles, access flags,
53+
* etc. Content of the returned map depends on a remote execution context that is
54+
* currently set on the device (working scenario).
55+
* One actaul example: "CONTEXT_TYPE OCL OCL_CONTEXT 0x5583b2ec7b40 OCL_QUEUE 0x5583b2e98ff0"
56+
* @ingroup ov_remote_context_c_api
57+
* @param context A pointer to the ov_remote_context_t instance.
58+
* @param size The size of param pairs.
59+
* @param params Param name:value list.
60+
* @return Status code of the operation: OK(0) for success.
61+
*/
62+
OPENVINO_C_API(ov_status_e)
63+
ov_remote_context_get_params(const ov_remote_context_t* context, size_t* size, char** params);
64+
65+
/**
66+
* @brief This method is used to create a host tensor object friendly for the device in current context.
67+
* For example, GPU context may allocate USM host memory (if corresponding extension is available),
68+
* which could be more efficient than regular host memory.
69+
* @ingroup ov_remote_context_c_api
70+
* @param context A pointer to the ov_remote_context_t instance.
71+
* @param type Defines the element type of the tensor.
72+
* @param shape Defines the shape of the tensor.
73+
* @param tensor Pointer to ov_tensor_t that contains host tensor.
74+
* @return Status code of the operation: OK(0) for success.
75+
*/
76+
OPENVINO_C_API(ov_status_e)
77+
ov_remote_context_create_host_tensor(const ov_remote_context_t* context,
78+
const ov_element_type_e type,
79+
const ov_shape_t shape,
80+
ov_tensor_t** tensor);
81+
82+
/**
83+
* @brief Release the memory allocated by ov_remote_context_t.
84+
* @ingroup ov_remote_context_c_api
85+
* @param context A pointer to the ov_remote_context_t to free memory.
86+
* @return Status code of the operation: OK(0) for success.
87+
*/
88+
OPENVINO_C_API(void) ov_remote_context_free(ov_remote_context_t* context);
89+
90+
/**
91+
* @brief Returns a string contains device-specific parameters required for low-level
92+
* operations with underlying object.
93+
* Parameters include device/context/surface/buffer handles, access flags,
94+
* etc. Content of the returned map depends on remote execution context that is
95+
* currently set on the device (working scenario).
96+
* One example: "MEM_HANDLE:0x559ff6904b00;OCL_CONTEXT:0x559ff71d62f0;SHARED_MEM_TYPE:OCL_BUFFER;"
97+
* @ingroup ov_remote_context_c_api
98+
* @param tensor Pointer to ov_tensor_t that contains host tensor.
99+
* @param size The size of param pairs.
100+
* @param params Param name:value list.
101+
* @return Status code of the operation: OK(0) for success.
102+
*/
103+
OPENVINO_C_API(ov_status_e)
104+
ov_remote_tensor_get_params(ov_tensor_t* tensor, size_t* size, char** params);
105+
106+
/**
107+
* @brief Returns name of a device on which underlying object is allocated.
108+
* @ingroup ov_remote_context_c_api
109+
* @param remote_tensor A pointer to the remote tensor instance.
110+
* @param device_name Device name will be return.
111+
* @return Status code of the operation: OK(0) for success.
112+
*/
113+
OPENVINO_C_API(ov_status_e)
114+
ov_remote_tensor_get_device_name(ov_tensor_t* remote_tensor, char** device_name);

0 commit comments

Comments
 (0)