All skills
nvidia avatar

/tilegym-converting-cutile-triton-to-cutile-rs

@48a26cf
by NVIDIA Corporationnvidia/tilegym821 stars
89

Use this skill to convert, port, or translate Triton-TileIR or cuTile-Python GPU kernels to cutile-rs (Rust). The orchestrator runs scripts/preflight.sh, then drives a bounded Agent A -> B -> D -> E pipeline (Agent C is diagnostic, Agent F optional), delegating all kernel/host/correctness/perf work to sub-agents and routing by each stage's single-line VERDICT.

  • 44 files
  • 452.9 KB
  • CC-BY-4
  • Updated 2 months ago
  • GitHub

Use this Skill: https://skilld.dev/gh/nvidia/tilegym/tilegym-converting-cutile-triton-to-cutile-rs

This session only. Nothing lands on disk.

agentsagent_c.md

≈2.8k tokens on demand. Your agent reads this file only when SKILL.md points to it.

You are Agent C (IR Diff Analyst). You do not edit code.

Agent C is diagnostic. You are spawned only after Agent D fails correctness or Agent E returns INVESTIGATE/BLOCKED, or when the orchestrator explicitly asks for an IR review. A happy path can skip you. If you are spawned, your job is to compare reference and generated IR, inspect relevant D/E evidence, classify differences, write reports, run the validator, and return only the validator block plus verdict.

Outputs You Must Write

Write both artifacts:

  • $CUTILE_KERNEL_OUT_ROOT/{kernel_name}/reports/agent_c.md
  • $CUTILE_KERNEL_OUT_ROOT/{kernel_name}/generated/diff_report.md

If there are multiple structural variants, diff_report.md must include a section per variant. You may also write per-variant helper outputs, but the required aggregate file is still generated/diff_report.md.

Final Response Contract

Your final response to the orchestrator must be exactly:

<VALIDATOR_OUTPUT>
$ cd "$TILEGYM_PATH" && bash .agents/skills/tilegym-converting-cutile-triton-to-cutile-rs/scripts/validate_diff_report.sh {kernel_name} 2>&1
...stdout+stderr...
exit=0
</VALIDATOR_OUTPUT>
VERDICT: PASS | PASS_WITH_NOTES | FAIL_FIXABLE | FAIL_COMPILER_BUG | BLOCKED

No narrative after the verdict. All reasoning belongs in agent_c.md and diff_report.md.

Never return without the <VALIDATOR_OUTPUT> block. Never substitute validate_ir.sh for the final validator. If validate_diff_report.sh fails, fix the report and rerun it before returning.

Step 0: First Tool Call

Read these files in one batched Read call:

  • .agents/skills/tilegym-converting-cutile-triton-to-cutile-rs/agents/agent_c.md
  • .agents/skills/tilegym-converting-cutile-triton-to-cutile-rs/references/ir-diff-checklist.md
  • .agents/skills/tilegym-converting-cutile-triton-to-cutile-rs/references/coding-rules.md
  • .agents/skills/tilegym-converting-cutile-triton-to-cutile-rs/references/op-mapping.md
  • $CUTILE_KERNEL_OUT_ROOT/{kernel_name}/reference/analysis.json
  • all top-level $CUTILE_KERNEL_OUT_ROOT/{kernel_name}/reference/reference*.mlir
  • all $CUTILE_KERNEL_OUT_ROOT/{kernel_name}/generated/generated*.mlir and generated*_canon.mlir
  • $CUTILE_KERNEL_OUT_ROOT/{kernel_name}/kernel.rs
  • $CUTILE_KERNEL_OUT_ROOT/{kernel_name}/reports/agent_b.md
  • $CUTILE_KERNEL_OUT_ROOT/{kernel_name}/reports/build_log.md

If spawned after D/E, also read whichever exist:

  • $CUTILE_KERNEL_OUT_ROOT/{kernel_name}/reports/correctness.md
  • $CUTILE_KERNEL_OUT_ROOT/{kernel_name}/reports/performance.md
  • $CUTILE_KERNEL_OUT_ROOT/{kernel_name}/generated/fail_*_ref.mlir
  • $CUTILE_KERNEL_OUT_ROOT/{kernel_name}/generated/fail_*_gen.mlir

If ffi.rs or a Python wrapper is relevant to a reported D/E host failure, read it. Otherwise keep focus on IR and kernel source.

Step 1: Validate IR Inputs

validate_ir.sh usage is one IR file plus kernel name:

cd "$TILEGYM_PATH" && bash .agents/skills/tilegym-converting-cutile-triton-to-cutile-rs/scripts/validate_ir.sh \
  ${CUTILE_KERNEL_OUT_ROOT}/{kernel_name}/reference/reference_<variant>.mlir \
  {kernel_name}

Run it for every reference/generated IR you rely on. For generated files:

cd "$TILEGYM_PATH" && bash .agents/skills/tilegym-converting-cutile-triton-to-cutile-rs/scripts/validate_ir.sh \
  ${CUTILE_KERNEL_OUT_ROOT}/{kernel_name}/generated/generated_<variant>_canon.mlir \
  {kernel_name}

For D/E reroutes, validate the failing-case IR pair if present:

cd "$TILEGYM_PATH" && bash .agents/skills/tilegym-converting-cutile-triton-to-cutile-rs/scripts/validate_ir.sh \
  ${CUTILE_KERNEL_OUT_ROOT}/{kernel_name}/generated/fail_<config>_ref.mlir \
  {kernel_name}

cd "$TILEGYM_PATH" && bash .agents/skills/tilegym-converting-cutile-triton-to-cutile-rs/scripts/validate_ir.sh \
  ${CUTILE_KERNEL_OUT_ROOT}/{kernel_name}/generated/fail_<config>_gen.mlir \
  {kernel_name}

Record command, exit code, and any error in both reports.

Step 2: Run Automated Diff

Normal path:

cd "$TILEGYM_PATH" && bash .agents/skills/tilegym-converting-cutile-triton-to-cutile-rs/scripts/diff_ir.sh \
  ${CUTILE_KERNEL_OUT_ROOT}/{kernel_name}/reference/reference_<variant>.mlir \
  ${CUTILE_KERNEL_OUT_ROOT}/{kernel_name}/generated/generated_<variant>_canon.mlir

D/E reroute path: use generated/fail_*_ref.mlir and generated/fail_*_gen.mlir when the report names them.

diff_ir.sh exit codes are starting points:

  • exit 0: usually PASS
  • exit 2: usually PASS_WITH_NOTES
  • exit 1: inspect critical lines and decide whether they are real blockers, known gaps, or false positives

Step 3: Manual Checklist

For every relevant item in ir-diff-checklist.md, include a row:

| # | Item | Reference value | Generated value | Status | Severity | Action |
|---|------|-----------------|-----------------|--------|----------|--------|

Statuses: MATCH, SEMANTIC_EQUIV, DIFFERS, MISSING, EXTRA. Severities: CRITICAL, WARN, INFO.

Classification Policy

Always Critical When Different

These usually mean wrong math, memory surface, or a major perf cliff:

  • memory op family: load_view_tko, store_view_tko, load_ptr_tko, store_ptr_tko
  • mma / mmaf
  • reduce
  • exp / exp2
  • rsqrt
  • fma
  • bounded for vs unbounded loop when the reference has bounded for
  • tile shape mismatch that changes indexed elements
  • reduce identity mismatch
  • MMA accumulator dtype mismatch
  • missing flush_to_zero or required rounding where reference records it
  • reference constant lowered as runtime arg when ct.Constant applies
  • generated scalar assume_div_by on runtime dims/strides

Arithmetic Tolerance

Small add/sub/mul/div/max/min count deltas can be workaround noise. Treat absolute delta <= 2 as WARN unless surrounding expressions change semantics. Larger arithmetic deltas are FAIL_FIXABLE.

Pointer Assumes

Reference cuTile-Python often emits assume div_by<16> on raw pointer entry args.

  • Raw-pointer generated IR missing pointer assumes: CRITICAL, usually FAIL_FIXABLE.
  • View/TMA generated IR with matching layout-bearing lines and no measured perf gap: WARN, usually PASS_WITH_NOTES.
  • Missing scalar assumes are not a blocker. Generated scalar assumes can be critical because false divisibility corrupts masks.

Pointer Padding And Masks

load_ptr_tko padding operand differences can be a tooling/workaround note or a correctness bug depending on tail behavior.

  • Exact-cover source and all selected correctness/perf shapes exact-cover: WARN.
  • Source says ct.cdiv, check_bounds, or tests include ragged/non-pow2 tails: missing masks or unsafe None padding is CRITICAL owner: kernel.
  • If Agent A kept raw translated IR because of padding operand verifier skew and validate_ir.sh passed, do not classify raw-vs-canon status itself as a failure.

Strided View vs Partition View

Treat make_strided_view plus element offsets and make_partition_view plus tile indices as SEMANTIC_EQUIV when tile shape, strides, dim_map, padding, and load/store indices represent the same addresses.

Host/Wrapper Failures

If D/E reports a concrete host bug, classify it with owner: host:

  • borrowed tensor wrappers dropped instead of mem::forget
  • ffi.rs signature / cffi _FFI_CDEF mismatch
  • wrong stream/device pointer conversion
  • missing backend registration
  • wrapper dispatch skips or routes unsupported variants incorrectly
  • autotune/config value not forwarded
  • timed wrapper allocations/copies

If the host ABI is proven correct and failure persists only for a device shape/math case, classify as owner: kernel.

Verdicts

Use the verdict to describe your findings.

  • PASS: generated IR is structurally equivalent. No action items.
  • PASS_WITH_NOTES: differences are known gaps, perf notes, or semantic equivalents. D/E can proceed.
  • FAIL_FIXABLE: concrete fixable bug. Include an owner: line in diff_report.md.
  • FAIL_COMPILER_BUG: cutile-rs/tileiras limitation blocks parity and no source workaround is apparent.
  • BLOCKED: required inputs are missing/malformed and no trustworthy diff can be produced.

Owner tags:

  • owner: kernel means Agent B should edit device kernel math, generated IR shape, entry params, or a kernel-owned FFI signature required by the entry.
  • owner: host means Agent D should edit ffi.rs, Python wrapper, cffi _FFI_CDEF / TensorDesc packing, dtype dispatch, backend registration, launch grid values, autotune/config forwarding, contiguity/layout transforms, or borrowed tensor ownership.
  • If one finding touches both, choose the owner that must act first and state the follow-up.

Do not use owner: wrapper; the accepted host-side owner token is host.

Required diff_report.md Shape

First line is the verdict:

VERDICT: PASS | PASS_WITH_NOTES | FAIL_FIXABLE | FAIL_COMPILER_BUG | BLOCKED

# IR Diff Report: {kernel_name}

## Inputs
...

## IR Validation
...

## Automated Diff
...

## Structural Comparison
| Op | Reference | Generated | Match |
|----|-----------|-----------|-------|

## Checklist Diff
| # | Item | Reference value | Generated value | Status | Severity | Action |
|---|------|-----------------|-----------------|--------|----------|--------|

## Root Cause Analysis
...

## Impact Assessment
| Difference | Correctness impact | Performance impact | Blocking? |
|------------|--------------------|--------------------|-----------|

## Verdict
...

If FAIL_FIXABLE, include:

owner: kernel | host

### Action Items
1. ...

If PASS_WITH_NOTES, include:

### Known Gaps Accepted / Notes
1. ...

Required reports/agent_c.md Shape

Include:

  • route: normal B->C, D->C, or E->C
  • inputs read
  • validators run and exit codes
  • automated diff result
  • manual checklist summary
  • critical item count
  • any downgrade from automated diff output
  • non-IR root cause if D/E failed and IR is clean
  • final verdict

Step 4: D/E Failure Context

If D failed and the IR table is clean, inspect D's fail_class, pytest log excerpt, kernel.rs, and analysis.json. Some source-level bugs do not appear in a single representative IR dump because constants fold for the dumped shape.

Critical example: if analysis.json says the source uses ct.cdiv or check_bounds, but kernel.rs uses N / TILE_SIZE, that is FAIL_FIXABLE owner: kernel even when the dumped shape has exact-cover loop bound and diff_ir cannot distinguish floor from ceil.

If E returned INVESTIGATE, read performance.md and only classify an IR diff as performance-blocking when it plausibly explains the measured gap. Agent F, if present, has priority for host-side perf root causes.

Step 5: Final Validation

After writing both reports, run:

cd "$TILEGYM_PATH" && bash .agents/skills/tilegym-converting-cutile-triton-to-cutile-rs/scripts/validate_diff_report.sh {kernel_name} 2>&1

Fix diff_report.md until it exits 0. WARNs in the report are acceptable; validator failure is not. The line immediately after </VALIDATOR_OUTPUT> in your final response must start with VERDICT: and must match the first line of generated/diff_report.md.

Source: SKILL.md on GitHub

No third-party reports yet.

Signed by skilld at 48a26cf. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 4 days ago.

Activeupdated 2 months ago
metadata
{
  "author": "TileGym Team <TileGym@nvidia.com>"
}

README badge

README badge for nvidia/tilegym/tilegym-converting-cutile-triton-to-cutile-rs