• 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_REGISTRY_KERNEL_INTERFACE_REGISTRY_H_
18 #define MINDSPORE_LITE_SRC_REGISTRY_KERNEL_INTERFACE_REGISTRY_H_
19 
20 #include <string>
21 #include <map>
22 #include <memory>
23 #include <mutex>
24 #include <set>
25 #include "include/registry/register_kernel_interface.h"
26 #include "include/model.h"
27 
28 namespace mindspore {
29 namespace registry {
30 class KernelInterfaceRegistry {
31  public:
Instance()32   static KernelInterfaceRegistry *Instance() {
33     static KernelInterfaceRegistry instance;
34     return &instance;
35   }
36 
37   std::shared_ptr<kernel::KernelInterface> GetKernelInterface(const std::string &provider,
38                                                               const schema::Primitive *primitive,
39                                                               const kernel::Kernel *kernel);
40   Status CustomReg(const std::string &provider, const std::string &op_type,
41                    const registry::KernelInterfaceCreator creator);
42   Status Reg(const std::string &provider, int op_type, const registry::KernelInterfaceCreator creator);
43   virtual ~KernelInterfaceRegistry();
44 
45  private:
46   KernelInterfaceRegistry() = default;
47   std::shared_ptr<kernel::KernelInterface> GetCacheInterface(const std::string &provider, int op_type);
48   std::shared_ptr<kernel::KernelInterface> GetCustomCacheInterface(const std::string &provider,
49                                                                    const std::string &type);
50   std::shared_ptr<kernel::KernelInterface> GetCustomKernelInterface(const schema::Primitive *primitive,
51                                                                     const kernel::Kernel *kernel);
52 
53   std::mutex mutex_;
54   // key: provider
55   std::map<std::string, registry::KernelInterfaceCreator *> kernel_creators_;
56   std::map<std::string, std::map<int, std::shared_ptr<kernel::KernelInterface>>> kernel_interfaces_;
57   // key: provider        key: custom type
58   std::map<std::string, std::map<std::string, registry::KernelInterfaceCreator>> custom_creators_;
59   std::map<std::string, std::map<std::string, std::shared_ptr<kernel::KernelInterface>>> custom_kernels_;
60 };
61 }  // namespace registry
62 }  // namespace mindspore
63 
64 #endif  // MINDSPORE_LITE_SRC_REGISTRY_KERNEL_INTERFACE_REGISTRY_H_
65