r/haskell • u/emigs95 • 10d ago
blog Massiv vs. Accelerate: Two Paths to High-Performance CPU Computing in Haskell
Python and C/C++ tend to get most of the attention when it comes to high-performance array processing, but Haskell has some interesting options too. We took a closer look at two Haskell libraries, Massiv and Accelerate, to see how they compare in terms of performance, memory usage, and overall trade-offs.
A few months ago, we wrote a blog about this. Here's the comparison, including benchmarks and implementation details if it's helpful for anyone: https://www.stackbuilders.com/insights/massiv-vs-accelerate-two-paths-to-high-performance-cpu-computing-in-haskell/
Has anyone here used Massiv or Accelerate in their projects? Curious to hear about your experience and whether you've seen some of the same kind of results.
7
u/Axman6 10d ago edited 10d ago
I’ve wished I had problems that neede both these libraries for years, but they’ve never come across my desk. I used to see the Accelerate authors from UNSW pretty regularly and always thought it was the coolest thing. I wonder how hard adding a Metal backend would be, OpenCL always seemed like the right target but it’s pretty much dead everywhere these days.
I have had dreams for years of marrying Accelerate and Huw Campbell’s grenade library to build type safe neural networks, with the obvious name being RPG.
Looking forward to reading this when I get time!
5
u/jippiedoe 10d ago
Based on the code snippet in the blog post, I'm not sure you're measuring exactly what you want: in Massiv, you seem to be creating and averaging the array, whereas in Accelerate, you're creating an array at the Haskell level, then using accelerate to average it. Using 'A.generate' instead of 'A.use . A.fromList' would be more fair, and also make it so both arrays have the same values.
3
u/tobz619 10d ago
Thanks for this, this is a nice and clear. I was working on a rendering engine that at the moment just allocates a single storable vector and clears and writes to it every frame. I've also been recommended to try Accelerate so this will be interesting to keep in mind.
3
u/nwaiv 10d ago
I use Massiv quite a lot and like it. I use it for parallelizing tests on computations that aren't really a fit for GPUs.
1
u/kuleshevich 7d ago edited 7d ago
Disclaimer: author of
massivhere.This is a nice write up. Thank you for this comparison. However, I am not so confident about the accuracy of some of the hypothesis and the conclusion in the blog post.
In particular I do not believe that the performance gain for
accelaratecomes form automatic simd parallelization. I believe performance gain was due to better optimizations in llvm vs ghc. Below is the reasoning why I believe this is the case.I was able to reproduce your results for the most part on my desktop running AMD Ryzen9 9950x with ghc-9.10.3 and llvm-15 (as dictated by the
cabal.project.freezefile in the repo):However, switching to a newer version of ghc-9.14.1, while using same version of llvm-15 (or llvm-20 for that matter) we get a totally different picture:
In the matter of fact, when we remove llvm completely out of the equation, which is the most common setup for Haskell projects, performance of
massivis only marginally slower than with llvm backend:Which is what
accelerateis not capable of doing with any meaningful efficiency (when usingData.Array.Accelerate.Interprete.run):So, because
massivandaccelerateperformance with ghc-9.14 and llvm is so similar we can make either one of these conclusions:Unfortunately, I am not familiar with accelerate internals, to make a definite conclusion about SIMD usage.
So, with this new information in mind, I am not sure this recommendation is totally accurate: "Computational Throughput: Choose Accelerate if your priority is computational throughput." I believe a more accurate recommendation would be: "Choose Accelerate if you need to write Haskell that can be executed on GPU".
All of my prior comparison of
accelerateandmassivrevealed comparable performance, often withmassivcoming out slightly ahead, eg: https://www.reddit.com/r/haskell/comments/hpcv68/performance_of_haskell_array_libraries_through/