cuda.core.experimental.utils.StridedMemoryView¶
- class cuda.core.experimental.utils.StridedMemoryView(obj=None, stream_ptr=None)¶
A dataclass holding metadata of a strided dense array/tensor.
A
StridedMemoryView
instance can be created in two ways:Using the
args_viewable_as_strided_memory
decorator (recommended)Explicit construction, see below
This object supports both DLPack (up to v1.0) and CUDA Array Interface (CAI) v3. When wrapping an arbitrary object it will try the DLPack protocol first, then the CAI protocol. A
BufferError
is raised if neither is supported.Since either way would take a consumer stream, for DLPack it is passed to
obj.__dlpack__()
as-is (except forNone
, see below); for CAI, a stream order will be established between the consumer stream and the producer stream (fromobj.__cuda_array_interface__()["stream"]
), as ifcudaStreamWaitEvent
is called by this method.To opt-out of the stream ordering operation in either DLPack or CAI, please pass
stream_ptr=-1
. Note that this deviates (on purpose) from the semantics ofobj.__dlpack__(stream=None, ...)
sincecuda.core
does not encourage using the (legacy) default/null stream, but is consistent with the CAI’s semantics. For DLPack,stream=-1
will be internally passed toobj.__dlpack__()
instead.- dtype¶
Data type of the tensor.
- Type:
- device_id¶
The device ID for where the tensor is located. It is -1 for CPU tensors (meaning those only accessible from the host).
- Type:
- exporting_obj¶
A reference to the original tensor object that is being viewed.
- Type:
Any
- Parameters:
obj (Any) – Any objects that supports either DLPack (up to v1.0) or CUDA Array Interface (v3).
stream_ptr (int) – The pointer address (as Python int) to the consumer stream. Stream ordering will be properly established unless
-1
is passed.