SuperAPI AI Directory

triton-operator-dev

Coding & development

View repository

Updated 10-15 19:58

About this skill

Triton Operator Full-Process Development

Workflow Overview

Building a Triton operator is divided into 7 stages (including 1 conditional stage):

# Stage Output Skill Skippable
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: 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: skipped if ratio ≥ target

⚠️ Core Constraints

  1. Must complete the entire process: stages 3-6 cannot be skipped, and you cannot stop after code generation
  2. Use TaskCreate to track progress: one Task per stage, on entry in_progress, on completion completed
  3. Do not perform performance optimization before precision passes(core principle of precision-eval)
  4. Output final report: precision results + performance ratio + optimization history + conclusion

Scenario Routing

User Intent Correct Approach
"Develop an operator", "develop from scratch" 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 (skippable)

Skip Determination:

  • Stage 1 skip condition: can import torch, torch_npu, triton and torch.npu.is_available()
  • Stage 2 skip condition: the user has already provided a design document (such as docs/context/*.md) or directly given the operator API specification

Stage 3: Code Generation

Call Skill(triton-operator-code-gen). This stageonly generates code and smoke test, does not run。

Before entering the next stage: kernel code + test file have been written to disk

Stage 4: Static Review

Call Skill(triton-operator-code-review). This stageonly performs static analysis, does 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 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 run)

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 performance target required by the user.

Call Skill(triton-operator-performance-optim). After optimizationprecision verification must be re-runto confirm there is no regression.

Common pitfalls

Pitfall Symptom Correct approach
Stop after code generation The user thinks development is complete but there is no verification Force execution of Phases 5-6
Optimize before precision passes Optimized the wrong code Passing precision is a prerequisite for optimization
Skip TaskCreate Phase omissions cannot be traced Create a Task for each phase
Confuse "generating tests" with "running tests" Only test files exist but were never executed Phases 5-6 must actually be run

Anti-pattern list (NEVER)

  • ❌ Stop after code generation without executing precision verification and performance evaluation
  • ❌ Do performance optimization before precision passes
  • ❌ Start execution without creating task tracking
  • ❌ Skip phases but do not update task status
  • ❌ Say "development complete" after only generating code
  • ❌ Use the excuse of "only need code" 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 Mandatory
{算子名}.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