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 #include "include/registry/register_kernel.h"
18 #include <set>
19 #include "include/errorcode.h"
20 #include "src/common/log_adapter.h"
21 #include "src/registry/register_kernel_impl.h"
22
23 namespace mindspore {
24 namespace registry {
RegCustomKernel(const std::string & arch,const std::string & provider,DataType data_type,const std::string & type,const CreateKernel creator)25 Status RegisterKernel::RegCustomKernel(const std::string &arch, const std::string &provider, DataType data_type,
26 const std::string &type, const CreateKernel creator) {
27 #ifndef CUSTOM_KERNEL_REGISTRY_CLIP
28 return RegistryKernelImpl::GetInstance()->RegCustomKernel(arch, provider, data_type, type, creator);
29 #else
30 MS_LOG(ERROR) << unsupport_custom_kernel_register_log;
31 return kLiteNotSupport;
32 #endif
33 }
34
RegKernel(const std::string & arch,const std::string & provider,DataType data_type,int op_type,const CreateKernel creator)35 Status RegisterKernel::RegKernel(const std::string &arch, const std::string &provider, DataType data_type, int op_type,
36 const CreateKernel creator) {
37 #ifndef CUSTOM_KERNEL_REGISTRY_CLIP
38 return RegistryKernelImpl::GetInstance()->RegKernel(arch, provider, data_type, op_type, creator);
39 #else
40 MS_LOG(ERROR) << unsupport_custom_kernel_register_log;
41 return kLiteNotSupport;
42 #endif
43 }
44
GetCreator(const schema::Primitive * primitive,KernelDesc * desc)45 CreateKernel RegisterKernel::GetCreator(const schema::Primitive *primitive, KernelDesc *desc) {
46 #ifndef CUSTOM_KERNEL_REGISTRY_CLIP
47 if (desc == nullptr || primitive == nullptr) {
48 return nullptr;
49 }
50 return RegistryKernelImpl::GetInstance()->GetProviderCreator(primitive, desc);
51 #else
52 MS_LOG(ERROR) << unsupport_custom_kernel_register_log;
53 return nullptr;
54 #endif
55 }
56 } // namespace registry
57 } // namespace mindspore
58