tiny.accy.tensor.interpret
Defined in tensor.
API (23)
Actions
Public operations.
BindContextFinishContextGraph.bindGraph.builderHandleGraph.finishGraph.operationLayerLeafBindContextSemanticsStackStepWithargumentsbindlayerresultrunsemanticsstackwith
Types and contracts
Public types and contracts.
Source
Source: lib/accy/src/tensor/interpret/graph.zig:5
pub const Graph = struct { builder: *trace.Builder, pub const Value: type = trace.Value; pub const Result: type = program_mod.Program; pub fn operation(self: *@This(), step: *step_mod.Step(Value)) !Value { var buffer: [program_mod.max_operation_operands]Value = undefined; return self.bind(step.op, step_mod.arguments(Value, step.op, step.values, &buffer)); } pub fn bind(self: *@This(), op: *const program_mod.Operation, args: []const Value) !Value { return self.builder.operation(op, args); } pub fn finish(self: *@This(), outputs: []const Value) !Result { return self.builder.finish(outputs); } pub fn builderHandle(self: *@This()) *trace.Builder { return self.builder; }};Source: lib/accy/src/tensor/interpret/context.zig:11
pub fn BindContext(comptime BoundValue: type, comptime Handle: type) type { return struct { next: Handle, op: *const program_mod.Operation, args: []const BoundValue, pub fn default(self: *@This()) !BoundValue { return self.next.bind(self.op, self.args); } pub fn arg(self: *@This(), index: usize) BoundValue { return self.args[index]; } pub fn builderHandle(self: *@This()) *trace.Builder { return self.next.builderHandle(); } };}Source: lib/accy/src/tensor/interpret/context.zig:31
pub fn FinishContext(comptime BoundValue: type, comptime Handle: type) type { return struct { next: Handle, pub fn default(self: *@This(), outputs: []const BoundValue) !pointerChild(Handle).Result { return self.next.finish(outputs); } pub fn builderHandle(self: *@This()) *trace.Builder { return self.next.builderHandle(); } };}Source: lib/accy/src/tensor/interpret/context.zig:45
pub fn LeafBindContext(comptime BoundValue: type) type { return struct { op: *const program_mod.Operation, args: []const BoundValue, pub fn arg(self: *@This(), index: usize) BoundValue { return self.args[index]; } };}Source: lib/accy/src/tensor/interpret/execute.zig:38
pub fn result(comptime Initial: type) type { if (comptime @hasDecl(Initial, "attach")) return @TypeOf(@as(Initial, undefined).attach(@as(graph_mod.Graph, undefined))).Result; return Normalized(Initial).Result;}Source: lib/accy/src/tensor/interpret/execute.zig:8
pub fn run( allocator: std.mem.Allocator, source: *const program_mod.Program, initial: anytype,) !result(@TypeOf(initial)) { var state = normalize(initial); const State = @TypeOf(state); const Value = State.Value; const values = try allocator.alloc(Value, source.valueCount()); defer allocator.free(values); for (source.operations) |*op| { var step = step_mod.Step(Value){ .source = source, .values = values, .op = op, }; values[op.id.index] = try state.operation(&step); } const outputs = try allocator.alloc(Value, source.outputs.len); defer allocator.free(outputs); for (source.outputs, 0..) |id, index| { outputs[index] = values[id.index]; } return try state.finish(outputs);}Source: lib/accy/src/tensor/interpret/leaf.zig:11
pub fn Semantics(comptime BoundValue: type, comptime Impl: type) type { return struct { impl: Impl, pub const Value: type = BoundValue; pub const Result: type = Impl.Result; pub fn operation(self: *@This(), step: *step_mod.Step(Value)) !Value { var buffer: [program_mod.max_operation_operands]Value = undefined; return self.bind(step.op, step_mod.arguments(Value, step.op, step.values, &buffer)); } pub fn bind(self: *@This(), op: *const program_mod.Operation, args: []const Value) !Value { if (comptime @hasDecl(Impl, "bind")) { return self.impl.bind(op, args); } var ctx = context.LeafBindContext(Value){ .op = op, .args = args, }; if (try dispatch.primitive(Value, &self.impl, &ctx)) |value| return value; if (comptime @hasDecl(Impl, "default")) return self.impl.default(&ctx); @compileError("tensor leaf semantics without bind must provide primitive handlers and default"); } pub fn finish(self: *@This(), outputs: []const Value) !Result { return self.impl.finish(outputs); } pub fn builderHandle(self: *@This()) *trace.Builder { return self.impl.builderHandle(); } };}Source: lib/accy/src/tensor/interpret/leaf.zig:7
pub fn semantics(comptime BoundValue: type, impl: anytype) Semantics(BoundValue, @TypeOf(impl)) { return .{ .impl = impl };}Source: lib/accy/src/tensor/interpret/spec.zig:46
pub fn Layer(comptime BoundValue: type, comptime Next: type, comptime Impl: type) type { return dispatch.Layer(BoundValue, Next, Impl);}Source: lib/accy/src/tensor/interpret/spec.zig:28
pub fn Stack(comptime Specs: type) type { _ = stackLength(Specs); return struct { specs: Specs, pub fn attach(self: @This(), next: anytype) StackAttach(0, Specs, @TypeOf(next)) { return attachFrom(0, self.specs, next); } };}Source: lib/accy/src/tensor/interpret/spec.zig:11
pub fn With(comptime Impl: type) type { return struct { impl: Impl, pub fn attach(self: @This(), next: anytype) Layer(stateValue(@TypeOf(next)), @TypeOf(next), Impl) { return .{ .next = next, .impl = self.impl, }; } };}Source: lib/accy/src/tensor/interpret/spec.zig:7
pub fn bind(impl: anytype) With(@TypeOf(impl)) { return with(impl);}Source: lib/accy/src/tensor/interpret/spec.zig:39
pub fn layer(comptime BoundValue: type, next: anytype, impl: anytype) Layer(BoundValue, @TypeOf(next), @TypeOf(impl)) { return .{ .next = next, .impl = impl, };}Source: lib/accy/src/tensor/interpret/spec.zig:24
pub fn stack(specs: anytype) Stack(@TypeOf(specs)) { return .{ .specs = specs };}Source: lib/accy/src/tensor/interpret/spec.zig:3
pub fn with(impl: anytype) With(@TypeOf(impl)) { return .{ .impl = impl };}Source: lib/accy/src/tensor/interpret/step.zig:3
pub fn Step(comptime Value: type) type { return struct { source: *const program_mod.Program, values: []const Value, op: *const program_mod.Operation, pub fn read(self: @This(), id: program_mod.Id) Value { return self.values[id.index]; } pub fn typeOf(self: @This(), id: program_mod.Id) program_mod.Type { return self.source.typeOf(id); } };}Source: lib/accy/src/tensor/interpret/step.zig:19
pub fn arguments(comptime Value: type, op: *const program_mod.Operation, values: []const Value, buffer: *[program_mod.max_operation_operands]Value) []const Value { return switch (op.kind) { .parameter, .constant, .iota => buffer[0..0], .unary => |unary| blk: { buffer[0] = values[unary.input.index]; break :blk buffer[0..1]; }, .binary => |binary| blk: { buffer[0] = values[binary.lhs.index]; buffer[1] = values[binary.rhs.index]; break :blk buffer[0..2]; }, .broadcast => |broadcast| blk: { buffer[0] = values[broadcast.input.index]; break :blk buffer[0..1]; }, .broadcast_in_dim => |broadcast| blk: { buffer[0] = values[broadcast.input.index]; break :blk buffer[0..1]; }, .reshape => |reshape| blk: { buffer[0] = values[reshape.input.index]; break :blk buffer[0..1]; }, .transpose => |transpose| blk: { buffer[0] = values[transpose.input.index]; break :blk buffer[0..1]; }, .reduce => |reduce| blk: { buffer[0] = values[reduce.input.index]; buffer[1] = values[reduce.init.index]; break :blk buffer[0..2]; }, .gather => |gather| blk: { buffer[0] = values[gather.input.index]; buffer[1] = values[gather.indices.index]; break :blk buffer[0..2]; }, .scatter_add => |scatter_add| blk: { buffer[0] = values[scatter_add.input.index]; buffer[1] = values[scatter_add.indices.index]; buffer[2] = values[scatter_add.updates.index]; break :blk buffer[0..3]; }, .sparse_cross_entropy => |sparse_cross_entropy| blk: { buffer[0] = values[sparse_cross_entropy.logits.index]; buffer[1] = values[sparse_cross_entropy.targets.index]; break :blk buffer[0..2]; }, .dot_general => |dot| blk: { buffer[0] = values[dot.lhs.index]; buffer[1] = values[dot.rhs.index]; break :blk buffer[0..2]; }, .compare => |compare| blk: { buffer[0] = values[compare.lhs.index]; buffer[1] = values[compare.rhs.index]; break :blk buffer[0..2]; }, .select => |select| blk: { buffer[0] = values[select.pred.index]; buffer[1] = values[select.on_true.index]; buffer[2] = values[select.on_false.index]; break :blk buffer[0..3]; }, .custom_call => |custom| blk: { for (custom.operands, 0..) |operand, index| buffer[index] = values[operand.index]; break :blk buffer[0..custom.operands.len]; }, .scan => |scan| blk: { for (scan.inits, 0..) |init, index| buffer[index] = values[init.index]; break :blk buffer[0..scan.inits.len]; }, .projection => |projection| blk: { buffer[0] = values[projection.source.index]; break :blk buffer[0..1]; }, };}Source: lib/accy/src/tensor/interpret/root.zig
const context_mod = @import("context.zig");const execute = @import("execute.zig");const graph_mod = @import("graph.zig");const leaf = @import("leaf.zig");const spec = @import("spec.zig");const step_mod = @import("step.zig");pub const Step = step_mod.Step;pub const arguments = step_mod.arguments;pub const Graph = graph_mod.Graph;pub const Semantics = leaf.Semantics;pub const BindContext = context_mod.BindContext;pub const FinishContext = context_mod.FinishContext;pub const LeafBindContext = context_mod.LeafBindContext;pub const With = spec.With;pub const Stack = spec.Stack;pub const Layer = spec.Layer;pub const semantics = leaf.semantics;pub const with = spec.with;pub const bind = spec.bind;pub const stack = spec.stack;pub const layer = spec.layer;pub const run = execute.run;pub const result = execute.result;Source: lib/accy/src/tensor/root.zig:4
pub const interpret = @import("interpret/root.zig");Audit
| Definitions | 24 |
|---|---|
| Public names | 24 |
| Members | 1 |
| Version | 26.7.0 |
| Revision | daab053ee433 |