summaryrefslogtreecommitdiffstats
path: root/Whisper/ML/LookupTables.cpp
diff options
context:
space:
mode:
authorKonstantin <const@const.me>2023-01-16 14:52:43 +0100
committerKonstantin <const@const.me>2023-01-16 14:52:43 +0100
commit8c4603c73675958efc960fbd4bb599a2909d106a (patch)
tree714dc6fc9a1672d5fd7f89676b97e10959662abc /Whisper/ML/LookupTables.cpp
parent990a8d0dbaefc996244097397259e92758b15cce (diff)
Source codes
Diffstat (limited to 'Whisper/ML/LookupTables.cpp')
-rw-r--r--Whisper/ML/LookupTables.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/Whisper/ML/LookupTables.cpp b/Whisper/ML/LookupTables.cpp
new file mode 100644
index 0000000..2fc1cc8
--- /dev/null
+++ b/Whisper/ML/LookupTables.cpp
@@ -0,0 +1,54 @@
+#include "stdafx.h"
+#include "LookupTables.h"
+#include "LookupTablesData.h"
+#include <memory>
+using namespace DirectCompute;
+
+namespace
+{
+ HRESULT uploadLookupTable( const std::array<uint16_t, 0x10000>& rsi, CComPtr<ID3D11ShaderResourceView>& rdi )
+ {
+ rdi = nullptr;
+ CComPtr<ID3D11Buffer> buffer;
+
+ CD3D11_BUFFER_DESC desc{ 0x10000 * 2, D3D11_BIND_SHADER_RESOURCE, D3D11_USAGE_IMMUTABLE };
+ D3D11_SUBRESOURCE_DATA srd{ rsi.data(), 0, 0 };
+ CHECK( device()->CreateBuffer( &desc, &srd, &buffer ) );
+
+ CD3D11_SHADER_RESOURCE_VIEW_DESC viewDesc{ D3D11_SRV_DIMENSION_BUFFER, DXGI_FORMAT_R16_UINT, 0, 0x10000 };
+ CHECK( device()->CreateShaderResourceView( buffer, &viewDesc, &rdi ) );
+
+ return S_OK;
+ }
+}
+
+HRESULT LookupTables::create()
+{
+ std::unique_ptr<LookupTablesData> data;
+ try
+ {
+ data = std::make_unique<LookupTablesData>();
+ }
+ catch( const std::bad_alloc& )
+ {
+ return E_OUTOFMEMORY;
+ }
+
+ CHECK( uploadLookupTable( data->gelu, m_gelu ) );
+ CHECK( uploadLookupTable( data->exponent, m_exponent ) );
+
+ return S_OK;
+}
+
+void LookupTables::clear()
+{
+ m_gelu = nullptr;
+ m_exponent = nullptr;
+}
+
+__m128i LookupTables::getMemoryUsage() const
+{
+ __m128i v = resourceMemoryUsage( m_gelu );
+ v = _mm_add_epi64( v, resourceMemoryUsage( m_exponent ) );
+ return v;
+} \ No newline at end of file