Vectorized and performance-portable Quicksort (2022)
Thread
Loading the complete thread in the background. This saved snapshot is available now. Refresh
Unofficial Hacker News client; not affiliated with Y Combinator.
Vectorized and performance-portable Quicksort (2022)
Loading the complete thread in the background. This saved snapshot is available now. Refresh
Unofficial Hacker News client; not affiliated with Y Combinator.
glouwbug · · focus · HN ↗
moralestapia · · focus · HN ↗
[dead]
kg · · focus · HN ↗
If you're curious why you would want a vectorized way to sort lists of numbers, one use case is building histograms - it's much easier to build a histogram if you've sorted all your samples first
mcdonje · · focus · HN ↗
I wonder what apps have implemented this now that a few years have passed.
mcdonje · · focus · HN ↗
janwas · · focus · HN ↗
<a href="https://sourcegraph.com/search?q=context:global+hwy/contrib/sort/+-repo:google/highway+-path:hwy/contrib/sort+-path:highway/hwy/+-file:CMakeLists.txt+-file:filelist+-path:g3doc/+-f:meson.build+-f:patch%24+-path:/hwy/&patternType=keyword&sm=0" rel="nofollow">https://sourcegraph.com/search?q=context:global+hwy/contrib/...
tucnak · · focus · HN ↗
sigbottle · · focus · HN ↗
Flex247A · · focus · HN ↗
trueno · · focus · HN ↗
cs702 · · focus · HN ↗
bananaflag · · focus · HN ↗
minitech · · focus · HN ↗
Actual sense in which it’s first:
> Happily, modern instruction sets (Arm SVE, RISC-V V, x86 AVX-512) include a special instruction suitable for partitioning. Given a separate input of yes/no values (whether an element is less than the pivot), this "compress-store" instruction stores to consecutive memory only the elements whose corresponding input is "yes". We can then logically negate the yes/no values and apply the instruction again to write the elements to the other partition. This strategy has been used in an AVX-512-specific Quicksort. But what about other instruction sets such as AVX2 that don't have compress-store? Previous work has shown how to emulate this instruction using permute instructions.
> We build on these techniques to achieve the first vectorized Quicksort that is portable to six instruction sets across three architectures, and in fact outperforms prior architecture-specific sorts.
mixologic · · focus · HN ↗
Would they do the same thing today or have an LLM re-implement those 3000 lines of c++ ?
atiedebee · · focus · HN ↗
glouwbug · · focus · HN ↗
shadowgovt · · focus · HN ↗
glouwbug · · focus · HN ↗
shadowgovt · · focus · HN ↗
That's what I mean about "discoverability crisis." This post is how I learned about the existence of the SIMD library.
janwas · · focus · HN ↗
I'd absolutely still use Highway, and do. My experience is that even two separate implementations diverge over time and I'd have low confidence in bringing the same updates and improvements to all, even with LLM assistance.
Our programming model is 1) an agent+human to generate the algorithmic approach, 2) a C++ library (Highway) to translate to intrinsics, while filling in gaps + allowing customization, 3) a compiler to generate the actual code with some optimizations.
Asking the compiler to do #1 is a pipe dream: compiler friends tell me they are not going to devise new shuffles/data layouts (like what VQSort does). Conflating #2 and #3 means a custom compiler/IR which has high engineering costs (ABI boundaries, hard to debug/profile/sanitize). And doing #3 at runtime (JIT), or moving fusions into #3 (MLIR), vastly complicates the compiler. We can still get runtime adaptability thanks to Highway's multi-target support. Fusion has been much easier to implement manually for LLMs than to construct a general fusion infrastructure. Templates hide most data type differences and we see 2-5x speedup vs llama.cpp for 128k prefill+batch decode on Zen5.
Instead of requiring a compiler to do heroic transforms at runtime, and get it right every time, we can do all kinds of agentic exploration, then verify the result/approach, check in the source code, then we 'just' have a C++ compiler afterwards. And if/when something breaks, it's easy to update centrally, in code we can modify directly, rather than indirectly via updating a compiler.
bee_rider · · focus · HN ↗
There’s something sort of beautiful about mergesort and heapsort. Their names tell you what their main idea is, and how they work is immediately obvious.
Quicksort, on the other hand, has nothing beautiful about it and is named after it’s one redeeming feature (that it is quick for a lot of cases).
thesz · · focus · HN ↗
The in-place property can be utilized to make it very close to cache-oblivious algorithm.
teiferer · · focus · HN ↗
Honest question, curious to hear about what that means to you.
drdexebtjl · · focus · HN ↗
So it feels like an optimization of merge sort for computers, rather than a different approach.
bee_rider · · focus · HN ↗
Real answer: I worked with an intro to programming class as a grad student and I guess I just thought quicksort didn’t fit in very well.
Mergesort is an elegant and straightforward example of recursion. Heapsort—you can make a priority queue and then if you plop a heap in there, that’s heapsort. I like the story.
With quicksort, it isn’t that complicated or anything but it doesn’t feel like it embodies an idea in the way the other two do. And it is annoying that the real big-O cost of the popular sorting algorithm is n^2, and the bad case is really obvious. I guess there’s value to getting over the hump of “well heuristics are a thing and big-O doesn’t tell you everything” but I still don’t like it.
rodrigosetti · · focus · HN ↗
DennisL123 · · focus · HN ↗
djsavvy · · focus · HN ↗
zX41ZdbW · · focus · HN ↗
Since pdqsort, vqsort, and glide sort, the current state-of-the-art are driftsort and ipnsort.
I've integrated them into ClickHouse: <a href="https://github.com/ClickHouse/ClickHouse/pull/106650" rel="nofollow">https://github.com/ClickHouse/ClickHouse/pull/106650
brrrrrm · · focus · HN ↗
rvz · · focus · HN ↗
Only the likes of MAG 7, and a couple of hedge-funds would ask to do it since this problem directly applies to them.
But certainly not pre-revenue startups.
sciencesama · · focus · HN ↗
starcast2026 · · focus · HN ↗
dang · · focus · HN ↗
Vectorized and performance-portable Quicksort - <a href="https://news.ycombinator.com/item?id=31622548">https://news.ycombinator.com/item?id=31622548 - June 2022 (142 comments)
Razengan · · focus · HN ↗
Could AI be used this way? Just splat a visual representation of each item on a virtual wall and have an AI "visually" pick them out?
Razengan · · focus · HN ↗
Could AI be used this way? Just splat a visual representation of each item on a virtual wall and have an AI "visually" pick them out?
jryan49 · · focus · HN ↗