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

Generated by: LCOV version 2.0-1