26 #define CLAMP_TO_EDGE(x, w) ((x) < 0 ? 0 : ((x) >= (w) ? (w - 1) : (x)))
41 #if HAVE_PTHREAD_CANCEL
51 conv_params =
av_malloc(
sizeof(*conv_params));
66 dnn_size += kernel_size * 4;
70 if (dnn_size > file_size || conv_params->
input_num <= 0 ||
77 if (!conv_params->
kernel) {
81 for (
int i = 0;
i < kernel_size; ++
i) {
98 layer->
params = conv_params;
118 int height = operands[input_operand_index].
dims[1];
119 int width = operands[input_operand_index].
dims[2];
120 int channel = operands[input_operand_index].
dims[3];
121 const float *
input = operands[input_operand_index].
data;
127 int filter_size = conv_params->
kernel_size * filter_linesize;
135 for (
int y = thread_param->
thread_start; y < thread_param->thread_end; ++y) {
136 for (
int x = pad_size; x <
width - pad_size; ++x) {
137 for (
int n_filter = 0; n_filter < conv_params->
output_num; ++n_filter) {
143 for (
int ch = 0; ch < conv_params->
input_num; ++ch) {
144 for (
int kernel_y = 0; kernel_y < conv_params->
kernel_size; ++kernel_y) {
145 for (
int kernel_x = 0; kernel_x < conv_params->
kernel_size; ++kernel_x) {
150 input_pel =
input[y_pos * src_linesize + x_pos * conv_params->
input_num + ch];
152 int y_pos = y + (kernel_y - radius) * conv_params->
dilation;
153 int x_pos = x + (kernel_x - radius) * conv_params->
dilation;
154 input_pel = (x_pos < 0 || x_pos >=
width || y_pos < 0 || y_pos >=
height) ? 0.0 :
155 input[y_pos * src_linesize + x_pos * conv_params->
input_num + ch];
159 output[n_filter] += input_pel * conv_params->
kernel[n_filter * filter_size + kernel_y * filter_linesize +
190 #if HAVE_PTHREAD_CANCEL
191 int thread_num = (
ctx->options.conv2d_threads <= 0 ||
ctx->options.conv2d_threads >
av_cpu_count())
200 int height = operands[input_operand_indexes[0]].
dims[1];
201 int width = operands[input_operand_indexes[0]].
dims[2];
203 DnnOperand *output_operand = &operands[output_operand_index];
206 output_operand->
dims[0] = operands[input_operand_indexes[0]].
dims[0];
207 output_operand->
dims[1] =
height - pad_size * 2;
208 output_operand->
dims[2] =
width - pad_size * 2;
212 if (output_operand->
length <= 0) {
223 thread_common_param.
operands = operands;
227 thread_common_param.
ctx =
ctx;
229 #if HAVE_PTHREAD_CANCEL
233 thread_stride = (
height - pad_size * 2) / thread_num;
235 for (
int i = 0;
i < thread_num;
i++){
247 for (
int i = 0;
i < thread_num;
i++){