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