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