LCOV - code coverage report
Current view: top level - legacy/ascend950/unified_platform/resource/buffer - buffer.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 50.0 % 2 1
Test Date: 2026-08-18 17:47:01 Functions: 66.7 % 3 2

            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              : #ifndef HCCL_BUFFER_H
      12              : #define HCCL_BUFFER_H
      13              : 
      14              : #include <cstdint>
      15              : #include <cstddef>
      16              : #include <string>
      17              : #include "hccl_mem_defs.h"
      18              : #include "enum_factory_legacy.h"
      19              : namespace Hccl {
      20              : 
      21              : class Buffer {
      22              : public:
      23              :     Buffer(uintptr_t addr, std::size_t size);
      24              : 
      25              :     explicit Buffer(std::size_t size);
      26              : 
      27              :     explicit Buffer(uintptr_t addr, std::size_t size, HcclMemType memType);
      28              : 
      29              :     explicit Buffer(uintptr_t addr, std::size_t size, HcclMemType memType, const char* memInfo);
      30              : 
      31              :     explicit Buffer(uintptr_t addr, std::size_t size, const char* memInfo);
      32              : 
      33         4311 :     virtual ~Buffer() = default;
      34              : 
      35              :     uintptr_t GetAddr() const;
      36              : 
      37              :     size_t GetSize() const;
      38              : 
      39              :     HcclMemType GetMemType() const;
      40              : 
      41              :     const std::string GetMemInfo() const;
      42              : 
      43              :     virtual std::string Describe() const;
      44              : 
      45              :     bool Contains(Buffer* buf) const;
      46              : 
      47              :     bool Contains(uintptr_t bufAddr, size_t bufSize) const;
      48              : 
      49              :     Buffer Range(std::size_t offset, std::size_t givenSize) const;
      50              : 
      51              :     // "bool"运算符(可执行if(object){...}的操作判断该buffer是否为空)
      52            0 :     operator bool() const { return addr_ != 0; }
      53              : 
      54              :     // "=="运算符
      55              :     bool operator==(const Buffer& that) const { return (addr_ == that.GetAddr()) && (size_ == that.GetSize()); }
      56              : 
      57              :     // "!="运算符
      58              :     bool operator!=(const Buffer& that) const { return (addr_ != that.GetAddr()) || (size_ != that.GetSize()); }
      59              : 
      60              : protected:
      61              :     uintptr_t addr_{0};
      62              :     std::size_t size_{0};
      63              :     HcclMemType memType_{HcclMemType::HCCL_MEM_TYPE_DEVICE};
      64              :     char memInfo_[256]{};
      65              : };
      66              : 
      67              : } // namespace Hccl
      68              : #endif // HCCL_BUFFER_H
        

Generated by: LCOV version 2.0-1