Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I need faster floating point math for .NET C# (for multiplying and dividing big arrays)

I need fastest possible way to multiply and divide big arrays of data.

I've read this (wrote by Ben Voigt here):

.NET doesn't use MMX or SSE or AVX, as of the current version

(...)

modern C++ compilers not only allow SIMD usage, but can auto-vectorize ordinary-looking code into SIMD instructions

.

I think I need:

  • SSE support with vector operations (for multiplying 4 floats at once)

  • multithreading support (solution/library that will not collide somehow with C# threading)

Is there any library/dll that i can use?

Edit: any alternatives for Octave? I neeed only 2 operations: divide, multiply. If I understood correctly what is Octave and how it works - I will need to parse output... It cant be fast...


According to "what have you tried" and "why you don't want to use simple for":

I need this for neural network training. Network (now) has more than 50 inputs, many neurons (each 50+ weights). Learning data contains 100.000+ rows, 50+ fields each. Each neuron input needs few (at least 5) multiply operations.

I have no idea how many learning epochs i need, but i tried to benchmark only multiply operations and i got result: about 16 secs per epoch on my Intel Core Duo T2500 2.0GHz CPU.

Of course i can buy faster computer, but new computer is worth more than few hours of my work, so I hope it looks logical...

like image 367
Kamil Avatar asked Jan 04 '13 15:01

Kamil


People also ask

Is integer arithmetic faster than floating point arithmetic?

In computer systems, integer arithmetic is exact, but the possible range of values is limited. Integer arithmetic is generally faster than floating-point arithmetic. Floating-point numbers represent what were called in school “real” numbers (i.e., those that have a fractional part, such as 3.1415927).

Is floating point slower than integer?

Floating point math is also much slower than integer math in performing calculations, so should be avoided if, for example, a loop has to run at top speed for a critical timing function. Programmers often go to some lengths to convert floating point calculations to integer math to increase speed.

Is fixed point arithmetic faster than floating point?

Fixed point math, independent of processor speed, is easier to code with and faster than floating point math. Fixed point is adequate unless you know that you will be dealing with higher numbers than the fixed-point unit can handle.

Are Floating points slower?

Floating point is about the same speed. The difference is when you use the result of a computation in memory address indexing - in that case, floating point tends to go through some rather slow CPU pathways for conversion and addressing.


1 Answers

When I saw this question, I searched for ways to use the GOTO BLAS libraries in C#. The GOTO libraries (named after the author, not the evil programming keyword) are widely considered the fastest CPU-based linear algebra libraries because they are written by a talented coder who tunes the library in assembly language for each specific CPU architecture (Opteron, Xeon, etc.)

It turns out that Math.NET Numerics is probably what you want.

From MSDN description:

Math.NET Numerics aims to be the standard open-source math library for the .NET Framework. It provides the methods and algorithms for numerical computations in science, engineering, and everyday use. The functionality covered by Math.NET Numerics includes special functions, linear algebra, probability models, statistics, random numbers, interpolation, and integral transforms (FFT). Math.NET Numerics provides a fully managed implementation that runs on .NET 4.0, Silverlight 4, and Mono (but can be compiled for other platforms). It also provides a parallelized managed implementation and supports optimization using native BLAS/LAPACK libraries (GotoBLAS, Intel MKL, and AMD ACML).

like image 99
Charles Burns Avatar answered Oct 12 '22 09:10

Charles Burns