|
| 1 | +From d588f34b236de463610a2d115c7555bf0a48f887 Mon Sep 17 00:00:00 2001 |
| 2 | +From: xiaoxial < [email protected]> |
| 3 | +Date: Fri, 10 Jan 2020 00:59:36 +0800 |
| 4 | +Subject: [PATCH] C API related changes for OpenVINO 2020.1 |
| 5 | + |
| 6 | +* Update configure for OpenVINO IE C API wrapper |
| 7 | +* Adapt the OpenVINO r4 IE C API |
| 8 | + |
| 9 | +Change-Id: I973b6d885c764eee25e58249a048b525ad8e96bf |
| 10 | +--- |
| 11 | + configure | 14 ++++---- |
| 12 | + .../inference_backend/openvino_image_inference.c | 41 ++++------------------ |
| 13 | + 2 files changed, 13 insertions(+), 42 deletions(-) |
| 14 | + |
| 15 | +diff --git a/configure b/configure |
| 16 | +index 9cf255b..04df301 100755 |
| 17 | +--- a/configure |
| 18 | ++++ b/configure |
| 19 | +@@ -240,7 +240,7 @@ External library support: |
| 20 | + --enable-libgsm enable GSM de/encoding via libgsm [no] |
| 21 | + --enable-libiec61883 enable iec61883 via libiec61883 [no] |
| 22 | + --enable-libilbc enable iLBC de/encoding via libilbc [no] |
| 23 | +- --enable-libinference_engine_c_api enable dldt inference engine c api [no] |
| 24 | ++ --enable-libinference_engine_c_wrapper enable dldt inference engine c wrapper [no] |
| 25 | + --enable-libjack enable JACK audio sound server [no] |
| 26 | + --enable-libjson_c enable libjson-c [no] |
| 27 | + --enable-libklvanc enable Kernel Labs VANC processing [no] |
| 28 | +@@ -1775,7 +1775,7 @@ EXTERNAL_LIBRARY_LIST=" |
| 29 | + libgsm |
| 30 | + libiec61883 |
| 31 | + libilbc |
| 32 | +- libinference_engine_c_api |
| 33 | ++ libinference_engine_c_wrapper |
| 34 | + libjack |
| 35 | + libjson_c |
| 36 | + libklvanc |
| 37 | +@@ -2610,7 +2610,7 @@ cbs_vp9_select="cbs" |
| 38 | + dct_select="rdft" |
| 39 | + dirac_parse_select="golomb" |
| 40 | + dnn_suggest="libtensorflow" |
| 41 | +-image_inference_suggest="libinference_engine_c_api" |
| 42 | ++image_inference_suggest="libinference_engine_c_wrapper" |
| 43 | + image_inference_deps="libjson_c" |
| 44 | + error_resilience_select="me_cmp" |
| 45 | + faandct_deps="faan" |
| 46 | +@@ -3484,9 +3484,9 @@ hqdn3d_filter_deps="gpl" |
| 47 | + inference_identify_filter_deps="libjson_c" |
| 48 | + inference_identify_filter_select="dnn" |
| 49 | + inference_metaconvert_filter_deps="libjson_c" |
| 50 | +-inference_classify_filter_deps="libinference_engine_c_api libjson_c" |
| 51 | ++inference_classify_filter_deps="libinference_engine_c_wrapper libjson_c" |
| 52 | + inference_classify_filter_select="image_inference" |
| 53 | +-inference_detect_filter_deps="libinference_engine_c_api libjson_c" |
| 54 | ++inference_detect_filter_deps="libinference_engine_c_wrapper libjson_c" |
| 55 | + inference_detect_filter_select="image_inference" |
| 56 | + interlace_filter_deps="gpl" |
| 57 | + kerndeint_filter_deps="gpl" |
| 58 | +@@ -6389,8 +6389,8 @@ enabled librdkafka && require_pkg_config librdkafka rdkafka "librdkafka/rdkafka |
| 59 | + |
| 60 | + enabled libjson_c && check_pkg_config libjson_c json-c json-c/json.h json_c_version |
| 61 | + |
| 62 | +-enabled libinference_engine_c_api && |
| 63 | +- require_pkg_config libinference_engine_c_api dldt_c_api "ie_c_api.h" ie_c_api_version |
| 64 | ++enabled libinference_engine_c_wrapper && |
| 65 | ++ require_pkg_config libinference_engine_c_wrapper dldt_c_api "ie_c_api.h" ie_c_api_version |
| 66 | + |
| 67 | + if enabled gcrypt; then |
| 68 | + GCRYPT_CONFIG="${cross_prefix}libgcrypt-config" |
| 69 | +diff --git a/libavfilter/inference_backend/openvino_image_inference.c b/libavfilter/inference_backend/openvino_image_inference.c |
| 70 | +index ed77eda..e0bdd2e 100644 |
| 71 | +--- a/libavfilter/inference_backend/openvino_image_inference.c |
| 72 | ++++ b/libavfilter/inference_backend/openvino_image_inference.c |
| 73 | +@@ -38,7 +38,7 @@ static inline void* mallocz(size_t size) { |
| 74 | + } |
| 75 | + |
| 76 | + static ie_config_t *StringToIEConfig(const char *configs, char **pre_processor_name, char **multi_device_list, |
| 77 | +- char **hetero_device_list, char **cpu_exetension, char**image_format) { |
| 78 | ++ char **hetero_device_list, char**image_format) { |
| 79 | + |
| 80 | + ie_config_t *config_res = NULL, *cfg_tmp = NULL; |
| 81 | + char *key = NULL, *value = NULL, *configs_temp = NULL; |
| 82 | +@@ -71,11 +71,6 @@ static ie_config_t *StringToIEConfig(const char *configs, char **pre_processor_n |
| 83 | + assert(list); |
| 84 | + strcpy(list, value); |
| 85 | + *pre_processor_name = list; |
| 86 | +- } else if (!strcmp(key, "CPU_EXTENSION")) { |
| 87 | +- list = (char *)mallocz(strlen(value) + 1); |
| 88 | +- assert(list); |
| 89 | +- strcpy(list, value); |
| 90 | +- *cpu_exetension = list; |
| 91 | + } else if (!strcmp(key, "IMAGE_FORMAT")) { |
| 92 | + list = (char *)mallocz(strlen(value) + 1); |
| 93 | + assert(list); |
| 94 | +@@ -326,11 +321,11 @@ static void SubmitImagePreProcess(ImageInferenceContext *ctx, const BatchRequest |
| 95 | + static int OpenVINOImageInferenceCreate(ImageInferenceContext *ctx, MemoryType type, const char *devices, |
| 96 | + const char *model, int batch_size, int nireq, const char *configs, |
| 97 | + void *allocator, CallbackFunc callback) { |
| 98 | +- int cpu_extension_needed = 0, input_num = 0; |
| 99 | ++ size_t input_num = 0; |
| 100 | + OpenVINOImageInference *vino = (OpenVINOImageInference *)ctx->priv; |
| 101 | +- char *cpu_exetension = NULL, *image_format = NULL; |
| 102 | ++ char *image_format = NULL; |
| 103 | + char *pre_processor_name = NULL, *multi_device_list = NULL, *hetero_device_list = NULL; |
| 104 | +- char *_devices = NULL, *weight = NULL; |
| 105 | ++ char *_devices = NULL; |
| 106 | + input_shapes_t network_input_shapes = {0}; |
| 107 | + ie_config_t net_config = {NULL, NULL, NULL}; |
| 108 | + VAII_DEBUG("Create"); |
| 109 | +@@ -353,15 +348,10 @@ static int OpenVINOImageInferenceCreate(ImageInferenceContext *ctx, MemoryType t |
| 110 | + |
| 111 | + if (configs) { |
| 112 | + ie_config_t *_configs = StringToIEConfig(configs, &pre_processor_name, &multi_device_list, |
| 113 | +- &hetero_device_list, &cpu_exetension, &image_format); |
| 114 | ++ &hetero_device_list, &image_format); |
| 115 | + ie_core_set_config(vino->core, _configs, devices); |
| 116 | + vino->resize_by_inference = (pre_processor_name && !strcmp(pre_processor_name, "ie")) ? 1 : 0; |
| 117 | + |
| 118 | +- if (multi_device_list && strstr(multi_device_list, "CPU") || |
| 119 | +- hetero_device_list && strstr(hetero_device_list, "CPU")) { |
| 120 | +- cpu_extension_needed = 1; |
| 121 | +- } |
| 122 | +- |
| 123 | + if (!strcmp(devices, "MULTI")) { |
| 124 | + if (multi_device_list) { |
| 125 | + _devices = (char *)malloc(strlen(devices) + strlen(multi_device_list) + 2); |
| 126 | +@@ -401,23 +391,8 @@ static int OpenVINOImageInferenceCreate(ImageInferenceContext *ctx, MemoryType t |
| 127 | + pre_processor_name = NULL, hetero_device_list = NULL, multi_device_list = NULL; |
| 128 | + } |
| 129 | + |
| 130 | +- // Extension for custom layers |
| 131 | +- if (cpu_extension_needed || strstr(devices, "CPU")) { |
| 132 | +- ie_core_add_extension(vino->core, cpu_exetension, "CPU"); |
| 133 | +- VAII_DEBUG("Cpu extension loaded!"); |
| 134 | +- if (cpu_exetension) |
| 135 | +- free(cpu_exetension); |
| 136 | +- cpu_exetension = NULL; |
| 137 | +- } |
| 138 | +- |
| 139 | + // Read network |
| 140 | +- weight = (char *)malloc(strlen(model) + 1); |
| 141 | +- assert(weight); |
| 142 | +- strncpy(weight, model, strlen(model) - 4); |
| 143 | +- weight[strlen(model) - 4] = '\0'; |
| 144 | +- strcat(weight, ".bin"); |
| 145 | +- ie_network_read(model, weight, &vino->network); |
| 146 | +- free(weight); |
| 147 | ++ ie_core_read_network(vino->core, model, NULL, &vino->network); |
| 148 | + if (!vino->network) { |
| 149 | + VAII_ERROR("Create network failed!"); |
| 150 | + goto err; |
| 151 | +@@ -530,8 +505,6 @@ static int OpenVINOImageInferenceCreate(ImageInferenceContext *ctx, MemoryType t |
| 152 | + pthread_mutex_init(&vino->count_mutex, NULL); |
| 153 | + pthread_cond_init(&vino->request_processed, NULL); |
| 154 | + |
| 155 | +- if (cpu_exetension) |
| 156 | +- free(cpu_exetension); |
| 157 | + return 0; |
| 158 | + err: |
| 159 | + if (pre_processor_name) |
| 160 | +@@ -540,8 +513,6 @@ err: |
| 161 | + free(hetero_device_list); |
| 162 | + if (multi_device_list) |
| 163 | + free(multi_device_list); |
| 164 | +- if (cpu_exetension) |
| 165 | +- free(cpu_exetension); |
| 166 | + if (image_format) |
| 167 | + free(image_format); |
| 168 | + if (_devices) |
| 169 | +-- |
| 170 | +2.7.4 |
| 171 | + |
0 commit comments