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 KiB43 linesraw
1#pragma warning disable CS0649
2using System.Runtime.InteropServices;
3
4namespace CompressShaders
5{
6	static class DetectFp64
7	{
8		struct DXBCHeader
9		{
10			public uint FourCC; // Four character code "DXBC"
11			public uint Hash0;            // 32-bit hash of the DXBC file
12			public uint Hash1;            // 32-bit hash of the DXBC file
13			public uint Hash2;            // 32-bit hash of the DXBC file
14			public uint Hash3;            // 32-bit hash of the DXBC file
15			public uint unknownOne;
16			public uint TotalSize;        // Total size of the DXBC file in bytes
17			public int NumChunks;        // Number of chunks in the DXBC file
18		};
19
20		public static bool usesFp64( ReadOnlySpan<byte> dxbc )
21		{
22			ReadOnlySpan<DXBCHeader> dxbcHeaderSpan = MemoryMarshal.Cast<byte, DXBCHeader>( dxbc );
23			DXBCHeader dxbcHeader = dxbcHeaderSpan[ 0 ];
24
25			int cbHeader = Marshal.SizeOf<DXBCHeader>();
26			int nChunks = dxbcHeader.NumChunks;
27			ReadOnlySpan<int> chunkOffsets = MemoryMarshal.Cast<byte, int>( dxbc.Slice( cbHeader, nChunks * 4 ) );
28			foreach( int off in chunkOffsets )
29			{
30				uint id = MemoryMarshal.Cast<byte, uint>( dxbc.Slice( off, 4 ) )[ 0 ];
31				const uint SFI0 = 0x30494653;
32				if( id != SFI0 )
33					continue;
34				int size = MemoryMarshal.Cast<byte, int>( dxbc.Slice( off + 4, 4 ) )[ 0 ];
35				if( size < 4 )
36					throw new ApplicationException();
37				uint data = MemoryMarshal.Cast<byte, uint>( dxbc.Slice( off + 8, 4 ) )[ 0 ];
38				return 0 != ( data & 1u );
39			}
40			return false;
41		}
42	}
43}