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// Compute tensor = ( tensor + repeat( pattern, tensor ) ) * scale 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{ 8uint4 tensorSize :packoffset ( c0 ); 9uint4 tensorStrides :packoffset ( c1 ); 10uint4 patternSize :packoffset ( c2 ); 11uint4 patternStrides :packoffset ( c3 ); 12float scalingMul :packoffset ( c4 . x ); 13} 14 15#ifndef THREADS 16#define THREADS 512 17#endif 18 19#include "repeatUtils.hlsli" 20 21inline void computeSimple ( uint idx , float add ) 22{ 23float f = tensor [ idx ]; 24f += add ; 25f *= scalingMul ; 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 p = pattern [ rsi ]; 39ROW_LOOP ( it ) 40computeSimple ( it . x , p ); 41} 42else if ( patternSize [ 0 ] <= THREADS ) 43{ 44// pattern size doesn't exceed thread group size: load pattern value outside of the loop 45const uint threadsPerGroup = THREADS - ( THREADS % patternSize [ 0 ] ); 46if ( thread >= threadsPerGroup ) 47return ; 48 49const float p = pattern [ rsi + ( thread % patternSize [ 0 ] ) * patternStrides [ 0 ] ]; 50ROW_LOOP_EX ( it , threadsPerGroup , tensorStrides ) 51computeSimple ( it . x , p ); 52} 53else 54{ 55// Pattern rows are larger than the thread group, need to stream from both buffers 56const uint rsiInc = THREADS * patternStrides [ 0 ]; 57const uint rsiDec = patternSize [ 0 ] * patternStrides [ 0 ]; 58const uint rsiEnd = rsi + rsiDec ; 59rsi += thread * patternStrides [ 0 ]; 60 61ROW_LOOP ( it ) 62{ 63float f = tensor [ it . x ]; 64float p = pattern [ rsi ]; 65rsi += rsiInc ; 66if ( rsi >= rsiEnd ) 67rsi -= rsiDec ; 68f += p ; 69f *= scalingMul ; 70tensor [ it . x ] = f ; 71} 72} 73}