diff --git a/docs/SUPPORTED_GPUS.md b/docs/SUPPORTED_GPUS.md index 6c11a351..650537a2 100644 --- a/docs/SUPPORTED_GPUS.md +++ b/docs/SUPPORTED_GPUS.md @@ -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`. | @@ -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 @@ -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 | -| 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 diff --git a/src/cuda/kernels.cu b/src/cuda/kernels.cu index b31c5616..a277107b 100644 --- a/src/cuda/kernels.cu +++ b/src/cuda/kernels.cu @@ -1085,7 +1085,7 @@ __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 // 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};" @@ -1093,6 +1093,8 @@ __device__ __forceinline__ void mma16816(float* c, u32 a0, u32 a1, u32 a2, u32 a 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 diff --git a/src/cuda/mod.rs b/src/cuda/mod.rs index f3695f5c..e3aae969 100644 --- a/src/cuda/mod.rs +++ b/src/cuda/mod.rs @@ -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() } @@ -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)) +} + /// 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. @@ -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")?; 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 @@ -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] @@ -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")); + } + #[test] fn device_log_names_turing_not_volta() { assert!(super::device_log(0, "x", "sm_75", (7, 5), false).contains("Turing"));