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
901 B40 linesraw
1#include "stdafx.h"
2#include "LookupTablesData.h"
3#include <immintrin.h>
4using namespace DirectCompute;
5
6namespace
7{
8	inline float fp32( uint16_t f16 )
9	{
10		__m128i i = _mm_cvtsi32_si128( f16 );
11		__m128 f = _mm_cvtph_ps( i );
12		return _mm_cvtss_f32( f );
13	}
14
15	inline uint16_t fp16( float fp32 )
16	{
17		__m128 f = _mm_set_ss( fp32 );
18		__m128i i = _mm_cvtps_ph( f, 0 );
19		uint32_t res = (uint32_t)_mm_cvtsi128_si32( i );
20		return (uint16_t)res;
21	}
22
23	constexpr double GELU_COEF_A = 0.044715;
24	constexpr double SQRT_2_OVER_PI = 0.79788456080286535587989211986876;
25
26	inline float computeGelu( float x )
27	{
28		return (float)( 0.5 * x * ( 1.0 + tanh( SQRT_2_OVER_PI * x * ( 1.0 + GELU_COEF_A * x * x ) ) ) );
29	}
30}
31
32LookupTablesData::LookupTablesData()
33{
34	for( int i = 0; i < 0x10000; i++ )
35	{
36		const float f = fp32( i );
37		gelu[ i ] = fp16( computeGelu( f ) );
38		exponent[ i ] = fp16( (float)exp( f ) );
39	}
40}