linear

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package linear provides reusable ANE-backed linear forward execution.

It compiles and caches in-memory kernels keyed by shape and weights, then executes row-major x*w^T using ANE runtime plumbing from this repository.

DynamicExecutor provides a compile-once variant for workloads whose weights change across evaluations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CallStats

type CallStats struct {
	Compiled      bool
	HWExecutionNS uint64
}

CallStats reports per-call execution details.

type DynamicExecutor

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

DynamicExecutor caches compile-once ANE kernels keyed by shape and accepts runtime-provided weights on each call.

It preserves the row-major linear API used by Executor:

  • x is [batch, inDim]
  • w is [outDim, inDim]
  • y is [batch, outDim]

func NewDynamic

func NewDynamic(opts Options) *DynamicExecutor

NewDynamic creates a dynamic linear executor.

func (*DynamicExecutor) Close

func (e *DynamicExecutor) Close()

Close releases all cached kernels.

func (*DynamicExecutor) Linear

func (e *DynamicExecutor) Linear(ctx context.Context, x, w []float32, batch, inDim, outDim int) ([]float32, error)

Linear computes x*w^T where x is [batch,inDim] and w is [outDim,inDim].

func (*DynamicExecutor) LinearIOIntoWithStats

func (e *DynamicExecutor) LinearIOIntoWithStats(ctx context.Context, dst, x, wIO []float32, batch, inDim, outDim int) (CallStats, error)

LinearIOIntoWithStats computes x*w where w is already laid out as [inDim,outDim].

This is a fast path for callers that maintain the dynamic kernel's native weight layout and want to avoid transposing [outDim,inDim] on every call.

func (*DynamicExecutor) LinearIntoWithStats

func (e *DynamicExecutor) LinearIntoWithStats(ctx context.Context, dst, x, w []float32, batch, inDim, outDim int) (CallStats, error)

LinearIntoWithStats computes x*w^T into dst and returns per-call execution stats.

func (*DynamicExecutor) LinearOneHotIOIntoWithStats

func (e *DynamicExecutor) LinearOneHotIOIntoWithStats(ctx context.Context, dst []float32, xs []int, batch, inDim, outDim int) (CallStats, error)

LinearOneHotIOIntoWithStats computes y = x*w for one-hot activations encoded by xs and a previously primed IO-layout weight matrix.

func (*DynamicExecutor) LinearWithStats

func (e *DynamicExecutor) LinearWithStats(ctx context.Context, x, w []float32, batch, inDim, outDim int) ([]float32, CallStats, error)

LinearWithStats computes x*w^T and returns per-call execution stats.

func (*DynamicExecutor) Prepare

func (e *DynamicExecutor) Prepare(batch, inDim, outDim int) error

Prepare compiles and caches a dynamic kernel for the provided shape.

func (*DynamicExecutor) PrimeWeightsIO

func (e *DynamicExecutor) PrimeWeightsIO(batch, inDim, outDim int, wIO []float32) error

PrimeWeightsIO stores an IO-layout weight matrix in the cached dynamic kernel.

func (*DynamicExecutor) Stats

func (e *DynamicExecutor) Stats() Stats

Stats returns a snapshot of executor counters.

func (*DynamicExecutor) UpdateWeightsIORows

func (e *DynamicExecutor) UpdateWeightsIORows(batch, inDim, outDim int, wIO []float32, rows []int) error

UpdateWeightsIORows patches a subset of IO-layout weight rows in the cached kernel.

type Executor

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

Executor caches compiled kernels and runs linear forwards.

func New

func New(opts Options) *Executor

New creates a linear executor.

func (*Executor) Close

func (e *Executor) Close()

Close releases all cached kernels.

func (*Executor) Linear

func (e *Executor) Linear(ctx context.Context, x, w []float32, batch, inDim, outDim int) ([]float32, error)

Linear computes x*w^T where x is [batch,inDim] and w is [outDim,inDim].

x and w use row-major layout.

func (*Executor) LinearIntoWithStats

func (e *Executor) LinearIntoWithStats(ctx context.Context, dst, x, w []float32, batch, inDim, outDim int) (CallStats, error)

LinearIntoWithStats computes x*w^T into dst and returns per-call execution stats.

dst must have length batch*outDim and uses row-major layout.

func (*Executor) LinearWithStats

func (e *Executor) LinearWithStats(ctx context.Context, x, w []float32, batch, inDim, outDim int) ([]float32, CallStats, error)

LinearWithStats computes x*w^T and returns per-call execution stats.

func (*Executor) Prepare

func (e *Executor) Prepare(w []float32, batch, inDim, outDim int) error

Prepare compiles and caches a kernel for the provided shape and weights.

func (*Executor) Stats

func (e *Executor) Stats() Stats

Stats returns a snapshot of executor counters.

type Options

type Options struct {
	QoS uint32
}

Options configures linear execution.

type Stats

type Stats struct {
	Compiles  int
	CacheHits int
	Kernels   int
}

Stats reports cache and compile counters.

Jump to

Keyboard shortcuts

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