Skip to main content

Overview

cute::Tensor is CuTe’s core data structure that combines an Engine (data storage) with a Layout (coordinate-to-index mapping). Tensors can be owning (allocating their own storage) or non-owning (viewing existing memory).

Class Template

Template Parameters

Engine
The data storage engine. Can be:
  • ViewEngine<T*> for non-owning views
  • ArrayEngine<T, N> for owning static arrays
  • ConstViewEngine<const T*> for const views
Layout<Shape, Stride>
The layout describing the coordinate-to-index mapping.

Source Location

include/cute/tensor_impl.hpp:135-341

Member Functions

Data Access

data()

Returns a pointer/iterator to the underlying data. Example:

layout()

Returns the layout of the tensor.

shape()

Returns the shape of the tensor.

stride()

Returns the stride of the tensor.

size()

Returns the total number of elements in the tensor.

Indexing

operator[]

Indexes into the tensor using array-style indexing. Returns a reference to the element. Example:

operator()

Indexes or slices the tensor. If coord contains _ (underscore), returns a sliced subtensor. Otherwise, returns a reference to the element. Example:

Transformation

compose()

Composes the tensor’s layout with other layouts, returning a new tensor view. Example:

tile()

Tiles the tensor into blocks. Example:

Coordinate Conversion

get_1d_coord()

Converts a linear index to a 1D logical coordinate.

get_hier_coord()

Converts a linear index to hierarchical coordinates matching the tensor’s shape structure.

get_flat_coord()

Converts a linear index to flat N-dimensional coordinates.

Factory Functions

make_tensor() - Owning

Creates an owning tensor that allocates static storage. Parameters:
  • T: Element type
  • args: Layout arguments (shape, stride, or Layout)
Example:

make_tensor() - Non-owning

Creates a non-owning tensor view over existing memory. Parameters:
  • iter: Pointer or iterator to the data
  • args: Layout arguments
Example:

make_tensor_like()

Creates a register tensor with the same shape and layout as another tensor. Example:

make_fragment_like()

Creates a register tensor optimized for fragments, with special handling for the first mode (typically used for MMA/Copy atom values). Example:

make_identity_tensor()

Creates a tensor that maps coordinates to themselves (useful for tracking transformations).

Engine Types

ViewEngine

Non-owning view of existing memory:

ArrayEngine

Owning static array (compile-time size):

Common Operations

Tensor Partitioning

Tensor Slicing

Tensor Reshaping

Usage Examples

Basic Tensor Creation and Access

Register Tensors (Fragments)

Tiled Tensor Processing

Hierarchical Tensor Layouts

See Also