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.7 KiB64 linesraw
1#pragma once
2#include "LargeBuffer.h"
3#include "Tensor.h"
4
5namespace CpuCompute
6{
7#ifdef NDEBUG
8	inline void dbgMarkUninitializedMemory( void* pv, size_t cb ) { }
9	inline void dbgMarkFreedMemory( void* pv, size_t cb ) { }
10#else
11	void dbgMarkUninitializedMemory( void* pv, size_t cb );
12	void dbgMarkFreedMemory( void* pv, size_t cb );
13#endif
14
15	// An implementation of arena allocator which slices pieces of a large buffer allocated in advance
16	class BufferAllocator : public iArenaAllocator
17	{
18		LargeBuffer buffer;
19		size_t head = 0;
20		size_t size = 0;
21
22		void resetArena() noexcept override final
23		{
24			head = 0;
25			dbgMarkFreedMemory( buffer.pointer(), size );
26		}
27
28		void* allocate( size_t cb, size_t align ) noexcept override final;
29
30	public:
31		BufferAllocator() = default;
32		BufferAllocator( const BufferAllocator& ) = delete;
33		~BufferAllocator() = default;
34
35		// Allocate a large buffer with the specified count of bytes
36		HRESULT create( size_t cb );
37	};
38
39	// An implementation of arena allocator which allocates a large chunk of virtual memory, and maps new physical pages into that memory region as needed.
40	class VirtualAllocator : public iArenaAllocator
41	{
42		uint8_t* pointer = nullptr;
43		size_t head = 0;
44		size_t sizeAllocated = 0;
45		size_t sizeVirtual = 0;
46
47		void resetArena() noexcept override final
48		{
49			head = 0;
50			dbgMarkFreedMemory( pointer, sizeAllocated );
51		}
52
53		void* allocate( size_t cb, size_t align ) noexcept override final;
54
55	public:
56
57		VirtualAllocator() = default;
58		VirtualAllocator( const VirtualAllocator& ) = delete;
59		~VirtualAllocator();
60
61		// Reserve virtual memory space for the specified count of bytes in the arena, but don't allocate any pages
62		HRESULT create( size_t cb );
63	};
64}