Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions skills/competition/nine-toothed-operator-dev/HONOR_CODE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Honor Code

I confirm that this submission is intended to comply with the NineToothed .skill Innovation Track rules.

- This skill does not contain hidden evaluation answers.
- This skill does not hard-code hidden task names or evaluation-specific bypass logic.
- This skill does not contain API keys, account credentials, private tokens, or unauthorized data.
- This skill does not instruct an AI agent to delete tests, fake benchmark results, bypass validation, or conceal failures.
- External references, public repositories, and AI assistance are disclosed in `REFERENCE.md`.
- Any benchmark or correctness result reported in the final submission should be reproducible from the included commands and environment notes.

Participant signature:

```text
Name: 韩博 (GitHub: tusu-code)
Team: 韩博 / tusu-code (个人参赛 / solo)
Date: 2026-07-11
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# [2026 Spring][T3-1-1] <GitHub ID>

## Skill

- Name: `nine-toothed-operator-dev`
- Team:
- Problem: T3-1-1 NineToothed Operator Development Skill

## Scope

Applicable:

- Elementwise and broadcast operators
- Reduction and block operators
- Non-contiguous, stride, and offset-sensitive tasks
- Correctness tests against PyTorch or existing implementations
- Benchmark, generated source, AOT build, and failing-test diagnosis

Not applicable:

- NineToothed compiler core redesign
- Hidden evaluation answers or task-specific bypasses
- Online-only services or private credentials

## Installation and Usage

Place the skill under:

```text
skills/competition/nine-toothed-operator-dev/
```

Prompt:

```text
Use the nine-toothed-operator-dev skill to implement this NineToothed operator task. Follow the required workflow, add correctness tests, run targeted validation, include benchmark evidence if performance-sensitive, and finish with changed files, commands, results, unsupported cases, and residual risk.
```

## Self-Test Records

| Task | Category | Correctness | Benchmark | Notes |
| --- | --- | --- | --- | --- |
| 01-elementwise-add | Elementwise/broadcast | TODO | TODO | TODO |
| 02-softmax-reduction | Reduction/block | TODO | TODO | TODO |
| 03-layout-stride-offset | Layout-sensitive | TODO | TODO/NA | TODO |
| 04-performance-diagnosis | Performance/diagnosis | TODO | TODO | TODO |

## Before/After Comparison

| Task | Without Skill | With Skill | Improvement |
| --- | --- | --- | --- |
| Elementwise | TODO | TODO | TODO |
| Reduction | TODO | TODO | TODO |
| Layout | TODO | TODO | TODO |
| Diagnosis | TODO | TODO | TODO |

## Validation Commands

```shell
python scripts/check_submission.py --skill-dir .
pytest <targeted-correctness-command>
pytest -m benchmark <targeted-benchmark-command>
```

## Compliance

- [ ] `HONOR_CODE.md` signed
- [ ] `REFERENCE.md` completed
- [ ] No secrets or credentials
- [ ] No hidden answers
- [ ] No test bypasses
- [ ] External references disclosed

## Attachments

- Proposal:
- Final report:
- Self-test logs:
87 changes: 87 additions & 0 deletions skills/competition/nine-toothed-operator-dev/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# NineToothed Operator Development Skill

Competition: 2026 Spring AI Competition, NineToothed .skill Innovation Track

Problem: T3-1-1 NineToothed Operator Development Skill

## Goal

This skill guides an AI agent to implement, test, benchmark, diagnose, and integrate NineToothed operators with a minimal reproducible patch.

It covers:

- elementwise and broadcast operators
- reduction and block operators
- non-contiguous, stride, and offset-sensitive tasks
- correctness tests against PyTorch or existing trusted implementations
- generated source, AOT build, benchmark, and failure diagnosis tasks
- arrangement debugging with `simulate_arrangement` or concrete `arranged.eval()` checks

It does not intentionally cover:

- modifying the NineToothed compiler core
- online-only services
- hidden evaluation answers
- hardware-specific hacks that cannot be reproduced by the judges

## Package Structure

```text
nine-toothed-operator-dev/
SKILL.md
references/
scripts/
examples/
tests/
reports/
README.md
HONOR_CODE.md
REFERENCE.md
```

## Installation

Copy this folder into the competition-designated skills directory. If no directory is specified, use the structure requested by the organizers, for example:

```text
skills/competition/nine-toothed-operator-dev/
```

Then start the AI agent in the NineToothed repository and ask it to use the skill for operator development tasks.

## Suggested Usage Prompt

```text
Use the nine-toothed-operator-dev skill to implement this NineToothed operator task. Follow the required workflow, add correctness tests, run targeted validation, include benchmark evidence if performance-sensitive, and finish with changed files, commands, results, unsupported cases, and residual risk.
```

## Self-Test Tasks

This package includes four self-test task records under `examples/`:

1. `01-elementwise-add`
2. `02-softmax-reduction`
3. `03-layout-stride-offset`
4. `04-performance-diagnosis`

The current self-test records already include the first round of RTX 4090 validation logs. Re-run and update them if the organizers provide a different final repository or evaluation environment.

## Reference Notes

The most important files for an AI agent are:

- `SKILL.md`: required workflow and hard rules.
- `references/nine-toothed-api-notes.md`: NineToothed symbolic tensor, arrangement, application, debugging, and AOT notes.
- `references/operator-patterns.md`: implementation patterns by operator family.
- `references/repository-pattern-index-ninetoothed.md`: public NineToothed repository file index.
- `references/repository-pattern-index-examples.md`: public NineToothed examples repository file index.

## Validation

Run:

```shell
python scripts/check_submission.py --skill-dir .
```

This checks file presence and self-test record structure. It does not replace running the real NineToothed tests or benchmarks.
23 changes: 23 additions & 0 deletions skills/competition/nine-toothed-operator-dev/REFERENCE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# References and Disclosure

## Public References

- NineToothed official repository: https://github.com/InfiniTensor/ninetoothed
- NineToothed examples repository: https://github.com/InfiniTensor/ninetoothed-examples
- NineToothed documentation: https://ninetoothed.org/
- NineToothed official Feishu wiki shared by the competition group: https://gxcttab8no8.feishu.cn/wiki/RSZSwpc9siOEXrkUoVyc2IPtnX3
- InfiniTensor Triton and NineToothed course shared by the competition group: https://www.infinitensor.com/camp/winter2025/stage/1/course/winter2025-triton-and-ninetoothed
- PyTorch documentation: https://pytorch.org/docs/
- Triton documentation: https://triton-lang.org/

## Competition Materials

- NineToothed .skill Innovation Track problem statement and rules, version v0.8.

## AI Assistance Disclosure

This skill package was drafted with AI assistance. The assistance was used to organize workflow instructions, create reusable templates, and prepare reproducibility check scripts. Final correctness results, benchmark results, environment details, and participant identity should be filled in and verified by the participant before submission.

## Third-Party Code

This package includes original instructional text and helper scripts. It references public NineToothed patterns but does not vendor NineToothed source code.
82 changes: 82 additions & 0 deletions skills/competition/nine-toothed-operator-dev/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
---
name: nine-toothed-operator-dev
description: Guide AI agents implementing, testing, benchmarking, diagnosing, or integrating NineToothed GPU operators. Use for NineToothed arrangement/application DSL tasks, operator correctness tests, PyTorch reference comparisons, generated source or AOT build checks, benchmark regression analysis, non-contiguous layout handling, and minimal patch repair work.
---

# NineToothed Operator Development

Use this skill to complete NineToothed operator tasks with a minimal verified patch. The priority order is correctness, reproducibility, repository style, then performance.

## Required Workflow

1. Restate the task contract before editing:
- operator semantics
- input/output tensors
- shape rules
- dtype rules
- broadcasting rules
- boundary behavior
- layout assumptions, including non-contiguous, stride, and offset cases
- unsupported cases
2. Inspect the repository before implementation:
- Search for similar operators, tests, examples, generated source helpers, AOT build paths, and benchmark files.
- Prefer existing NineToothed idioms over new abstractions.
- Read `references/operator-patterns.md` when writing or modifying operator code.
- Read `references/nine-toothed-api-notes.md` when unsure about tensor meta-operations, arrangement shape alignment, debugging, or AOT.
3. Design the arrangement before coding the application:
- Write down the intended outer launch shape for every arranged tensor.
- Ensure all arranged parameter tensors have the same outermost shape unless the repository has an explicit scalar/constexpr pattern.
- Ensure the second outermost tensor level is exactly what each program should consume.
- Use `Tensor(..., other=identity)` for out-of-bound tile values in reductions and boundary-sensitive operators.
4. Implement the smallest repository-style change:
- Use the arrange-and-apply pattern when the repository uses kernel modules.
- Use `@ninetoothed.jit` when the surrounding tests use inline kernels.
- Keep tensor ranks, `Symbol` kinds, `Tensor(..., other=...)`, tiling, flattening, and dtype squeeze/expand behavior explicit.
5. Add or update correctness tests:
- Compare against PyTorch or an existing trusted implementation.
- Cover at least one ordinary case and one boundary/layout case when relevant.
- Read `references/testing.md` before writing tests.
6. Run targeted validation:
- Run the narrowest relevant `pytest` command first.
- If CUDA or dependencies are unavailable, record the exact blocker and still run import/static checks where possible.
- For complex arrangements, validate with `ninetoothed.debugging.simulate_arrangement` or `arranged.eval()` when available.
7. Add performance evidence when the task is performance-sensitive:
- Read `references/performance.md`.
- Benchmark against PyTorch, Triton, or the existing implementation when available.
- Record input sizes, dtype, device, command, timing, and conclusion.
8. Diagnose failures with a closed loop:
- Read `references/failure-diagnosis.md`.
- Record symptom, command, suspected root cause, minimal fix, rerun command, and result.
9. Finish with an audit note:
- changed files
- correctness commands and results
- benchmark commands and results, if any
- unsupported cases
- residual risk

## Hard Rules

- Do not delete, skip, weaken, or fake tests.
- Do not hard-code hidden task names, hidden answers, environment-specific paths, secrets, or online-only dependencies.
- Do not make broad formatting-only changes or unrelated refactors.
- Do not claim benchmark success without command, input scale, device/dtype, and observed result.
- Do not assume contiguous layout unless the task or existing operator explicitly requires it.
- Do not leave generated-source, AOT, or benchmark failures unexplained.

## Reference Routing

- Operator implementation: `references/operator-patterns.md`
- NineToothed API concepts and gotchas: `references/nine-toothed-api-notes.md`
- Correctness tests and self-test design: `references/testing.md`
- Benchmarks and performance analysis: `references/performance.md`
- Generated source, AOT, failing tests, and recovery: `references/failure-diagnosis.md`
- Final competition packaging: `references/final-submission.md`

## Useful Scripts

- `scripts/scan_repo.py --repo <path>`: summarize candidate files and patterns in a NineToothed checkout.
- `scripts/build_pattern_index.py --repo <path> --out references/repository-pattern-index.md`: generate a compact index of nearby operator/test/benchmark files.
- `scripts/make_selftest_task.py --name <task-name> --kind <kind> --out <dir>`: create a self-test task log template.
- `scripts/check_submission.py --skill-dir <path>`: check required competition files and self-test material.

Scripts are helpers only. If a script fails, inspect and continue manually.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
display_name: NineToothed Operator Dev
short_description: Build NineToothed operators well
default_prompt: Use this skill to implement, test, benchmark, and diagnose a NineToothed operator task with a minimal verified patch.
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Self-Test 01: Elementwise Add With Broadcast Awareness

## Category

Elementwise / broadcast operator.

## Input Task Statement

Implement or repair a NineToothed elementwise add-style operator. The operator should accept two tensors, produce an output matching PyTorch addition semantics for the selected supported shapes, and include correctness tests.

Required coverage:

- fp32 correctness
- at least one non-power-of-two size
- explicit note on whether broadcasting is supported
- no unrelated refactor

## Expected Agent Workflow

1. Search for existing add, silu, swiglu, or elementwise kernels.
2. Restate shape, dtype, broadcast, and layout assumptions.
3. Implement the smallest operator or patch.
4. Compare against `torch.add`.
5. Run targeted pytest.
6. Run benchmark if the final environment has CUDA.

## Produced Patch Summary

No source patch was needed for this public-repository self-test. The task verified that the existing NineToothed add operator and the skill's elementwise guidance match the repository pattern.

## Correctness

Command:

```shell
/usr/local/miniconda3/envs/py312/bin/python -m pytest tests/test_ops.py::TestAdd::test_correctness -q
```

Result:

```text
1 passed in 5.58s
```

## Benchmark

Command:

```shell
/usr/local/miniconda3/envs/py312/bin/python -m pytest tests/test_benchmarks.py::TestAddBenchmark::test_benchmark -q -m benchmark
```

Result:

```text
1 passed in 9.80s
```

## Performance Conclusion

Additional custom timing on RTX 4090, torch 2.9.1+cu128, fp16 shape `(98432,)`:

```text
add allclose True
add ninetoothed_ms 0.05119999870657921
add torch_ms 0.020479999482631683
```

Conclusion: correctness is exact for this fp16 elementwise case. PyTorch is faster on the small custom timing, so the skill should require benchmark evidence before claiming an optimization.

## Unsupported Cases

This self-test does not prove broadcasting or non-contiguous support. A separate layout task shows non-contiguous add mismatch in the public examples wrapper.
Loading
Loading