INNER CODE UNIT · Python
__init__
onnx/onnx-tensorrt · onnx_tensorrt/tensorrt_engine.py:62
def __init__(self, size: int, dtype: Optional[np.dtype] = None):
if dtype is None:
dtype = np.dtype(np.uint8)
else:
dtype = np.dtype(dtype)
nbytes = size * dtype.itemsize
host_mem = cuda_call(cudart.cudaMallocHost(nbytes))
self._host_ptr = host_mem
self._host_size = size
self._nbytes = nbytes
self._dtype = dtype
@property
def array(self) -> np.ndarray:
# Create view with proper memory ownership
pointer_type = ctypes.POINTER(np.ctypeslib.as_ctypes_type(self._dtype))
host_array = np.ctypeslib.as_array(ctypes.cast(self._host_ptr, pointer_type), (self._host_size,))