1 /** 2 * Copyright 2023 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 17 #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_CPU_NNACL_KERNEL_H_ 18 #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_CPU_NNACL_KERNEL_H_ 19 20 #include <vector> 21 #include "nnacl/kernel.h" 22 #include "src/executor/kernel_exec.h" 23 #include "src/litert/lite_kernel.h" 24 25 namespace mindspore::nnacl { 26 class NNACLKernel : public kernel::LiteKernel { 27 public: NNACLKernel(OpParameter * parameter,const std::vector<lite::Tensor * > & inputs,const std::vector<lite::Tensor * > & outputs,const lite::InnerContext * ctx)28 explicit NNACLKernel(OpParameter *parameter, const std::vector<lite::Tensor *> &inputs, 29 const std::vector<lite::Tensor *> &outputs, const lite::InnerContext *ctx) 30 : LiteKernel(parameter, inputs, outputs, ctx) { 31 exec_env_ = const_cast<ExecEnv *>(ctx->GetExecEnv()); 32 } 33 ~NNACLKernel() override; 34 int Prepare() override; 35 int ReSize() override; 36 int Run() override; 37 38 /* Execute after NNACLKernel creation 39 * Create KernelBase */ 40 int InitKernel(const TypeId &data_type, const lite::InnerContext *ctx); Kernel()41 const KernelBase *Kernel() const { return kernel_; } 42 43 protected: 44 void UpdateTensorC(); 45 int OptimizeDataCopy(); 46 47 private: 48 int NNACLCheckArgs(); 49 50 protected: 51 ExecEnv *exec_env_ = nullptr; 52 KernelBase *kernel_ = nullptr; 53 TensorC **in_ = nullptr; 54 TensorC **out_ = nullptr; 55 size_t in_size_ = 0; 56 size_t out_size_ = 0; 57 }; 58 } // namespace mindspore::nnacl 59 60 #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_CPU_NNACL_KERNEL_H_ 61