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.8 KiB76 linesraw
1// ggml_compute_forward_conv_1d_1s_f16_f32, GGML_TASK_COMPUTE implementation
2// Dispatch [ ne10, 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 completeVectors = len / 32;
22	uint i;
23	for( i = 0; i < completeVectors; i++, s0 += 32, s1 += 32 )
24		curr = mad( arg0[ s0 + thread ], arg1[ s1 + thread ], curr );
25
26	horizontalSumCompatNew( thread, curr );
27
28	if( 0 == thread )
29	{
30		const uint rem = len % 32;
31		if( 0 != rem )
32		{
33			double f64 = curr;
34			for( i = 0; i < rem; i++ )
35			{
36				precise float a = arg0[ s0 + i ];
37				precise float b = arg1[ s1 + i ];
38				precise float prod = a * b;
39				f64 += prod;
40			}
41			curr = (float)f64;
42		}
43		acc += curr;
44	}
45}
46
47#include "miscUtils.hlsli"
48
49[ numthreads( 32, 1, 1 ) ]
50void main( uint3 group: SV_GroupID, uint thread : SV_GroupIndex )
51{
52	const uint i1 = group.y;
53	const uint i0 = group.x;
54
55	const uint ne00 = src0_elements[ 0 ];
56	const uint nk = ne00;
57	const int nh = (int)( nk / 2 );
58
59	const uint ne01 = src0_elements[ 1 ];
60	const int ew0 = roundUp32( ne01 );
61
62	float res = 0;
63	for( int k = -nh; k <= nh; k++ )
64	{
65		const uint source0 = i1 * ew0 * ne00 + uint( nh + k ) * ew0;
66		const uint source1 = uint( i0 + nh + k ) * ew0;
67		computeDotProduct( source0, source1, ew0, thread, res );
68	}
69
70	if( 0 != thread )
71		return;
72
73	const uint nb1 = result_strides[ 1 ];
74	const uint rdi = i1 * nb1 + i0;
75	result[ rdi ] = res;
76}