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 + 31 ) / 32, 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 double eps = 1e-5 ; // TODO: make this a parameter 14 15#include "groupReduce.hlsli" 16 17double computeVectorSum ( uint i , const uint length ) 18{ 19double res = 0.0 ; 20const uint iEnd = i + length ; 21for ( ; i < iEnd ; i ++ ) 22res += arg0 [ i ]; 23return res ; 24} 25 26double offsetAndComputeSumSquares ( uint rsi , uint rdi , const double mean , const uint length ) 27{ 28 precisedouble sum2 = 0.0 ; 29const uint rsiEnd = rsi + length ; 30for ( ; rsi < rsiEnd ; rsi ++ , rdi ++ ) 31{ 32double v = arg0 [ rsi ]; 33v -= mean ; 34result [ rdi ] = ( float ) v ; 35double prod = v * v ; 36sum2 += prod ; 37} 38return sum2 ; 39} 40 41void scaleVector ( uint rdi , const float scale , const uint length ) 42{ 43const uint rdiEnd = rdi + length ; 44for ( ; rdi < rdiEnd ; rdi ++ ) 45{ 46float f = result [ rdi ]; 47f *= scale ; 48result [ rdi ] = f ; 49} 50} 51 52#include "fp64Utils.hlsli" 53 54[ numthreads ( 32 , 1 , 1 ) ] 55void main ( uint3 dtid : SV_DispatchThreadID ) 56{ 57const uint i03 = dtid . z ; 58const uint i02 = dtid . y ; 59const uint i01 = dtid . x ; 60if ( i01 >= src0_elements [ 1 ] ) 61return ; 62 63const uint nb01 = src0_strides [ 1 ]; 64const uint nb02 = src0_strides [ 2 ]; 65const uint nb03 = src0_strides [ 3 ]; 66 67const uint p = i01 * nb01 + i02 * nb02 + i03 * nb03 ; 68const uint ne00 = src0_elements [ 0 ]; 69 70double mean = computeVectorSum ( p , ne00 ); 71mean = div64 ( mean , ( double )( int ) ne00 ); 72 73const uint nb1 = result_strides [ 1 ]; 74const uint nb2 = result_strides [ 2 ]; 75const uint nb3 = result_strides [ 3 ]; 76const uint y = i01 * nb1 + i02 * nb2 + i03 * nb3 ; 77 78const double sum2 = offsetAndComputeSumSquares ( p , y , mean , ne00 ); 79const float scale = ( float ) div64 ( 1.0 , sqrt64 ( sum2 / ( float )( int ) ne00 + eps ) ); 80 81scaleVector ( y , scale , ne00 ); 82}