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// Ported from ggml_compute_forward_norm_f32 2// Dispatch [ ne01, ne02, ne03 ] thread groups of this shader 3Buffer < float > arg0 :register ( t0 ); 4RWBuffer < float > result :register ( u0 ); 5 6cbuffer Constants :register ( b0 ) 7{ 8uint4 src0_elements :packoffset ( c0 ); 9uint4 src0_strides :packoffset ( c1 ); 10uint4 result_strides :packoffset ( c3 ); 11} 12 13static const float eps = 1e-5f ; // TODO: make this a parameter 14 15#include "groupReduce.hlsli" 16 17float computeVectorSum ( uint i , const uint length , const uint thread ) 18{ 19float res = 0.0 ; 20 21const uint iEnd = i + length ; 22i += thread ; 23for ( ; i < iEnd ; i += 32 ) 24res += arg0 [ i ]; 25 26horizontalSumBroadcast ( thread , res ); 27return res ; 28} 29 30float offsetAndComputeSumSquares ( uint rsi , uint rdi , const float mean , const uint length , const uint thread ) 31{ 32float sum2 = 0.0 ; 33 34const uint rsiEnd = rsi + length ; 35rsi += thread ; 36rdi += thread ; 37for ( ; rsi < rsiEnd ; rsi += 32 , rdi += 32 ) 38{ 39float v = arg0 [ rsi ] - mean ; 40result [ rdi ] = v ; 41sum2 = mad ( v , v , sum2 ); 42} 43 44horizontalSumBroadcast ( thread , sum2 ); 45return sum2 ; 46} 47 48void scaleVector ( uint rdi , const float scale , const uint length , const uint thread ) 49{ 50const uint rdiEnd = rdi + length ; 51for ( rdi += thread ; rdi < rdiEnd ; rdi += 32 ) 52{ 53float f = result [ rdi ]; 54f *= scale ; 55result [ rdi ] = f ; 56} 57} 58 59[ numthreads ( 32 , 1 , 1 ) ] 60void main ( uint3 group : SV_GroupID , uint thread : SV_GroupIndex ) 61{ 62const uint i03 = group . z ; 63const uint i02 = group . y ; 64const uint i01 = group . x ; 65 66const uint nb01 = src0_strides [ 1 ]; 67const uint nb02 = src0_strides [ 2 ]; 68const uint nb03 = src0_strides [ 3 ]; 69 70const uint p = i01 * nb01 + i02 * nb02 + i03 * nb03 ; 71 72const uint ne00 = src0_elements [ 0 ]; 73 74float mean = computeVectorSum ( p , ne00 , thread ); 75mean /= ( float )( int ) ne00 ; 76 77const uint nb1 = result_strides [ 1 ]; 78const uint nb2 = result_strides [ 2 ]; 79const uint nb3 = result_strides [ 3 ]; 80const uint y = i01 * nb1 + i02 * nb2 + i03 * nb3 ; 81 82float sum2 = offsetAndComputeSumSquares ( p , y , mean , ne00 , thread ); 83const float scale = 1.0 / sqrt ( sum2 / ( float )( int ) ne00 + eps ); 84 85scaleVector ( y , scale , ne00 , thread ); 86}