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.5 KiB62 linesraw
1#pragma once
2#include "../D3D/downloadBuffer.h"
3#include "../D3D/RenderDoc/renderDoc.h"
4#include <unordered_set>
5#include <functional>
6
7// Funfact: this code written by ChatGPT
8namespace std
9{
10	template<>
11	struct hash<array<uint32_t, 8>>
12	{
13		size_t operator()( const array<uint32_t, 8>& arr ) const
14		{
15			size_t result = 0;
16			for( uint32_t element : arr )
17				result = ( result * 31 ) ^ element;
18			return result;
19		}
20	};
21}
22
23namespace DirectCompute
24{
25	struct sTensorDiff
26	{
27		// maximum( absolute( a - b ) )
28		float maxAbsDiff;
29		// average( ( a - b )^2 )
30		float avgDiffSquared;
31		size_t length;
32
33		void print() const;
34		void print( const char* what ) const;
35	};
36
37	// Compute difference between 2 FP32 vectors
38	sTensorDiff computeDiff( const float* a, const float* b, size_t length );
39
40	// Compute difference between 2 FP16 vectors
41	sTensorDiff computeDiff( const uint16_t* a, const uint16_t* b, size_t length );
42
43	class Tensor;
44	sTensorDiff computeDiff( const Tensor& a, const Tensor& b );
45
46	HRESULT dbgWriteBinaryFile( LPCTSTR fileName, const void* rsi, size_t cb );
47
48	// Print unique sizes of the two tensors
49	class PrintUniqueTensorSizes
50	{
51		std::unordered_set<std::array<uint32_t, 8>> set;
52		const char* const what;
53		void printImpl( const std::array<uint32_t, 8>& a );
54
55	public:
56		PrintUniqueTensorSizes( const char* w ) : what( w ) { }
57
58		void print( const Tensor& lhs, const Tensor& rhs );
59		void print( const Tensor& lhs );
60		void print( const int* lhs, const int* rhs );
61	};
62}