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.6 KiB56 linesraw
1// ggml_compute_forward_dup_f32 when we actually need to reshape the tensor
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{
8	uint4 src0_elements: packoffset( c0 );
9	uint4 src0_strides: packoffset( c1 );
10	bool downcastFp32 : packoffset( c2.x );
11}
12
13#include "miscUtils.hlsli"
14
15[ numthreads( 32, 1, 1 ) ]
16void main( uint3 group: SV_GroupID, uint thread : SV_GroupIndex )
17{
18	const uint nb00 = src0_strides[ 0 ];
19	const uint nb01 = src0_strides[ 1 ];
20	const uint nb02 = src0_strides[ 2 ];
21	const uint nb03 = src0_strides[ 3 ];
22
23	const uint ne00 = src0_elements[ 0 ];
24	const uint ne01 = src0_elements[ 1 ];
25	const uint ne02 = src0_elements[ 2 ];
26	const uint ne03 = src0_elements[ 3 ];
27
28	const uint i01 = group.x;
29	const uint i02 = group.y;
30	const uint i03 = group.z;
31
32	// We need following integer: i01*ne00 + i02*ne00*ne01 + i03*ne00*ne01*ne02
33	// We want to minimize count of integer multiplications
34	// Also, DXBC assembly features `imad` instruction which computes a*b+c for integers, the actual hardware hopefully has an equivalent
35	// i03*ne00*ne01*ne02 + i02*ne00*ne01 + i01*ne00
36	// ( i03*ne01*ne02 + i02*ne01 + i01 ) * ne00
37	// ( ( i03*ne02 + i02) * ne01 + i01 ) * ne00
38	uint rdi = ( ( i03 * ne02 + i02 ) * ne01 + i01 ) * ne00;
39
40	const uint rdiEnd = rdi + ne00;
41
42	uint rsi = i01 * nb01 + i02 * nb02 + i03 * nb03;
43	const uint rsiInc = 32 * nb00;
44
45	rdi += thread;
46	rsi += thread * nb00;
47
48	for( ; rdi < rdiEnd; rdi += 32, rsi += rsiInc )
49	{
50		float f = arg0[ rsi ];
51		[branch]
52		if( downcastFp32 )
53			f = adjustFp16( f );
54		result[ rdi ] = f;
55	}
56}