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

KonstantinSource codes8c4603c

master
1.2 KiB62 linesraw
1// ggml_compute_forward_soft_max_f32
2// Dispatch [ ( nr + 31 ) / 32, 1, 1 ] thread groups of this shader
3RWBuffer<float> result: register( u0 );
4
5// table_exp_f16
6Buffer<uint> lookupTable: register( t0 );
7
8cbuffer Constants: register( b0 )
9{
10	uint4 elements: packoffset( c0 );
11	uint4 strides: packoffset( c1 );
12	uint nr: packoffset( c2.x );
13}
14
15#include "miscUtils.hlsli"
16#include "fp64Utils.hlsli"
17
18static const float negativeInfinity = asfloat( 0xff800000 );
19
20[ numthreads( 32, 1, 1 ) ]
21void main( uint3 dtid: SV_DispatchThreadID )
22{
23	if( dtid.x >= nr )
24		return;
25
26	const uint p = dtid.x * strides[ 1 ];
27	const uint nc = elements[ 0 ];
28	const uint pEnd = p + nc;
29	uint i;
30
31	float m = negativeInfinity;
32	for( i = p; i < pEnd; i++ )
33		m = max( m, result[ i ] );
34
35	double sum = 0;
36	for( i = p; i < pEnd; i++ )
37	{
38		float f = result[ i ];
39
40		[branch]
41		if( f != negativeInfinity )
42		{
43			uint s = fp16Rounded( f - m );
44			s = lookupTable[ s ];
45			f = f16tof32( s );
46			sum += f;
47		}
48		else
49			f = 0;
50
51		result[ i ] = f;
52	}
53
54	const float scale = (float)div64( 1.0, sum );
55	// ggml_vec_scale_f32
56	for( i = p; i < pEnd; i++ )
57	{
58		float f = result[ i ];
59		f *= scale;
60		result[ i ] = f;
61	}
62}