Workflow Overview
Building a Triton operator is divided into 7 stages (including 1 conditional stage):
| # | Stage | Output | Skill | Can It Be Skipped |
|---|---|---|---|---|
| 1 | Environment Configuration | Environment Verification Report | triton-operator-env-config |
Yes: torch/torch_npu/triton already available |
| 2 | Requirements Design | Design Document | triton-operator-design |
Yes: the user has already provided a complete design document |
| 3 | Code Generation | kernel + smoke test | triton-operator-code-gen |
No |
| 4 | Static Review | Review Report | triton-operator-code-review |
No |
| 5 | Precision Verification | Precision Report | triton-operator-precision-eval |
No |
| 6 | Performance Evaluation | Performance Report + ratio | triton-operator-performance-eval |
No |
| 7 | Performance Optimization | Optimized Code | triton-operator-performance-optim |
Conditional: skip if ratio ≥ target |
⚠️ Core Constraints
- The full process must be followed: Stages 3-6 cannot be skipped, and you cannot stop after code generation
- Use TaskCreate to track progress: one Task per stage, on entry
in_progress, after completioncompleted - Do not perform performance optimization before precision passes(the core principle of precision-eval)
- Output the final report: precision results + performance ratio + optimization history + conclusion
Scenario Routing
| User Intent | Correct Approach |
|---|---|
| "Develop an operator", "develop from scratch" | The full process of this skill |
| "Help me write operator code" | Do not use this skill, directly triton-operator-code-gen |
| "Optimize operator performance" | Do not use this skill, directly triton-operator-performance-optim |
| "Check operator precision" | Do not use this skill, directly triton-operator-precision-eval |
Stage Execution Key Points
Stages 1-2: Environment + Design (can be skipped)
Skip Determination:
- Stage 1 skip condition: can
import torch, torch_npu, tritonandtorch.npu.is_available() - Stage 2 skip condition: the user has already provided a design document (such as
docs/context/*.md) or directly provided the operator API specification
Stage 3: Code Generation
Call Skill(triton-operator-code-gen). At this stageonly generate code and smoke test, do not run。
Before entering the next stage: the kernel code + test file have been written to disk
Stage 4: Static Review
Call Skill(triton-operator-code-review). At this stageonly static analysis, do not run。
Before entering the next stage: P0/P1 issues have been fixed
Stage 5: Precision Verification (MANDATORY run)
Call Skill(triton-operator-precision-eval)。
This stage must run tests on the NPU. Key outputs:
- Error metrics for multiple shape × dtype
- Pass/fail determination
Before entering the next phase: all precision tests pass
Phase 6: Performance Evaluation (MANDATORY execution)
Call Skill(triton-operator-performance-eval)。
This phase must run the benchmark on the NPU. Key outputs:
- ratio of Triton vs torch_npu
- Bottleneck type diagnosis
Phase 7: Performance Optimization (conditional execution)
Trigger condition: the ratio in Phase 6 < the user-required performance target.
Call Skill(triton-operator-performance-optim). After optimization,precision verification must be re-runto confirm there is no regression.
Common Pitfalls
| Pitfall | Symptom | Correct approach |
|---|---|---|
| Stopping after code generation | The user thinks development is complete but there is no verification | Mandatorily execute Phases 5-6 |
| Optimizing before precision passes | Optimized the wrong code | Passing precision is a prerequisite for optimization |
| Skipping TaskCreate | Omitted phases cannot be traced | Create a Task for each phase |
| Confusing "generating tests" with "running tests" | Only test files exist but were never executed | Phases 5-6 must actually run |
Anti-pattern Checklist (NEVER)
- ❌ Stopping after code generation without executing precision verification and performance evaluation
- ❌ Doing performance optimization before precision passes
- ❌ Starting execution without creating task tracking
- ❌ Skipping phases but not updating task status
- ❌ Only generating code and then saying "development is complete"
- ❌ Using the excuse of "only code is needed" to skip the verification process
Checklist (confirm before final output)
- code has been generated and passed static review (P0/P1 cleared)
- Precision tests have been run on the NPU, all dtype/shape pass
- Performance tests have been run on the NPU, with ratio data
- when ratio < target, optimization has been attempted and precision re-verified
- Performance report has been generated and written to disk(including ratio data, bottleneck diagnosis, optimization history, conclusion)
- Precision report has been generated and written to disk(including error metrics for multiple shape × dtype, pass/fail determination)
- output the complete final report to the user (precision + performance + conclusion)
Final Deliverables
After the full process is complete,mustoutput the following files in the operator directory:
| File | Content | Required |
|---|---|---|
{算子名}.py |
Kernel code + Host interface | Yes |
test_{算子名}.py |
Smoke test | Yes |
precision_eval.py |
Precision evaluation script | Yes |
precision_report.md |
Precision report | Yes |
performance_eval.py |
Performance evaluation script | Yes |
performance_report.md |
Performance report | Yes |