Contents

struct

SushiBLAS::Tensor

A structure that represents a multi-dimensional array of data.

Declared in
include/SushiBLAS/tensor.hpp

The Tensor structure stores metadata like shape and strides. It does not own the memory directly but uses a Storage object to access data.

Public attributes

std::array< int64_t, SushiBLAS::Core::MAX_TENSOR_RANK > shape {}

The size of each dimension (e.g., {rows, columns}).

std::array< int64_t, SushiBLAS::Core::MAX_TENSOR_RANK > strides {}

The memory step size for each dimension to calculate indices.

int32_t rank = 0

The number of dimensions in the tensor (e.g., 2 for a matrix).

SushiBLAS::Core::DataType dtype = SushiBLAS::Core::DataType::FLOAT32

The type of data stored in the tensor (e.g., FLOAT32).

SushiBLAS::Core::Layout layout = SushiBLAS::Core::Layout::ROW_MAJOR

How the data is arranged in memory (ROW_MAJOR or COLUMN_MAJOR).

int64_t num_elements = 0

The total number of elements in the tensor.

SushiRuntime::sushi_ptr< Storage > storage

A pointer to the memory storage where the actual data is kept.

int64_t storage_offset = 0

Holds where the first element sits inside the storage, in elements.

See also

include/SushiBLAS/README.md

Public member functions

Tensor()=default

Default constructor for an empty tensor.

Tensor(SushiRuntime::sushi_ptr< Storage > s, SushiRuntime::span< const int64_t > dims, Core::DataType d=Core::DataType::FLOAT32, int64_t offset=0, Core::Layout l=Core::Layout::ROW_MAJOR)

Creates a Tensor whose strides derive from its dimensions and layout.

Parameters

offset

The starting position in the storage, in elements.

l

Orders the memory within one matrix; batch axes stay outermost.

Exceptions

std::runtime_error

on a rank too high, a negative dimension, an overflowing size, or a storage too small.

Tensor(SushiRuntime::sushi_ptr< Storage > s, SushiRuntime::span< const int64_t > dims, const std::array< int64_t, SushiBLAS::Core::MAX_TENSOR_RANK > &strides_in, Core::DataType d, int64_t offset, Core::Layout l)

Creates a Tensor view whose strides are given instead of derived from its shape.

Parameters

strides_in

The stride of each dimension, in elements; none within the rank may be negative.

offset

The starting position in the storage, in elements.

Exceptions

std::runtime_error

on a rank too high, a negative dimension or stride, an overflowing size, or elements past the end of s.

See also

include/SushiBLAS/README.md

Tensor(SushiRuntime::sushi_ptr< Storage > s, std::initializer_list< int64_t > dims, Core::DataType d=Core::DataType::FLOAT32, int64_t offset=0, Core::Layout l=Core::Layout::ROW_MAJOR)

Creates a Tensor from an initializer list of dimensions.

sycl::device get_device() const

Get the hardware device (GPU/CPU) where this tensor lives.

Returns

The SYCL device object.

void * data()

Returns a pointer to the first element, storage_offset elements past the allocation base.

Exceptions

std::runtime_error

if the tensor has no storage.

See also

include/SushiBLAS/README.md

const void * data() const

Returns a read-only pointer to the first element, storage_offset elements past the allocation base.

Exceptions

std::runtime_error

if the tensor has no storage.

See also

include/SushiBLAS/README.md

void * data_or_null()

Returns the address of the first element, or nullptr if the tensor has no storage.

See also

include/SushiBLAS/README.md

const void * data_or_null() const

Returns the read-only address of the first element, or nullptr if the tensor has no storage.

See also

include/SushiBLAS/README.md

template <typename T = float>
T * data_as()

Get a pointer to the data cast to a specific type.

Template parameters

T

The type to cast to (default is float).

Returns

A pointer of type T.

template <typename T = float>
const T * data_as() const

Get a read-only pointer to the data cast to a specific type.

Template parameters

T

The type to cast to (default is float).

Returns

A pointer of type const T.

int64_t element_span() const

Returns how many elements the view spans from its first to its last, inclusive.

Returns

The span in elements; 0 for an empty tensor.

See also

include/SushiBLAS/README.md

SushiRuntime::Core::ResourceRegion region() const

Returns the byte interval this view occupies, keyed on the allocation base.

Returns

The region, or an empty base-less region if the tensor has no storage.

See also

include/SushiBLAS/README.md

bool is_contiguous() const

Returns whether the strides match what layout_strides gives for this shape and layout.

See also

include/SushiBLAS/README.md

bool is_aligned() const

Check if the data pointer is correctly aligned for high performance.

Returns

True if aligned, false otherwise.

Tensor transpose(int32_t dim0, int32_t dim1) const

Swap two dimensions of the tensor (e.g., for matrix transpose).

This is a "view" operation; it does not move data in memory.

Parameters

dim0

The first dimension index.

dim1

The second dimension index.

Returns

A new Tensor view with swapped dimensions.

Exceptions

std::runtime_error

if either index is negative or not below the rank.

Tensor reshape(std::initializer_list< int64_t > new_dims) const

Change the shape of the tensor without changing its data.

The tensor must be contiguous for this to work correctly.

Parameters

new_dims

The new dimensions for the tensor.

Returns

A new Tensor view with the new shape.

Tensor reshape(const std::vector< int64_t > &new_dims) const

Returns a view of the same elements under dimensions known only at run time.

Precondition

The tensor is contiguous.

Exceptions

std::runtime_error

on an element count mismatch, a negative dimension or a strided tensor.

Tensor slice(int32_t dim, int64_t start, int64_t end) const

Returns a view that narrows one axis and keeps the parent's strides.

Parameters

start

Inclusive; negative counts back from the end.

end

Exclusive; negative counts back from the end.

Exceptions

std::runtime_error

if dim is not a dimension of this tensor.

See also

include/SushiBLAS/README.md

Static public member functions

static std::array< int64_t, SushiBLAS::Core::MAX_TENSOR_RANK > layout_strides(SushiRuntime::span< const int64_t > dims, Core::Layout l)

Returns the strides a shape implies under a layout.

Returns

The stride of each dimension, in elements; entries past dims.size() are 0.

Exceptions

std::runtime_error

on a rank too high, a negative dimension or an overflowing stride.

See also

include/SushiBLAS/README.md