lavfi/dnn: Error Specificity in Native Backend Layers

This commit returns specific error codes from the execution
functions in the Native Backend layers instead of DNN_ERROR.

Signed-off-by: Shubhanshu Saxena <shubhanshu.e01@gmail.com>
release/5.1
Shubhanshu Saxena 3 years ago committed by Guo Yejun
parent e5ce6a6070
commit b602f11a06
  1. 6
      libavfilter/dnn/dnn_backend_native_layer_avgpool.c
  2. 3
      libavfilter/dnn/dnn_backend_native_layer_avgpool.h
  3. 14
      libavfilter/dnn/dnn_backend_native_layer_conv2d.c
  4. 3
      libavfilter/dnn/dnn_backend_native_layer_conv2d.h
  5. 6
      libavfilter/dnn/dnn_backend_native_layer_dense.c
  6. 3
      libavfilter/dnn/dnn_backend_native_layer_dense.h
  7. 6
      libavfilter/dnn/dnn_backend_native_layer_depth2space.c
  8. 3
      libavfilter/dnn/dnn_backend_native_layer_depth2space.h
  9. 6
      libavfilter/dnn/dnn_backend_native_layer_mathbinary.c
  10. 6
      libavfilter/dnn/dnn_backend_native_layer_mathunary.c
  11. 3
      libavfilter/dnn/dnn_backend_native_layer_mathunary.h
  12. 4
      libavfilter/dnn/dnn_backend_native_layer_maximum.c
  13. 4
      libavfilter/dnn/dnn_backend_native_layer_pad.c
  14. 2
      libavfilter/dnn_interface.h

@ -109,12 +109,12 @@ int ff_dnn_execute_layer_avg_pool(DnnOperand *operands, const int32_t *input_ope
output_operand->length = ff_calculate_operand_data_length(output_operand); output_operand->length = ff_calculate_operand_data_length(output_operand);
if (output_operand->length <= 0) { if (output_operand->length <= 0) {
av_log(ctx, AV_LOG_ERROR, "The output data length overflow\n"); av_log(ctx, AV_LOG_ERROR, "The output data length overflow\n");
return DNN_ERROR; return AVERROR(EINVAL);
} }
output_operand->data = av_realloc(output_operand->data, output_operand->length); output_operand->data = av_realloc(output_operand->data, output_operand->length);
if (!output_operand->data) { if (!output_operand->data) {
av_log(ctx, AV_LOG_ERROR, "Failed to reallocate memory for output\n"); av_log(ctx, AV_LOG_ERROR, "Failed to reallocate memory for output\n");
return DNN_ERROR; return AVERROR(ENOMEM);
} }
output = output_operand->data; output = output_operand->data;
@ -143,5 +143,5 @@ int ff_dnn_execute_layer_avg_pool(DnnOperand *operands, const int32_t *input_ope
} }
} }
return 0; return DNN_SUCCESS;
} }

@ -60,7 +60,8 @@ int ff_dnn_load_layer_avg_pool(Layer *layer, AVIOContext *model_file_context, in
* @param parameters average pooling parameters * @param parameters average pooling parameters
* @param ctx pointer to Native model context for logging * @param ctx pointer to Native model context for logging
* @retval 0 if the execution succeeds * @retval 0 if the execution succeeds
* @retval DNN_ERROR if the execution fails * @retval AVERROR(ENOMEM) if memory allocation fails
* @retval AVERROR(EINVAL) for invalid arguments
*/ */
int ff_dnn_execute_layer_avg_pool(DnnOperand *operands, const int32_t *input_operand_indexes, int ff_dnn_execute_layer_avg_pool(DnnOperand *operands, const int32_t *input_operand_indexes,
int32_t output_operand_index, const void *parameters, NativeContext *ctx); int32_t output_operand_index, const void *parameters, NativeContext *ctx);

@ -211,12 +211,12 @@ int ff_dnn_execute_layer_conv2d(DnnOperand *operands, const int32_t *input_opera
output_operand->length = ff_calculate_operand_data_length(output_operand); output_operand->length = ff_calculate_operand_data_length(output_operand);
if (output_operand->length <= 0) { if (output_operand->length <= 0) {
av_log(ctx, AV_LOG_ERROR, "The output data length overflow\n"); av_log(ctx, AV_LOG_ERROR, "The output data length overflow\n");
return DNN_ERROR; return AVERROR(EINVAL);
} }
tmp = av_realloc(output_operand->data, output_operand->length); tmp = av_realloc(output_operand->data, output_operand->length);
if (!tmp) { if (!tmp) {
av_log(ctx, AV_LOG_ERROR, "Failed to reallocate memory for output\n"); av_log(ctx, AV_LOG_ERROR, "Failed to reallocate memory for output\n");
return DNN_ERROR; return AVERROR(ENOMEM);
} }
output_operand->data = tmp; output_operand->data = tmp;
thread_common_param.output_data = output_operand->data; thread_common_param.output_data = output_operand->data;
@ -229,17 +229,19 @@ int ff_dnn_execute_layer_conv2d(DnnOperand *operands, const int32_t *input_opera
#if HAVE_PTHREAD_CANCEL #if HAVE_PTHREAD_CANCEL
thread_param = av_malloc_array(thread_num, sizeof(*thread_param)); thread_param = av_malloc_array(thread_num, sizeof(*thread_param));
if (!thread_param) if (!thread_param)
return DNN_ERROR; return AVERROR(ENOMEM);
thread_stride = (height - pad_size * 2) / thread_num; thread_stride = (height - pad_size * 2) / thread_num;
//create threads //create threads
for (int i = 0; i < thread_num; i++){ for (int i = 0; i < thread_num; i++){
int thread_ret = 0;
thread_param[i].thread_common_param = &thread_common_param; thread_param[i].thread_common_param = &thread_common_param;
thread_param[i].thread_start = thread_stride * i + pad_size; thread_param[i].thread_start = thread_stride * i + pad_size;
thread_param[i].thread_end = (i == thread_num - 1) ? (height - pad_size) : (thread_param[i].thread_start + thread_stride); thread_param[i].thread_end = (i == thread_num - 1) ? (height - pad_size) : (thread_param[i].thread_start + thread_stride);
if (pthread_create(&thread_param[i].thread, NULL, thread_ret = pthread_create(&thread_param[i].thread, NULL,
dnn_execute_layer_conv2d_thread, &thread_param[i])) { dnn_execute_layer_conv2d_thread, &thread_param[i]);
if (thread_ret) {
thread_num = i; thread_num = i;
ret = DNN_ERROR; ret = AVERROR(thread_ret);
break; break;
} }
} }

@ -60,7 +60,8 @@ int ff_dnn_load_layer_conv2d(Layer *layer, AVIOContext *model_file_context, int
* @param parameters convolution parameters * @param parameters convolution parameters
* @param ctx pointer to Native model context for logging * @param ctx pointer to Native model context for logging
* @retval 0 if the execution succeeds * @retval 0 if the execution succeeds
* @retval DNN_ERROR if the execution fails * @retval AVERROR(ENOMEM) if memory allocation fails
* @retval AVERROR(EINVAL) for invalid arguments
*/ */
int ff_dnn_execute_layer_conv2d(DnnOperand *operands, const int32_t *input_operand_indexes, int ff_dnn_execute_layer_conv2d(DnnOperand *operands, const int32_t *input_operand_indexes,
int32_t output_operand_index, const void *parameters, NativeContext *ctx); int32_t output_operand_index, const void *parameters, NativeContext *ctx);

@ -104,12 +104,12 @@ int ff_dnn_execute_layer_dense(DnnOperand *operands, const int32_t *input_operan
output_operand->length = ff_calculate_operand_data_length(output_operand); output_operand->length = ff_calculate_operand_data_length(output_operand);
if (output_operand->length <= 0) { if (output_operand->length <= 0) {
av_log(ctx, AV_LOG_ERROR, "The output data length overflow\n"); av_log(ctx, AV_LOG_ERROR, "The output data length overflow\n");
return DNN_ERROR; return AVERROR(EINVAL);
} }
output_operand->data = av_realloc(output_operand->data, output_operand->length); output_operand->data = av_realloc(output_operand->data, output_operand->length);
if (!output_operand->data) { if (!output_operand->data) {
av_log(ctx, AV_LOG_ERROR, "Failed to reallocate memory for output\n"); av_log(ctx, AV_LOG_ERROR, "Failed to reallocate memory for output\n");
return DNN_ERROR; return AVERROR(ENOMEM);
} }
output = output_operand->data; output = output_operand->data;
@ -147,5 +147,5 @@ int ff_dnn_execute_layer_dense(DnnOperand *operands, const int32_t *input_operan
output += dense_params->output_num; output += dense_params->output_num;
} }
} }
return 0; return DNN_SUCCESS;
} }

@ -57,7 +57,8 @@ int ff_dnn_load_layer_dense(Layer *layer, AVIOContext *model_file_context, int f
* @param parameters dense layer parameters * @param parameters dense layer parameters
* @param ctx pointer to Native model context for logging * @param ctx pointer to Native model context for logging
* @retval 0 if the execution succeeds * @retval 0 if the execution succeeds
* @retval DNN_ERROR if the execution fails * @retval AVERROR(ENOMEM) if memory allocation fails
* @retval AVERROR(EINVAL) for invalid arguments
*/ */
int ff_dnn_execute_layer_dense(DnnOperand *operands, const int32_t *input_operand_indexes, int ff_dnn_execute_layer_dense(DnnOperand *operands, const int32_t *input_operand_indexes,
int32_t output_operand_index, const void *parameters, NativeContext *ctx); int32_t output_operand_index, const void *parameters, NativeContext *ctx);

@ -76,12 +76,12 @@ int ff_dnn_execute_layer_depth2space(DnnOperand *operands, const int32_t *input_
output_operand->length = ff_calculate_operand_data_length(output_operand); output_operand->length = ff_calculate_operand_data_length(output_operand);
if (output_operand->length <= 0) { if (output_operand->length <= 0) {
av_log(ctx, AV_LOG_ERROR, "The output data length overflow\n"); av_log(ctx, AV_LOG_ERROR, "The output data length overflow\n");
return DNN_ERROR; return AVERROR(EINVAL);
} }
output_operand->data = av_realloc(output_operand->data, output_operand->length); output_operand->data = av_realloc(output_operand->data, output_operand->length);
if (!output_operand->data) { if (!output_operand->data) {
av_log(ctx, AV_LOG_ERROR, "Failed to reallocate memory for output\n"); av_log(ctx, AV_LOG_ERROR, "Failed to reallocate memory for output\n");
return DNN_ERROR; return AVERROR(ENOMEM);
} }
output = output_operand->data; output = output_operand->data;
@ -98,5 +98,5 @@ int ff_dnn_execute_layer_depth2space(DnnOperand *operands, const int32_t *input_
} }
output += output_linesize; output += output_linesize;
} }
return 0; return DNN_SUCCESS;
} }

@ -63,7 +63,8 @@ int ff_dnn_load_layer_depth2space(Layer *layer, AVIOContext *model_file_context,
* @param parameters depth to space layer parameters * @param parameters depth to space layer parameters
* @param ctx pointer to Native model context for logging * @param ctx pointer to Native model context for logging
* @retval 0 if the execution succeeds * @retval 0 if the execution succeeds
* @retval DNN_ERROR if the execution fails * @retval AVERROR(ENOMEM) if memory allocation fails
* @retval AVERROR(EINVAL) for invalid arguments
*/ */
int ff_dnn_execute_layer_depth2space(DnnOperand *operands, const int32_t *input_operand_indexes, int ff_dnn_execute_layer_depth2space(DnnOperand *operands, const int32_t *input_operand_indexes,
int32_t output_operand_index, const void *parameters, NativeContext *ctx); int32_t output_operand_index, const void *parameters, NativeContext *ctx);

@ -159,12 +159,12 @@ int ff_dnn_execute_layer_math_binary(DnnOperand *operands, const int32_t *input_
output->length = ff_calculate_operand_data_length(output); output->length = ff_calculate_operand_data_length(output);
if (output->length <= 0) { if (output->length <= 0) {
av_log(ctx, AV_LOG_ERROR, "The output data length overflow\n"); av_log(ctx, AV_LOG_ERROR, "The output data length overflow\n");
return DNN_ERROR; return AVERROR(EINVAL);
} }
output->data = av_realloc(output->data, output->length); output->data = av_realloc(output->data, output->length);
if (!output->data) { if (!output->data) {
av_log(ctx, AV_LOG_ERROR, "Failed to reallocate memory for output\n"); av_log(ctx, AV_LOG_ERROR, "Failed to reallocate memory for output\n");
return DNN_ERROR; return AVERROR(ENOMEM);
} }
switch (params->bin_op) { switch (params->bin_op) {
@ -188,6 +188,6 @@ int ff_dnn_execute_layer_math_binary(DnnOperand *operands, const int32_t *input_
return 0; return 0;
default: default:
av_log(ctx, AV_LOG_ERROR, "Unmatch math binary operator\n"); av_log(ctx, AV_LOG_ERROR, "Unmatch math binary operator\n");
return DNN_ERROR; return AVERROR(EINVAL);
} }
} }

@ -68,12 +68,12 @@ int ff_dnn_execute_layer_math_unary(DnnOperand *operands, const int32_t *input_o
output->length = ff_calculate_operand_data_length(output); output->length = ff_calculate_operand_data_length(output);
if (output->length <= 0) { if (output->length <= 0) {
av_log(ctx, AV_LOG_ERROR, "The output data length overflow\n"); av_log(ctx, AV_LOG_ERROR, "The output data length overflow\n");
return DNN_ERROR; return AVERROR(EINVAL);
} }
output->data = av_realloc(output->data, output->length); output->data = av_realloc(output->data, output->length);
if (!output->data) { if (!output->data) {
av_log(ctx, AV_LOG_ERROR, "Failed to reallocate memory for output\n"); av_log(ctx, AV_LOG_ERROR, "Failed to reallocate memory for output\n");
return DNN_ERROR; return AVERROR(ENOMEM);
} }
dims_count = ff_calculate_operand_dims_count(output); dims_count = ff_calculate_operand_dims_count(output);
@ -151,6 +151,6 @@ int ff_dnn_execute_layer_math_unary(DnnOperand *operands, const int32_t *input_o
return 0; return 0;
default: default:
av_log(ctx, AV_LOG_ERROR, "Unmatch math unary operator\n"); av_log(ctx, AV_LOG_ERROR, "Unmatch math unary operator\n");
return DNN_ERROR; return AVERROR(EINVAL);
} }
} }

@ -83,7 +83,8 @@ int ff_dnn_load_layer_math_unary(Layer *layer, AVIOContext *model_file_context,
* @param parameters unary math layer parameters * @param parameters unary math layer parameters
* @param ctx pointer to Native model context for logging * @param ctx pointer to Native model context for logging
* @retval 0 if the execution succeeds * @retval 0 if the execution succeeds
* @retval DNN_ERROR if the execution fails * @retval AVERROR(ENOMEM) if memory allocation fails
* @retval AVERROR(EINVAL) for invalid arguments
*/ */
int ff_dnn_execute_layer_math_unary(DnnOperand *operands, const int32_t *input_operand_indexes, int ff_dnn_execute_layer_math_unary(DnnOperand *operands, const int32_t *input_operand_indexes,
int32_t output_operand_index, const void *parameters, NativeContext *ctx); int32_t output_operand_index, const void *parameters, NativeContext *ctx);

@ -65,12 +65,12 @@ int ff_dnn_execute_layer_maximum(DnnOperand *operands, const int32_t *input_oper
output->length = ff_calculate_operand_data_length(output); output->length = ff_calculate_operand_data_length(output);
if (output->length <= 0) { if (output->length <= 0) {
av_log(ctx, AV_LOG_ERROR, "The output data length overflow\n"); av_log(ctx, AV_LOG_ERROR, "The output data length overflow\n");
return DNN_ERROR; return AVERROR(EINVAL);
} }
output->data = av_realloc(output->data, output->length); output->data = av_realloc(output->data, output->length);
if (!output->data) { if (!output->data) {
av_log(ctx, AV_LOG_ERROR, "Failed to reallocate memory for output\n"); av_log(ctx, AV_LOG_ERROR, "Failed to reallocate memory for output\n");
return DNN_ERROR; return AVERROR(ENOMEM);
} }
dims_count = ff_calculate_operand_dims_count(output); dims_count = ff_calculate_operand_dims_count(output);

@ -113,12 +113,12 @@ int ff_dnn_execute_layer_pad(DnnOperand *operands, const int32_t *input_operand_
output_operand->length = ff_calculate_operand_data_length(output_operand); output_operand->length = ff_calculate_operand_data_length(output_operand);
if (output_operand->length <= 0) { if (output_operand->length <= 0) {
av_log(ctx, AV_LOG_ERROR, "The output data length overflow\n"); av_log(ctx, AV_LOG_ERROR, "The output data length overflow\n");
return DNN_ERROR; return AVERROR(EINVAL);
} }
output_operand->data = av_realloc(output_operand->data, output_operand->length); output_operand->data = av_realloc(output_operand->data, output_operand->length);
if (!output_operand->data) { if (!output_operand->data) {
av_log(ctx, AV_LOG_ERROR, "Failed to reallocate memory for output\n"); av_log(ctx, AV_LOG_ERROR, "Failed to reallocate memory for output\n");
return DNN_ERROR; return AVERROR(ENOMEM);
} }
output = output_operand->data; output = output_operand->data;

@ -30,6 +30,8 @@
#include "libavutil/frame.h" #include "libavutil/frame.h"
#include "avfilter.h" #include "avfilter.h"
#define DNN_GENERIC_ERROR FFERRTAG('D','N','N','!')
typedef enum {DNN_SUCCESS, DNN_ERROR} DNNReturnType; typedef enum {DNN_SUCCESS, DNN_ERROR} DNNReturnType;
typedef enum {DNN_NATIVE, DNN_TF, DNN_OV} DNNBackendType; typedef enum {DNN_NATIVE, DNN_TF, DNN_OV} DNNBackendType;

Loading…
Cancel
Save