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 : #ifndef HCCLV2_RECOVER_INFO_H
11 : #define HCCLV2_RECOVER_INFO_H
12 :
13 : #include <string>
14 : #include <vector>
15 : #include "types.h"
16 : #include "string_util.h"
17 : #include "exception_util.h"
18 : #include "internal_exception.h"
19 : namespace Hccl {
20 :
21 : const u32 RECOVER_OP_TAG_MAX_LEN = 191; // 最大的tag长度
22 :
23 9 : template <typename T> inline std::vector<char> ReCoverCustomTypeToCharVector(const T &data)
24 : {
25 9 : std::vector<char> v;
26 9 : v.resize(sizeof(T));
27 9 : int ret = memcpy_s(v.data(), v.size(), &data, sizeof(T));
28 9 : if (ret != 0) {
29 0 : THROW<InternalException>(StringFormat("CustomTypeToCharVector copy dwqe failed, ret=%d", ret));
30 : }
31 9 : return v;
32 0 : }
33 :
34 4 : template <typename T> inline T RecoverCharVectorToCustomType(const std::vector<char> &v)
35 : {
36 4 : T result;
37 4 : int ret = memcpy_s(&result, sizeof(result), &v[0], v.size());
38 4 : if (ret != 0) {
39 0 : THROW<InternalException>(StringFormat("VectorByteToCustomType copy dwqe failed, ret=%d", ret));
40 : }
41 4 : return result;
42 : }
43 :
44 : struct RecoverInfoData {
45 : // 通信算子数目
46 : u32 collOpIndex{0};
47 : // RankTable CRC值
48 : u32 crcValue{0};
49 : // 通信步骤
50 : u32 step{0};
51 :
52 7 : RecoverInfoData()
53 7 : {
54 7 : }
55 :
56 12 : RecoverInfoData(u32 collOpIndex, u32 crcValue, u32 step)
57 12 : : 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
|