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#include "stdafx.h" 2#include "LookupTables.h" 3#include "LookupTablesData.h" 4#include <memory> 5using namespace DirectCompute ; 6 7namespace 8{ 9HRESULT uploadLookupTable (const std::array < uint16_t ,0x10000 >& rsi ,CComPtr < ID3D11ShaderResourceView >& rdi ) 10 { 11rdi = nullptr ; 12CComPtr < ID3D11Buffer > buffer ; 13 14CD3D11_BUFFER_DESC desc {0x10000 * 2 ,D3D11_BIND_SHADER_RESOURCE ,D3D11_USAGE_IMMUTABLE }; 15D3D11_SUBRESOURCE_DATA srd {rsi .data (),0 ,0 }; 16CHECK (device ()-> CreateBuffer (& desc ,& srd ,& buffer ) ); 17 18CD3D11_SHADER_RESOURCE_VIEW_DESC viewDesc {D3D11_SRV_DIMENSION_BUFFER ,DXGI_FORMAT_R16_UINT ,0 ,0x10000 }; 19CHECK (device ()-> CreateShaderResourceView (buffer ,& viewDesc ,& rdi ) ); 20 21return S_OK ; 22 } 23} 24 25HRESULT LookupTables ::create () 26{ 27 std::unique_ptr < LookupTablesData > data ; 28try 29 { 30data = std::make_unique < LookupTablesData > (); 31 } 32catch (const std::bad_alloc & ) 33 { 34return E_OUTOFMEMORY ; 35 } 36 37CHECK (uploadLookupTable (data -> gelu ,m_gelu ) ); 38CHECK (uploadLookupTable (data -> exponent ,m_exponent ) ); 39 40return S_OK ; 41} 42 43void LookupTables ::clear () 44{ 45m_gelu = nullptr ; 46m_exponent = nullptr ; 47} 48 49__m128i LookupTables ::getMemoryUsage ()const 50{ 51__m128i v = resourceMemoryUsage (m_gelu ); 52v = _mm_add_epi64 (v ,resourceMemoryUsage (m_exponent ) ); 53return v ; 54}