e5rt

package
v0.6.21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2026 License: MIT Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package e5rt binds the e5rt_* direct dispatch route exported by the private Espresso framework.

The route reaches the Neural Engine without Core ML: build a network description, compile it to the engine's program format, load the compiled program, bind a buffer object to each named I/O port, then encode the loaded program into an execution stream and submit it. Compile and load run once; bind and dispatch run in the hot loop. Compile packages that established single-function route for callers that need host-visible input and output buffers.

Status of this binding

Every symbol named here has been observed to resolve with dlsym against /System/Library/PrivateFrameworks/Espresso.framework/Espresso on macOS 26.x, with a negative control proving the probe can report a miss.

The whole route has now been driven from this package on macOS 26.x: a MIL program compiled, its function retained, buffer objects bound to its ports, and the operation encoded and submitted, with the output matching a float64 CPU reference exactly over 128 elements. Two controls back that up. Perturbing one input element moved the output and the new output matched its own reference, so the engine is reading the bound buffer rather than returning a constant or a stale result; and the compiled bundle records which backend was chosen, which reads ane under a Neural Engine mask and bnns or mps_graph under the other two, so the work is placed on the engine and not silently fallen back. See the e5rtdispatch example.

That covers only the wrappers that route uses. The rest have since been driven too, by TestUnverifiedCalls, which runs each in its own process because two of them abort:

The event family has since been wrapped and driven too. Building the graph works: a completion event binds to an operation, that event binds as a second operation's dependency, and the pair encodes and dispatches correctly, while an operation given its own event is refused. Lib.AsyncEventSignal moves an event to a caller-supplied value; its one-argument predecessor was wrong. Lib.AsyncEventSyncWait has a recovered three-argument shape, but its blocking and timeout behavior have not been driven from this package. Completion events under submit_async are probed separately; use Lib.SubmitAsync's completion function for blocking completion.

A zero status means only that an E5RT entry point accepted the call. It is not, by itself, evidence that the operation had its apparent effect: Lib.PrepareOpForEncode returns zero while making this package's self-created stream unusable. Treat an effect as established only where the wrapper documentation names a control that observed it.

Every name in Symbols now has a wrapper that has been called, save e5rt_e5_compiler_is_new_compile_required, which is listed so the probe reports on it but has no argument list anywhere consulted. Being called is not the same as being understood: Lib.CompilerOptionsSetCustomANECompilerOptions runs and returns zero without any observable effect, and the event family is as described above. A wrapper's doc comment names the evidence behind it and says where that evidence runs out; where it cites only ANEForge, that is outside evidence and nothing more.

Every argument list here came from one of two outside sources, and each doc comment says which:

  • The paper cited below.
  • ANEForge (github.com/sbryngelson/ANEForge), the paper author's own working reference implementation, whose aneforge/_lib/e5rt_api.h carries recovered signatures and aneforge/_lib/ane_e5rt_dispatch.mm drives the whole route. A call site there outranks a declaration, and both outrank the paper.

Where a citation survives it records provenance, which is not the same as evidence. A signature this package has since driven is confirmed by that run, and the doc comment says so; the citation stays only to record where the argument list came from. A signature that has never been exercised, and every claim about behavior that no test here reproduces, has nothing behind it but the citation, and those comments say that too. Read a bare ANEForge reference as the second case unless the comment states an observation.

Symbols this package will not guess at have no typed wrapper; reach them through Lib.Sym or Lib.Lookup and supply your own convention.

Stability

These interfaces are private and undocumented. They require no entitlement, but that means only that the path is reachable from ordinary user space, not that it is supported. Expect it to change across operating-system updates and do not ship it in App Store software.

Performance

The source paper reports (section 6.4) that this unentitled direct path is performance-complete for dispatch: a submission driving several on-engine steps runs at the same rate as the same steps issued one host call at a time, so it reaches the same throughput as any more-privileged path. That claim is the paper's and has not been reproduced here.

Sources: Bryngelson, arXiv:2606.22283, chapter 6; and ANEForge, at github.com/sbryngelson/ANEForge.

Index

Constants

View Source
const (
	ComputeDeviceCPU uint64 = 0x1 // BNNS
	ComputeDeviceGPU uint64 = 0x2 // MPSGraph
	ComputeDeviceANE uint64 = 0x4
)

Compute device bits for Lib.CompilerOptionsSetComputeDeviceTypesMask.

View Source
const FrameworkPath = "/System/Library/PrivateFrameworks/Espresso.framework/Espresso"

FrameworkPath is the Espresso framework the e5rt_* symbols are exported from.

View Source
const MaxPipelineFunctions = 15

MaxPipelineFunctions is the largest number of distinct compiled functions a pipeline stream may contain.

A macOS 26.x stream-retention control measured 15 distinct compiled functions in this process: releasing an encoded operation did not free the next function slot, while releasing its stream did. The pool is shared, so contention can make a smaller pipeline fail.

View Source
const MaxPipelineStages = MaxPipelineFunctions

MaxPipelineStages is kept for source compatibility.

Deprecated: the measured limit is MaxPipelineFunctions. Repeated stages that use the same bundle function do not consume additional function slots.

Variables

View Source
var ErrUnsupported = errors.New("e5rt: unsupported platform")

ErrUnsupported is returned on platforms that do not have Espresso.

View Source
var Symbols = []string{
	"e5rt_e5_compiler_config_options_create",
	"e5rt_e5_compiler_config_options_set_cache_bundle_location",
	"e5rt_e5_compiler_config_options_release",
	"e5rt_e5_compiler_create_with_config",
	"e5rt_e5_compiler_release",
	"e5rt_e5_compiler_options_create",
	"e5rt_e5_compiler_options_set_compute_device_types_mask",
	"e5rt_e5_compiler_options_get_compute_device_types_mask",
	"e5rt_e5_compiler_options_set_force_recompilation",
	"e5rt_e5_compiler_options_set_segmenter",
	"e5rt_e5_compiler_options_set_custom_ane_compiler_options",
	"e5rt_e5_compiler_options_release",
	"e5rt_e5_compiler_compile",
	"e5rt_e5_compiler_is_new_compile_required",
	"e5rt_program_library_create",
	"e5rt_program_library_retain_program_function",
	"e5rt_program_library_release",
	"e5rt_program_function_load_for_execution",
	"e5rt_program_function_release",
	"e5rt_precompiled_compute_op_create_options_create_with_program_function",
	"e5rt_precompiled_compute_op_create_options_set_operation_name",
	"e5rt_precompiled_compute_op_create_options_set_allocate_intermediate_buffers",
	"e5rt_precompiled_compute_op_create_options_release",
	"e5rt_execution_stream_operation_create_precompiled_compute_operation_with_options",
	"e5rt_execution_stream_operation_release",
	"e5rt_buffer_object_alloc",
	"e5rt_buffer_object_get_data_ptr",
	"e5rt_buffer_object_get_size",
	"e5rt_buffer_object_release",
	"e5rt_io_port_bind_buffer_object",
	"e5rt_io_port_release",
	"e5rt_execution_stream_operation_retain_input_port",
	"e5rt_execution_stream_operation_retain_inout_port",
	"e5rt_execution_stream_operation_retain_output_port",
	"e5rt_execution_stream_create",
	"e5rt_execution_stream_operation_prepare_op_for_encode",
	"e5rt_execution_stream_encode_operation",
	"e5rt_execution_stream_execute_sync",
	"e5rt_execution_stream_submit_async",
	"e5rt_execution_stream_reset",
	"e5rt_execution_stream_release",
	"e5rt_execution_stream_set_quality_of_service",
	"e5rt_execution_stream_set_ane_execution_priority",
	"e5rt_async_event_create",
	"e5rt_async_event_release",
	"e5rt_async_event_signal",
	"e5rt_async_event_sync_wait",
	"e5rt_async_event_get_last_signaled_value",
	"e5rt_async_event_get_active_future_value",
	"e5rt_async_event_set_active_future_value",
	"e5rt_execution_stream_operation_bind_completion_event",
	"e5rt_execution_stream_operation_bind_dependent_events",
}

Symbols lists the e5rt_* entry points this package resolves on darwin.

Functions

This section is empty.

Types

type Buffer

type Buffer struct {
	// contains filtered or unexported fields
}

A Buffer is the host-visible storage bound to one Program port.

Bytes remains valid until the Program is closed. Execute serializes with Close, but callers must not read or write Bytes while another goroutine calls Execute.

func (*Buffer) Bytes

func (b *Buffer) Bytes() []byte

Bytes returns the storage bound to the port.

func (*Buffer) ReadFP16

func (b *Buffer) ReadFP16(dst []float32) error

ReadFP16 decodes contiguous little-endian IEEE 754 binary16 values into dst.

func (*Buffer) WriteFP16

func (b *Buffer) WriteFP16(data []float32) error

WriteFP16 stores data as contiguous little-endian IEEE 754 binary16 values.

type BundleOptions

type BundleOptions struct {
	BundlePath string

	FunctionName string
	Inputs       []Port
	Outputs      []Port
}

BundleOptions describes an already-compiled E5RT program bundle.

BundlePath names the bundle returned by the compiler. FunctionName defaults to "main". Inputs and Outputs name the function's externally bound ports.

A bundle is not a portable artifact: E5RT bundle reuse has been observed across processes that share a code-signing identity and a parent on macOS 26.x, and across a restart of the aned daemon. Reuse after a reboot or from an unrelated process is unmeasured, and a bundle roughly a day old has been seen to stop opening; see examples/ane/internal/anedrestart.

type Lib

type Lib struct{}

A Lib is the loaded Espresso framework with its e5rt_* entry points resolved.

func Open

func Open() (*Lib, error)

Open loads the Espresso framework and resolves every name in Symbols.

func (*Lib) AsyncEventActiveFutureValue

func (l *Lib) AsyncEventActiveFutureValue(uintptr) (uint64, error)

AsyncEventActiveFutureValue reports the event's active future value.

func (*Lib) AsyncEventCreate

func (l *Lib) AsyncEventCreate(string) (uintptr, error)

AsyncEventCreate creates a named async event.

func (*Lib) AsyncEventLastSignaledValue

func (l *Lib) AsyncEventLastSignaledValue(uintptr) (uint64, error)

AsyncEventLastSignaledValue reports how many times an event has been signaled.

func (*Lib) AsyncEventRelease

func (l *Lib) AsyncEventRelease(uintptr) error

AsyncEventRelease releases an async event.

func (*Lib) AsyncEventSetActiveFutureValue

func (l *Lib) AsyncEventSetActiveFutureValue(uintptr, uint64) error

AsyncEventSetActiveFutureValue sets the value an event is expected to reach.

func (*Lib) AsyncEventSignal

func (l *Lib) AsyncEventSignal(uintptr, uint64) error

AsyncEventSignal signals an async event from the host.

func (*Lib) AsyncEventSyncWait

func (l *Lib) AsyncEventSyncWait(uintptr, uint64, uint64) error

AsyncEventSyncWait waits for an async event to reach a value.

func (*Lib) BindStatePort

func (l *Lib) BindStatePort(op uintptr, portName string, buf uintptr, lay StateLayout) (uintptr, error)

BindStatePort retains the named inout port of op and binds buf to it, after checking that buf is large enough for lay.

This is Lib.OperationRetainInoutPort followed by Lib.IOPortBindBufferObject with the size check that neither of them performs. The size comes from Lib.BufferObjectGetSize, so the caller does not have to track it alongside the buffer.

On success the returned port is the caller's to release. On any failure nothing is left retained.

The check is one-sided: a buffer larger than the layout requires is accepted, because binding a subregion of a larger allocation is a reasonable thing to do and this package has no way to know it is not intended.

func (*Lib) BufferObjectAlloc

func (l *Lib) BufferObjectAlloc(uintptr, int) (uintptr, error)

BufferObjectAlloc allocates a buffer object.

func (*Lib) BufferObjectGetDataPtr

func (l *Lib) BufferObjectGetDataPtr(uintptr) (uintptr, error)

BufferObjectGetDataPtr returns the host address of a buffer object's storage.

func (*Lib) BufferObjectGetSize

func (l *Lib) BufferObjectGetSize(uintptr) (uintptr, error)

BufferObjectGetSize returns the number of bytes a buffer object holds.

func (*Lib) BufferObjectRelease

func (l *Lib) BufferObjectRelease(uintptr) error

BufferObjectRelease releases a buffer object.

func (*Lib) CompilerCompile

func (l *Lib) CompilerCompile(uintptr, string, uintptr) (uintptr, error)

CompilerCompile compiles the network description at modelPath.

func (*Lib) CompilerConfigOptionsCreate

func (l *Lib) CompilerConfigOptionsCreate() (uintptr, error)

CompilerConfigOptionsCreate creates a compiler configuration.

func (*Lib) CompilerConfigOptionsRelease

func (l *Lib) CompilerConfigOptionsRelease(uintptr) error

CompilerConfigOptionsRelease releases a compiler configuration.

func (*Lib) CompilerConfigOptionsSetCacheBundleLocation

func (l *Lib) CompilerConfigOptionsSetCacheBundleLocation(uintptr, string) error

CompilerConfigOptionsSetCacheBundleLocation sets the compiled-bundle directory.

func (*Lib) CompilerCreateWithConfig

func (l *Lib) CompilerCreateWithConfig(uintptr) (uintptr, error)

CompilerCreateWithConfig creates a compiler from a configuration handle.

func (*Lib) CompilerOptionsCreate

func (l *Lib) CompilerOptionsCreate() (uintptr, error)

CompilerOptionsCreate creates a per-compile options object.

func (*Lib) CompilerOptionsGetComputeDeviceTypesMask

func (l *Lib) CompilerOptionsGetComputeDeviceTypesMask(uintptr) (uint64, error)

CompilerOptionsGetComputeDeviceTypesMask reports the mask set on an options object.

func (*Lib) CompilerOptionsRelease

func (l *Lib) CompilerOptionsRelease(uintptr) error

CompilerOptionsRelease releases a compiler options object.

func (*Lib) CompilerOptionsSetComputeDeviceTypesMask

func (l *Lib) CompilerOptionsSetComputeDeviceTypesMask(uintptr, uint64) error

CompilerOptionsSetComputeDeviceTypesMask selects the backends the compiler may target.

func (*Lib) CompilerOptionsSetCustomANECompilerOptions

func (l *Lib) CompilerOptionsSetCustomANECompilerOptions(uintptr, string) error

CompilerOptionsSetCustomANECompilerOptions passes a string to the Neural Engine compiler.

func (*Lib) CompilerOptionsSetForceRecompilation

func (l *Lib) CompilerOptionsSetForceRecompilation(uintptr, bool) error

CompilerOptionsSetForceRecompilation makes the compiler ignore a cached bundle.

func (*Lib) CompilerOptionsSetSegmenter

func (l *Lib) CompilerOptionsSetSegmenter(uintptr, string) error

CompilerOptionsSetSegmenter selects how the compiler partitions the network.

func (*Lib) CompilerRelease

func (l *Lib) CompilerRelease(uintptr) error

CompilerRelease releases a compiler.

func (*Lib) EncodeOperation

func (l *Lib) EncodeOperation(uintptr, uintptr) error

EncodeOperation encodes a prepared operation into a stream.

func (*Lib) ErrorString

func (l *Lib) ErrorString(Status) (string, error)

ErrorString returns Espresso's static description of status.

func (*Lib) ExecuteSync

func (l *Lib) ExecuteSync(uintptr) error

ExecuteSync submits an encoded stream and blocks until it completes.

func (*Lib) ExecutionStreamCreate

func (l *Lib) ExecutionStreamCreate() (uintptr, error)

ExecutionStreamCreate creates an execution stream.

func (*Lib) ExecutionStreamRelease

func (l *Lib) ExecutionStreamRelease(uintptr) error

ExecutionStreamRelease releases an execution stream.

func (*Lib) ExecutionStreamReset

func (l *Lib) ExecutionStreamReset(uintptr) error

ExecutionStreamReset resets a stream for reuse after execution.

func (*Lib) ExecutionStreamSetANEExecutionPriority

func (l *Lib) ExecutionStreamSetANEExecutionPriority(uintptr, uint64) error

ExecutionStreamSetANEExecutionPriority sets a stream's Neural Engine priority.

func (*Lib) ExecutionStreamSetQualityOfService

func (l *Lib) ExecutionStreamSetQualityOfService(uintptr, uint64) error

ExecutionStreamSetQualityOfService sets a stream's dispatch quality of service.

func (*Lib) IOPortBindBufferObject

func (l *Lib) IOPortBindBufferObject(uintptr, uintptr) error

IOPortBindBufferObject binds a buffer object to a retained I/O port.

func (*Lib) IOPortRelease

func (l *Lib) IOPortRelease(uintptr) error

IOPortRelease releases a retained I/O port from the standalone direct route.

func (*Lib) Lookup

func (l *Lib) Lookup(string) (uintptr, error)

Lookup resolves any exported symbol of the framework by name.

func (*Lib) OperationBindCompletionEvent

func (l *Lib) OperationBindCompletionEvent(uintptr, uintptr) error

OperationBindCompletionEvent binds the event an operation signals when it finishes.

func (*Lib) OperationBindDependentEvents

func (l *Lib) OperationBindDependentEvents(uintptr, []uintptr) error

OperationBindDependentEvents makes an operation wait for the given events.

func (*Lib) OperationCreatePrecompiled

func (l *Lib) OperationCreatePrecompiled(uintptr) (uintptr, error)

OperationCreatePrecompiled creates the executable operation from its options.

func (*Lib) OperationRelease

func (l *Lib) OperationRelease(uintptr) error

OperationRelease releases an operation.

func (*Lib) OperationRetainInoutPort

func (l *Lib) OperationRetainInoutPort(uintptr, string) (uintptr, error)

OperationRetainInoutPort retains the named inout port of an operation.

func (*Lib) OperationRetainInputPort

func (l *Lib) OperationRetainInputPort(uintptr, string) (uintptr, error)

OperationRetainInputPort retains the named input port of an operation.

func (*Lib) OperationRetainOutputPort

func (l *Lib) OperationRetainOutputPort(uintptr, string) (uintptr, error)

OperationRetainOutputPort retains the named output port of an operation.

func (*Lib) PrecompiledComputeOpOptionsCreate

func (l *Lib) PrecompiledComputeOpOptionsCreate(uintptr) (uintptr, error)

PrecompiledComputeOpOptionsCreate creates operation options from a program function.

func (*Lib) PrecompiledComputeOpOptionsRelease

func (l *Lib) PrecompiledComputeOpOptionsRelease(uintptr) error

PrecompiledComputeOpOptionsRelease releases an operation options object.

func (*Lib) PrecompiledComputeOpOptionsSetAllocateIntermediateBuffers

func (l *Lib) PrecompiledComputeOpOptionsSetAllocateIntermediateBuffers(uintptr, bool) error

PrecompiledComputeOpOptionsSetAllocateIntermediateBuffers asks the runtime to allocate the operation's internal buffers.

func (*Lib) PrecompiledComputeOpOptionsSetOperationName

func (l *Lib) PrecompiledComputeOpOptionsSetOperationName(uintptr, string) error

PrecompiledComputeOpOptionsSetOperationName names the operation.

func (*Lib) PrepareOpForEncode

func (l *Lib) PrepareOpForEncode(uintptr) error

PrepareOpForEncode prepares an operation before each encode.

func (*Lib) ProgramFunctionLoadForExecution

func (l *Lib) ProgramFunctionLoadForExecution(uintptr) error

ProgramFunctionLoadForExecution prepares a program function for execution.

func (*Lib) ProgramFunctionRelease

func (l *Lib) ProgramFunctionRelease(uintptr) error

ProgramFunctionRelease releases a retained program function.

func (*Lib) ProgramLibraryCreate

func (l *Lib) ProgramLibraryCreate(string) (uintptr, error)

ProgramLibraryCreate opens an already-compiled bundle.

func (*Lib) ProgramLibraryRelease

func (l *Lib) ProgramLibraryRelease(uintptr) error

ProgramLibraryRelease releases a program library.

func (*Lib) ProgramLibraryRetainProgramFunction

func (l *Lib) ProgramLibraryRetainProgramFunction(uintptr, string) (uintptr, error)

ProgramLibraryRetainProgramFunction retains a callable program function.

func (*Lib) Resolved

func (l *Lib) Resolved() []string

Resolved reports the names from Symbols that resolved.

func (*Lib) SubmitAsync

func (l *Lib) SubmitAsync(uintptr, func() Status) (func(), error)

SubmitAsync submits an encoded stream without blocking and returns a function that releases the completion block.

func (*Lib) Sym

func (l *Lib) Sym(string) (uintptr, error)

Sym returns the address of an entry point named in Symbols.

type Pipeline

type Pipeline struct {
	// contains filtered or unexported fields
}

A Pipeline is a compiled, bound, and encoded sequence of E5RT functions.

The zero value is not usable. A Pipeline is not safe for concurrent use. Call Pipeline.Close when finished.

func CompilePipeline

func CompilePipeline(opts PipelineOptions) (_ *Pipeline, err error)

CompilePipeline compiles, links, and encodes stages into one E5RT stream.

func (*Pipeline) Close

func (p *Pipeline) Close() error

Close releases the E5RT objects owned by p. It is safe to call Close more than once. Any buffers returned by Input or Output become invalid on return.

func (*Pipeline) Execute

func (p *Pipeline) Execute() error

Execute synchronously runs every encoded pipeline stage in order.

func (*Pipeline) Input

func (p *Pipeline) Input(stage int, name string) (*Buffer, error)

Input returns the buffer bound to name on stage.

func (*Pipeline) Output

func (p *Pipeline) Output(stage int, name string) (*Buffer, error)

Output returns the buffer bound to name on stage.

type PipelineLink struct {
	From PipelinePort
	To   PipelinePort
}

A PipelineLink binds an output buffer to a later stage's input port.

The linked stages execute in order in one stream. The two ports use the same buffer object; no host copy is made between them.

type PipelineOptions

type PipelineOptions struct {
	CacheDir string

	DeviceMask         uint64
	Segmenter          string
	ForceRecompilation bool

	Stages []PipelineStage
	Links  []PipelineLink
}

PipelineOptions describes one encoded multi-stage E5RT stream.

Model-backed stages are compiled independently under CacheDir; bundle-backed stages open an existing compiled bundle. Every stage is then encoded in the order listed. Links must flow from an earlier stage to a later one. Unlinked inputs and outputs remain host-visible through Pipeline.Input and Pipeline.Output. CacheDir is required only when at least one stage has a ModelPath.

type PipelinePort

type PipelinePort struct {
	Stage int
	Name  string
}

A PipelinePort identifies a named port on a pipeline stage.

type PipelineStage

type PipelineStage struct {
	// Exactly one of ModelPath and BundlePath must be set.
	// ModelPath is compiled into CacheDir. BundlePath opens an existing bundle.
	ModelPath  string
	BundlePath string

	FunctionName string
	Inputs       []Port
	Outputs      []Port
}

A PipelineStage describes one function in a Pipeline.

type Port

type Port struct {
	Name string
	Size int
}

A Port describes one externally bound program port.

Size is the number of bytes the program reads or writes. The caller is responsible for using the representation the MIL program declares.

type Program

type Program struct {
	// contains filtered or unexported fields
}

A Program is a compiled, bound, and encoded E5RT function.

The zero value is not usable. Programs are not safe for concurrent use. Call Program.Close when finished.

func Compile

func Compile(opts ProgramOptions) (_ *Program, err error)

Compile compiles, binds, and encodes one E5RT function.

Execute may then be called repeatedly after changing the input buffers. The result is a single encoded operation; Compile does not add an operation to an existing stream or plan a multi-function graph.

func OpenBundle

func OpenBundle(opts BundleOptions) (_ *Program, err error)

OpenBundle opens, binds, and encodes a function from an existing compiled E5RT bundle.

func (*Program) Close

func (p *Program) Close() error

Close releases the E5RT objects owned by p. It is safe to call Close more than once. Any buffers returned by Input or Output become invalid on return.

func (*Program) Execute

func (p *Program) Execute() error

Execute synchronously runs the encoded operation.

func (*Program) Input

func (p *Program) Input(name string) (*Buffer, error)

Input returns the buffer bound to the named input port.

func (*Program) Output

func (p *Program) Output(name string) (*Buffer, error)

Output returns the buffer bound to the named output port.

type ProgramOptions

type ProgramOptions struct {
	ModelPath string
	CacheDir  string

	FunctionName string
	DeviceMask   uint64
	Segmenter    string

	ForceRecompilation bool
	Inputs             []Port
	Outputs            []Port
}

ProgramOptions describes a single-function E5RT program.

ModelPath names the MIL program to compile. CacheDir receives the compiler's bundles. Inputs and Outputs name the function's externally bound ports. FunctionName defaults to "main", DeviceMask defaults to ComputeDeviceANE, and Segmenter defaults to "graph".

A Program has one encoded operation. It deliberately does not expose E5RT's reset, prepare, events, or multi-operation interfaces: their useful behavior has not been established by this package.

type StateLayout

type StateLayout struct {
	Channels int
	Dim      int
}

A StateLayout describes how a rank-4 fp16 MIL state tensor of shape [1, Channels, 1, Dim] occupies a bound buffer object.

It is not the packed element count. Each channel starts on a 64-byte boundary, so a state of shape [1, 4, 1, 4] occupies 256 bytes where its 16 fp16 elements would pack into 32. Use StateLayout.Size to allocate and StateLayout.Offset to address elements; the trailing bytes of each row are padding the engine does not read.

This matters because getting it wrong is silent. A caller who allocates the packed size receives no error from Lib.BufferObjectAlloc or from Lib.IOPortBindBufferObject. The engine addresses the padded offsets regardless, so a program that writes its state writes past the end of the allocation — and because a reader reads back the same out-of-bounds offsets, the round trip is self-consistent and the corruption does not show up as a wrong answer. That is exactly how it went unnoticed in this package's own probes. Lib.BindStatePort is the checked bind that refuses it.

What has been measured

The 64-byte row alignment was measured on macOS 26.x on one machine, for fp16 states of shape [1, C, 1, D], at (C, D) of (4,4), (4,32), (4,40), (2,64) and (8,2), by binding an oversized buffer, filling every two-byte slot with its own index, and reading back which slot each element came from. Shapes whose row already fills whole 64-byte lines, such as D=32, are packed by coincidence; code developed at those shapes works and corrupts memory at others.

Element types other than fp16, ranks other than 4, and leading extents other than 1 are UNMEASURED. So is whether the 64-byte figure is a property of this hardware generation, this OS version, or the E5RT ABI. Callers should compute sizes with this type rather than hard-coding them, and examples/ane/statecache -layout re-runs the measurement.

Ordinary input and output ports are packed. Only the state carries padding.

func (StateLayout) Offset

func (l StateLayout) Offset(channel, i int) int

Offset returns the byte offset of element i of the given channel. It panics if either index is out of range, which is a programming error rather than a runtime condition.

func (StateLayout) Packed

func (l StateLayout) Packed() bool

Packed reports whether the layout leaves no padding, which happens only when a channel row exactly fills a whole number of 64-byte lines. A caller must not rely on this being true for a particular shape; it is offered so that a diagnostic can say which case it is in.

func (StateLayout) RowBytes

func (l StateLayout) RowBytes() int

RowBytes is the distance in bytes between the starts of consecutive channels.

func (StateLayout) Size

func (l StateLayout) Size() int

Size is the number of bytes a buffer object bound to this state must hold.

func (StateLayout) Values

func (l StateLayout) Values() int

Values is the number of logical elements, Channels*Dim.

type Status

type Status int64

Status is a normalized signed 32-bit E5RT status code. A zero code means the entry point accepted the call; see the darwin build for effects that remain unverified.

func (Status) Err

func (s Status) Err(op string) error

Err reports a non-nil error for any nonzero status.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL