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
984 B42 linesraw
1#pragma once
2#include "Tensor.h"
3
4namespace DirectCompute
5{
6	// A tensor which supports dynamic updates from CPU, or downloads from VRAM to system RAM
7	class TensorEx : public Tensor
8	{
9	protected:
10		CComPtr<ID3D11Buffer> buffer;
11		CComPtr<ID3D11Buffer> stagingBuffer;
12
13		HRESULT getViewSize( uint32_t& cbElement, uint32_t& countElements ) const;
14
15	public:
16
17		HRESULT create( const ggml_tensor& ggml, eBufferUse usage, bool uploadData );
18		HRESULT create( eDataType type, eBufferUse usage, const std::array<uint32_t, 4>& sizeElements );
19
20		HRESULT download( void* rdi, size_t cb ) const;
21
22		HRESULT download( void* rdi ) const;
23
24		template<class E>
25		HRESULT download( std::vector<E>& vec ) const
26		{
27			uint32_t cbElement, numElements;
28			CHECK( getViewSize( cbElement, numElements ) );
29
30			try
31			{
32				vec.resize( numElements );
33			}
34			catch( const std::bad_alloc& )
35			{
36				return E_OUTOFMEMORY;
37			}
38
39			return download( vec.data(), (size_t)cbElement * numElements );
40		}
41	};
42}