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.9 KiB59 linesraw
1#include "stdafx.h"
2#include "MlContext.h"
3#include "../source/ggml.h"
4#include "testUtils.h"
5using namespace DirectCompute;
6
7#define E_TYPE HRESULT_FROM_WIN32( ERROR_DATATYPE_MISMATCH )
8
9static void dbgPrintSizeDiff( const char* what, __m128i ref, __m128i gpu )
10{
11	std::array<int, 8> a;
12	_mm_storeu_si128( ( __m128i* ) & a[ 0 ], ref );
13	_mm_storeu_si128( ( __m128i* ) & a[ 4 ], gpu );
14	printf( "%s; reference [ %i, %i, %i, %i ], GPGPU [ %i, %i, %i, %i ]\n",
15		what,
16		a[ 0 ], a[ 1 ], a[ 2 ], a[ 3 ],
17		a[ 4 ], a[ 5 ], a[ 6 ], a[ 7 ] );
18}
19
20void MlContext::dbgPrintDifference( const ggml_tensor* reference, const Tensor& gpu, const char* what, bool trapToDebugger )
21{
22	sTensorDiff diff;
23	const __m128i gpuSize = gpu.sizeVec();
24	const __m128i gpuStrides = gpu.stridesVec();
25	__m128i expectedStrides;
26	if( reference->type == GGML_TYPE_F32 )
27	{
28		if( gpu.getType() != eDataType::FP32 )
29			throw E_TYPE;
30		expectedStrides = _mm_slli_epi32( gpuStrides, 2 );
31
32		std::vector<float> v;
33		gpu.download( v );
34		diff = computeDiff( v.data(), (const float*)reference->data, v.size() );
35	}
36	else if( reference->type == GGML_TYPE_F16 )
37	{
38		if( gpu.getType() != eDataType::FP16 )
39			throw E_TYPE;
40		expectedStrides = _mm_slli_epi32( gpuStrides, 1 );
41
42		std::vector<uint16_t> v;
43		gpu.download( v );
44		diff = computeDiff( v.data(), (const uint16_t*)reference->data, v.size() );
45	}
46	else
47		throw E_NOTIMPL;
48
49	const __m128i ggmlSize = _mm_loadu_si128( ( const __m128i* ) & reference->ne[ 0 ] );
50	const __m128i ggmlStrides = _mm_loadu_si128( ( const __m128i* ) & reference->nb[ 0 ] );
51	if( !vectorEqual( gpuSize, ggmlSize ) )
52		dbgPrintSizeDiff( "dbgPrintDifference - size is different", ggmlSize, gpuSize );
53	// if( !vectorEqual( expectedStrides, ggmlStrides ) ) dbgPrintSizeDiff( "dbgPrintDifference - stride is different", ggmlStrides, expectedStrides );
54
55	diff.print( what );
56
57	if( trapToDebugger )
58		__debugbreak();
59}