stream_class.h#

Defines

FIELD_VARINT#
FIELD_FIXED64#
FIELD_FIXED_SIZE#
FIELD_FIXED32#
SERIALIZATION_METHOD()#

Serialization/parsing API declaration macro for generated proto classes.

BEGIN_PROTO(cls, doc)#

Macro for beginning a generated proto class with a default constructor.

BEGIN_PROTO_NOINIT(cls, doc)#

Macro for beginning a generated proto class without adding a default constructor.

END_PROTO()#

Macro for ending a generated proto class and injecting the serialization/parsing API.

FIELD(type, name, order, doc)#
FIELD_DEFAULT(type, name, order, default_value, doc)#
FIELD_STR(name, order, doc)#
FIELD_REPEATED(type, name, order, doc)#
FIELD_REPEATED_STR(type, name, order, doc)#
FIELD_REPEATED_PROTO(type, name, order, doc)#
FIELD_REPEATED_PACKED(type, name, order, doc)#
_FIELD_OPTIONAL(type, name, order, doc)#
FIELD_OPTIONAL(type, name, order, doc)#
FIELD_OPTIONAL_ONEOF(type, name, order, oneof, doc)#
FIELD_OPTIONAL_ENUM(type, name, order, doc)#
namespace ONNX_LIGHT_NAMESPACE

Enums

enum class FileLoadMode : int32_t#

Selects which file-backed BinaryStream implementation is used when parsing a model from a file path (for example via ModelProto::ParseFromFile).

  • kAuto (default): pick the fastest implementation that is compatible with the other options. Today that means MmapFileStream except when no_copy is true with a single-file model — see ParseFromFile for the precise selection rules.

  • kMmap: force usage of MmapFileStream (memory-mapped file).

  • kFileStream: force usage of FileStream (buffered std::ifstream).

Values:

enumerator kAuto#
enumerator kMmap#
enumerator kFileStream#

Functions

template<typename T>
inline bool _has_field_(const T&)#

Returns true if the field holds a non-default value (always true for scalar types other than String and raw-bytes vectors, which have their own specializations).

template<>
inline bool _has_field_(const utils::String &field)#

Returns true if the string field is non-empty.

template<>
inline bool _has_field_(const std::vector<uint8_t> &field)#

Returns true if the raw-bytes field is non-empty.

template<>
inline bool _has_field_(const utils::ByteSpan &field)#

Returns true if the ByteSpan field is non-empty (owned or borrowed).

template<typename T>
void CopyProtoFrom(T &dest, const T &src)#

Copies all fields from src into dest. Generated for every proto class.

class Message#
#include <stream_class.h>

Base class for generated ONNX proto messages.

Public Functions

inline explicit Message()#

Constructs an empty message base object.

inline bool operator==(const Message&) const#

Throws an exception as a placeholder; generated classes provide their own operator==.

struct ParseOptions : public ONNX_LIGHT_NAMESPACE::TensorBufferOptions#
#include <stream_class.h>

Controls behavior when parsing ONNX protobuf messages from a stream or string.

Public Functions

inline ParseOptions()#

Constructs a ParseOptions instance with the default raw_data_threshold of 1024 bytes.

inline bool is_parallel() const#

Returns true when parallel reading should be enabled, i.e. when num_threads is greater than 1 or negative. num_threads == 0 and num_threads == 1 both disable parallelization.

Public Members

bool skip_raw_data = false#

if true, raw data will not be read but skipped, tensors are not valid in that case but the model structure is still available

int32_t num_threads = 1#

Number of threads to use for parallel reading of big blocks.

  • 1 (default): no parallelization, everything runs on the calling thread.

  • > 1: use exactly this many worker threads.

  • < 0: choose a sensible value based on the number of available CPU cores (std::thread::hardware_concurrency()).

  • 0: treated the same as 1 (no parallelization) for the purposes of :cpp:func:is_parallel.

int64_t min_parallel_block_size = 0#

minimum raw-data block size in bytes to submit to the thread pool when parallel reading is enabled (num_threads != 1); blocks smaller than this value are read on the main thread to avoid thread-pool overhead

bool no_copy = false#

If true, raw_data blocks are not copied into a new buffer. Inline protobuf raw_data borrows directly from the source bytes buffer (for example the bytes passed to ParseFromString), so the caller MUST keep that buffer alive for as long as any TensorProto references it. For external-data files, onnx-light loads each weights file once into a shared model-owned buffer and each tensor borrows a view into that buffer.

bool _touch_raw_data_pages = false#

If true, parses all tensors normally and then touches one byte per memory page in each non-empty raw_data buffer (plus the last byte). This forces lazy page faults (for example mmap-backed no-copy buffers) to occur within the parse timing window.

FileLoadMode file_load_mode = FileLoadMode::kAuto#

Selects the file-backed BinaryStream implementation used when parsing a model from a file path (e.g. ModelProto::ParseFromFile). See FileLoadMode for the semantics of each value. Ignored when parsing from bytes/streams.

struct SerializeOptions : public ONNX_LIGHT_NAMESPACE::TensorBufferOptions#
#include <stream_class.h>

Controls behavior when serializing ONNX protobuf messages to a stream or string.

Public Functions

inline SerializeOptions()#

Constructs a SerializeOptions instance with the default raw_data_threshold.

inline bool is_parallel() const#

Returns true when parallel writing should be enabled, i.e. when num_threads is greater than 1 or negative. num_threads == 0 and num_threads == 1 both disable parallelization.

Public Members

bool skip_raw_data = false#

if true, raw data will not be written but skipped, tensors are not valid in that case but the model structure is still available

int32_t num_threads = 1#

Number of threads to use for parallel writing of big blocks.

  • 1 (default): no parallelization, everything runs on the calling thread.

  • > 1: use exactly this many worker threads.

  • < 0: choose a sensible value based on the number of available CPU cores (std::thread::hardware_concurrency()).

  • 0: treated the same as 1 (no parallelization) for the purposes of :cpp:func:is_parallel.

int64_t min_parallel_block_size = 0#

minimum raw-data block size in bytes to submit to the thread pool when parallel writing is enabled (num_threads != 1); blocks smaller than this value are written on the main thread to avoid thread-pool overhead

bool use_external_data_location = true#

if true, tensors already marked with data_location=EXTERNAL are serialized using their external_data metadata location (can target multiple weights files).

int64_t max_external_file_size = 0#

maximum size in bytes for one external weights file when saving with external data; 0 means no limit (single weights file)

struct TensorBufferOptions#
#include <stream_class.h>

Common options shared by tensor buffer operations: in-place consolidation (ConsolidateTensorsToBuffer), serialization (SerializeOptions) and parsing (ParseOptions).

Subclassed by ONNX_LIGHT_NAMESPACE::ParseOptions, ONNX_LIGHT_NAMESPACE::SerializeOptions

Public Members

int64_t raw_data_threshold = kSmallTensorDataThresholdBytes#

Specifies the minimum raw_data size (in bytes) to include in buffer operations. Tensors whose raw_data is smaller than this threshold are left in-place.

int64_t alignment = 0#

Controls the alignment boundary for tensor offsets within the buffer. If > 0, each tensor’s offset is padded to a multiple of this many bytes. 0 disables alignment. Use 4096 for mmap-friendly page-aligned offsets.