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 : #include "recover_info.h"
11 : #include "string_util.h"
12 : #include "invalid_params_exception.h"
13 :
14 : namespace Hccl {
15 :
16 3 : static void ReportRecoverInfoCheckFailed(const std::string& paraName, uint32_t localPara, uint32_t remotePara)
17 : {
18 3 : THROW<InvalidParamsException>(StringFormat(
19 : "[recover_info][ReportOpInfoCheckFailed]recover information %s check fail. local[%u], remote[%u]",
20 : paraName.c_str(), localPara, remotePara));
21 : }
22 :
23 14 : RecoverInfo::RecoverInfo(const RecoverInfoData& recoverInfoData, RankId myRank)
24 14 : : recoverInfoData(recoverInfoData),
25 14 : myRank(myRank)
26 14 : {}
27 :
28 1 : RecoverInfo::RecoverInfo(const std::vector<char>& v)
29 : {
30 1 : size_t recoverInfoDataSize = sizeof(RecoverInfoData);
31 1 : if (v.size() != recoverInfoDataSize) {
32 0 : THROW<InternalException>(StringFormat("Vector size does not match RecoverInfoData size"));
33 : }
34 :
35 1 : int ret = memcpy_s(&this->recoverInfoData, recoverInfoDataSize, &v[0], v.size());
36 1 : if (ret != 0) {
37 0 : THROW<InternalException>(StringFormat("Vector size does not match RecoverInfoData size"));
38 : }
39 1 : }
40 :
41 1 : std::string RecoverInfo::Describe() const { return recoverInfoData.Describe(); }
42 :
43 9 : std::vector<char> RecoverInfo::GetUniqueId() const
44 : {
45 9 : std::vector<char> byteVector = ReCoverCustomTypeToCharVector<RecoverInfoData>(recoverInfoData);
46 :
47 9 : return byteVector;
48 : }
49 :
50 1 : void RecoverInfo::SetCrcValue(u32 crcValue) { recoverInfoData.crcValue = crcValue; }
51 :
52 : // 功能说明:一致性校验
53 : // 输入说明:const std::vector<char> &rmtUniqueId:对端数据
54 4 : void RecoverInfo::Check(const std::vector<char>& rmtUniqueId) const
55 : {
56 4 : RecoverInfoData rmtRecoverInfoData = RecoverCharVectorToCustomType<RecoverInfoData>(rmtUniqueId);
57 4 : CompareRecoverInfo(rmtRecoverInfoData);
58 1 : }
59 :
60 4 : void RecoverInfo::CompareRecoverInfo(const RecoverInfoData& otherRecoverInfoData) const
61 : {
62 4 : if (recoverInfoData.collOpIndex != otherRecoverInfoData.collOpIndex) {
63 3 : ReportRecoverInfoCheckFailed("collOpIndex", recoverInfoData.collOpIndex, otherRecoverInfoData.collOpIndex);
64 3 : } else if (recoverInfoData.crcValue != otherRecoverInfoData.crcValue) {
65 3 : ReportRecoverInfoCheckFailed("crcValue", recoverInfoData.crcValue, otherRecoverInfoData.crcValue);
66 2 : } else if (recoverInfoData.step != otherRecoverInfoData.step) {
67 3 : ReportRecoverInfoCheckFailed("step", recoverInfoData.step, otherRecoverInfoData.step);
68 : }
69 1 : return;
70 : }
71 :
72 : } // namespace Hccl
|