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
aaeab77
master
1#pragma once 2#include <atlcoll.h> 3#include "CpuProfiler.h" 4 5namespace DirectCompute 6{ 7enum struct eComputeShader :uint16_t ; 8enum struct eProfilerBlock :uint16_t ; 9} 10 11namespace Whisper 12{ 13struct WhisperModel ; 14 15enum struct eCpuBlock :uint8_t 16 { 17LoadModel , 18RunComplete , 19Run , 20Callbacks , 21Spectrogram , 22Sample , 23VAD , 24Encode , 25Decode , 26DecodeStep , 27DecodeLayer , 28 }; 29 30class ProfileCollection 31 { 32public : 33ProfileCollection (const WhisperModel & model ); 34 35struct Measure 36{ 37size_t count = 0 ; 38// 100-nanosecond ticks 39uint64_t totalTicks = 0 ; 40 41void reset () 42{ 43count = 0 ; 44totalTicks = 0 ; 45} 46 47void ( const char * name ) const; 48 49void add ( uint64_t val ) 50{ 51count ++ ; 52totalTicks += val; 53} 54}; 55 56Measure & measure ( DirectCompute::eProfilerBlock which ); 57Measure & measure ( DirectCompute::eComputeShader which ); 58Measure & measure ( eCpuBlock which ); 59#if PROFILER_COLLECT_TAGS 60Measure & measure ( DirectCompute::eComputeShader which, uint16_t tag ); 61#endif 62void (); 63 64void reset (); 65 66class CpuRaii 67{ 68Measure * dest; 69const int64_t tsc; 70 71public : 72CpuRaii ( Measure & m ) : dest ( & m ), tsc ( tscNow () ) 73{ } 74CpuRaii( const CpuRaii & ) = delete; 75CpuRaii ( CpuRaii && that ) noexcept : 76tsc ( that. tsc ) 77{ 78dest = that. dest ; 79that. dest = nullptr ; 80} 81 82~ CpuRaii () 83{ 84if ( nullptr != dest ) 85{ 86const int64_t elapsed = tscNow () - tsc; 87dest -> add ( ticksFromTsc ( elapsed ) ); 88} 89} 90}; 91 92decltype( auto ) cpuBlock ( eCpuBlock which ) 93{ 94return CpuRaii{ measure( which ) }; 95} 96 97uint16_t makeTagId ( const char * tag ); 98 99private : 100CAtlMap < uint32_t, Measure > measures; 101CComAutoCriticalSection critSec; 102#if PROFILER_COLLECT_TAGS 103CAtlMap < const char * , uint16_t > tagIDs; 104std ::vector < const char *> tagNames; 105CAtlMap < uint32_t, Measure > taggedShaders; 106std ::vector < uint32_t > taggedKeysTemp; 107struct TaggedTemp 108{ 109uint64_t ticks ; 110size_t count ; 111const char * name ; 112 113bool operator < ( const TaggedTemp & that ) const 114{ 115// Flipping the comparison to sort in descending order 116return ticks > that . ticks ; 117} 118 119void () const ; 120}; 121std ::vector < TaggedTemp > taggedTimes; 122#endif 123std ::vector < uint32_t > keysTemp ; 124 }; 125}