• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 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 
17 #ifndef MINDSPORE_LITE_SRC_RUNTIME_DELEGATE_NPU_NPU_EXECUTOR_H_
18 #define MINDSPORE_LITE_SRC_RUNTIME_DELEGATE_NPU_NPU_EXECUTOR_H_
19 #include <string>
20 #include <memory>
21 #include <utility>
22 #include <vector>
23 #include "include/errorcode.h"
24 #include "include/HiAiModelManagerService.h"
25 #include "src/litert/delegate/npu/npu_manager.h"
26 #include "src/litert/delegate/npu/op/npu_op.h"
27 
28 namespace mindspore::lite {
29 class NPUExecutor {
30  public:
31   explicit NPUExecutor(const std::string &model_name, NPUManager *npu_manager = nullptr)
model_name_(model_name)32       : model_name_(model_name), npu_manager_(npu_manager) {}
33   ~NPUExecutor();
34   int Prepare();
35 
36   int Run(const std::vector<mindspore::MSTensor> &in_tensors, const std::vector<mindspore::MSTensor> &valid_out_tensors,
37           const std::vector<mindspore::MSTensor> &all_out_tensors, const std::vector<NPUOp *> &out_ops);
38 
InitInputMappingRelationShip(const std::vector<size_t> & input_index)39   void InitInputMappingRelationShip(const std::vector<size_t> &input_index) { input_relationship_ = input_index; }
40 
41  private:
42   int GetIOTensorVec();
43 
44   int UpdateInputTensorVec(const std::vector<hiai::TensorDimension> &input_dimension);
45 
46   int UpdateOutputTensorVec(const std::vector<hiai::TensorDimension> &output_dimension);
47 
48  private:
49   std::string model_name_;
50   NPUManager *npu_manager_ = nullptr;
51   std::shared_ptr<hiai::AiModelMngerClient> client_ = nullptr;
52   std::vector<std::shared_ptr<hiai::AiTensor>> npu_input_tensors_;
53   std::vector<std::shared_ptr<hiai::AiTensor>> npu_output_tensors_;
54   std::vector<size_t> input_relationship_;
55 };
56 }  // namespace mindspore::lite
57 #endif  // MINDSPORE_LITE_SRC_RUNTIME_DELEGATE_NPU_NPU_EXECUTOR_H_
58