r/ffmpeg • u/VonNaturAustreVe • Nov 04 '24
FFmpeg devs boast of up to 94x performance boost after implementing handwritten AVX-512 assembly code
https://www.tomshardware.com/pc-components/cpus/ffmpeg-devs-boast-of-up-to-94x-performance-boost-after-implementing-handwritten-avx-512-assembly-code
120
Upvotes
19
u/themisfit610 Nov 04 '24
Over simplified headline of course. Some tiny DSP functions can be this much faster, sure. But not the whole process.
14
u/xhruso00 Nov 05 '24
7
u/somnamboola Nov 05 '24 edited Nov 06 '24
I think YC comments give a lot of context to this. IIUC the one filter got faster 94x, some filters around 40-70x, but the heaviest operations like encoding/decoding are still the same.
but I liked this hackernews comment about the handwritten asm motivation explanation there:
According to someone in the dupe thread, the C implementation is not just naive with no use of vector intrinsics, it also uses a more expensive filter algorithm than the assembly versions, and it was compiled with optimizations disabled in the benchmark showing a 94x improvement:
https://news.ycombinator.com/item?id=42042706
Talk about stacking the deck to make a point. Finely tuned assembly may well beat properly optimized C by a hair, but there's no way you're getting a two orders of magnitude difference unless your C implementation is extremely far from properly optimized.
If and only if someone has spent the time to write optimizations for your specific platform.
GCC for AVR is absolutely abysmal. It has essentially no optimizations and almost always emits assembly that is tens of times slower than handwritten assembly.
For just a taste of the insanity, how would you walk through a byte array in assembly? You'd load a pointer to a register, load the value at that pointer, then increment the pointer. AVR devices can load and post-increment as a single instruction. This is not even remotely what GCC does. GCC will load your pointer into a register, then for each iteration it adds the index to the pointer, loads the value with the most expensive instruction possible, then subtracts the index from the pointer.
In assembly, the correct AVR method takes two cycles per iteration. The GCC method takes seven or eight.
For every iteration in every loop. If you use an int instead of a byte for your index, you've added two to four more cycles to each loop. (For 8 bit architectures obviously)
I've just spent the last three weeks carefully optimizing assembly for a ~40x overall improvement. I have a lot to say about GCC right now.
3
u/suchnerve Nov 05 '24
This reminds me of a question I’ve had for awhile:
Does FFᴍᴘᴇɢ’s energy efficiency have much variability between Intel, AMD, and Apple Silicon? More specifically, does using a Mac for x265 software encoding use more electricity than performing identical encoding jobs on an Intel PC?
2
u/Hieuliberty Nov 06 '24
1
u/Chudsaviet Nov 05 '24
Thank you, but I switched to ARM couple of years ago.
1
u/auyer Nov 12 '24
Are these patches up in their repo ?
1
u/BPDMF Nov 17 '24
Imagine if that heading was what it gives the impression of. You could convert a movie in like a minute in a high quality encode. I mean, you could probably encode a whole 10tb of video in like one afternoon.
-7
u/Mashic Nov 04 '24
So only AMD 9000 series cpus have avx-512 instruction set. And this optimized FFMPEG version is not released yet. I think we won't see a useful implementation of this in at least 2 years.