Embedding an embedding vector in C #

Do I need to "vectorize" adding elements to arrays in SIMD mode?

For example, I would like to include:

var a = new[] { 1, 2, 3, 4 }; var b = new[] { 1, 2, 3, 4 }; var c = new[] { 1, 2, 3, 4 }; var d = new[] { 1, 2, 3, 4 }; var e = new int[4]; for (int i = 0; i < a.Length; i++) { e[i] = a[i] + b[i] + c[i] + d[i]; } // e should equal { 4, 8, 12, 16 } 

In something like:

 var e = VectorAdd(a,b,c,d); 

I know that something may exist in C ++ / XNA libraries, but I did not know if we have it in standard .Net libraries.

Thanks!

+7
source share
3 answers

You want to see Mono.Simd:

http://tirania.org/blog/archive/2008/Nov-03.html

It supports SIMD in C #

 using Mono.Simd; //... var a = new Vector4f( 1, 2, 3, 4 ); var b = new Vector4f( 1, 2, 3, 4 ); var c = new Vector4f( 1, 2, 3, 4 ); var d = new Vector4f( 1, 2, 3, 4 ); var e = a+b+c+d; 
+13
source

Mono provides a relatively decent SIMD API (as mentioned), but if Mono is not an option, I would probably write a C ++ / CLI interface library for hard work. C # works very well for most task sets, but if you are starting to get high-performance code, it's best to switch to a language that gives you control to really be messy with performance.

Here at work, we use P / Invoke to call image processing routines written in C ++ from C #. P / Invoke has some overhead, but if you make very few calls and do a lot of processing on the home side, it might be worth it.

+5
source

I think it all depends on what you are doing, but if you are worried about vectorizing vector sums, you can take a look at a library such as Math.NET that provide optimized numerical calculations.

On its website:

It targets Microsoft.Net 4.0, Mono, and Silverlight 4 and, in addition to a purely managed implementation, will also support its own hardware optimization (MKL, ATLAS).

+2
source

All Articles