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#pragma once 2 3namespace Whisper 4{ 5// A callback to offload to the thread pool 6using pfnParallelForCallback = HRESULT (* )(int ith ,void * ctx )noexcept ; 7 8// A simple parallel for implementation; Windows includes a decent thread pool since Vista (2006) 9HRESULT parallelFor (pfnParallelForCallback pfn ,int threadsCount ,void * ctx ); 10 11// Use this version when you wanna use the thread pool repeatedly, for the same work. 12// This class caches native work handle, saving a couple of WinAPI calls. 13class alignas(64 )ThreadPoolWork 14 { 15PTP_WORK work = nullptr ; 16 17// We want these volatile fields in another cache line from the rest of the data of this class. 18// threadIndex field is concurrently modified by different CPU cores, and these cache coherency protocols are slow. 19// OTOH, work and callback fields of this class only change when created / destroyed, that cache line is shared by CPU cores without any performance penalty. 20 alignas(64 )volatile long threadIndex = 0 ; 21volatile HRESULT status = E_UNEXPECTED ; 22 23static void __stdcallcallbackStatic (PTP_CALLBACK_INSTANCE Instance ,PVOID pv ,PTP_WORK Work ); 24 25protected : 26virtual HRESULT threadPoolCallback (int ith )noexcept = 0 ; 27 28public : 29ThreadPoolWork ()= default ; 30ThreadPoolWork (const ThreadPoolWork & )= delete ; 31 32 ~ThreadPoolWork (); 33 34HRESULT create (); 35 36HRESULT parallelFor (int threadsCount )noexcept ; 37 }; 38}