4 ms·
Performance: SIMD, Vectorization and Performance Tuning [video]
- theparanoid 10y agoMike Acton's CppCon talk "Data-Oriented Design and C++" [1] is also good. [1] https://www.youtube.com/watch?v=rX0ItVEVjHc https://www.youtube.com/watch?v=rX0ItVEVjHc
- deleted 10y ago[deleted]
- exDM69 10y agoWatching this makes me sad that there are no languages that would have first class SIMD vector types that would enable writing portable SIMD code for different CPU instruction sets (SSE, AVX, NEON, etc). The closest thing to what I want is C vector extensions available in GCC and Clang [0] (you still need some compiler-specific #ifdefs). GPU and shader languages (GLSL, OpenCL C) have a bit better support, but I want that on the CPU too. Here's a list of my requirements: 1. Built-in types for floating point and integer vectors (compile time constant width). E.g. float32x4_t or int64x2_t. Maybe have some matrix types too. 2. Normal infix operators for arithmetic (+, -, /). You can do this with C [1]. Built-in syntax for vector shuffles (can't do this in C) [2]. 3. Compile time polymorphism to make vector-width agnostic code. If you write sin4f and sin8f (in C), they are line-by-line identical except for types. You should be able to write a single sin() function that works for any vector width 4. A standard library that has all the usual libm math functions (sin, cos, log, exp, asin, atanh, etc). I could do with less-than-perfect precision for performance (at least if -ffast-math is enabled) 5. A standard library for some basic vector and matrix operations for static-sized vectors and matrices. E.g. dot product, matrixmatrix product, matrixvector product, inverse matrix, etc. I put some hope on Rust, which has been working on some SIMD stuff. But the current iteration doesn't fulfill most of my requirements. [0] https://gcc.gnu.org/onlinedocs/gcc/Vector-Extensions.html https://gcc.gnu.org/onlinedocs/gcc/Vector-Extensions.html [1] You can do this: typedef float float32x4_t __attribute__((vector_size(16))); float32x4_t a = { 1, 2, 3, 4 }, b = { 5, 6, 7, 8 }, c = (a+b)*(a-b); [2] You'll need some #ifdefs around __builtin_shuffle (GCC) and __builtin_shufflevector (Clang). Something like my_vec.xxyy, similar to GLSL, would be nicer.
- dragandj 10y agoYou'll find almost all of those in OpenCL.
- exDM69 10y agoI know. I want to use them on the CPU, without having to deal with a big runtime system like OpenCL. OpenCL is still missing the vector width polymorphism. The others are more or less covered. This is a matter of language standardization and some implementation work. I'm not aware of anyone working on this.
- CyberDildonics 10y agoYou should take a good look at ISPC, a C like language bought by Intel for exactly this purpose. It compiles to tiny .o files or intrinsics filled (.h/.c)? files.
- exDM69 10y agoMy understanding is that ISPC is a special compiler that takes a function and emits a SIMD function that computes the original function 4/8 times (and repeats). And it's Intel only. It might be great for some uses, but it's not what I'm looking for.
- CyberDildonics 10y agoI don't think that that is true, it compiles C like programs to use SIMD units more effectively using a 'varying' keyword. I've used it to make programs that run very fast. It may be x64 only.
- jackmott 10y ago.NET languages come close to what you want with System.Numerics, but it lacks complete coverage of SIMD operations. But the basics are there, and it can be very useful at times. https://msdn.microsoft.com/en-us/library/dn858218(v=vs.111).aspx https://msdn.microsoft.com/en-us/library/dn858218(v=vs.111)....