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