1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef NEURAL_NETWORK_RUNTIME_POOLING_BUILDER_H 17 #define NEURAL_NETWORK_RUNTIME_POOLING_BUILDER_H 18 19 #include "mindir.h" 20 21 #include "ops_builder.h" 22 23 namespace OHOS { 24 namespace NeuralNetworkRuntime { 25 namespace Ops { 26 class PoolingBuilder : public OpsBuilder { 27 public: 28 typedef OH_NN_ReturnCode (PoolingBuilder::*FuncPtr)(const std::shared_ptr<NNTensor>&); 29 30 PoolingBuilder() = default; 31 virtual ~PoolingBuilder() = default; 32 33 OH_NN_ReturnCode PoolingBuild(const std::vector<uint32_t>& paramsIndex, 34 const std::vector<uint32_t>& inputsIndex, 35 const std::vector<uint32_t>& outputsIndex, 36 const std::vector<std::shared_ptr<NNTensor>>& allTensors); 37 38 OH_NN_ReturnCode SetInputAndOutput(const std::vector<uint32_t>& inputsIndex, 39 const std::vector<uint32_t>& outputsIndex, 40 const std::vector<std::shared_ptr<NNTensor>>& allTensors); 41 42 OH_NN_ReturnCode SetKernel(const std::shared_ptr<NNTensor>& tensor); 43 OH_NN_ReturnCode SetStrides(const std::shared_ptr<NNTensor>& tensor); 44 OH_NN_ReturnCode SetPadModeOrPaddings(const std::shared_ptr<NNTensor>& tensor); 45 OH_NN_ReturnCode SetRoundMode(const std::shared_ptr<NNTensor>& tensor); 46 OH_NN_ReturnCode SetActivation(const std::shared_ptr<NNTensor>& tensor); 47 OH_NN_ReturnCode SetGlobal(const std::shared_ptr<NNTensor>& tensor); 48 49 protected: 50 std::vector<int64_t> m_kernelSize; 51 std::vector<int64_t> m_pad; 52 std::vector<int64_t> m_strides; 53 mindspore::lite::PadMode m_padMode {mindspore::lite::PAD_MODE_PAD}; 54 mindspore::lite::ActivationType m_activationType {mindspore::lite::ACTIVATION_TYPE_NO_ACTIVATION}; 55 mindspore::lite::RoundMode m_roundMode {mindspore::lite::ROUND_MODE_FLOOR}; 56 mindspore::lite::Format m_format {mindspore::lite::FORMAT_NCHW}; 57 bool m_global {false}; 58 std::unordered_map<OH_NN_TensorType, FuncPtr> m_paramMap = { 59 {OH_NN_MAX_POOL_KERNEL_SIZE, &PoolingBuilder::SetKernel}, 60 {OH_NN_MAX_POOL_STRIDE, &PoolingBuilder::SetStrides}, 61 {OH_NN_MAX_POOL_PAD_MODE, &PoolingBuilder::SetPadModeOrPaddings}, 62 {OH_NN_MAX_POOL_PAD, &PoolingBuilder::SetPadModeOrPaddings}, 63 {OH_NN_MAX_POOL_ACTIVATION_TYPE, &PoolingBuilder::SetActivation}, 64 {OH_NN_MAX_POOL_ROUND_MODE, &PoolingBuilder::SetRoundMode}, 65 {OH_NN_MAX_POOL_GLOBAL, &PoolingBuilder::SetGlobal}, 66 67 {OH_NN_AVG_POOL_KERNEL_SIZE, &PoolingBuilder::SetKernel}, 68 {OH_NN_AVG_POOL_STRIDE, &PoolingBuilder::SetStrides}, 69 {OH_NN_AVG_POOL_PAD_MODE, &PoolingBuilder::SetPadModeOrPaddings}, 70 {OH_NN_AVG_POOL_PAD, &PoolingBuilder::SetPadModeOrPaddings}, 71 {OH_NN_AVG_POOL_ACTIVATION_TYPE, &PoolingBuilder::SetActivation}, 72 {OH_NN_AVG_POOL_ROUND_MODE, &PoolingBuilder::SetRoundMode}, 73 {OH_NN_AVG_POOL_GLOBAL, &PoolingBuilder::SetGlobal} 74 }; 75 }; 76 } // namespace Ops 77 } // namespace NeuralNetworkRuntime 78 } // namespace OHOS 79 80 #endif // NEURAL_NETWORK_RUNTIME_POOLING_BUILDER_H 81