LCOV - code coverage report
Current view: top level - legacy/ascend950/unified_platform/resource/buffer - buffer.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 94.4 % 36 34
Test Date: 2026-08-04 10:52:23 Functions: 100.0 % 13 13

            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 "buffer.h"
      12              : #include "range_utils.h"
      13              : #include "log.h"
      14              : #include "string_util.h"
      15              : namespace Hccl {
      16              : 
      17          869 : Buffer::Buffer(uintptr_t addr, std::size_t size) : addr_(addr), size_(size)
      18              : {
      19          869 : }
      20              : 
      21         3194 : Buffer::Buffer(std::size_t size) : size_(size)
      22              : {
      23         3194 : }
      24              : 
      25           18 : Buffer::Buffer(uintptr_t addr, std::size_t size, HcclMemType memType) : addr_(addr), size_(size), memType_(memType)
      26              : {
      27           18 : }
      28              : 
      29           78 : Buffer::Buffer(uintptr_t addr, std::size_t size, HcclMemType memType, const char *memInfo) : addr_(addr), size_(size), memType_(memType)
      30              : {
      31           78 :     if (memInfo != nullptr) {
      32           78 :         snprintf_s(memInfo_, sizeof(memInfo_), strlen(memInfo), "%s", memInfo);
      33              :     } else {
      34            0 :         memInfo_[0] = '\0'; // 初始化为空字符串
      35              :     }
      36           78 : }
      37              : 
      38            2 : Buffer::Buffer(uintptr_t addr, std::size_t size, const char *memInfo) : addr_(addr), size_(size)
      39              : {
      40            2 :     if (memInfo != nullptr) {
      41            2 :         snprintf_s(memInfo_, sizeof(memInfo_), strlen(memInfo), "%s", memInfo);
      42              :     } else {
      43            0 :         memInfo_[0] = '\0'; // 初始化为空字符串
      44              :     }
      45            2 : }
      46      4612289 : uintptr_t Buffer::GetAddr() const
      47              : {
      48      4612289 :     return addr_;
      49              : }
      50              : 
      51      9236352 : size_t Buffer::GetSize() const
      52              : {
      53      9236352 :     return size_;
      54              : }
      55              : 
      56           82 : HcclMemType Buffer::GetMemType() const
      57              : {
      58           82 :     return memType_;
      59              : }
      60              : 
      61           89 : const std::string Buffer::GetMemInfo() const
      62              : {
      63          178 :     return memInfo_;
      64              : }
      65              : 
      66            4 : std::string Buffer::Describe() const
      67              : {
      68            4 :     return StringFormat("Buffer[addr=0x%llx, size=0x%llx, memInfo=%s]", addr_, size_, memInfo_);
      69              : }
      70              : 
      71            1 : bool Buffer::Contains(Buffer *buf) const
      72              : {
      73            1 :     return IsRangeInclude(addr_, size_, buf->addr_, buf->size_);
      74              : }
      75              : 
      76           16 : bool Buffer::Contains(uintptr_t bufAddr, size_t bufSize) const
      77              : {
      78           16 :     return IsRangeInclude(addr_, size_, bufAddr, bufSize);
      79              : }
      80              : 
      81           25 : Buffer Buffer::Range(std::size_t offset, std::size_t givenSize) const
      82              : {
      83           75 :     HCCL_INFO("[Buffer::Range] offset[%zu] givenSize[%zu] size[%zu]", offset, givenSize, size_);
      84           25 :     if (addr_ != 0 && (offset + givenSize) <= size_) {
      85           24 :         return Buffer(addr_ + offset, givenSize);
      86              :     } else {
      87            3 :         HCCL_WARNING("Buffer range[%zu] size[%zu Byte] error or addr[0x%llx] null", offset + givenSize, size_, addr_);
      88            1 :         return Buffer(0, 0);
      89              :     }
      90              : }
      91              : 
      92              : } // namespace Hccl
        

Generated by: LCOV version 2.0-1