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

            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 "host_buffer.h"
      12              : #include "string_util.h"
      13              : #include "internal_exception.h"
      14              : #include "exception_util.h"
      15              : #include "orion_adapter_rts.h"
      16              : namespace Hccl {
      17              : 
      18            3 : HostBuffer::HostBuffer(uintptr_t devAddr, std::size_t devSize) : Buffer(devSize), selfOwned(false)
      19              : {
      20            3 :     addr_ = devAddr;
      21            3 :     size_ = devSize;
      22            3 : }
      23              : 
      24          182 : HostBuffer::HostBuffer(std::size_t allocSize) : Buffer(allocSize), selfOwned(true)
      25              : {
      26          182 :     if (allocSize == 0) {
      27            1 :         std::string msg = "allocaSize should not be 0!";
      28            1 :         THROW<InternalException>(msg);
      29            1 :     }
      30          181 :     addr_ = reinterpret_cast<uintptr_t>(HrtMallocHost(allocSize));
      31          182 : }
      32              : 
      33          358 : HostBuffer::~HostBuffer()
      34              : {
      35          184 :     if (selfOwned) {
      36          181 :         DECTOR_TRY_CATCH("Buffer", HrtFreeHost(reinterpret_cast<void*>(addr_)))
      37              :     }
      38          358 : }
      39              : 
      40            2 : std::string HostBuffer::Describe() const
      41              : {
      42            2 :     return StringFormat("HostBuffer[addr=0x%llx, size=0x%llx, selfOwned=%d]", addr_, size_, selfOwned);
      43              : }
      44              : 
      45            2 : bool HostBuffer::GetSelfOwned() const { return selfOwned; }
      46              : 
      47              : } // namespace Hccl
        

Generated by: LCOV version 2.0-1