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 "Tensor.h" 3#include "ParallelForRunner.h" 4 5namespace CpuCompute 6{ 7class MlContext 8 { 9ParallelForRunner pfor ; 10iMemoryAllocator * allocator = nullptr ; 11 12public : 13MlContext (int threads ); 14MlContext (const MlContext & )= delete ; 15 ~MlContext ()= default ; 16 17HRESULT setThreadsCount (int threads ) 18 { 19return pfor .setThreadsCount (threads ); 20 } 21 22iMemoryAllocator * setAllocator (iMemoryAllocator * alloc ) 23 { 24iMemoryAllocator * const ret = allocator ; 25allocator = alloc ; 26return ret ; 27 } 28 29Tensor createTensor (eDataType type ,const std ::array < uint32_t ,4 >& size ); 30Tensor createTensor (eDataType type ,std ::initializer_list < uint32_t > size ); 31 32Tensor addRows (const Tensor & d_te ,const Tensor & d_pe ,const int * tokens ,const int n_tokens ,const int n_past ); 33 34Tensor norm (const Tensor & arg ); 35 36// cur = add( mul( repeat( w, cur ), cur ), repeat( b, cur ) ); 37void fmaRepeat (Tensor & cur ,const Tensor & w ,const Tensor & b ); 38 39inline void fmaRepeat (Tensor & cur ,const TensorPair wb ) 40 { 41fmaRepeat (cur ,wb .w ,wb .b ); 42 } 43 44// Multiply two matrices 45Tensor mulMat (const Tensor & a ,const Tensor & b ); 46 47// cur = add( repeat( b, cur ), cur ); cur = scale(cur, scaling) 48void addRepeatScale (Tensor & cur ,const Tensor & b ,float scaling ); 49 50void addRepeat (Tensor & cur ,const Tensor & b ); 51 52Tensor add (const Tensor & a ,const Tensor & b ); 53void addInPlace (Tensor & a ,const Tensor & b ); 54void addRepeatGelu (Tensor & cur ,const Tensor & b ); 55 56// cur = scale(cur, scaling) 57void scale (Tensor & cur ,float scaling ); 58 59void diagMaskInf (Tensor & cur ,uint32_t n_past ); 60 61void softMax (Tensor & cur ,float inputScale = 1.0f ); 62 63Tensor copy (const Tensor & a ,eDataType type ,std ::initializer_list < uint32_t > size ); 64 65HRESULT copyImpl (Tensor & result ,const Tensor & source ); 66 67Tensor permute (const Tensor & a ,uint8_t axis0 ,uint8_t axis1 ,uint8_t axis2 ,uint8_t axis3 ); 68 69void copyInPlace (Tensor & dest ,const Tensor & a ,eDataType type ,std ::initializer_list < uint32_t > size ); 70 }; 71}