|
Mila 0.13.48
Deep Neural Network Library
|
Device-aware N-dimensional tensor. More...


Public Types | |
| using | DataType = TensorDataType |
| Abstract data type enumeration. | |
| using | DataTypeTraits = TensorDataTypeTraits<TDataType> |
| Compile-time data type characteristics. | |
| using | host_value_t = std::conditional_t<TensorDataTypeTraits<TDataType>::is_integer_type, int32_t, float> |
| Host value type for scalars. | |
| using | MemoryResource = TMemoryResource |
| Memory resource type for this tensor. | |
Public Member Functions | |
| Tensor (Compute::DeviceId device_id, const shape_t &shape, std::string name={}) | |
| Creates a tensor bound to the specified device id and shape. | |
| Tensor (const Tensor &other)=delete | |
| Copy constructor - explicitly deleted for performance safety. | |
| Tensor (Tensor &&other) noexcept | |
| Efficiently transfers ownership from another tensor. | |
| ~Tensor ()=default | |
| Destructor with automatic resource cleanup via RAII. | |
| constexpr const auto * | data () const noexcept |
| Returns type-safe immutable pointer to tensor data with concrete host type. | |
| constexpr auto * | data () noexcept |
| Returns type-safe pointer to tensor data with concrete host type. | |
| size_t | elementSize () const override |
| Returns the size in bytes of a single tensor element. | |
| bool | empty () const |
| Checks if the tensor contains no elements. | |
| Tensor< TDataType, TMemoryResource > & | flatten () |
| Flattens tensor to 2D shape in-place. | |
| TensorDataType | getDataType () const override |
| Returns the tensor's abstract data type identifier. | |
| std::string | getDataTypeName () const override |
| Returns human-readable name of the tensor's data type. | |
| Compute::DeviceId | getDeviceId () const override |
| Compute::DeviceType | getDeviceType () const override |
| Returns the device type of this tensor's memory resource. | |
| Compute::MemoryResource * | getMemoryResource () const override |
| Returns pointer to the memory resource managing this tensor's storage. | |
| std::string | getName () const override |
| Returns the tensor's optional user-assigned name. | |
| size_t | getStorageSize () const override |
| Returns the total storage size in bytes backing the tensor's buffer. | |
| std::string | getUId () const override |
| Returns the tensor's unique identifier. | |
| bool | isScalar () const noexcept override |
| Checks if tensor is a scalar (0-dimensional). | |
| bool | isValid () const noexcept |
| Check if tensor is in a valid state (not moved-from). | |
| bool | isView () const override |
| Check if this tensor is a view of another tensor's data. | |
| auto & | item () |
| Gets the scalar value for 0-dimensional tensors. | |
| const auto & | item () const |
| Gets the scalar value for 0-dimensional tensors (const version). | |
| Tensor & | operator= (const Tensor &other)=delete |
| Copy assignment operator - explicitly deleted. | |
| Tensor & | operator= (Tensor &&other) noexcept |
| Efficiently moves resources from another tensor. | |
| auto & | operator[] (const index_t &indices) |
| Accesses tensor element using multi-dimensional indices. | |
| const auto & | operator[] (const index_t &indices) const |
| Accesses tensor element using multi-dimensional indices (const version). | |
| template<typename... Indices> requires TMemoryResource::is_host_accessible | |
| auto & | operator[] (Indices... indices) &&(std |
| Variadic index access (non-const). | |
| template<typename... Indices> requires TMemoryResource::is_host_accessible | |
| const auto & | operator[] (Indices... indices) const &&(std |
| Variadic index access (const). | |
| size_t | rank () const |
| Returns the number of dimensions in the tensor. | |
| const void * | rawData () const override |
| Returns raw pointer to tensor data (const version). | |
| void * | rawData () override |
| Returns raw pointer to tensor data (implements ITensor protected API). | |
| void | reshape (const shape_t &new_shape) |
| Modifies tensor shape while preserving total element count. | |
| void | setName (const std::string &value) |
| Assigns a descriptive name to the tensor. | |
| const shape_t & | shape () const override |
| Returns the tensor's dimensional shape vector. | |
| size_t | size () const override |
| Returns the total number of logical elements in the tensor. | |
| const stride_t & | strides () const |
| Returns the tensor's memory stride information. | |
| std::string | toString (bool showBuffer=false) const |
| Generates string representation of the tensor. | |
| Tensor | view (const shape_t &new_shape, size_t offset=0) const |
| Public Member Functions inherited from Mila::Dnn::ITensor | |
| virtual | ~ITensor ()=default |
| template<typename T> | |
| bool | isType () const |
| Type-safe check for tensor element type. | |
Static Public Member Functions | |
| static constexpr bool | is_device_accessible () |
| Checks if tensor data is accessible from device (GPU) code. | |
| static constexpr bool | is_host_accessible () |
| Checks if tensor data is accessible from host (CPU) code. | |
Private Member Functions | |
| Tensor (const Tensor &parent, const shape_t &shape, size_t offset) | |
| void | allocateBuffer () |
| Allocates and initializes the tensor's data buffer. | |
| int64_t | computeFlatIndex (const index_t &indices) const |
| Computes flat memory index from multi-dimensional indices. | |
| int64_t | computeSize (const shape_t &shape) const |
| Computes total element count from shape vector. | |
| stride_t | computeStrides (const shape_t &shape) |
| Computes row-major memory strides from shape. | |
| std::string | getBufferString () const |
| Gets formatted buffer content for string representation. | |
| std::string | outputBuffer (size_t index, size_t depth) const |
| std::string | outputLayout () const |
| Generates formatted layout information string. | |
| std::string | setUId () |
| Generates unique identifier for new tensor instance. | |
| void | validateIndices (const index_t &indices, const char *fn) const |
| Validates multi-dimensional indices against tensor shape. | |
Static Private Member Functions | |
| static Compute::DeviceId | validateDeviceId (Compute::DeviceId device_id) |
| Validates device id against the memory resource requirement. | |
Private Attributes | |
| std::shared_ptr< TensorBuffer< TDataType, TMemoryResource > > | buffer_ { nullptr } |
| Managed buffer containing tensor data. | |
| Compute::DeviceId | device_id_ |
| DeviceId for proper device binding and resource management. | |
| bool | is_view_ { false } |
| std::string | name_ |
| Optional user-assigned name for debugging. | |
| shape_t | shape_ {} |
| Dimensional sizes for each tensor dimension. | |
| size_t | size_ { 0 } |
| Total number of logical elements in the tensor. | |
| stride_t | strides_ {} |
| Memory stride values for multi-dimensional indexing. | |
| std::string | uid_ |
| Unique identifier for this tensor instance. | |
| size_t | view_offset_ { 0 } |
Device-aware N-dimensional tensor.
Move-only tensor parameterized by an abstract TensorDataType and a MemoryResource. Scalars are represented by an empty shape ({}), which yields size() == 1.
| TDataType | Abstract tensor data type from TensorDataType enumeration |
| TMemoryResource | Memory resource type defining storage location and access patterns |
| using Mila::Dnn::Tensor< TDataType, TMemoryResource >::DataType = TensorDataType |
Abstract data type enumeration.
| using Mila::Dnn::Tensor< TDataType, TMemoryResource >::DataTypeTraits = TensorDataTypeTraits<TDataType> |
Compile-time data type characteristics.
| using Mila::Dnn::Tensor< TDataType, TMemoryResource >::host_value_t = std::conditional_t<TensorDataTypeTraits<TDataType>::is_integer_type, int32_t, float> |
Host value type for scalars.
| using Mila::Dnn::Tensor< TDataType, TMemoryResource >::MemoryResource = TMemoryResource |
Memory resource type for this tensor.
|
inlineexplicit |
Creates a tensor bound to the specified device id and shape.
Constructs a tensor using a DeviceId. Empty shape {} creates a scalar (0D tensor) with size 1. Shape containing a zero produces an empty tensor.
| device_id | Device identifier (type + index) |
| shape | Vector defining the size of each dimension in row-major order |
| std::invalid_argument | If device id is invalid (checked by validateDeviceId) |
| std::runtime_error | If device type doesn't match memory resource |
| std::bad_alloc | If memory allocation fails |

|
delete |
Copy constructor - explicitly deleted for performance safety.
Use clone() for deep copies or std::move() for ownership transfer.
|
inlinenoexcept |
Efficiently transfers ownership from another tensor.
Moves resources from the source tensor, leaving it in a moved-from state.
|
default |
Destructor with automatic resource cleanup via RAII.
|
inlineprivate |
|
inlineprivate |
Allocates and initializes the tensor's data buffer.
Scalars allocate normally (size==1); truly empty tensors allocate nothing.

|
inlineprivate |
Computes flat memory index from multi-dimensional indices.

|
inlineprivate |
Computes total element count from shape vector.

|
inlineprivate |
Computes row-major memory strides from shape.

|
inlinenodiscardconstexprnoexcept |
Returns type-safe immutable pointer to tensor data with concrete host type.
|
inlinenodiscardconstexprnoexcept |
Returns type-safe pointer to tensor data with concrete host type.
Only available for host-accessible memory resources.

|
inlineoverridevirtual |
Returns the size in bytes of a single tensor element.
Implements Mila::Dnn::ITensor.

|
inline |
Checks if the tensor contains no elements.
Scalars are NOT empty (size == 1). Empty tensors have size == 0.

|
inline |
Flattens tensor to 2D shape in-place.
No-op for scalars and vectors.
|
inlineprivate |
Gets formatted buffer content for string representation.

|
inlineoverridevirtual |
Returns the tensor's abstract data type identifier.
Implements Mila::Dnn::ITensor.
|
inlineoverridevirtual |
Returns human-readable name of the tensor's data type.
Implements Mila::Dnn::ITensor.
|
inlineoverridevirtual |
|
inlineoverridevirtual |
Returns the device type of this tensor's memory resource.
Equivalent to TMemoryResource::device_type.
Implements Mila::Dnn::ITensor.
|
inlineoverridevirtual |
Returns pointer to the memory resource managing this tensor's storage.
Implements Mila::Dnn::ITensor.
|
inlineoverridevirtual |
Returns the tensor's optional user-assigned name.
Implements Mila::Dnn::ITensor.
|
inlineoverridevirtual |
Returns the total storage size in bytes backing the tensor's buffer.
Forwards to the authoritative TensorBuffer::storageBytes() value and returns 0 when no buffer is allocated.
Implements Mila::Dnn::ITensor.

|
inlineoverridevirtual |
Returns the tensor's unique identifier.
Implements Mila::Dnn::ITensor.
|
inlinestaticconstexpr |
Checks if tensor data is accessible from device (GPU) code.
|
inlinestaticconstexpr |
Checks if tensor data is accessible from host (CPU) code.

|
inlineoverridevirtualnoexcept |
Checks if tensor is a scalar (0-dimensional).
Scalars: shape {} and size() == 1.
Implements Mila::Dnn::ITensor.

|
inlinenoexcept |
Check if tensor is in a valid state (not moved-from).
|
inlineoverridevirtual |
Check if this tensor is a view of another tensor's data.
Implements Mila::Dnn::ITensor.
|
inline |
Gets the scalar value for 0-dimensional tensors.
Only available for host-accessible memory resources.
| std::runtime_error | If tensor is not a scalar (rank != 0) |
|
inline |
Gets the scalar value for 0-dimensional tensors (const version).
Only available for host-accessible memory resources.
| std::runtime_error | If tensor is not a scalar (rank != 0) |
|
delete |
Copy assignment operator - explicitly deleted.
Use clone() for deep copies or std::move() for transfers.
|
inlinenoexcept |
Efficiently moves resources from another tensor.
Self-assignment safe implementation.
|
inline |
Accesses tensor element using multi-dimensional indices.
Only available for host-accessible memory resources.

|
inline |
Accesses tensor element using multi-dimensional indices (const version).
|
inline |
Variadic index access (non-const).
|
inline |
Variadic index access (const).
|
inlineprivate |

|
inlineprivate |
Generates formatted layout information string.

|
inline |
Returns the number of dimensions in the tensor.

|
inlineoverridevirtual |
Returns raw pointer to tensor data (const version).
Implements Mila::Dnn::ITensor.
|
inlineoverridevirtual |
Returns raw pointer to tensor data (implements ITensor protected API).
Implements Mila::Dnn::ITensor.

|
inline |
Modifies tensor shape while preserving total element count.
The new shape must have the same total number of elements as the current shape, unless the tensor is empty.

|
inline |
Assigns a descriptive name to the tensor.
Names must be non-empty strings.

|
inlineprivate |
Generates unique identifier for new tensor instance.
|
inlineoverridevirtual |
Returns the tensor's dimensional shape vector.
Implements Mila::Dnn::ITensor.

|
inlineoverridevirtual |
Returns the total number of logical elements in the tensor.
Implements Mila::Dnn::ITensor.

|
inline |
Returns the tensor's memory stride information.
|
inline |
Generates string representation of the tensor.
Includes UID, name, shape, data type and device information.

|
inlinestaticprivate |
Validates device id against the memory resource requirement.
Throws if types do not match.
|
inlineprivate |
Validates multi-dimensional indices against tensor shape.

|
inlinenodiscard |

|
private |
Managed buffer containing tensor data.
|
private |
DeviceId for proper device binding and resource management.
|
private |
|
private |
Optional user-assigned name for debugging.
|
private |
Dimensional sizes for each tensor dimension.
|
private |
Total number of logical elements in the tensor.
|
private |
Memory stride values for multi-dimensional indexing.
|
private |
Unique identifier for this tensor instance.
|
private |