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
2.2 KiB63 linesraw
1#include "stdafx.h"
2#include "Binder.h"
3#include <algorithm>
4using namespace DirectCompute;
5
6void Binder::bind( ID3D11ShaderResourceView* srv0, ID3D11UnorderedAccessView* uav0 )
7{
8	ID3D11DeviceContext* const ctx = context();
9	ctx->CSSetUnorderedAccessViews( 0, 1, &uav0, nullptr );
10
11	ctx->CSSetShaderResources( 0, 1, &srv0 );
12
13	maxSrv = std::max( maxSrv, (uint8_t)1 );
14	maxUav = std::max( maxUav, (uint8_t)1 );
15}
16
17void Binder::bind( ID3D11UnorderedAccessView* uav0 )
18{
19	context()->CSSetUnorderedAccessViews( 0, 1, &uav0, nullptr );
20	maxUav = std::max( maxUav, (uint8_t)1 );
21}
22
23void Binder::bind( ID3D11ShaderResourceView* srv0, ID3D11ShaderResourceView* srv1, ID3D11UnorderedAccessView* uav0 )
24{
25	ID3D11DeviceContext* const ctx = context();
26	ctx->CSSetUnorderedAccessViews( 0, 1, &uav0, nullptr );
27
28	std::array< ID3D11ShaderResourceView*, 2> arr = { srv0, srv1 };
29	ctx->CSSetShaderResources( 0, 2, arr.data() );
30
31	maxSrv = std::max( maxSrv, (uint8_t)2 );
32	maxUav = std::max( maxUav, (uint8_t)1 );
33}
34
35void Binder::bind( std::initializer_list<ID3D11ShaderResourceView*> srvs, std::initializer_list<ID3D11UnorderedAccessView*> uavs )
36{
37	ID3D11DeviceContext* const ctx = context();
38
39	const size_t lengthResources = srvs.size();
40	const size_t lengthUnordered = uavs.size();
41	assert( lengthResources > 0 && lengthResources < D3D11_COMMONSHADER_INPUT_RESOURCE_REGISTER_COUNT );
42	assert( lengthUnordered > 0 && lengthUnordered < D3D11_PS_CS_UAV_REGISTER_COUNT );
43
44	ctx->CSSetUnorderedAccessViews( 0, (UINT)lengthUnordered, uavs.begin(), nullptr );
45	ctx->CSSetShaderResources( 0, (UINT)lengthResources, srvs.begin() );
46
47	maxSrv = std::max( maxSrv, (uint8_t)lengthResources );
48	maxUav = std::max( maxUav, (uint8_t)lengthUnordered );
49}
50
51Binder::~Binder()
52{
53	uint8_t count = std::max( maxSrv, maxUav );
54	if( 0 == count )
55		return;
56#pragma warning (disable: 6255) // Compiler doesn't know we have very few of these things
57	size_t* arr = (size_t*)_alloca( count * sizeof( size_t ) );
58	memset( arr, 0, count * sizeof( size_t ) );
59
60	ID3D11DeviceContext* const ctx = context();
61	ctx->CSSetShaderResources( 0, maxSrv, (ID3D11ShaderResourceView**)arr );
62	ctx->CSSetUnorderedAccessViews( 0, maxUav, (ID3D11UnorderedAccessView**)arr, nullptr );
63}