Line data Source code
1 : /**
2 : * Copyright (c) 2025 Huawei Technologies Co., Ltd.
3 : * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4 : * CANN Open Software License Agreement Version 2.0 (the "License").
5 : * Please refer to the License for details. You may not use this file except in compliance with the License.
6 : * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7 : * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8 : * See LICENSE in the root of the software repository for the full text of the License.
9 : */
10 :
11 : #include "coll_alg_exec_registry.h"
12 :
13 : namespace hccl {
14 :
15 6699 : CollAlgExecRegistry &CollAlgExecRegistry::Instance()
16 : {
17 6699 : static CollAlgExecRegistry globalExecRegistry;
18 6698 : return globalExecRegistry;
19 : }
20 :
21 6622 : HcclResult CollAlgExecRegistry::Register(const std::string &tag, const CollExecCreator &collExecCreator)
22 : {
23 6622 : const std::lock_guard<std::mutex> lock(mu_);
24 6622 : if (execCreators_.find(tag) != execCreators_.end()) {
25 0 : HCCL_WARNING("[CollAlgExecRegistry]Exec tag[%s] already registered.", tag.c_str());
26 0 : return HcclResult::HCCL_E_INTERNAL;
27 : }
28 6622 : execCreators_.emplace(tag, collExecCreator);
29 6622 : return HcclResult::HCCL_SUCCESS;
30 6622 : }
31 :
32 75 : std::unique_ptr<CollExecutorBase> CollAlgExecRegistry::GetAlgExec(
33 : const std::string &tag, const HcclDispatcher dispatcher, std::unique_ptr<TopoMatcher> &topoMatcher)
34 : {
35 75 : if (execCreators_.find(tag) == execCreators_.end()) {
36 0 : HCCL_DEBUG("[CollAlgExecRegistry]Creator for executor tag[%s] has not registered.", tag.c_str());
37 0 : return nullptr;
38 : }
39 63 : HCCL_DEBUG("[CollAlgExecRegistry][GetAlgExec]get executor by algName[%s].", tag.c_str());
40 78 : return std::unique_ptr<CollExecutorBase>(execCreators_[tag](dispatcher, topoMatcher));
41 : }
42 :
43 : } // namespace Hccl
|