summaryrefslogtreecommitdiffstats
path: root/Whisper/ML
diff options
context:
space:
mode:
authorKonstantin <const@const.me>2023-01-23 20:28:59 +0100
committerKonstantin <const@const.me>2023-01-23 20:28:59 +0100
commit15dbcacdbc5db68c1ea86bb330d07ec70de75af6 (patch)
tree7740da539ecd498ad143b733a50fa5043658e9cd /Whisper/ML
parentd3fe947eee55ea149c55c4f3a83ea285f9c0f5ba (diff)
Minor, micro-optimization
Diffstat (limited to 'Whisper/ML')
-rw-r--r--Whisper/ML/Context.ops.cpp17
-rw-r--r--Whisper/ML/TensorShape.h4
2 files changed, 16 insertions, 5 deletions
diff --git a/Whisper/ML/Context.ops.cpp b/Whisper/ML/Context.ops.cpp
index a94497e..f6309f0 100644
--- a/Whisper/ML/Context.ops.cpp
+++ b/Whisper/ML/Context.ops.cpp
@@ -84,9 +84,20 @@ Tensor __declspec( noinline ) MlContext::view2d( const Tensor& a, uint32_t ne0,
Tensor MlContext::transpose( const Tensor& a )
{
- Tensor result = a;
- std::swap( result.ne[ 0 ], result.ne[ 1 ] );
- std::swap( result.nb[ 0 ], result.nb[ 1 ] );
+ Tensor result;
+
+ // A magic number for _mm_shuffle_epi32 SSE2 instruction to swap two lower int32 lanes in a vector
+ constexpr int swapXy = _MM_SHUFFLE( 3, 2, 0, 1 );
+
+ __m128i v = a.sizeVec();
+ v = _mm_shuffle_epi32( v, swapXy );
+ store( result.ne, v );
+
+ v = a.stridesVec();
+ v = _mm_shuffle_epi32( v, swapXy );
+ store( result.nb, v );
+
+ result.setGpuViews( a, a );
return result;
}
diff --git a/Whisper/ML/TensorShape.h b/Whisper/ML/TensorShape.h
index 473b0c9..5749764 100644
--- a/Whisper/ML/TensorShape.h
+++ b/Whisper/ML/TensorShape.h
@@ -28,11 +28,11 @@ namespace DirectCompute
HRESULT create( const ggml_tensor& ggml );
TensorShape( const ggml_tensor& ggml );
- __m128i sizeVec() const
+ __m128i __vectorcall sizeVec() const
{
return load( ne );
}
- __m128i stridesVec() const
+ __m128i __vectorcall stridesVec() const
{
return load( nb );
}