WIP: add nkigen-lite as a standalone IR-based kernel generation backend#59
Draft
ymwangg wants to merge 1 commit into
Draft
WIP: add nkigen-lite as a standalone IR-based kernel generation backend#59ymwangg wants to merge 1 commit into
ymwangg wants to merge 1 commit into
Conversation
Migrates tensor_ir, nki_ir, and the direct lowering passes from nano-tensorizer/ir_lab into the nkipy workspace as a new package. The pipeline (canonicalize → decompose → layout_solver → direct_lower) produces legal NKI IR directly without intermediate passes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
nkigen-lite, a standalone IR-based kernel generation backend that lowers numpy-style tensor programs to NKI (Neuron Kernel Interface) code for NeuronCore targets.Architecture
The system is structured as a three-layer IR stack with a multi-phase lowering pipeline:
Core (
core.py)Shared SSA-based IR infrastructure used by both IRs:
Value,Op,Graph— SSA primitives with use-lists and mutation helpersDTypeenum covering f32/f16/bf16/tf32/fp8/int typesTensor IR (
tensor_ir/)High-level, hardware-agnostic IR operating on whole tensors:
NKI IR (
nki_ir/)Low-level IR that makes hardware concerns explicit:
Lowering Pipeline (
tensor_ir/passes/)The full pipeline:
tensor_ir → canonicalize → decompose → layout_solver → direct_lower → nki_irCanonicalize — recomposes primitive-op chains into high-level ops (e.g.,
div(1, sqrt(x))→rsqrt(x),mul(x, div(1, add(1, exp(neg(x)))))→silu(x))Decompose — lowers ops without direct NISA equivalents into supported primitives (e.g.,
div(a,b)→mul(a, reciprocal(b)),reduce(mean)→reduce(sum) * 1/N)Layout Solver — assigns each tensor dimension to one of three roles:
Propagates constraints across the graph to find a globally consistent assignment.
Direct Lower — converts tensor IR ops to tiled NKI IR:
Hardware Target (
passes/hardware.py)Parameterized hardware profiles (TRN2 defaults) defining partition limits, SBUF/PSUM sizes, and matmul constraints.
Status
🚧 Work in progress — not ready for review.
Test plan
uv run pytest nkigen-lite/tests/ -n auto)