• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2023 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 "nnacl/nnacl_manager.h"
18 
19 namespace mindspore::nnacl {
NNACLSupportKernel(int op_type,TypeId data_type)20 bool NNACLSupportKernel(int op_type, TypeId data_type) {
21   auto creator = KernelRegistry::GetInstance()->Creator({op_type, data_type});
22   if (creator != nullptr) {
23     return true;
24   }
25   return SupportKernelC(op_type, data_type);
26 }
27 
NNACLKernelRegistry(OpParameter * parameter,const std::vector<lite::Tensor * > & inputs,const std::vector<lite::Tensor * > & outputs,const lite::InnerContext * ctx,const kernel::KernelKey & key)28 NNACLKernel *NNACLKernelRegistry(OpParameter *parameter, const std::vector<lite::Tensor *> &inputs,
29                                  const std::vector<lite::Tensor *> &outputs, const lite::InnerContext *ctx,
30                                  const kernel::KernelKey &key) {
31   auto creator = KernelRegistry::GetInstance()->Creator({key.type, key.data_type});
32   NNACLKernel *kernel = nullptr;
33   if (creator != nullptr) {
34     kernel = creator(parameter, inputs, outputs, ctx);
35   }
36   if (kernel == nullptr) {
37     kernel = new (std::nothrow) NNACLKernel(parameter, inputs, outputs, ctx);
38   }
39   if (kernel == nullptr) {
40     MS_LOG(ERROR) << "Create nnacl kernel failed:  " << parameter->name_;
41     return nullptr;
42   }
43 
44   auto ret = kernel->InitKernel(key.data_type, ctx);
45   if (ret != RET_OK) {
46     MS_LOG(WARNING) << "Init nnacl kernel failed:  " << parameter->name_;
47     kernel->set_parameter(nullptr);  // Do not Free parameter here, Free where it was malloced.
48     delete kernel;
49     return nullptr;
50   }
51 
52   return kernel;
53 }
54 }  // namespace mindspore::nnacl
55