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#include "stdafx.h" 2#include "TensorShape.h" 3#include "../source/ggml.h" 4using namespace DirectCompute ; 5 6TensorShape ::TensorShape () 7{ 8setZero (); 9} 10 11TensorShape ::TensorShape (const TensorShape & that ) 12{ 13_mm_storeu_si128 ( (__m128i * )ne .data (),that .sizeVec () ); 14_mm_storeu_si128 ( (__m128i * )nb .data (),that .stridesVec () ); 15} 16 17void TensorShape ::operator= (const TensorShape & that ) 18{ 19_mm_storeu_si128 ( (__m128i * )ne .data (),that .sizeVec () ); 20_mm_storeu_si128 ( (__m128i * )nb .data (),that .stridesVec () ); 21} 22 23HRESULT TensorShape ::create (const ggml_tensor & ggml ) 24{ 25for (size_t i = 0 ;i < 4 ;i ++ ) 26ne [i ]= (uint32_t )ggml .ne [i ]; 27 28const ggml_type dataType = ggml .type ; 29// Verify a few things 30uint32_t cbElement = (uint32_t )ggml_type_size (dataType ); 31for (size_t i = 0 ;i < 4 ;i ++ ) 32 { 33size_t stride = ggml .nb [i ]; 34if (0 != stride %cbElement ) 35return E_INVALIDARG ; 36size_t nn = stride /cbElement ; 37if (nn > UINT_MAX ) 38return DISP_E_OVERFLOW ; 39nb [i ]= (uint32_t )nn ; 40 } 41return S_OK ; 42} 43 44TensorShape ::TensorShape (const ggml_tensor & ggml ) 45{ 46HRESULT hr = create (ggml ); 47if (FAILED (hr ) ) 48throw hr ; 49} 50 51void TensorShape ::setDenseStrides () 52{ 53nb [0 ]= 1 ; 54nb [1 ]= ne [0 ]; 55const uint32_t p01 = ne [0 ]* ne [1 ]; 56nb [2 ]= p01 ; 57nb [3 ]= p01 * ne [2 ]; 58} 59 60bool DirectCompute ::canMulMat (const TensorShape & t0 ,const TensorShape & t1 ) 61{ 62/* 63return 64( t0.ne[ 0 ] == t1.ne[ 0 ] ) && 65( t0.ne[ 2 ] == t1.ne[ 2 ] ) && 66( t0.ne[ 3 ] == t1.ne[ 3 ] ); */ 67__m128i a = t0 .sizeVec (); 68__m128i b = t1 .sizeVec (); 69__m128i xx = _mm_xor_si128 (a ,b ); 70xx = _mm_shuffle_epi32 (xx ,_MM_SHUFFLE (3 ,2 ,0 ,0 ) ); 71return (bool )_mm_testz_si128 (xx ,xx ); 72}