diff --git a/CMakeLists.txt b/CMakeLists.txt index daef8bfe..7e9017cf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -114,6 +114,11 @@ if(STRATA_ENABLE_CUDA) "CUDA 12.8 crashed on long prompts on these cards (issues #220, #224). Use CUDA 13.0 or newer.") endif() endforeach() + if(STRATA_EXPERIMENTAL_SM60) + # every target sees it: the Pascal / Volta code paths (the Volta prompt attention, PR #600) are compiled into this + # build only, so the ready-made engine (sm_75+) keeps exactly the code it had + add_compile_definitions(STRATA_EXPERIMENTAL_SM60=1) + endif() message(STATUS "Strata: CUDA enabled, arch ${CMAKE_CUDA_ARCHITECTURES}") set(_strata_gpu_runtime_target CUDA::cudart) set(_strata_gpu_blas_target CUDA::cublas) diff --git a/src/kernels/cuda/qsa_prompt_attn.cu b/src/kernels/cuda/qsa_prompt_attn.cu index 914690af..8062176c 100644 --- a/src/kernels/cuda/qsa_prompt_attn.cu +++ b/src/kernels/cuda/qsa_prompt_attn.cu @@ -737,7 +737,9 @@ bool launch(const float* q, const QsaAttnPools& pools, const int32_t* ids, const } -#if !defined(__HIPCC__) +// PR #600: compiled only into the experimental build (-DSTRATA_EXPERIMENTAL_SM60=ON), the one build that runs on a +// Volta card; the ready-made engine has none of it (no extra kernels to load, the same code as before). +#if !defined(__HIPCC__) && defined(STRATA_EXPERIMENTAL_SM60) // ---- sm_70 (Volta): v1's structure on mma.m8n8k4 ------------------------------------------------------------------ // Volta's tensor cores only have m8n8k4 (FP16 in, FP32 accumulate): per warp FOUR independent 8x8x4 products, one per // quad-pair (QP q = lanes 4q..4q+3 and 4q+16..4q+19; thread j = (lane & 3) + 4 * (lane >> 4) within it). Layout, measured on @@ -1111,13 +1113,13 @@ bool launch70(const float* q, const QsaAttnPools& pools, const int32_t* ids, con } return true; } -#else // AMD: no m8n8k4 kernel; the dispatcher never selects it there +#else // AMD, or a build without STRATA_EXPERIMENTAL_SM60: no m8n8k4 kernel (the caller keeps the old one) template bool launch70(const float*, const QsaAttnPools&, const int32_t*, const int32_t*, int64_t, const QsaShapes&, float*, int64_t, cudaStream_t) { return false; } -#endif // !__HIPCC__ +#endif // !__HIPCC__ && STRATA_EXPERIMENTAL_SM60 #if defined(__HIPCC__) // ---- S6: the int8-KV prompt attention on RDNA4 matrix cores (opt-in: STRATA_HIP_WMMA=1, gfx12 only). The design of diff --git a/src/prefill/gemm.cu b/src/prefill/gemm.cu index 1d71bbb7..445c7447 100644 --- a/src/prefill/gemm.cu +++ b/src/prefill/gemm.cu @@ -402,18 +402,20 @@ __global__ void bf16_to_f16_kernel(const uint16_t* __restrict__ in, __half* __re out[i] = __float2half_rn(f); } } -__global__ void bf16_to_f32_kernel(const uint16_t* __restrict__ in, float* __restrict__ out, int64_t n) { - const int64_t i = (int64_t) blockIdx.x * blockDim.x + threadIdx.x; - if (i < n) out[i] = __uint_as_float((uint32_t) in[i] << 16); -} void bf16_to_f16(const uint16_t* in, uint16_t* out, int64_t n, cudaStream_t st) { if (n <= 0) return; bf16_to_f16_kernel<<<(unsigned) ((n + 255) / 256), 256, 0, st>>>(in, reinterpret_cast<__half*>(out), n); } +#if defined(STRATA_EXPERIMENTAL_SM60) // Pascal runs only the experimental build +__global__ void bf16_to_f32_kernel(const uint16_t* __restrict__ in, float* __restrict__ out, int64_t n) { + const int64_t i = (int64_t) blockIdx.x * blockDim.x + threadIdx.x; + if (i < n) out[i] = __uint_as_float((uint32_t) in[i] << 16); +} void bf16_to_f32(const uint16_t* in, float* out, int64_t n, cudaStream_t st) { if (n <= 0) return; bf16_to_f32_kernel<<<(unsigned) ((n + 255) / 256), 256, 0, st>>>(in, out, n); } +#endif // The current device's compute capability as 10 * major + minor, per device (a layer split can mix cards); 0: not // known, read as "not an old card" so a failed query keeps the cuBLAS BF16 call. int current_cc() { @@ -483,7 +485,9 @@ void Gemm::bf16(const uint16_t* X, const uint16_t* W, float* Y, int64_t T, int64 } return; } - } else if (path == 2) { + } +#if defined(STRATA_EXPERIMENTAL_SM60) + else if (path == 2) { // Pascal: fp32 copies (2 elements of the 2-byte buffers each). Every tile is a disjoint block of Y, so each // gets the caller's beta. const int64_t x_rows = std::max(1, std::min(T, kXSliceElems / K)); @@ -501,6 +505,7 @@ void Gemm::bf16(const uint16_t* X, const uint16_t* W, float* Y, int64_t T, int64 return; } } +#endif #endif // Column-major view: Y^T[N, T] = W[N, K] (stored K x N col-major, transposed) . X^T[K, T]. ck(cublasGemmEx((cublasHandle_t) handle_, CUBLAS_OP_T, CUBLAS_OP_N, (int) N, (int) T, (int) K, &alpha, W,