• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "avgpool_builder.h"
17 
18 namespace OHOS {
19 namespace NeuralNetworkRuntime {
20 namespace Ops {
21 static const std::string OP_NAME = "AvgPool";
22 
AvgPoolBuilder()23 AvgPoolBuilder::AvgPoolBuilder() {}
24 
~AvgPoolBuilder()25 AvgPoolBuilder::~AvgPoolBuilder() {}
26 
Build(const std::vector<uint32_t> & paramsIndex,const std::vector<uint32_t> & inputsIndex,const std::vector<uint32_t> & outputsIndex,const std::vector<std::shared_ptr<NNTensor>> & allTensors)27 OH_NN_ReturnCode AvgPoolBuilder::Build(const std::vector<uint32_t>& paramsIndex,
28                                        const std::vector<uint32_t>& inputsIndex,
29                                        const std::vector<uint32_t>& outputsIndex,
30                                        const std::vector<std::shared_ptr<NNTensor>>& allTensors)
31 {
32     OH_NN_ReturnCode returnCode = PoolingBuild(paramsIndex, inputsIndex, outputsIndex, allTensors);
33     if (returnCode != OH_NN_SUCCESS) {
34         LOGE("[AvgPool] Build failed, the PoolingBuild failed.");
35         return returnCode;
36     }
37 
38     m_isBuild = true;
39     m_name = OP_NAME;
40     return OH_NN_SUCCESS;
41 }
42 
GetPrimitive()43 LiteGraphPrimitvePtr AvgPoolBuilder::GetPrimitive()
44 {
45     if (!m_isBuild) {
46         LOGE("[AvgPool] GetPrimitive failed, cannot get primitive before call build.");
47         return {nullptr, DestroyLiteGraphPrimitive};
48     }
49 
50     void* primitive = mindspore::lite::MindIR_AvgPoolFusion_CreatePrimitive(m_kernelSize, m_strides, m_pad,
51         m_padMode, m_roundMode, m_format, m_global, m_activationType);
52 
53     LiteGraphPrimitvePtr graphPrimitivePtr(primitive, DestroyLiteGraphPrimitive);
54     return graphPrimitivePtr;
55 }
56 
57 REGISTER_OPS(AvgPoolBuilder, OH_NN_OPS_AVG_POOL);
58 } // namespace Ops
59 } // namespace NeuralNetworkRuntime
60 } // namespace OHOS
61