LCOV - code coverage report
Current view: top level - legacy/ascend910/algorithm/impl/resource_manager - queue_notify_manager.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 83.3 % 66 55
Test Date: 2026-08-04 10:52:23 Functions: 88.9 % 9 8

            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_notify_manager.h"
      12              : #include <algorithm>
      13              : #include "device_capacity.h"
      14              : #include "adapter_rts_common.h"
      15              : 
      16              : namespace hccl {
      17              : constexpr u32 NOTIFY_MAX_NUM = 2048;
      18              : const std::string HCCL_ALLTOALL = "ALLTOALL";
      19         1044 : QueueNotifyManager::QueueNotifyManager()
      20              : {
      21         1044 : }
      22              : 
      23         1044 : QueueNotifyManager::~QueueNotifyManager()
      24              : {
      25         1044 :     HcclResult ret = Destroy();
      26         1044 :     if (ret != HCCL_SUCCESS) {
      27            0 :         HCCL_WARNING("destroy QueueNotifyManager resources failed, ret[%d]", ret);
      28              :     }
      29         1044 : }
      30              : 
      31         1043 : HcclResult QueueNotifyManager::Init()
      32              : {
      33         1043 :     notifies_.reserve(NOTIFY_MAX_NUM);
      34         1043 :     notifiesForA2A_.reserve(NOTIFY_MAX_NUM);
      35         1042 :     deviceNotifies_.reserve(NOTIFY_MAX_NUM);
      36         1043 :     return HCCL_SUCCESS;
      37              : }
      38              : 
      39          117 : HcclResult QueueNotifyManager::Alloc(const std::string &tag, u32 notifyNum,
      40              :     std::vector<std::shared_ptr<LocalNotify>> &localNotifys, const NotifyLoadType type)
      41              : {
      42          117 :     if (type == NotifyLoadType::HOST_NOTIFY) {
      43          111 :         std::string upTag = tag;
      44          112 :         std::transform(upTag.begin(), upTag.end(), upTag.begin(), ::toupper);
      45          111 :         bool hasAlltoAll = upTag.find(HCCL_ALLTOALL) != std::string::npos;
      46          111 :         HCCL_INFO("RegisterOp hasAlltoAll[%d]", hasAlltoAll);
      47          112 :         NotifyPoolNoIPC &notifies = hasAlltoAll ? notifiesForA2A_ : notifies_;
      48          112 :         CHK_RET(AllocNotifies(type, notifies, notifyNum));
      49          112 :         localNotifys.assign(notifies.begin(), notifies.begin() + notifyNum);
      50          118 :     } else if (type == NotifyLoadType::DEVICE_NOTIFY) { // 申请device上使用的notify资源
      51            6 :         CHK_RET(AllocNotifies(type, deviceNotifies_, notifyNum));
      52            6 :         localNotifys.assign(deviceNotifies_.begin(),
      53           12 :             deviceNotifies_.begin() + notifyNum);
      54              :     }
      55          118 :     return HCCL_SUCCESS;
      56              : }
      57              : 
      58          118 : HcclResult QueueNotifyManager::AllocNotifies(const NotifyLoadType type, NotifyPoolNoIPC &notifies, u32 notifyNum)
      59              : {
      60          118 :     if (notifies.size() < notifyNum) {
      61          582 :         for (u32 i = notifies.size(); i < notifyNum; i++) {
      62          520 :             notifies.emplace_back(nullptr);
      63          515 :             CHK_RET(CreateNotify(notifies[i], type));
      64          520 :             CHK_SMART_PTR_NULL(notifies[i]);
      65              :         }
      66              :     }
      67          118 :     return HCCL_SUCCESS;
      68              : }
      69              : 
      70          515 : HcclResult QueueNotifyManager::CreateNotify(std::shared_ptr<LocalNotify> &localNotify, const NotifyLoadType type)
      71              : {
      72          515 :     EXCEPTION_CATCH((localNotify = std::make_shared<LocalNotify>()), return HCCL_E_PTR);
      73              : 
      74          516 :     HcclResult ret = HCCL_SUCCESS;
      75          516 :     bool errorFlag = false;
      76              :     do {
      77          516 :         ret = localNotify->Init(type);
      78          519 :         CHK_PRT_BREAK(ret != HCCL_SUCCESS, HCCL_ERROR("[QueueNotifyManager][CreateNotify]localNotify init failed, "
      79              :             "ret[%d]", ret), errorFlag = true);
      80              : 
      81          519 :         HCCL_DEBUG("Is310PDevice[%d]", Is310PDevice());
      82          520 :         if (Is310PDevice()) {
      83            0 :             ret = localNotify->SetIpc();
      84            0 :             CHK_PRT_BREAK(ret != HCCL_SUCCESS, HCCL_ERROR("[QueueNotifyManager][CreateNotify]localNotify "
      85              :                 "set ipc failed, ret[%d]", ret), errorFlag = true);
      86              :         }
      87              :     } while (0);
      88              : 
      89          520 :     if (errorFlag) {
      90            0 :         HCCL_ERROR("[QueueNotifyManager][CreateNotify]localNotify create failed ,ret[%d]", ret);
      91            0 :         localNotify = nullptr;
      92            0 :         return ret;
      93              :     }
      94              : 
      95          520 :     return HCCL_SUCCESS;
      96              : }
      97              : 
      98         1043 : HcclResult QueueNotifyManager::Destroy()
      99              : {
     100         1043 :     HCCL_INFO("QueueNotifyManager Destroy.");
     101              : 
     102         1044 :     CHK_RET(DestroyNotifies(notifies_));
     103         1044 :     CHK_RET(DestroyNotifies(deviceNotifies_));
     104         1044 :     CHK_RET(DestroyNotifies(notifiesForA2A_));
     105              : 
     106         1043 :     HCCL_INFO("QueueNotifyManager Destroy success.");
     107         1044 :     return HCCL_SUCCESS;
     108              : }
     109              : 
     110         3132 : HcclResult QueueNotifyManager::DestroyNotifies(NotifyPoolNoIPC &notifies)
     111              : {
     112         3652 :     for (auto &notify : notifies) {
     113          520 :         CHK_SMART_PTR_NULL(notify);
     114          520 :         CHK_RET(notify->Destroy());
     115              :     }
     116         3130 :     notifies.clear();
     117         3131 :     return HCCL_SUCCESS;
     118              : }
     119              : 
     120            0 : HcclResult QueueNotifyManager::ResetNotify()
     121              : {
     122            0 :     for (auto &localNotify : deviceNotifies_) {
     123            0 :         CHK_SMART_PTR_NULL(localNotify);
     124            0 :         CHK_RET(hrtNotifyReset(localNotify->ptr()));
     125              :     }
     126            0 :     return HCCL_SUCCESS;
     127              : }
     128              : }  // namespace hccl
        

Generated by: LCOV version 2.0-1