diff --git a/src/backend.rs b/src/backend.rs index efbacad0..a3c57541 100644 --- a/src/backend.rs +++ b/src/backend.rs @@ -608,6 +608,11 @@ pub trait Backend: Send { /// words a row, rows up to `t` rounded up to 64; see `qsa_select`). `qm` 0: no mask. `sink` (0 = none): per-head /// attention-sink logits. `win` (0 = none): sliding-window width. fn attn_prefill_m(&self, q: u64, kc: u64, vc: u64, qg: u64, out: u64, step: u64, t: usize, nh: usize, nkv: usize, hd: usize, scale: f32, qm: u64, mw: usize, sink: u64, win: usize) -> anyhow::Result<()>; + #[allow(clippy::too_many_arguments)] + fn attn_prefill_m_at(&self, q: u64, kc: u64, vc: u64, qg: u64, out: u64, step: u64, t: usize, nh: usize, nkv: usize, hd: usize, + scale: f32, qm: u64, mw: usize, sink: u64, win: usize, _pos: usize) -> anyhow::Result<()> { + self.attn_prefill_m(q, kc, vc, qg, out, step, t, nh, nkv, hd, scale, qm, mw, sink, win) + } /// QSA indexer keys (see `Model::qsa`): pool the blocks of 4 positions that the `t` raw keys (rows of 128) at /// positions step[0] .. complete into `pool` (rows of 128 per block: mean, rms norm with `w`, NEOX rope at the /// block's first position). `ring`: 4 rows of 128, the raw keys of the incomplete block (row = position % 4). diff --git a/src/cuda/kernels.cu b/src/cuda/kernels.cu index 64454c0e..b43bdd03 100644 --- a/src/cuda/kernels.cu +++ b/src/cuda/kernels.cu @@ -6064,6 +6064,127 @@ extern "C" __global__ void moe_combine_seq(float* x, const float* ye, const floa x[i] += y; } +extern "C" __global__ void kv_to_h(const u16* kc, const u16* vc, u16* k16, u16* v16, int rows, int n, int hd) { + int i = blockIdx.x * blockDim.x + threadIdx.x; + if (i >= rows * n / 8) return; + size_t off = (size_t)(i / (hd / 8)) * hd + (i % (hd / 8)) * 8; + unsigned o[4]; + ldkv(kc, off, hd, o); + *(uint4*)(k16 + off) = *(uint4*)o; + ldkv(vc, off, hd, o); + *(uint4*)(v16 + off) = *(uint4*)o; +} + +extern "C" __global__ void q_to_h(const float* q, u16* out, int n, float scale) { + int i = 4 * (blockIdx.x * blockDim.x + threadIdx.x); + if (i >= n) return; + float4 v = *(const float4*)(q + i); + *(uint2*)(out + i) = make_uint2(h2pack(v.x * scale, v.y * scale), h2pack(v.z * scale, v.w * scale)); +} + +#if STRATA_HIP +__device__ __forceinline__ float att_exp(float x) { + float y = x * 1.442695041f, r; + asm volatile("v_exp_f32 %0, %1" : "=v"(r) : "0"(y)); + return r; +} +#define ATT_EXP(x) att_exp(x) +#else +#define ATT_EXP(x) __expf(x) +#endif + +template +__device__ __forceinline__ void att_softmax_wave(u16* row, float* inv, int n, int L, const unsigned* mr) { + const int lane = threadIdx.x & 31, nv = L >> 3; + auto bits = [&](int k) { return mr[k >> 7] >> ((k >> 2) & 31); }; + float m = -3.402823466e38f; + for (int v = lane; v < nv; v += 32) { + int k = v << 3; + unsigned w = 3u; + if constexpr (MASKED) { + w = bits(k); + if (!(w & 3u)) continue; + } + uint4 x = *(const uint4*)(row + k); + float f[8] = {h2f((u16)x.x), h2f((u16)(x.x >> 16)), h2f((u16)x.y), h2f((u16)(x.y >> 16)), + h2f((u16)x.z), h2f((u16)(x.z >> 16)), h2f((u16)x.w), h2f((u16)(x.w >> 16))}; + if (k + 8 <= n) { +#pragma unroll + for (int j = 0; j < 8; j++) + if (w >> (j >> 2) & 1u) m = fmaxf(m, f[j]); + } else { +#pragma unroll + for (int j = 0; j < 8; j++) + if (k + j < n && (w >> (j >> 2) & 1u)) m = fmaxf(m, f[j]); + } + } + for (int k = (nv << 3) + lane; k < n; k += 32) + if (!MASKED || (bits(k) & 1u)) m = fmaxf(m, h2f(row[k])); +#pragma unroll + for (int o = 16; o > 0; o >>= 1) m = fmaxf(m, __shfl_xor_sync(0xffffffffu, m, o)); + float sum = 0.f; + for (int v = lane; v < nv; v += 32) { + int k = v << 3; + unsigned w = 3u; + if constexpr (MASKED) { + w = bits(k); + if (!(w & 3u)) { *(uint4*)(row + k) = make_uint4(0u, 0u, 0u, 0u); continue; } + } + uint4 x = *(const uint4*)(row + k); + float f[8] = {h2f((u16)x.x), h2f((u16)(x.x >> 16)), h2f((u16)x.y), h2f((u16)(x.y >> 16)), + h2f((u16)x.z), h2f((u16)(x.z >> 16)), h2f((u16)x.w), h2f((u16)(x.w >> 16))}; + unsigned p[4] = {}; + if (k + 8 <= n) { +#pragma unroll + for (int j = 0; j < 8; j++) { + float e = (w >> (j >> 2) & 1u) ? ATT_EXP(f[j] - m) : 0.f; + sum += e; + p[j >> 1] |= (unsigned)f2h(e) << (16 * (j & 1)); + } + } else { +#pragma unroll + for (int j = 0; j < 8; j++) { + float e = k + j < n && (w >> (j >> 2) & 1u) ? ATT_EXP(f[j] - m) : 0.f; + sum += e; + p[j >> 1] |= (unsigned)f2h(e) << (16 * (j & 1)); + } + } + *(uint4*)(row + k) = make_uint4(p[0], p[1], p[2], p[3]); + } + for (int k = (nv << 3) + lane; k < n; k += 32) { + float e = !MASKED || (bits(k) & 1u) ? ATT_EXP(h2f(row[k]) - m) : 0.f; + sum += e; + row[k] = f2h(e); + } +#pragma unroll + for (int o = 16; o > 0; o >>= 1) sum += __shfl_xor_sync(0xffffffffu, sum, o); + if (lane == 0) *inv = sum > 0.f ? 1.f / sum : 0.f; +} + +extern "C" __global__ void att_softmax(u16* s, float* inv, int qb, int L, int pos, int q0, int nh, int rows, + const unsigned* qm, int mw) { + int r = blockIdx.x * (blockDim.x >> 5) + (threadIdx.x >> 5); + if (r >= rows) return; + int i = r / nh, n = pos + q0 + i + 1; + u16* row = s + (size_t)(r % nh) * qb * L + (size_t)i * L; + if (qm) att_softmax_wave(row, inv + r, n, L, qm + (size_t)(q0 + i) * mw); + else att_softmax_wave(row, inv + r, n, L, 0); +} + +extern "C" __global__ void att_scale(float* out, const float* inv, const float* qg, int nh, int hd, int n) { + int i = 4 * (blockIdx.x * blockDim.x + threadIdx.x); + if (i >= n) return; + float4 v = *(float4*)(out + i); + float s = inv[i / hd]; + if (qg) { + const float* g = qg + (size_t)(i / (nh * hd)) * nh * 2 * hd + (size_t)((i / hd) % nh) * 2 * hd + hd + i % hd; + v.x *= s * sigmoid(g[0]); v.y *= s * sigmoid(g[1]); v.z *= s * sigmoid(g[2]); v.w *= s * sigmoid(g[3]); + } else { + v.x *= s; v.y *= s; v.z *= s; v.w *= s; + } + *(float4*)(out + i) = v; +} + // ---- attention prefill (flash, tensor cores) ---- // grid = (ceil(T / 64), heads), block = 128: warp w owns queries 16w .. 16w + 15 of the tile. Query t (position diff --git a/src/cuda/mod.rs b/src/cuda/mod.rs index 989c3f11..a585eae7 100644 --- a/src/cuda/mod.rs +++ b/src/cuda/mod.rs @@ -587,6 +587,7 @@ fn kernel_names_with(sm80: bool, dp4a: bool) -> Vec { .chain(QTYPES.iter().filter(int8_d).map(|&t| kname("gemmd", t))) .chain([64, 128, 256, 512].iter().flat_map(|h| [format!("attn_decode_{h}"), format!("attn_decode_gqa_{h}")])) .chain(["attn_decode_gqa4_128".to_string()]) + .chain(["kv_to_h", "q_to_h", "att_softmax", "att_scale"].map(String::from)) .collect() } @@ -2415,8 +2416,8 @@ mod tests { #[test] fn kernel_names() { let (sm70, sm80) = (super::kernel_names(false), super::kernel_names(true)); - assert_eq!(sm80.len(), 470); - assert_eq!(sm70.len(), 398); + assert_eq!(sm80.len(), 474); + assert_eq!(sm70.len(), 402); assert!(sm70.iter().all(|n| !n.starts_with("gemmi") && !n.starts_with("gemmd")), "sm_70 must not load the int8 prefill GEMM: {:?}", sm70.iter().filter(|n| n.starts_with("gemmi")).collect::>()); @@ -2427,7 +2428,7 @@ mod tests { #[test] fn kernel_names_tu11x_dp4a() { let tu11x = super::kernel_names_with(false, true); - assert_eq!(tu11x.len(), 446); + assert_eq!(tu11x.len(), 450); assert!(tu11x.contains(&"gemmi_q4_k".to_string())); assert!(tu11x.contains(&"gemmis_q8_0".to_string())); assert!(tu11x.iter().all(|n| !n.starts_with("gemmd")), diff --git a/src/gpu_model/prefill.rs b/src/gpu_model/prefill.rs index c16fa787..a7f439c5 100644 --- a/src/gpu_model/prefill.rs +++ b/src/gpu_model/prefill.rs @@ -757,7 +757,11 @@ impl GpuModel<'_> { } _ => (kc[self.cur].addr(), vc[self.cur].addr()), }; - g.attn_prefill_m(at(l.b), kca, vca, if c.q_gate { at(l.a) } else { 0 }, at(l.d), step, t, nh, nkv, hd, 1.0 / (hd as f32).sqrt(), qm, mw, sink_addr, win)?; + if rows.is_none() { + g.attn_prefill_m_at(at(l.b), kca, vca, if c.q_gate { at(l.a) } else { 0 }, at(l.d), step, t, nh, nkv, hd, 1.0 / (hd as f32).sqrt(), qm, mw, sink_addr, win, self.pos)?; + } else { + g.attn_prefill_m(at(l.b), kca, vca, if c.q_gate { at(l.a) } else { 0 }, at(l.d), step, t, nh, nkv, hd, 1.0 / (hd as f32).sqrt(), qm, mw, sink_addr, win)?; + } probe(&mut tr, "q", &pf.slab, at(l.a), nh * qs, t)?; probe(&mut tr, "k", &pf.slab, kk, kv, t)?; probe(&mut tr, "v", &pf.slab, vv, kv, t)?; diff --git a/src/hip/ffi.rs b/src/hip/ffi.rs index 18a5d51e..f214a7b5 100644 --- a/src/hip/ffi.rs +++ b/src/hip/ffi.rs @@ -66,6 +66,104 @@ fn candidates(vars: Option, default_suffix: &[&str]) -> Vec { v } +pub const BLAS_OP_N: c_int = 111; +pub const BLAS_OP_T: c_int = 112; +pub const BLAS_R_16F: c_int = 150; +pub const BLAS_R_32F: c_int = 151; +pub const BLAS_COMPUTE_32F: c_int = BLAS_R_32F; +pub const BLAS_GEMM_DEFAULT: c_int = 160; +pub const BLAS_V2_R_16F: c_int = 2; +pub const BLAS_V2_COMPUTE_32F: c_int = 2; + +type GemmEx = unsafe extern "C" fn(*mut c_void, c_int, c_int, c_int, c_int, c_int, *const c_void, *const c_void, + c_int, c_int, *const c_void, c_int, c_int, *const c_void, *mut c_void, c_int, + c_int, c_int, c_int) -> c_int; + +pub struct Blas { + handle: *mut c_void, + destroy: unsafe extern "C" fn(*mut c_void) -> c_int, + set_stream: unsafe extern "C" fn(*mut c_void, Stream) -> c_int, + gemm_ex: GemmEx, + gemm_ex_v2: Option, + _lib: &'static Library, +} + +impl Drop for Blas { + fn drop(&mut self) { if !self.handle.is_null() { unsafe { (self.destroy)(self.handle) }; } } +} + +impl Blas { + pub fn open() -> anyhow::Result { + let want = candidates(std::env::var_os("STRATA_HIPBLAS_LIB").map(Into::into), + &["hipblas.dll", "libhipblas.so", "libhipblas.so.7", "libhipblas.so.6"]); + let mut tried = Vec::new(); + for path in &want { + let lib = match unsafe { Library::new(path) } { + Ok(l) => l, + Err(e) => { tried.push(format!("{}: not loadable ({e})", path.display())); continue } + }; + unsafe { + let create: unsafe extern "C" fn(*mut *mut c_void) -> c_int = match Self::sym(&lib, "hipblasCreate") { + Some(f) => f, + None => { tried.push(format!("{}: no hipblasCreate", path.display())); continue } + }; + let Some(set_stream) = Self::sym:: c_int>(&lib, "hipblasSetStream") else { + tried.push(format!("{}: no hipblasSetStream", path.display())); continue + }; + let Some(gemm_ex) = Self::sym::(&lib, "hipblasGemmEx") else { + tried.push(format!("{}: no hipblasGemmEx", path.display())); continue + }; + let Some(destroy) = Self::sym:: c_int>(&lib, "hipblasDestroy") else { + tried.push(format!("{}: no hipblasDestroy", path.display())); continue + }; + let mut handle: *mut c_void = std::ptr::null_mut(); + if create(&mut handle) != 0 || handle.is_null() { + tried.push(format!("{}: hipblasCreate failed", path.display())); continue + } + let gemm_ex_v2 = Self::sym::(&lib, "hipblasGemmEx_v2"); + return Ok(Blas { handle, destroy, set_stream, gemm_ex, gemm_ex_v2, _lib: Box::leak(Box::new(lib)) }); + } + } + Err(anyhow::anyhow!("no hipblas: {}", tried.join(", "))).context("hipblas init") + } + + pub fn set_stream(&self, stream: Stream) -> anyhow::Result<()> { + let r = unsafe { (self.set_stream)(self.handle, stream) }; + if r != 0 { anyhow::bail!("hipblasSetStream: {r}") } + Ok(()) + } + + #[allow(clippy::too_many_arguments)] + pub fn gemm_ex_f16_f32(&self, transa: c_int, transb: c_int, m: usize, n: usize, k: usize, alpha: f32, + a: u64, lda: usize, b: u64, ldb: usize, beta: f32, c: u64, ldc: usize) -> anyhow::Result<()> { + let r = unsafe { (self.gemm_ex)(self.handle, transa, transb, m as c_int, n as c_int, k as c_int, + &alpha as *const f32 as *const c_void, a as *const c_void, BLAS_R_16F, lda as c_int, + b as *const c_void, BLAS_R_16F, ldb as c_int, + &beta as *const f32 as *const c_void, c as *mut c_void, BLAS_R_32F, ldc as c_int, + BLAS_COMPUTE_32F, BLAS_GEMM_DEFAULT) }; + if r != 0 { anyhow::bail!("hipblasGemmEx({m}x{n}x{k}): status {r}") } + Ok(()) + } + + #[allow(clippy::too_many_arguments)] + pub fn gemm_ex_f16_f16(&self, transa: c_int, transb: c_int, m: usize, n: usize, k: usize, alpha: f32, + a: u64, lda: usize, b: u64, ldb: usize, beta: f32, c: u64, ldc: usize) -> anyhow::Result<()> { + let Some(f) = self.gemm_ex_v2 else { anyhow::bail!("hipblasGemmEx_v2 is not exported") }; + let r = unsafe { f(self.handle, transa, transb, m as c_int, n as c_int, k as c_int, + &alpha as *const f32 as *const c_void, a as *const c_void, BLAS_V2_R_16F, lda as c_int, + b as *const c_void, BLAS_V2_R_16F, ldb as c_int, + &beta as *const f32 as *const c_void, c as *mut c_void, BLAS_V2_R_16F, ldc as c_int, + BLAS_V2_COMPUTE_32F, BLAS_GEMM_DEFAULT) }; + if r != 0 { anyhow::bail!("hipblasGemmEx_v2({m}x{n}x{k}): status {r}") } + Ok(()) + } + + unsafe fn sym(lib: &Library, name: &str) -> Option { + let s = unsafe { lib.get::(format!("{name}\0").as_bytes()).ok() }?; + Some(*s) + } +} + pub struct Hip { pub init: unsafe extern "C" fn(c_int) -> c_int, pub device_count: unsafe extern "C" fn(*mut c_int) -> c_int, diff --git a/src/hip/mod.rs b/src/hip/mod.rs index cfa7119b..fb3f1b83 100644 --- a/src/hip/mod.rs +++ b/src/hip/mod.rs @@ -80,6 +80,11 @@ pub struct Gpu { /// Pinned staging for large `htod`, used as a ring: the copy returns before its DMA, so the host fills the next /// region while the card reads the previous one (expert streaming in prefill). staging: Mutex, + blas: Option, + att_kv: std::cell::RefCell>, + att_q: std::cell::RefCell>, + att_s: std::cell::RefCell>, + att_inv: std::cell::RefCell>, } // The HIP handles are raw pointers but the runtime is thread-safe for the calls the backend makes, and `Backend` @@ -177,6 +182,55 @@ fn cache_key(src: &str, arch: &str, rtc: &str) -> u64 { } impl Gpu { + + fn blas_buf(&self, cell: &std::cell::RefCell>, bytes: usize) -> anyhow::Result { + let mut b = cell.borrow_mut(); + if b.as_ref().map(|buf| buf.len() < bytes).unwrap_or(true) { + *b = None; + *b = Some(self.alloc(bytes)?); + } + Ok(b.as_ref().unwrap().addr()) + } + + fn attn_prefill_blas(&self, q: u64, kc: u64, vc: u64, qg: u64, out: u64, t: usize, pos: usize, nh: usize, nkv: usize, hd: usize, + scale: f32, qm: u64, mw: usize) -> anyhow::Result<()> { + let blas = self.blas.as_ref().unwrap(); + let (rows, n) = (pos + t, nkv * hd); + let kv_bytes = rows * n * 2; + let k16 = self.blas_buf(&self.att_kv, 2 * kv_bytes)?; + let v16 = k16 + kv_bytes as u64; + launch!(self, "kv_to_h", cfg(((rows * n / 8).div_ceil(256) as u32, 1), 256, 0), + kc, vc, k16, v16, rows as i32, n as i32, hd as i32); + let q16 = self.blas_buf(&self.att_q, t * nh * hd * 2)?; + launch!(self, "q_to_h", cfg(((t * nh * hd / 4).div_ceil(256) as u32, 1), 256, 0), q, q16, (t * nh * hd) as i32, scale); + let qb = (ATT_S_BYTES / (nh * ((pos + t + 7) & !7) * 2)).clamp(1, ATT_QB).min(t).max(1); + let s = self.blas_buf(&self.att_s, nh * qb * ((pos + t + 7) & !7) * 2)?; + let inv = self.blas_buf(&self.att_inv, t * nh * 4)?; + for q0 in (0..t).step_by(qb) { + let (b, l) = (qb.min(t - q0), pos + q0 + qb.min(t - q0)); + let lp = (l + 7) & !7; + for h in 0..nh { + let sh = s + (h * qb * lp * 2) as u64; + blas.gemm_ex_f16_f16(ffi::BLAS_OP_T, ffi::BLAS_OP_N, l, b, hd, 1.0, + k16 + ((h / (nh / nkv)) * hd * 2) as u64, n, q16 + ((q0 * nh + h) * hd * 2) as u64, nh * hd, + 0.0, sh, lp)?; + } + launch!(self, "att_softmax", cfg(((b * nh).div_ceil(8) as u32, 1), 256, 0), + s, inv + (q0 * nh * 4) as u64, qb as i32, lp as i32, pos as i32, q0 as i32, nh as i32, (b * nh) as i32, + qm, mw as i32); + for h in 0..nh { + let sh = s + (h * qb * lp * 2) as u64; + blas.gemm_ex_f16_f32(ffi::BLAS_OP_N, ffi::BLAS_OP_N, hd, b, l, 1.0, + v16 + ((h / (nh / nkv)) * hd * 2) as u64, n, sh, lp, 0.0, + out + ((q0 * nh + h) * hd * 4) as u64, nh * hd)?; + } + launch!(self, "att_scale", cfg(((b * nh * hd / 4).div_ceil(256) as u32, 1), 256, 0), + out + (q0 * nh * hd * 4) as u64, inv + (q0 * nh * 4) as u64, + if qg == 0 { 0 } else { qg + (q0 * nh * 2 * hd * 4) as u64 }, + nh as i32, hd as i32, (b * nh * hd) as i32); + } + Ok(()) + } pub fn new(device: usize) -> anyhow::Result { let (kv_k_mode, kv_v_mode) = (crate::cuda::kv_k_mode(), crate::cuda::kv_v_mode()); anyhow::ensure!(!((kv_k_mode > 0 || kv_v_mode > 0) && crate::cuda::llama_numerics()), "--kv q8/q4 does not combine with --llama-numerics (its attention reads f16 KV)"); @@ -251,8 +305,13 @@ impl Gpu { let sms = hip.attribute(ffi::ATTR_MULTIPROCESSOR_COUNT, device as i32).unwrap_or(16).max(1) as usize; let wm = hip_wmma && wmma_arch(&arch); let (mla_wmma, idx_wmma) = (wm && std::env::var_os("STRATA_MLA_SIMT").is_none(), wm && std::env::var("STRATA_IDX_WMMA").is_ok_and(|v| v == "1")); + let rdna2 = arch.starts_with("gfx103"); + let blas = (std::env::var("STRATA_HIPBLAS").map(|v| v != "0").unwrap_or(rdna2)) + .then(|| ffi::Blas::open().ok()).flatten() + .filter(|b| b.set_stream(stream).is_ok()); + if blas.is_some() { crate::say!("hipblas: prefill GEMMs run on GemmEx (fp16 in, f32 compute)"); } Ok(Gpu { hip, device, stream, side, marks, next_mark: Default::default(), pinned: Default::default(), beside: Default::default(), beside_lag: Default::default(), fns, arch, kv_mode: if kv_k_mode == kv_v_mode { kv_k_mode } else { 10 }, kv_k_mode, kv_v_mode, flags: ink_flags(), pci, max_smem, sms, mla_wmma, idx_wmma, am: am_buf, - graphs: Mutex::new(HashMap::new()), graph_failed: Default::default(), fr: Mutex::new((HashMap::new(), Vec::new())), staging: Mutex::new(staging) }) + graphs: Mutex::new(HashMap::new()), graph_failed: Default::default(), fr: Mutex::new((HashMap::new(), Vec::new())), staging: Mutex::new(staging), blas, att_kv: Default::default(), att_q: Default::default(), att_s: Default::default(), att_inv: Default::default() }) } pub fn arch(&self) -> &str { &self.arch } @@ -569,6 +628,11 @@ const GRAPHS_MAX: usize = 32; const RING: usize = 64 << 20; /// Mark events of the copy queue (`Gpu::mark`). const MARKS: usize = 64; + +const ATT_QB: usize = 1024; +const ATT_S_BYTES: usize = 768 << 20; +static ATT_FALLBACK: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false); +const ATT_DENSE_MAX: usize = 1 << 40; const RING_MIN: usize = 256 << 10; fn alloc_raw(hip: &Arc, bytes: usize) -> anyhow::Result { @@ -1186,6 +1250,24 @@ impl Backend for Gpu { Ok(()) } + + #[allow(clippy::too_many_arguments)] + fn attn_prefill_m_at(&self, q: u64, kc: u64, vc: u64, qg: u64, out: u64, step: u64, t: usize, nh: usize, nkv: usize, hd: usize, + scale: f32, qm: u64, mw: usize, sink: u64, win: usize, pos: usize) -> anyhow::Result<()> { + if self.blas.is_some() && !ATT_FALLBACK.load(std::sync::atomic::Ordering::Relaxed) + && self.kv_k_mode < 4 && self.kv_v_mode < 4 + && sink == 0 && win == 0 && hd % 8 == 0 && nh % nkv == 0 && t >= 8 && pos + t <= ATT_DENSE_MAX { + match self.attn_prefill_blas(q, kc, vc, qg, out, t, pos, nh, nkv, hd, scale, qm, mw) { + Ok(()) => return Ok(()), + Err(e) if !ATT_FALLBACK.swap(true, std::sync::atomic::Ordering::Relaxed) => { + crate::say!("hipblas attention: {e:#}; the flash kernel takes over"); + } + Err(_) => {} + } + } + self.attn_prefill_m(q, kc, vc, qg, out, step, t, nh, nkv, hd, scale, qm, mw, sink, win) + } + fn qsa_pool(&self, ik: u64, ring: u64, pool: u64, w: u64, step: u64, t: usize, n_rot: usize, base: f32, eps: f32) -> anyhow::Result<()> { launch!(self, "qsa_pool", cfg(((t / 4 + 1) as u32, 1), 128, 0), ik, ring, pool, w, step, t as i32, n_rot as i32, base, eps); Ok(())