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 KiB44 linesraw
1#pragma once
2
3namespace CpuCompute
4{
5	// A large memory buffer allocated with VirtualAlloc kernel API, bypassing the heap.
6	class LargeBuffer
7	{
8		void* pv = nullptr;
9	public:
10		LargeBuffer() = default;
11		LargeBuffer( const LargeBuffer& ) = delete;
12		LargeBuffer( LargeBuffer&& that ) noexcept
13		{
14			pv = that.pv;
15			that.pv = nullptr;
16		}
17		~LargeBuffer()
18		{
19			deallocate();
20		}
21		void operator=( LargeBuffer&& that ) noexcept
22		{
23			std::swap( pv, that.pv );
24		}
25		void operator=( const LargeBuffer& that ) = delete;
26
27		// Allocate buffer with specified count of bytes, and read+write memory protection
28		// The OS kernel guarantees zero-initialization of that memory.
29		HRESULT allocate( size_t cb );
30
31		// Change memory protection of the buffer to read only
32		HRESULT setReadOnly( size_t cb );
33
34		// Unless the pointer is nullptr, deallocate the buffer
35		void deallocate();
36
37		// Pointer to the start of the buffer, aligned by memory page = 4 kilobytes
38		uint8_t* pointer() const
39		{
40			assert( nullptr != pv );
41			return (uint8_t*)pv;
42		}
43	};
44}