• 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_DELEGATE_H_
18 #define MINDSPORE_LITE_SRC_RUNTIME_DELEGATE_NPU_NPU_DELEGATE_H_
19 
20 #include <vector>
21 #include <map>
22 #include <string>
23 #include "include/api/delegate.h"
24 #include "src/litert/delegate/npu/npu_manager.h"
25 #include "src/litert/delegate/npu/pass/npu_pass_manager.h"
26 #include "src/litert/delegate/npu/op/npu_op.h"
27 #include "src/litert/inner_context.h"
28 
29 namespace mindspore::lite {
30 class NPUDelegate : public Delegate {
31  public:
NPUDelegate(NpuDeviceInfo device_info,const std::string & cache_dir)32   explicit NPUDelegate(NpuDeviceInfo device_info, const std::string &cache_dir) : Delegate() {
33     frequency_ = device_info.frequency_;
34     cache_dir_ = cache_dir;
35   }
36 
37   ~NPUDelegate() override;
38 
39   Status Init() override;
40 
41   Status Build(DelegateModel<schema::Primitive> *model) override;
42 
43  protected:
44   NPUOp *GetOP(kernel::Kernel *kernel, const schema::Primitive *primitive);
45 
46   kernel::Kernel *CreateNPUGraph(const std::vector<NPUOp *> &ops, DelegateModel<schema::Primitive> *model,
47                                  KernelIter from, KernelIter end);
48 
49   Status AddPasses();
50 
51   NPUManager *npu_manager_ = nullptr;
52   NPUPassManager *pass_manager_ = nullptr;
53   std::map<schema::PrimitiveType, NPUGetOp> op_func_lists_;
54   int frequency_ = 0;
55   std::string cache_dir_{};
56 };
57 }  // namespace mindspore::lite
58 
59 #endif  // MINDSPORE_LITE_SRC_RUNTIME_DELEGATE_NPU_DELEGATE_H_
60