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
cacec67
master
1#include "stdafx.h" 2#include "DelayExecution.h" 3 4namespace 5{ 6constexpr bool useHighRezTimer = false; 7 8constexpr int64_t sleepMicroseconds = 200 ; 9 10inline HRESULT sleepImpl (HANDLE timer ) 11 { 12constexpr int64_t sleepTicks = sleepMicroseconds * 10 ; 13 14LARGE_INTEGER li ; 15// Negative values indicate relative time 16li .QuadPart = - sleepTicks ; 17if ( !SetWaitableTimerEx (timer ,& li ,0 ,nullptr ,nullptr ,nullptr ,0 ) ) 18return getLastHr (); 19const DWORD res = WaitForSingleObject (timer ,50 ); 20if (res == WAIT_OBJECT_0 ) 21return S_OK ; 22if (res == WAIT_FAILED ) 23return getLastHr (); 24return E_FAIL ; 25 } 26} 27 28void DelayExecution ::sleepOnTheTimer (const DelayExecution & delay ) 29{ 30HRESULT hr = sleepImpl (delay .timer ); 31if (SUCCEEDED (hr ) ) 32return ; 33logWarningHr (hr ,u8"DelayExecution.sleepOnTheTimer" ); 34} 35 36void DelayExecution ::spinWait (const DelayExecution & ) 37{ 38for (size_t i = 0 ;i < 1024 ;i ++ ) 39_mm_pause (); 40} 41 42void DelayExecution ::sleep (const DelayExecution & ) 43{ 44Sleep (0 ); 45} 46 47DelayExecution ::DelayExecution () 48{ 49if constexpr (useHighRezTimer ) 50 { 51constexpr DWORD flags = CREATE_WAITABLE_TIMER_HIGH_RESOLUTION ; 52HANDLE h = CreateWaitableTimerEx (nullptr ,nullptr ,flags ,TIMER_ALL_ACCESS ); 53if (nullptr != h ) 54 { 55timer .Attach (h ); 56pfn = & sleepOnTheTimer ; 57return ; 58 } 59 60const HRESULT hr = getLastHr (); 61logWarningHr (hr ,u8"CreateWaitableTimerEx" ); 62 } 63 64pfn = & spinWait ; 65// pfn = &sleep; 66}