jackmott / nim_simd

Nim experiment for a write once run optimum simd anywhere *at runtime* library
MIT License
30 stars 1 forks source link

nim_simd

This is an experiment / proof of concept to use Nim's metaprogramming to provide an easy to use SIMD abstraction layer. The goal is for users of the library to be able to write blocks of code containing SIMD intrinsics one time and end up with optimum or near optimum SIMD instructions being used at runtime according to the users hardware. If you are interested in this, you may be interested in my other Rust library, which is a more complete version of the same idea: SIMDeez

How this will work:

Progress So Far:

See simd.nim for the proof of concept so far. Already you can write code like this successfully:

var
    a = newSeq[float32](12)
    b = newSeq[float32](12)
    r = newSeq[float32](12)

for i,v in a:
    a[i] = float32(i)
    b[i] = 2.0'f32

SIMD:     
    for i in countup(0,<a.len,simd.width div 4):
        let av = simd.loadu_ps(addr a[i])
        let bv = simd.loadu_ps(addr b[i])
        let rv = simd.add_ps(av,bv)
        simd.storeu_ps(addr r[i],rv)

echo a
echo b
echo r

Goals / Todo

Help Needed

I would love help with this, I am slowly learning Nim meta programming, so anyone who can help with that aspect, or who can help with SIMD issues would be appreciated. Feel free to jump in.