ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Conv2D.cpp File Reference
#include "Conv2D.h"
#include "Assert.h"
#include "internal/Spatial.h"

Go to the source code of this file.

Functions

bool convPrepare (const Shape &input, const Shape &filter, const Shape &bias, int32_t padding_left, int32_t padding_right, int32_t padding_top, int32_t padding_bottom, int32_t stride_width, int32_t stride_height, Shape *output)
 

Function Documentation

◆ convPrepare()

bool convPrepare ( const Shape input,
const Shape filter,
const Shape bias,
int32_t  padding_left,
int32_t  padding_right,
int32_t  padding_top,
int32_t  padding_bottom,
int32_t  stride_width,
int32_t  stride_height,
Shape output 
)

Definition at line 23 of file Conv2D.cpp.

26{
27 ASSERT(input.type == filter.type);
28 if (input.type == OperandType::TENSOR_QUANT8_ASYMM)
29 {
30 ASSERT(bias.type == OperandType::TENSOR_INT32);
31 }
32 else
33 {
34 ASSERT(input.type == bias.type);
35 }
36 ASSERT(getNumberOfDimensions(input) == 4);
37 ASSERT(getNumberOfDimensions(filter) == 4);
38 ASSERT(getNumberOfDimensions(bias) == 1);
39
40 ASSERT(getSizeOfDimension(filter, 0) == getSizeOfDimension(bias, 0));
41 ASSERT(getSizeOfDimension(filter, 3) == getSizeOfDimension(input, 3));
42
43 uint32_t channels_out = getSizeOfDimension(filter, 0);
44 uint32_t width = getSizeOfDimension(input, 2);
45 uint32_t height = getSizeOfDimension(input, 1);
46 uint32_t filterWidth = getSizeOfDimension(filter, 2);
47 uint32_t filterHeight = getSizeOfDimension(filter, 1);
48 uint32_t batches = getSizeOfDimension(input, 0);
49
50 uint32_t outWidth = computeOutSize(width, filterWidth, stride_width, padding_left, padding_right);
51 uint32_t outHeight =
52 computeOutSize(height, filterHeight, stride_height, padding_top, padding_bottom);
53
54 output->type = input.type;
55 output->dimensions = {batches, outHeight, outWidth, channels_out};
56 return true;
57}
uint32_t computeOutSize(uint32_t imageSize, uint32_t filterSize, uint32_t stride, uint32_t paddingHead, uint32_t paddingTail)
Definition Spatial.h:23
#define ASSERT(v)
Definition Assert.h:24
uint32_t getSizeOfDimension(const Shape &shape, uint32_t dimensionIdx)
Definition Shape.cpp:60
uint32_t getNumberOfDimensions(const Shape &shape)
Definition Shape.cpp:58

References ASSERT, computeOutSize(), getNumberOfDimensions(), and getSizeOfDimension().