[CAPI] improve property implement to achieve better compatibility (#12887)

* Solve some code style issues

Change-Id: I06c31ad9513463c758db96dbe33031983a8fd7a5

* Refine ov_dimension with C style structure

Use C style definition to replace opaque C++ handle:
 1). Improve partial shape
 2). Improve dimension/rank
 3). Improve shape

Change-Id: I680fd3e76c63d0c06d9d8b07c67af0440fb15bb7

* Some minor update

Change-Id: I237490a765e6ecd6f3896b1bd75d5f962304f43b

* add partial_shape_is_dynamic and update doc

Change-Id: Ief358f27de8386e35485d08847c8243d1490157f

* Rename property and add basic test cases

Change-Id: Ifbed0bbf7a5e836d2cab186763d7e5f8f2cb7d44

* address reviewer's comments

Change-Id: I9a5d1ede6d086906f3777c3d29237986a505db52

* Fix compile error

Change-Id: I72267a8dda32dd8f43c1ea1522d07b392052358f

* Use ov_any_t to replace ov_property_value_t

Change-Id: Ia4062d0da0941c901990bf5f16497ae3c8f2eb0f

* update doc for ov_model

Change-Id: I80183394f16dd1e07ff998993e26f8b903f2402e

* Property key apply string variables replace enum variable

Change-Id: I0e1699862de3913ccdc06ded5b8f8ac5a2bf8773

* Fix compiling error in windows

Change-Id: I4f9c7c746e218db94491c5f4bc5aeda1b3fde62b

* Change init/deinit method to create/free, remove unnecessary methods

Change-Id: Ibc5de039da94e92db494583ab1ff1a63e0586c73

* Pass by value for single C structure data

Change-Id: I289eb56e2ba1ab90942c8c801c585ab0f792952f

* fix dllexport issue in windows

Change-Id: I1632375e5e651fdfa076cdab2d8d1c3e83986549

* Fix static build error

Change-Id: I6633fe4887edad0b3a8b7e10730fb9d36a6ac0cd

* Use pass by value for all transparent structure

Change-Id: I652f6e70b420ef7c5af5cff3f5d482911cf0d75a

* Unify parameter order in  C APIs, input first and then output parameters

Change-Id: Ib89c77d81c314e3a81bfcec9917630abbc896f5e

* Rename preprocess api to be more readable

Change-Id: I0a8ecd005e73e4ba8e90a8f25bedf0739fe31836

* Simplfy property implement for set and get property

Change-Id: Icad41606368cef9520b1623f6207784c295f1b9f

* check string type property issue

Change-Id: Ie8ee6995dda401f1db0cc098e061ffcfd24de92a

* Fix memory leak

Change-Id: Ife8980736be320314eca6fb3f3605e019663e1da

* Check string property data

Change-Id: I542a136ff874cb345c67f7d3c1dbc74981a909df

* Fix issues caused by rebase

Change-Id: I3d675a16cf76980a6414e369a83464a46dec1e49

* Remove some redundant code

Change-Id: Iab6bf7f355ec7a7424d884e620319ed9db80ecf5

* Remove property type from interface

ov_core_set_property will have 2 cases:

1) enum type:  <const char* property_key, ov_property_xxx_e property_value>
2) other: <const char* property_key, const char* property_value>

Change-Id: Id7dec1ac40948d45c4f8baee687652aee92ea75d

* Remove redundant code

Change-Id: I66865d3313e305b0109cb63bd049772a01c0688f

* Remove exception log and update propery size argument

Change-Id: Ia1a60c07c9adf08d175d94a7d5e4298adb27bf80

* Apply string for enum property

Change-Id: I591b1db453a52b5ea9000e0cc3e11edf0ef5f790

* Add test case for MULTI_DEVICE_PRIORITIES

Change-Id: I59e4307564a2560724b4dacdb83c3ed45ea1ce8d

* Fix test issues and add more negative test case

Change-Id: Ib849fb8c098e487a537c1b1ab881f5e905871f73
This commit is contained in:
River Li 2022-09-20 05:59:27 -07:00 committed by GitHub
parent 08e397d571
commit ed31a46b7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 571 additions and 588 deletions

View File

@ -201,8 +201,7 @@ int main(int argc, char** argv) {
CHECK_STATUS(ov_preprocess_prepostprocessor_build(preprocess, &new_model));
// -------- Step 5. Loading a model to the device --------
ov_properties_t* property = NULL;
CHECK_STATUS(ov_core_compile_model(core, new_model, device_name, property, &compiled_model));
CHECK_STATUS(ov_core_compile_model(core, new_model, device_name, 0, &compiled_model));
// -------- Step 6. Create an infer request --------
CHECK_STATUS(ov_compiled_model_create_infer_request(compiled_model, &infer_request));

View File

@ -264,7 +264,7 @@ int main(int argc, char** argv) {
CHECK_STATUS(ov_preprocess_prepostprocessor_build(preprocess, &new_model));
// -------- Step 4. Loading a model to the device --------
CHECK_STATUS(ov_core_compile_model(core, new_model, device_name, NULL, &compiled_model));
CHECK_STATUS(ov_core_compile_model(core, new_model, device_name, 0, &compiled_model));
// -------- Step 5. Create an infer request --------
CHECK_STATUS(ov_compiled_model_create_infer_request(compiled_model, &infer_request));

View File

@ -75,6 +75,8 @@ typedef enum {
*/
INVALID_C_PARAM = -14,
UNKNOWN_C_ERROR = -15,
NOT_IMPLEMENT_C_METHOD = -16,
UNKNOW_EXCEPTION = -17,
} ov_status_e;
/**
@ -102,38 +104,6 @@ typedef enum {
U64, //!< u64 element type
} ov_element_type_e;
/**
* @enum ov_any_type_e
* @brief Enum to define ov_any data type.
*/
typedef enum {
BOOL = 0U, //!< boolean data
CHAR, //!< char data
INT32, //!< int32 data
UINT32, //!< uint32 data
INT64, //!< int64 data
UINT64, //!< uint64 data
ENUM, //!< enum data, must define U32 data for enumeration
FLOAT, //!< float data
DOUBLE, //!< double data
} ov_any_type_e;
/**
* @struct ov_any_t
* @brief Represent a property value
*/
typedef struct {
void* ptr;
size_t size;
ov_any_type_e type;
} ov_any_t;
/**
* @brief Free ov_any data.
* @param value The ov_any data will be freed.
*/
OPENVINO_C_API(void) ov_any_free(ov_any_t* value);
/**
* @brief Print the error info.
* @param ov_status_e a status code.

View File

@ -139,25 +139,29 @@ OPENVINO_C_API(ov_status_e)
ov_compiled_model_create_infer_request(const ov_compiled_model_t* compiled_model, ov_infer_request_t** infer_request);
/**
* @brief Sets properties for the current compiled model.
* @brief Sets properties for a device, acceptable keys can be found in ov_property_key_xxx.
* @ingroup compiled_model
* @param compiled_model A pointer to the ov_compiled_model_t.
* @param property ov_properties_t.
* @param property_key The property key.
* @param ... variadic paramaters The format is <char *property_key, char* property_value>.
* Supported property key please see ov_property.h.
* @return Status code of the operation: OK(0) for success.
*/
OPENVINO_C_API(ov_status_e)
ov_compiled_model_set_property(const ov_compiled_model_t* compiled_model, const ov_properties_t* property);
ov_compiled_model_set_property(const ov_compiled_model_t* compiled_model, ...);
/**
* @brief Gets properties for current compiled model.
* @ingroup compiled_model
* @param compiled_model A pointer to the ov_compiled_model_t.
* @param property_name Property name.
* @param property_key Property key.
* @param property_value A pointer to property value.
* @return Status code of the operation: OK(0) for success.
*/
OPENVINO_C_API(ov_status_e)
ov_compiled_model_get_property(const ov_compiled_model_t* compiled_model, const char* key, ov_any_t* value);
ov_compiled_model_get_property(const ov_compiled_model_t* compiled_model,
const char* property_key,
char** property_value);
/**
* @brief Exports the current compiled model to an output stream `std::ostream`.

View File

@ -151,17 +151,19 @@ ov_core_read_model_from_memory(const ov_core_t* core,
* @param core A pointer to the ie_core_t instance.
* @param model Model object acquired from Core::read_model.
* @param device_name Name of a device to load a model to.
* @param property Optional pack of pairs: (property name, property value) relevant only for this load operation
* operation.
* @param property_args_size How many properties args will be passed, each property contains 2 args: key and value.
* @param compiled_model A pointer to the newly created compiled_model.
* @param property paramater: Optional pack of pairs: <char* property_key, char* property_value> relevant only
* for this load operation operation. Supported property key please see ov_property.h.
* @return Status code of the operation: OK(0) for success.
*/
OPENVINO_C_API(ov_status_e)
ov_core_compile_model(const ov_core_t* core,
const ov_model_t* model,
const char* device_name,
const ov_properties_t* property,
ov_compiled_model_t** compiled_model);
const size_t property_args_size,
ov_compiled_model_t** compiled_model,
...);
/**
* @brief Reads a model and creates a compiled model from the IR/ONNX/PDPD file.
@ -171,28 +173,32 @@ ov_core_compile_model(const ov_core_t* core,
* @param core A pointer to the ie_core_t instance.
* @param model_path Path to a model.
* @param device_name Name of a device to load a model to.
* @param property Optional pack of pairs: (property name, property value) relevant only for this load operation
* operation.
* @param property_args_size How many properties args will be passed, each property contains 2 args: key and value.
* @param compiled_model A pointer to the newly created compiled_model.
* @param property paramater: Optional pack of pairs: <char* property_key, char* property_value> relevant only
* for this load operation operation. Supported property key please see ov_property.h.
* @return Status code of the operation: OK(0) for success.
*/
OPENVINO_C_API(ov_status_e)
ov_core_compile_model_from_file(const ov_core_t* core,
const char* model_path,
const char* device_name,
const ov_properties_t* property,
ov_compiled_model_t** compiled_model);
const size_t property_args_size,
ov_compiled_model_t** compiled_model,
...);
/**
* @brief Sets properties for a device, acceptable keys can be found in ov_property_key_e.
* @brief Sets properties for a device, acceptable keys can be found in ov_property_key_xxx.
* @ingroup Core
* @param core A pointer to the ie_core_t instance.
* @param device_name Name of a device.
* @param property ov_property propertys.
* @param property_key The property key.
* @param ... variadic paramaters The format is <char* property_key, char* property_value>.
* Supported property key please see ov_property.h.
* @return Status code of the operation: OK(0) for success.
*/
OPENVINO_C_API(ov_status_e)
ov_core_set_property(const ov_core_t* core, const char* device_name, const ov_properties_t* property);
ov_core_set_property(const ov_core_t* core, const char* device_name, ...);
/**
* @brief Gets properties related to device behaviour.
@ -200,15 +206,12 @@ ov_core_set_property(const ov_core_t* core, const char* device_name, const ov_pr
* @ingroup Core
* @param core A pointer to the ie_core_t instance.
* @param device_name Name of a device to get a property value.
* @param property_name Property name.
* @param property_value A pointer to property value.
* @param property_key Property key.
* @param property_value A pointer to property value with string format.
* @return Status code of the operation: OK(0) for success.
*/
OPENVINO_C_API(ov_status_e)
ov_core_get_property(const ov_core_t* core,
const char* device_name,
const char* property_name,
ov_any_t* property_value);
ov_core_get_property(const ov_core_t* core, const char* device_name, const char* property_key, char** property_value);
/**
* @brief Returns devices available for inference.

View File

@ -13,60 +13,139 @@
#include "openvino/c/ov_common.h"
typedef struct ov_property {
const char* key;
ov_any_t value;
} ov_property_t;
typedef struct ov_properties {
ov_property_t* list;
size_t size;
} ov_properties_t;
/**
* @enum ov_performance_mode_e
* @brief Enum to define possible performance mode hints
* @brief This represents OpenVINO 2.0 ov::hint::PerformanceMode entity.
*
* @brief property key
*/
typedef enum {
UNDEFINED_MODE = -1, //!< Undefined value, performance setting may vary from device to device
LATENCY = 1, //!< Optimize for latency
THROUGHPUT = 2, //!< Optimize for throughput
CUMULATIVE_THROUGHPUT = 3, //!< Optimize for cumulative throughput
} ov_performance_mode_e;
/**
* @enum ov_affinity_e
* @brief Enum to define possible affinity patterns
*/
typedef enum {
NONE = -1, //!< Disable threads affinity pinning
CORE = 0, //!< Pin threads to cores, best for static benchmarks
NUMA = 1, //!< Pin threads to NUMA nodes, best for real-life, contented cases. On the Windows and MacOS* this
//!< option behaves as CORE
HYBRID_AWARE = 2, //!< Let the runtime to do pinning to the cores types, e.g. prefer the "big" cores for latency
//!< tasks. On the hybrid CPUs this option is default
} ov_affinity_e;
//!< Read-only property<string> to get a string list of supported read-only properties.
OPENVINO_C_VAR(const char*) ov_property_key_supported_properties;
//!< Read-only property<string> to get a list of available device IDs
OPENVINO_C_VAR(const char*) ov_property_key_available_devices;
//!< Read-only property<uint32_t string> to get an unsigned integer value of optimaln
//!< number of compiled model infer requests.
OPENVINO_C_VAR(const char*) ov_property_key_optimal_number_of_infer_requests;
//!< Read-only property<string(unsigned int, unsigned int, unsigned int)> to provide a
//!< hint for a range for number of async infer requests. If device supports
//!< streams, the metric provides range for number of IRs per stream.
OPENVINO_C_VAR(const char*) ov_property_key_range_for_async_infer_requests;
//!< Read-only property<string(unsigned int, unsigned int)> to provide information about a range for
//!< streams on platforms where streams are supported
OPENVINO_C_VAR(const char*) ov_property_key_range_for_streams;
//!< Read-only property<string> to get a string value representing a full device name.
OPENVINO_C_VAR(const char*) ov_property_key_device_full_name;
//!< Read-only property<string> to get a string list of capabilities options per device.
OPENVINO_C_VAR(const char*) ov_property_key_device_capabilities;
OPENVINO_C_VAR(const char*) ov_property_key_cache_dir;
OPENVINO_C_VAR(const char*) ov_property_key_num_streams;
OPENVINO_C_VAR(const char*) ov_property_key_affinity;
OPENVINO_C_VAR(const char*) ov_property_key_inference_num_threads;
OPENVINO_C_VAR(const char*) ov_property_key_hint_performance_mode;
//!< Read-only property<string> to get a name of name of a model
OPENVINO_C_VAR(const char*) ov_property_key_model_name;
OPENVINO_C_VAR(const char*) ov_property_key_hint_inference_precision;
//!< Read-only property<uint32_t string> to query information optimal batch size for the given device
//!< and the network
OPENVINO_C_VAR(const char*) ov_property_key_optimal_batch_size;
//!< Read-only property to get maximum batch size which does not cause performance degradation due
//!< to memory swap impact.
OPENVINO_C_VAR(const char*) ov_property_key_max_batch_size;
//!< Read-write property<string> to set/get the directory which will be used to store any data cached
//!< by plugins.
OPENVINO_C_VAR(const char*) ov_property_key_cache_dir;
//!< Read-write property<uint32_t string> to set/get the number of executor logical partitions.
OPENVINO_C_VAR(const char*) ov_property_key_num_streams;
//!< Read-write property to set/get the name for setting CPU affinity per thread option.
//!< All property values are string format, below are optional value:
//!< "NONE" - Disable threads affinity pinning
//!< "CORE" - Pin threads to cores, best for static benchmarks
//!< "NUMA" - Pin threads to NUMA nodes, best for real-life, contented cases. On the Windows and MacOS* this
//!< option behaves as CORE
//!< "HYBRID_AWARE" - Let the runtime to do pinning to the cores types, e.g. prefer the "big" cores for latency
//!< tasks. On the hybrid CPUs this option is default.
OPENVINO_C_VAR(const char*) ov_property_key_affinity;
//!< Read-write property<int32_t string> to set/get the maximum number of threads that can be used
//!< for inference tasks.
OPENVINO_C_VAR(const char*) ov_property_key_inference_num_threads;
//!< Read-write property, it is high-level OpenVINO Performance Hints
//!< unlike low-level properties that are individual (per-device), the hints are something that
//!< every device accepts and turns into device-specific settings detail.
//!< All property values are string, below are optional value:
//!< "UNDEFINED_MODE" - Undefined value, performance setting may vary from device to device
//!< "LATENCY" - Optimize for latency
//!< "THROUGHPUT" - Optimize for throughput
//!< "CUMULATIVE_THROUGHPUT" - Optimize for cumulative throughput
OPENVINO_C_VAR(const char*) ov_property_key_hint_performance_mode;
//!< Read-write property<ov_element_type_e> to set the hint for device to use specified
//!< precision for inference
//!< All property values are string, below are optional value:
//!< "UNDEFINED" - Undefined element type
//!< "DYNAMIC" - Dynamic element type
//!< "BOOLEAN" - boolean element type
//!< "BF16" - bf16 element type
//!< "F16" - f16 element type
//!< "F32" - f32 element type
//!< "F64" - f64 element type
//!< "I4" - i4 element type
//!< "I8" - i8 element type
//!< "I16" - i16 element type
//!< "I32" - i32 element type
//!< "I64" - i64 element type
//!< "U1" - binary element type
//!< "U4" - u4 element type
//!< "U8" - u8 element type
//!< "U16" - u16 element type
//!< "U32" - u32 element type
//!< "U64" - u64 element type
OPENVINO_C_VAR(const char*) ov_property_key_hint_inference_precision;
//!< (Optional) Read-write property<uint32_t string> that backs the Performance Hints by giving
//!< additional information on how many inference requests the application will be
//!< keeping in flight usually this value comes from the actual use-case (e.g.
//!< number of video-cameras, or other sources of inputs)
OPENVINO_C_VAR(const char*) ov_property_key_hint_num_requests;
//!< Read-write property<string> for setting desirable log level.
//!< All property values are string, below are optional value:
//!< "NO" - disable any logging
//!< "ERR" - error events that might still allow the application to continue running
//!< "WARNING" - potentially harmful situations which may further lead to ERROR
//!< "INFO" - informational messages that display the progress of the application at coarse-grained level
//!< "DEBUG" - fine-grained events that are most useful to debug an application.
//!< "TRACE" - finer-grained informational events than the DEBUG
OPENVINO_C_VAR(const char*) ov_property_key_log_level;
//!< Read-write property, high-level OpenVINO model priority hint.
//!< Defines what model should be provided with more performant bounded resource first.
//!< All property value are string format, below is optional value:
//!< "LOW" - Low priority
//!< "MEDIUM" - Medium priority
//!< "HIGH" - High priority
//!< "DEFAULT" - Default priority is MEDIUM
OPENVINO_C_VAR(const char*) ov_property_key_hint_model_priority;
//!< Read-write property<string> for setting performance counters option.
//!< All property values are string, below are optional value:
//!< "YES" - true
//!< "NO" - false
OPENVINO_C_VAR(const char*) ov_property_key_enable_profiling;
//!< Read-write property<std::pair<std::string, Any>>, device Priorities config option, with comma-separated devices
//!< listed in the desired priority
//!< Some optional values for MULTI device:
//! "CPU,GPU"
//! "GPU,CPU"
//! Note: CPU plugin is not implement.
OPENVINO_C_VAR(const char*) ov_property_key_device_priorities;
// Property
/**
* @defgroup Property Property
@ -75,21 +154,4 @@ OPENVINO_C_VAR(const char*) ov_property_key_hint_num_requests;
* @{
*/
/**
* @brief Initialize a properties list object.
* @ingroup property
* @param property The properties list will be initialized.
* @param size The list size.
* @return ov_status_e a status code, return OK if successful
*/
OPENVINO_C_API(ov_status_e) ov_properties_create(ov_properties_t* property, size_t size);
/**
* @brief Deinitialized properties list.
* properties->list[i].value.ptr need be managed by user.
* @ingroup property
* @param property The properties list object will be deinitialized.
*/
OPENVINO_C_API(void) ov_properties_free(ov_properties_t* property);
/** @} */ // end of Property

View File

@ -35,9 +35,15 @@
CATCH_OV_EXCEPTION(NETWORK_NOT_READ, NetworkNotRead) \
CATCH_OV_EXCEPTION(INFER_CANCELLED, InferCancelled) \
catch (...) { \
return ov_status_e::UNEXPECTED; \
return ov_status_e::UNKNOW_EXCEPTION; \
}
#define GET_PROPERTY_FROM_ARGS_LIST \
std::string property_key = va_arg(args_ptr, char*); \
std::string _value = va_arg(args_ptr, char*); \
ov::Any value = _value; \
property[property_key] = value;
/**
* @struct ov_core
* @brief This struct represents OpenVINO Core entity.

View File

@ -22,7 +22,9 @@ char const* error_infos[] = {"success",
"network is not ready",
"inference is canceled",
"invalid c input parameters",
"unknown c error"};
"unknown c error",
"not implement in c method",
"unknown exception"};
const char* ov_get_error_info(ov_status_e status) {
auto index = -status;
@ -32,18 +34,7 @@ const char* ov_get_error_info(ov_status_e status) {
return error_infos[index];
}
void ov_any_free(ov_any_t* value) {
if (value) {
if (value->ptr) {
char* temp = static_cast<char*>(value->ptr);
delete temp;
}
value->ptr = nullptr;
value->size = 0;
}
}
void ov_free(const char* content) {
if (content)
delete content;
delete[] content;
}

View File

@ -3,6 +3,8 @@
//
#include "openvino/c/ov_compiled_model.h"
#include <stdarg.h>
#include "common.h"
//!< Read-only property<char *> to get a string list of supported read-only properties.
@ -173,27 +175,20 @@ ov_status_e ov_compiled_model_create_infer_request(const ov_compiled_model_t* co
return ov_status_e::OK;
}
inline ov_status_e ov_compiled_model_properies_to_anymap(const ov_properties_t* properties, ov::AnyMap& dest) {
if (!properties || properties->size <= 0) {
return ov_status_e::INVALID_C_PARAM;
}
return ov_status_e::NOT_IMPLEMENTED;
}
ov_status_e ov_compiled_model_set_property(const ov_compiled_model_t* compiled_model, const ov_properties_t* property) {
if (!compiled_model || !property) {
ov_status_e ov_compiled_model_set_property(const ov_compiled_model_t* compiled_model, ...) {
if (!compiled_model) {
return ov_status_e::INVALID_C_PARAM;
}
try {
ov::AnyMap dest;
auto ret = ov_compiled_model_properies_to_anymap(property, dest);
if (ret == ov_status_e::OK) {
compiled_model->object->set_property(dest);
} else {
return ret;
}
ov::AnyMap property = {};
va_list args_ptr;
va_start(args_ptr, compiled_model);
GET_PROPERTY_FROM_ARGS_LIST;
va_end(args_ptr);
compiled_model->object->set_property(property);
}
CATCH_OV_EXCEPTIONS
@ -202,30 +197,15 @@ ov_status_e ov_compiled_model_set_property(const ov_compiled_model_t* compiled_m
ov_status_e ov_compiled_model_get_property(const ov_compiled_model_t* compiled_model,
const char* key,
ov_any_t* value) {
if (!compiled_model || !value || !key) {
char** property_value) {
if (!compiled_model || !key || !property_value) {
return ov_status_e::INVALID_C_PARAM;
}
try {
std::string _key = std::string(key);
if (_key == ov_property_key_supported_properties_) {
auto supported_properties = compiled_model->object->get_property(ov::supported_properties);
std::string tmp_s;
for (const auto& i : supported_properties) {
tmp_s = tmp_s + "\n" + i;
}
char* temp = new char[tmp_s.length() + 1];
std::copy_n(tmp_s.c_str(), tmp_s.length() + 1, temp);
value->ptr = static_cast<void*>(temp);
value->size = tmp_s.length() + 1;
value->type = ov_any_type_e::CHAR;
} else {
return ov_status_e::NOT_IMPLEMENTED;
}
auto value = compiled_model->object->get_property(key);
*property_value = str_to_char_array(value.as<std::string>());
}
CATCH_OV_EXCEPTIONS
return ov_status_e::OK;
}

View File

@ -3,74 +3,10 @@
//
#include "openvino/c/ov_core.h"
#include <stdarg.h>
#include "common.h"
//!< Read-only property<char *> to get a string list of supported read-only properties.
const char* ov_property_key_supported_properties = "SUPPORTED_PROPERTIES";
//!< Read-only property<char *> to get a list of available device IDs
const char* ov_property_key_available_devices = "AVAILABLE_DEVICES";
//!< Read-only property<uint32_t> to get an unsigned integer value of optimaln
//!< number of compiled model infer requests.
const char* ov_property_key_optimal_number_of_infer_requests = "OPTIMAL_NUMBER_OF_INFER_REQUESTS";
//!< Read-only property<unsigned int, unsigned int, unsigned int> to provide a
//!< hint for a range for number of async infer requests. If device supports
//!< streams, the metric provides range for number of IRs per stream.
const char* ov_property_key_range_for_async_infer_requests = "RANGE_FOR_ASYNC_INFER_REQUESTS";
//!< Read-only property<unsigned int, unsigned int> to provide information about a range for
//!< streams on platforms where streams are supported
const char* ov_property_key_range_for_streams = "RANGE_FOR_STREAMS";
//!< Read-only property<char *> to get a string value representing a full device name.
const char* ov_property_key_device_full_name = "FULL_DEVICE_NAME";
//!< Read-only property<char *> to get a string list of capabilities options per device.
const char* ov_property_key_device_capabilities = "OPTIMIZATION_CAPABILITIES";
//!< Read-write property<char *> to set/get the directory which will be used to store any data cached
//!< by plugins.
const char* ov_property_key_cache_dir = "CACHE_DIR";
//!< Read-write property<uint32_t> to set/get the number of executor logical partitions.
const char* ov_property_key_num_streams = "NUM_STREAMS";
//!< Read-write property to set/get the name for setting CPU affinity per thread option.
const char* ov_property_key_affinity = "AFFINITY";
//!< Read-write property<int32_t> to set/get the maximum number of threads that can be used
//!< for inference tasks.
const char* ov_property_key_inference_num_threads = "INFERENCE_NUM_THREADS";
//!< Read-write property<ov_performance_mode_e>, it is high-level OpenVINO Performance Hints
//!< unlike low-level properties that are individual (per-device), the hints are something that
//!< every device accepts and turns into device-specific settings detail see
//!< ov_performance_mode_e to get its hint's key name
const char* ov_property_key_hint_performance_mode = "PERFORMANCE_HINT";
//!< Read-only property<char *> to get a name of name of a model
const char* ov_property_key_model_name = "NETWORK_NAME";
//!< Read-write property<ov_element_type_e> to set the hint for device to use specified
//!< precision for inference
const char* ov_property_key_hint_inference_precision = "INFERENCE_PRECISION_HINT";
//!< Read-only property<uint32_t> to query information optimal batch size for the given device
//!< and the network
const char* ov_property_key_optimal_batch_size = "OPTIMAL_BATCH_SIZE";
//!< Read-only property to get maximum batch size which does not cause performance degradation due
//!< to memory swap impact.
const char* ov_property_key_max_batch_size = "MAX_BATCH_SIZE";
//!< (Optional) property<uint32_t> that backs the Performance Hints by giving
//!< additional information on how many inference requests the application will be
//!< keeping in flight usually this value comes from the actual use-case (e.g.
//!< number of video-cameras, or other sources of inputs)
const char* ov_property_key_hint_num_requests = "PERFORMANCE_HINT_NUM_REQUESTS";
char* str_to_char_array(const std::string& str) {
std::unique_ptr<char> _char_array(new char[str.length() + 1]);
char* char_array = _char_array.release();
@ -174,20 +110,30 @@ ov_status_e ov_core_read_model_from_memory(const ov_core_t* core,
ov_status_e ov_core_compile_model(const ov_core_t* core,
const ov_model_t* model,
const char* device_name,
const ov_properties_t* property,
ov_compiled_model_t** compiled_model) {
if (!core || !model || !compiled_model) {
const size_t property_args_size,
ov_compiled_model_t** compiled_model,
...) {
if (!core || !model || !compiled_model || property_args_size % 2 != 0) {
return ov_status_e::INVALID_C_PARAM;
}
try {
ov::AnyMap property = {};
va_list args_ptr;
va_start(args_ptr, compiled_model);
size_t property_size = property_args_size / 2;
for (size_t i = 0; i < property_size; i++) {
GET_PROPERTY_FROM_ARGS_LIST;
}
va_end(args_ptr);
std::string dev_name = "";
ov::CompiledModel object;
if (device_name) {
dev_name = device_name;
object = core->object->compile_model(model->object, dev_name);
object = core->object->compile_model(model->object, dev_name, property);
} else {
object = core->object->compile_model(model->object);
object = core->object->compile_model(model->object, property);
}
std::unique_ptr<ov_compiled_model_t> _compiled_model(new ov_compiled_model_t);
_compiled_model->object = std::make_shared<ov::CompiledModel>(std::move(object));
@ -200,20 +146,30 @@ ov_status_e ov_core_compile_model(const ov_core_t* core,
ov_status_e ov_core_compile_model_from_file(const ov_core_t* core,
const char* model_path,
const char* device_name,
const ov_properties_t* property,
ov_compiled_model_t** compiled_model) {
if (!core || !model_path || !compiled_model) {
const size_t property_args_size,
ov_compiled_model_t** compiled_model,
...) {
if (!core || !model_path || !compiled_model || property_args_size % 2 != 0) {
return ov_status_e::INVALID_C_PARAM;
}
try {
ov::AnyMap property = {};
size_t property_size = property_args_size / 2;
va_list args_ptr;
va_start(args_ptr, compiled_model);
for (size_t i = 0; i < property_size; i++) {
GET_PROPERTY_FROM_ARGS_LIST;
}
va_end(args_ptr);
ov::CompiledModel object;
std::string dev_name = "";
if (device_name) {
dev_name = device_name;
object = core->object->compile_model(model_path, dev_name);
object = core->object->compile_model(model_path, dev_name, property);
} else {
object = core->object->compile_model(model_path);
object = core->object->compile_model(model_path, property);
}
std::unique_ptr<ov_compiled_model_t> _compiled_model(new ov_compiled_model_t);
_compiled_model->object = std::make_shared<ov::CompiledModel>(std::move(object));
@ -223,252 +179,42 @@ ov_status_e ov_core_compile_model_from_file(const ov_core_t* core,
return ov_status_e::OK;
}
const std::map<ov_performance_mode_e, ov::hint::PerformanceMode> performance_mode_map = {
{ov_performance_mode_e::UNDEFINED_MODE, ov::hint::PerformanceMode::UNDEFINED},
{ov_performance_mode_e::THROUGHPUT, ov::hint::PerformanceMode::THROUGHPUT},
{ov_performance_mode_e::LATENCY, ov::hint::PerformanceMode::LATENCY},
{ov_performance_mode_e::CUMULATIVE_THROUGHPUT, ov::hint::PerformanceMode::CUMULATIVE_THROUGHPUT}};
inline ov_status_e ov_core_properies_to_anymap(const ov_properties_t* properties, ov::AnyMap& dest) {
if (!properties || properties->size <= 0) {
ov_status_e ov_core_set_property(const ov_core_t* core, const char* device_name, ...) {
if (!core) {
return ov_status_e::INVALID_C_PARAM;
}
try {
auto size = properties->size;
for (size_t i = 0; i < size; i++) {
auto& property = properties->list[i];
auto& value = property.value;
std::string key = std::string(property.key);
if (key == ov_property_key_hint_num_requests) {
if (value.size != 1 || value.type != ov_any_type_e::UINT32) {
return ov_status_e::INVALID_C_PARAM;
}
uint32_t v = *(static_cast<uint32_t*>(value.ptr));
dest.emplace(ov::hint::num_requests(v));
} else if (key == ov_property_key_num_streams) {
if (value.size != 1 || value.type != ov_any_type_e::UINT32) {
return ov_status_e::INVALID_C_PARAM;
}
uint32_t v = *(static_cast<uint32_t*>(value.ptr));
dest.emplace(ov::num_streams(v));
} else if (key == ov_property_key_hint_performance_mode) {
if (value.size != 1 || value.type != ov_any_type_e::ENUM) {
return ov_status_e::INVALID_C_PARAM;
}
ov_performance_mode_e m = *(static_cast<ov_performance_mode_e*>(value.ptr));
if (m > ov_performance_mode_e::CUMULATIVE_THROUGHPUT) {
return ov_status_e::INVALID_C_PARAM;
}
auto v = performance_mode_map.at(m);
dest.emplace(ov::hint::performance_mode(v));
} else if (key == ov_property_key_affinity) {
if (value.size != 1 || value.type != ov_any_type_e::ENUM) {
return ov_status_e::INVALID_C_PARAM;
}
ov_affinity_e v = *(static_cast<ov_affinity_e*>(value.ptr));
if (v < ov_affinity_e::NONE || v > ov_affinity_e::HYBRID_AWARE) {
return ov_status_e::INVALID_C_PARAM;
}
ov::Affinity affinity = static_cast<ov::Affinity>(v);
dest.emplace(ov::affinity(affinity));
} else if (key == ov_property_key_inference_num_threads) {
if (value.size != 1 || value.type != ov_any_type_e::INT32) {
return ov_status_e::INVALID_C_PARAM;
}
int32_t v = *(static_cast<int32_t*>(value.ptr));
dest.emplace(ov::inference_num_threads(v));
} else if (key == ov_property_key_hint_inference_precision) {
if (value.size != 1 || value.type != ov_any_type_e::ENUM) {
return ov_status_e::INVALID_C_PARAM;
}
ov_element_type_e v = *(static_cast<ov_element_type_e*>(value.ptr));
if (v > ov_element_type_e::U64) {
return ov_status_e::INVALID_C_PARAM;
}
ov::element::Type type(static_cast<ov::element::Type_t>(v));
dest.emplace(ov::hint::inference_precision(type));
} else if (key == ov_property_key_cache_dir) {
if (value.size < 1 || value.type != ov_any_type_e::CHAR) {
return ov_status_e::INVALID_C_PARAM;
}
char* dir = static_cast<char*>(value.ptr);
dest.emplace(ov::cache_dir(std::string(dir)));
} else {
return ov_status_e::NOT_IMPLEMENTED;
}
} // end of for
}
CATCH_OV_EXCEPTIONS
return ov_status_e::OK;
}
ov::AnyMap property = {};
va_list args_ptr;
va_start(args_ptr, device_name);
GET_PROPERTY_FROM_ARGS_LIST;
va_end(args_ptr);
ov_status_e ov_core_set_property(const ov_core_t* core, const char* device_name, const ov_properties_t* property) {
if (!core || !property) {
return ov_status_e::INVALID_C_PARAM;
}
try {
ov::AnyMap dest;
auto ret = ov_core_properies_to_anymap(property, dest);
if (ret != ov_status_e::OK) {
return ret;
if (property.size() == 0) {
return ov_status_e::INVALID_C_PARAM;
}
if (device_name) {
core->object->set_property(device_name, dest);
core->object->set_property(device_name, property);
} else {
core->object->set_property(dest);
core->object->set_property(property);
}
}
CATCH_OV_EXCEPTIONS
return ov_status_e::OK;
}
ov_status_e ov_core_get_property(const ov_core_t* core, const char* device_name, const char* key, ov_any_t* value) {
if (!core || !value || !key) {
ov_status_e ov_core_get_property(const ov_core_t* core,
const char* device_name,
const char* property_key,
char** property_value) {
if (!core || !property_key || !property_value) {
return ov_status_e::INVALID_C_PARAM;
}
try {
std::string _key = std::string(key);
if (_key == ov_property_key_supported_properties) {
auto supported_properties = core->object->get_property(device_name, ov::supported_properties);
std::string tmp_s;
for (const auto& i : supported_properties) {
tmp_s = tmp_s + "\n" + i;
}
char* tmp = new char[tmp_s.length() + 1];
std::copy_n(tmp_s.begin(), tmp_s.length() + 1, tmp);
value->ptr = static_cast<void*>(tmp);
value->size = tmp_s.length() + 1;
value->type = ov_any_type_e::CHAR;
} else if (_key == ov_property_key_available_devices) {
auto available_devices = core->object->get_property(device_name, ov::available_devices);
std::string tmp_s;
for (const auto& i : available_devices) {
tmp_s = tmp_s + "\n" + i;
}
char* tmp = new char[tmp_s.length() + 1];
std::copy_n(tmp_s.begin(), tmp_s.length() + 1, tmp);
value->ptr = static_cast<void*>(tmp);
value->size = tmp_s.length() + 1;
value->type = ov_any_type_e::CHAR;
} else if (_key == ov_property_key_optimal_number_of_infer_requests) {
auto optimal_number_of_infer_requests =
core->object->get_property(device_name, ov::optimal_number_of_infer_requests);
uint32_t* temp = new uint32_t;
*temp = optimal_number_of_infer_requests;
value->ptr = static_cast<void*>(temp);
value->size = 1;
value->type = ov_any_type_e::UINT32;
} else if (_key == ov_property_key_range_for_async_infer_requests) {
auto range = core->object->get_property(device_name, ov::range_for_async_infer_requests);
uint32_t* temp = new uint32_t[3];
temp[0] = std::get<0>(range);
temp[1] = std::get<1>(range);
temp[2] = std::get<2>(range);
value->ptr = static_cast<void*>(temp);
value->size = 3;
value->type = ov_any_type_e::UINT32;
} else if (_key == ov_property_key_range_for_streams) {
auto range = core->object->get_property(device_name, ov::range_for_streams);
uint32_t* temp = new uint32_t[2];
temp[0] = std::get<0>(range);
temp[1] = std::get<1>(range);
value->ptr = static_cast<void*>(temp);
value->size = 2;
value->type = ov_any_type_e::UINT32;
} else if (_key == ov_property_key_device_full_name) {
auto name = core->object->get_property(device_name, ov::device::full_name);
char* tmp = new char[name.length() + 1];
std::copy_n(name.begin(), name.length() + 1, tmp);
value->ptr = static_cast<void*>(tmp);
value->size = name.length() + 1;
value->type = ov_any_type_e::CHAR;
} else if (_key == ov_property_key_device_capabilities) {
auto capabilities = core->object->get_property(device_name, ov::device::capabilities);
std::string tmp_s;
for (const auto& i : capabilities) {
tmp_s = tmp_s + "\n" + i;
}
char* tmp = new char[tmp_s.length() + 1];
std::copy_n(tmp_s.begin(), tmp_s.length() + 1, tmp);
value->ptr = static_cast<void*>(tmp);
value->size = tmp_s.length() + 1;
value->type = ov_any_type_e::CHAR;
} else if (_key == ov_property_key_cache_dir) {
auto dir = core->object->get_property(device_name, ov::cache_dir);
char* tmp = new char[dir.length() + 1];
std::copy_n(dir.begin(), dir.length() + 1, tmp);
value->ptr = static_cast<void*>(tmp);
value->size = dir.length() + 1;
value->type = ov_any_type_e::CHAR;
} else if (_key == ov_property_key_num_streams) {
auto num = core->object->get_property(device_name, ov::num_streams);
int32_t* temp = new int32_t;
*temp = num.num;
value->ptr = static_cast<void*>(temp);
value->size = 1;
value->type = ov_any_type_e::INT32;
} else if (_key == ov_property_key_affinity) {
auto affinity = core->object->get_property(device_name, ov::affinity);
ov_affinity_e* temp = new ov_affinity_e;
*temp = static_cast<ov_affinity_e>(affinity);
value->ptr = static_cast<void*>(temp);
value->size = 1;
value->type = ov_any_type_e::ENUM;
} else if (_key == ov_property_key_inference_num_threads) {
auto num = core->object->get_property(device_name, ov::inference_num_threads);
int32_t* temp = new int32_t;
*temp = num;
value->ptr = static_cast<void*>(temp);
value->size = 1;
value->type = ov_any_type_e::INT32;
} else if (_key == ov_property_key_hint_performance_mode) {
auto perf_mode = core->object->get_property(device_name, ov::hint::performance_mode);
ov_performance_mode_e* temp = new ov_performance_mode_e;
*temp = static_cast<ov_performance_mode_e>(perf_mode);
value->ptr = static_cast<void*>(temp);
value->size = 1;
value->type = ov_any_type_e::ENUM;
} else if (_key == ov_property_key_model_name) {
auto name = core->object->get_property(device_name, ov::model_name);
char* tmp = new char[name.length() + 1];
std::copy_n(name.begin(), name.length() + 1, tmp);
value->ptr = static_cast<void*>(tmp);
value->size = name.length() + 1;
value->type = ov_any_type_e::CHAR;
} else if (_key == ov_property_key_hint_inference_precision) {
auto infer_precision = core->object->get_property(device_name, ov::hint::inference_precision);
ov_element_type_e* temp = new ov_element_type_e;
*temp = static_cast<ov_element_type_e>(ov::element::Type_t(infer_precision));
value->ptr = static_cast<void*>(temp);
value->size = 1;
value->type = ov_any_type_e::ENUM;
} else if (_key == ov_property_key_optimal_batch_size) {
auto batch_size = core->object->get_property(device_name, ov::optimal_batch_size);
uint32_t* temp = new uint32_t;
*temp = batch_size;
value->ptr = static_cast<void*>(temp);
value->size = 1;
value->type = ov_any_type_e::UINT32;
} else if (_key == ov_property_key_max_batch_size) {
auto batch_size = core->object->get_property(device_name, ov::max_batch_size);
uint32_t* temp = new uint32_t;
*temp = batch_size;
value->ptr = static_cast<void*>(temp);
value->size = 1;
value->type = ov_any_type_e::UINT32;
} else if (_key == ov_property_key_hint_num_requests) {
auto num_requests = core->object->get_property(device_name, ov::hint::num_requests);
uint32_t* temp = new uint32_t;
*temp = num_requests;
value->ptr = static_cast<void*>(temp);
value->size = 1;
value->type = ov_any_type_e::UINT32;
} else {
return ov_status_e::OUT_OF_BOUNDS;
}
auto value = core->object->get_property(device_name, property_key);
*property_value = str_to_char_array(value.as<std::string>());
}
CATCH_OV_EXCEPTIONS
return ov_status_e::OK;

View File

@ -5,22 +5,27 @@
#include "common.h"
ov_status_e ov_properties_create(ov_properties_t* property, size_t size) {
if (!property || size < 0) {
return ov_status_e::INVALID_C_PARAM;
}
try {
std::unique_ptr<ov_property_t> _property(new ov_property_t[size]);
property->list = _property.release();
property->size = size;
}
CATCH_OV_EXCEPTIONS
return ov_status_e::OK;
}
// Read-only property key
const char* ov_property_key_supported_properties = "SUPPORTED_PROPERTIES";
const char* ov_property_key_available_devices = "AVAILABLE_DEVICES";
const char* ov_property_key_optimal_number_of_infer_requests = "OPTIMAL_NUMBER_OF_INFER_REQUESTS";
const char* ov_property_key_range_for_async_infer_requests = "RANGE_FOR_ASYNC_INFER_REQUESTS";
const char* ov_property_key_range_for_streams = "RANGE_FOR_STREAMS";
const char* ov_property_key_device_full_name = "FULL_DEVICE_NAME";
const char* ov_property_key_device_capabilities = "OPTIMIZATION_CAPABILITIES";
const char* ov_property_key_model_name = "NETWORK_NAME";
const char* ov_property_key_optimal_batch_size = "OPTIMAL_BATCH_SIZE";
const char* ov_property_key_max_batch_size = "MAX_BATCH_SIZE";
void ov_properties_free(ov_properties_t* properties) {
if (properties && properties->list) {
delete[] properties->list;
properties->size = 0;
}
}
// Read-write property key
const char* ov_property_key_cache_dir = "CACHE_DIR";
const char* ov_property_key_num_streams = "NUM_STREAMS";
const char* ov_property_key_affinity = "AFFINITY";
const char* ov_property_key_inference_num_threads = "INFERENCE_NUM_THREADS";
const char* ov_property_key_hint_performance_mode = "PERFORMANCE_HINT";
const char* ov_property_key_hint_inference_precision = "INFERENCE_PRECISION_HINT";
const char* ov_property_key_hint_num_requests = "PERFORMANCE_HINT_NUM_REQUESTS";
const char* ov_property_key_hint_model_priority = "MODEL_PRIORITY";
const char* ov_property_key_log_level = "LOG_LEVEL";
const char* ov_property_key_enable_profiling = "PERF_COUNT";
const char* ov_property_key_device_priorities = "MULTI_DEVICE_PRIORITIES";

View File

@ -16,7 +16,7 @@ TEST_P(ov_compiled_model, ov_compiled_model_inputs_size) {
EXPECT_NE(nullptr, model);
ov_compiled_model_t* compiled_model = nullptr;
OV_EXPECT_OK(ov_core_compile_model(core, model, device_name.c_str(), nullptr, &compiled_model));
OV_EXPECT_OK(ov_core_compile_model(core, model, device_name.c_str(), 0, &compiled_model));
EXPECT_NE(nullptr, compiled_model);
size_t input_size;
@ -39,7 +39,7 @@ TEST_P(ov_compiled_model, ov_compiled_model_input) {
EXPECT_NE(nullptr, model);
ov_compiled_model_t* compiled_model = nullptr;
OV_EXPECT_OK(ov_core_compile_model(core, model, device_name.c_str(), nullptr, &compiled_model));
OV_EXPECT_OK(ov_core_compile_model(core, model, device_name.c_str(), 0, &compiled_model));
EXPECT_NE(nullptr, compiled_model);
ov_output_const_port_t* input_port = nullptr;
@ -63,7 +63,7 @@ TEST_P(ov_compiled_model, ov_compiled_model_input_by_index) {
ASSERT_NE(nullptr, model);
ov_compiled_model_t* compiled_model = nullptr;
OV_EXPECT_OK(ov_core_compile_model(core, model, device_name.c_str(), nullptr, &compiled_model));
OV_EXPECT_OK(ov_core_compile_model(core, model, device_name.c_str(), 0, &compiled_model));
EXPECT_NE(nullptr, compiled_model);
ov_output_const_port_t* input_port = nullptr;
@ -91,7 +91,7 @@ TEST_P(ov_compiled_model, ov_compiled_model_input_by_name) {
ASSERT_NE(nullptr, model);
ov_compiled_model_t* compiled_model = nullptr;
OV_EXPECT_OK(ov_core_compile_model(core, model, device_name.c_str(), nullptr, &compiled_model));
OV_EXPECT_OK(ov_core_compile_model(core, model, device_name.c_str(), 0, &compiled_model));
EXPECT_NE(nullptr, compiled_model);
ov_output_const_port_t* input_port = nullptr;
@ -108,6 +108,94 @@ TEST_P(ov_compiled_model, ov_compiled_model_input_by_name) {
ov_core_free(core);
}
TEST_P(ov_compiled_model, set_and_get_property) {
// It seems that all set_property() for CPU plugin are not implement in compiled_model.
auto device_name = "MULTI:GPU,CPU";
ov_core_t* core = nullptr;
OV_ASSERT_OK(ov_core_create(&core));
ASSERT_NE(nullptr, core);
char* info = nullptr;
const char* key_0 = ov_property_key_available_devices;
if (ov_core_get_property(core, "GPU", key_0, &info) != ov_status_e::OK) {
ov_core_free(core);
GTEST_SKIP();
}
ov_model_t* model = nullptr;
OV_EXPECT_OK(ov_core_read_model(core, xml, bin, &model));
EXPECT_NE(nullptr, model);
ov_compiled_model_t* compiled_model = nullptr;
OV_EXPECT_OK(ov_core_compile_model(core, model, device_name, 0, &compiled_model));
EXPECT_NE(nullptr, compiled_model);
const char* key_1 = ov_property_key_device_priorities;
const char* value_1 = "GPU,CPU";
OV_EXPECT_OK(ov_compiled_model_set_property(compiled_model, key_1, value_1));
char* result = nullptr;
OV_EXPECT_OK(ov_compiled_model_get_property(compiled_model, key_1, &result));
EXPECT_STREQ(value_1, result);
ov_free(result);
const char* key_2 = ov_property_key_supported_properties;
OV_EXPECT_OK(ov_compiled_model_get_property(compiled_model, key_2, &result));
ov_free(result);
ov_compiled_model_free(compiled_model);
ov_model_free(model);
ov_core_free(core);
}
TEST_P(ov_compiled_model, get_property) {
auto device_name = GetParam();
ov_core_t* core = nullptr;
OV_ASSERT_OK(ov_core_create(&core));
ASSERT_NE(nullptr, core);
ov_model_t* model = nullptr;
OV_EXPECT_OK(ov_core_read_model(core, xml, bin, &model));
EXPECT_NE(nullptr, model);
ov_compiled_model_t* compiled_model = nullptr;
OV_EXPECT_OK(ov_core_compile_model(core, model, device_name.c_str(), 0, &compiled_model));
EXPECT_NE(nullptr, compiled_model);
const char* key = ov_property_key_supported_properties;
char* result = nullptr;
OV_EXPECT_OK(ov_compiled_model_get_property(compiled_model, key, &result));
ov_free(result);
ov_compiled_model_free(compiled_model);
ov_model_free(model);
ov_core_free(core);
}
TEST_P(ov_compiled_model, create_compiled_model_with_property) {
auto device_name = GetParam();
ov_core_t* core = nullptr;
OV_ASSERT_OK(ov_core_create(&core));
ASSERT_NE(nullptr, core);
ov_model_t* model = nullptr;
OV_EXPECT_OK(ov_core_read_model(core, xml, bin, &model));
EXPECT_NE(nullptr, model);
const char* key = ov_property_key_hint_num_requests;
const char* num = "9";
ov_compiled_model_t* compiled_model = nullptr;
OV_EXPECT_OK(ov_core_compile_model(core, model, device_name.c_str(), 2, &compiled_model, key, num));
EXPECT_NE(nullptr, compiled_model);
char* result = nullptr;
OV_EXPECT_OK(ov_compiled_model_get_property(compiled_model, key, &result));
EXPECT_STREQ(result, "9");
ov_free(result);
ov_compiled_model_free(compiled_model);
ov_model_free(model);
ov_core_free(core);
}
TEST_P(ov_compiled_model, ov_compiled_model_outputs_size) {
auto device_name = GetParam();
ov_core_t* core = nullptr;
@ -119,7 +207,7 @@ TEST_P(ov_compiled_model, ov_compiled_model_outputs_size) {
EXPECT_NE(nullptr, model);
ov_compiled_model_t* compiled_model = nullptr;
OV_EXPECT_OK(ov_core_compile_model(core, model, device_name.c_str(), nullptr, &compiled_model));
OV_EXPECT_OK(ov_core_compile_model(core, model, device_name.c_str(), 0, &compiled_model));
EXPECT_NE(nullptr, compiled_model);
size_t output_size;
@ -142,7 +230,7 @@ TEST_P(ov_compiled_model, ov_compiled_model_output) {
EXPECT_NE(nullptr, model);
ov_compiled_model_t* compiled_model = nullptr;
OV_EXPECT_OK(ov_core_compile_model(core, model, device_name.c_str(), nullptr, &compiled_model));
OV_EXPECT_OK(ov_core_compile_model(core, model, device_name.c_str(), 0, &compiled_model));
EXPECT_NE(nullptr, compiled_model);
ov_output_const_port_t* output_port = nullptr;
@ -166,7 +254,7 @@ TEST_P(ov_compiled_model, ov_compiled_model_output_by_index) {
ASSERT_NE(nullptr, model);
ov_compiled_model_t* compiled_model = nullptr;
OV_EXPECT_OK(ov_core_compile_model(core, model, device_name.c_str(), nullptr, &compiled_model));
OV_EXPECT_OK(ov_core_compile_model(core, model, device_name.c_str(), 0, &compiled_model));
EXPECT_NE(nullptr, compiled_model);
ov_output_const_port_t* output_port = nullptr;
@ -194,7 +282,7 @@ TEST_P(ov_compiled_model, ov_compiled_model_output_by_name) {
ASSERT_NE(nullptr, model);
ov_compiled_model_t* compiled_model = nullptr;
OV_EXPECT_OK(ov_core_compile_model(core, model, device_name.c_str(), nullptr, &compiled_model));
OV_EXPECT_OK(ov_core_compile_model(core, model, device_name.c_str(), 0, &compiled_model));
EXPECT_NE(nullptr, compiled_model);
ov_output_const_port_t* output_port = nullptr;
@ -222,7 +310,7 @@ TEST_P(ov_compiled_model, get_runtime_model) {
EXPECT_NE(nullptr, model);
ov_compiled_model_t* compiled_model = nullptr;
OV_EXPECT_OK(ov_core_compile_model(core, model, device_name.c_str(), nullptr, &compiled_model));
OV_EXPECT_OK(ov_core_compile_model(core, model, device_name.c_str(), 0, &compiled_model));
EXPECT_NE(nullptr, compiled_model);
ov_model_t* runtime_model = nullptr;
@ -246,7 +334,7 @@ TEST_P(ov_compiled_model, get_runtime_model_error_handling) {
EXPECT_NE(nullptr, model);
ov_compiled_model_t* compiled_model = nullptr;
OV_EXPECT_OK(ov_core_compile_model(core, model, device_name.c_str(), nullptr, &compiled_model));
OV_EXPECT_OK(ov_core_compile_model(core, model, device_name.c_str(), 0, &compiled_model));
EXPECT_NE(nullptr, compiled_model);
ov_model_t* runtime_model = nullptr;
@ -270,7 +358,7 @@ TEST_P(ov_compiled_model, create_infer_request) {
EXPECT_NE(nullptr, model);
ov_compiled_model_t* compiled_model = nullptr;
OV_EXPECT_OK(ov_core_compile_model(core, model, device_name.c_str(), nullptr, &compiled_model));
OV_EXPECT_OK(ov_core_compile_model(core, model, device_name.c_str(), 0, &compiled_model));
EXPECT_NE(nullptr, compiled_model);
ov_infer_request_t* infer_request = nullptr;
@ -294,7 +382,7 @@ TEST_P(ov_compiled_model, create_infer_request_error_handling) {
EXPECT_NE(nullptr, model);
ov_compiled_model_t* compiled_model = nullptr;
OV_EXPECT_OK(ov_core_compile_model(core, model, device_name.c_str(), nullptr, &compiled_model));
OV_EXPECT_OK(ov_core_compile_model(core, model, device_name.c_str(), 0, &compiled_model));
EXPECT_NE(nullptr, compiled_model);
ov_infer_request_t* infer_request = nullptr;

View File

@ -99,8 +99,7 @@ TEST_P(ov_core, ov_core_compile_model) {
ASSERT_NE(nullptr, model);
ov_compiled_model_t* compiled_model = nullptr;
ov_properties_t* property = nullptr;
OV_ASSERT_OK(ov_core_compile_model(core, model, device_name.c_str(), property, &compiled_model));
OV_ASSERT_OK(ov_core_compile_model(core, model, device_name.c_str(), 0, &compiled_model));
ASSERT_NE(nullptr, compiled_model);
ov_compiled_model_free(compiled_model);
@ -108,6 +107,53 @@ TEST_P(ov_core, ov_core_compile_model) {
ov_core_free(core);
}
TEST_P(ov_core, ov_core_compile_model_with_property) {
auto device_name = GetParam();
ov_core_t* core = nullptr;
OV_ASSERT_OK(ov_core_create(&core));
ASSERT_NE(nullptr, core);
ov_model_t* model = nullptr;
OV_ASSERT_OK(ov_core_read_model(core, xml, nullptr, &model));
ASSERT_NE(nullptr, model);
ov_compiled_model_t* compiled_model = nullptr;
const char* key = ov_property_key_num_streams;
const char* num = "11";
OV_ASSERT_OK(ov_core_compile_model(core, model, device_name.c_str(), 2, &compiled_model, key, num));
ASSERT_NE(nullptr, compiled_model);
char* property_value = nullptr;
OV_EXPECT_OK(ov_compiled_model_get_property(compiled_model, key, &property_value));
EXPECT_STREQ(property_value, "11");
ov_free(property_value);
ov_compiled_model_free(compiled_model);
ov_model_free(model);
ov_core_free(core);
}
TEST_P(ov_core, ov_core_compile_model_with_property_invalid) {
auto device_name = GetParam();
ov_core_t* core = nullptr;
OV_ASSERT_OK(ov_core_create(&core));
ASSERT_NE(nullptr, core);
ov_model_t* model = nullptr;
OV_ASSERT_OK(ov_core_read_model(core, xml, nullptr, &model));
ASSERT_NE(nullptr, model);
ov_compiled_model_t* compiled_model = nullptr;
const char* key = ov_property_key_num_streams;
const char* num = "11";
OV_EXPECT_NOT_OK(ov_core_compile_model(core, model, device_name.c_str(), 1, &compiled_model, key, num));
OV_EXPECT_NOT_OK(ov_core_compile_model(core, model, device_name.c_str(), 3, &compiled_model, key, num, "Test"));
ov_compiled_model_free(compiled_model);
ov_model_free(model);
ov_core_free(core);
}
TEST_P(ov_core, ov_core_compile_model_from_file) {
auto device_name = GetParam();
ov_core_t* core = nullptr;
@ -115,32 +161,129 @@ TEST_P(ov_core, ov_core_compile_model_from_file) {
ASSERT_NE(nullptr, core);
ov_compiled_model_t* compiled_model = nullptr;
ov_properties_t* property = nullptr;
OV_ASSERT_OK(ov_core_compile_model_from_file(core, xml, device_name.c_str(), property, &compiled_model));
OV_ASSERT_OK(ov_core_compile_model_from_file(core, xml, device_name.c_str(), 0, &compiled_model));
ASSERT_NE(nullptr, compiled_model);
ov_compiled_model_free(compiled_model);
ov_core_free(core);
}
TEST_P(ov_core, ov_core_set_property) {
TEST_P(ov_core, ov_core_set_property_enum) {
auto device_name = GetParam();
ov_core_t* core = nullptr;
OV_ASSERT_OK(ov_core_create(&core));
ASSERT_NE(nullptr, core);
ov_properties_t properties;
OV_ASSERT_OK(ov_properties_create(&properties, 1));
const char* key = ov_property_key_log_level;
const char* mode = "WARNING";
OV_ASSERT_OK(ov_core_set_property(core, device_name.c_str(), key, mode));
ov_core_free(core);
}
TEST_P(ov_core, ov_core_set_property_invalid_number_property_arguments) {
auto device_name = GetParam();
ov_core_t* core = nullptr;
OV_ASSERT_OK(ov_core_create(&core));
ASSERT_NE(nullptr, core);
const char* key_1 = ov_property_key_inference_num_threads;
const char* value_1 = "12";
const char* key_2 = ov_property_key_hint_performance_mode;
const char* value_2 = "LATENCY";
OV_ASSERT_OK(ov_core_set_property(core, device_name.c_str(), key_1, value_1, key_2, value_2));
char* ret = nullptr;
OV_ASSERT_OK(ov_core_get_property(core, device_name.c_str(), key_1, &ret));
EXPECT_STREQ(value_1, ret);
ov_free(ret);
OV_ASSERT_OK(ov_core_get_property(core, device_name.c_str(), key_2, &ret));
EXPECT_STRNE(value_2, ret);
ov_free(ret);
ov_core_free(core);
}
TEST_P(ov_core, ov_core_set_property_enum_invalid) {
auto device_name = GetParam();
ov_core_t* core = nullptr;
OV_ASSERT_OK(ov_core_create(&core));
ASSERT_NE(nullptr, core);
const char* key = ov_property_key_hint_performance_mode;
ov_performance_mode_e mode = ov_performance_mode_e::THROUGHPUT;
ov_any_t value = {(void*)&mode, 1, ov_any_type_e::ENUM};
properties.size = 1;
properties.list[0].key = key;
properties.list[0].value = value;
const char* mode = "LATENCY";
OV_ASSERT_OK(ov_core_set_property(core, device_name.c_str(), key, mode));
char* ret = nullptr;
OV_ASSERT_OK(ov_core_get_property(core, device_name.c_str(), key, &ret));
EXPECT_STREQ(mode, ret);
ov_free(ret);
const char* invalid_mode = "LATENCY_TEST";
OV_EXPECT_NOT_OK(ov_core_set_property(core, device_name.c_str(), key, invalid_mode));
ret = nullptr;
OV_ASSERT_OK(ov_core_get_property(core, device_name.c_str(), key, &ret));
EXPECT_STRNE(invalid_mode, ret);
ov_free(ret);
ov_core_free(core);
}
TEST_P(ov_core, ov_core_set_and_get_property_enum) {
auto device_name = GetParam();
ov_core_t* core = nullptr;
OV_ASSERT_OK(ov_core_create(&core));
ASSERT_NE(nullptr, core);
const char* key = ov_property_key_affinity;
const char* affinity = "HYBRID_AWARE";
OV_ASSERT_OK(ov_core_set_property(core, device_name.c_str(), key, affinity));
char* ret = nullptr;
OV_ASSERT_OK(ov_core_get_property(core, device_name.c_str(), key, &ret));
EXPECT_STREQ(affinity, ret);
ov_free(ret);
key = ov_property_key_hint_inference_precision;
const char* precision = "f32";
OV_ASSERT_OK(ov_core_set_property(core, device_name.c_str(), key, precision));
ret = nullptr;
OV_ASSERT_OK(ov_core_get_property(core, device_name.c_str(), key, &ret));
EXPECT_STREQ(precision, ret);
ov_free(ret);
ov_core_free(core);
}
TEST_P(ov_core, ov_core_set_and_get_property_bool) {
auto device_name = GetParam();
ov_core_t* core = nullptr;
OV_ASSERT_OK(ov_core_create(&core));
ASSERT_NE(nullptr, core);
const char* key = ov_property_key_enable_profiling;
const char* enable = "YES";
OV_ASSERT_OK(ov_core_set_property(core, device_name.c_str(), key, enable));
char* ret = nullptr;
OV_ASSERT_OK(ov_core_get_property(core, device_name.c_str(), key, &ret));
EXPECT_STREQ(enable, ret);
ov_free(ret);
ov_core_free(core);
}
TEST_P(ov_core, ov_core_set_and_get_property_bool_invalid) {
auto device_name = GetParam();
ov_core_t* core = nullptr;
OV_ASSERT_OK(ov_core_create(&core));
ASSERT_NE(nullptr, core);
const char* key = ov_property_key_enable_profiling;
const char* enable = "TEST";
OV_ASSERT_OK(ov_core_set_property(core, device_name.c_str(), key, enable));
char* ret = nullptr;
OV_EXPECT_NOT_OK(ov_core_get_property(core, device_name.c_str(), key, &ret));
EXPECT_STRNE(enable, ret);
ov_free(ret);
OV_ASSERT_OK(ov_core_set_property(core, device_name.c_str(), &properties));
ov_properties_free(&properties);
ov_core_free(core);
}
@ -150,10 +293,10 @@ TEST_P(ov_core, ov_core_get_property) {
OV_ASSERT_OK(ov_core_create(&core));
ASSERT_NE(nullptr, core);
ov_any_t property_value;
char* property_value;
OV_ASSERT_OK(
ov_core_get_property(core, device_name.c_str(), ov_property_key_supported_properties, &property_value));
ov_any_free(&property_value);
ov_free(property_value);
ov_core_free(core);
}
@ -163,24 +306,16 @@ TEST_P(ov_core, ov_core_set_get_property_str) {
OV_ASSERT_OK(ov_core_create(&core));
ASSERT_NE(nullptr, core);
ov_properties_t properties;
OV_ASSERT_OK(ov_properties_create(&properties, 1));
const char* key = ov_property_key_cache_dir;
const char cache_dir[] = "./cache_dir";
ov_any_t value = {(void*)cache_dir, sizeof(cache_dir), ov_any_type_e::CHAR};
properties.size = 1;
properties.list[0].key = key;
properties.list[0].value = value;
OV_ASSERT_OK(ov_core_set_property(core, device_name.c_str(), &properties));
OV_ASSERT_OK(ov_core_set_property(core, device_name.c_str(), key, cache_dir));
ov_any_t property_value;
char* property_value = nullptr;
OV_ASSERT_OK(ov_core_get_property(core, device_name.c_str(), key, &property_value));
EXPECT_STREQ(cache_dir, (char*)property_value.ptr);
EXPECT_STREQ(cache_dir, property_value);
ov_properties_free(&properties);
ov_any_free(&property_value);
ov_free(property_value);
ov_core_free(core);
}
@ -190,75 +325,80 @@ TEST_P(ov_core, ov_core_set_get_property_int) {
OV_ASSERT_OK(ov_core_create(&core));
ASSERT_NE(nullptr, core);
ov_properties_t properties;
OV_ASSERT_OK(ov_properties_create(&properties, 1));
const char* key = ov_property_key_inference_num_threads;
int32_t num = 8;
ov_any_t value = {(void*)&num, 1, ov_any_type_e::INT32};
properties.size = 1;
properties.list[0].key = key;
properties.list[0].value = value;
const char* num = "8";
OV_ASSERT_OK(ov_core_set_property(core, device_name.c_str(), key, num));
OV_ASSERT_OK(ov_core_set_property(core, device_name.c_str(), &properties));
ov_any_t property_value;
char* property_value = nullptr;
OV_ASSERT_OK(ov_core_get_property(core, device_name.c_str(), key, &property_value));
int32_t res = *(int32_t*)property_value.ptr;
EXPECT_EQ(num, res);
ov_any_free(&property_value);
EXPECT_STREQ(num, property_value);
ov_free(property_value);
ov_properties_free(&properties);
ov_core_free(core);
}
TEST_P(ov_core, ov_core_set_multiple_properties) {
TEST_P(ov_core, ov_core_set_property_int_invalid) {
auto device_name = GetParam();
ov_core_t* core = nullptr;
OV_ASSERT_OK(ov_core_create(&core));
ASSERT_NE(nullptr, core);
ov_properties_t properties;
OV_ASSERT_OK(ov_properties_create(&properties, 3));
const char* key = ov_property_key_inference_num_threads;
OV_ASSERT_OK(ov_core_set_property(core, device_name.c_str(), key, "abc"));
char* ret = nullptr;
OV_EXPECT_NOT_OK(ov_core_get_property(core, device_name.c_str(), key, &ret));
ov_free(ret);
ov_core_free(core);
}
TEST_P(ov_core, ov_core_set_multiple_common_properties) {
auto device_name = GetParam();
ov_core_t* core = nullptr;
OV_ASSERT_OK(ov_core_create(&core));
ASSERT_NE(nullptr, core);
// Test enum
const char* key_1 = ov_property_key_hint_performance_mode;
ov_performance_mode_e mode = ov_performance_mode_e::THROUGHPUT;
ov_any_t value_1 = {(void*)&mode, 1, ov_any_type_e::ENUM};
properties.list[0].key = key_1;
properties.list[0].value = value_1;
const char* value_1 = "THROUGHPUT";
OV_ASSERT_OK(ov_core_set_property(core, device_name.c_str(), key_1, value_1));
char* property_value_1 = nullptr;
OV_ASSERT_OK(ov_core_get_property(core, device_name.c_str(), key_1, &property_value_1));
EXPECT_STREQ(property_value_1, value_1);
ov_free(property_value_1);
// Test string
const char* key_2 = ov_property_key_cache_dir;
const char cache_dir[] = "./cache_dir";
ov_any_t value_2 = {(void*)cache_dir, sizeof(cache_dir), ov_any_type_e::CHAR};
properties.list[1].key = key_2;
properties.list[1].value = value_2;
OV_ASSERT_OK(ov_core_set_property(core, device_name.c_str(), key_2, cache_dir));
const char* key_3 = ov_property_key_hint_num_requests;
int32_t num = 8;
ov_any_t value_3 = {(void*)&num, 1, ov_any_type_e::UINT32};
properties.list[2].key = key_3;
properties.list[2].value = value_3;
OV_ASSERT_OK(ov_core_set_property(core, device_name.c_str(), &properties));
ov_any_t property_value_1;
OV_ASSERT_OK(ov_core_get_property(core, device_name.c_str(), key_1, &property_value_1));
int32_t res_1 = *(ov_performance_mode_e*)property_value_1.ptr;
EXPECT_EQ(mode, res_1);
ov_any_free(&property_value_1);
ov_any_t property_value_2;
char* property_value_2 = nullptr;
OV_ASSERT_OK(ov_core_get_property(core, device_name.c_str(), key_2, &property_value_2));
EXPECT_STREQ(cache_dir, (char*)property_value_2.ptr);
ov_any_free(&property_value_2);
EXPECT_STREQ(property_value_2, cache_dir);
ov_free(property_value_2);
ov_any_t property_value_3;
// Test int32
const char* key_3 = ov_property_key_hint_num_requests;
const char* num = "8";
OV_ASSERT_OK(ov_core_set_property(core, device_name.c_str(), key_3, num));
char* property_value_3 = nullptr;
OV_ASSERT_OK(ov_core_get_property(core, device_name.c_str(), key_3, &property_value_3));
int32_t res_3 = *(int32_t*)property_value_3.ptr;
EXPECT_EQ(num, res_3);
ov_any_free(&property_value_3);
EXPECT_STREQ(property_value_3, num);
ov_free(property_value_3);
ov_properties_free(&properties);
// Test bool
const char* key_4 = ov_property_key_enable_profiling;
const char* enable = "YES";
OV_ASSERT_OK(ov_core_set_property(core, device_name.c_str(), key_4, enable));
char* property_value_4 = nullptr;
OV_ASSERT_OK(ov_core_get_property(core, device_name.c_str(), key_4, &property_value_4));
EXPECT_STREQ(property_value_4, "YES");
ov_free(property_value_4);
ov_core_free(core);
}
TEST(ov_core, ov_core_get_available_devices) {
@ -280,7 +420,7 @@ TEST_P(ov_core, ov_compiled_model_export_model) {
ASSERT_NE(nullptr, core);
ov_compiled_model_t* compiled_model = nullptr;
OV_ASSERT_OK(ov_core_compile_model_from_file(core, xml, device_name.c_str(), nullptr, &compiled_model));
OV_ASSERT_OK(ov_core_compile_model_from_file(core, xml, device_name.c_str(), 0, &compiled_model));
ASSERT_NE(nullptr, compiled_model);
std::string export_path = TestDataHelpers::generate_model_path("test_model", "exported_model.blob");
@ -298,7 +438,7 @@ TEST_P(ov_core, ov_core_import_model) {
ASSERT_NE(nullptr, core);
ov_compiled_model_t* compiled_model = nullptr;
OV_ASSERT_OK(ov_core_compile_model_from_file(core, xml, device_name.c_str(), nullptr, &compiled_model));
OV_ASSERT_OK(ov_core_compile_model_from_file(core, xml, device_name.c_str(), 0, &compiled_model));
ASSERT_NE(nullptr, compiled_model);
std::string export_path = TestDataHelpers::generate_model_path("test_model", "exported_model.blob");

View File

@ -51,7 +51,7 @@ protected:
EXPECT_NE(nullptr, input_tensor);
compiled_model = nullptr;
OV_EXPECT_OK(ov_core_compile_model(core, model, device_name.c_str(), nullptr, &compiled_model));
OV_EXPECT_OK(ov_core_compile_model(core, model, device_name.c_str(), 0, &compiled_model));
EXPECT_NE(nullptr, compiled_model);
infer_request = nullptr;
@ -147,7 +147,7 @@ protected:
EXPECT_NE(nullptr, model);
compiled_model = nullptr;
OV_EXPECT_OK(ov_core_compile_model(core, model, device_name.c_str(), nullptr, &compiled_model));
OV_EXPECT_OK(ov_core_compile_model(core, model, device_name.c_str(), 0, &compiled_model));
EXPECT_NE(nullptr, compiled_model);
infer_request = nullptr;

View File

@ -82,7 +82,6 @@ TEST(ov_partial_shape, ov_partial_shape_create_invalid_dimension) {
int64_t rank = 4;
ov_dimension_t dims[4] = {{1, 1}, {-1, -1}, {300, 100}, {40, 100}};
OV_EXPECT_NOT_OK(ov_partial_shape_create(rank, dims, &partial_shape));
ov_partial_shape_free(&partial_shape);
}
@ -134,4 +133,5 @@ TEST(ov_partial_shape, ov_shape_to_partial_shape) {
EXPECT_STREQ(tmp, str);
ov_partial_shape_free(&partial_shape);
ov_shape_free(&shape);
ov_free(tmp);
}

View File

@ -1,11 +0,0 @@
// Copyright (C) 2018-2022 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "ov_test.hpp"
TEST(ov_property, ov_properties_create_test) {
ov_properties_t properties;
OV_ASSERT_OK(ov_properties_create(&properties, 6));
ov_properties_free(&properties);
}