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
2.2 KiB77 linesraw
1// Implementation of fmaRepeat() when both source arguments have same size and strides
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> patternMul: register( t0 );
5Buffer<float> patternAdd: register( t1 );
6
7cbuffer Constants: register( b0 )
8{
9	uint4 tensorSize: packoffset( c0 );
10	uint4 tensorStrides: packoffset( c1 );
11	uint4 patternSize: packoffset( c2 );
12	uint4 patternStrides: packoffset( c3 );
13}
14
15#ifndef THREADS
16#define THREADS 512
17#endif
18
19#include "repeatUtils.hlsli"
20
21inline void computeSimple( uint idx, float mul, float add )
22{
23	precise float f = tensor[ idx ];
24	f *= mul;
25	f += add;
26	tensor[ idx ] = f;
27}
28
29[ numthreads( THREADS, 1, 1 ) ]
30void main( uint3 group: SV_GroupID, uint thread : SV_GroupIndex )
31{
32	uint3 it = tensorIteratorState( group, thread, tensorSize, tensorStrides );
33	uint rsi = rowOffset( group % patternSize.yzw, patternStrides );
34
35	if( patternSize[ 0 ] == 1 )
36	{
37		// The pattern only has 1 column - broadcasting over the row
38		const float pMul = patternMul[ rsi ];
39		const float pAdd = patternAdd[ rsi ];
40		ROW_LOOP( it )
41			computeSimple( it.x, pMul, pAdd );
42	}
43	else if( patternSize[ 0 ] <= THREADS )
44	{
45		// pattern size doesn't exceed thread group size: load pattern value outside of the loop
46		const uint threadsPerGroup = THREADS - ( THREADS % patternSize[ 0 ] );
47		if( thread >= threadsPerGroup )
48			return;
49
50		rsi += ( thread % patternSize[ 0 ] ) * patternStrides[ 0 ];
51		const float pMul = patternMul[ rsi ];
52		const float pAdd = patternAdd[ rsi ];
53		ROW_LOOP_EX( it, threadsPerGroup, tensorStrides )
54			computeSimple( it.x, pMul, pAdd );
55	}
56	else
57	{
58		// Pattern rows are larger than the thread group, need to stream from both buffers
59		const uint rsiInc = THREADS * patternStrides[ 0 ];
60		const uint rsiDec = patternSize[ 0 ] * patternStrides[ 0 ];
61		const uint rsiEnd = rsi + rsiDec;
62		rsi += thread * patternStrides[ 0 ];
63
64		ROW_LOOP( it )
65		{
66			precise float f = tensor[ it.x ];
67			float mul = patternMul[ rsi ];
68			float add = patternAdd[ rsi ];
69			rsi += rsiInc;
70			if( rsi >= rsiEnd )
71				rsi -= rsiDec;
72			f *= mul;
73			f += add;
74			tensor[ it.x ] = f;
75		}
76	}
77}