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#include "../Whisper/WhisperModel.h" 3#include "../CPU/MlContext.h" 4#include "../CPU/BufferAllocator.h" 5#include "KeyValueDownloader.h" 6#include "../CPU/KvTensors.h" 7 8// This version of the hybrid context uses the new, custom-built kernels 9class HybridContext 10{ 11CpuCompute ::MlContext ml ; 12CpuCompute ::VirtualAllocator allocCompute ,allocComputeLayer ; 13 14class AllocSingle :public CpuCompute ::iArenaAllocator 15 { 16CpuCompute ::LargeBuffer buffer ; 17size_t capacity = 0 ; 18bool allocated = false; 19// Inherited via iArenaAllocator 20virtual void * allocate (size_t cb ,size_t align )override final ; 21 22public : 23virtual void resetArena ()override final ; 24 }; 25AllocSingle allocLayerOutput ; 26 27const CpuCompute ::DecoderTensors & model ; 28const Whisper ::WhisperModel & whisperModel ; 29KeyValueDownloader kvCross ; 30CpuCompute ::KvTensors kv ; 31 32class SetAllocatorRaii ; 33 34public : 35 36HybridContext (const Whisper ::WhisperModel & wm ); 37 38HRESULT create (); 39 40HRESULT downloadKeyValues (const DirectCompute ::KeyValueBuffers & source ) 41 { 42return kvCross .download (source ); 43 } 44 45struct sDecParams 46 { 47int n_threads ; 48int M ; 49 }; 50 51HRESULT decode (const int * tokens ,const int n_tokens ,const int n_past ,const sDecParams & dp ,std ::vector < float >& probs_out ); 52};