nndeploy.device.buffer 源代码

import nndeploy._nndeploy_internal as _C

import numpy as np

import nndeploy.base
from .device import Device
from .type import BufferDesc
from .memory_pool import MemoryPool


[文档]class Buffer(_C.device.Buffer):
[文档] def __init__(self, *args, **kwargs): # 将Device转换为_C.device.Device if len(args) > 0 and isinstance(args[0], Device): args = (args[0]._device,) + args[1:] # 将MemoryPool转换为_C.device.MemoryPool elif len(args) > 0 and isinstance(args[0],MemoryPool): args = (args[0]._memory_pool,) + args[1:] super().__init__(*args, **kwargs)
[文档] def clone(self): """Clone the buffer""" return super().clone()
[文档] def copy_to(self, dst): """Copy the buffer to the destination buffer""" return super().copyTo(dst)
[文档] def serialize(self, bin_str: str): """Serialize the buffer to a binary string""" return super().serialize(bin_str)
[文档] def deserialize(self, bin_str: str): """Deserialize the buffer from a binary string""" return super().deserialize(bin_str)
[文档] def print(self): """Print buffer information""" return super().print()
[文档] def just_modify(self, size): """Modify the buffer size""" return super().justModify(size)
[文档] def empty(self): """Check if the buffer is empty""" return super().empty()
[文档] def get_device_type(self): """Get the device type of the buffer""" return super().getDeviceType()
[文档] def get_device(self): """Get the device of the buffer""" c_device = super().getDevice() return Device(c_device)
[文档] def get_memory_pool(self): """Get the memory pool of the buffer""" c_memory_pool = super().getMemoryPool() return MemoryPool(c_memory_pool)
[文档] def is_memory_pool(self): """Check if the buffer is from a memory pool""" return super().isMemoryPool()
[文档] def get_desc(self): """Get the buffer descriptor""" return super().getDesc()
[文档] def get_size(self): """Get the size of the buffer""" return super().getSize()
[文档] def get_size_vector(self): """Get the size vector of the buffer""" return super().getSizeVector()
[文档] def get_real_size(self): """Get the real size of the buffer""" return super().getRealSize()
[文档] def get_real_size_vector(self): """Get the real size vector of the buffer""" return super().getRealSizeVector()
[文档] def get_config(self): """Get the configuration of the buffer""" return super().getConfig()
[文档] def get_data(self): """Get the data pointer of the buffer""" return super().getData()
[文档] def get_memory_type(self): """Get the memory type of the buffer""" return super().getMemoryType()
[文档] def add_ref(self): """Increase the reference count of the buffer""" return super().addRef()
[文档] def sub_ref(self): """Decrease the reference count of the buffer""" return super().subRef()
[文档] def to_numpy(self, *args, **kwargs): """Convert the buffer to numpy array 支持两种调用方式: 1. to_numpy(dtype) - 直接传入dtype对象 2. to_numpy(dtype_obj) - 传入可转换为dtype的对象 """ if len(args) == 1 and isinstance(args[0], np.dtype): return super().to_numpy_v0(args[0]) else: return super().to_numpy_v1(*args, **kwargs)
[文档] @staticmethod def from_numpy(array): """Convert numpy array to buffer""" return _C.device.Buffer.from_numpy(array)