Mila
Deep Neural Network Library
Loading...
Searching...
No Matches
Tensor.Serialization.ixx File Reference

Tensor-specific serialization helpers and metadata. More...

#include <string>
#include <cstddef>
#include <stdexcept>
#include <utility>
import Compute.CpuMemoryResource;
import Dnn.TensorBuffer;
import Dnn.TensorTypes;
import Dnn.TensorDataTypeTraits;
import Dnn.TensorDataType;
import Serialization.Metadata;
import Serialization.ModelArchive;

Classes

struct  Mila::Dnn::Serialization::ITensorBlob
 Type-erased interface for a serialized tensor blob. More...
struct  Mila::Dnn::Serialization::TensorBlob< MR >
 Concrete tensor blob owning a TensorBuffer-backed raw byte buffer. More...
struct  Mila::Dnn::Serialization::TensorBlobView
 Non-owning ITensorBlob view over externally-owned bytes. More...
 Metadata describing a tensor in serialized form. More...

Namespaces

namespace  Mila
 Mila main API namespace.

Functions

template<typename MR = Compute::CpuMemoryResource>
requires isValidTensor<dtype_t::UINT8, MR>
TensorBlob< MR > Mila::Dnn::Serialization::readTensorBlob (const ModelArchive &archive, const std::string &prefix, int device_id=0)
 Read tensor metadata and raw bytes from prefix into a typed blob.
void Mila::Dnn::Serialization::writeTensorBlob (ModelArchive &archive, const std::string &prefix, const TensorMetadata &meta, const void *data, size_t size)
 Write tensor metadata and raw bytes under the given prefix into archive.

Detailed Description

Tensor-specific serialization helpers and metadata.

Provides TensorMetadata, ITensorBlob, and free helpers to write/read tensor metadata + raw bytes using ModelArchive. This partition keeps tensor concerns out of ModelArchive and lets tensor implementations call these helpers.

Function Documentation

◆ readTensorBlob()

template<typename MR = Compute::CpuMemoryResource>
requires isValidTensor<dtype_t::UINT8, MR>
TensorBlob< MR > Mila::Dnn::Serialization::readTensorBlob ( const ModelArchive & archive,
const std::string & prefix,
int device_id = 0 )
export

Read tensor metadata and raw bytes from prefix into a typed blob.

Allocates a TensorBuffer<UINT8, MR> sized to total_bytes and reads directly into it via readBlobInto – no intermediate vector copy. When MR is CudaPinnedMemoryResource the returned blob carries a pinned host pointer ready for direct DMA in copyFromBlob.

Template Parameters
MRMemory resource for the blob data buffer. Defaults to CpuMemoryResource.
Parameters
archiveModelArchive to read from
prefixPath prefix for tensor files (e.g., "tensors/weight")
device_idDevice index passed to the memory resource constructor.
Returns
TensorBlob<MR> owning the metadata and raw byte buffer.
Exceptions
std::runtime_errorif read operations fail or size mismatch detected

◆ writeTensorBlob()

void Mila::Dnn::Serialization::writeTensorBlob ( ModelArchive & archive,
const std::string & prefix,
const TensorMetadata & meta,
const void * data,
size_t size )
inlineexport

Write tensor metadata and raw bytes under the given prefix into archive.

Writes: prefix + "/meta.json" – TensorMetadata as SerializationMetadata prefix + "/data.bin" – raw tensor bytes

Parameters
archiveModelArchive to write to
prefixPath prefix for tensor files (e.g., "tensors/weight")
metaTensor metadata
dataPointer to raw tensor bytes
sizeNumber of bytes to write
Exceptions
std::runtime_errorif write operations fail