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
6 changes: 4 additions & 2 deletions docs/SUPPORTED_GPUS.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ row.
| AMD Radeon VII (Vega 20) | GCN5, wave64 | Vulkan | Runs | masanork (PR #5) | RADV Mesa 26.0.8. Each 64-lane subgroup runs as two logical 32-lane warps. See [AMD.md](AMD.md). |
| AMD Radeon RX 9070 XT | RDNA 4 | Vulkan | Runs, known issues | user reports | Linux (RADV) and Windows (AMD driver). See [AMD.md](AMD.md) for the issues and what to send. |
| NVIDIA Turing card | Turing, sm_75 | CUDA | Runs | x-Pepsy (PR #6) | `m16n8k8` tensor cores, no int8 GEMM, 64 KB shared memory (16-key prefill tile at head_dim 256). The GPU model was not recorded in the PR. |
| NVIDIA GeForce GTX 1660 SUPER 6 GB | Turing, sm_75 (TU116, no tensor cores) | CUDA | Runs | PedroRossi | CUDA-core FMA for the f16 prefill GEMM and the prefill attention (`MMA_FMA`, on by default for Turing cards without tensor cores; `STRATA_GEMM_TC=1` keeps `m16n8k8`). `bench --prompt-file` on real text (prose and code), pp 4096 / 16384: prefill 214 / 162 tok/s against 103 / 88 with `m16n8k8`, decode 50.0 / 44.2 tok/s either way (MTP off, `--ctx 32768`, 2,494 of 10,240 experts resident). MTP 1-4 measured slower than off here. Driver 550.163.01, NVRTC 12.4, GPU clocks locked at 1200 MHz. |
| NVIDIA GeForce GTX 1660 SUPER 6 GB | Turing, sm_75 (TU116) | Vulkan | Runs | PedroRossi | No cooperative matrices, so the `_dp` kernels run. Same real-text bench: prefill 274 / 188 tok/s, decode 38.0 / 33.6 tok/s (GPU clocks locked at 1200 MHz). |
| NVIDIA A100-SXM4 80 GB | Ampere, sm_80 | CUDA | Full test suite passes | yugt | pp 4096 prefill 6203 tok/s, decode 174 tok/s (MTP off, whole model in VRAM). See [datacenter-nvidia-results.md](datacenter-nvidia-results.md). Calibrated in a later job: decode 280 tok/s with MTP 1, 174 with `--mtp 0`. |
| NVIDIA A100-SXM4 80 GB | Ampere, sm_80 | Vulkan | Full test suite passes with `--test-threads=1`; default parallel runs can hang in `vkDestroyDevice` on this driver ([details](datacenter-nvidia-results.md#2026-11-10--parallel-tests-can-hang-in-vkdestroydevice-on-this-driver)) | yugt | Cooperative matrices (f16 and int8). pp 4096 prefill 5589 tok/s, decode 132 tok/s. Calibrated in a later job: decode 234 tok/s with MTP 2, 118 with `--mtp 0`. |
| NVIDIA A30 24 GB | Ampere, sm_80 | CUDA | Full test suite passes | yugt | pp 4096 prefill 3544 tok/s, decode 132 tok/s. Calibrated in a later job: decode 193 tok/s with MTP 1, 132 with `--mtp 0`. |
Expand All @@ -29,7 +31,7 @@ row.

| GPU class | Arch | Backend | What is checked |
| --- | --- | --- | --- |
| Turing | sm_75 | CUDA | `cargo test` compiles the whole source with NVRTC for sm_75 (`nvrtc_compiles_full_source_for_sm75`). |
| Turing | sm_75 | CUDA | `cargo test` compiles the whole source with NVRTC for sm_75, with and without `MMA_FMA` (`nvrtc_compiles_full_source_for_sm75`). |
| Volta | sm_70 | CUDA | Same with an NVRTC 12.x (`nvrtc_compiles_full_source_for_sm70`); skipped on CUDA 13. |

## Not supported
Expand All @@ -45,7 +47,7 @@ row.
| Arch | Matrix multiply | Int8 GEMM | Async copy | Shared memory per block |
| --- | --- | --- | --- | --- |
| sm_80 and newer | `mma.m16n8k16` | yes | `cp.async` | 100 KB or more |

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Low · Maintainability · 5 of 5

The sm_75 row says nothing about STRATA_GEMM_FMA, but on sm_75 that variable now also switches the kernel branch. turing_fma returns true for any sm_75 card when gemm_fma is set, so an RTX 2070 user who sets STRATA_GEMM_FMA=1, which the row for sm_70 documents as Volta-only, now gets the CUDA-core path. Their performance changes and the documentation does not explain why.

Prompt for your AI agent
File: docs/SUPPORTED_GPUS.md
Line: 49
Issue: The sm_75 row says nothing about STRATA_GEMM_FMA, but on sm_75 that variable now also switches the kernel branch. turing_fma returns true for any sm_75 card when gemm_fma is set, so an RTX 2070 user who sets STRATA_GEMM_FMA=1, which the row for sm_70 documents as Volta-only, now gets the CUDA-core path. Their performance changes and the documentation does not explain why.
Make the smallest change that fixes this, add a test, and change nothing unrelated.

Reply /dismiss (optionally with a reason) if this isn't helpful - Aletheore won't raise it again on this repo.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 5e7755a. The sm_75 tier row now says that STRATA_GEMM_FMA=1 selects the CUDA-core branch on any sm_75 card, and that STRATA_GEMM_TC=1 keeps m16n8k8.

| sm_75 | `mma.m16n8k8` (two steps per k16) | no | register copy | 64 KB |
| sm_75 | `mma.m16n8k8` (two steps per k16); cards without tensor cores (TU116/TU117: the GTX 16 series, MX450/MX550, T400-T2000, CMP 30HX) take the CUDA-core FMA branch instead (`MMA_FMA`). `STRATA_GEMM_FMA=1` selects that branch on any sm_75 card, `STRATA_GEMM_TC=1` keeps `m16n8k8` | no | register copy | 64 KB |
| sm_70 | `mma.m8n8k4` (`GEMM_TC`), or CUDA-core FMA with `STRATA_GEMM_FMA=1` | no | register copy | 96 KB opt-in |

## Add your GPU
Expand Down
4 changes: 3 additions & 1 deletion src/cuda/kernels.cu
Original file line number Diff line number Diff line change
Expand Up @@ -1085,14 +1085,16 @@ __device__ __forceinline__ void ldsm4t(u32* r, const u16* p) {
}
__device__ __forceinline__ void mma16816(float* c, u32 a0, u32 a1, u32 a2, u32 a3, u32 b0, u32 b1) {
#if defined(__CUDA_ARCH__) && __CUDA_ARCH__ < 800
#if __CUDA_ARCH__ >= 750
#if __CUDA_ARCH__ >= 750 && !MMA_FMA

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Low · Maintainability · 4 of 5

The sm_75 MMA_FMA branch is only checked for NVRTC compilation, never for numerical equivalence with the tensor-core path. The FMA branch of mma16816 could compute the wrong product, such as a transposed B fragment or a wrong k-half offset. The new test only confirms that the source compiles for sm_75, so the wrong result would ship on GTX 16 cards unnoticed. A small GEMM comparing the FMA and m16n8k8 outputs would catch this.

Prompt for your AI agent
File: src/cuda/kernels.cu
Line: 1088
Issue: The sm_75 MMA_FMA branch is only checked for NVRTC compilation, never for numerical equivalence with the tensor-core path. The FMA branch of mma16816 could compute the wrong product, such as a transposed B fragment or a wrong k-half offset. The new test only confirms that the source compiles for sm_75, so the wrong result would ship on GTX 16 cards unnoticed. A small GEMM comparing the FMA and m16n8k8 outputs would catch this.
Make the smallest change that fixes this, add a test, and change nothing unrelated.

Reply /dismiss (optionally with a reason) if this isn't helpful - Aletheore won't raise it again on this repo.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked on a GeForce GTX 1660 SUPER (driver 550.163.01, NVRTC 12.4) with 5e7755a, running the existing GPU tests that cover both users of mma16816:

test CUDA-core FMA (default on this card) STRATA_GEMM_TC=1 (m16n8k8)
kernels: gemm_matches_reference_for_every_type, small_batch_gemm_matches_tile_gemm pass pass
kernels: the four attn_prefill_* tests pass pass
gpu_model: gpu_forward_matches_cpu_reference, prefill_matches_reference (chunked prefill vs the CPU f32 reference), on Qwen3.6-35B-A3B-UD-Q2_K_XL.gguf pass -
greedy generate, 2,405-token prompt, 64 tokens same tokens as m16n8k8; prefill 211.8 tok/s prefill 100.6 tok/s

So the FMA branch matches both the reference and the tensor-core path. No new test, since the existing ones exercise this product; they just need a GPU, which CI doesn't have.

// Turing (sm_75) has no m16n8k16 f16 mma: the same product is two m16n8k8 steps, k = 0..7 and k = 8..15
// (the a0/a1, a2/a3 and b0, b1 fragments are those half-K fragments of the k16 layout).
asm volatile("mma.sync.aligned.m16n8k8.row.col.f32.f16.f16.f32 {%0,%1,%2,%3}, {%4,%5}, {%6}, {%0,%1,%2,%3};"
: "+f"(c[0]), "+f"(c[1]), "+f"(c[2]), "+f"(c[3]) : "r"(a0), "r"(a1), "r"(b0));
asm volatile("mma.sync.aligned.m16n8k8.row.col.f32.f16.f16.f32 {%0,%1,%2,%3}, {%4,%5}, {%6}, {%0,%1,%2,%3};"
: "+f"(c[0]), "+f"(c[1]), "+f"(c[2]), "+f"(c[3]) : "r"(a2), "r"(a3), "r"(b1));
#else
// Also taken on sm_75 with MMA_FMA: the GTX 16 series (TU116/TU117) has no tensor cores and runs m16n8k8 far
// slower than this CUDA-core version (see `turing_fma` in mod.rs).
// D[16,8] += A[16,16] * B[16,8] on CUDA cores. mma.sync.aligned.m16n8k16 is sm_80+ (unlike ldmatrix, which is
// sm_75+, hence the different guard). Lane l = 4*g + t (g = l >> 2, t = l & 3) owns A rows g / g+8 at the
// k-halves {2t, 2t+1, 2t+8, 2t+9}, and B column g at those same k. The four accumulators are sums over all 16
Expand Down
59 changes: 56 additions & 3 deletions src/cuda/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ pub fn kv_q8() -> bool { kv_mode() == 1 }
pub fn kv_legacy_symmetric(k: u32, v: u32) -> bool { k == v && k <= 3 }

/// `STRATA_GEMM_FMA`: force the CUDA-core FMA fallback in the f16 prefill kernels instead of the sm_70 tensor-core
/// path (`GEMM_TC` in kernels.cu). It covers both the f16 prefill GEMM and the prefill attention (`attn_prefill_t`):
/// path (`GEMM_TC` in kernels.cu), and on sm_75 instead of `m16n8k8` (`MMA_FMA`, see `turing_fma`; Turing cards without
/// tensor cores take it by default). It covers both the f16 prefill GEMM and the prefill attention (`attn_prefill_t`):
/// the attention's P staging tile is part of every request, so the shared-memory size does not depend on it.
/// Ignored on sm_80+, which always uses `mma.m16n8k16`.
pub fn gemm_fma() -> bool { std::env::var_os("STRATA_GEMM_FMA").is_some() }
Expand Down Expand Up @@ -364,12 +365,29 @@ fn device_log(device: usize, name: &str, arch: &str, cc: (i32, i32), gemm_fma: b
(c, _) if c < (7, 0) => " (pre-Volta, not supported)", // not reached from `Gpu::new`: `min_arch_error`
(c, false) if c < (7, 5) => " (Volta, m8n8k4)",
(c, true) if c < (7, 5) => " (Volta fallback)",
(c, true) if c < (8, 0) => " (Turing, CUDA-core FMA)",
(c, _) if c < (8, 0) => " (Turing, m16n8k8)",
_ => "", // sm_80+ always uses mma.m16n8k16
};
format!("cuda device {device}: {name}, {arch}{path}")
}

/// The Turing chips without tensor cores, TU116 and TU117: the GTX 16 series, MX450/MX550, the T400-T2000 workstation
/// and laptop cards and the CMP 30HX. CUDA does not report tensor cores, so the product name decides.
fn no_tensor_cores(name: &str) -> bool {
const TU11X: [&str; 10] = ["MX450", "MX550", "T400", "T500", "T550", "T600", "T1000", "T1200", "T2000", "30HX"];
name.contains("GTX 16") || name.split_whitespace().any(|w| TU11X.contains(&w))
}

/// Turing cards without tensor cores still execute `mma.sync` m16n8k8, but far slower than CUDA-core FMA: on a GTX
/// 1660 SUPER the f16 prefill ran ~3.5x slower than llama.cpp's. On sm_75 such a card, or `gemm_fma`
/// (`STRATA_GEMM_FMA`) on any sm_75 card, compiles the CUDA-core branch of `mma16816` instead (`MMA_FMA` in
/// kernels.cu, covering the f16 prefill GEMM and the prefill attention); `keep_tc` (`STRATA_GEMM_TC=1`) keeps the
/// tensor cores.
fn turing_fma(name: &str, cc: (i32, i32), gemm_fma: bool, keep_tc: bool) -> bool {
cc == (7, 5) && !keep_tc && (gemm_fma || no_tensor_cores(name))
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High · Correctness · 1 of 5

Name-based detection misses other TU116/TU117 cards (MX450, T600 and similar). A laptop with an MX450 or a Quadro T600 (TU117, no tensor cores) reports a name without the substring "GTX 16", so turing_fma is false and it runs the slow m16n8k8 path that this change is meant to avoid. Gating on the device name is fragile, and compute capability alone cannot separate TU116/TU117 from TU102/104/106.

Prompt for your AI agent
File: src/cuda/mod.rs
Line: 381
Issue: Name-based detection misses other TU116/TU117 cards (MX450, T600 and similar). A laptop with an MX450 or a Quadro T600 (TU117, no tensor cores) reports a name without the substring "GTX 16", so turing_fma is false and it runs the slow m16n8k8 path that this change is meant to avoid. Gating on the device name is fragile, and compute capability alone cannot separate TU116/TU117 from TU102/104/106.
Make the smallest change that fixes this, add a test, and change nothing unrelated.

Reply /dismiss (optionally with a reason) if this isn't helpful - Aletheore won't raise it again on this repo.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 5e7755a. no_tensor_cores() now matches every TU116/TU117 product name: the GTX 16 series, MX450/MX550, T400-T2000 and CMP 30HX. The test covers those names, plus Turing cards that do have tensor cores (RTX 2070, Tesla T4, Quadro RTX 4000, TITAN RTX).

/// Whether the device has int8 tensor cores, i.e. whether the `gemmi_*`/`gemmis_*` prefill GEMM exists in its cubin
/// and may be launched. Volta (sm_70) does not: the s8 `mma` shapes need sm_80, so the kernels are compiled out of
/// the sm_70 build (see the `#if __CUDA_ARCH__ >= 800` guards in kernels.cu) and dropped from the loaded name list.
Expand Down Expand Up @@ -614,9 +632,14 @@ impl Gpu {
.unwrap_or(48 << 10).max(48 << 10) as u32;
let arch: &'static str = Box::leak(format!("sm_{maj}{min}").into_boxed_str());
let gemm_fma = gemm_fma();
crate::say!("{}", device_log(device, &ctx.name().unwrap_or_default(), arch, (maj, min), gemm_fma));
let name = ctx.name().unwrap_or_default();
let mma_fma = turing_fma(&name, (maj, min), gemm_fma, std::env::var_os("STRATA_GEMM_TC").is_some());
let fma_path = if (maj, min) >= (7, 5) { mma_fma } else { gemm_fma }; // the branch actually compiled
crate::say!("{}", device_log(device, &name, arch, (maj, min), fma_path));
let stream = ctx.new_stream()?;
let module = ctx.load_module(ptx(&source(kv_k_mode, kv_v_mode, !gemm_fma && (maj, min) < (7, 5)), arch, (maj, min))?).context("load cubin")?;
let src = source(kv_k_mode, kv_v_mode, !gemm_fma && (maj, min) < (7, 5));
let src = if mma_fma { format!("#define MMA_FMA 1\n{src}") } else { src };
let module = ctx.load_module(ptx(&src, arch, (maj, min))?).context("load cubin")?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High · Correctness · 2 of 5

Module is built through ptx(&src, arch, cc); if that cache is keyed on arch and cc only, the MMA_FMA define is ignored. If ptx() memoises compiled output by (arch, cc) without the source text, a process that first compiles the default source on sm_75 and then loads the GTX 16 variant gets the tensor-core cubin. The FMA path is silently not used, and the device log still claims CUDA-core FMA. This cannot be verified from the diff.

Prompt for your AI agent
File: src/cuda/mod.rs
Line: 633
Symbol: new
Issue: Module is built through ptx(&src, arch, cc); if that cache is keyed on arch and cc only, the MMA_FMA define is ignored. If ptx() memoises compiled output by (arch, cc) without the source text, a process that first compiles the default source on sm_75 and then loads the GTX 16 variant gets the tensor-core cubin. The FMA path is silently not used, and the device log still claims CUDA-core FMA. This cannot be verified from the diff.
Make the smallest change that fixes this, add a test, and change nothing unrelated.

Reply /dismiss (optionally with a reason) if this isn't helpful - Aletheore won't raise it again on this repo.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/dismiss This can't happen here. ptx() names the cached cubin cache_key(src, arch, &tag), and src is the full kernel source with #define MMA_FMA 1 prepended, so the two variants hash to different files. 5e7755a adds cubin_cache_key_changes_with_mma_fma to pin that.

let i8_gemm = int8_gemm_arch((maj, min));
let turing = !int8_mma && (maj, min) >= (7, 5);
// The per-block dynamic shared memory ceiling the driver reports: 96 KiB on Volta per the roadmap, but
Expand Down Expand Up @@ -1810,6 +1833,9 @@ mod tests {
super::nvrtc::cubin(&super::source(2, 2, false), "sm_75").unwrap_or_else(|e| panic!("sm_75 kv_q4 must compile: {e:#}"));
super::nvrtc::cubin(&super::source(3, 3, false), "sm_75").unwrap_or_else(|e| panic!("sm_75 kv_q2 must compile: {e:#}"));
super::nvrtc::cubin(&super::source(4, 4, false), "sm_75").unwrap_or_else(|e| panic!("sm_75 kv_turbo4 must compile: {e:#}"));
// The GTX 16 build: the CUDA-core branch of mma16816 on sm_75 (see `turing_fma`).
let fma = format!("#define MMA_FMA 1\n{}", super::source(0, 0, false));
super::nvrtc::cubin(&fma, "sm_75").unwrap_or_else(|e| panic!("sm_75 MMA_FMA (GTX 16) must compile: {e:#}"));
}

#[test]
Expand All @@ -1826,6 +1852,33 @@ mod tests {
}
}

#[test]
fn turing_fma_only_for_turing_without_tensor_cores() {
// TU116/TU117 cards, at sm_75 only; `gemm_fma` (STRATA_GEMM_FMA) turns it on for any sm_75 card and `keep_tc`
// (STRATA_GEMM_TC) off. Flags are passed in, so the caller's environment does not matter.
for name in ["NVIDIA GeForce GTX 1660 SUPER", "NVIDIA GeForce GTX 1650", "NVIDIA GeForce GTX 1650 Ti with Max-Q Design",
"NVIDIA GeForce MX450", "NVIDIA T600 Laptop GPU", "Quadro T1000", "NVIDIA T1000 8GB", "NVIDIA CMP 30HX"] {
assert!(super::turing_fma(name, (7, 5), false, false), "{name}");
assert!(!super::turing_fma(name, (7, 5), false, true), "{name} with STRATA_GEMM_TC");
}
for name in ["NVIDIA GeForce RTX 2070", "Tesla T4", "Quadro RTX 4000", "NVIDIA TITAN RTX", "NVIDIA RTX A2000"] {
assert!(!super::turing_fma(name, (7, 5), false, false), "{name}");
}
assert!(super::turing_fma("NVIDIA GeForce RTX 2070", (7, 5), true, false)); // STRATA_GEMM_FMA
assert!(!super::turing_fma("NVIDIA GeForce GTX 1660 SUPER", (8, 6), false, false));
assert!(!super::turing_fma("Tesla V100-SXM2-32GB", (7, 0), true, false));
assert!(super::device_log(0, "x", "sm_75", (7, 5), true).contains("CUDA-core FMA"));
assert!(super::device_log(0, "x", "sm_75", (7, 5), false).contains("m16n8k8"));
}

#[test]
fn cubin_cache_key_changes_with_mma_fma() {
// A GTX 16 card must not load the tensor-core cubin from the cache: the define is in the source the key hashes.
let src = super::source(0, 0, false);
let fma = format!("#define MMA_FMA 1\n{src}");
assert_ne!(super::cache_key(&src, "sm_75", "12.4"), super::cache_key(&fma, "sm_75", "12.4"));
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Low · Maintainability · 1 of 1

cubin_cache_key test passes for any prepended string, so it does not check the MMA_FMA define. The test prepends '#define MMA_FMA 1' to source(0, 0, false) and asserts the hash differs. Any prefix would change the hash, so the test still passes if the real GTX 16 source never gets the define, or if the define is applied to the wrong source. A regression in how the define is attached would go unnoticed.

Prompt for your AI agent
File: src/cuda/mod.rs
Line: 1880
Symbol: cache_key_depends_on_nvrtc_tag
Issue: cubin_cache_key test passes for any prepended string, so it does not check the MMA_FMA define. The test prepends '#define MMA_FMA 1' to source(0, 0, false) and asserts the hash differs. Any prefix would change the hash, so the test still passes if the real GTX 16 source never gets the define, or if the define is applied to the wrong source. A regression in how the define is attached would go unnoticed.
Make the smallest change that fixes this, add a test, and change nothing unrelated.

Reply /dismiss (optionally with a reason) if this isn't helpful - Aletheore won't raise it again on this repo.


#[test]
fn device_log_names_turing_not_volta() {
assert!(super::device_log(0, "x", "sm_75", (7, 5), false).contains("Turing"));
Expand Down