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.7 KiB60 linesraw
1// ggml_compute_forward_conv_1d_2s_f16_f32, GGML_TASK_COMPUTE implementation
2// Dispatch [ ne10 / 2, ne02, 1 ] thread groups
3Buffer<float> arg0: register( t0 );
4Buffer<float> arg1: register( t1 );
5RWBuffer<float> result: register( u0 );
6
7cbuffer Constants: register( b0 )
8{
9	uint4 src0_elements: packoffset( c0 );
10	uint4 src0_strides: packoffset( c1 );
11	uint4 src1_elements: packoffset( c2 );
12	uint4 result_elements: packoffset( c4 );
13	uint4 result_strides: packoffset( c5 );
14}
15
16#include "groupReduce.hlsli"
17
18inline void computeDotProduct( uint s0, uint s1, uint len, uint thread, inout float acc )
19{
20	float curr = 0;
21	const uint s0End = s0 + len;
22	s0 += thread;
23	s1 += thread;
24	for( ; s0 < s0End; s0 += 32, s1 += 32 )
25		curr = mad( arg0[ s0 ], arg1[ s1 ], curr );
26
27	horizontalSumCompatNew( thread, curr );
28	if( 0 == thread )
29		acc += curr;
30}
31
32#include "miscUtils.hlsli"
33
34[ numthreads( 32, 1, 1 ) ]
35void main( uint3 group: SV_GroupID, uint thread : SV_GroupIndex )
36{
37	const uint ne00 = src0_elements[ 0 ];
38	const uint ne01 = src0_elements[ 1 ];
39	const int ew0 = roundUp32( ne01 );
40
41	float res = 0;
42	uint s0 = group.y * ew0 * ne00;
43	uint s1 = group.x * 2 * ew0;
44	// The original implementation did following:
45	// int nh = (int)( nk / 2 );
46	// for( int k = -nh; k <= nh; k++ )
47	// What we doing instead:
48	// for( uint len = ( nk / 2 ) * 2 + 1, i = 0; i < len; i++ )
49	// len = ( nk / 2 ) * 2 + 1 is equal to ( nk | 1 )
50	const uint s0End = s0 + ( ne00 | 1u ) * ew0;
51	for( ; s0 < s0End; s0 += ew0, s1 += ew0 )
52		computeDotProduct( s0, s1, ew0, thread, res );
53
54	if( 0 != thread )
55		return;
56
57	const uint nb1 = result_strides[ 1 ];
58	const uint rdi = group.y * nb1 + group.x;
59	result[ rdi ] = res;
60}