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 : #ifndef HCCLV2_RECOVER_INFO_H
12 : #define HCCLV2_RECOVER_INFO_H
13 :
14 : #include <string>
15 : #include <vector>
16 : #include "types.h"
17 : #include "string_util.h"
18 : #include "exception_util.h"
19 : #include "internal_exception.h"
20 : namespace Hccl {
21 :
22 : const u32 RECOVER_OP_TAG_MAX_LEN = 191; // 最大的tag长度
23 :
24 : template <typename T>
25 9 : inline std::vector<char> ReCoverCustomTypeToCharVector(const T& data)
26 : {
27 9 : std::vector<char> v;
28 9 : v.resize(sizeof(T));
29 9 : int ret = memcpy_s(v.data(), v.size(), &data, sizeof(T));
30 9 : if (ret != 0) {
31 0 : THROW<InternalException>(StringFormat("CustomTypeToCharVector copy dwqe failed, ret=%d", ret));
32 : }
33 9 : return v;
34 0 : }
35 :
36 : template <typename T>
37 4 : inline T RecoverCharVectorToCustomType(const std::vector<char>& v)
38 : {
39 4 : T result;
40 4 : int ret = memcpy_s(&result, sizeof(result), &v[0], v.size());
41 4 : if (ret != 0) {
42 0 : THROW<InternalException>(StringFormat("VectorByteToCustomType copy dwqe failed, ret=%d", ret));
43 : }
44 4 : return result;
45 : }
46 :
47 : struct RecoverInfoData {
48 : // 通信算子数目
49 : u32 collOpIndex{0};
50 : // RankTable CRC值
51 : u32 crcValue{0};
52 : // 通信步骤
53 : u32 step{0};
54 :
55 7 : RecoverInfoData() {}
56 :
57 12 : RecoverInfoData(u32 collOpIndex, u32 crcValue, u32 step) : collOpIndex(collOpIndex), crcValue(crcValue), step(step)
58 : {
59 12 : this->collOpIndex = collOpIndex;
60 12 : this->crcValue = crcValue;
61 12 : this->step = step;
62 12 : }
63 1 : std::string Describe() const
64 : {
65 1 : return StringFormat("RecoverInfo[CollOpIndex=%u,CrcValue=%u,Step=%u]", collOpIndex, crcValue, step);
66 : }
67 : };
68 :
69 : class RecoverInfo {
70 : public:
71 : explicit RecoverInfo(const RecoverInfoData& recoverInfoData, RankId myRank);
72 :
73 : explicit RecoverInfo(const std::vector<char>& v);
74 :
75 : std::string Describe() const;
76 :
77 : // 获取当前RecoverInfoData的唯一标识
78 : std::vector<char> GetUniqueId() const;
79 :
80 : void SetCrcValue(u32 crcValue);
81 :
82 : void Check(const std::vector<char>& rmtUniqueId) const;
83 :
84 : void CompareRecoverInfo(const RecoverInfoData& otherRecoverInfoData) const;
85 :
86 : private:
87 : RecoverInfoData recoverInfoData;
88 : RankId myRank{0};
89 : };
90 :
91 : } // namespace Hccl
92 :
93 : #endif // HCCLV2_RECOVER_INFO_H
|