LCOV - code coverage report
Current view: top level - coll_communicator_mgr/communicator/device/resource_mgr/local/my_rank/comm_engine_reses/notify - notify_aicpu_mgr.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 12.5 % 48 6
Test Date: 2026-08-18 17:47:01 Functions: 80.0 % 5 4

            Line data    Source code
       1              : /**
       2              :  * Copyright (c) 2026 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 "notify_aicpu_mgr.h"
      12              : #include "notify_manager.h"
      13              : #include "log.h"
      14              : #include <sstream>
      15              : #include <iomanip>
      16              : #include <algorithm>
      17              : 
      18              : constexpr u32 NOTIFY_SIZE_EIGHT = 8;
      19              : 
      20           23 : NotifyAicpuMgr::NotifyAicpuMgr() { notifys_.reserve(hccl::HCCL_THREAD_NOTIFY_MAX_NUM); }
      21              : 
      22            2 : void NotifyAicpuMgr::ReserveNotifyCapacity(size_t n) { notifys_.reserve(n); }
      23              : 
      24            2 : HcclResult NotifyAicpuMgr::NotifyFree(NotifyMgrAicpuParam* param)
      25              : {
      26            2 :     CHK_PTR_NULL(param);
      27            0 :     u32 notifyNum = param->notifyNum;
      28            0 :     NotifyHandle* notifyArray = static_cast<NotifyHandle*>(param->deviceHandle);
      29            0 :     std::string hcomId(param->hcomId);
      30            0 :     CHK_PTR_NULL(notifyArray);
      31            0 :     for (size_t i = 0; i < notifyNum; ++i) {
      32            0 :         LocalNotify* notify = reinterpret_cast<LocalNotify*>(notifyArray[i]);
      33            0 :         HCCL_INFO(
      34              :             "[NotifyAicpuMgr][%s] notifyArray[%zu]=[%llu]", __func__, i,
      35              :             static_cast<unsigned long long>(notifyArray[i]));
      36            0 :         auto it = std::find_if(notifys_.begin(), notifys_.end(), [notify](const std::unique_ptr<LocalNotify>& ptr) {
      37            0 :             return ptr.get() == notify;
      38              :         });
      39            0 :         if (it != notifys_.end()) {
      40            0 :             HCCL_INFO(
      41              :                 "[NotifyAicpuMgr][%s] comm identifier[%s], free notifys[%llu] success", __func__, hcomId.c_str(),
      42              :                 static_cast<unsigned long long>(notifyArray[i]));
      43            0 :             notifys_.erase(it);
      44              :         } else {
      45            0 :             HCCL_RUN_WARNING("[NotifyAicpuMgr][%s] localNotify[%zu] not found in notifys_", __func__, i);
      46              :         }
      47              :     }
      48              : 
      49            0 :     HCCL_INFO(
      50              :         "[NotifyAicpuMgr][%s] comm identifier[%s], free notifys num[%u] success", __func__, hcomId.c_str(), notifyNum);
      51            0 :     return HCCL_SUCCESS;
      52            0 : }
      53              : 
      54            2 : HcclResult NotifyAicpuMgr::NotifyAlloc(NotifyMgrAicpuParam* param)
      55              : {
      56            2 :     CHK_PTR_NULL(param);
      57            0 :     u32 notifyNum = param->notifyNum;
      58            0 :     std::string notifysStr = std::string(param->notifyParam, NOTIFY_UNIQUE_ID_MAX_SIZE);
      59            0 :     std::string hcomId(param->hcomId);
      60            0 :     size_t notifySize = notifys_.size();
      61            0 :     HCCL_INFO(
      62              :         "[NotifyAicpuMgr][%s] comm identifier[%s], alloc notifys num[%u] begin, before notifySize[%zu]", __func__,
      63              :         hcomId.c_str(), notifyNum, notifySize);
      64            0 :     if (UNLIKELY(HcclCheckLogLevel(HCCL_LOG_INFO))) {
      65            0 :         std::ostringstream oss;
      66            0 :         oss << "notifyParam" << " raw bytes: ";
      67            0 :         for (u32 i = 0; i < NOTIFY_UNIQUE_ID_MAX_SIZE; ++i) {
      68            0 :             oss << std::hex << std::setw(2) << std::setfill('0')
      69            0 :                 << static_cast<unsigned int>(static_cast<unsigned char>(param->notifyParam[i])) << " ";
      70              :         }
      71            0 :         HCCL_INFO("[NotifyAicpuMgr][%s] %s", __func__, oss.str().c_str());
      72            0 :     }
      73            0 :     HcclResult ret = NotifyManager::ParseBinNotifys(notifysStr, notifys_);
      74            0 :     if (ret != HCCL_SUCCESS) {
      75            0 :         HCCL_ERROR(
      76              :             "[NotifyAicpuMgr][%s] comm identifier[%s], alloc notifys num[%u] failed %d", __func__, hcomId.c_str(),
      77              :             notifyNum, static_cast<int>(ret));
      78            0 :         return ret;
      79              :     }
      80            0 :     HCCL_INFO(
      81              :         "[NotifyAicpuMgr][%s] comm identifier[%s], alloc notifys num[%u] end, after notifySize[%zu]", __func__,
      82              :         hcomId.c_str(), notifyNum, notifys_.size());
      83            0 :     NotifyHandle* notifyArray = static_cast<NotifyHandle*>(param->deviceHandle);
      84            0 :     CHK_PTR_NULL(notifyArray);
      85            0 :     for (size_t i = 0; i < notifyNum; ++i) {
      86            0 :         notifyArray[i] = reinterpret_cast<NotifyHandle>(notifys_[i + notifySize].get());
      87            0 :         HCCL_INFO(
      88              :             "[NotifyAicpuMgr][%s] notifyArray[%zu] = [%llu]", __func__, i + notifySize,
      89              :             static_cast<unsigned long long>(notifyArray[i]));
      90              :     }
      91              : 
      92            0 :     HCCL_INFO(
      93              :         "[NotifyAicpuMgr][%s] comm identifier[%s], alloc notifys num[%u] success", __func__, hcomId.c_str(), notifyNum);
      94            0 :     return HCCL_SUCCESS;
      95            0 : }
        

Generated by: LCOV version 2.0-1