Skip to content

Commit 501b732

Browse files
committed
Initial ntops.lab operators
0 parents  commit 501b732

284 files changed

Lines changed: 20465 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.gitattributes‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
* text=auto eol=lf
2+
3+
*.bat text eol=crlf
4+
*.ps1 text eol=crlf

‎.github/workflows/ci.yml‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
metadata:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
- uses: actions/setup-python@v5
13+
with:
14+
python-version: "3.11"
15+
- name: Install package
16+
run: |
17+
python -m pip install --upgrade pip
18+
pip install -e ".[dev]"
19+
- name: Validate manifest
20+
run: python scripts/check_manifest.py
21+
- name: Run tests
22+
run: pytest

‎.gitignore‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
__pycache__/
2+
*.py[cod]
3+
.pytest_cache/
4+
.mypy_cache/
5+
.ruff_cache/
6+
.venv/
7+
venv/
8+
build/
9+
dist/
10+
*.egg-info/
11+
.ninetoothed/
12+
*.log
13+
htmlcov/
14+
.coverage

‎CHANGELOG.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Changelog
2+
3+
## 0.1.0
4+
5+
- Initial `ntops.lab` repository layout.
6+
- Added canonical operator catalog with 468 unique operator entries.
7+
- Added 371 runnable NineToothed operator implementations.
8+
- Added 97 todo/scaffold entries with support analysis.
9+
- Added CLI, manifest validation, metadata tests, and GPU smoke helpers.

‎CONTRIBUTING.md‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Contributing
2+
3+
`ntops.lab` welcomes focused operator improvements.
4+
5+
Before opening a pull request:
6+
7+
1. Keep each operator in a separate file.
8+
2. Add or update the PyTorch reference in the same module.
9+
3. Update `src/ntops_lab/operator_manifest.json`.
10+
4. Run:
11+
12+
```bash
13+
python scripts/check_manifest.py
14+
pytest
15+
```
16+
17+
If you add a runnable GPU kernel, also run:
18+
19+
```bash
20+
ntops-lab check <operator-name>
21+
```
22+
23+
For blocked operators, leave a precise `REASON` explaining whether the blocker
24+
is a missing NineToothed interface, a missing math primitive, or just manual
25+
lowering work.

‎LICENSE‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2026 InfiniTensor and ntops.lab contributors
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

‎Makefile‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.PHONY: check test summary smoke-one smoke-pointwise
2+
3+
check:
4+
python scripts/check_manifest.py
5+
python -m compileall -q src scripts tests
6+
7+
test:
8+
python -m pytest
9+
10+
summary:
11+
python -m ntops_lab.cli summary
12+
13+
smoke-one:
14+
python scripts/run_operator.py add
15+
16+
smoke-pointwise:
17+
python scripts/run_smoke_suite.py --category pointwise --limit 10 --continue-on-error

‎README.md‎

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
# ntops.lab
2+
3+
`ntops.lab` is an experimental operator lab for
4+
[NineToothed](https://github.com/InfiniTensor/ninetoothed). It collects
5+
generated and hand-shaped NineToothed kernels, keeps a runnable operator
6+
catalog, and records the current gaps that need compiler/runtime support.
7+
8+
The project is intentionally a lab: many kernels are produced with LLM-assisted
9+
operator development, then smoke-tested against PyTorch on CUDA.
10+
11+
## Current Coverage
12+
13+
The canonical catalog contains:
14+
15+
- 250 runnable NineToothed implementations
16+
- 0 unsupported/scaffold source files included in the commit-ready tree
17+
- gap analysis retained in documentation only
18+
19+
Primary categories:
20+
21+
- `pointwise`
22+
- `reduction`
23+
- `linear`
24+
- `layout`
25+
- `creation`
26+
- `normalization`
27+
- `fused/general`
28+
- `fused/fla`
29+
- `fused/dsa`
30+
- `fused/mhc`
31+
32+
See [docs/operator-coverage.md](docs/operator-coverage.md) for the full list.
33+
34+
## Repository Layout
35+
36+
```text
37+
src/ntops_lab/
38+
catalog.py # manifest loading and query helpers
39+
cli.py # ntops-lab CLI
40+
operator_manifest.json # canonical runnable operator catalog
41+
operators/ # generated NineToothed kernels
42+
docs/
43+
operator-coverage.md # runnable coverage
44+
runnable-operators.md # runnable operator list
45+
unrunnable-operators.md # excluded unsupported operator notes
46+
support-analysis.md # missing capability analysis
47+
tests/
48+
test_catalog.py # CPU-only metadata tests
49+
scripts/
50+
run_operator.py # run one operator's check()
51+
check_manifest.py # validate manifest/file consistency
52+
```
53+
54+
## Install
55+
56+
For metadata inspection and CPU-only tests:
57+
58+
```bash
59+
python -m venv .venv
60+
source .venv/bin/activate
61+
pip install -e ".[dev]"
62+
```
63+
64+
For running kernels, use an environment that already has CUDA, PyTorch, and
65+
NineToothed installed:
66+
67+
```bash
68+
pip install -e ".[dev]"
69+
```
70+
71+
NineToothed and PyTorch are kept as optional GPU dependencies because this
72+
repository is often inspected on machines without a GPU.
73+
74+
## Use The Catalog
75+
76+
```bash
77+
ntops-lab summary
78+
ntops-lab list --status done
79+
ntops-lab list --category reduction
80+
```
81+
82+
From Python:
83+
84+
```python
85+
from ntops_lab import list_operators, runnable_operators
86+
87+
print(len(runnable_operators()))
88+
print(list_operators(category="linear"))
89+
```
90+
91+
## Run A Kernel Smoke Test
92+
93+
On a CUDA machine with NineToothed available:
94+
95+
```bash
96+
ntops-lab check add
97+
python scripts/run_operator.py softmax
98+
```
99+
100+
Most runnable operator modules expose:
101+
102+
```python
103+
make_inputs()
104+
run_ninetoothed(...)
105+
run_pytorch(...)
106+
check()
107+
```
108+
109+
`check()` generates representative inputs, runs the NineToothed kernel, runs
110+
the PyTorch reference, and compares results.
111+
112+
## Run Repository Tests
113+
114+
CPU-only catalog checks:
115+
116+
```bash
117+
python -m pytest
118+
python scripts/check_manifest.py
119+
python -m compileall -q src scripts tests
120+
```
121+
122+
GPU smoke checks should be run selectively:
123+
124+
```bash
125+
ntops-lab check add
126+
ntops-lab check mm
127+
ntops-lab check moe_sum
128+
```
129+
130+
Running every GPU check can take a while because many operators compile kernels
131+
on first use.
132+
133+
## What Is Not Included Yet?
134+
135+
Unsupported scaffold source files are intentionally excluded from this commit-ready tree. Remaining gaps mostly need one of these capabilities:
136+
137+
- complex manual layout/indexing
138+
- dynamic gather/scatter, cache writes, or masked updates
139+
- top-k/sort/histogram/atomic primitives
140+
- cross-tile scan, recurrent state, or triangular solve
141+
- RNG/stateful random distribution support
142+
- normalization backward or running-stat APIs
143+
144+
See [docs/support-analysis.md](docs/support-analysis.md).
145+
146+
## Project Philosophy
147+
148+
This is a practical operator workshop:
149+
150+
- keep each operator in its own file
151+
- keep PyTorch references close to implementations
152+
- make every runnable operator independently smoke-testable
153+
- record why excluded operators are blocked
154+
- prefer clear templates over pretending incomplete kernels are done
155+
156+
## License
157+
158+
Standard MIT License. The MIT license is not versioned, so the repository uses
159+
the canonical MIT text and SPDX-compatible `MIT` package metadata.

‎docs/README.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Documentation
2+
3+
- [Operator coverage](operator-coverage.md)
4+
- [Runnable operators](runnable-operators.md)
5+
- [Unrunnable operators](unrunnable-operators.md)
6+
- [Support analysis](support-analysis.md)
7+
- [Development guide](development-guide.md)

‎docs/development-guide.md‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Development Guide
2+
3+
## Add A New Operator
4+
5+
1. Choose a category under `src/ntops_lab/operators`.
6+
2. Create one file per operator.
7+
3. Include these module-level fields:
8+
9+
```python
10+
OP_NAME = "my_op"
11+
IMPLEMENTATION_STATUS = "implemented_ninetoothed"
12+
SOURCE_PATH = "source/or/reference"
13+
```
14+
15+
4. Implement the standard functions:
16+
17+
```python
18+
def make_inputs(...): ...
19+
def run_ninetoothed(*inputs): ...
20+
def run_pytorch(*inputs): ...
21+
def check(...): ...
22+
```
23+
24+
5. Add the operator to `src/ntops_lab/operator_manifest.json`.
25+
6. Run:
26+
27+
```bash
28+
python scripts/check_manifest.py
29+
ntops-lab check my_op
30+
```
31+
32+
## Mark A Todo Operator
33+
34+
Todo files should stay importable and explain the blocker:
35+
36+
```python
37+
OP_NAME = "blocked_op"
38+
IMPLEMENTATION_STATUS = "needs_manual_ninetoothed_implementation"
39+
REASON = "Needs dynamic scatter/gather support."
40+
```
41+
42+
## Naming
43+
44+
- Use source-facing operator names in the manifest, such as `add_` or
45+
`softmax_out`.
46+
- Use filesystem-safe names for modules, such as `add_inplace.py`.
47+
- Keep category names stable; coverage tooling depends on them.
48+
49+
## Validation Levels
50+
51+
- **Catalog validation**: no GPU required; checks manifest/file consistency.
52+
- **Single-op smoke**: compiles and runs one NineToothed kernel.
53+
- **Batch smoke**: run selected representative operators by category.
54+
55+
Full GPU coverage is intentionally not part of default `pytest`, because kernel
56+
compilation requires a CUDA/NineToothed environment.

0 commit comments

Comments
 (0)