-
Notifications
You must be signed in to change notification settings - Fork 0
Home
SmartVectorDotNet provides simple vectorizations for your calculation.
To vectorize,
- prepare all argument set as
ReadOnlySpan<T>
- prepare answer destination as
Span<T>
- use methods in
SmartVectorDotNet.Vectorization.SIMD
using SmartVectorDotNet;
var a = new double[]{ 0, 1, 2, 3, 4, 5, 6, 7, };
var b = new double[]{ 1, -1, 1, -1, 1, -1, 1, -1, };
var ans = new double[a.Length];
Vectorization.SIMD.Multiply<double>(a, b, ans);
Console.WriteLine(string.Join(", ", ans));
// 0, -1, 2, -3, 4, -5, 6, -7
This library has 3 layers:
-
ScalarOp
/ScalarMath
provides generalized and backward-compatibility-enhanced operators and Math/MathF functions. -
VectorOp
/VectorMath
provides SIMD parallelized APIs which are corresponding with each method in ScalarOp/ScalarMath. -
Vectorization
provides span based sequential operation. Their APIs are declared as strategy pattern, you can select simple loop or SIMD vectorized operation.
The APIs in their layers are defined on consistent rule:
-
if
ScalarOp
class hasT XXXX<T>(T arg1, T arg2, ... , T argN)
method,VectorOp
class hasVector<T> XXXX<T>(in Vector<T> arg1, in Vector<T> arg2, ... , in Vector<T> argN)
method which is simply replaced original calculation with SIMD operation. -
there is same relation between
ScalarMath
andVectorMath
. -
if
VectorOp
orVectorMath
class hasVector<T> XXXX<T>(in Vector<T> arg1, in Vector<T> arg2, ... , in Vector<T> argN)
method,Vectorization.Emulated
andVectorization.SIMD
havevoid XXXX<T>(ReadOnlySpan<T> arg1, ReadOnlySpan<T> arg2, ... , ReadOnlySpan<T> argN, Span<T> ans)
method which is generalized for arbitrary length sequence.
These rules enables you to find required method easily.