Line data Source code
1 : /**
2 : * Copyright (c) 2026 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_comm_config_consistency.h"
12 :
13 : namespace hccl {
14 170 : CollCommConfigConsistency::CollCommConfigConsistency()
15 : {
16 170 : }
17 :
18 170 : CollCommConfigConsistency::~CollCommConfigConsistency()
19 : {
20 170 : HCCL_INFO("[CollCommConfigConsistency][~CollCommConfigConsistency] CollCommConfigConsistency deinit");
21 170 : remoteExchangeInfoMap_.clear();
22 170 : ResetExchangeInfo();
23 170 : }
24 :
25 7 : HcclResult CollCommConfigConsistency::AddExchangeInfo(const void* data, uint32_t length)
26 : {
27 7 : CHK_PTR_NULL(data);
28 7 : if (length > 0 && length <= HCCL_EXCHANGE_INFO_LEN) {
29 7 : exchangeInfoBuf_.resize(length);
30 7 : s32 sRet = memcpy_s(exchangeInfoBuf_.data(), length, data, length);
31 7 : CHK_PRT_RET(sRet != EOK,
32 : HCCL_ERROR("[AddExchangeInfo] memcpy_s failed, ret[%d]", sRet), HCCL_E_MEMORY);
33 7 : HCCL_INFO("[AddExchangeInfo] success, length[%u].", length);
34 7 : }else {
35 0 : HCCL_ERROR("[AddExchangeInfo] length[%u] is illegal", length);
36 0 : return HCCL_E_PARA;
37 : }
38 :
39 7 : return HCCL_SUCCESS;
40 : }
41 :
42 2 : HcclResult CollCommConfigConsistency::GetExchangeInfo(uint32_t remoteRank, uint32_t length, void* data, uint32_t* actualLength)
43 : {
44 2 : CHK_PTR_NULL(data);
45 2 : auto iter = remoteExchangeInfoMap_.find(remoteRank);
46 2 : if (iter == remoteExchangeInfoMap_.end()) {
47 0 : *actualLength = 0;
48 0 : HCCL_INFO("[GetExchangeInfo] remoteExchangeInfoMap_ is null");
49 0 : return HCCL_SUCCESS;
50 : }
51 2 : *actualLength = static_cast<uint32_t>(iter->second.size());
52 :
53 2 : if (length == *actualLength || *actualLength == 0) {
54 2 : s32 sRet = memcpy_s(data, length, iter->second.data(), iter->second.size());
55 2 : CHK_PRT_RET(sRet != EOK,
56 : HCCL_ERROR("[GetExchangeInfo] memcpy_s failed, ret[%d]", sRet), HCCL_E_MEMORY);
57 2 : } else {
58 0 : HCCL_ERROR("[GetExchangeInfo] failed, length[%u] actualLength[%u].", length, *actualLength);
59 0 : return HCCL_E_PARA;
60 : }
61 :
62 : // 读后清除
63 2 : remoteExchangeInfoMap_.erase(iter);
64 2 : HCCL_INFO("[GetExchangeInfo] success, remoteRank[%u], actualLength[%u].", remoteRank, *actualLength);
65 2 : return HCCL_SUCCESS;
66 : }
67 :
68 2 : HcclResult CollCommConfigConsistency::StoreRemoteExchangeInfo(uint32_t remoteRank, std::vector<u8>& data)
69 : {
70 2 : remoteExchangeInfoMap_[remoteRank] = std::move(data);
71 2 : HCCL_INFO("[StoreRemoteExchangeInfo] success, remoteRank[%u], length[%zu].", remoteRank, remoteExchangeInfoMap_[remoteRank].size());
72 2 : return HCCL_SUCCESS;
73 : }
74 :
75 174 : HcclResult CollCommConfigConsistency::ResetExchangeInfo()
76 : {
77 174 : exchangeInfoBuf_.clear();
78 174 : HCCL_INFO("[ResetExchangeInfo] exchange info state cleared.");
79 174 : return HCCL_SUCCESS;
80 : }
81 :
82 4 : HcclResult CollCommConfigConsistency::GetExchangeInfoBuf(std::vector<u8> &exchangeInfoBuf)
83 : {
84 4 : exchangeInfoBuf = exchangeInfoBuf_;
85 4 : return HCCL_SUCCESS;
86 : }
87 :
88 3 : uint32_t CollCommConfigConsistency::GetExchangeInfoLen() const
89 : {
90 3 : return static_cast<uint32_t>(exchangeInfoBuf_.size());
91 : }
92 :
93 : }
94 :
|