yum-archive/TaSTT-Whisper

High-performance GPGPU inference of OpenAI's Whisper automatic speech recognition (ASR) model

git clone https://git.yummers.dev/yum-archive/TaSTT-Whisper

KonstantinSource codes8c4603c

master
1.2 KiB46 linesraw
1#ifndef THREADS
2#define THREADS 256
3#endif
4
5// dec.tokenEmbedding tensor
6Buffer<float> tokenEmbedding: register( t0 );
7// dec.positionalEmbedding tensor
8Buffer<float> positionalEmbedding: register( t1 );
9// R32_UINT buffer with the input tokens
10Buffer<uint> embd: register( t2 );
11// Output tensor
12RWBuffer<float> result: register( u0 );
13
14cbuffer Constants: register( b0 )
15{
16	uint rowLength: packoffset( c0.x );
17	uint pastTokensCount: packoffset( c0.y );
18	uint outputRowStride: packoffset( c0.z );
19	uint2 embStrides: packoffset( c1.x );
20	uint2 posStrides: packoffset( c1.z );
21}
22
23[ numthreads( THREADS, 1, 1 ) ]
24void main( uint3 group: SV_GroupID, uint thread : SV_GroupIndex )
25{
26	const uint row = group.x;
27	const uint rowTok = embd[ row ];
28	const uint rowPos = row + pastTokensCount;
29
30	uint rdi = row * outputRowStride;
31	const uint rdiEnd = rdi + rowLength;
32	rdi += thread;
33
34	uint rsiTok = rowTok * embStrides.y;
35	rsiTok += thread * embStrides.x;
36
37	uint rsiPos = rowPos * posStrides.y;
38	rsiPos += thread * posStrides.x;
39
40	for( ; rdi < rdiEnd; rdi += THREADS, rsiTok += THREADS * embStrides.x, rsiPos += THREADS * posStrides.x )
41	{
42		float a = tokenEmbedding[ rsiTok ];
43		float b = positionalEmbedding[ rsiPos ];
44		result[ rdi ] = a + b;
45	}
46}