35 for (
int i = 0;
i < 4; ++
i) {
55 return (2 * paddings - 1 - given);
57 return (2 * paddings - given);
67 int offset = given - border;
68 return (border - 1 - offset);
70 int offset = given - border;
71 return (border - 2 - offset);
87 int32_t input_operand_index = input_operand_indexes[0];
88 int number = operands[input_operand_index].
dims[0];
89 int height = operands[input_operand_index].
dims[1];
90 int width = operands[input_operand_index].
dims[2];
91 int channel = operands[input_operand_index].
dims[3];
92 const float *
input = operands[input_operand_index].
data;
100 int wc_stride = c_stride *
width;
101 int hwc_stride = wc_stride *
height;
103 int new_c_stride = new_channel;
104 int new_wc_stride = new_c_stride * new_width;
105 int new_hwc_stride = new_wc_stride * new_height;
107 DnnOperand *output_operand = &operands[output_operand_index];
108 output_operand->
dims[0] = new_number;
109 output_operand->
dims[1] = new_height;
110 output_operand->
dims[2] = new_width;
111 output_operand->
dims[3] = new_channel;
114 if (output_operand->
length <= 0) {
119 if (!output_operand->
data) {
123 output = output_operand->
data;
126 for (
int n = 0; n < number; n++) {
129 const float *
src = input + n * hwc_stride +
h * wc_stride +
w * c_stride;
130 float *dst = output + (n + params->
paddings[0][0]) * new_hwc_stride
131 + (
h + params->
paddings[1][0]) * new_wc_stride
132 + (
w + params->
paddings[2][0]) * new_c_stride
134 memcpy(dst, src, channel *
sizeof(
float));
140 before_paddings = params->
paddings[0][0];
141 after_paddings = params->
paddings[0][1];
142 for (
int n = 0; n < before_paddings; n++) {
143 float *dst = output + n * new_hwc_stride;
145 for (
int i = 0;
i < new_hwc_stride;
i++) {
151 float *
src = output + buddy * new_hwc_stride;
152 memcpy(dst, src, new_hwc_stride *
sizeof(
float));
155 for (
int n = 0; n < after_paddings; n++) {
156 int given = number + before_paddings + n;
157 float *dst = output + given * new_hwc_stride;
159 for (
int i = 0;
i < new_hwc_stride;
i++) {
164 float *
src = output + buddy * new_hwc_stride;
165 memcpy(dst, src, new_hwc_stride *
sizeof(
float));
170 before_paddings = params->
paddings[1][0];
171 after_paddings = params->
paddings[1][1];
172 for (
int n = 0; n < new_number; n++) {
173 float *start = output + n * new_hwc_stride;
174 for (
int h = 0;
h < before_paddings;
h++) {
175 float *dst = start +
h * new_wc_stride;
177 for (
int i = 0;
i < new_wc_stride;
i++) {
182 float *
src = start + buddy * new_wc_stride;
183 memcpy(dst, src, new_wc_stride *
sizeof(
float));
186 for (
int h = 0;
h < after_paddings;
h++) {
187 int given = height + before_paddings +
h;
188 float *dst = start + given * new_wc_stride;
190 for (
int i = 0;
i < new_wc_stride;
i++) {
195 float *
src = start + buddy * new_wc_stride;
196 memcpy(dst, src, new_wc_stride *
sizeof(
float));
202 before_paddings = params->
paddings[2][0];
203 after_paddings = params->
paddings[2][1];
204 for (
int n = 0; n < new_number; n++) {
205 for (
int h = 0;
h < new_height;
h++) {
206 float *start = output + n * new_hwc_stride +
h * new_wc_stride;
207 for (
int w = 0;
w < before_paddings;
w++) {
208 float *dst = start +
w * new_c_stride;
210 for (
int i = 0;
i < new_c_stride;
i++) {
215 float *
src = start + buddy * new_c_stride;
216 memcpy(dst, src, new_c_stride *
sizeof(
float));
219 for (
int w = 0;
w < after_paddings;
w++) {
220 int given = width + before_paddings +
w;
221 float *dst = start + given * new_c_stride;
223 for (
int i = 0;
i < new_c_stride;
i++) {
228 float *
src = start + buddy * new_c_stride;
229 memcpy(dst, src, new_c_stride *
sizeof(
float));
236 before_paddings = params->
paddings[3][0];
237 after_paddings = params->
paddings[3][1];
238 for (
int n = 0; n < new_number; n++) {
239 for (
int h = 0;
h < new_height;
h++) {
240 for (
int w = 0;
w < new_width;
w++) {
241 float *start = output + n * new_hwc_stride +
h * new_wc_stride +
w * new_c_stride;
242 for (
int c = 0;
c < before_paddings;
c++) {
243 float *dst = start +
c;
248 float *
src = start + buddy;
252 for (
int c = 0;
c < after_paddings;
c++) {
253 int given = channel + before_paddings +
c;
254 float *dst = start + given;
259 float *
src = start + buddy;
void * av_realloc(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory.
int ff_dnn_execute_layer_pad(DnnOperand *operands, const int32_t *input_operand_indexes, int32_t output_operand_index, const void *parameters, NativeContext *ctx)
int32_t input_operand_indexes[4]
a layer can have multiple inputs and one output.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce output
DNNDataType data_type
support different kinds of data type such as float, half float, int8 etc, first support float now...
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
unsigned int avio_rl32(AVIOContext *s)
void * data
data pointer with data length in bytes.
simple assert() macros that are a bit more flexible than ISO C assert().
int32_t dims[4]
there are two memory layouts, NHWC or NCHW, so we use dims, dims[0] is Number.
static int after_get_buddy(int given, int border, LayerPadModeParam mode)
static int before_get_buddy(int given, int paddings, LayerPadModeParam mode)
layer pad (equivalent to tf.pad) for native backend.
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some input
channel
Use these values when setting the channel map with ebur128_set_channel().
int ff_dnn_load_layer_pad(Layer *layer, AVIOContext *model_file_context, int file_size, int operands_num)
mode
Use these values in ebur128_init (or'ed).
int32_t ff_calculate_operand_data_length(const DnnOperand *oprd)
int32_t output_operand_index