nki-kernel-bench / README.md
jburtoft's picture
nki-kernel-bench v0.1
0fef070
|
Raw History Blame Contribute Delete
6.98 kB
metadata
license: apache-2.0
pretty_name: nki-kernel-bench
tags:
  - nki
  - aws-neuron
  - trainium
  - kernels
  - performance
  - compiler-testing
size_categories:
  - n<1K
configs:
  - config_name: results
    data_files: release/RESULTS.csv

nki-kernel-bench

A dataset of real NKI kernels with several versions each (release-to-release changes, optimization steps, rejected variants). Every version compiles and runs on one pinned toolchain and comes with:

  • the kernel source
  • numpy inputs
  • an independent numpy reference
  • simulator and hardware parity results
  • the NEFF
  • two neuron-explorer hardware profiles

Uses

  • Compiler and toolchain testing. Run every kernel version against a new compiler build or flag and see what breaks or regresses (tools/compare.py).
  • Comparing optimization techniques. Within a family, every pair of versions shares inputs and an output contract, so any two of them form a valid A/B pair at the same shape. The version history records which change was tried, kept or rejected, and what it did to device time.
  • Training and evaluating performance models on held-out pairs (nkb.iter_pairs).

Contents (v0.1)

Toolchain SDK 2.33 DLAMI, nki 0.7.0, neuronx-cc 2.28.7631.0 (TOOLCHAIN.md)
Timing host trn2.48xlarge (every version)
Families / versions 216 / 599, every version passes simulator + hardware parity with 2 profiles (release/DATASET.md)
A/B pairs 2744 within-family pairs
Sources aws-neuron/nki-library release tags 2.27-2.33 and commits on a public fork of it; Hugging Face Kernel Hub repositories; unpublished kernels from model-porting work

Layout

dataset/<domain>/<family>/{family.yaml, inputs.py, reference.py, <version>/{manifest.yaml, kernel.py, deps/, results/}}
release/       DATASET.md (summary), RESULTS.csv (all timings), CONTENTS.sha256
FORMAT.md      entry format, family / A-B rule, manifest + results schema
PORTING.md     how older NKI versions were ported to 0.7.0 (syntax only; pattern ids P00-P15)
TOOLCHAIN.md   exact pinned versions and environment
harness/       run.py (one entry), batch.py (many, sharded, resumable)
nkb.py         loader: load_dataset / load_family / iter_pairs
tools/         validate.py (schema + hygiene), compare.py (variant vs baseline), freeze.py, scrub_paths.py
schema/        JSON schemas

Quick start

import nkb
ds = nkb.load_dataset("dataset")
for a, b, shape in nkb.iter_pairs(ds):
    print(a.id, "->", b.id, shape, f"{a.time_us(shape) / b.time_us(shape):.3f}x")

Reproducing the hardware results on a trn2 instance:

source toolchain/env.sh
python harness/batch.py --hw dataset --force --workers 4

Testing a compiler knob across the dataset (on trn2.48xlarge, the timing host of record):

python tools/compare.py --name pe_transpose --env NKI_DMA_TRANSPOSE_AS_PE_TRANSPOSE=1
python tools/paired_profile.py dataset --variant compare_pe_transpose --out paired.jsonl   # placement-controlled verdicts

NEURON_CC_FLAGS=-O1/-O3/--auto-cast have no effect on NKI kernels on this toolchain; see eval_public/COMPARE_PE_TRANSPOSE.md.

Provenance and licenses

Everything in this package is licensed under the Apache License 2.0 (LICENSE). Third-party sources keep their notices (NOTICE).

Each version's manifest.yaml records its origin. provenance.source is one of:

source meaning provenance.origin
nki-lib aws-neuron/nki-library release tags and upstream commits public GitHub URL + commit
hugging-face Hugging Face Kernel Hub repositories public HF URL + commit
jburtoft maintainer-written kernels: commits on a public nki-library fork, plus kernels written during model-porting work that were never published as-is the public fork URL + commit, or unpublished; when a later version of the same kernel family was posted publicly, provenance.related_public links to it

Versions are byte-identical to their origin unless port.status: ported. port.notes lists every change, using PORTING.md pattern ids. The changes are either edits needed to run on SDK 2.33 or the removal of non-technical comments (P00).

Source records. A full source inventory is kept privately and is not part of this package. It covers, for every version, the original location, commit and file path, the pre-edit text of every kernel, and the list of candidate kernels that were scanned and excluded, with reasons. Researchers who need the provenance of a specific kernel for their work can contact the maintainer.

Host comparison and multicore timings

eval_public/HOST_COMPARISON.md compares single-core and fully loaded host ("multicore") timings on trn2.48xlarge and trn2.3xlarge, with eval_public/host_comparison.csv. In short:

  • utilization throttling (from the NTFF throttle notifications) caps about 30 % of profiles, mostly the activity cap at 0.5, with power caps in 23 profiles. It is recorded per profile and does not change the reported times or explain the differences below;
  • most kernels time the same alone and with the whole host loaded;
  • a tail of about 13 % of kernels is more than 10 % slower when all 16 devices are busy;
  • the two instance types agree for most kernels but not all, so compare within one instance type.

Every profile ships with its raw profile.ntff, so it can be opened directly in neuron-explorer with the version's NEFF.

Core placement (read before comparing timings)

On trn2 the same NEFF can run 10-40 % slower on one half of a device (pcores 0-3 vs 4-7) than on the other. This is reproducible and concentrated in kernels with many GpSimd DMAs. Every timing carries placement.half_A_us / half_B_us and controlled_us (the faster half). For A/B comparisons, use controlled_us, or run both NEFFs on the same cores with tools/paired_profile.py. Details are in eval_public/PLACEMENT.md; the worked compiler-knob comparison that exposed it is in eval_public/COMPARE_PE_TRANSPOSE.md.

Cold start and the Tensor-Engine warm-up

All timings are cold starts: each profiled execution begins with an idle Tensor Engine. On Trn2 the engine runs the first ~3 us of every burst at about half speed (dI/dt ramp). Every timing therefore also carries:

  • opening_ramp_us: the ramp cost of the first burst;
  • warm_est_us: the estimated time with the engine already busy;
  • ramp_frac: the ramp cost of all bursts.

The opening ramp is at most 6 % of any kernel. Ramps inside bursty kernels reach 24 %. eval_public/WARM_START.md has the method and the trn2 validation.

Timing semantics

results/timing.json:total_time_us is the minimum, over 2 profiles, of Summary.total_time for the second execution, measured by neuron-explorer capture with the version's own inputs at launch_grid LNC. noise_pct is the spread between the two profiles. These are single-NeuronCore kernel timings, not model throughput.