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: 92.9 % 28 26
Test Date: 2026-08-18 17:47:01 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              : 
      11              : #include "data_buf_manager.h"
      12              : #include "log.h"
      13              : #include "exception_util.h"
      14              : namespace Hccl {
      15              : 
      16          319 : DataBufManager::~DataBufManager() { DECTOR_TRY_CATCH("DataBufManager", Destroy()); }
      17              : 
      18            2 : bool DataBufManager::IsExist(const std::string& opTag, BufferType type)
      19              : {
      20            2 :     return bufs.find(opTag) != bufs.end() && bufs[opTag].find(type) != bufs[opTag].end();
      21              : }
      22              : 
      23          257 : Buffer* DataBufManager::Register(const std::string& opTag, BufferType type, std::shared_ptr<Buffer> buffer)
      24              : {
      25          257 :     if (buffer == nullptr) {
      26           21 :         HCCL_WARNING("opTag[%s] type[%s] 's buffer is nullptr", opTag.c_str(), type.Describe().c_str());
      27            7 :         return nullptr;
      28              :     }
      29          250 :     bufs[opTag][type] = buffer;
      30          250 :     return bufs[opTag][type].get();
      31              : }
      32              : 
      33            2 : void DataBufManager::Deregister(const std::string& opTag, BufferType type)
      34              : {
      35            2 :     if (!IsExist(opTag, type)) {
      36            3 :         HCCL_WARNING("Cannot find Buffer in map.");
      37            1 :         return;
      38              :     }
      39            1 :     bufs[opTag].erase(type);
      40            1 :     if (bufs[opTag].empty()) {
      41            1 :         bufs.erase(opTag);
      42              :     }
      43              : }
      44              : 
      45            1 : HcclResult DataBufManager::Deregister(const std::string& opTag)
      46              : {
      47            1 :     if (bufs.find(opTag) == bufs.end()) {
      48            3 :         HCCL_WARNING("[DataBufManager::%s] opTag[%s] Cannot find Buffer in bufs.", __func__, opTag.c_str());
      49            1 :         return HCCL_SUCCESS;
      50              :     }
      51            0 :     bufs.erase(opTag);
      52            0 :     return HCCL_SUCCESS;
      53              : }
      54              : 
      55           26 : Buffer* DataBufManager::Get(const std::string& opTag, BufferType type)
      56              : {
      57           26 :     if (bufs.find(opTag) != bufs.end() && bufs[opTag].find(type) != bufs[opTag].end()) {
      58           15 :         return bufs[opTag][type].get();
      59              :     }
      60           33 :     HCCL_WARNING("Buffer doesn't exist, opTag[%s], dataBuf[type=%s]", opTag.c_str(), type.Describe().c_str());
      61           11 :     return nullptr;
      62              : }
      63              : 
      64          319 : void DataBufManager::Destroy() { bufs.clear(); }
      65              : 
      66              : } // namespace Hccl
        

Generated by: LCOV version 2.0-1