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 : #include "rank_table_crc_bridge.h"
12 : #include "checkcrc.h"
13 : #include "log.h"
14 : using namespace Hccl;
15 :
16 1 : RankTableCrcBridge::~RankTableCrcBridge() = default;
17 :
18 5 : RankTableCrcBridge& RankTableCrcBridge::GetInstance()
19 : {
20 5 : static RankTableCrcBridge instance;
21 5 : return instance;
22 : }
23 :
24 5 : void RankTableCrcBridge::RecordRankTableJsonCrc(s32 deviceLogicId, const std::string& rankTableJson)
25 : {
26 5 : Hccl::CheckCrc checkCrc;
27 5 : u32 crc = 0;
28 5 : HcclResult ret = checkCrc.CalcStringCrc(rankTableJson.c_str(), &crc);
29 5 : if (ret != HCCL_SUCCESS) {
30 0 : HCCL_ERROR("[RecordRankTableJsonCrc] CalcStringCrc failed, ret[%d]", ret);
31 0 : return;
32 : }
33 5 : rankTableJsonCrcMap_[deviceLogicId] = crc;
34 15 : HCCL_INFO("[RecordRankTableJsonCrc] deviceLogicId[%d], crc[0x%08x] recorded.", deviceLogicId, crc);
35 5 : }
36 :
37 0 : u32 RankTableCrcBridge::ConsumeRankTableJsonCrc(s32 deviceLogicId)
38 : {
39 0 : auto it = rankTableJsonCrcMap_.find(deviceLogicId);
40 0 : if (it == rankTableJsonCrcMap_.end()) {
41 0 : return 0;
42 : }
43 0 : u32 crc = it->second;
44 0 : rankTableJsonCrcMap_.erase(it);
45 0 : return crc;
46 : }
|