Skip to content

feat(balls): add NliBall — non-uniform linear interpolation for non-linear ops (SiLU) - #105

Open
chipcrowd[bot] wants to merge 3 commits into
mainfrom
nli-ball
Open

feat(balls): add NliBall — non-uniform linear interpolation for non-linear ops (SiLU)#105
chipcrowd[bot] wants to merge 3 commits into
mainfrom
nli-ball

Conversation

@chipcrowd

@chipcrowd chipcrowd Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Implements issue #34: a new NliBall for non-linear operators, using the NLI (Non-uniform Linear Interpolation) methodology from "NLI: Non-uniform Linear Interpolation Approximation of Nonlinear Operations for Efficient LLMs Inference".

What it does

NliBall approximates any non-linear function with 16 piecewise-linear segments whose cutpoints are placed non-uniformly (offline, where the function is most curved). The Ball is function-agnostic — the segment table (cutpoints / slopes / intercepts) is loaded through a coefficient bank with MVIN, so SiLU, GELU, exp, … all run on the same hardware.

Per INT8 lane it selects the segment with a comparator tree, then evaluates one Q7 MAC:

seg = #{ cutpoint <= x }
out = clamp( (slope[seg] * x) >> 7 + intercept[seg], -128, 127 )

Deliverables

  • RTLexamples/balls/nli/arch/src/main/scala/NliBall.scala (Chisel, 2 read / 1 write ports, 16 INT8 lanes/row).
  • C testexamples/balls/nli/workloads/ctests/nli_test.c (datapath + SiLU accuracy), workloads/isa/nli.h.
  • READMEexamples/balls/nli/README.md (contract, data layout, datapath, results).
  • CompilerNliBall.td, LegalizeForLLVMExport.cpp, AssignPhysicalBankPatterns.cpp.
  • Emulatoremu/src/{lib.rs,nli.rs} (BEMU golden model, bit-exact with RTL).
  • Offline tablegenscripts/gen_silu_table.py (cutpoint optimisation).
  • Registered in the pebble core: ballNum 11, bid 10, mnemonic NLI, funct7 73.

Results

SiLU over the full INT8 domain [-128, 127] (16 segments):

metric value
max abs error 1.0 LSB (@ x=37)
mean abs error 0.50 LSB
vs uniform 16-entry LUT 8.0 LSB max / 2.0 LSB mean
vs uniform 256-entry LUT same 1.0 LSB, but 16x the storage

16 non-uniform linear segments reach the fixed-point quantization floor and match a 256-entry uniform LUT with 16x less table — including the extreme outliers where a coarse uniform LUT collapses.

Validation performed

  • validate (ball-domain registration): all checks pass.
  • Config derivation (chip.pb) and compiler registry generation: pass; NLI td/legalize/assign all discovered.
  • Chisel RTL compiles (mill buckyball.compile).
  • Emulator datapath verified bit-exact against an independent reference (max/mean error match the offline model).

Note: full bemu/Verilator simulation requires the buckyball-dev MCP tooling, which was not available in this session (the nix development environment could not be entered under the sandbox), so the on-target sim run is left for CI.

…rm linear interpolation)

Add a new NliBall that evaluates non-linear functions with NLI
(non-uniform linear interpolation): 16 piecewise-linear segments whose
cutpoints are placed offline where the function is most curved. The Ball is
function-agnostic (SiLU, GELU, exp, ...); the segment table is loaded through
the coefficient bank with MVIN.

- arch: Chisel RTL (2 read / 1 write ports, 16 INT8 lanes, comparator-tree
  segment select + Q7 MAC)
- emu: BEMU golden model (bit-exact with RTL)
- compiler: NliBall.td + LegalizeForLLVMExport + AssignPhysicalBank patterns
- workloads: C test (datapath + SiLU accuracy) + ISA header
- scripts: offline cutpoint optimisation for SiLU
- README: contract, data layout, datapath and accuracy results

Register NliBall in the pebble core (ballNum 11, bid 10, mnemonic NLI,
funct7 73).
…tters

- Move registration from pebble to toy (toy is the maintenance core for new
  Balls; production cores keep their fixed Ball set).
- Revert the pebble balldomain and compiler wiring.
- Apply scalafmt / black / clang-format so the pre-commit CI job passes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

0 participants