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 : #ifndef RANK_CONSISTENCY_CHECKER_V2_H
12 : #define RANK_CONSISTENCY_CHECKER_V2_H
13 :
14 : #include <string>
15 : #include <mutex>
16 : #include <vector>
17 : #include <unordered_map>
18 : #include <hccl/hccl_types.h>
19 : #include "hccl/base.h"
20 :
21 : namespace hccl {
22 : constexpr u32 CANN_VERSION_MAX_LEN = 50; // CANN版本最大长度
23 : static constexpr u32 MAX_CRC_LEN_V2 = 16; // A5最大CRC个数
24 :
25 : struct CrcEntryV2 {
26 : std::string name; // 对比的crc名(如"HCCL_BUFFSIZE")
27 : u32 crc = 0;
28 : CrcEntryV2() = default;
29 2 : CrcEntryV2(std::string n, u32 c) : name(n), crc(c) {}
30 : };
31 :
32 : struct CheckFrameV2 {
33 : u32 rankTableCrcNum = 0; // ranktable CRC个数
34 : u32 rankTableCrcArray[MAX_CRC_LEN_V2] = {0}; // ranktable CRC数组
35 : char version[CANN_VERSION_MAX_LEN + 1] = {0};
36 : };
37 :
38 : class RankConsistencyCheckerV2 {
39 : public:
40 : ~RankConsistencyCheckerV2();
41 : static RankConsistencyCheckerV2& GetInstance(const s32& deviceLogicId);
42 :
43 : HcclResult RecordRankTableCrcV2(u32 crc);
44 : HcclResult RecordCannVersionV2(const std::string& version);
45 : HcclResult GenerateCheckFrameV2(CheckFrameV2& localFrame);
46 : HcclResult CompareCheckFrameV2(const CheckFrameV2& local, const CheckFrameV2& remote);
47 : u64 GetCheckFrameLengthV2() const;
48 :
49 : void SetInconsistentCheckFirstDone(
50 : bool inconsistentCheckFirstDone); // 用于标识env_config中InconsistentCheckModel::FIRST时是否已校验
51 : bool GetInconsistentCheckFirstDone() const;
52 :
53 : private:
54 : HcclResult CalcRawDataCrc(const void* ptr, u64 length, u32& crc) const;
55 : bool CompareCrcArrayV2(
56 : const u32* localArray, const u32* remoteArray, const std::vector<CrcEntryV2>& nameSource,
57 : const std::string& categoryLabel) const;
58 : HcclResult CompareVersionV2(const CheckFrameV2& local, const CheckFrameV2& remote, bool& isDiff) const;
59 :
60 : // cann 版本号
61 : char cannVersion_[CANN_VERSION_MAX_LEN + 1] = {0};
62 : std::vector<CrcEntryV2> rankTableCrcV2_; // A5 ranktable CRC
63 : bool inconsistentCheckFirstDone_ = false; // 是否完成首次校验
64 : };
65 : } // namespace hccl
66 : #endif /* RANK_CONSISTENCY_CHECKER_V2_H */
|