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_op_registry.h"
12 :
13 : namespace hccl {
14 :
15 786 : CollAlgOpRegistry& CollAlgOpRegistry::Instance()
16 : {
17 786 : static CollAlgOpRegistry globalOpRegistry;
18 787 : return globalOpRegistry;
19 : }
20 :
21 705 : HcclResult CollAlgOpRegistry::Register(const HcclCMDType& opType, const CollAlgOpCreator& collAlgOpCreator)
22 : {
23 705 : const std::lock_guard<std::mutex> lock(mu_);
24 705 : if (opCreators_.find(opType) != opCreators_.end()) {
25 0 : HCCL_ERROR("[CollAlgOpRegistry]Op Type[%d] already registered.", opType);
26 0 : return HcclResult::HCCL_E_INTERNAL;
27 : }
28 705 : opCreators_.emplace(opType, collAlgOpCreator);
29 705 : return HcclResult::HCCL_SUCCESS;
30 705 : }
31 :
32 83 : std::unique_ptr<CollAlgOperator> CollAlgOpRegistry::GetAlgOp(
33 : const HcclCMDType& opType, AlgConfigurator* algConfigurator, CCLBufferManager& cclBufferManager,
34 : HcclDispatcher dispatcher, std::unique_ptr<TopoMatcher>& topoMatcher)
35 : {
36 83 : if (opCreators_.find(opType) == opCreators_.end()) {
37 1 : HCCL_ERROR("[CollAlgOpRegistry]Creator for op type[%d] has not registered.", opType);
38 1 : return nullptr;
39 : }
40 : return std::unique_ptr<CollAlgOperator>(
41 77 : opCreators_[opType](algConfigurator, cclBufferManager, dispatcher, topoMatcher));
42 : }
43 :
44 : } // namespace hccl
|