Skip to content
Open
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
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,40 @@ print(f'Final state shape: {final_state.shape}') # [2, 32, 128, 128]
- `beta` supports both `float32` and `bfloat16`; `initial_state` must be `float32`.
- `cu_seqlens` (for variable-length sequences) must be `int32`.

### Gated DeltaNet-2 Prefill β€” Hopper (SM90)

```python
import torch

from cula.gdn2 import chunk_gdn2

q = torch.randn(66, 16, 128, device="cuda", dtype=torch.bfloat16)
k = torch.randn_like(q)
v = torch.randn(66, 32, 128, device="cuda", dtype=torch.bfloat16)
g = -torch.rand_like(q, dtype=torch.float32) * 0.05
b = torch.rand_like(q)
w = torch.rand_like(v)
cu_seqlens = torch.tensor([0, 65, 66], device="cuda", dtype=torch.int64)

output, final_state = chunk_gdn2(
q,
k,
v,
g,
b,
w,
cu_seqlens=cu_seqlens,
output_final_state=True,
)
```

The SM90a CuTe DSL backend supports packed MHA, GVA2, and GVA4 with
`Hq=16`, `Hv={16,32,64}`, `K=V=128`, and up to 32 non-empty sequences.
Q/K/V/B/W are BF16, G and recurrent state are FP32, and state uses public
`[N,Hv,V,K]` orientation. Unsupported inputs fail explicitly without a
fallback. See the [GDN2 SM90 API guide](docs/gdn2_sm90_api.md) and
[GDN2 SM90 pipeline](docs/gdn2_sm90_pipeline.md).

## Usage

See [USAGE.md](USAGE.md) for detailed usage examples and notes.
Expand Down Expand Up @@ -176,6 +210,11 @@ python benchmarks/bench_la_decode_vs_fla.py --heads 64 --head-dim 128
# Hopper (SM90)
python benchmarks/bench_kda_sm90_prefill.py --mode both
python benchmarks/bench_kda_sm90_cp.py

# GDN2 prefill β€” canonical five-row SM90 product/FLA matrix
python benchmarks/bench_gdn2_prefill.py \
--implementation both \
--output gdn2-sm90-benchmark.json
```

## Tests
Expand All @@ -193,6 +232,16 @@ python tests/test_lightning_sm100_prefill.py
python -m pytest tests/test_lightning_attn_prefill_dispatch.py tests/test_lightning_attn_prefill_sm90.py -v
# Tests for Lightning Attention decode
python -m pytest tests/test_lightning_decode.py -v
# Tests for GDN2 SM90 product dispatch and tokenwise correctness
python -m pytest tests/gdn2/test_gdn2_prefill_sm90.py -v
# GDN2 SM90 deterministic stress: one process, 100,000 product launches
python tests/gdn2/stress_gdn2_sm90.py \
--iterations 100000 \
--output gdn2-sm90-stress.json
# GDN2 SM90 memcheck/initcheck/synccheck/racecheck, 120 launches per tool
tests/gdn2/run_compute_sanitizer_sm90.sh \
gdn2-sm90-sanitizers \
120

# test_kda_sm100_chunk_vs_naive.py and test_kda_sm100_chunk_vs_fla.py support a fast/slow split.
# Fast (default) β€” representative correctness paths for default CI and local iteration
Expand Down
9 changes: 9 additions & 0 deletions REPO_LAYOUT.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ cuLA/
β”‚ β”œβ”€β”€ cudac.py # Lazy proxy for the per-architecture CUDA extension
β”‚ β”œβ”€β”€ utils.py # Architecture, stream-buffer, and cu_seqlens helpers
β”‚ β”‚
β”‚ β”œβ”€β”€ gdn2/ # [non-KDA] Gated DeltaNet-2 public API
β”‚ β”‚
β”‚ β”œβ”€β”€ kda/ # KDA public API, wrappers, autograd, routing, and Triton support kernels
β”‚ β”‚ β”œβ”€β”€ __init__.py # Lazy exports for chunk, prefill, and decode APIs
β”‚ β”‚ β”œβ”€β”€ backends/ # kda_prefill runtime dispatch
Expand All @@ -32,6 +34,12 @@ cuLA/
β”‚ └── ops/ # CuTeDSL kernels and shared low-level helpers
β”‚ β”œβ”€β”€ inv.py / ptx.py # Shared low-level helpers
β”‚ β”œβ”€β”€ sm100/ptx.py # Shared SM100 PTX helpers
β”‚ β”œβ”€β”€ gdn2/ # [non-KDA] Gated DeltaNet-2 prefill kernels
β”‚ β”‚ └── sm90/ # SM90a CuTe DSL implementation
β”‚ β”‚ β”œβ”€β”€ config.py # Host-side product contract and supported ranges
β”‚ β”‚ β”œβ”€β”€ prefill.py # Validation, compile cache, and TVM-FFI launch
β”‚ β”‚ β”œβ”€β”€ prefill_kernel.py # Fused packed recurrent prefill kernel
β”‚ β”‚ └── collective_inverse_hmma.py / inverse_helpers.py # Triangular inverse
β”‚ β”œβ”€β”€ kda/
β”‚ β”‚ β”œβ”€β”€ cp_mode.py # Shared intracard-CP mode vocabulary
β”‚ β”‚ β”œβ”€β”€ sm100/ # Blackwell modular forward/backward kernels
Expand Down Expand Up @@ -82,5 +90,6 @@ cuLA/
| `cula/ops/kda/` | Python (CuTeDSL) | CuTeDSL KDA kernels organized into SM100 modular kernels, SM90 FlashKDA K1+K2 and intracard CP, decode, and experimental code. The fully-fused SM90 implementation lives under `csrc/`, not here. |
| `csrc/kda/{sm90,sm100}/` | CUDA C++ | Hopper fully-fused prefill and Blackwell modular chunk kernels. |
| `csrc/api/` Β· `cula/cudac.py` | CUDA C++ / Python | Per-architecture `_cudac_sm90` and `_cudac_sm100` extensions, exposed lazily through the `cula.cudac` compatibility proxy. |
| `cula/gdn2/` Β· `cula/ops/gdn2/` | Python (CuTeDSL) | `[non-KDA]` Gated DeltaNet-2 packed-varlen prefill. `chunk_gdn2` dispatches directly to the SM90a backend with no fallback; unsupported inputs and out-of-range CuTeDSL versions fail closed. See [`docs/gdn2_sm90_api.md`](docs/gdn2_sm90_api.md). |
| `cula/ops/lightning/` Β· `cula/ops/experimental/` | Python (CuTeDSL) | `[non-KDA]` Lightning/linear-attention kernels and prototypes. Lightning prefill dispatches to the SM90 or SM100 backend from Q's device capability. |
| `cula/ops/{inv,ptx}.py` Β· `cula/ops/sm100/ptx.py` | Python | Shared low-level helpers used across operators. |
Loading