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.3 KiB46 linesraw
1groupshared float sharedAccumulators[ 64 ];
2
3// Compute horisontal sum of the numbers. The result is only correct on the thread #0 of the group.
4void horizontalSum( const uint thread, inout float sum )
5{
6	sharedAccumulators[ thread ] = sum;
7	for( uint i = 32; i > 1; i /= 2 )
8	{
9		GroupMemoryBarrierWithGroupSync();
10		if( thread < i )
11		{
12			sum += sharedAccumulators[ thread + i ];
13			sharedAccumulators[ thread ] = sum;
14		}
15	}
16	GroupMemoryBarrierWithGroupSync();
17	if( 0 == thread )
18		sum += sharedAccumulators[ 1 ];
19}
20
21// Compute horisontal sum of the numbers, and broadcast to all threads of the group.
22void horizontalSumBroadcast( const uint thread, inout float sum )
23{
24	horizontalSum( thread, sum );
25	if( 0 == thread )
26		sharedAccumulators[ 0 ] = sum;
27	GroupMemoryBarrierWithGroupSync();
28	sum = sharedAccumulators[ 0 ];
29}
30
31// Compute horizontal maximum of the numbers, and broadcast to all threads of the group.
32void horizontalMaxBroadcast( const uint thread, inout float ax )
33{
34	sharedAccumulators[ thread ] = ax;
35	for( uint i = 32; i > 0; i /= 2 )
36	{
37		GroupMemoryBarrierWithGroupSync();
38		if( thread < i )
39		{
40			ax = max( ax, sharedAccumulators[ thread + i ] );
41			sharedAccumulators[ thread ] = ax;
42		}
43	}
44	GroupMemoryBarrierWithGroupSync();
45	ax = sharedAccumulators[ 0 ];
46}