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.9 KiB70 linesraw
1// Compute tensor = tensor + repeat( pattern, tensor ) in 1 shot, without VRAM allocations
2// Dispatch [ nb[ 1 ], nb[ 2 ], nb[ 3 ] ] thread groups of this shader, where nb is size of the destination tensor
3RWBuffer<float> tensor: register( u0 );
4Buffer<float> pattern: register( t0 );
5
6cbuffer Constants: register( b0 )
7{
8	uint4 tensorSize: packoffset( c0 );
9	uint4 tensorStrides: packoffset( c1 );
10	uint4 patternSize: packoffset( c2 );
11	uint4 patternStrides: packoffset( c3 );
12}
13
14#ifndef THREADS
15#define THREADS 256
16#endif
17
18#include "repeatUtils.hlsli"
19
20inline void computeSimple( uint idx, float add )
21{
22	float f = tensor[ idx ];
23	f += add;
24	tensor[ idx ] = f;
25}
26
27[ numthreads( THREADS, 1, 1 ) ]
28void main( uint3 group: SV_GroupID, uint thread : SV_GroupIndex )
29{
30	uint3 it = tensorIteratorState( group, thread, tensorSize, tensorStrides );
31	uint rsi = rowOffset( group % patternSize.yzw, patternStrides );
32
33	if( patternSize[ 0 ] == 1 )
34	{
35		// The pattern only has 1 column - broadcasting over the row
36		const float p = pattern[ rsi ];
37		ROW_LOOP( it )
38			computeSimple( it.x, p );
39	}
40	else if( patternSize[ 0 ] <= THREADS )
41	{
42		// pattern size doesn't exceed thread group size: load pattern value outside of the loop
43		const uint threadsPerGroup = THREADS - ( THREADS % patternSize[ 0 ] );
44		if( thread >= threadsPerGroup )
45			return;
46
47		const float p = pattern[ rsi + ( thread % patternSize[ 0 ] ) * patternStrides[ 0 ] ];
48		ROW_LOOP_EX( it, threadsPerGroup, tensorStrides )
49			computeSimple( it.x, p );
50	}
51	else
52	{
53		// Pattern rows are larger than the thread group, need to stream from both buffers
54		const uint rsiInc = THREADS * patternStrides[ 0 ];
55		const uint rsiDec = patternSize[ 0 ] * patternStrides[ 0 ];
56		const uint rsiEnd = rsi + rsiDec;
57		rsi += thread * patternStrides[ 0 ];
58
59		ROW_LOOP( it )
60		{
61			float f = tensor[ it.x ];
62			float p = pattern[ rsi ];
63			rsi += rsiInc;
64			if( rsi >= rsiEnd )
65				rsi -= rsiDec;
66			f += p;
67			tensor[ it.x ] = f;
68		}
69	}
70}