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

Generated by: LCOV version 2.0-1