Contents

class

SushiBLAS::IO

Input/Output operations for Tensors.

Declared in
include/SushiBLAS/io.hpp

This class provides methods to save, load, and display tensors. It supports both native .sushi formats and NumPy .npy exports for interoperability.

Public member functions

explicit IO(Engine &e)

Construct a new IO object.

Parameters

e

Reference to the parent Engine.

void save(const Tensor &t, const std::string &path)

Save tensor in the native .sushi format.

This includes a header with metadata (shape, dtype) followed by raw data.

Parameters

t

The tensor to save; stored and contiguous.

path

The filesystem path to save the file to.

Exceptions

std::invalid_argument

when t is strided or has no storage.

std::runtime_error

when a write fails; the partial file is removed.

void load(Tensor &t, const std::string &path)

Load a .sushi file into a tensor.

Runs the recorded graph first, then verifies that the file metadata matches the tensor.

Parameters

t

The target tensor to load data into.

path

The filesystem path of the .sushi file.

void read(const Tensor &t, void *dst, size_t bytes)

Runs the recorded graph, then copies the tensor's elements into host memory.

Parameters

t

A stored, contiguous tensor; any residency.

bytes

Must equal num_elements times the dtype's element size.

Exceptions

std::invalid_argument

when t breaks those rules or bytes differs.

void write(Tensor &t, const void *src, size_t bytes)

Runs the recorded graph, then copies host memory into the tensor's elements.

Parameters

t

A stored, contiguous tensor; any residency.

bytes

Must equal num_elements times the dtype's element size.

Exceptions

std::invalid_argument

when t breaks those rules or bytes differs.

template <typename T>
std::vector< T > to_vector(const Tensor &t)

Returns the tensor's elements as a host vector, after running the graph.

Template parameters

T

The host type matching t.dtype (see Detail::HostDataType).

Exceptions

std::invalid_argument

when t's dtype is not T's, or read() rejects t.

template <typename T>
void from_vector(Tensor &t, const std::vector< T > &values)

Copies a host vector into the tensor's elements, after running the graph.

Template parameters

T

The host type matching t.dtype (see Detail::HostDataType).

Exceptions

std::invalid_argument

when t's dtype is not T's, the sizes differ, or write() rejects t.

void save_npy(const Tensor &t, const std::string &path)

Save tensor in NumPy .npy format.

This allows the tensor to be loaded directly in Python using np.load().

Parameters

t

The tensor to export; stored, contiguous, and not COLUMN_MAJOR at rank 3 or more.

path

The filesystem path to save the .npy file.

Exceptions

std::invalid_argument

when t breaks one of those rules.

std::runtime_error

when a write fails; the partial file is removed.

void load_npy(Tensor &t, const std::string &path)

Runs the recorded graph, then loads a .npy file of version 1.0, 2.0 or 3.0.

The header's descr, fortran_order and shape must match the tensor exactly.

Parameters

t

A stored, contiguous tensor, not COLUMN_MAJOR at rank 3 or more.

Exceptions

std::invalid_argument

when t breaks one of those rules.

std::runtime_error

on another version, a malformed header or a mismatch.

See also

include/SushiBLAS/README.md

void save_bin(const Tensor &t, const std::string &path)

Raw binary save (no header).

Parameters

t

The tensor to save; stored and contiguous.

path

The filesystem path for the binary file.

Exceptions

std::runtime_error

when a write fails; the partial file is removed.

void load_bin(Tensor &t, const std::string &path)

Raw binary load (no header), after running the recorded graph.

Parameters

t

The target tensor to load data into.

path

The filesystem path of the binary file.

void print(const Tensor &t, int precision=4, int edge_items=3)

Print tensor content to the console in a readable format.

Parameters

t

The tensor to print.

precision

Number of decimal places for numeric display.

edge_items

Number of items to show at the edges of each dimension.

std::string to_string(const Tensor &t, int precision=4, int edge_items=3)

Returns the tensor's content as a string in the format print() uses.

Parameters

t

Any stored view; its elements are read through its strides.

precision

Number of decimal places for numeric display.

edge_items

Number of items shown at the edges of each dimension.