bnns-amx-draft

command
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: 16 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.

README

bnns-amx-draft

Demonstrates compiling a batch=1 residual MLP draft block in pure Go with x/coremlcompiler and executing it on Apple Silicon CPU/AMX via x/bnnsgraph with a preallocated page-aligned workspace (0 Go heap allocations per step), comparing numerical parity and per-step latency against a Metal GPU compute shader and a float64 Go reference.

Model

A two-layer residual MLP (dim=256, hidden=1024, batch=1, fp32, ~1.05M FLOPs):

h = relu(x * W1^T + b1)
y = (h * W2^T + b2) + x

The model and weights are emitted directly to an .mlmodelc bundle in Go using x/coremlcompiler.CompileProgram (no Python, no coremltools, no cgo).

Usage

CGO_ENABLED=0 go run ./examples/accelerate/bnns-amx-draft
CGO_ENABLED=0 go run ./examples/accelerate/bnns-amx-draft -dim 256 -hidden 1024 -iters 500
CGO_ENABLED=0 go test -v -count=1 ./examples/accelerate/bnns-amx-draft

Measured Results (Apple M4 Max, macOS 26.6.2, Go 1.27.0)

batch=1, dim=256, hidden=1024, iters=500, single_thread=true:

  • Compiled BNNSGraph IR: 2,118,748 bytes
  • Preallocated page-aligned workspace: 5,120 bytes
  • Heap allocations per Context.Execute: 0.00 (testing.AllocsPerRun)
Backend Mean (µs) p50 (µs) p95 (µs) p99 (µs) Max abs err vs fp64
BNNSGraph (AMX/CPU) 12.75 7.83 20.00 88.67 1.192e-07
Metal Compute (GPU) 748.43 654.04 1277.12 2732.88 1.788e-07
Go Reference (fp64) 1054.17 1028.25 1108.75 1628.33 0 (oracle)
  • BNNSGraph vs Metal max abs diff: 1.788e-07
  • Speedup (BNNSGraph p50 vs Metal p50): 83.50x (batch=1 avoids per-step GPU command buffer submission and synchronization latency).

Documentation

Rendered for darwin/amd64

Overview

Command bnns-amx-draft builds a batch=1 residual MLP draft block in pure Go via x/coremlcompiler, compiles and runs it on Apple Silicon CPU/AMX via x/bnnsgraph with a preallocated workspace (zero heap allocations per step), and compares numerical parity and per-step latency against a Metal GPU compute shader and a float64 CPU reference.

go run ./examples/accelerate/bnns-amx-draft
go run ./examples/accelerate/bnns-amx-draft -dim 256 -hidden 1024 -iters 500

Jump to

Keyboard shortcuts

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