LCOV - code coverage report
Current view: top level - legacy/ascend950/unified_platform/resource/buffer - data_buffer.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 5 5
Test Date: 2026-08-18 17:47:01 Functions: 83.3 % 6 5

            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_Data_DataBuffer_H
      12              : #define HCCL_Data_DataBuffer_H
      13              : 
      14              : #include <cstdint>
      15              : #include <cstddef>
      16              : #include <string>
      17              : #include "string_util.h"
      18              : #include "hash_utils.h"
      19              : namespace Hccl {
      20              : 
      21              : class DataBuffer {
      22              : public:
      23           75 :     DataBuffer(uintptr_t addr, std::size_t size) : addr(addr), size(size) {};
      24              : 
      25              :     explicit DataBuffer(std::size_t size) : size(size) {};
      26              : 
      27          466 :     virtual ~DataBuffer() = default;
      28              : 
      29            7 :     uintptr_t GetAddr() const { return addr; }
      30              : 
      31           13 :     size_t GetSize() const { return size; }
      32              : 
      33            8 :     virtual std::string Describe() const { return StringFormat("Buffer[addr=0x%llx, size=0x%llx]", addr, size); }
      34              : 
      35              :     // "=="运算符
      36              :     bool operator==(const DataBuffer& that) const { return (addr == that.GetAddr()) && (size == that.GetSize()); }
      37              : 
      38              :     // "!="运算符
      39              :     bool operator!=(const DataBuffer& that) const { return (addr != that.GetAddr()) || (size != that.GetSize()); }
      40              : 
      41              : protected:
      42              :     uintptr_t addr{0};
      43              :     std::size_t size{0};
      44              : };
      45              : } // namespace Hccl
      46              : 
      47              : namespace std {
      48              : 
      49              : template <>
      50              : class hash<Hccl::DataBuffer> {
      51              : public:
      52              :     size_t operator()(const Hccl::DataBuffer& dataBuffer) const
      53              :     {
      54              :         auto addrHash = hash<uint8_t>{}(dataBuffer.GetAddr());
      55              :         auto sizeHash = hash<uint8_t>{}(dataBuffer.GetSize());
      56              : 
      57              :         return Hccl::HashCombine({addrHash, sizeHash});
      58              :     }
      59              : };
      60              : } // namespace std
      61              : #endif // HCCL_DataBuffer_H
        

Generated by: LCOV version 2.0-1