Did anyone else try std::experimental::simd?

hobold

Ars Tribunus Militum
2,657
I have no specific question (or homework to outsource:)), it's just that I recently discovered std::experimental::simd and grown fond of it. It is a proposed syntax for portable C++ code, with semantics that make it easy for the compiler to target the various SIMD execution units of various CPUs. Recent GCC and Clang versions come with implementations, and pretty much all CPUs in the personal computing space come with some form of hardware support.

If all the above sounds like gibberish to you, it probably doesn't help when I say this is about reaping performance from SSE, AVX, NEON, SVE, or AVX-512.

I'd like to know if others have written code using std::experimental::simd, and what their experiences were.

Documentation at cppreference.com.
 
  • Like
Reactions: MilleniX

moosemaimer

Ars Scholae Palatinae
717
I ran into this while going over the docs for Mojo... it's a bit jarring when you're reading what is effectively Python and then come across:

Python:
from math import sqrt

fn rsqrt[dt: DType, width: Int](x: SIMD[dt, width]) -> SIMD[dt, width]:
    return 1 / sqrt(x)

var v = SIMD[DType.float16, 4](42)
print(rsqrt(v))

[0.154296875, 0.154296875, 0.154296875, 0.154296875]
 

Aeonsim

Ars Scholae Palatinae
1,057
Subscriptor++
A number of languages are currently doing this, both JAVA (since 17: https://docs.oracle.com/en/java/jav...tor/jdk/incubator/vector/package-summary.html ) and RUST ( https://doc.rust-lang.org/std/simd/index.html ) have similar additions. I've made some use of the Java one using Scala for some fairly compute heavy code I wanted to run across both ARM and X86_64 machines. Get a nice performance boost out of using it though you do seem to loose a bit of performance compared to writing the code using the native functions.