120 points · by ashvardanian · 3y ago · 56 comments
My conclusion (feel free to enlighten me if I am wrong) is that a system will profit by having more cores instead of AVX-512 for the same power consumption.
It is time to stop quoting this rant, which is rather far removed from actual practice and reality.
Specifically for sorting, Intel's sort and ours can be about 10x as fast as scalar.
AVX-512 has high power? Great! Power is work per time. Let's have more of that. It is _useful_ work per _energy spent_ that we want to maximize, and there scalar code falls flat. Consider that OoO scheduling/control overhead is the real culprit; executing one instruction costs far more energy than the actual operation. SIMD divides that fixed cost over 16 elements, leading to 5-10x higher power efficiency.
Top frequency reduction? Not since the first implementation on Skylake, and even there a non-issue, see https://github.com/google/highway/blob/master/hwy/contrib/so....
More cores? The shared-memory fabric is already bursting at the seams (see on-chip bottlenecks of Genoa), we are already cramming in too many for the current memory interface.
What would actually be necessary: more bandwidth! A64FX CPUs actually beat GPUs in 2019 for supercomputing applications thanks to their HBM. Intel's Sappire Rapids Max also has this. Let's build more of those, at a decent price. And start using the wide vector units, they are there precisely because lots of highly-clocked cores in one big NUMA domain is not always the best way forward.
The 10x number is from comparing against std::sort on random data, yes? Both common std::sort implementations are branching quicksorts from the era when introsort was still considered exciting new technology, and are much slower than pdqsort and other branchless quicksorts. The measurements at [0] show by my estimate about a gain of 3x against pdqsort and 2x against ipnsort. For vqsort only; intel barely beats ipnsort. I also pointed out to you at [1] benchmarks showing 1450MB/s for 32-bit radix sort at a million elements on M1, which is comparable to your Xeon measurements and nearly 3x faster than the 499MB/s for M1 in the vqsort paper.
If you're going to quote a std::sort number, at least give the name instead of implying it's a good representative for scalar sorts! I would strongly recommend, however, that you benchmark against and study more modern scalar algorithms. I know SIMD and have even vectorized parts of pdqsort in the past; I've chosen to work with scalar algorithms for the past year or two because I think these methods still have a lot to offer.
[0] https://github.com/Voultapher/sort-research-rs/blob/main/wri...
> The 10x number is from comparing against std::sort on random data, yes?
That's just one example. For another, check out how many projects still use the even slower HeapSort: https://sourcegraph.com/search?q=context:global+HeapSort+cou... (198K search hits)
When comparing against ipnsort, that is also (partially) vectorized, right?
FWIW I agree that radix sort can be great in certain cases, especially if one core is allowed to soak up all the system memory bandwidth. Unfortunately this is rare from where I sit.
I'm curious which specific parts/aspects of scalar algorithms you'd recommend for study? From my perspective (admittedly skewed towards servers), anything as energy-inefficient as scalar code running on big OoO cores is a hard sell whenever vector alternatives exist.
512-byte SIMD operations are great, but if I'm constantly having to copy things over to SIMD registers to do it... am I really winning?
More cores just means more cache evictions / contention in many workloads.
Then 4 years later AMD has the option to bump to full-speed AVX-512 if it is really needed. This is the same they did with AVX2 initially.
The main exception is that some of the models of Intel Sapphire Rapids, only the most expensive of them, i.e. Xeon Platinum and most of the Xeon Gold models, have a second FMA unit, so only these models are able to execute two 512-bit FMA instructions per cycle, while Zen 4 can execute only one 512-bit FMA instruction + one 512-bit FADD instruction per cycle.
The second advantage of Intel is that it has double bandwidth towards the L1 cache, which is absolutely necessary for Intel, because otherwise it would have been impossible to provide the operands for two FMA instructions per cycle.
While the more expensive Intel models have this FMA throughput advantage, there are also many AVX-512 instructions where AMD has lower latencies than Intel. AMD has also higher clock frequencies when all the cores are busy, and also higher memory throughput, so the result is that for many AVX-512 workloads a Zen 4 beats easily a Sapphire Rapids.
The main applications where Intel wins are those that depend mainly on FMA, i.e. linear algebra operations on dense arrays, e.g. DGEMM or LINPACK.
You could probably find a workload where your conclusion is correct but I think the vast majority of workloads would be faster with AVX-512 if you have the time to leverage it.
Some workloads can be accelerated via AVX-512 as shown here by Anandtech:
https://www.anandtech.com/show/17601/intel-core-i9-13900k-an...
See how AMD CPUs with AVX-512 enabled some a massive boost even with similar/less cores
I would agree that most typical workloads don't benefit much from AVX-512, it requires software support and good use-case(wide parallel SIMD)
for CPUs INT perf is king, even in HPC/enterprise
Tldr it is not that it isn't useful, but the 512 bit part makes implementation prohibitively expensive.
------------------------------------------------------------
Benchmark Time Bytes Items
------------------------------------------------------------
Hwy/random 2.16 s 474.1M/s 62.1M/s
Hwy/sorted_runs 2.29 s 446.7M/s 58.5M/s
IntelX86SIMD/random 2.90 s 353.9M/s 46.3M/s
IntelX86SIMD/sorted_runs 2.68 s 382.4M/s 50.1M/s
https://github.com/funrollloops/parallel-sort-benchWhen those benchmarks were first done, for random input, vqsort was faster once you get around ~20,000 items, but for 1,000 items the new AVX512 sort is 13x faster than vqsort.
As you read it, you'll see that the vqsort issue for small arrays has been fixed, and as of a few weeks ago or so, vqsort is now faster than the AVX512 sort for random.
https://store.steampowered.com/hwsurvey/Steam-Hardware-Softw...
The data set is a mixed bag though. Some types of system are going to be over-represented.
By my lack of knowledge (and the heat of today :0 ) can't guess what algorithms or processes do lots of sorting behind the scenes.
So I was tasked to improve that and I had to write inline assembly to abuse specific cpu instructions that could effectively do much more char comparisons per clock cycle. We ended up not using it because of the usual reasons (not portable, hard to maintain) and our customers had to live with the 20-30s delay when entering a large directory, versus the 5-6s my code achieved.
(Sorry this has little to do with the topic at hand, I don't really know when sorting becomes a problem on a multicore 5ghz cpu)
It is common at the far ends of scalability spectrum: low end where people use $2 VPS, and high end where big tech can afford to invest a lot in engineering effort to build complex systems that are fine tuned for many levels of memory hierarchy.
Most systems can just add memory until data fits. (of course frequently they still don't, and keep doing more expensive things like having many separate copies for different purposes built in various different expensive projects... Sometimes additionally faux justified by using cloud platforms that charge prohitively for memory)
And even writes, there's sorting there. An LSM or a B-epsilon-tree, etc. they're doing sorting and ordered key traversals before paging out.
Anything using an ordered data structure -- btrees, red-black tree etc maps and sets, they're doing sorting.
Which, well, databases. Huge one.
Also, it’s unfortunate that this stuff won’t run on most developer machines.
Disclosure: I am the main author of vqsort, which is also a vectorized Quicksort but portable.