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#pragma once 2#include "LargeBuffer.h" 3#include "Tensor.h" 4 5namespace CpuCompute 6{ 7#ifdef NDEBUG 8inline void dbgMarkUninitializedMemory (void * pv ,size_t cb ) { } 9inline void dbgMarkFreedMemory (void * pv ,size_t cb ) { } 10#else 11void dbgMarkUninitializedMemory (void * pv ,size_t cb ); 12void 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 16class BufferAllocator :public iArenaAllocator 17 { 18LargeBuffer buffer ; 19size_t head = 0 ; 20size_t size = 0 ; 21 22void resetArena ()noexcept override final 23 { 24head = 0 ; 25dbgMarkFreedMemory (buffer .pointer (),size ); 26 } 27 28void * allocate (size_t cb ,size_t align )noexcept override final ; 29 30public : 31BufferAllocator ()= default ; 32BufferAllocator (const BufferAllocator & )= delete ; 33 ~BufferAllocator ()= default ; 34 35// Allocate a large buffer with the specified count of bytes 36HRESULT 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. 40class VirtualAllocator :public iArenaAllocator 41 { 42uint8_t * pointer = nullptr ; 43size_t head = 0 ; 44size_t sizeAllocated = 0 ; 45size_t sizeVirtual = 0 ; 46 47void resetArena ()noexcept override final 48 { 49head = 0 ; 50dbgMarkFreedMemory (pointer ,sizeAllocated ); 51 } 52 53void * allocate (size_t cb ,size_t align )noexcept override final ; 54 55public : 56 57VirtualAllocator ()= default ; 58VirtualAllocator (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 62HRESULT create (size_t cb ); 63 }; 64}