5 ms·
There's "knowing C syntax" and then there's knowing C well enough to be able to read this code and understand what's going on. One of these days I'd like to get
by eachro 5y ago
There's "knowing C syntax" and then there's knowing C well enough to be able to read this code and understand what's going on. One of these days I'd like to get to the point where I can conceivably read this code and understand it well enough to build my own matrix library using similar optimizations for the rest of the matrix operation primitives. Some day ...
- saagarjha 5y agoThis code is less about knowing C and more about knowing vector intrinsics which are not standard C. The actual code is mostly straightforward constructs.
- qayxc 5y agoInterestingly knowing vector intrinsics is exactly what optimising compilers are good at. The article even shows that - look at the C++ code - no instrisics in sight, just pure basic C++ getting the optimisation and performance from the compiler alone.
- saagarjha 5y agoYou probably want to look at the kernels themselves: https://github.com/HazyResearch/blocking-tutorial/blob/master/matrix_kernel16_6.c https://github.com/HazyResearch/blocking-tutorial/blob/maste...
- qayxc 5y agoI was referring to https://github.com/HazyResearch/blocking-tutorial/blob/master/compare_blas.cpp https://github.com/HazyResearch/blocking-tutorial/blob/maste... which upon closer inspection uses intrinsics in the inner loop, but to a much lesser degree and arguably specifying -mavx2 -mfma compiler options would yield comparable results...
- galosh 5y agoEach architecture has a "library" of these bizarrely named functions that are mapped by the compiler to CPU-specific instructions. I'd suggest 90%+ of C programmers couldn't name a single one of them, and that's fine, because they have no place in C outside of tight platform-specific optimization work, which very few people have a need for or mandate to actually work on
- stncls 5y agoIntrinsics-heavy code does looks scary because you see tons of weirdly-named functions with no clue as to what they do. However, you can learn the basics in an hour, and read/write small amounts of code (like in the article) very quickly. The trick that you don't learn all those functions, instead you constantly use the amazing interactive guide: https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html https://www.intel.com/content/www/us/en/docs/intrinsics-guid... I guess real pros do memorize the API of course, but I have written many (<1000) lines of intrinsics code like this.
- sitkack 5y agoPSA the database of instructions and intrinsics is in this xml file https://www.intel.com/content/dam/develop/public/us/en/include/intrinsics-guide/data-3-6-1.xml https://www.intel.com/content/dam/develop/public/us/en/inclu...