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:
- Lib.ProgramLibraryCreate works. A compiled bundle can be reopened directly, with no compiler.
- Lib.ProgramFunctionLoadForExecution is gone, returning status 2 and saying so.
- Lib.PrepareOpForEncode returns zero on this package's self-created streams and leaves them unusable and unreleasable. A separate engine-borrowed, post-reset route reports it works; that route is not reproduced here.
- Lib.ExecutionStreamReset works on a fresh stream, contradicting ANEForge.
- Lib.SubmitAsync works. It needs a real Objective-C block, which [objc.NewBlock] supplies, and the completion block runs.
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
- Variables
- type Buffer
- type BundleOptions
- type Lib
- func (l *Lib) AsyncEventActiveFutureValue(uintptr) (uint64, error)
- func (l *Lib) AsyncEventCreate(string) (uintptr, error)
- func (l *Lib) AsyncEventLastSignaledValue(uintptr) (uint64, error)
- func (l *Lib) AsyncEventRelease(uintptr) error
- func (l *Lib) AsyncEventSetActiveFutureValue(uintptr, uint64) error
- func (l *Lib) AsyncEventSignal(uintptr, uint64) error
- func (l *Lib) AsyncEventSyncWait(uintptr, uint64, uint64) error
- func (l *Lib) BindStatePort(op uintptr, portName string, buf uintptr, lay StateLayout) (uintptr, error)
- func (l *Lib) BufferObjectAlloc(uintptr, int) (uintptr, error)
- func (l *Lib) BufferObjectGetDataPtr(uintptr) (uintptr, error)
- func (l *Lib) BufferObjectGetSize(uintptr) (uintptr, error)
- func (l *Lib) BufferObjectRelease(uintptr) error
- func (l *Lib) CompilerCompile(uintptr, string, uintptr) (uintptr, error)
- func (l *Lib) CompilerConfigOptionsCreate() (uintptr, error)
- func (l *Lib) CompilerConfigOptionsRelease(uintptr) error
- func (l *Lib) CompilerConfigOptionsSetCacheBundleLocation(uintptr, string) error
- func (l *Lib) CompilerCreateWithConfig(uintptr) (uintptr, error)
- func (l *Lib) CompilerOptionsCreate() (uintptr, error)
- func (l *Lib) CompilerOptionsGetComputeDeviceTypesMask(uintptr) (uint64, error)
- func (l *Lib) CompilerOptionsRelease(uintptr) error
- func (l *Lib) CompilerOptionsSetComputeDeviceTypesMask(uintptr, uint64) error
- func (l *Lib) CompilerOptionsSetCustomANECompilerOptions(uintptr, string) error
- func (l *Lib) CompilerOptionsSetForceRecompilation(uintptr, bool) error
- func (l *Lib) CompilerOptionsSetSegmenter(uintptr, string) error
- func (l *Lib) CompilerRelease(uintptr) error
- func (l *Lib) EncodeOperation(uintptr, uintptr) error
- func (l *Lib) ErrorString(Status) (string, error)
- func (l *Lib) ExecuteSync(uintptr) error
- func (l *Lib) ExecutionStreamCreate() (uintptr, error)
- func (l *Lib) ExecutionStreamRelease(uintptr) error
- func (l *Lib) ExecutionStreamReset(uintptr) error
- func (l *Lib) ExecutionStreamSetANEExecutionPriority(uintptr, uint64) error
- func (l *Lib) ExecutionStreamSetQualityOfService(uintptr, uint64) error
- func (l *Lib) IOPortBindBufferObject(uintptr, uintptr) error
- func (l *Lib) IOPortRelease(uintptr) error
- func (l *Lib) Lookup(string) (uintptr, error)
- func (l *Lib) OperationBindCompletionEvent(uintptr, uintptr) error
- func (l *Lib) OperationBindDependentEvents(uintptr, []uintptr) error
- func (l *Lib) OperationCreatePrecompiled(uintptr) (uintptr, error)
- func (l *Lib) OperationRelease(uintptr) error
- func (l *Lib) OperationRetainInoutPort(uintptr, string) (uintptr, error)
- func (l *Lib) OperationRetainInputPort(uintptr, string) (uintptr, error)
- func (l *Lib) OperationRetainOutputPort(uintptr, string) (uintptr, error)
- func (l *Lib) PrecompiledComputeOpOptionsCreate(uintptr) (uintptr, error)
- func (l *Lib) PrecompiledComputeOpOptionsRelease(uintptr) error
- func (l *Lib) PrecompiledComputeOpOptionsSetAllocateIntermediateBuffers(uintptr, bool) error
- func (l *Lib) PrecompiledComputeOpOptionsSetOperationName(uintptr, string) error
- func (l *Lib) PrepareOpForEncode(uintptr) error
- func (l *Lib) ProgramFunctionLoadForExecution(uintptr) error
- func (l *Lib) ProgramFunctionRelease(uintptr) error
- func (l *Lib) ProgramLibraryCreate(string) (uintptr, error)
- func (l *Lib) ProgramLibraryRelease(uintptr) error
- func (l *Lib) ProgramLibraryRetainProgramFunction(uintptr, string) (uintptr, error)
- func (l *Lib) Resolved() []string
- func (l *Lib) SubmitAsync(uintptr, func() Status) (func(), error)
- func (l *Lib) Sym(string) (uintptr, error)
- type Pipeline
- type PipelineLink
- type PipelineOptions
- type PipelinePort
- type PipelineStage
- type Port
- type Program
- type ProgramOptions
- type StateLayout
- type Status
Constants ¶
const ( ComputeDeviceCPU uint64 = 0x1 // BNNS ComputeDeviceGPU uint64 = 0x2 // MPSGraph ComputeDeviceANE uint64 = 0x4 )
Compute device bits for Lib.CompilerOptionsSetComputeDeviceTypesMask.
const FrameworkPath = "/System/Library/PrivateFrameworks/Espresso.framework/Espresso"
FrameworkPath is the Espresso framework the e5rt_* symbols are exported from.
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.
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 ¶
var ErrUnsupported = errors.New("e5rt: unsupported platform")
ErrUnsupported is returned on platforms that do not have Espresso.
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.
type BundleOptions ¶
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 (*Lib) AsyncEventActiveFutureValue ¶
AsyncEventActiveFutureValue reports the event's active future value.
func (*Lib) AsyncEventCreate ¶
AsyncEventCreate creates a named async event.
func (*Lib) AsyncEventLastSignaledValue ¶
AsyncEventLastSignaledValue reports how many times an event has been signaled.
func (*Lib) AsyncEventRelease ¶
AsyncEventRelease releases an async event.
func (*Lib) AsyncEventSetActiveFutureValue ¶
AsyncEventSetActiveFutureValue sets the value an event is expected to reach.
func (*Lib) AsyncEventSignal ¶
AsyncEventSignal signals an async event from the host.
func (*Lib) AsyncEventSyncWait ¶
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 ¶
BufferObjectAlloc allocates a buffer object.
func (*Lib) BufferObjectGetDataPtr ¶
BufferObjectGetDataPtr returns the host address of a buffer object's storage.
func (*Lib) BufferObjectGetSize ¶
BufferObjectGetSize returns the number of bytes a buffer object holds.
func (*Lib) BufferObjectRelease ¶
BufferObjectRelease releases a buffer object.
func (*Lib) CompilerCompile ¶
CompilerCompile compiles the network description at modelPath.
func (*Lib) CompilerConfigOptionsCreate ¶
CompilerConfigOptionsCreate creates a compiler configuration.
func (*Lib) CompilerConfigOptionsRelease ¶
CompilerConfigOptionsRelease releases a compiler configuration.
func (*Lib) CompilerConfigOptionsSetCacheBundleLocation ¶
CompilerConfigOptionsSetCacheBundleLocation sets the compiled-bundle directory.
func (*Lib) CompilerCreateWithConfig ¶
CompilerCreateWithConfig creates a compiler from a configuration handle.
func (*Lib) CompilerOptionsCreate ¶
CompilerOptionsCreate creates a per-compile options object.
func (*Lib) CompilerOptionsGetComputeDeviceTypesMask ¶
CompilerOptionsGetComputeDeviceTypesMask reports the mask set on an options object.
func (*Lib) CompilerOptionsRelease ¶
CompilerOptionsRelease releases a compiler options object.
func (*Lib) CompilerOptionsSetComputeDeviceTypesMask ¶
CompilerOptionsSetComputeDeviceTypesMask selects the backends the compiler may target.
func (*Lib) CompilerOptionsSetCustomANECompilerOptions ¶
CompilerOptionsSetCustomANECompilerOptions passes a string to the Neural Engine compiler.
func (*Lib) CompilerOptionsSetForceRecompilation ¶
CompilerOptionsSetForceRecompilation makes the compiler ignore a cached bundle.
func (*Lib) CompilerOptionsSetSegmenter ¶
CompilerOptionsSetSegmenter selects how the compiler partitions the network.
func (*Lib) CompilerRelease ¶
CompilerRelease releases a compiler.
func (*Lib) EncodeOperation ¶
EncodeOperation encodes a prepared operation into a stream.
func (*Lib) ErrorString ¶
ErrorString returns Espresso's static description of status.
func (*Lib) ExecuteSync ¶
ExecuteSync submits an encoded stream and blocks until it completes.
func (*Lib) ExecutionStreamCreate ¶
ExecutionStreamCreate creates an execution stream.
func (*Lib) ExecutionStreamRelease ¶
ExecutionStreamRelease releases an execution stream.
func (*Lib) ExecutionStreamReset ¶
ExecutionStreamReset resets a stream for reuse after execution.
func (*Lib) ExecutionStreamSetANEExecutionPriority ¶
ExecutionStreamSetANEExecutionPriority sets a stream's Neural Engine priority.
func (*Lib) ExecutionStreamSetQualityOfService ¶
ExecutionStreamSetQualityOfService sets a stream's dispatch quality of service.
func (*Lib) IOPortBindBufferObject ¶
IOPortBindBufferObject binds a buffer object to a retained I/O port.
func (*Lib) IOPortRelease ¶
IOPortRelease releases a retained I/O port from the standalone direct route.
func (*Lib) OperationBindCompletionEvent ¶
OperationBindCompletionEvent binds the event an operation signals when it finishes.
func (*Lib) OperationBindDependentEvents ¶
OperationBindDependentEvents makes an operation wait for the given events.
func (*Lib) OperationCreatePrecompiled ¶
OperationCreatePrecompiled creates the executable operation from its options.
func (*Lib) OperationRelease ¶
OperationRelease releases an operation.
func (*Lib) OperationRetainInoutPort ¶
OperationRetainInoutPort retains the named inout port of an operation.
func (*Lib) OperationRetainInputPort ¶
OperationRetainInputPort retains the named input port of an operation.
func (*Lib) OperationRetainOutputPort ¶
OperationRetainOutputPort retains the named output port of an operation.
func (*Lib) PrecompiledComputeOpOptionsCreate ¶
PrecompiledComputeOpOptionsCreate creates operation options from a program function.
func (*Lib) PrecompiledComputeOpOptionsRelease ¶
PrecompiledComputeOpOptionsRelease releases an operation options object.
func (*Lib) PrecompiledComputeOpOptionsSetAllocateIntermediateBuffers ¶
PrecompiledComputeOpOptionsSetAllocateIntermediateBuffers asks the runtime to allocate the operation's internal buffers.
func (*Lib) PrecompiledComputeOpOptionsSetOperationName ¶
PrecompiledComputeOpOptionsSetOperationName names the operation.
func (*Lib) PrepareOpForEncode ¶
PrepareOpForEncode prepares an operation before each encode.
func (*Lib) ProgramFunctionLoadForExecution ¶
ProgramFunctionLoadForExecution prepares a program function for execution.
func (*Lib) ProgramFunctionRelease ¶
ProgramFunctionRelease releases a retained program function.
func (*Lib) ProgramLibraryCreate ¶
ProgramLibraryCreate opens an already-compiled bundle.
func (*Lib) ProgramLibraryRelease ¶
ProgramLibraryRelease releases a program library.
func (*Lib) ProgramLibraryRetainProgramFunction ¶
ProgramLibraryRetainProgramFunction retains a callable program function.
func (*Lib) SubmitAsync ¶
SubmitAsync submits an encoded stream without blocking and returns a function that releases the completion block.
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 ¶
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.
type PipelineLink ¶
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 ¶
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 ¶
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 ¶
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.
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 ¶
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.