From 8c4603c73675958efc960fbd4bb599a2909d106a Mon Sep 17 00:00:00 2001 From: Konstantin Date: Mon, 16 Jan 2023 14:52:43 +0100 Subject: Source codes --- Whisper/ML/LookupTables.cpp | 54 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 Whisper/ML/LookupTables.cpp (limited to 'Whisper/ML/LookupTables.cpp') diff --git a/Whisper/ML/LookupTables.cpp b/Whisper/ML/LookupTables.cpp new file mode 100644 index 0000000..2fc1cc8 --- /dev/null +++ b/Whisper/ML/LookupTables.cpp @@ -0,0 +1,54 @@ +#include "stdafx.h" +#include "LookupTables.h" +#include "LookupTablesData.h" +#include +using namespace DirectCompute; + +namespace +{ + HRESULT uploadLookupTable( const std::array& rsi, CComPtr& rdi ) + { + rdi = nullptr; + CComPtr buffer; + + CD3D11_BUFFER_DESC desc{ 0x10000 * 2, D3D11_BIND_SHADER_RESOURCE, D3D11_USAGE_IMMUTABLE }; + D3D11_SUBRESOURCE_DATA srd{ rsi.data(), 0, 0 }; + CHECK( device()->CreateBuffer( &desc, &srd, &buffer ) ); + + CD3D11_SHADER_RESOURCE_VIEW_DESC viewDesc{ D3D11_SRV_DIMENSION_BUFFER, DXGI_FORMAT_R16_UINT, 0, 0x10000 }; + CHECK( device()->CreateShaderResourceView( buffer, &viewDesc, &rdi ) ); + + return S_OK; + } +} + +HRESULT LookupTables::create() +{ + std::unique_ptr data; + try + { + data = std::make_unique(); + } + catch( const std::bad_alloc& ) + { + return E_OUTOFMEMORY; + } + + CHECK( uploadLookupTable( data->gelu, m_gelu ) ); + CHECK( uploadLookupTable( data->exponent, m_exponent ) ); + + return S_OK; +} + +void LookupTables::clear() +{ + m_gelu = nullptr; + m_exponent = nullptr; +} + +__m128i LookupTables::getMemoryUsage() const +{ + __m128i v = resourceMemoryUsage( m_gelu ); + v = _mm_add_epi64( v, resourceMemoryUsage( m_exponent ) ); + return v; +} \ No newline at end of file -- cgit v1.2.3