diff --git a/src/kernels/cuda/iq_kernels.cu b/src/kernels/cuda/iq_kernels.cu index 17ef0a8d..bd388c8a 100644 --- a/src/kernels/cuda/iq_kernels.cu +++ b/src/kernels/cuda/iq_kernels.cu @@ -1752,8 +1752,13 @@ void launch_mmvq(const uint8_t* W, size_t rb, const block_q8_1* X, float* y, int // Bitwise equal to native_gu_multi_kernel / native_down_multi_kernel (S26 harness, real UD-IQ4_XS expert blobs, T 1-3, // memcmp of every output): each row's lane sums and warp_sum are the same; a warp interleaves RPW rows (more loads in // flight) and reads the chunk's activation rows from LDS and, for IQ3_S, the grid table from LDS (the same values). +#if defined(__HIPCC__) +#define STRATA_NT_LOAD(p) __builtin_nontemporal_load(p) +#else // (opt-in S26 kernels, AMD-tuned: a CUDA build compiles them with plain loads) +#define STRATA_NT_LOAD(p) (*(p)) +#endif template __device__ __forceinline__ int ld16i(const uint16_t* p) { - if constexpr (NT) return (int) __builtin_nontemporal_load(p); else return (int) *p; + if constexpr (NT) return (int) STRATA_NT_LOAD(p); else return (int) *p; } template __device__ __forceinline__ int ldb2(const void* x, int i32) { const uint16_t* x16 = (const uint16_t*) x; @@ -1762,7 +1767,7 @@ template __device__ __forceinline__ int ldb2(const void* x, int i32) { return x32; } template __device__ __forceinline__ int ld8i(const uint8_t* p) { - if constexpr (NT) return (int) __builtin_nontemporal_load(p); else return (int) *p; + if constexpr (NT) return (int) STRATA_NT_LOAD(p); else return (int) *p; } template __device__ __forceinline__ float ldhalf(const half* p) { return __half2float(__ushort_as_half((unsigned short) ld16i(reinterpret_cast(p)))); @@ -1881,7 +1886,7 @@ __global__ void __launch_bounds__(256) s26_gu_l_kernel(const unsigned long long* __syncthreads(); // the previous chunk is done with s_x for (int i = threadIdx.x; i < n * xb; i += 256) { const int c = i / xb, j = i - c * xb; - s_x[c * S26_XMAX + j] = xq[(size_t) ent_tok[e + c] * xb + j]; + memcpy(&s_x[c * S26_XMAX + j], &xq[(size_t) ent_tok[e + c] * xb + j], sizeof(s_x[0])); } #pragma unroll for (int c = 0; c < GRP_NC; ++c) off[c] = min(c, n - 1) * S26_XMAX; @@ -1965,7 +1970,7 @@ __global__ void __launch_bounds__(256) s26_down_l_kernel(const unsigned long lon __syncthreads(); for (int i = threadIdx.x; i < n * hb; i += 256) { const int c = i / hb, j = i - c * hb; - s_h[c * S26_HMAX + j] = hq[(size_t) (e + c) * hb + j]; + memcpy(&s_h[c * S26_HMAX + j], &hq[(size_t) (e + c) * hb + j], sizeof(s_h[0])); } __syncthreads(); #pragma unroll @@ -2248,7 +2253,7 @@ __global__ void __launch_bounds__(256) s27_gu_kernel(const unsigned long long* _ __syncthreads(); // the previous chunk is done with s_x for (int i = threadIdx.x; i < n * xb; i += 256) { const int c = i / xb, j = i - c * xb; - s_x[c * S26_XMAX + j] = xq[(size_t) ent_tok[e + c] * xb + j]; + memcpy(&s_x[c * S26_XMAX + j], &xq[(size_t) ent_tok[e + c] * xb + j], sizeof(s_x[0])); } #pragma unroll for (int c = 0; c < GRP_NC; ++c) off[c] = min(c, n - 1) * S26_XMAX; @@ -2332,7 +2337,7 @@ __global__ void __launch_bounds__(256) s27_down_kernel(const unsigned long long* __syncthreads(); for (int i = threadIdx.x; i < n * hb; i += 256) { const int c = i / hb, j = i - c * hb; - s_h[c * S26_HMAX + j] = hq[(size_t) (e + c) * hb + j]; + memcpy(&s_h[c * S26_HMAX + j], &hq[(size_t) (e + c) * hb + j], sizeof(s_h[0])); } __syncthreads(); #pragma unroll diff --git a/src/kernels/cuda/s26_tsum.cuh b/src/kernels/cuda/s26_tsum.cuh index 38cfc97c..575ec8e2 100644 --- a/src/kernels/cuda/s26_tsum.cuh +++ b/src/kernels/cuda/s26_tsum.cuh @@ -24,8 +24,8 @@ template __device__ __forceinline__ float xmov(float v) { return __shfl_xor_sync(0xffffffffu, v, O); } #endif -constexpr int pow2_ceil(int t) { return t <= 1 ? 1 : t <= 2 ? 2 : t <= 4 ? 4 : t <= 8 ? 8 : t <= 16 ? 16 : 32; } -constexpr int log2c(int p) { return p <= 1 ? 0 : p == 2 ? 1 : p == 4 ? 2 : p == 8 ? 3 : p == 16 ? 4 : 5; } +__host__ __device__ constexpr int pow2_ceil(int t) { return t <= 1 ? 1 : t <= 2 ? 2 : t <= 4 ? 4 : t <= 8 ? 8 : t <= 16 ? 16 : 32; } +__host__ __device__ constexpr int log2c(int p) { return p <= 1 ? 0 : p == 2 ? 1 : p == 4 ? 2 : p == 8 ? 3 : p == 16 ? 4 : 5; } template __device__ __forceinline__ float tplain(float x) { diff --git a/src/prefill/wmma_gemm.h b/src/prefill/wmma_gemm.h index 1e54e911..f9551c91 100644 --- a/src/prefill/wmma_gemm.h +++ b/src/prefill/wmma_gemm.h @@ -26,8 +26,14 @@ bool strata_pf_gemm_f16(const uint16_t* X, const uint16_t* W, float* Y, int64_t /// S23 (STRATA_PF_HCDOWN=1): lo[t, n] = sum_k X[t, k] Wd[n, k] (n < nd) and inj[t, n] = sum_k X[t, k] Wi[n, k] /// (n < ni) in one BF16 WMMA GEMM over X (T x K, token stride ldx >= K, a multiple of 8; Wd / Wi row-major, stride /// K); lo T x nd and inj T x ni, FP32. K a multiple of 64, T >= 64. False (nothing launched) otherwise / off gfx11. +#if defined(STRATA_USE_HIP) bool strata_pf_hcdown_bf16(const uint16_t* X, int64_t ldx, const uint16_t* Wd, const uint16_t* Wi, int64_t nd, int64_t ni, float* lo, float* inj, int64_t T, int64_t K, void* stream = nullptr); +#else +// wmma_gemm.cu is part of the AMD builds only: another build has no such kernel (prefill.cpp then stops with its error) +inline bool strata_pf_hcdown_bf16(const uint16_t*, int64_t, const uint16_t*, const uint16_t*, int64_t, int64_t, float*, float*, + int64_t, int64_t, void* = nullptr) { return false; } +#endif /// S (STRATA_HCD_EXACT=1): Y[t, n] = sum_k X[t, k] W[n, k] for N 320, K 10240 (BF16, FP32 out, X token stride ldx >= K, a /// multiple of 8), bitwise equal to hipBLASLt solution 1176 / 1177 for that shape (its k order, StaggerU included). /// False (nothing launched) for any other shape / off gfx11.