text stringlengths 14 100k | source stringclasses 1
value | repo stringclasses 810
values | language stringclasses 13
values |
|---|---|---|---|
<|fim_prefix|>#pragma once
namespace Dir<|fim_suffix|>std::vector<E>& vec );
}<|fim_middle|>ectCompute
{
// Download a buffer from VRAM into std::vector
// The function is relatively expensive, creates a temporary staging buffer on each call, and only used to test things.
template<class E>
HRESULT downloadBuffer( ... | fim | Const-me/Whisper | c |
<|fim_suffix|>wFormats[ (uint8_t)dt ];
}<|fim_prefix|>#include "stdafx.h"
#include "enums.h"
static const alignas( 16 ) <|fim_middle|>std::array<DXGI_FORMAT, 3> s_tensorViewFormats = { DXGI_FORMAT_R16_FLOAT, DXGI_FORMAT_R32_FLOAT, DXGI_FORMAT_R32_UINT };
DXGI_FORMAT DirectCompute::viewFormat( eDataType dt )
{
return... | fim | Const-me/Whisper | cpp |
<|fim_suffix|>erUse : uint8_t
{
// Immutable tensor, readable from GPU
Immutable,
// Read+write tensor, readable and writable on GPU
ReadWrite,
// Read+write tensor, readable and writable on GPU, which supports downloads from GPU
ReadWriteDownload,
// The tensor is accessible by both GPU (read only) and ... | fim | Const-me/Whisper | c |
<|fim_prefix|>#include "stdafx.h"
#include "listGPUs.h"
#pragma comment(lib, "DXGI.lib")
#include <charconv>
#include <optional>
namespace DirectCompute
{
static HRESULT createFactory( CComPtr<IDXGIFactory1>& rdi )
{
HRESULT hr = CreateDXGIFactory1( IID_PPV_ARGS( &rdi ) );
if( SUCCEEDED( hr ) )
return S_OK;
... | fim | Const-me/Whisper | cpp |
<|fim_prefix|>#pragma once
#include <API/iContext.cl.<|fim_suffix|>ter1> selectAdapter( const std::wstring& requestedName );
}<|fim_middle|>h>
namespace DirectCompute
{
CComPtr<IDXGIAdap<|endoftext|> | fim | Const-me/Whisper | c |
<|fim_prefix|>#pragma once
#include <stdint.h>
namespace DirectCompute
{
// DXGI_ADAPTER_DESC.VendorId magic numbers; they come from that database: https://pcisig.com/membership/member-companies
enum struct eGpuVendor : uint16_t
{
AMD = 0x1002,
NVidia = 0x10de,
Intel = 0x8086,
VMWare = 0x15ad,
};
enum st... | fim | Const-me/Whisper | c |
<|fim_prefix|>// This source file is generated by a tool
#include "stdafx.h"
#include "shaderNames.h"
static const std::array<const char*, 41> s_shaderNames =
{
"add",
"addInPlace",
"addRepeat",
"addRe<|fim_suffix|>t i = (uint16_t)cs;
if( i < s_shaderNames.size() )
return s_shaderNames[ i ];
return nullptr;
}... | fim | Const-me/Whisper | cpp |
<|fim_prefix|>// This header is generated by a tool
#pragma once
#include <stdint.h>
namespace DirectCompute
{
enum struct eComputeShader: uint16_t
{
add = 0,
addInPlace = 1,
addRepeat = 2,
addRepeatEx = 3,
addRepeatGelu = 4,
addRepeatScale = 5,
addRows = 6,
convolutionMain = 7,
convolutionMain2 = ... | fim | Const-me/Whisper | c |
<|fim_prefix|>#include "stdafx.h"
#include "shaders.h"
#include "device.h"
#include "../Utils/LZ4/lz4.h"
namespace
{
#ifdef _DEBUG
#include "shaderData-Debug.inl"
#else
#include "shaderData-Release.inl"
#endif
// static std::vector<CComPtr<ID3D11ComputeShader>> s_shaders;
}
HRESULT DirectCompute::createComputeShade... | fim | Const-me/Whisper | cpp |
<|fim_suffix|>mputeShader shader );
}<|fim_prefix|>#pragma once
#include "shaderNames.h"
namespace DirectCompute
{
HRESULT createComputeShaders( std::vector<CComPtr<ID3D11C<|fim_middle|>omputeShader>>& shaders );
void bindShader( eCo<|endoftext|> | fim | Const-me/Whisper | c |
<|fim_suffix|>HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved )
{
// Perform actions based on the reason for calling.
switch( fdwReason )
{
case DLL_PROCESS_ATTACH:
// Initialize once for each new process. Return FALSE to fail DLL load.
DisableThreadLibraryCalls( (HMODULE)hinstDLL );
break;
case DLL_... | fim | Const-me/Whisper | cpp |
<|fim_prefix|>#include "stdafx.h"
#include <immintrin.h>
#include <optional>
#include "HybridContext.h"
#include "../Utils/Trace/tracing.h"
#if BUILD_HYBRID_VERSION
#ifndef __AVX__
#error Hybrid version requires AVX build, and ideally AVX2 CPU
#endif // !__AVX__
namespace
{
int threadsCount( int t )
{
#ifdef NDEBUG... | fim | Const-me/Whisper | cpp |
<|fim_suffix|>nst Whisper::WhisperModel& wm );
HRESULT create();
HRESULT downloadKeyValues( const DirectCompute::KeyValueBuffers& source )
{
return kvCross.download( source );
}
struct sDecParams
{
int n_threads;
int M;
};
HRESULT decode( const int* tokens, const int n_tokens, const int n_past, const ... | fim | Const-me/Whisper | c |
<|fim_prefix|>#include "stdafx.h"
#include "KeyValueDownloader.h"
HRESULT KeyValueDownloader::create( const Whisper::sModelParams& mp )
{
const uint32_t n_audio_ctx = mp.n_audio_ctx;
const uint32_t n_mem = mp.n_text_layer * mp.n_audio_ctx;
const uint32_t n_elements = mp.n_text_state * n_mem;
CD3D11_BUFFER_DESC de... | fim | Const-me/Whisper | cpp |
<|fim_suffix|>/ A slice of model.memory_k tensor
CpuCompute::Tensor keysView( uint32_t len, uint32_t off ) const
{
if( len + off <= length )
{
E* rsi = (E*)mappedKeys.data();
rsi += off;
return CpuCompute::Tensor::fromData( rsi, dataType, len );
}
throw E_BOUNDS;
}
// A slice of model.m... | fim | Const-me/Whisper | c |
<|fim_suffix|>lf = _mm_set1_ps( 0.5f );
for( ; rsi < rsiEndAligned; rsi += 8, rdiStereo += 8, rdiMono += 4 )
{
// Load 4 samples = 8 floats
__m128 v0 = _mm_loadu_ps( rsi ); // L0, R0, L1, R1
__m128 v1 = _mm_loadu_ps( rsi + 4 );// L2, R2, L3, R3
// Store into the stereo PCM vector
_mm_storeu_ps( rdiStereo,... | fim | Const-me/Whisper | cpp |
<|fim_prefix|>#pragma once
#include <vector>
namespace Whisper
{
struct AudioBuffer
{
std::vector<float> mono;
std::vector<float> stereo;
void appendMono( const float* rsi, size_t countFloats );
void appendDownmixedStereo( const float* rsi, size_t countFloats );
void appendStereo( const float* rsi, size_t... | fim | Const-me/Whisper | c |
<|fim_prefix|>#include "stdafx.h"
#include <atlstr.h>
#include <mfapi.h>
#include <mfidl.h>
#include <mfreadwrite.h>
#include "AudioCapture.h"
#include "../API/iMediaFoundation.cl.h"
#include "../ComLightLib/comLightServer.h"
#pragma comment(lib, "Mf.lib")
namespace
{
struct Strings
{
CString displayName, endpoint... | fim | Const-me/Whisper | cpp |
<|fim_suffix|>tureOpen( iMediaFoundation* owner, const wchar_t* endpoint, const sCaptureParams& captureParams, iAudioCapture** pp ) noexcept;
}<|fim_prefix|>#pragma once
#include "../API/MfStructs.h"
namespace Whisper<|fim_middle|>
{
struct iAudioCapture;
struct iMediaFoundation;
HRESULT __stdcall captureDeviceLis... | fim | Const-me/Whisper | c |
<|fim_suffix|>NTER;
if( 0 != ( size >> 32 ) )
return DISP_E_OVERFLOW; // SHCreateMemStream is limited to 4GB, it seems
CComPtr<IStream> comStream;
// Microsoft neglected to document their API, but Wine returns a new stream with reference counter = 1
// See shstream_create() function there https://sourc... | fim | Const-me/Whisper | cpp |
<|fim_prefix|>#include "stdafx.h"
#include "PcmReader.h"
#include <mfapi.h>
#include <Mferror.h>
#include "mfUtils.h"
namespace Whisper
{
__interface iSampleHandler
{
void copyChunk( PcmMonoChunk* pMono, const AudioBuffer& rsi, size_t sourceOffset, PcmStereoChunk* pStereo ) const;
void moveBufferData( AudioBuff... | fim | Const-me/Whisper | cpp |
#pragma once
#include "../Whisper/audioConstants.h"
#include <mfidl.h>
#include <mfreadwrite.h>
#include "AudioBuffer.h"
#include "../API/iMediaFoundation.cl.h"
namespace Whisper
{
// PCM buffer with 10 milliseconds of single-channel audio
struct PcmMonoChunk
{
std::array<float, FFT_STEP> mono;
};
// PCM buffer... | fim | Const-me/Whisper | c |
<|fim_prefix|>#include "stdafx.h"
#include "../ComLightLib/comLightServer.h"
#include "loadAudioFile.h"
#include "mfUtils.h"
#include "AudioBuffer.h"
#include <mfidl.h>
#include <mfreadwrite.h>
#include <mfapi.h>
#pragma comment(lib, "Mfreadwrite.lib")
#pragma comment(lib, "mfuuid.lib")
namespace Whisper
{
class Med... | fim | Const-me/Whisper | cpp |
<|fim_suffix|>uffer** pp );
}<|fim_prefix|><|fim_middle|>#pragma once
#include "../API/iMediaFoundation.cl.h"
namespace Whisper
{
HRESULT COMLIGHTCALL loadAudioFile( LPCTSTR path, bool stereo, iAudioB<|endoftext|> | fim | Const-me/Whisper | c |
<|fim_prefix|>#include "stdafx.h"
#include "mfStartup.h"
#include <atlbase.h>
#include <mfapi.h>
#pragma comment(lib, "Mfplat.lib")
namespace
{
struct sCoInitStatus
{
// Possible state:
// -1 is the initial state, coInitialize never called
// S_OK - CoInitializeEx succeeded, in this state the counter tracks th... | fim | Const-me/Whisper | cpp |
<|fim_prefix|>#pragma once
na<|fim_suffix|>rtupRaii() = default;
~MfStartupRaii();
MfStartupRaii( const MfStartupRaii& ) = delete;
HRESULT startup();
};
}<|fim_middle|>mespace Whisper
{
class MfStartupRaii
{
uint8_t successFlags = 0;
public:
MfSta<|endoftext|> | fim | Const-me/Whisper | c |
<|fim_prefix|>#include "stdafx.h"
#include "mfUtils.h"
#include <mfapi.h>
HRESULT Whisper::createMediaType( bool stereo, IMFMediaType** pp )
{
if( nullptr == pp )
return E_POINTER;
CComPtr<IMFMediaType> mt;
CHECK( MFCreateMediaType( &mt ) );
CHECK( mt->SetGUID( MF_MT_MAJOR_TYPE, MFMediaType_Audio ) );
CHECK( m... | fim | Const-me/Whisper | cpp |
<|fim_prefix|>#pragma once
#include <stdint.h>
#include <mfidl.h>
#include <mfobjects.h>
#include <mfreadwrite.h>
#include "../Whisper/audioConstants.h"
namespace Whisper
{
HRESULT createMediaType( bool stereo, IMFMediaType** pp );
HRESULT getStreamDuration( IMFSourceReader* reader, int64_t& duration );
HRESULT v... | fim | Const-me/Whisper | c |
<|fim_prefix|>#include "stdafx.h"
#include "ConstantBuffer.h"
#include "../D3D/MappedResource.h"
using namespace DirectCompute;
HRESULT ConstantBuffer::create()
{
if( nullptr == buffer )
{
CD3D11_BUFFER_DESC desc{ 16 * 3 * 2, D3D11_BIND_CONSTANT_BUFFER, D3D11_USAGE_DYNAMIC, D3D11_CPU_ACCESS_WRITE };
return devic... | fim | Const-me/Whisper | cpp |
<|fim_suffix|>pe& t1 );
HRESULT update( const TensorShape& t0, const TensorShape& t1, const TensorShape& t2 );
void bind() const;
__m128i getMemoryUse() const
{
return bufferMemoryUsage( buffer );
}
};
}<|fim_prefix|>#pragma once
#include "../D3D/device.h"
#include "TensorShape.h"
namespace DirectCompu... | fim | Const-me/Whisper | c |
<|fim_suffix|>nb[ 3 ];
return res;
}
Tensor MlContext::flashAttention( const Tensor& q, const Tensor& k, const Tensor& v, bool masked )
{
if( !canMulMat( k, q ) )
throw E_INVALIDARG;
if constexpr( enableInexactOptimizations )
{
if( !masked )
{
profiler.setNextTag( "flashAttn.1" );
Tensor tmp = mulMat(... | fim | Const-me/Whisper | cpp |
<|fim_prefix|>#include "stdafx.h"
#include "DbgNanTest.h"
#include "../D3D/Ma<|fim_suffix|>ta();
return val != 0;
}<|fim_middle|>ppedResource.h"
using namespace DirectCompute;
HRESULT DbgNanTest::create()
{
ID3D11Device* const dev = DirectCompute::device();
CD3D11_BUFFER_DESC desc{ 4, D3D11_BIND_UNORDERED_ACCESS }... | fim | Const-me/Whisper | cpp |
<|fim_suffix|>dAccessView* ( ) const
{
return uav;
}
bool test() const;
};
#if DBG_TEST_NAN
const DbgNanTest& getNanTestBuffers();
#endif
}<|fim_prefix|>#pragma once
namespace DirectCom<|fim_middle|>pute
{
class DbgNanTest
{
CComPtr<ID3D11Buffer> bufferDefault, bufferStaging;
CComPtr<ID3D11UnorderedA... | fim | Const-me/Whisper | c |
<|fim_suffix|>= ts_device;
if( nullptr != dev && nullptr != dev->smallCb )
{
ID3D11Buffer* cb = dev->smallCb;
MappedResource mapped;
check( mapped.map( cb, false ) );
store16( mapped.data(), cbData );
return cb;
}
throw OLE_E_BLANK;
}
#if DBG_TEST_NAN
const DbgNanTest& DirectCompute::getNanTestBuffers()... | fim | Const-me/Whisper | cpp |
<|fim_prefix|>#pragma once
#include <string>
#include "../D3D/sGpuInfo.h"
#include "LookupTables.h"
#include "DbgNanTest.h"
namespace DirectCompute
{
struct Device
{
CComPtr<ID3D11Device> device;
CComPtr<ID3D11DeviceContext> context;
std::vector<CComPtr<ID3D11ComputeShader>> shaders;
CComPtr<ID3D11Buffer> s... | fim | Const-me/Whisper | c |
<|fim_prefix|>#include "<|fim_suffix|>MemoryUsage() const
{
__m128i v = resourceMemoryUsage( m_gelu );
v = _mm_add_epi64( v, resourceMemoryUsage( m_exponent ) );
return v;
}<|fim_middle|>stdafx.h"
#include "LookupTables.h"
#include "LookupTablesData.h"
#include <memory>
#include "mlUtils.h"
using namespace DirectCom... | fim | Const-me/Whisper | cpp |
<|fim_suffix|>ryUsage() const;
};
const LookupTables& lookupTables();
}<|fim_prefix|>#pragma once
#include "../D3D/device.h"
namespace DirectCompute
{
class LookupTables
{
CComPtr<ID3D11ShaderResourceView> m_gelu, m_exponent;
public:
HRESULT create();
<|fim_middle|>HRESULT createClone( const LookupTables... | fim | Const-me/Whisper | c |
<|fim_prefix|>#include "stdafx.h"
#include "LookupTablesData.h"
#include <immintrin.h>
#include <atlfile.h>
#include <Utils/LZ4/lz4.h>
using namespace DirectCompute;
namespace
{
inline float fp32( uint16_t f16 )
{
__m128i i = _mm_cvtsi32_si128( f16 );
__m128 f = _mm_cvtph_ps( i );
return _mm_cvtss_f32( f );
}... | fim | Const-me/Whisper | cpp |
#pragma once
#include <stdint.h>
#include <array>
namespace DirectCompute
{
struct LookupTablesData
{
std::array<uint16_t, 0x10000> gelu;
std::array<uint16_t, 0x10000> exponent;
LookupTablesData();
};
}<|endoftext|> | fim | Const-me/Whisper | c |
<|fim_suffix|>nst uint32_t rowLength = tokenEmbedding.ne[ 0 ];
const uint32_t rows = embd.ne[ 0 ];
Tensor result = createTensor( eDataType::FP32, { rowLength, rows } );
TensorShape constants;
// rowLength
constants.ne[ 0 ] = rowLength;
// pastTokensCount
constants.ne[ 1 ] = pastTokensCount;
// outputRowStride
... | fim | Const-me/Whisper | cpp |
#include "stdafx.h"
#include "MlContext.h"
#include "../source/ggml.h"
#include "testUtils.h"
using namespace DirectCompute;
#define E_TYPE HRESULT_FROM_WIN32( ERROR_DATATYPE_MISMATCH )
static void dbgPrintSizeDiff( const char* what, __m128i ref, __m128i gpu )
{
std::array<int, 8> a;
_mm_storeu_si128( ( __m128i* ) ... | fim | Const-me/Whisper | cpp |
<|fim_prefix|>#pragma once
#include <vector>
#include "TempBuffers.h"
#include "ConstantBuffer.h"
#include "Tensor.h"
#include "../Utils/GpuProfiler.h"
#include "../Utils/ProfileCollection.h"
namespace DirectCompute
{
enum struct eComputeShader : uint16_t;
class MlContext
{
// When false, the implementation is 1... | fim | Const-me/Whisper | c |
#include "stdafx.h"
#include "Reshaper.h"
#include "../D3D/MappedResource.h"
#include "../D3D/Binder.h"
#include "../D3D/shaders.h"
#include "reshapedMultiply.h"
namespace
{
using namespace DirectCompute;
struct Constants
{
// Size and strides of the source tensor
TensorShape arg0;
uint32_t zzPadding;
// Co... | fim | Const-me/Whisper | cpp |
<|fim_prefix|>#pragma once
#include "Tensor.h"
namespace DirectCompute
{
// This class res<|fim_suffix|>& tensor, eDataType dataType );
};
}<|fim_middle|>hapes some of the model’s tensor, immediately after they’re loaded.
// That feature is used on all AMD GPUs.
class Reshaper
{
CComPtr<ID3D11Buffer> constantB... | fim | Const-me/Whisper | c |
<|fim_suffix|>size( DXGI_FORMAT_R16_FLOAT, countElements, 2, zeroMemory );
if( FAILED( hr ) )
throw hr;
return m_fp16_2;
}
const TensorGpuViews& TempBuffers::fp32( size_t countElements, bool zeroMemory )
{
HRESULT hr = m_fp32.resize( DXGI_FORMAT_R32_FLOAT, countElements, 4, zeroMemory );
if( FAILED( hr ) )
thr... | fim | Const-me/Whisper | cpp |
<|fim_prefix|>#pragma once
#include "TensorGpuViews.h"
namespace DirectCompute
{
class TempBuffers
{
class Buffer : public TensorGpuViews
{
size_t capacity = 0;
public:
<|fim_suffix|> HRESULT resize( DXGI_FORMAT format, size_t elements, size_t cbElement, bool zeroMemory );
size_t getCapacity() const... | fim | Const-me/Whisper | c |
<|fim_prefix|>#include "stdafx.h"
#include "Tensor.h"
#include "../D3D/MappedResource.h"
#include "../D3D/createBuffer.h"
#i<|fim_suffix|>) );
#ifdef _DEBUG
dbgType = that.dbgType;
#endif
}
Tensor& Tensor::operator=( const Tensor& that )
{
ne = that.ne;
nb = that.nb;
srv = that.srv;
uav = that.uav;
#ifdef _DEBUG
... | fim | Const-me/Whisper | cpp |
<|fim_prefix|>#pragma once
#include "TensorShape.h"
#include "TensorGpuViews.h"
#include "../D3D/enums.h"
namespace DirectCompute
{
// A minimal tensor object sufficient to compute things on GPU, with compute shaders
// This class only takes 48 bytes in system memory, and is very cheap to make copies 'coz GPU object... | fim | Const-me/Whisper | c |
<|fim_prefix|>#include "stdafx.h"
#include "TensorEx.h"
#include "../D3D/createBuffer.h"
#include "../source/ggml.h"
#include "../D3D/MappedResource.h"
using namespace DirectCompute;
HRESULT TensorEx::create( const ggml_tensor& ggml, eBufferUse usage, bool uploadData )
{
TensorGpuViews::clear();
buffer = nullptr;
s... | fim | Const-me/Whisper | cpp |
<|fim_prefix|>#pragma once
#include "Tensor.h"
namespace DirectCompute
{
// A tensor which supports dynamic updates from CPU, or downloads from VRAM to system RAM
class TensorEx : public Tensor
{
protected:
CComPtr<ID3D11Buffer> buffer;
CComPtr<ID3D11Buffer> stagingBuffer;
HRESULT getViewSize( uint32_t& cbE... | fim | Const-me/Whisper | c |
<|fim_suffix|>ptr;
if( countElements > UINT_MAX )
return DISP_E_OVERFLOW;
CD3D11_SHADER_RESOURCE_VIEW_DESC viewDesc{ D3D11_SRV_DIMENSION_BUFFER, format, 0, (UINT)countElements };
CHECK( device()->CreateShaderResourceView( gpuBuffer, &viewDesc, &srv ) );
if( makeUav )
{
CD3D11_UNORDERED_ACCESS_VIEW_DESC uavD... | fim | Const-me/Whisper | cpp |
<|fim_prefix|>#pragma once
#include <stdint.h>
#include "../D3D/device.h"
namespace DirectCompute
{
class TensorGpuViews
{
protected:
CComPtr<ID3D11ShaderResourceView> srv;
CComPtr<ID3D11UnorderedAccessView> uav;
public:
operator ID3D11ShaderResourceView* ( ) const { return srv; }
operator ID3D11Unordere... | fim | Const-me/Whisper | c |
<|fim_suffix|>] == t1.ne[ 2 ] ) &&
( t0.ne[ 3 ] == t1.ne[ 3 ] ); */
__m128i a = t0.sizeVec();
__m128i b = t1.sizeVec();
__m128i xx = _mm_xor_si128( a, b );
xx = _mm_shuffle_epi32( xx, _MM_SHUFFLE( 3, 2, 0, 0 ) );
return (bool)_mm_testz_si128( xx, xx );
}<|fim_prefix|>#include "stdafx.h"
#include "TensorShape.h"
... | fim | Const-me/Whisper | cpp |
<|fim_suffix|>ents, up to 4 coordinates
// The unused coordinates are set to 1
std::array<uint32_t, 4> ne;
// Strides of the tensor
// For a dense row-major tensor, these numbers are [ 1, ne[0], ne[0]*ne[1], ne[0]*ne[1]*ne[2] ]
// Note that unlike GGML code, these numbers are expressed in elements not bytes,... | fim | Const-me/Whisper | c |
#include "stdafx.h"
#include "TensorsArena.h"
#include "../D3D/createBuffer.h"
#include "mlUtils.h"
static inline uint32_t roundUpPower2( uint32_t x )
{
// std::bit_ceil from C++/20 standard library implements runtime dispatch, uses LZCNT when AVX2 is available, otherwise BSR
// That's not what we want.
// BSR is o... | fim | Const-me/Whisper | cpp |
<|fim_prefix|>#pragma once
#include "Tensor.h"
namespace DirectCompute
{
using pfnNewCapacity = uint32_t( * )( uint32_t current, uint32_t requested );
uint32_t defaultNewCapacity( uint32_t current, uint32_t requested );
class PooledTensor
{
TensorGpuViews views;
uint32_t capacity = 0;
public:
Tensor tenso... | fim | Const-me/Whisper | c |
<|fim_prefix|>#include "stdafx.h"
#include "LookupTables.h"
#include "../D3D/MappedResource.h"
#include "mlUtils.h"
#include "../D3D/shaders.h"
#include "../D3D/Binder.h"
#include "DbgNanTest.h"
namespace DirectCompute
{
void zeroMemory( ID3D11UnorderedAccessView* uav, uint32_t length, bool fillWithNaN )
{
__m128i... | fim | Const-me/Whisper | cpp |
<|fim_prefix|>#pragma once
namespace DirectCompute
{
// Update the sma<|fim_suffix|>sourceView** rdi );
}<|fim_middle|>ll dynamic constant buffer
ID3D11Buffer* __vectorcall updateSmallCb( __m128i cbData );
// Fill the tensor with either 0.0 or NaN values
void zeroMemory( ID3D11UnorderedAccessView* uav, uint32_t l... | fim | Const-me/Whisper | c |
<|fim_suffix|>32_t TILE_SIZE = 32;
}
}<|fim_prefix|>#pragma once
#in<|fim_middle|>clude <stdint.h>
namespace DirectCompute
{
namespace ReshapedMultiply
{
constexpr uint<|endoftext|> | fim | Const-me/Whisper | c |
<|fim_prefix|>#include "stdafx.h"
#include "tensorOpsTests.h"
#include "MlContext.h"
#include "TensorEx.h"
#include "../D3D/shaders.h"
#include "../D3D/Binder.h"
#include "testUtils.h"
#include "../Whisper/WhisperContext.h"
void DirectCompute::testMulMat( const ggml_tensor* src0, const ggml_tensor* src1, const ggml_te... | fim | Const-me/Whisper | cpp |
<|fim_suffix|>or* src1, const ggml_tensor* dst );
void computeConvolution( const ggml_tensor* src0, const ggml_tensor* src1, ggml_tensor* dst );
}<|fim_prefix|>#pragma once
#include "../source/ggml.h"
namespace DirectCompute
{
// void testM<|fim_middle|>ulMatReshape( const ggml_tensor* src1, const void* tempBuffer )... | fim | Const-me/Whisper | c |
<|fim_prefix|>#include "stdafx.h"
#include "testUtils.h"
#include <immintrin.h>
#include <atlfile.h>
#include <atlpath.h>
namespace
{
using DirectCompute::sTensorDiff;
__forceinline __m256 load( const float* rsi )
{
return _mm256_loadu_ps( rsi );
}
__forceinline __m256 load( const uint16_t* rsi )
{
const _... | fim | Const-me/Whisper | cpp |
<|fim_prefix|>#pragma once
#include "../D3D/downloadBuffer.h"
#include "../D3D/RenderDoc/renderDoc.h"
#include <unordered_set>
#include <functional>
// Funfact: this code written by ChatGPT
namespace std
{
template<>
struct hash<array<uint32_t, 8>>
{
size_t operator()( const array<uint32_t, 8>& arr ) const
{
... | fim | Const-me/Whisper | c |
<|fim_suffix|>splus
}
#endif<|fim_prefix|>#pragma once
#ifdef __cplusplus
extern "C"
{
#endif
void print<|fim_middle|>UniqueTensorSize( const char* name, const int* lhs, const int* rhs );
#ifdef __cplu<|endoftext|> | fim | Const-me/Whisper | c |
<|fim_suffix|>freq = frequency;
if( freq == 0 )
freq = computeTscFrequency();
return makeTime( tsc, freq );
}
};
uint64_t __declspec( noinline ) CpuTimescale::computeTscFrequency()
{
int64_t tsc = tscNow();
int64_t qpc = qpcNow();
tsc -= tscStart;
qpc -= qpcStart;
uint64_t qpcFreq;
QueryPe... | fim | Const-me/Whisper | cpp |
<|fim_suffix|> // More specifically, each CPU core has a timestamp counter which runs at CPU's base frequency, regardless on the frequency scaling of that core.
inline int64_t tscNow()
{
return __rdtsc();
}
// Scale the time interval from CPU time stamp counter clock into 100-nanosecond ticks, rounding to neares... | fim | Const-me/Whisper | c |
<|fim_prefix|>#include "stdafx.h"
#include "DelayExecution.h"
namespace
{
constexpr bool useHighRezTimer = false;
constexpr int64_t sleepMicroseconds = 200;
inline HRESULT sleepImpl( HANDLE timer )
{
constexpr int64_t sleepTicks = sleepMicroseconds * 10;
LARGE_INTEGER li;
// Negative values indicate relat... | fim | Const-me/Whisper | cpp |
<|fim_prefix|>#pragma once
#include <atlbase.h>
// Utility class i<|fim_suffix|>() function
class DelayExecution
{
using pfnDelay = void( * )( const DelayExecution& de );
pfnDelay pfn = nullptr;
CHandle timer;
static void sleepOnTheTimer( const DelayExecution& delay );
static void spinWait( const DelayExecution&... | fim | Const-me/Whisper | c |
<|fim_prefix|>#include "stdafx.h"
#include "GpuProfiler.h"
#include "GpuProfilerSimple.h"
using namespace DirectCompute;
inline void GpuProfiler::sProfilerData::reset()
{
_mm_storeu_si128( ( __m128i* ) & callsPending, _mm_setzero_si128() );
}
inline void GpuProfiler::sProfilerData::addPending( int64_t time )
{
call... | fim | Const-me/Whisper | cpp |
<|fim_prefix|>#pragma once
#inc<|fim_suffix|> delay;
CComPtr<ID3D11Query> disjoint, begin, end;
public:
HRESULT create();
HRESULT time( uint64_t& rdi ) const;
};
}<|fim_middle|>lude "../D3D/device.h"
#include "DelayExecution.h"
namespace DirectCompute
{
// A simple profiler which doesn't collect anything, use... | fim | Const-me/Whisper | c |
<|fim_prefix|>/*
* LZ4 - Fast LZ compression algorithm
* Header File
* Copyright (C) 2011-2020, Yann Collet.
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the followi... | fim | Const-me/Whisper | c |
<|fim_prefix|>#include "stdafx.h"
#include "Logger.h"
#include "../API/iContext.cl.h"
#include <cstdarg>
#include <atlstr.h>
namespace
{
wchar_t* formatMessage( HRESULT hr )
{
wchar_t* err;
if( FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
hr,
MAKELANGID( LANG_NEUTRAL... | fim | Const-me/Whisper | cpp |
<|fim_suffix|>ssage( Whisper::eLogLevel lvl );
#ifdef __cplusplus
}
#endif
<|fim_prefix|>#pragma once
#include "../API/loggerApi.h"
#ifdef __cplusplus
extern "C" {
#endif
void logError( const char8_t* pszFormat, ... <|fim_middle|>);
void logError16( const wchar_t* pszFormat, ... );
void logErrorHr( long hr, const ... | fim | Const-me/Whisper | c |
<|fim_prefix|>// https://github.com/aappleby/smhasher/blob/master/src/MurmurHash3.cpp
#include <stdafx.h>
//-----------------------------------------------------------------------------
// MurmurHash3 was written by Austin Appleby, and is placed in the public
// domain. The author hereby disclaims copyright to this sou... | fim | Const-me/Whisper | cpp |
<|fim_suffix|>uct StringPtrTraits : public ATL::CDefaultElementTraits<const char*>
{
using INARGTYPE = const char*;
static inline bool CompareElements( const char* a, const char* b )
{
return 0 == strcmp( a, b );
}
static inline int CompareElementsOrdered( const char* a, const char* b )
{
return strcmp( a, ... | fim | Const-me/Whisper | c |
<|fim_suffix|>n 0;
#endif
}<|fim_prefix|>#include "stdafx.h"
#include "ProfileCollection.h"
#include "GpuProfiler.h"
#include "../Whisper/WhisperModel.h"
#include "../D3D/shaderNames.h"
using namespace Whisper;
ProfileCollection::Measure& ProfileCollection::measure( DirectCompute::eProfilerBlock which )
{
uint32_t ke... | fim | Const-me/Whisper | cpp |
<|fim_suffix|>pping the comparison to sort in descending order
return ticks > that.ticks;
}
void print() const;
};
std::vector<TaggedTemp> taggedTimes;
#endif
std::vector<uint32_t> keysTemp;
};
}<|fim_prefix|>#pragma once
#include <atlcoll.h>
#include "CpuProfiler.h"
namespace DirectCompute
{
enum s... | fim | Const-me/Whisper | c |
<|fim_prefix|>#pragma once
#include "../ComLightLib/streams.h"
#include "../ComLightLib/comLightServer.h"
#define WIN32_LEAN_AND_MEAN
#include <atlfile.h>
class ReadStream : public ComLight::ObjectRoot<ComLight::iReadStream>
{
CAtlFile file;
// TODO: implement a buffer in this class, at leas<|fim_suffix|>oid* lpBuff... | fim | Const-me/Whisper | c |
#include "stdafx.h"
#include "TraceStructures.h"
using namespace Tracing;
uint64_t sTraceItem::buffer( uint64_t off, size_t length, eDataType type )
{
payloadOffset = off;
payloadSize = length * DirectCompute::elementSize( type );
*(uint64_t*)( &size[ 0 ] ) = length;
*(uint64_t*)( &size[ 2 ] ) = 0;
_mm_storeu_si1... | fim | Const-me/Whisper | cpp |
<|fim_prefix|>#pragma once
#include <array>
#include <emmintrin.h>
#include "../../D3D/enums.h"
namespace Tracing
{
using DirectCompute::eDataType;
// File header of the trace file
struct sFileHeader
{
static constexpr uint32_t correctMagic = 0xE6B4A12Du; // random.org
uint32_t magic;
uint8_t formatVersio... | fim | Const-me/Whisper | c |
<|fim_prefix|>#include "stdafx.h"
#include "TraceWriter.h"
#include <atlfile.h>
#include <atlcoll.h>
#include <atlstr.h>
#include "TraceStructures.h"
#include "../../ML/Tensor.h"
#include "../../CPU/Tensor.h"
#include <Shlobj.h>
using namespace Tracing;
namespace
{
static HRESULT createDir( LPCTSTR pathFile )
{
LP... | fim | Const-me/Whisper | cpp |
<|fim_suffix|> );
};
}<|fim_prefix|>#pragma once
#include <memory>
#include "../../D3D/enums.h"
namespace DirectCompute
{
class Tensor;
}
namespace CpuCompute
{
class Tensor;
}
struct ggml_tensor;
namespace Tracing
{
using DirectCompute::eDataType;
struct ItemName
{
const char* pointer;
std::array<uint32_... | fim | Const-me/Whisper | c |
<|fim_suffix|>, tensor.countElements() );
if( !found )
return S_FALSE;
__debugbreak();
return S_FALSE;
}
#endif
}<|fim_prefix|>#include "stdafx.h"
#include "tracing.h"
#include "../../source/ggml.h"
#include "../../ML/Tensor.h"
namespace Tracing
{
#if SAVE_DEBUG_TRACE
std::unique_ptr<iTraceWriter> s_writer;... | fim | Const-me/Whisper | cpp |
<|fim_suffix|> HRESULT vector( const ItemName& name, const std::vector<float>& vec )
{
const float* rsi = vec.empty() ? nullptr : vec.data();
return buffer( name, rsi, vec.size(), eDataType::FP32 );
}
inline HRESULT vector( const ItemName& name, const float* rsi, size_t length )
{
return buffer( name, rsi, le... | fim | Const-me/Whisper | c |
<|fim_prefix|>#include "stdafx.h"
#include "miscUtils.h"
#include <cmath>
void setCurrentThreadName( const char* threadName )
{
const DWORD dwThreadID = GetCurrentThreadId();
// https://stackoverflow.com/a/10364541/126995
#pragma pack(push,8)
typedef struct tagTHREADNAME_INFO
{
DWORD dwType; // Must be 0x1... | fim | Const-me/Whisper | cpp |
#pragma once
#define CHECK( hr ) { const HRESULT __hr = ( hr ); if( FAILED( __hr ) ) return __hr; }
#define CHECK_LOG( hr ) { const HRESULT __hr = ( hr ); if( FAILED( __hr ) ) { logErrorHr(__hr, u8"%s failed", #hr ); return __hr; } }
inline void check( HRESULT hr )
{
if( SUCCEEDED( hr ) )
return;
throw hr;
}
inl... | fim | Const-me/Whisper | c |
<|fim_suffix|>nullptr == work )
{
work = CreateThreadpoolWork( &callbackStatic, this, nullptr );
if( nullptr != work )
return S_OK;
return getLastHr();
}
return HRESULT_FROM_WIN32( ERROR_ALREADY_INITIALIZED );
}
HRESULT ThreadPoolWork::parallelFor( int threadsCount ) noexcept
{
if( nullptr != work )
{
... | fim | Const-me/Whisper | cpp |
<|fim_prefix|>#pragma once
namespace Whisper
{
// A callback to offload to the thread pool
using pfnParallelForCallback = HRESULT( * )( int ith, void* ctx ) noexcept;
// A simple parallel for implementation; Windows includes a decent thread pool since Vista (2006)
HRESULT parallelFor( pfnParallelForCallback pfn, ... | fim | Const-me/Whisper | c |
<|fim_suffix|> While voice is continuously detected, we allow to grow the buffer up to `maxDuration` time
}
else
{
// A voice is detected in the buffer, but it was a while ago
clearStateFlag( eCaptureStatus::Voice );
if( newSamples < captureParams.minDuration )
return S_OK; // When detected pause in ... | fim | Const-me/Whisper | cpp |
<|fim_prefix|>#include "stdafx.h"
#include "ContextImpl.h"
#include "Languages.h"
#include "../Utils/Trace/tracing.h"
using namespace Whisper;
ContextImpl::ContextImpl( const DirectCompute::Device& dev, const WhisperModel& modelData, iModel* modelPointer ) :
device( dev ),
model( modelData ),
modelPtr( modelPointer... | fim | Const-me/Whisper | cpp |
<|fim_suffix|> would mean the following is true: ( ( left > right * 1.1 ) && ( right > left * 1.1 ) )
return (eSpeakerChannel)mask;
}
}
HRESULT COMLIGHTCALL ContextImpl::detectSpeaker( const sTimeInterval& time, eSpeakerChannel& result ) const noexcept
{
// Ensure we have the spectrogram
if( nullptr == currentSp... | fim | Const-me/Whisper | cpp |
<|fim_suffix|>iAudioCapture* reader ) override final;
struct Segment
{
int64_t t0;
int64_t t1;
mutable std::string text;
std::vector<sTokenData> tokens;
size_t memoryUsage() const;
};
std::vector<Segment> result_all;
std::vector<whisper_token> prompt_past;
// [EXPERIMENTAL] token-level tim... | fim | Const-me/Whisper | c |
<|fim_prefix|>#include "stdafx.h"
#include "ContextImpl.h"
#include <mfapi.h>
#include "MelStreamer.h"
#include "../API/iMediaFoundation.cl.h"
#include "../Utils/Trace/tracing.h"
using namespace Whisper;
static int getCpuCoresCount()
{
DWORD bufferSize = 0;
GetLogicalProcessorInformation( NULL, &bufferSize );
// ... | fim | Const-me/Whisper | cpp |
<|fim_suffix|>;
}
}
Tensor DecoderInputBuffers::embedding( const int* rsi ) const
{
if( nullptr == embd || m_size == 0 )
throw OLE_E_BLANK;
// Upload the data
{
MappedResource mapped;
check( mapped.map( embd, false ) );
int* const rdi = (int*)mapped.data();
memcpy( rdi, rsi, m_size * (size_t)4 );
}
r... | fim | Const-me/Whisper | cpp |
<|fim_prefix|>#pragma once
#include "../ML/Tensor.h"
namespace DirectCompute
{
// A dynamic buffer
class DecoderInputBuffers
{
CComPtr<ID3D11Buffer> embd;
uint32_t m_size = 0;
uint32_t m_c<|fim_suffix|>_epi64x( (int64_t)i, 0 );
}
HRESULT zeroMemory() const;
};
}<|fim_middle|>apacity = 0;
public:
vo... | fim | Const-me/Whisper | c |
<|fim_suffix|>coderResultBuffer::copyToVector( std::vector<float>& vec ) const
{
vec.resize( m_size );
if( vec.empty() )
throw OLE_E_BLANK;
MappedResource mapped;
check( mapped.map( buffer, true ) );
memcpy( vec.data(), mapped.data(), (size_t)4 * m_size );
}
void DecoderResultBuffer::clear()
{
buffer = nullpt... | fim | Const-me/Whisper | cpp |
<|fim_suffix|>sage( buffer );
}
};
}<|fim_prefix|>#pragma once
#include "../ML/Tensor.h"
namespace DirectCompute
{
class DecoderResultBuffer
{
CComPtr<ID3D11Buffer> buffer;
uint32_t m_size = 0;
uint32_t m_capacity = 0;
public:
void copyFromVram( const Tensor& rsi );
void copyToVector( std::vector<fl... | fim | Const-me/Whisper | c |
<|fim_suffix|>ew( buffer, &srvDesc, &srv ) );
CD3D11_UNORDERED_ACCESS_VIEW_DESC uavDesc{ D3D11_UAV_DIMENSION_BUFFER, DXGI_FORMAT_R16_FLOAT, offset, length };
check( device()->CreateUnorderedAccessView( buffer, &uavDesc, &uav ) );
TensorShape shape;
shape.ne = { length, 1, 1, 1 };
shape.setDenseStrides();
return... | fim | Const-me/Whisper | cpp |
<|fim_prefix|>#pragma once
#include "../ML/Tensor.h"
namespace DirectCompute
{
// FP16 buffer for self-attention and cross-attention layers
class AttentionBuffer
{
CComPtr<ID3D11Buffer> buffer;
uint32_t m_size = 0;
public:
// Create buffer for the specified count of elements
void resize( uint32_t size );
... | fim | Const-me/Whisper | c |
<|fim_prefix|>#include "stdafx.h"
#include "Languages.h"
#include <atlcoll.h>
#include "../API/iContext.cl.h"
namespace
{
// These structures are compiled into the DLL, in read only data section
using Lang = Whisper::sLanguageEntry;
static const Lang s_languageData[] =
{
#include "languageCodez.inl"
};
using W... | fim | Const-me/Whisper | cpp |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.