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

Go to the source code of this file.

Functions

bool depthwiseConvPrepare (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

◆ depthwiseConvPrepare()

bool depthwiseConvPrepare ( 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 DepthwiseConv2D.cpp.

27{
28 ASSERT(input.type == filter.type);
29 if (input.type == OperandType::TENSOR_QUANT8_ASYMM)
30 {
31 ASSERT(bias.type == OperandType::TENSOR_INT32);
32 }
33 else
34 {
35 ASSERT(input.type == bias.type);
36 }
37 ASSERT(getNumberOfDimensions(input) == 4);
38 ASSERT(getNumberOfDimensions(filter) == 4);
39 ASSERT(getNumberOfDimensions(bias) == 1);
40
41 ASSERT(getSizeOfDimension(filter, 3) == getSizeOfDimension(bias, 0));
42
43 uint32_t channels_out = getSizeOfDimension(filter, 3);
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().