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 : #include "queue_wait_group_cnt_notify_manager.h"
12 :
13 : namespace Hccl {
14 :
15 728 : QueueWaitGroupCntNotifyManager::QueueWaitGroupCntNotifyManager() {}
16 :
17 728 : QueueWaitGroupCntNotifyManager::~QueueWaitGroupCntNotifyManager()
18 : {
19 728 : DECTOR_TRY_CATCH("QueueWaitGroupCntNotifyManager", Destroy());
20 728 : }
21 :
22 8 : void QueueWaitGroupCntNotifyManager::ApplyFor(QId qid, u32 topicId)
23 : {
24 24 : HCCL_INFO("[QueueWaitGroupCntNotifyManager][%s] start, qid[%u] topicId[%u]", __func__, qid, topicId);
25 8 : const auto& pair = make_pair(qid, topicId);
26 8 : if (notifyPool[pair] == nullptr) {
27 8 : notifyPool[pair] = make_unique<RtsCntNotify>();
28 : }
29 8 : }
30 :
31 10 : RtsCntNotify* QueueWaitGroupCntNotifyManager::Get(QId qid, u32 topicId)
32 : {
33 10 : if (!IsExist(qid, topicId)) {
34 9 : HCCL_WARNING("Count Notify for qid[%u] and topic Id[%u] does not exist", qid, topicId);
35 3 : return nullptr;
36 : }
37 :
38 7 : return notifyPool[make_pair(qid, topicId)].get();
39 : }
40 :
41 1 : bool QueueWaitGroupCntNotifyManager::Release(QId qid, u32 topicId)
42 : {
43 1 : if (!IsExist(qid, topicId)) {
44 3 : HCCL_WARNING("Count Notify for qid[%u] and topic Id[%u] does not exist.", qid, topicId);
45 : }
46 1 : notifyPool.erase(make_pair(qid, topicId));
47 1 : return true;
48 : }
49 :
50 11 : bool QueueWaitGroupCntNotifyManager::IsExist(QId qid, u32 topicId)
51 : {
52 11 : return notifyPool.count(make_pair(qid, topicId)) != 0;
53 : }
54 :
55 729 : void QueueWaitGroupCntNotifyManager::Destroy() { notifyPool.clear(); }
56 :
57 4 : std::vector<char> QueueWaitGroupCntNotifyManager::GetPackedData()
58 : {
59 4 : std::vector<char> result;
60 4 : BinaryStream binaryStream;
61 :
62 4 : u32 poolSize = notifyPool.size();
63 4 : binaryStream << poolSize;
64 :
65 8 : for (auto& it : notifyPool) {
66 4 : binaryStream << it.first.first;
67 4 : binaryStream << it.first.second;
68 4 : binaryStream << it.second->GetUniqueId();
69 : }
70 4 : binaryStream.Dump(result);
71 4 : return result;
72 4 : }
73 :
74 : } // namespace Hccl
|