News for hackers. Stuff that matters.
Re:Transcoding Unicode with AVX-512: AMD Zen 4 vs. Intel Ice... by moonchild on Thursday January 05, 2023 @07:35PM (#34269227)
Most of what's interesting about avx512 is the new instructions; the wider vectors are just icing on the cake. You would need to rewrite your code regardless.
Re:Transcoding Unicode with AVX-512: AMD Zen 4 vs. Intel Ice... by readonlybarbie on Thursday January 05, 2023 @07:56PM (#34269462)
Noob question- must one write avx512 assembly directly by hand, or is this something a c compiler would do for you?
Re:Transcoding Unicode with AVX-512: AMD Zen 4 vs. Intel Ice... by habitue on Thursday January 05, 2023 @08:26PM (#34269729)
Potentially both. Most compilers have vectorization optimizations if you compile for an architecture that supports it.

However, a lot of software is compiled on one machine to be run on potentially many possible architectures, so they target a very lowest common denominator arch like x86-64. This will have some SIMD instructions but (I don't think) AVX-512.

So if a developer wants to ensure those instructions are used if they're supported, they'll write two code paths. one path will explicitly call the avx512 instructions with compiler intrinsics and then the other path will just use the manual code and let the compiler decide how to turn it into x86-64 safe instructions.

[dead]
Re:Transcoding Unicode with AVX-512: AMD Zen 4 vs. Intel Ice... by janwas on Friday January 06, 2023 @04:06AM (#34272598)
A compiler turning C(++) code into SIMD instructions is called "autovectorization". In my experience this works for simple loops such as dot products (even that requires special compiler flags to enable FMA and reorders), but unfortunately the wheels often fall off for more complex code. Also, I haven't seen the compiler generate the more exotic instructions.
Re:Transcoding Unicode with AVX-512: AMD Zen 4 vs. Intel Ice... by brrrrrm on Thursday January 05, 2023 @08:50PM (#34269913)
typically if it's available, compilers will use the avx512 register file. This means you'll see things like xmm25 and ymm25 (128 and 256 bit registers) and those are avx512 only. However, compilers using 512-wide instructions is kinda rare from what I've seen
[dead]
Re:Transcoding Unicode with AVX-512: AMD Zen 4 vs. Intel Ice... by brrrrrm on Friday January 06, 2023 @10:53AM (#34276086)
without using intrinsics? `-O3 -march=skylake-avx512 -mprefer-vector-width=512`
Re:Transcoding Unicode with AVX-512: AMD Zen 4 vs. Intel Ice... by celrod on Friday January 06, 2023 @03:19AM (#34272289)
You can use `-mprefer-vector-width=512` to use 512 bit vectors, or if you want a particular function to use 512, you could try the min-vector-width attribute: https://clang.llvm.org/docs/AttributeReference.html#min-vect...

In my experience, clang unrolls too much, so you end up spending all your time in the non-vectorized remainder. Using smaller vectors cuts the size of the non-vectorized remainders in half, so smaller vectors often give better performance for that reason. (Unrolling less could have the same effect while decreasing code size, but alas)

Re:Transcoding Unicode with AVX-512: AMD Zen 4 vs. Intel Ice... by moloch-hai on Thursday January 05, 2023 @08:53PM (#34269935)
Generally you are better off coding with "intrinsics", compiler extensions that represent the instructions more symbolically, if in fact the compiler offers what you need.

I am not sure the really interesting AVX-512 instructions have intrinsics yet. For those it's asm or nothing.

Re:Transcoding Unicode with AVX-512: AMD Zen 4 vs. Intel Ice... by Iwan-Zotow on Thursday January 05, 2023 @10:43PM (#34270697)
You should use Intel intrinsics - generally, they are supported by all compilers.

E.g. https://www.intel.com/content/www/us/en/develop/documentatio...

[dead]
Re:Transcoding Unicode with AVX-512: AMD Zen 4 vs. Intel Ice... by janwas on Friday January 06, 2023 @04:07AM (#34272605)
It would be simpler to use the portable intrinsics from github.com/google/highway (disclosure: I am the main author). You include a header, and use the same functions on all platforms; the library provides wrapper functions which boil down to the platform's intrinsics.
Re:Transcoding Unicode with AVX-512: AMD Zen 4 vs. Intel Ice... by Iwan-Zotow on Friday January 06, 2023 @08:15PM (#34283908)
Well, there is SIMD proposal for C++23 with kind-of-reference implementation. But I don't know how well it works for AVX0512
Re:Transcoding Unicode with AVX-512: AMD Zen 4 vs. Intel Ice... by janwas on Saturday January 07, 2023 @05:22AM (#34286843)
From what I have seen, this is unfortunately not very useful: it mainly only includes operations that the compiler is often able to autovectorize anyway (simple arithmetic). Support for anything more interesting such as swizzles seems nonexistent. Also, last I checked, this was only available on GCC 11+; has that changed?
Re:Transcoding Unicode with AVX-512: AMD Zen 4 vs. Intel Ice... by Iwan-Zotow on Sunday January 08, 2023 @08:57PM (#34305809)
I think proposed Vc lib is tested under clang as well.
Re:Transcoding Unicode with AVX-512: AMD Zen 4 vs. Intel Ice... by janwas on Monday January 09, 2023 @01:37AM (#34307506)
Here is my source: https://github.com/VcDevel/std-simd

Ah, but this repo mentions that the GCC 11 implementation apparently also works with clang: https://github.com/VcDevel/Vc. Thanks!

Re:Transcoding Unicode with AVX-512: AMD Zen 4 vs. Intel Ice... by gulikoza on Friday January 06, 2023 @02:58AM (#34272135)
I wonder how much compilers could be improved with AI?

I'd imagine outputting optimized avx code from an existing C for() loop would be much easier than going from a "write me a python code that..." prompt.

Re:Transcoding Unicode with AVX-512: AMD Zen 4 vs. Intel Ice... by stabbles on Thursday January 05, 2023 @08:21PM (#34269683)
I wonder to what extent compilers even emit avx512 instructions apart from the common ones (load, store, shuffle, arithmetic) in case you don’t want to manually optimize for sse / avx / avx2 / avx512.
Re:Transcoding Unicode with AVX-512: AMD Zen 4 vs. Intel Ice... by celrod on Thursday January 05, 2023 @08:35PM (#34269793)
How much code is compiled with `-march=native` or function multiversioning? I would guess the percentage is relatively small, at least when it comes to distributed binaries.

Compiler autovectorizers also aren't very good at producing fast AVX512 code, so most of the benefit would probably come from using optimized libraries like Intel's MKL or simdjson.

Re:Transcoding Unicode with AVX-512: AMD Zen 4 vs. Intel Ice... by derefr on Thursday January 05, 2023 @09:31PM (#34270204)
> How much code is compiled with `-march=native`

Any installation of Gentoo is, presumably. (Otherwise, what's the point of compiling it all yourself?)

More interestingly, possibly all OEM firmware-installed copies of ChromeOS are -march=native builds as well, given that ChromeOS is based off of a Gentoo upstream.

Re:Transcoding Unicode with AVX-512: AMD Zen 4 vs. Intel Ice... by celrod on Friday January 06, 2023 @04:39AM (#34272804)
True. I have never gone down the Gentoo rabbit hole. Might be fun to try sometime, but I'd seriously doubt that the time spent compiling would be won back from better performance.

Clear Linux is probably a more practical alternative. I used it a couple years ago, and found that they had a lot of avx2 and avx512 versions of random libraries built, with the appropriate ones presumably being loaded based on the hardware.

Random glibc math function calls, for example, were much faster on Clear Linux than Arch or Fedora. But development of Clear seems to have stopped, libraries like llvm aren't being updated anymore so the toolchains are outdated. I'd wanted to avoid the blood and sweat of managing my own toolchains, and ironically being on bleeding edge distros (Arch,Fedora,etc) was the way to keep that to a minimum. Next time I reinstall an OS, I'll look at Clear again. Or maybe Guix or Nix. Or maybe use spack for package management on top of some other distro.

Re:Transcoding Unicode with AVX-512: AMD Zen 4 vs. Intel Ice... by Thev00d00 on Friday January 06, 2023 @07:55AM (#34274121)
When I ran Gentoo I just had the builds running in the background with a really high niceness.
Re:Transcoding Unicode with AVX-512: AMD Zen 4 vs. Intel Ice... by ryao on Thursday January 05, 2023 @08:45PM (#34269873)
Even if you use the GNU C vector extension to explicitly give the compiler ways of optimizing C, it is not very good at generating good vector code:

https://github.com/openzfs/zfs/pull/14234#issuecomment-13345...

A bug report has been filed with GCC for one of the issues. LLVM is much better here, but not perfect, or at least that has been my experience when trying to have the compiler generate assembly for an explicitly vectorized fletcher4 implementation.

Re:Transcoding Unicode with AVX-512: AMD Zen 4 vs. Intel Ice... by ryao on Thursday January 05, 2023 @08:42PM (#34269846)
Using the RISC-V V vector instructions means that the underlying hardware vector width can change and the code will automatically take advantage of the larger width.

That said, many of the avx512 instructions are simply extended width AVX2/avx2 instructions. The interesting things about it are really the increased width and the additional registers. Not many of the new instructions that are not bitwidtg extended versions of the old ones are particularly interesting since Intel had already implemented most of the interesting things for smaller vector widths.

Re:Transcoding Unicode with AVX-512: AMD Zen 4 vs. Intel Ice... by kolbe on Thursday January 05, 2023 @09:52PM (#34270363)
I've only scratched the surface of the avx512 instructions, but they are much more broad and useful. Masked gather, scatter, double precision exp and mantissa extraction, and floating point to integer conversions are all new and all proving useful to me.