LCOV - code coverage report
Current view: top level - legacy/ascend910/algorithm/impl/coll_executor - alg_profiling.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 75.6 % 41 31
Test Date: 2026-08-04 10:52:23 Functions: 100.0 % 4 4

            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 "alg_profiling.h"
      12              : #include "adapter_rts_common.h"
      13              : 
      14              : namespace hccl {
      15              : 
      16         1329 : AlgWrap &AlgWrap::GetInstance()
      17              : {
      18         1329 :     static AlgWrap algWrap;
      19         1329 :     return algWrap;
      20              : }
      21              : 
      22          521 : HcclResult AlgWrap::RegisterAlgCallBack(const std::string &comm, void *userPtr, TaskCallBack callback, s32 deviceLogicID)
      23              : {
      24          521 :     CHK_PRT_RET(initialized_ == false, HCCL_WARNING("[alg_profiling][RegisterAlgCallBack] AlgWrap has not initialized"), HCCL_SUCCESS);
      25              : 
      26          521 :     if (deviceLogicID < 0 || static_cast<u32>(deviceLogicID) >= MAX_MODULE_DEVICE_NUM) {
      27            0 :         HCCL_ERROR("[alg_profiling][RegisteralgCallBack] deviceLogicID %d is invalid", deviceLogicID);
      28            0 :         return HCCL_E_PARA;
      29              :     }
      30          521 :     std::lock_guard<std::mutex> lock(aivCallBackMutex_);
      31          521 :     aivCallBackMap_[comm][deviceLogicID] = callback;
      32          521 :     aivCallBackUserPtrMap_[comm][deviceLogicID] = userPtr;
      33          521 :     return HCCL_SUCCESS;
      34          521 : }
      35              : 
      36          802 : void AlgWrap::UnregisterAlgCallBack(const std::string &comm)
      37              : {
      38          802 :     if (!initialized_) {
      39            0 :         HCCL_WARNING("[alg_profiling][UnRegisterAlgCallBack] AlgWrap has not initialized yet");
      40            0 :         return;
      41              :     }
      42              : 
      43          802 :     std::lock_guard<std::mutex> lock(aivCallBackMutex_);
      44          804 :     aivCallBackMap_.erase(comm);
      45          804 :     aivCallBackUserPtrMap_.erase(comm);
      46          804 : }
      47              : 
      48            5 : HcclResult AlgWrap::TaskAivProfiler(const std::string &comm, struct TaskParaGeneral &taskParaGeneral)
      49              : {
      50            5 :     CHK_PRT_RET(initialized_ == false, HCCL_WARNING("[alg_profiling][RegisterAlgCallBack] AlgWrap has not initialized"), HCCL_SUCCESS);
      51              : 
      52            5 :     s32 deviceLogicID = INVALID_INT;
      53            5 :     CHK_RET(hrtGetDevice(&deviceLogicID));
      54            5 :     if (deviceLogicID < 0 || static_cast<u32>(deviceLogicID) >= MAX_MODULE_DEVICE_NUM) {
      55            0 :         HCCL_ERROR("[alg_profiling][TaskAivProfiler] deviceLogicID %d is invalid", deviceLogicID);
      56            0 :         return HCCL_E_PARA;
      57              :     }
      58              : 
      59            5 :     std::lock_guard<std::mutex> lock(aivCallBackMutex_);
      60           10 :     if (aivCallBackMap_.find(comm) == aivCallBackMap_.end() ||
      61           10 :         aivCallBackUserPtrMap_.find(comm) == aivCallBackUserPtrMap_.end()) {
      62            0 :         HCCL_ERROR("[alg_profiling][TaskAivProfiler] comm %s is invalid", comm.c_str());
      63            0 :         return HCCL_E_PARA;
      64              :     }
      65              : 
      66            5 :     auto *aivCallBack = aivCallBackMap_[comm][deviceLogicID];
      67            5 :     auto *aivCallBackUserPtr = aivCallBackUserPtrMap_[comm][deviceLogicID];
      68            5 :     if (aivCallBack == nullptr || aivCallBackUserPtr == nullptr) {
      69            0 :         HCCL_ERROR("[alg_profiling][TaskAivProfiler] aivCallBack or aivCallBackUserPtr is invalid");
      70            0 :         return HCCL_E_PTR;
      71              :     }
      72              : 
      73              :     // 回调
      74            5 :     (aivCallBack)(aivCallBackUserPtr, static_cast<void *>(&taskParaGeneral), sizeof(struct TaskParaGeneral));
      75            5 :     return HCCL_SUCCESS;
      76            5 : }
      77              : 
      78              : }  // namespace hccl
        

Generated by: LCOV version 2.0-1