1 /** 2 * Copyright 2020 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_REGISTER_KERNEL_IMPL_H_ 18 #define MINDSPORE_LITE_SRC_REGISTRY_REGISTER_KERNEL_IMPL_H_ 19 20 #include <string> 21 #include <map> 22 #include <mutex> 23 #include <unordered_map> 24 #include <vector> 25 #include <set> 26 #include "include/registry/register_kernel.h" 27 28 namespace mindspore::registry { 29 class RegistryKernelImpl { 30 public: 31 RegistryKernelImpl() = default; 32 virtual ~RegistryKernelImpl(); 33 GetInstance()34 static RegistryKernelImpl *GetInstance() { 35 static RegistryKernelImpl instance; 36 return &instance; 37 } 38 39 Status RegCustomKernel(const std::string &arch, const std::string &provider, DataType data_type, 40 const std::string &type, const registry::CreateKernel creator); 41 42 Status RegKernel(const std::string &arch, const std::string &provider, DataType data_type, int type, 43 const registry::CreateKernel creator); 44 45 virtual registry::CreateKernel GetProviderCreator(const schema::Primitive *primitive, registry::KernelDesc *desc); 46 kernel_creators()47 const std::map<std::string, std::unordered_map<std::string, registry::CreateKernel *>> &kernel_creators() { 48 return kernel_creators_; 49 } 50 51 const std::map<std::string, std::map<std::string, std::unordered_map<std::string, registry::CreateKernel *>>> GetCustomKernelCreators()52 &GetCustomKernelCreators() const { 53 return custom_kernel_creators_; 54 } 55 56 protected: 57 // keys:provider, arch 58 std::map<std::string, std::unordered_map<std::string, registry::CreateKernel *>> kernel_creators_; 59 60 // keys:provider, arch, type 61 std::map<std::string, std::map<std::string, std::unordered_map<std::string, registry::CreateKernel *>>> 62 custom_kernel_creators_; 63 64 private: 65 std::mutex lock_; 66 67 registry::CreateKernel GetCustomKernelCreator(const schema::Primitive *primitive, registry::KernelDesc *desc); 68 }; 69 } // namespace mindspore::registry 70 71 #endif // MINDSPORE_LITE_SRC_REGISTRY_REGISTER_KERNEL_IMPL_H_ 72