tiny.accy.tensor.wire
Defined in tensor.
A way to write a tensor program as bytes and read it back, for hosts outside this process.
API (7)
Actions
Public operations.
decode: A caller uses this function to rebuild a tensor program from wire bytes, the versioned byte encoding of a tensor program, sent by another process.encode: A caller uses this to send a tensor program to another process, so the function writesprogramas version 1 bytes, which the caller owns.
Types and contracts
Public types and contracts.
Error: A caller matches on these to tell why a program failed to encode or decode, so the set lists the wire failures other than bytes that end early or run past the program: a wrong magic number, another version, an unknown code, a reference to a missing value, too many operands and scans nested too deep.
Namespaces
Public namespaces.
format: Layout, version 1, of a tensor program written as bytes, shared by the encoder and the decoder.
Values and defaults
Public values and defaults.
magic: A reader checks these four bytes first to tell wire bytes, the versioned byte encoding of a tensor program, from other data: the value is the four bytes "ACTP" read as a little-endian 32-bit number.max_scan_depth: A caller relies on this bound when building programs for transfer with nested scans that repeat a body graph: a program may nest scans inside scan bodies at most eight levels deep.version: A writer and a reader agree on the layout through this number: the current layout is version 1.
Source
Source: lib/accy/src/tensor/wire/decode.zig:31
zig
/// A caller uses this function to rebuild a tensor program from wire bytes, the versioned byte/// encoding of a tensor program, sent by another process. The function reads version 1 bytes and/// replays each operation through `Builder.operation` on the program builder, the object that/// builds a program one checked operation at a time, which works out every result type again and/// checks it, so the bytes never supply a result type the builder did not derive. Bytes that end/// early or carry anything after the program return `error.InvalidArtifact`. A wrong magic number/// returns `error.BadMagic` and another version returns `error.UnsupportedVersion`. The caller owns/// the returned program and frees it with `Program.deinit`. The builder copies names and payloads/// into the program's own memory, so the caller may free `bytes` as soon as the call returns.pub fn decode(allocator: std.mem.Allocator, bytes: []const u8) !Program { var decoder = Decoder{ .allocator = allocator, .reader = .{ .bytes = bytes } }; defer decoder.deinit(); if (try decoder.reader.readU32() != format.magic) return error.BadMagic; if (try decoder.reader.readU32() != format.version) return error.UnsupportedVersion; const name = try decoder.reader.readLengthPrefixedBytes(); try decoder.open(name, .{}); for (0..bytes.len) |_| { const frame = &decoder.frames[decoder.count - 1]; if (frame.remaining != 0) { frame.remaining -= 1; try decoder.operation(frame); } else if (decoder.count == 1) { return decoder.finish(frame); } else { try decoder.close(); } } unreachable;}Source: lib/accy/src/tensor/wire/encode.zig:28
zig
/// A caller uses this to send a tensor program to another process, so the function writes `program`/// as version 1 bytes, which the caller owns. The call returns `error.InvalidProgram` unless the/// operation ids run densely from zero and the parameter operations appear in parameter order, and/// every program made by the program builder meets both. The program builder is the tracer that/// appends one operation at a time and checks each result type as it goes. The call returns/// `error.ScanTooDeep` when scans nest deeper than eight levels and `error.InvalidArtifact` when a/// list or string is longer than a 32-bit count can hold.pub fn encode(allocator: std.mem.Allocator, program: *const Program) ![]u8 { var sink = Sink{ .allocator = allocator }; errdefer sink.writer.deinit(allocator); try sink.word(format.magic); try sink.word(format.version); try sink.bytes(program.name); var frames: [format.max_scan_depth + 1]Frame = undefined; frames[0] = .{ .graph = .{ .values = program.values, .operations = program.operations, .parameters = program.parameters, .outputs = program.outputs, } }; var count: usize = 1; try sink.graph(frames[0].graph); while (count != 0) { const frame = &frames[count - 1]; std.debug.assert(frame.next <= frame.graph.operations.len); if (frame.next == frame.graph.operations.len) { try sink.idList(frame.graph.outputs); count -= 1; continue; } const op = frame.graph.operations[frame.next]; frame.next += 1; try sink.operation(op); if (op.kind != .scan) continue; if (count > format.max_scan_depth) return error.ScanTooDeep; frames[count] = .{ .graph = op.kind.scan.body.* }; count += 1; std.debug.assert(count <= frames.len); try sink.graph(op.kind.scan.body.*); } return sink.writer.toOwnedSlice(allocator);}Source: lib/accy/src/tensor/root.zig:17
zig
pub const wire = @import("wire/root.zig");Source: lib/accy/src/tensor/wire/root.zig
zig
//! A way to write a tensor program as bytes and read it back, for hosts outside this process. A//! host has to hand over a program, and this side has to accept only programs that are well typed.//! Any host can send any bytes, and a layout that changes without notice breaks senders built//! against the old one.//!//! Programs travel as versioned bytes (*wire bytes*) that begin with the four bytes "ACTP" and//! version 1. The reader replays every operation through the same checked step that builds a//! program one operation at a time, so the bytes cannot introduce a type that step did not derive.//! The parts are the byte layout (`format`), the encoder (`encode`) and the decoder (`decode`).pub const format = @import("format.zig");pub const magic = format.magic;pub const version = format.version;pub const max_scan_depth = format.max_scan_depth;pub const Error = format.Error;pub const encode = @import("encode.zig").encode;pub const decode = @import("decode.zig").decode;Audit
| Definitions | 3 |
|---|---|
| Public names | 3 |
| Members | 0 |
| Version | 26.7.0 |
| Revision | daab053ee433 |