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
204 ov_tensor_t* tensor = NULL;204 ov_tensor_t* tensor = NULL;
205 ov_shape_t input_shape = {0};205 ov_shape_t input_shape = {0};
206 ov_element_type_e precision;206 ov_element_type_e precision;
207 void *input_data_ptr = NULL;
208#else207#else
209 dimensions_t dims;208 dimensions_t dims;
210 precision_e precision;209 precision_e precision;
@@ -249,12 +248,6 @@ static int fill_model_input_ov(OVModel *ov_model, OVRequestItem *request) · 38 unmodified lines
249 input.width = dims[2];248 input.width = dims[2];
250 input.channels = dims[3];249 input.channels = dims[3];
251 input.dt = precision_to_datatype(precision);250 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;
258#else251#else
259 status = ie_infer_request_get_blob(request->infer_request, task->input_name, &input_blob);252 status = ie_infer_request_get_blob(request->infer_request, task->input_name, &input_blob);
260 if (status != OK) {253 if (status != OK) {
@@ -297,6 +290,26 @@ static int fill_model_input_ov(OVModel *ov_model, OVRequestItem *request) · 36 unmodified lines
297 request->lltasks[i] = lltask;290 request->lltasks[i] = lltask;
298 request->lltask_count = i + 1;291 request->lltask_count = i + 1;
299 task = lltask->task;292 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
300 switch (ov_model->model->func_type) {313 switch (ov_model->model->func_type) {
301 case DFT_PROCESS_FRAME:314 case DFT_PROCESS_FRAME:
302 if (task->do_ioproc) {315 if (task->do_ioproc) {
@@ -317,24 +330,11 @@ static int fill_model_input_ov(OVModel *ov_model, OVRequestItem *request) · 14 unmodified lines
317 av_assert0(!"should not reach here");330 av_assert0(!"should not reach here");
318 break;331 break;
319 }332 }
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
333 input.data = (uint8_t *)input.data333 input.data = (uint8_t *)input.data
334 + input.width * input.height * input.channels * get_datatype_size(input.dt);334 + input.width * input.height * input.channels * get_datatype_size(input.dt);
335 }335 }
336#if HAVE_OPENVINO2336#if HAVE_OPENVINO2
337 av_freep(&input_data_ptr);337 ov_tensor_free(tensor);
338#else338#else
339 ie_blob_free(&input_blob);339 ie_blob_free(&input_blob);
340#endif340#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