• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "ops_registry.h"
17 
18 namespace OHOS {
19 namespace NeuralNetworkRuntime {
20 namespace Ops {
Registrar(OH_NN_OperationType opsType,std::function<std::unique_ptr<OpsBuilder> ()> createFunc)21 OpsRegistry::Registrar::Registrar(OH_NN_OperationType opsType, std::function<std::unique_ptr<OpsBuilder>()> createFunc)
22 {
23     OpsRegistry& registry = OpsRegistry::GetSingleton();
24     if (registry.m_opsRegedit.find(opsType) != registry.m_opsRegedit.end()) {
25         LOGW("Operantion has been registered, cannot register twice. Operation type: %d", opsType);
26     } else {
27         registry.m_opsRegedit[opsType] = createFunc;
28     }
29 }
30 
GetSingleton()31 OpsRegistry& OpsRegistry::GetSingleton()
32 {
33     static OpsRegistry opsRegistry;
34     return opsRegistry;
35 }
36 
GetOpsBuilder(OH_NN_OperationType type) const37 std::unique_ptr<OpsBuilder> OpsRegistry::GetOpsBuilder(OH_NN_OperationType type) const
38 {
39     if (m_opsRegedit.find(type) != m_opsRegedit.end()) {
40         return m_opsRegedit.at(type)();
41     }
42     return nullptr;
43 }
44 } // namespace Ops
45 } // namespace NeuralNetworkRuntime
46 } // namespace OHOS