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
01325d7
master
1#include "stdafx.h" 2#include "miscUtils.h" 3#include <cmath> 4 5void setCurrentThreadName (const char * threadName ) 6{ 7const DWORD dwThreadID = GetCurrentThreadId (); 8 9// https://stackoverflow.com/a/10364541/126995 10#pragma pack(push,8) 11typedef struct tagTHREADNAME_INFO 12 { 13DWORD dwType ;// Must be 0x1000. 14LPCSTR szName ;// Pointer to name (in user addr space). 15DWORD dwThreadID ;// Thread ID (-1=caller thread). 16DWORD dwFlags ;// Reserved for future use, must be zero. 17 }THREADNAME_INFO ; 18#pragma pack(pop) 19 20THREADNAME_INFO info ; 21info .dwType = 0x1000 ; 22info .szName = threadName ; 23info .dwThreadID = dwThreadID ; 24info .dwFlags = 0 ; 25 26constexpr DWORD MS_VC_EXCEPTION = 0x406D1388 ; 27 __try 28 { 29RaiseException (MS_VC_EXCEPTION ,0 ,sizeof (info ) /sizeof (ULONG_PTR ), (ULONG_PTR * )& info ); 30 } 31 __except(EXCEPTION_EXECUTE_HANDLER ) 32 { 33 } 34} 35 36float computeScaling (int mul ,int div ) 37{ 38#ifdef _DEBUG 39const float ref = (float )std::pow ( (double )mul / (double )div ,-0.25 ); 40#endif 41// Make int32 vector with both numbers 42__m128i iv = _mm_cvtsi32_si128 (mul ); 43iv = _mm_insert_epi32 (iv ,div ,1 ); 44// Convert both numbers to FP64 45__m128d v = _mm_cvtepi32_pd (iv ); 46// Compute mul / div 47v = _mm_div_sd (v ,_mm_unpackhi_pd (v ,v ) ); 48// Square root 49v = _mm_sqrt_sd (v ,v ); 50// 4-th root 51v = _mm_sqrt_sd (v ,v ); 52// Invert the value 53v = _mm_div_sd (_mm_set_sd (1.0 ),v ); 54// Downcast to FP32, and return the result 55__m128 f32 = _mm_cvtsd_ss (_mm_setzero_ps (),v ); 56return _mm_cvtss_f32 (f32 ); 57}