ONE - On-device Neural Engine
Loading...
Searching...
No Matches
DepthwiseConv2D.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
3 * Copyright (C) 2017 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#include "DepthwiseConv2D.h"
19#include "Assert.h"
20
21#include "internal/Spatial.h"
22
23bool depthwiseConvPrepare(const Shape &input, const Shape &filter, const Shape &bias,
24 int32_t padding_left, int32_t padding_right, int32_t padding_top,
25 int32_t padding_bottom, int32_t stride_width, int32_t stride_height,
26 Shape *output)
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
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 Shape.h:28