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 "ConstantBuffer.h" 3#include "../D3D/MappedResource.h" 4using namespace DirectCompute ; 5 6HRESULT ConstantBuffer ::create () 7{ 8if (nullptr == buffer ) 9 { 10CD3D11_BUFFER_DESC desc {16 * 3 * 2 ,D3D11_BIND_CONSTANT_BUFFER ,D3D11_USAGE_DYNAMIC ,D3D11_CPU_ACCESS_WRITE }; 11return device ()-> CreateBuffer (& desc ,nullptr ,& buffer ); 12 } 13return HRESULT_FROM_WIN32 (ERROR_ALREADY_INITIALIZED ); 14} 15 16namespace 17{ 18 __forceinlinevoid copy32 (__m128i * rdi ,const TensorShape & ts ) 19 { 20_mm_storeu_si128 (rdi ,ts .sizeVec () ); 21_mm_storeu_si128 (rdi + 1 ,ts .stridesVec () ); 22 } 23} 24 25HRESULT ConstantBuffer ::update (const TensorShape & t0 ) 26{ 27MappedResource mapped ; 28CHECK (mapped .map (buffer , false ) ); 29 30__m128i * const rdi = (__m128i * )mapped .data (); 31copy32 (rdi ,t0 ); 32return S_OK ; 33} 34 35HRESULT ConstantBuffer ::update (const TensorShape & t0 ,const TensorShape & t1 ) 36{ 37MappedResource mapped ; 38CHECK (mapped .map (buffer , false ) ); 39 40__m128i * const rdi = (__m128i * )mapped .data (); 41copy32 (rdi ,t0 ); 42copy32 (rdi + 2 ,t1 ); 43return S_OK ; 44} 45 46HRESULT ConstantBuffer ::update (const TensorShape & t0 ,const TensorShape & t1 ,const TensorShape & t2 ) 47{ 48MappedResource mapped ; 49CHECK (mapped .map (buffer , false ) ); 50 51__m128i * const rdi = (__m128i * )mapped .data (); 52copy32 (rdi ,t0 ); 53copy32 (rdi + 2 ,t1 ); 54copy32 (rdi + 4 ,t2 ); 55return S_OK ; 56} 57 58void ConstantBuffer ::bind ()const 59{ 60ID3D11Buffer * p = buffer ; 61assert (nullptr != p ); 62context ()-> CSSetConstantBuffers (0 ,1 ,& p ); 63}