Skip to content

Commit

Permalink
Make SIMD compatible with latest version of System.Numerics.Vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
terrajobst committed Nov 3, 2014
1 parent fb2fa8f commit a819804
Show file tree
Hide file tree
Showing 25 changed files with 164 additions and 159 deletions.
4 changes: 3 additions & 1 deletion System.Numerics/SIMD/Mandelbrot/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
using System.Diagnostics;
using System.Threading;

using Vector = System.Numerics.Vector;

namespace Mandelbrot
{
/// <summary>
Expand All @@ -27,7 +29,7 @@ protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);

if (!VectorMath.IsHardwareAccelerated)
if (!Vector.IsHardwareAccelerated)
{
MessageBox.Show("SIMD isn't enabled for the current process. Please make sure that" + Environment.NewLine + Environment.NewLine +
"(1) You've run the 'enable-jit.cmd' script prior to running this app" + Environment.NewLine +
Expand Down
4 changes: 2 additions & 2 deletions System.Numerics/SIMD/Mandelbrot/Mandelbrot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<Reference Include="System.Data" />
<Reference Include="System.Numerics" />
<Reference Include="System.Numerics.Vectors">
<HintPath>..\packages\Microsoft.Bcl.Simd.1.0.1-beta\lib\portable-net45+win8\System.Numerics.Vectors.dll</HintPath>
<HintPath>..\packages\System.Numerics.Vectors.1.1.5-beta\lib\portable-net45+win8\System.Numerics.Vectors.dll</HintPath>
</Reference>
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
Expand Down Expand Up @@ -99,10 +99,10 @@
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
<Content Include="RunWithSimd.bat">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
16 changes: 8 additions & 8 deletions System.Numerics/SIMD/Mandelbrot/VectorDouble.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void RenderSingleThreadedNoADT(float xminf, float xmaxf, float yminf, flo
double step = (double)stepf;

Vector<double> vlimit = new Vector<double>(limit);
Vector<double> vinc = new Vector<double>((double)Vector<double>.Length * step);
Vector<double> vinc = new Vector<double>((double)Vector<double>.Count * step);
Vector<double> vstep = new Vector<double>(step);
Vector<long> vmax_iters = new Vector<long>(max_iters);
Vector<double> vxmin = VectorHelper.Create(i => xmin + step * i);
Expand All @@ -43,7 +43,7 @@ public void RenderSingleThreadedNoADT(float xminf, float xmaxf, float yminf, flo
{
int xp = 0;
Vector<double> vxmaxd = new Vector<double>(xmax);
for (Vector<double> vx = vxmin; Vector.LessThanOrEqualAny(vx, vxmaxd); vx += vinc, xp += Vector<long>.Length)
for (Vector<double> vx = vxmin; Vector.LessThanOrEqualAny(vx, vxmaxd); vx += vinc, xp += Vector<long>.Count)
{
Vector<double> accumx = vx;
Vector<double> accumy = vy;
Expand Down Expand Up @@ -80,7 +80,7 @@ public void RenderSingleThreadedWithADT(float xminf, float xmaxf, float yminf, f
double step = (double)stepf;

Vector<double> vlimit = new Vector<double>(limit);
Vector<double> vinc = new Vector<double>((double)Vector<double>.Length * step);
Vector<double> vinc = new Vector<double>((double)Vector<double>.Count * step);
Vector<double> vstep = new Vector<double>(step);
Vector<long> vmax_iters = new Vector<long>(max_iters);
Vector<double> vxmax = new Vector<double>(xmax);
Expand All @@ -91,7 +91,7 @@ public void RenderSingleThreadedWithADT(float xminf, float xmaxf, float yminf, f
for (Vector<double> vy = new Vector<double>(ymin); y <= ymax && !Abort; vy += vstep, y += step, yp++)
{
int xp = 0;
for (Vector<double> vx = vxmin; Vector.LessThanOrEqualAny(vx, vxmax); vx += vinc, xp += Vector<long>.Length)
for (Vector<double> vx = vxmin; Vector.LessThanOrEqualAny(vx, vxmax); vx += vinc, xp += Vector<long>.Count)
{
ComplexVecDouble num = new ComplexVecDouble(vx, vy);
ComplexVecDouble accum = num;
Expand Down Expand Up @@ -125,7 +125,7 @@ public void RenderMultiThreadedNoADT(float xminf, float xmaxf, float yminf, floa

Vector<long> vmax_iters = new Vector<long>(max_iters);
Vector<double> vlimit = new Vector<double>(limit);
Vector<double> vinc = new Vector<double>((double)Vector<double>.Length * step);
Vector<double> vinc = new Vector<double>((double)Vector<double>.Count * step);
Vector<double> vxmax = new Vector<double>(xmax);
Vector<double> vstep = new Vector<double>(step);
Vector<double> vxmin = VectorHelper.Create(i => xmin + step * i);
Expand All @@ -137,7 +137,7 @@ public void RenderMultiThreadedNoADT(float xminf, float xmaxf, float yminf, floa
Vector<double> vy = new Vector<double>(ymin + step * yp);
int xp = 0;
for (Vector<double> vx = vxmin; Vector.LessThanOrEqualAny(vx, vxmax); vx += vinc, xp += Vector<long>.Length)
for (Vector<double> vx = vxmin; Vector.LessThanOrEqualAny(vx, vxmax); vx += vinc, xp += Vector<long>.Count)
{
Vector<double> accumx = vx;
Vector<double> accumy = vy;
Expand Down Expand Up @@ -175,7 +175,7 @@ public void RenderMultiThreadedWithADT(float xminf, float xmaxf, float yminf, fl

Vector<long> vmax_iters = new Vector<long>(max_iters);
Vector<double> vlimit = new Vector<double>(limit);
Vector<double> vinc = new Vector<double>((double)Vector<double>.Length * step);
Vector<double> vinc = new Vector<double>((double)Vector<double>.Count * step);
Vector<double> vxmax = new Vector<double>(xmax);
Vector<double> vstep = new Vector<double>(step);
Vector<double> vxmin = VectorHelper.Create(i => xmin + step * i);
Expand All @@ -187,7 +187,7 @@ public void RenderMultiThreadedWithADT(float xminf, float xmaxf, float yminf, fl
Vector<double> vy = new Vector<double>(ymin + step * yp);
int xp = 0;
for (Vector<double> vx = vxmin; Vector.LessThanOrEqualAny(vx, vxmax); vx += vinc, xp += Vector<long>.Length)
for (Vector<double> vx = vxmin; Vector.LessThanOrEqualAny(vx, vxmax); vx += vinc, xp += Vector<long>.Count)
{
ComplexVecDouble num = new ComplexVecDouble(vx, vy);
ComplexVecDouble accum = num;
Expand Down
16 changes: 8 additions & 8 deletions System.Numerics/SIMD/Mandelbrot/VectorDoubleStrict.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void RenderMultiThreadedWithADT(float xminf, float xmaxf, float yminf, fl
Vector<double> vmax_iters = new Vector<double>((double)max_iters);
Vector<double> vlimit = new Vector<double>(limit);
Vector<double> vstep = new Vector<double>(step);
Vector<double> vinc = new Vector<double>((double)Vector<double>.Length * step);
Vector<double> vinc = new Vector<double>((double)Vector<double>.Count * step);
Vector<double> vxmax = new Vector<double>(xmax);
Vector<double> vxmin = VectorHelper.Create(i => xmin + step * i);

Expand All @@ -49,7 +49,7 @@ public void RenderMultiThreadedWithADT(float xminf, float xmaxf, float yminf, fl
Vector<double> vy = new Vector<double>(ymin + step * yp);
int xp = 0;
for (Vector<double> vx = vxmin; Vector.LessThanOrEqualAll(vx, vxmax); vx += vinc, xp += Vector<double>.Length)
for (Vector<double> vx = vxmin; Vector.LessThanOrEqualAll(vx, vxmax); vx += vinc, xp += Vector<double>.Count)
{
ComplexVecDouble num = new ComplexVecDouble(vx, vy);
ComplexVecDouble accum = num;
Expand Down Expand Up @@ -83,7 +83,7 @@ public void RenderMultiThreadedNoADT(float xminf, float xmaxf, float yminf, floa
Vector<double> vmax_iters = new Vector<double>((double)max_iters);
Vector<double> vlimit = new Vector<double>(limit);
Vector<double> vstep = new Vector<double>(step);
Vector<double> vinc = new Vector<double>((double)Vector<double>.Length * step);
Vector<double> vinc = new Vector<double>((double)Vector<double>.Count * step);
Vector<double> vxmax = new Vector<double>(xmax);
Vector<double> vxmin = VectorHelper.Create(i => xmin + step * i);

Expand All @@ -94,7 +94,7 @@ public void RenderMultiThreadedNoADT(float xminf, float xmaxf, float yminf, floa
Vector<double> vy = new Vector<double>(ymin + step * yp);
int xp = 0;
for (Vector<double> vx = vxmin; Vector.LessThanOrEqualAll(vx, vxmax); vx += vinc, xp += Vector<double>.Length)
for (Vector<double> vx = vxmin; Vector.LessThanOrEqualAll(vx, vxmax); vx += vinc, xp += Vector<double>.Count)
{
Vector<double> accumx = vx;
Vector<double> accumy = vy;
Expand Down Expand Up @@ -132,7 +132,7 @@ public void RenderSingleThreadedWithADT(float xminf, float xmaxf, float yminf, f
Vector<double> vmax_iters = new Vector<double>((double)max_iters);
Vector<double> vlimit = new Vector<double>(limit);
Vector<double> vstep = new Vector<double>(step);
Vector<double> vinc = new Vector<double>((double)Vector<double>.Length * step);
Vector<double> vinc = new Vector<double>((double)Vector<double>.Count * step);
Vector<double> vxmax = new Vector<double>(xmax);
Vector<double> vxmin = VectorHelper.Create(i => xmin + step * i);

Expand All @@ -141,7 +141,7 @@ public void RenderSingleThreadedWithADT(float xminf, float xmaxf, float yminf, f
for (Vector<double> vy = new Vector<double>(ymin); y <= ymax && !Abort; vy += vstep, y += step, yp++)
{
int xp = 0;
for (Vector<double> vx = vxmin; Vector.LessThanOrEqualAny(vx, vxmax); vx += vinc, xp += Vector<double>.Length)
for (Vector<double> vx = vxmin; Vector.LessThanOrEqualAny(vx, vxmax); vx += vinc, xp += Vector<double>.Count)
{
ComplexVecDouble num = new ComplexVecDouble(vx, vy);
ComplexVecDouble accum = num;
Expand Down Expand Up @@ -175,7 +175,7 @@ public void RenderSingleThreadedNoADT(float xminf, float xmaxf, float yminf, flo
Vector<double> vmax_iters = new Vector<double>((double)max_iters);
Vector<double> vlimit = new Vector<double>(limit);
Vector<double> vstep = new Vector<double>(step);
Vector<double> vinc = new Vector<double>((double)Vector<double>.Length * step);
Vector<double> vinc = new Vector<double>((double)Vector<double>.Count * step);
Vector<double> vxmax = new Vector<double>(xmax);
Vector<double> vxmin = VectorHelper.Create(i => xmin + step * i);

Expand All @@ -184,7 +184,7 @@ public void RenderSingleThreadedNoADT(float xminf, float xmaxf, float yminf, flo
for (Vector<double> vy = new Vector<double>(ymin); y <= ymax && !Abort; vy += vstep, y += step, yp++)
{
int xp = 0;
for (Vector<double> vx = vxmin; Vector.LessThanOrEqualAll(vx, vxmax); vx += vinc, xp += Vector<double>.Length)
for (Vector<double> vx = vxmin; Vector.LessThanOrEqualAll(vx, vxmax); vx += vinc, xp += Vector<double>.Count)
{
Vector<double> accumx = vx;
Vector<double> accumy = vy;
Expand Down
16 changes: 8 additions & 8 deletions System.Numerics/SIMD/Mandelbrot/VectorFloat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void RenderSingleThreadedWithADT(float xmin, float xmax, float ymin, floa
Vector<float> vlimit = new Vector<float>(limit);
Vector<float> vstep = new Vector<float>(step);
Vector<float> vxmax = new Vector<float>(xmax);
Vector<float> vinc = new Vector<float>((float)Vector<float>.Length * step);
Vector<float> vinc = new Vector<float>((float)Vector<float>.Count * step);
// Use my little helper routine: it's kind of slow, but I find it pleasantly readable.
// The alternative would be this:
// float[] xmins = new float[Vector<float>.Length];
Expand All @@ -52,7 +52,7 @@ public void RenderSingleThreadedWithADT(float xmin, float xmax, float ymin, floa
int xp = 0;
for (Vector<float> vx = vxmin;
Vector.LessThanOrEqualAny(vx, vxmax); // Vector.{comparision}Any|All return bools, not masks
vx += vinc, xp += Vector<int>.Length)
vx += vinc, xp += Vector<int>.Count)
{
ComplexVecFloat num = new ComplexVecFloat(vx, vy);
ComplexVecFloat accum = num;
Expand Down Expand Up @@ -100,15 +100,15 @@ public void RenderSingleThreadedNoADT(float xmin, float xmax, float ymin, float
Vector<float> vlimit = new Vector<float>(limit);
Vector<float> vstep = new Vector<float>(step);
Vector<float> vxmax = new Vector<float>(xmax);
Vector<float> vinc = new Vector<float>((float)Vector<float>.Length * step);
Vector<float> vinc = new Vector<float>((float)Vector<float>.Count * step);
Vector<float> vxmin = VectorHelper.Create(i => xmin + step * i);

float y = ymin;
int yp = 0;
for (Vector<float> vy = new Vector<float>(ymin); y <= ymax && !Abort; vy += vstep, y += step, yp++)
{
int xp = 0;
for (Vector<float> vx = vxmin; Vector.LessThanOrEqualAll(vx, vxmax); vx += vinc, xp += Vector<int>.Length)
for (Vector<float> vx = vxmin; Vector.LessThanOrEqualAll(vx, vxmax); vx += vinc, xp += Vector<int>.Count)
{
Vector<float> accumx = vx;
Vector<float> accumy = vy;
Expand Down Expand Up @@ -140,7 +140,7 @@ public void RenderMultiThreadedNoADT(float xmin, float xmax, float ymin, float y
Vector<int> vmax_iters = new Vector<int>(max_iters);
Vector<float> vlimit = new Vector<float>(limit);
Vector<float> vstep = new Vector<float>(step);
Vector<float> vinc = new Vector<float>((float)Vector<float>.Length * step);
Vector<float> vinc = new Vector<float>((float)Vector<float>.Count * step);
Vector<float> vxmax = new Vector<float>(xmax);
Vector<float> vxmin = VectorHelper.Create(i => xmin + step * i);

Expand All @@ -151,7 +151,7 @@ public void RenderMultiThreadedNoADT(float xmin, float xmax, float ymin, float y
Vector<float> vy = new Vector<float>(ymin + step * yp);
int xp = 0;
for (Vector<float> vx = vxmin; Vector.LessThanOrEqualAll(vx, vxmax); vx += vinc, xp += Vector<int>.Length)
for (Vector<float> vx = vxmin; Vector.LessThanOrEqualAll(vx, vxmax); vx += vinc, xp += Vector<int>.Count)
{
Vector<float> accumx = vx;
Vector<float> accumy = vy;
Expand Down Expand Up @@ -184,7 +184,7 @@ public void RenderMultiThreadedWithADT(float xmin, float xmax, float ymin, float
Vector<int> vmax_iters = new Vector<int>(max_iters);
Vector<float> vlimit = new Vector<float>(limit);
Vector<float> vstep = new Vector<float>(step);
Vector<float> vinc = new Vector<float>((float)Vector<float>.Length * step);
Vector<float> vinc = new Vector<float>((float)Vector<float>.Count * step);
Vector<float> vxmax = new Vector<float>(xmax);
Vector<float> vxmin = VectorHelper.Create(i => xmin + step * i);

Expand All @@ -195,7 +195,7 @@ public void RenderMultiThreadedWithADT(float xmin, float xmax, float ymin, float
Vector<float> vy = new Vector<float>(ymin + step * yp);
int xp = 0;
for (Vector<float> vx = vxmin; Vector.LessThanOrEqualAll(vx, vxmax); vx += vinc, xp += Vector<int>.Length)
for (Vector<float> vx = vxmin; Vector.LessThanOrEqualAll(vx, vxmax); vx += vinc, xp += Vector<int>.Count)
{
ComplexVecFloat num = new ComplexVecFloat(vx, vy);
ComplexVecFloat accum = num;
Expand Down

2 comments on commit a819804

@birbilis
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when I first noticed you changed "Length" to "Count" it looked strange, but if this returns number of elements in the vector, then definitely it is the way to go (since Length means other thing in geometry)

@mellinoe
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, we wanted to make sure there was no confusion between the two terms, and since "Count" is already used for things like Lists, etc. we figured this was clearer.

Please sign in to comment.