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
8c4603c
master
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{ 9uint4 tensorSize :packoffset ( c0 ); 10uint4 tensorStrides :packoffset ( c1 ); 11uint4 patternSize :packoffset ( c2 ); 12uint4 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 precisefloat f = tensor [ idx ]; 24f *= mul ; 25f += add ; 26tensor [ idx ] = f ; 27} 28 29[ numthreads ( THREADS , 1 , 1 ) ] 30void main ( uint3 group : SV_GroupID , uint thread : SV_GroupIndex ) 31{ 32uint3 it = tensorIteratorState ( group , thread , tensorSize , tensorStrides ); 33uint rsi = rowOffset ( group % patternSize . yzw , patternStrides ); 34 35if ( patternSize [ 0 ] == 1 ) 36{ 37// The pattern only has 1 column - broadcasting over the row 38const float pMul = patternMul [ rsi ]; 39const float pAdd = patternAdd [ rsi ]; 40ROW_LOOP ( it ) 41computeSimple ( it . x , pMul , pAdd ); 42} 43else if ( patternSize [ 0 ] <= THREADS ) 44{ 45// pattern size doesn't exceed thread group size: load pattern value outside of the loop 46const uint threadsPerGroup = THREADS - ( THREADS % patternSize [ 0 ] ); 47if ( thread >= threadsPerGroup ) 48return ; 49 50rsi += ( thread % patternSize [ 0 ] ) * patternStrides [ 0 ]; 51const float pMul = patternMul [ rsi ]; 52const float pAdd = patternAdd [ rsi ]; 53ROW_LOOP_EX ( it , threadsPerGroup , tensorStrides ) 54computeSimple ( it . x , pMul , pAdd ); 55} 56else 57{ 58// Pattern rows are larger than the thread group, need to stream from both buffers 59const uint rsiInc = THREADS * patternStrides [ 0 ]; 60const uint rsiDec = patternSize [ 0 ] * patternStrides [ 0 ]; 61const uint rsiEnd = rsi + rsiDec ; 62rsi += thread * patternStrides [ 0 ]; 63 64ROW_LOOP ( it ) 65{ 66 precisefloat f = tensor [ it . x ]; 67float mul = patternMul [ rsi ]; 68float add = patternAdd [ rsi ]; 69rsi += rsiInc ; 70if ( rsi >= rsiEnd ) 71rsi -= rsiDec ; 72f *= mul ; 73f += add ; 74tensor [ it . x ] = f ; 75} 76} 77}