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