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