We can directly get data ptr from tensor, so that extral memory allocation can be removed.
Showing the changes to libavfilter (1 of 1 file). Show all
Unified · Split
| @@ -204,7 +204,6 @@ static int fill_model_input_ov(OVModel *ov_model, OVRequestItem *request) · 203 unmodified lines | ||
| 204 | 204 | ov_tensor_t* tensor = NULL; |
| 205 | 205 | ov_shape_t input_shape = {0}; |
| 206 | 206 | ov_element_type_e precision; |
| 207 | − void *input_data_ptr = NULL; | |
| 208 | 207 | #else |
| 209 | 208 | dimensions_t dims; |
| 210 | 209 | precision_e precision; |
| @@ -249,12 +248,6 @@ static int fill_model_input_ov(OVModel *ov_model, OVRequestItem *request) · 38 unmodified lines | ||
| 249 | 248 | input.width = dims[2]; |
| 250 | 249 | input.channels = dims[3]; |
| 251 | 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 | 251 | #else |
| 259 | 252 | status = ie_infer_request_get_blob(request->infer_request, task->input_name, &input_blob); |
| 260 | 253 | if (status != OK) { |
| @@ -297,6 +290,26 @@ static int fill_model_input_ov(OVModel *ov_model, OVRequestItem *request) · 36 unmodified lines | ||
| 297 | 290 | request->lltasks[i] = lltask; |
| 298 | 291 | request->lltask_count = i + 1; |
| 299 | 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 | 313 | switch (ov_model->model->func_type) { |
| 301 | 314 | case DFT_PROCESS_FRAME: |
| 302 | 315 | if (task->do_ioproc) { |
| @@ -317,24 +330,11 @@ static int fill_model_input_ov(OVModel *ov_model, OVRequestItem *request) · 14 unmodified lines | ||
| 317 | 330 | av_assert0(!"should not reach here"); |
| 318 | 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 | 333 | input.data = (uint8_t *)input.data |
| 334 | 334 | + input.width * input.height * input.channels * get_datatype_size(input.dt); |
| 335 | 335 | } |
| 336 | 336 | #if HAVE_OPENVINO2 |
| 337 | − av_freep(&input_data_ptr); | |
| 337 | + ov_tensor_free(tensor); | |
| 338 | 338 | #else |
| 339 | 339 | ie_blob_free(&input_blob); |
| 340 | 340 | #endif |