• 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/delegate/npu/npu_manager.h"
26 #include "src/delegate/npu/op/npu_op.h"
27 
28 namespace mindspore {
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> &out_tensors,
37           const std::vector<NPUOp *> &in_ops);
38 
39  private:
40   int GetIOTensorVec();
41 
42   int UpdateInputTensorVec(const std::vector<hiai::TensorDimension> &input_dimension);
43 
44   int UpdateOutputTensorVec(const std::vector<hiai::TensorDimension> &output_dimension);
45 
46  private:
47   std::string model_name_;
48   NPUManager *npu_manager_ = nullptr;
49   std::shared_ptr<hiai::AiModelMngerClient> client_ = nullptr;
50   std::vector<std::shared_ptr<hiai::AiTensor>> npu_input_tensors_;
51   std::vector<std::shared_ptr<hiai::AiTensor>> npu_output_tensors_;
52 };
53 }  // namespace mindspore
54 #endif  // MINDSPORE_LITE_SRC_RUNTIME_DELEGATE_NPU_NPU_EXECUTOR_H_
55