Commit b602f11a authored by Shubhanshu Saxena's avatar Shubhanshu Saxena Committed by Guo Yejun

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: 's avatarShubhanshu Saxena <shubhanshu.e01@gmail.com>
parent e5ce6a60
......@@ -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);
if (output_operand->length <= 0) {
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);
if (!output_operand->data) {
av_log(ctx, AV_LOG_ERROR, "Failed to reallocate memory for output\n");
return DNN_ERROR;
return AVERROR(ENOMEM);
}
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 ctx pointer to Native model context for logging
* @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,
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);
if (output_operand->length <= 0) {
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);
if (!tmp) {
av_log(ctx, AV_LOG_ERROR, "Failed to reallocate memory for output\n");
return DNN_ERROR;
return AVERROR(ENOMEM);
}
output_operand->data = tmp;
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
thread_param = av_malloc_array(thread_num, sizeof(*thread_param));
if (!thread_param)
return DNN_ERROR;
return AVERROR(ENOMEM);
thread_stride = (height - pad_size * 2) / thread_num;
//create threads
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_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);
if (pthread_create(&thread_param[i].thread, NULL,
dnn_execute_layer_conv2d_thread, &thread_param[i])) {
thread_ret = pthread_create(&thread_param[i].thread, NULL,
dnn_execute_layer_conv2d_thread, &thread_param[i]);
if (thread_ret) {
thread_num = i;
ret = DNN_ERROR;
ret = AVERROR(thread_ret);
break;
}
}
......
......@@ -60,7 +60,8 @@ int ff_dnn_load_layer_conv2d(Layer *layer, AVIOContext *model_file_context, int
* @param parameters convolution parameters
* @param ctx pointer to Native model context for logging
* @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,
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);
if (output_operand->length <= 0) {
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);
if (!output_operand->data) {
av_log(ctx, AV_LOG_ERROR, "Failed to reallocate memory for output\n");
return DNN_ERROR;
return AVERROR(ENOMEM);
}
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;
}
}
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 ctx pointer to Native model context for logging
* @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,
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);
if (output_operand->length <= 0) {
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);
if (!output_operand->data) {
av_log(ctx, AV_LOG_ERROR, "Failed to reallocate memory for output\n");
return DNN_ERROR;
return AVERROR(ENOMEM);
}
output = output_operand->data;
......@@ -98,5 +98,5 @@ int ff_dnn_execute_layer_depth2space(DnnOperand *operands, const int32_t *input_
}
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 ctx pointer to Native model context for logging
* @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,
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);
if (output->length <= 0) {
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);
if (!output->data) {
av_log(ctx, AV_LOG_ERROR, "Failed to reallocate memory for output\n");
return DNN_ERROR;
return AVERROR(ENOMEM);
}
switch (params->bin_op) {
......@@ -188,6 +188,6 @@ int ff_dnn_execute_layer_math_binary(DnnOperand *operands, const int32_t *input_
return 0;
default:
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);
if (output->length <= 0) {
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);
if (!output->data) {
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);
......@@ -151,6 +151,6 @@ int ff_dnn_execute_layer_math_unary(DnnOperand *operands, const int32_t *input_o
return 0;
default:
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 ctx pointer to Native model context for logging
* @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,
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);
if (output->length <= 0) {
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);
if (!output->data) {
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);
......
......@@ -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);
if (output_operand->length <= 0) {
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);
if (!output_operand->data) {
av_log(ctx, AV_LOG_ERROR, "Failed to reallocate memory for output\n");
return DNN_ERROR;
return AVERROR(ENOMEM);
}
output = output_operand->data;
......
......@@ -30,6 +30,8 @@
#include "libavutil/frame.h"
#include "avfilter.h"
#define DNN_GENERIC_ERROR FFERRTAG('D','N','N','!')
typedef enum {DNN_SUCCESS, DNN_ERROR} DNNReturnType;
typedef enum {DNN_NATIVE, DNN_TF, DNN_OV} DNNBackendType;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment