LCOV - code coverage report
Current view: top level - legacy/ascend950/framework/resource_manager/notify - queue_notify_manager.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 80.5 % 41 33
Test Date: 2026-08-17 10:19:35 Functions: 87.5 % 8 7

            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              : #include "queue_notify_manager_v2.h"
      11              : #include "communicator_impl.h"
      12              : namespace Hccl {
      13              : 
      14          617 : QueueNotifyManager::QueueNotifyManager(const CommunicatorImpl& comm) : comm(const_cast<CommunicatorImpl*>(&comm)) {}
      15              : 
      16          617 : QueueNotifyManager::~QueueNotifyManager() { DECTOR_TRY_CATCH("QueueNotifyManager", Destroy()); }
      17              : 
      18           10 : void QueueNotifyManager::ApplyFor(QId postQid, QId waitQid, u32 topicId)
      19              : {
      20           10 :     if (topicId > MAX_NUM_FOR_QPAIR) {
      21              :         string msg = StringFormat(
      22              :             "topicId=%d, Exceed max notify number %d for queue tuple {postQid=%d, waitQid=%d}", topicId,
      23            0 :             MAX_NUM_FOR_QPAIR, postQid, waitQid);
      24            0 :         THROW<InvalidParamsException>(msg);
      25            0 :     }
      26           10 :     const auto& tuple = std::make_tuple(postQid, waitQid, topicId);
      27           10 :     if (notifyPool[tuple] == nullptr) {
      28            8 :         notifyPool[tuple] = std::make_unique<RtsNotify>(comm->GetOpAiCpuTSFeatureFlag()); // 算子粒度
      29              :     }
      30           10 : }
      31              : 
      32            2 : bool QueueNotifyManager::Release(QId postQid, QId waitQid, u32 topicId)
      33              : {
      34            2 :     if (!IsExist(postQid, waitQid, topicId)) {
      35            3 :         HCCL_WARNING("Notify for postQid[%u] and waitQid[%u] does not exist, no need to release.", postQid, waitQid);
      36            1 :         return true;
      37              :     }
      38              : 
      39            1 :     notifyPool.erase(std::make_tuple(postQid, waitQid, topicId));
      40            1 :     return true;
      41              : }
      42              : 
      43          618 : bool QueueNotifyManager::Destroy()
      44              : {
      45          618 :     notifyPool.clear();
      46          618 :     return true;
      47              : }
      48              : 
      49            0 : RtsNotify* QueueNotifyManager::Get(QId postQid, QId waitQid, u32 topicId)
      50              : {
      51            0 :     if (!IsExist(postQid, waitQid, topicId)) {
      52            0 :         HCCL_WARNING("Notify for postQid[%u] and waitQid[%u] does not exist", postQid, waitQid);
      53            0 :         return nullptr;
      54              :     }
      55              : 
      56            0 :     return notifyPool[std::make_tuple(postQid, waitQid, topicId)].get();
      57              : }
      58              : 
      59            2 : bool QueueNotifyManager::IsExist(QId postQid, QId waitQid, u32 topicId)
      60              : {
      61            2 :     return notifyPool.count(std::make_tuple(postQid, waitQid, topicId)) != 0;
      62              : }
      63              : 
      64              : constexpr u8 QUEUE_NOTIFY_POST_QID_POS = 0;
      65              : constexpr u8 QUEUE_NOTIFY_WAIT_QID_POS = 1;
      66              : constexpr u8 QUEUE_NOTIFY_TOPIC_ID_POS = 2;
      67              : 
      68            3 : std::vector<char> QueueNotifyManager::GetPackedData()
      69              : {
      70            3 :     std::vector<char> result;
      71            3 :     BinaryStream binaryStream;
      72              : 
      73            3 :     u32 poolSize = notifyPool.size();
      74            3 :     binaryStream << poolSize;
      75              : 
      76            6 :     for (auto& it : notifyPool) {
      77            3 :         binaryStream << (std::get<QUEUE_NOTIFY_POST_QID_POS>(it.first));
      78            3 :         binaryStream << (std::get<QUEUE_NOTIFY_WAIT_QID_POS>(it.first));
      79            3 :         binaryStream << (std::get<QUEUE_NOTIFY_TOPIC_ID_POS>(it.first));
      80            3 :         binaryStream << it.second->GetUniqueId();
      81            9 :         HCCL_INFO(
      82              :             "QueueNotifyManager::GetPackedData: postQid=%u, waitQid=%u, topicId=%u, %s",
      83              :             (std::get<QUEUE_NOTIFY_POST_QID_POS>(it.first)), (std::get<QUEUE_NOTIFY_WAIT_QID_POS>(it.first)),
      84              :             (std::get<QUEUE_NOTIFY_TOPIC_ID_POS>(it.first)), it.second->Describe().c_str());
      85              :     }
      86            3 :     binaryStream.Dump(result);
      87            3 :     return result;
      88            3 : }
      89              : 
      90              : } // namespace Hccl
        

Generated by: LCOV version 2.0-1