LCOV - code coverage report
Current view: top level - legacy/ascend950/framework/resource_manager/buffer - data_buf_manager.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 93.8 % 32 30
Test Date: 2026-08-04 10:52:23 Functions: 100.0 % 7 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 "data_buf_manager.h"
      11              : #include "log.h"
      12              : #include "exception_util.h"
      13              : namespace Hccl {
      14              : 
      15          318 : DataBufManager::~DataBufManager()
      16              : {
      17          318 :     DECTOR_TRY_CATCH("DataBufManager", Destroy());
      18          318 : }
      19              : 
      20            2 : bool DataBufManager::IsExist(const std::string &opTag, BufferType type)
      21              : {
      22            2 :     return bufs.find(opTag) != bufs.end() && bufs[opTag].find(type) != bufs[opTag].end();
      23              : }
      24              : 
      25          272 : Buffer *DataBufManager::Register(const std::string &opTag, BufferType type, std::shared_ptr<Buffer> buffer)
      26              : {
      27          272 :     if (buffer == nullptr) {
      28           51 :         HCCL_WARNING("opTag[%s] type[%s] 's buffer is nullptr", opTag.c_str(), type.Describe().c_str());
      29           17 :         return nullptr;
      30              :     }
      31          255 :     bufs[opTag][type] = buffer;
      32          255 :     return bufs[opTag][type].get();
      33              : }
      34              : 
      35            2 : void DataBufManager::Deregister(const std::string &opTag, BufferType type)
      36              : {
      37            2 :     if (!IsExist(opTag, type)) {
      38            3 :         HCCL_WARNING("Cannot find Buffer in map.");
      39            1 :         return;
      40              :     }
      41            1 :     bufs[opTag].erase(type);
      42            1 :     if (bufs[opTag].empty()) {
      43            1 :         bufs.erase(opTag);
      44              :     }
      45              : }
      46              : 
      47            1 : HcclResult DataBufManager::Deregister(const std::string &opTag)
      48              : {
      49            1 :     if (bufs.find(opTag) == bufs.end()) {
      50            3 :         HCCL_WARNING("[DataBufManager::%s] opTag[%s] Cannot find Buffer in bufs.", __func__, opTag.c_str());
      51            1 :         return HCCL_SUCCESS;
      52              :     }
      53            0 :     bufs.erase(opTag);
      54            0 :     return HCCL_SUCCESS;
      55              : }
      56              : 
      57           26 : Buffer *DataBufManager::Get(const std::string &opTag, BufferType type)
      58              : {
      59           26 :     if (bufs.find(opTag) != bufs.end() && bufs[opTag].find(type) != bufs[opTag].end()) {
      60           15 :         return bufs[opTag][type].get();
      61              :     }
      62           33 :     HCCL_WARNING("Buffer doesn't exist, opTag[%s], dataBuf[type=%s]", opTag.c_str(), type.Describe().c_str());
      63           11 :     return nullptr;
      64              : }
      65              : 
      66          318 : void DataBufManager::Destroy()
      67              : {
      68          318 :     bufs.clear();
      69          318 : }
      70              : 
      71              : } // namespace Hccl
        

Generated by: LCOV version 2.0-1