QSA scorer: an FP32 fallback for Turing (the experimental sm_75 build, a layer-split stage on a 2080 Ti)

This commit is contained in:
Niko1221 committed 2026-09-29 00:14:23 +02:00
1 parent 500eb977a9
commit c8b10915aa
1 file changed
+20
+20
View File
@@ -32,6 +32,7 @@ constexpr int D=128, HEADS=4, R=4, ROWS=32, WARPS=2, STRIDE=36, COMBINE=68;
struct TileA { uint32_t x[4]; };
struct TileB { uint32_t x[2]; };
struct TileC { float x[4]={0.0f,0.0f,0.0f,0.0f}; };
#if !defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 800
__device__ __forceinline__ void load_a(TileA& a,const float* p) {
const float* src=p+(threadIdx.x%16)*STRIDE+(threadIdx.x/16)*4;
asm volatile("ldmatrix.sync.aligned.m8n8.x4.b16 {%0,%1,%2,%3}, [%4];"
@@ -48,6 +49,7 @@ __device__ __forceinline__ void mma(TileC& c,const TileA& a,const TileB& b) {
: "+f"(c.x[0]),"+f"(c.x[1]),"+f"(c.x[2]),"+f"(c.x[3])
: "r"(a.x[0]),"r"(a.x[1]),"r"(a.x[2]),"r"(a.x[3]),"r"(b.x[0]),"r"(b.x[1]));
}
#endif
__global__ __launch_bounds__(64,1) void score_kernel(
const float* __restrict__ pooled,const float* __restrict__ query,
const float* __restrict__ bias,const int32_t* __restrict__ step,
@@ -58,6 +60,23 @@ __global__ __launch_bounds__(64,1) void score_kernel(
const int row0=blockIdx.x*ROWS;
if(row0>full)return;
const int lane=threadIdx.x,warp=threadIdx.y;
#if defined(__CUDA_ARCH__) && __CUDA_ARCH__ < 800
// Turing (STRATA_EXPERIMENTAL_SM75, a layer-split stage): no tf32 mma. The same scores with FP32 FMAs, one row
// per thread of the first warp - rounded differently from the tensor-core path (FP32 instead of TF32 inputs).
if(warp!=0)return;
const int row=row0+lane;
if(row>full)return;
float h[HEADS];
for(int j=0;j<HEADS;++j){
float acc=0.0f;
for(int d=0;d<D;++d)acc=fmaf(pooled[size_t(row)*D+d],query[j*D+d],acc);
h[j]=fmaxf(acc,0.0f);
}
float sum=__fadd_rn(__fadd_rn(__fadd_rn(h[0],h[1]),h[2]),h[3]);
if(bias)sum=__fadd_rn(sum,bias[row]);
sum=__fadd_rn(sum,row==full&&n%R?1e9f:0.0f);
for(int i=row*R;i<n&&i<(row+1)*R;++i)cells[i]=sum;
#else
__shared__ __align__(16) float shared[WARPS*16*STRIDE];
float* tile=shared+warp*16*STRIDE;
TileC c[2];
@@ -118,6 +137,7 @@ __global__ __launch_bounds__(64,1) void score_kernel(
sum=__fadd_rn(sum,0.0f);
for(int i=row*R;i<n&&i<(row+1)*R;++i)cells[i]=sum;
}
#endif
}
struct Span{const void* p;size_t n;};
void validate(Span s){