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