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

KonstantinSource codes8c4603c

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