1 /** 2 * Copyright 2022 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 LITE_NNRT_MODEL_KERNEL_H 17 #define LITE_NNRT_MODEL_KERNEL_H 18 #include <vector> 19 #include <queue> 20 #include <map> 21 #include <utility> 22 #include "include/api/kernel.h" 23 #include "interfaces/kits/c/neural_network_runtime.h" 24 #include "src/common/log_adapter.h" 25 #include "include/errorcode.h" 26 27 namespace mindspore { 28 29 class NNRTModelKernel : public kernel::Kernel { 30 /** 31 * Because nnr can't run single op, but the whole model. So we decide to make the whole model into one kernel. 32 * */ 33 public: NNRTModelKernel(OH_NNExecutor * oh_nn_executor,const std::vector<mindspore::MSTensor> & inputs,const std::vector<mindspore::MSTensor> & outputs)34 NNRTModelKernel(OH_NNExecutor *oh_nn_executor, const std::vector<mindspore::MSTensor> &inputs, 35 const std::vector<mindspore::MSTensor> &outputs) 36 : kernel::Kernel(inputs, outputs, nullptr, nullptr), oh_nn_executor(oh_nn_executor) {} 37 int Prepare() override; 38 int Execute() override; ReSize()39 int ReSize() override { 40 MS_LOG(ERROR) << "NNRT does not support the resize function temporarily."; 41 return lite::RET_ERROR; 42 }; 43 OH_NN_DataType ConvertDataType(mindspore::DataType data_type); 44 int PrepareInputs(); 45 int TransferOutputs(); ~NNRTModelKernel()46 ~NNRTModelKernel() override { 47 MS_LOG(INFO) << "start NNExecutor Destroy."; 48 OH_NNExecutor_Destroy(&oh_nn_executor); 49 MS_LOG(INFO) << "start NNExecutor Finish."; 50 } 51 52 protected: 53 OH_NNExecutor *oh_nn_executor = nullptr; 54 }; 55 } // namespace mindspore 56 57 #endif // LITE_NNRTT_MODEL_KERNEL_H 58