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.0 KiB32 linesraw
1#include "stdafx.h"
2#include "KeyValueDownloader.h"
3
4HRESULT KeyValueDownloader::create( const Whisper::sModelParams& mp )
5{
6	const uint32_t n_audio_ctx = mp.n_audio_ctx;
7	const uint32_t n_mem = mp.n_text_layer * mp.n_audio_ctx;
8	const uint32_t n_elements = mp.n_text_state * n_mem;
9
10	CD3D11_BUFFER_DESC desc{ n_elements * 2, 0, D3D11_USAGE_STAGING, D3D11_CPU_ACCESS_READ };
11	ID3D11Device* dev = DirectCompute::device();
12	CHECK( dev->CreateBuffer( &desc, nullptr, &keys ) );
13	CHECK( dev->CreateBuffer( &desc, nullptr, &values ) );
14
15	length = n_elements;
16	return S_OK;
17}
18
19HRESULT KeyValueDownloader::download( const DirectCompute::KeyValueBuffers& source )
20{
21	ID3D11DeviceContext* ctx = DirectCompute::context();
22	ctx->CopyResource( keys, source.keys.getBuffer() );
23	ctx->CopyResource( values, source.values.getBuffer() );
24	return S_OK;
25}
26
27KeyValueDownloader::ReadMap::ReadMap( KeyValueDownloader& owner ) :
28	length( owner.length )
29{
30	check( mappedKeys.map( owner.keys, true ) );
31	check( mappedValues.map( owner.values, true ) );
32}