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
11c399b
master
1#pragma once 2#include <atlcomcli.h> 3#include <string> 4 5namespace DirectCompute 6{ 7ID3D11Device * device (); 8ID3D11DeviceContext * context (); 9D3D_FEATURE_LEVEL featureLevel (); 10 11HRESULT initialize (uint32_t flags ); 12void terminate (); 13 14// DXGI_ADAPTER_DESC.VendorId magic numbers; they come from that database: https://pcisig.com/membership/member-companies 15enum struct eGpuVendor :uint16_t 16 { 17AMD = 0x1002 , 18NVidia = 0x10de , 19Intel = 0x8086 , 20VMWare = 0x15ad , 21 }; 22 23enum struct eGpuEffectiveFlags :uint8_t 24 { 25Wave64 = 1 , 26ReshapedMatMul = 2 , 27 }; 28 29struct sGpuInfo 30 { 31eGpuEffectiveFlags flags ; 32eGpuVendor vendor ; 33uint16_t device ,revision ; 34uint32_t subsystem ; 35size_t vramDedicated ,ramDedicated ,ramShared ; 36std ::wstring description ; 37 38inline bool wave64 ()const 39 { 40return 0 != ( (uint8_t )flags & (uint8_t )eGpuEffectiveFlags ::Wave64 ); 41 } 42 43// On nVidia 1080Ti that approach is much slower, by a factor of 2.4 44// On AMD Cezanne that approach is faster by a factor of 0.69, i.e. 30% faster. 45// Dunno why that is, maybe 'coz on that AMD complete panels fit in L3 cache. 46// Anyway, we do want extra 30% perf on AMD Cezanne, so only using that code on AMD GPUs. 47// Dunno how it gonna behave on other GPUs, need to test. 48inline bool useReshapedMatMul ()const 49 { 50return 0 != ( (uint8_t )flags & (uint8_t )eGpuEffectiveFlags ::ReshapedMatMul ); 51 } 52 }; 53extern const sGpuInfo & gpuInfo ; 54 55inline bool available () 56 { 57return nullptr != device (); 58 } 59 60inline void csSetCB (ID3D11Buffer * cb ) 61 { 62context ()-> CSSetConstantBuffers (0 ,1 ,& cb ); 63 } 64 65__m128i bufferMemoryUsage (ID3D11Buffer * buffer ); 66 67__m128i resourceMemoryUsage (ID3D11ShaderResourceView * srv ); 68}