|
Mila
Deep Neural Network Library
|
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... | |
| struct | Mila::Dnn::Serialization::TensorMetadata |
| 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. | |
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.
|
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.
| MR | Memory resource for the blob data buffer. Defaults to CpuMemoryResource. |
| archive | ModelArchive to read from |
| prefix | Path prefix for tensor files (e.g., "tensors/weight") |
| device_id | Device index passed to the memory resource constructor. |
| std::runtime_error | if read operations fail or size mismatch detected |
|
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
| archive | ModelArchive to write to |
| prefix | Path prefix for tensor files (e.g., "tensors/weight") |
| meta | Tensor metadata |
| data | Pointer to raw tensor bytes |
| size | Number of bytes to write |
| std::runtime_error | if write operations fail |