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 "kernel/graph_kernel/graph_kernel_builder_manager.h"
18 #include <memory>
19 namespace mindspore {
20 namespace kernel {
Instance()21 GraphKernelBuildManager &GraphKernelBuildManager::Instance() {
22 static GraphKernelBuildManager instance{};
23 return instance;
24 }
25
Register(const std::string & device_type,bool is_dynamic,GraphKernelBuildCreator && creator)26 void GraphKernelBuildManager::Register(const std::string &device_type, bool is_dynamic,
27 GraphKernelBuildCreator &&creator) {
28 auto idx = std::make_pair(device_type, is_dynamic);
29 if (base_map_.find(idx) == base_map_.end()) {
30 (void)base_map_.emplace(idx, creator);
31 }
32 }
33
GetGraphKernelBuilder(const std::string & device_type,bool is_dynamic)34 std::shared_ptr<GraphKernelBuilder> GraphKernelBuildManager::GetGraphKernelBuilder(const std::string &device_type,
35 bool is_dynamic) {
36 auto idx = std::make_pair(device_type, is_dynamic);
37 auto iter = base_map_.find(idx);
38 if (base_map_.end() != iter) {
39 MS_EXCEPTION_IF_NULL(iter->second);
40 return (iter->second)();
41 }
42 return nullptr;
43 }
44 } // namespace kernel
45 } // namespace mindspore
46