Expand description
Tensor descriptor — binary encoding and decoding.
The TensorDescriptor type is the top-level carrier for all metadata
required to interpret a tensor’s data buffer: element type, rank, shape,
memory layout, buffer handles, and optional quantization, shard, statistics,
and extension-type annotations.
§Wire format
Defined in docs/spec/metadata.md. Fixed header (20 bytes) followed by
variable-length core fields, layout-specific payload, buffer table, and
up to four optional sections selected by the flags bitmask.
§Examples
use hurray_core::{
BufferHandle, DeviceTag, ElementType, Shape, SyncMode, MIN_BUFFER_ALIGNMENT,
descriptor::TensorDescriptor,
layout::LayoutDescriptor,
};
// Build a float32 [3, 4] row-major tensor descriptor (the spec's worked example).
let shape = Shape::new(vec![3, 4]).unwrap();
let buffer = BufferHandle::new(192, MIN_BUFFER_ALIGNMENT, DeviceTag::Cpu, SyncMode::ProducerSynced).unwrap();
let desc = TensorDescriptor::new(
1, 0,
ElementType::Float32,
shape,
0,
LayoutDescriptor::RowMajor,
vec![buffer],
None, None, None, None,
).unwrap();
let encoded = desc.encode().unwrap();
assert_eq!(encoded.len(), 61); // spec worked example is 61 bytes
let decoded = TensorDescriptor::decode(&encoded).unwrap();
assert_eq!(decoded, desc);Re-exports§
pub use composite_member::CompositeMemberDescriptor;pub use composite_member::MemberRole;pub use ext_type::ExtensionTypeDescriptor;pub use shard::ShardDescriptor;pub use statistics::Statistics;pub use statistics::StatisticsMask;
Modules§
- composite_
member - Composite Member section — binary encode/decode.
- ext_
type - Extension type descriptor — binary encode/decode.
- layout_
codec - Per-layout-tag encode/decode dispatch for the layout-specific fields section.
- shard
- Shard descriptor — binary encode/decode.
- statistics
- Statistics section — binary encode/decode.
Structs§
- Descriptor
Flags - Descriptor flags bitmask (wire field
flags, offset 10 in the fixed header). - Tensor
Descriptor - The top-level tensor descriptor carrying all metadata required to interpret a tensor’s data buffer.
Constants§
- DESCRIPTOR_
VERSION_ MAJOR - Current major version of the descriptor format.
- DESCRIPTOR_
VERSION_ MINOR - Current minor version of the descriptor format.
- MAGIC
- Magic bytes that open every Hurray tensor descriptor: ASCII
"HRRY".