Skip to content
Merged
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
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,68 @@ julia --project=julia/ julia/test/runtests.jl

See `julia/Project.toml` for the full dependency list.

### 5. Enable the cuTile-rs (Rust) backend (Optional)

A subset of ops ships an additional **cuTile-rs** backend under
[`src/tilegym/ops/cutile_rs`](src/tilegym/ops/cutile_rs) — kernels authored in
Rust with [`cutile-rs`](https://github.com/NVlabs/cutile-rs) and loaded through
a C-ABI `libcutile_kernels.so`. It is opt-in and only usable from a source
checkout.

**Prerequisites** (in addition to the base install above), matching
[cuTile-rs](https://github.com/NVlabs/cutile-rs):

- **Rust 1.89+** — `cargo` and `rustc` on `PATH`:

```bash
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustup default stable
```

- **CUDA toolkit with headers** — the Rust build runs `bindgen` against
`cuda.h`. Set `CUDA_TOOLKIT_PATH` to your install; if unset, cuTile-rs falls
back to `/usr/local/cuda`:

```bash
export CUDA_TOOLKIT_PATH=/usr/local/cuda # must contain include/cuda.h
```

**Use it.** The backend loader builds the shared library lazily on first use
(`cargo build --release`), so no manual build step is required:

```python
import tilegym
tilegym.set_backend("cutile-rs")

from tilegym.backend.selector import get_available_backends
print(get_available_backends()) # should include "cutile-rs"

from tilegym.ops import bmm # backend-agnostic import
# ... bmm(...) now dispatches to the cuTile-rs kernel
```

**Optional environment knobs:**

```bash
export CUTILE_RS_AUTOBUILD=0 # skip the lazy rebuild; use a prebuilt .so
export CUTILE_RS_KERNELS_DIR=/abs/path/to/cutile_kernels # override the crate location
```

> If `cargo` is not on `PATH` and no prebuilt `libcutile_kernels.so` is present,
> the backend reports itself unavailable and cuTile-rs tests are skipped rather
> than failing.

**Benchmarking cuTile-rs.** When comparing cuTile-rs perf against the
cuTile-Python baseline, run the perf tests with **`CUPTI=1`** (uses CUPTI /
`torch.profiler` device time instead of CUDA events). cuTile-rs kernels often
have different host/launch overhead than the reference, which CUDA-event wall
timing over-counts on small (sub-microsecond) kernels; CUPTI measures pure GPU
kernel time and gives a stable, apples-to-apples ratio:

```bash
CUPTI=1 pytest tests/ops/test_bmm.py -k "test_perf and cutile_rs" --print-record
```

## Contributing

We welcome contributions of all kinds. Please read our [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines, including the Contributor License Agreement (CLA) process.
Expand Down
54 changes: 54 additions & 0 deletions README_chs.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,60 @@ julia --project=julia/ julia/test/runtests.jl

完整依赖列表请参阅 `julia/Project.toml`。

### 5. 启用 cuTile-rs (Rust) 后端 (可选)

部分算子在 [`src/tilegym/ops/cutile_rs`](src/tilegym/ops/cutile_rs) 下额外提供了
**cuTile-rs** 后端——内核用 Rust 基于 [`cutile-rs`](https://github.com/NVlabs/cutile-rs)
编写,并通过 C-ABI 的 `libcutile_kernels.so` 加载。该后端为可选项,且仅在源码安装模式下可用。

**前置要求**(在上述基础安装之外),与 [cuTile-rs](https://github.com/NVlabs/cutile-rs) 保持一致:

- **Rust 1.89+**——`cargo` 和 `rustc` 需在 `PATH` 中:

```bash
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustup default stable
```

- **CUDA toolkit 并包含头文件**——Rust 构建会用 `bindgen` 处理 `cuda.h`。请将
`CUDA_TOOLKIT_PATH` 指向你的安装目录;若未设置,cuTile-rs 会回退到 `/usr/local/cuda`:

```bash
export CUDA_TOOLKIT_PATH=/usr/local/cuda # 必须包含 include/cuda.h
```

**使用方法。** 后端加载器会在首次使用时延迟构建共享库(`cargo build --release`),因此无需手动构建:

```python
import tilegym
tilegym.set_backend("cutile-rs")

from tilegym.backend.selector import get_available_backends
print(get_available_backends()) # 应包含 "cutile-rs"

from tilegym.ops import bmm # 与后端无关的导入
# ... bmm(...) 现在会分发到 cuTile-rs 内核
```

**可选环境变量:**

```bash
export CUTILE_RS_AUTOBUILD=0 # 跳过延迟重建;使用预构建的 .so
export CUTILE_RS_KERNELS_DIR=/abs/path/to/cutile_kernels # 覆盖 crate 位置
```

> 若 `cargo` 不在 `PATH` 中且没有预构建的 `libcutile_kernels.so`,该后端会报告为不可用,
> cuTile-rs 相关测试会被跳过而非失败。

**cuTile-rs 性能测试。** 测量 cuTile-rs 性能时,建议用 **`CUPTI=1`** 运行 perf 测试
(使用 CUPTI / `torch.profiler` 的 device time,而非 CUDA events)。cuTile-rs 内核与参考
实现的 host/launch 开销通常不同,CUDA-event 墙钟计时在亚微秒级小内核上会高估这部分开销;
CUPTI 测的是纯 GPU 内核时间,给出更稳定、可对比的结果:

```bash
CUPTI=1 pytest tests/ops/test_bmm.py -k "test_perf and cutile_rs" --print-record
```

## 贡献

我们欢迎各种形式的贡献。请阅读我们的 [CONTRIBUTING.md](CONTRIBUTING.md) 了解指南,包括贡献者许可协议(CLA)流程。
Expand Down
54 changes: 54 additions & 0 deletions README_cht.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,60 @@ julia --project=julia/ julia/test/runtests.jl

完整依賴列表請參閱 `julia/Project.toml`。

### 5. 啟用 cuTile-rs (Rust) 後端 (選填)

部分運算子在 [`src/tilegym/ops/cutile_rs`](src/tilegym/ops/cutile_rs) 下額外提供了
**cuTile-rs** 後端——核心以 Rust 基於 [`cutile-rs`](https://github.com/NVlabs/cutile-rs)
撰寫,並透過 C-ABI 的 `libcutile_kernels.so` 載入。此後端為選填,且僅在原始碼安裝模式下可用。

**前置需求**(在上述基礎安裝之外),與 [cuTile-rs](https://github.com/NVlabs/cutile-rs) 保持一致:

- **Rust 1.89+**——`cargo` 與 `rustc` 需在 `PATH` 中:

```bash
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustup default stable
```

- **CUDA toolkit 並包含標頭檔**——Rust 建置會用 `bindgen` 處理 `cuda.h`。請將
`CUDA_TOOLKIT_PATH` 指向你的安裝目錄;若未設定,cuTile-rs 會回退到 `/usr/local/cuda`:

```bash
export CUDA_TOOLKIT_PATH=/usr/local/cuda # 必須包含 include/cuda.h
```

**使用方法。** 後端載入器會在首次使用時延遲建置共享程式庫(`cargo build --release`),因此無需手動建置:

```python
import tilegym
tilegym.set_backend("cutile-rs")

from tilegym.backend.selector import get_available_backends
print(get_available_backends()) # 應包含 "cutile-rs"

from tilegym.ops import bmm # 與後端無關的匯入
# ... bmm(...) 現在會分派到 cuTile-rs 核心
```

**選填環境變數:**

```bash
export CUTILE_RS_AUTOBUILD=0 # 跳過延遲重建;使用預先建置的 .so
export CUTILE_RS_KERNELS_DIR=/abs/path/to/cutile_kernels # 覆寫 crate 位置
```

> 若 `cargo` 不在 `PATH` 中且沒有預先建置的 `libcutile_kernels.so`,此後端會回報為不可用,
> cuTile-rs 相關測試會被略過而非失敗。

**cuTile-rs 效能測試。** 量測 cuTile-rs 效能時,建議以 **`CUPTI=1`** 執行 perf 測試
(使用 CUPTI / `torch.profiler` 的 device time,而非 CUDA events)。cuTile-rs 核心與參考
實作的 host/launch 開銷通常不同,CUDA-event 牆鐘計時在次微秒級小核心上會高估此開銷;
CUPTI 量測純 GPU 核心時間,給出更穩定、可對比的結果:

```bash
CUPTI=1 pytest tests/ops/test_bmm.py -k "test_perf and cutile_rs" --print-record
```

## 貢獻

我們歡迎各種形式的貢獻。請閱讀我們的 [CONTRIBUTING.md](CONTRIBUTING.md) 了解指南,包括貢獻者授權協議(CLA)流程。
Expand Down
61 changes: 61 additions & 0 deletions README_fr.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,67 @@ julia --project=julia/ julia/test/runtests.jl

Consultez `julia/Project.toml` pour la liste complète des dépendances.

### 5. Activer le backend cuTile-rs (Rust) (Optionnel)

Un sous-ensemble d'opérateurs fournit un backend **cuTile-rs** supplémentaire sous
[`src/tilegym/ops/cutile_rs`](src/tilegym/ops/cutile_rs) — des noyaux écrits en Rust
avec [`cutile-rs`](https://github.com/NVlabs/cutile-rs) et chargés via une
`libcutile_kernels.so` à ABI C. Il est optionnel et utilisable uniquement depuis une
installation depuis les sources.

**Prérequis** (en plus de l'installation de base ci-dessus), conformes à
[cuTile-rs](https://github.com/NVlabs/cutile-rs) :

- **Rust 1.89+** — `cargo` et `rustc` dans le `PATH` :

```bash
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustup default stable
```

- **CUDA toolkit avec les en-têtes** — la compilation Rust exécute `bindgen` sur
`cuda.h`. Définissez `CUDA_TOOLKIT_PATH` vers votre installation ; s'il n'est pas
défini, cuTile-rs utilise `/usr/local/cuda` par défaut :

```bash
export CUDA_TOOLKIT_PATH=/usr/local/cuda # doit contenir include/cuda.h
```

**Utilisation.** Le chargeur du backend compile la bibliothèque partagée de façon paresseuse
lors de la première utilisation (`cargo build --release`), aucune étape de compilation manuelle n'est donc requise :

```python
import tilegym
tilegym.set_backend("cutile-rs")

from tilegym.backend.selector import get_available_backends
print(get_available_backends()) # doit inclure "cutile-rs"

from tilegym.ops import bmm # import indépendant du backend
# ... bmm(...) est désormais dispatché vers le noyau cuTile-rs
```

**Variables d'environnement optionnelles :**

```bash
export CUTILE_RS_AUTOBUILD=0 # ignorer la recompilation paresseuse ; utiliser un .so pré-compilé
export CUTILE_RS_KERNELS_DIR=/abs/path/to/cutile_kernels # remplacer l'emplacement du crate
```

> Si `cargo` n'est pas dans le `PATH` et qu'aucune `libcutile_kernels.so` pré-compilée n'est présente,
> le backend se déclare indisponible et les tests cuTile-rs sont ignorés plutôt qu'échoués.

**Benchmark de cuTile-rs.** Pour mesurer les performances de cuTile-rs, exécutez les tests
de perf avec **`CUPTI=1`** (utilise le temps GPU de CUPTI / `torch.profiler` au lieu des
CUDA events). Les noyaux cuTile-rs ont souvent une surcharge host/launch différente de la
référence, que le chronométrage en temps réel des CUDA events surestime sur les petits
noyaux (sous la microseconde) ; CUPTI mesure le temps GPU pur du noyau et donne un ratio
stable et comparable :

```bash
CUPTI=1 pytest tests/ops/test_bmm.py -k "test_perf and cutile_rs" --print-record
```

## Contribution

Nous accueillons les contributions de toutes sortes. Veuillez lire notre [CONTRIBUTING.md](CONTRIBUTING.md) pour les directives, y compris le processus d'accord de licence de contributeur (CLA).
Expand Down
57 changes: 57 additions & 0 deletions README_ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,63 @@ julia --project=julia/ julia/test/runtests.jl

依存関係の詳細は `julia/Project.toml` を参照してください。

### 5. cuTile-rs (Rust) バックエンドの有効化 (オプション)

一部の演算子は [`src/tilegym/ops/cutile_rs`](src/tilegym/ops/cutile_rs) の下に追加の
**cuTile-rs** バックエンドを提供します。カーネルは [`cutile-rs`](https://github.com/NVlabs/cutile-rs)
を用いて Rust で記述され、C-ABI の `libcutile_kernels.so` を介して読み込まれます。
これはオプションであり、ソースからのインストール時のみ利用できます。

**前提条件**(上記の基本インストールに加えて)、[cuTile-rs](https://github.com/NVlabs/cutile-rs) に準拠:

- **Rust 1.89+** — `cargo` と `rustc` が `PATH` にあること:

```bash
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustup default stable
```

- **CUDA toolkit(ヘッダー付き)** — Rust ビルドは `bindgen` で `cuda.h` を処理します。
`CUDA_TOOLKIT_PATH` をインストール先に設定してください。未設定の場合、cuTile-rs は
`/usr/local/cuda` にフォールバックします:

```bash
export CUDA_TOOLKIT_PATH=/usr/local/cuda # include/cuda.h を含む必要があります
```

**使い方。** バックエンドローダーは初回使用時に共有ライブラリを遅延ビルドする(`cargo build --release`)ため、手動ビルドは不要です:

```python
import tilegym
tilegym.set_backend("cutile-rs")

from tilegym.backend.selector import get_available_backends
print(get_available_backends()) # "cutile-rs" が含まれるはずです

from tilegym.ops import bmm # バックエンド非依存のインポート
# ... bmm(...) が cuTile-rs カーネルにディスパッチされます
```

**オプションの環境変数:**

```bash
export CUTILE_RS_AUTOBUILD=0 # 遅延リビルドをスキップし、ビルド済み .so を使用
export CUTILE_RS_KERNELS_DIR=/abs/path/to/cutile_kernels # crate の場所を上書き
```

> `cargo` が `PATH` になく、ビルド済みの `libcutile_kernels.so` も存在しない場合、
> バックエンドは利用不可として報告され、cuTile-rs のテストは失敗せずスキップされます。

**cuTile-rs のベンチマーク。** cuTile-rs の性能を測定する際は、**`CUPTI=1`** を付けて perf
テストを実行してください(CUDA events ではなく CUPTI / `torch.profiler` のデバイス時間を使用)。
cuTile-rs カーネルは参照実装と host/launch オーバーヘッドが異なることが多く、CUDA-event の
実時間計測はサブマイクロ秒の小さなカーネルでこれを過大に数えます。CUPTI は純粋な GPU カーネル
時間を測定し、安定した比較可能な結果を与えます:

```bash
CUPTI=1 pytest tests/ops/test_bmm.py -k "test_perf and cutile_rs" --print-record
```

## コントリビューション

あらゆる種類のコントリビューションを歓迎します。ガイドラインについては、コントリビューターライセンス契約(CLA)プロセスを含む [CONTRIBUTING.md](CONTRIBUTING.md) をお読みください。
Expand Down
19 changes: 19 additions & 0 deletions format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,24 @@ echo ""
echo "✨ Formatting code..."
python3 -m ruff format .

echo ""
echo "🦀 Formatting Rust (.rs) files..."
# rustfmt is optional: most contributors are Python-only and have no Rust
# toolchain. Skip (with a hint) when it is absent instead of force-installing.
# Run rustfmt per-file rather than `cargo fmt` so standalone .rs (cutile-rs
# skill examples, per-op kernel.rs/ffi.rs) are covered, not just crate members.
if command -v rustfmt >/dev/null 2>&1; then
rs_files=$(git ls-files '*.rs')
if [ -n "$rs_files" ]; then
echo "$rs_files" | xargs rustfmt --edition 2024
echo "✅ rustfmt formatted $(printf '%s\n' "$rs_files" | wc -l) .rs file(s)."
else
echo "No tracked .rs files; skipping rustfmt."
fi
else
echo "⚠️ rustfmt not found — skipping .rs formatting."
echo " Install with: rustup component add rustfmt (see https://rustup.rs)"
fi

echo ""
echo "✅ Done! SPDX headers added, code is formatted, and imports are sorted."
Loading
Loading