History

libavfilter/dnn/openvino: Reduce redundant memory allocation

We can directly get data ptr from tensor, so that extral memory allocation can be removed.

Wenbin Chen committed 3 years ago

Commit fa81de41 parent 49719d31 file · +21 −21Browse files

Showing the changes to libavfilter (1 of 1 file). Show all

Unified · Split

libavfilter/dnn/dnn_backend_openvino.c+21−21
@@ -204,7 +204,6 @@ static int fill_model_input_ov(OVModel *ov_model, OVRequestItem *request) · 203 unmodified lines
204204 ov_tensor_t* tensor = NULL;
205205 ov_shape_t input_shape = {0};
206206 ov_element_type_e precision;
207− void *input_data_ptr = NULL;
208207 #else
209208 dimensions_t dims;
210209 precision_e precision;
@@ -249,12 +248,6 @@ static int fill_model_input_ov(OVModel *ov_model, OVRequestItem *request) · 38 unmodified lines
249248 input.width = dims[2];
250249 input.channels = dims[3];
251250 input.dt = precision_to_datatype(precision);
252− input.data = av_malloc(input.height * input.width * input.channels * get_datatype_size(input.dt));
253− if (!input.data) {
254− ov_shape_free(&input_shape);
255− return AVERROR(ENOMEM);
256− }
257− input_data_ptr = input.data;
258251 #else
259252 status = ie_infer_request_get_blob(request->infer_request, task->input_name, &input_blob);
260253 if (status != OK) {
@@ -297,6 +290,26 @@ static int fill_model_input_ov(OVModel *ov_model, OVRequestItem *request) · 36 unmodified lines
297290 request->lltasks[i] = lltask;
298291 request->lltask_count = i + 1;
299292 task = lltask->task;
293+#if HAVE_OPENVINO2
294+ if (tensor)
295+ ov_tensor_free(tensor);
296+ status = ov_tensor_create(precision, input_shape, &tensor);
297+ ov_shape_free(&input_shape);
298+ if (status != OK) {
299+ av_log(ctx, AV_LOG_ERROR, "Failed to create tensor from host prt.\n");
300+ return ov2_map_error(status, NULL);
301+ }
302+ status = ov_tensor_data(tensor, &input.data);
303+ if (status != OK) {
304+ av_log(ctx, AV_LOG_ERROR, "Failed to get input data.\n");
305+ return ov2_map_error(status, NULL);
306+ }
307+ status = ov_infer_request_set_input_tensor(request->infer_request, tensor);
308+ if (status != OK) {
309+ av_log(ctx, AV_LOG_ERROR, "Failed to Set an input tensor for the model.\n");
310+ return ov2_map_error(status, NULL);
311+ }
312+#endif
300313 switch (ov_model->model->func_type) {
301314 case DFT_PROCESS_FRAME:
302315 if (task->do_ioproc) {
@@ -317,24 +330,11 @@ static int fill_model_input_ov(OVModel *ov_model, OVRequestItem *request) · 14 unmodified lines
317330 av_assert0(!"should not reach here");
318331 break;
319332 }
320−#if HAVE_OPENVINO2
321− status = ov_tensor_create_from_host_ptr(precision, input_shape, input.data, &tensor);
322− ov_shape_free(&input_shape);
323− if (status != OK) {
324− av_log(ctx, AV_LOG_ERROR, "Failed to create tensor from host prt.\n");
325− return ov2_map_error(status, NULL);
326− }
327− status = ov_infer_request_set_input_tensor(request->infer_request, tensor);
328− if (status != OK) {
329− av_log(ctx, AV_LOG_ERROR, "Failed to Set an input tensor for the model.\n");
330− return ov2_map_error(status, NULL);
331− }
332−#endif
333333 input.data = (uint8_t *)input.data
334334 + input.width * input.height * input.channels * get_datatype_size(input.dt);
335335 }
336336 #if HAVE_OPENVINO2
337− av_freep(&input_data_ptr);
337+ ov_tensor_free(tensor);
338338 #else
339339 ie_blob_free(&input_blob);
340340 #endif

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t