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 = 0The number of dimensions in the tensor (e.g., 2 for a matrix).
SushiBLAS::Core::DataType dtype = SushiBLAS::Core::DataType::FLOAT32The type of data stored in the tensor (e.g., FLOAT32).
SushiBLAS::Core::Layout layout = SushiBLAS::Core::Layout::ROW_MAJORHow the data is arranged in memory (ROW_MAJOR or COLUMN_MAJOR).
int64_t num_elements = 0The total number of elements in the tensor.
SushiRuntime::sushi_ptr< Storage > storageA pointer to the memory storage where the actual data is kept.
int64_t storage_offset = 0Holds where the first element sits inside the storage, in elements.
See also
include/SushiBLAS/README.md
Public member functions
Tensor()=defaultDefault 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
offsetThe starting position in the storage, in elements.
lOrders the memory within one matrix; batch axes stay outermost.
Exceptions
std::runtime_erroron 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_inThe stride of each dimension, in elements; none within the rank may be negative.
offsetThe starting position in the storage, in elements.
Exceptions
std::runtime_erroron 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() constGet 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_errorif the tensor has no storage.
See also
include/SushiBLAS/README.md
const void * data() constReturns a read-only pointer to the first element, storage_offset elements past the allocation base.
Exceptions
std::runtime_errorif 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() constReturns 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
TThe type to cast to (default is float).
Returns
A pointer of type T.
template <typename T = float>
const T * data_as() constGet a read-only pointer to the data cast to a specific type.
Template parameters
TThe type to cast to (default is float).
Returns
A pointer of type const T.
int64_t element_span() constReturns 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() constReturns 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() constReturns whether the strides match what layout_strides gives for this shape and layout.
See also
include/SushiBLAS/README.md
bool is_aligned() constCheck if the data pointer is correctly aligned for high performance.
Returns
True if aligned, false otherwise.
Tensor transpose(int32_t dim0, int32_t dim1) constSwap two dimensions of the tensor (e.g., for matrix transpose).
This is a "view" operation; it does not move data in memory.
Parameters
dim0The first dimension index.
dim1The second dimension index.
Returns
A new Tensor view with swapped dimensions.
Exceptions
std::runtime_errorif either index is negative or not below the rank.
Tensor reshape(std::initializer_list< int64_t > new_dims) constChange the shape of the tensor without changing its data.
The tensor must be contiguous for this to work correctly.
Parameters
new_dimsThe new dimensions for the tensor.
Returns
A new Tensor view with the new shape.
Tensor reshape(const std::vector< int64_t > &new_dims) constReturns a view of the same elements under dimensions known only at run time.
Precondition
The tensor is contiguous.
Exceptions
std::runtime_erroron an element count mismatch, a negative dimension or a strided tensor.
Tensor slice(int32_t dim, int64_t start, int64_t end) constReturns a view that narrows one axis and keeps the parent's strides.
Parameters
startInclusive; negative counts back from the end.
endExclusive; negative counts back from the end.
Exceptions
std::runtime_errorif 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_erroron a rank too high, a negative dimension or an overflowing stride.
See also
include/SushiBLAS/README.md

