Skip to main content

Overview

TensorRef is a template for objects pointing to the start of tensors of arbitrary rank and layout within memory. A TensorRef combines a pointer and a Layout concept to provide structured access to multi-dimensional data. Header: cutlass/tensor_ref.h

Template Signature

Template Parameters

typename
Data type of element stored within tensor (concept: NumericType). Examples: float, half_t, int8_t
typename
Defines a mapping from logical coordinate to linear memory (concept: Layout). Examples: layout::RowMajor, layout::ColumnMajor, IdentityTensorLayout<2>

Member Types

Constructors

Default Constructor

Constructs a null TensorRef.

Pointer and Layout Constructor

Parameters:
  • ptr: Pointer to start of tensor
  • layout: Layout object containing stride and mapping function

Converting Constructor

Converting constructor from TensorRef to non-constant data.

Member Functions

const_ref

Returns a reference to constant-valued tensor.

non_const_ref

Returns a reference to non-constant tensor.

reset

Updates the pointer, optionally with a new layout.

good

Returns true if the TensorRef is non-null.

data

Returns the pointer to referenced data, or a reference to the element at a given linear index.

layout

Returns the layout object.

stride

Returns the layout object’s stride vector or a specific stride dimension.

offset

Computes the offset of an index from the origin of the tensor.

at

Returns a reference to the element at a given coordinate.

operator[]

Returns a reference to the element at a given coordinate.

add_pointer_offset

Adds an offset to the pointer.

add_coord_offset

Adds a coordinate offset to the pointer.

Arithmetic Operators

Returns or modifies a TensorRef offset by a given amount.

Helper Functions

make_TensorRef

Constructs a TensorRef, deducing types from arguments.

TensorRef_aligned

Checks if a TensorRef’s pointer and strides are aligned to the specified alignment.

Usage Examples

From include/cutlass/tensor_ref.h:120-144:

Column-major matrix

Row-major matrix

Interleaved matrix

Contiguous matrix with runtime layout

Accessing elements

See Also

  • Layout Types - Layout functions for various matrix formats
  • Gemm - GEMM operator that uses TensorRef for matrix operands
  • Array - Statically-sized array container