Pascal decode: keep __restrict__ and drop the PDL prefetch below sm_70 (#1469, #1470)

2e4ddf6 (the #904 port) removed __restrict__ from the activation pointers of
native_quantize_q8_1_kernel, bf16_f32_mmvf_multi_kernel and
native_mmvq_multi_kernel on every CUDA architecture, and turned on the weight
prefetch before pdl_wait(). Both only matter for PDL (sm_90+). On sm_61 the
missing restrict loses the read-only data path (LDG.CI) and decode halves
(36.4 -> 17.7 tok/s on a Tesla P40, 32-36 -> 17.7-18.6 on a GTX 1080 + 1070).

STRATA_PDL_RESTRICT is __restrict__ and kPdlPrefetch false again for
__CUDA_ARCH__ < 700 in the device pass. sm_70 and newer compile to the same
SASS as before (cuobjdump -sass of native_mmvq.cu and native_bf16.cu at sm_70,
86, 90 and 120 is identical); the host pass is unchanged.

Reported and bisected by paulhothersall and lineape.
This commit is contained in:
Niko1221 committed 2026-10-08 02:58:44 +02:00
1 parent d5ea713374
commit c788e2aa72
3 files changed
+23 -9

No files matched your search

+12 -2
View File
@@ -33,10 +33,16 @@ bool pdl_supported();
#if (defined(__CUDACC__) || defined(__HIPCC__))
// not __CUDA_ARCH__-dependent: the host pass must see the same kernel signature (MSVC rejects the template stubs
// otherwise), so on CUDA these parameters lose __restrict__ for every architecture
// STRATA_PDL_RESTRICT never goes on a __global__ signature: the host pass and the stub must see the same signature on
// every architecture (MSVC rejects the template stubs otherwise, and so does g++ when the stub is generated from a
// device pass). A kernel takes plain pointers and declares `const T* STRATA_PDL_RESTRICT p = p_;` locals in its body.
// On CUDA the activation pointers lose __restrict__ so the compiler cannot load them before pdl_wait() - but only
// where PDL can run (sm_70 and newer here). On Pascal and older (__CUDA_ARCH__ < 700, no PDL) `__restrict__` is what
// lets the compiler use the read-only data path (LDG.CI): without it decode on sm_61 halves (#1469).
#if defined(__HIPCC__)
#define STRATA_PDL_RESTRICT __restrict__
#elif defined(__CUDA_ARCH__) && (__CUDA_ARCH__ < 700)
#define STRATA_PDL_RESTRICT __restrict__
#else
#define STRATA_PDL_RESTRICT
#endif
@@ -44,7 +50,11 @@ bool pdl_supported();
#if defined(__HIPCC__)
inline constexpr bool kPdlPrefetch = false; // HIP: no PDL, the kernels keep their plain loops
#else
#if defined(__CUDA_ARCH__) && (__CUDA_ARCH__ < 700)
inline constexpr bool kPdlPrefetch = false; // Pascal and older: no PDL, the prefetch only costs registers (#1469)
#else
inline constexpr bool kPdlPrefetch = true; // CUDA: the weights a kernel can load before pdl_wait() are loaded there
#endif
/// `kernel` may be launched with the PDL attribute into `stream` now (see the header comment).
bool pdl_launch_ok(const void* kernel, cudaStream_t stream);
#endif
+4 -2
View File
@@ -75,8 +75,10 @@ __global__ void bf16_f32_mmvf_kernel(const float* __restrict__ x, const uint16_t
// token keeps its own accumulator with exactly the single-row kernel's order (pairs, two ordered FMAs, the same warp
// and block reductions), so each output is bit-identical to a bf16_f32_mmvf_kernel launch of its own.
template <int BLOCK_SIZE, int NT, bool EXACT_T = true>
__global__ void bf16_f32_mmvf_multi_kernel(const float* STRATA_PDL_RESTRICT x, int64_t ldx, const uint16_t* __restrict__ w,
float* STRATA_PDL_RESTRICT y, int64_t ldy, int n_in, int n_tok) {
__global__ void bf16_f32_mmvf_multi_kernel(const float* x_, int64_t ldx, const uint16_t* __restrict__ w,
float* y_, int64_t ldy, int n_in, int n_tok) {
const float* STRATA_PDL_RESTRICT x = x_; // __restrict__ below sm_70 only (pdl.hpp, #1469)
float* STRATA_PDL_RESTRICT y = y_;
const int t = threadIdx.x;
const uint16_t* row = w + (size_t) blockIdx.x * n_in;
const uint32_t* weights2 = reinterpret_cast<const uint32_t*>(row);
+7 -5
View File
@@ -150,8 +150,9 @@ __device__ __forceinline__ float warp_max(float x) {
}
__launch_bounds__(QUANT_THREADS, 1)
__global__ void native_quantize_q8_1_kernel(const float* STRATA_PDL_RESTRICT x,
Q81Block* STRATA_PDL_RESTRICT y, int n_in) {
__global__ void native_quantize_q8_1_kernel(const float* x_, Q81Block* y_, int n_in) {
const float* STRATA_PDL_RESTRICT x = x_; // __restrict__ below sm_70 only (pdl.hpp, #1469)
Q81Block* STRATA_PDL_RESTRICT y = y_;
pdl_trigger(); // PDL (pdl.hpp): the projection after this one may start loading its weights
pdl_wait();
const int i = int(blockIdx.x) * QUANT_THREADS + int(threadIdx.x);
@@ -1162,10 +1163,11 @@ static bool s26_tsum_on() {
// input in one launch; each output's code is the single matrix's)
template<typename F, int NCOLS, int NW, int ROWS, bool TS = false, bool PAIR = false>
__launch_bounds__(NW * WARP, (ROWS <= 2 ? 4 : 1))
__global__ void native_mmvq_multi_kernel(const typename F::Block* __restrict__ w,
const Q81Block* STRATA_PDL_RESTRICT x,
float* STRATA_PDL_RESTRICT y, int n_in, int n_out,
__global__ void native_mmvq_multi_kernel(const typename F::Block* __restrict__ w, const Q81Block* x_, float* y_,
int n_in, int n_out,
const typename F::Block* __restrict__ w2 = nullptr, float* __restrict__ y2 = nullptr) {
const Q81Block* STRATA_PDL_RESTRICT x = x_; // __restrict__ below sm_70 only (pdl.hpp, #1469)
float* STRATA_PDL_RESTRICT y = y_;
constexpr int BPI = F::BPI * NW / WARPS; // blocks per iteration scale with the warp count
const int tid = WARP * int(threadIdx.y) + int(threadIdx.x);
int bxi = int(blockIdx.x);