Tilegym Converting Cutile To Julia

作者 nvidiacf5224d14250CC-BY-4.0 AND Apache-2.03.5K 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫今天更新

Converts cuTile Python GPU kernels (@ct.kernel) to cuTile.jl Julia equivalents. Handles kernel syntax translation, 0-indexed to 1-indexed conversion, broadcasting differences, memory layout (row-major to column-major), type system mapping, and launch API differences. Use when converting, porting, or translating cuTile Python kernels to Julia cuTile.jl, or debugging/optimizing existing Julia cuTile translations.

AI 產生的概覽

將 cuTile Python GPU 核心轉換為 cuTile.jl Julia 等效實作,並提供規則、範例與靜態驗證器。

功能
指導把 cuTile Python 的 @ct.kernel GPU 核心轉譯為 cuTile.jl 的 Julia 核心,涵蓋語法、索引方式、廣播、記憶體佈局與啟動 API 的差異。它提供轉換工作流程、API 對應、關鍵規則、除錯與測試參考,以及 add、matmul、softmax 的 Python 與 Julia 對照範例。它另外附帶一個 Python 指令碼,用於靜態檢查 Julia 檔案中的 cuTile 反模式。
適用情境
適用於將 cuTile Python 核心移植或轉譯為 Julia cuTile.jl 的情境,也用於除錯與最佳化既有的 Julia cuTile 轉譯。為轉換後的核心撰寫 Julia 原生測試時同樣適用。
執行需求
需要 julia/Project.toml 中宣告的 Julia 版本、CUDA 13.1+ 驅動程式、Blackwell GPU(運算能力 10+),以及透過 Pkg.instantiate 安裝的 Julia 套件 CUDA.jl、cuTile.jl、NNlib.jl 與 Test。此技能附帶可執行指令碼,其中包括一個 Python 驗證器。

cuTile Python → cuTile.jl (Julia) Conversion

Convert @ct.kernel Python kernels to Julia function ... end cuTile.jl kernels.

Workflow Selection

  • Standard conversion → Full workflow: translations/workflow.md [blocked]
  • Errors (MethodError, IRError, numerical mismatch) → references/debugging.md [blocked]
  • Quick reference → references/api-mapping.md [blocked] + references/critical-rules.md [blocked]
  • Test patterns → references/testing.md [blocked]

Architecture

Julia kernels are standalone — no Python bridge, no pytest integration. The Julia sub-project lives in julia/ at the repo root with its own Project.toml for dependency management.

julia/                          # Self-contained Julia sub-project├── Project.toml                # Dependencies: CUDA.jl, cuTile.jl, NNlib.jl, Test├── kernels/                    # cuTile.jl kernel implementations│   ├── add.jl                  # ← Ground-truth: 1D element-wise with alpha scaling (tensor+tensor, tensor+scalar)│   ├── matmul.jl               # ← Ground-truth: 2D tiled MMA, standard Julia layout (M,K)×(K,N)→(M,N)│   └── softmax.jl              # ← Ground-truth: 3 strategies (TMA, online, chunked) using ct.load/ct.store└── test/                       # Julia-native tests (using Test stdlib)    ├── runtests.jl             # Test runner entry point    ├── test_add.jl    ├── test_matmul.jl    └── test_softmax.jl

Ground-truth reference: Always consult julia/kernels/*.jl and julia/test/*.jl for patterns that compile and pass tests. These are the canonical examples of working cuTile.jl code.

Instructions

  1. Analyze the Python kernel: identify patterns, shapes, dtypes, operations
  2. Write Julia kernel — julia/kernels/<op>.jl with cuTile.jl kernel + bridge function(s)
  3. Convert kernel signature (see translations/workflow.md Phase 2)
  4. Convert kernel body (apply references/api-mapping.md + references/critical-rules.md)
  5. Write Julia test — julia/test/test_<op>.jl using Test stdlib + NNlib.jl for reference
  6. Register test — add include(...) in julia/test/runtests.jl
  7. Validate — run the bundled validator: python <skill-dir>/scripts/validate_cutile_jl.py <file.jl>
  8. Test — run julia --project=julia/ julia/test/runtests.jl

Full conversion checklist with post-conversion verification → translations/workflow.md [blocked]

⚠️ Top Pitfalls

The most dangerous translation errors. Full rules (17 total) in references/critical-rules.md [blocked].

#PitfallOne-line fix
1ct.full() doesn't exist in JuliaUse fill(val, shape), zeros(T, dims...), or ones(T, dims...)
2max(a, b) on tiles → IRErrorUse max.(a, b) (broadcast dot)
3IRError / MethodError mentioning IRStructurizerCompiler bug — file upstream with minimal reproducer
4ct.launch arg order silently wrongArgs are positional — match kernel signature exactly
5ct.load with order — index positions wrongorder remaps BOTH shape AND index (Critical Rule 16)

Worked Examples

Side-by-side Python → Julia conversions matching the released Julia kernels in julia/kernels/. Each directory contains cutile_python.py (before) and cutile_julia.jl (after).

#ExampleKey PatternsWhen to Reference
01add [blocked]1D ct.load/ct.store, alpha scaling, scalar broadcast, fill/zeros, keyword load/storeStarting point; basic TMA + element-wise patterns
02matmul [blocked]muladd, TF32 conversion, K-loop with for, 2D swizzle, standard Julia layout, ct.@compiler_optionsMMA / tensor core operations
03softmax [blocked]Persistent scheduling, for loops, gather/scatter, padding_mode, multi-passLarge-tensor reduction patterns

These match the released kernels in julia/kernels/ (add.jl, matmul.jl, softmax.jl). The examples are simplified teaching versions — always consult julia/kernels/*.jl for the canonical, tested implementations.

Reference Documents

CategoryDocumentContent
Workflowstranslations/workflow.md [blocked]Full conversion workflow with todo list, validation loop, checklist
Rulesreferences/critical-rules.md [blocked]17 Critical Rules for cuTile Python → Julia conversion
APIreferences/api-mapping.md [blocked]Python↔Julia bidirectional API mapping + kernel patterns
Testingreferences/testing.md [blocked]Julia-native test patterns, tolerances, failure diagnosis
Debuggingreferences/debugging.md [blocked]Julia-specific error diagnosis + IR debug commands
Scriptsscripts/validate_cutile_jl.py [blocked]Static validation for Julia anti-patterns (run it)
Ground Truthjulia/kernels/*.jl + julia/test/*.jlActual working implementations in the codebase

Environment Setup

Prerequisite — Julia: this skill requires the Julia version declared in julia/Project.toml under [compat] julia. If julia --version is missing or older than that, install from the official Julia site at https://julialang.org/install/ following the verified installer instructions for your OS. Resume below once julia --version is compatible.

Then, from the repo root:

bash
# Install Julia dependencies declared in julia/Project.tomljulia --project=julia/ -e 'using Pkg; Pkg.instantiate()'
# Run testsjulia --project=julia/ julia/test/runtests.jl

Requirements:

  • Julia (minimum version declared in julia/Project.toml under [compat] julia)
  • CUDA 13.1+ driver
  • Blackwell GPU (compute capability 10+)
  • Dependencies managed via julia/Project.toml: CUDA.jl, cuTile.jl, NNlib.jl, Test

來源與署名

來源:nvidia/skills位於skills/tilegym-converting-cutile-to-julia提交cf5224d

授權條款: CC-BY-4.0 AND Apache-2.0

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架