wip: T10 batched forward (validation)
This commit is contained in:
@@ -63,4 +63,26 @@ void launch_transpose_3d01_f32(const float* in, float* out, int a, int b, int c,
|
||||
transpose_3d01_k<<<grid, blk, 0, (cudaStream_t)s>>>(in, out, a, b, c);
|
||||
}
|
||||
|
||||
// =====================================================================
|
||||
// 4D axis-(1,2) transpose: in:[a,b,c,d] -> out:[a,c,b,d]. out[i,k,j,l]=in[i,j,k,l].
|
||||
// Lays out batched multi-head attention: [B,S,nh,hd] <-> [B,nh,S,hd], so a
|
||||
// flattened [B*nh, S, hd] view feeds the strided-batched-GEMM attention. Its own
|
||||
// backward is the same op (swap b,c), so one kernel suffices.
|
||||
// =====================================================================
|
||||
|
||||
__global__ void transpose_4d12_k(const float* in, float* out, int a, int b, int c, int d) {
|
||||
int idx = blockIdx.x * blockDim.x + threadIdx.x; // over a*b*c*d
|
||||
if (idx >= a * b * c * d) return;
|
||||
int l = idx % d;
|
||||
int k = (idx / d) % c;
|
||||
int j = (idx / (d * c)) % b;
|
||||
int i = idx / (d * c * b);
|
||||
// out[i,k,j,l] at ((i*c + k)*b + j)*d + l
|
||||
out[(((i * c + k) * b) + j) * d + l] = in[idx];
|
||||
}
|
||||
void launch_transpose_4d12_f32(const float* in, float* out, int a, int b, int c, int d, void* s) {
|
||||
int n = a * b * c * d, blk = 256, grid = (n + blk - 1) / blk;
|
||||
transpose_4d12_k<<<grid, blk, 0, (cudaStream_t)s>>>(in, out, a, b, c, d);
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
Reference in New Issue
Block a user