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.2 KiB46 linesraw
1#include "stdafx.h"
2#include "TraceReader.h"
3using namespace Tracing;
4
5const sTraceItem& TraceReader::operator[]( size_t idx ) const
6{
7	if( idx >= countItems )
8		throw E_BOUNDS;
9	return items[ idx ];
10}
11
12CStringA TraceReader::getName( const sTraceItem& item ) const
13{
14	const size_t idx = item.stringIndex;
15	if( idx >= countStrings )
16		throw E_BOUNDS;
17	const char* const source = stringData + stringIndex[ idx ];
18	CStringA res;
19	res.Format( source, item.formatArgs[ 0 ], item.formatArgs[ 1 ], item.formatArgs[ 2 ], item.formatArgs[ 3 ] );
20	return res;
21}
22
23HRESULT TraceReader::open( LPCTSTR path )
24{
25	CHECK( file.Create( path, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING ) );
26	CHECK( mapping.MapFile( file ) );
27
28	const uint8_t* rsi = mapping;
29	const sFileHeader& header = *(const sFileHeader*)rsi;
30	if( header.magic != header.correctMagic )
31		return E_INVALIDARG;
32	countItems = header.countItems;
33	countStrings = header.countStrings;
34
35	rsi += sizeof( sFileHeader );
36	payloadPointer = rsi;
37
38	rsi += header.bytesPayload;
39	stringIndex = (const uint32_t*)( rsi );
40	stringData = (const char*)( rsi + countStrings * 4 );
41
42	rsi += header.bytesStrings;
43	items = (const sTraceItem*)rsi;
44
45	return S_OK;
46}