1 /** 2 * Copyright 2020-2021 Huawei Technologies Co., Ltd 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #ifndef MINDSPORE_LITE_SRC_RUNTIME_DELEGATE_NPU_OP_CONVOLUTION_BASE_NPU_H_ 17 #define MINDSPORE_LITE_SRC_RUNTIME_DELEGATE_NPU_OP_CONVOLUTION_BASE_NPU_H_ 18 19 #include <vector> 20 #include <memory> 21 #include <string> 22 #include "include/graph/op/all_ops.h" 23 #include "src/delegate/npu/op/npu_op.h" 24 namespace mindspore { 25 constexpr int WEIGHT_INDEX = 1; 26 constexpr int BIAS_INDEX = 2; 27 constexpr int CONV_INPUT_SIZE = 3; 28 29 class ConvolutionBaseNPUOp : public NPUOp { 30 public: ConvolutionBaseNPUOp(const schema::Primitive * primitive,const std::vector<mindspore::MSTensor> & in_tensors,const std::vector<mindspore::MSTensor> & out_tensors,std::string name)31 ConvolutionBaseNPUOp(const schema::Primitive *primitive, const std::vector<mindspore::MSTensor> &in_tensors, 32 const std::vector<mindspore::MSTensor> &out_tensors, std::string name) 33 : NPUOp(primitive, in_tensors, out_tensors, name) {} 34 35 ~ConvolutionBaseNPUOp() override; 36 37 protected: 38 int InitWeightConst(const std::vector<mindspore::MSTensor> &inputs); 39 int InitBiasConst(const std::vector<mindspore::MSTensor> &inputs); 40 int SetActivation(const ge::Operator *input, schema::ActivationType act_type); 41 void FreeTmpWeight(); 42 hiai::op::Activation *act_ = nullptr; 43 hiai::op::Const *weight_ = nullptr; 44 hiai::op::Const *bias_ = nullptr; 45 float *fp32_weight_ = nullptr; 46 float *nchw_weight_ = nullptr; 47 }; 48 } // namespace mindspore 49 #endif // MINDSPORE_LITE_SRC_RUNTIME_DELEGATE_NPU_OP_CONVOLUTION_BASE_NPU_H_ 50