MCPcopy Create free account
hub / github.com/NVIDIA/TensorRT / view

Method view

tools/Polygraphy/polygraphy/cuda/cuda.py:454–479  ·  view source on GitHub ↗

Creates a read-only DeviceView from this DeviceArray. Args: shape (Sequence[int]): The desired shape of the view. Defaults to the shape of this array or view. dtype (numpy.dtype): The desired data t

(self, shape=None, dtype=None)

Source from the content-addressed store, hash-verified

452 return self
453
454 def view(self, shape=None, dtype=None):
455 """
456 Creates a read-only DeviceView from this DeviceArray.
457
458 Args:
459 shape (Sequence[int]):
460 The desired shape of the view.
461 Defaults to the shape of this array or view.
462 dtype (numpy.dtype):
463 The desired data type of the view.
464 Defaults to the data type of this array or view.
465
466 Returns:
467 DeviceView: A view of this arrays data on the device.
468 """
469 shape = util.default(shape, self.shape)
470 dtype = util.default(dtype, self.dtype)
471 view = DeviceView(self.ptr, shape, dtype)
472
473 if view.nbytes > self.nbytes:
474 G_LOGGER.critical(
475 "A view cannot exceed the number of bytes of the original array.\n"
476 f"Note: Original array has shape: {self.shape} and dtype: {self.dtype}, which requires {self.nbytes} bytes, "
477 f"while the view has shape: {shape} and dtype: {dtype}, which requires {view.nbytes} bytes, "
478 )
479 return view
480
481 def __str__(self):
482 return f"DeviceArray[(dtype={np.dtype(self.dtype).name}, shape={self.shape}), ptr={hex(self.ptr)}]"

Calls 3

DeviceViewClass · 0.85
defaultMethod · 0.45
criticalMethod · 0.45