Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Haskell perfom SIMD optimizations automatically?

Tags:

haskell

simd

It is possible to write SIMD-based vector library in Haskell using https://hackage.haskell.org/package/ghc-prim-0.4.0.0/docs/GHC-Prim.html#g:28 but will it make any sense? I've came across several papers devoted to automatic SIMD optimization in Haskell, but what the current status (2014)? E.g. will https://hackage.haskell.org/package/vector use SIMD or it is better to write optimized library manually using low-level SIMD primitives?

like image 315
schernichkin Avatar asked Jun 03 '15 15:06

schernichkin


2 Answers

First: I had no idea GHC even had primops for SIMD. Nice find!

Anyway, that aside, my understanding is this:

  • The GHC native codegen backend will never emit SIMD instructions all by itself.
  • The optional LLVM backend may produce SIMD, I don't know. But that's not the default compilation route; my understanding is it's still rather experimental.
  • Given the existence of the primops you mention, the Vector library could conceivably be generating SIMD code. I suspect it isn't, but the only way to really know for sure is to ask the author(s) or just grep the source code...
  • If you want something specific, it seems perfectly reasonable to code it yourself. I have no idea how much work it would be...
like image 90
MathematicalOrchid Avatar answered Oct 30 '22 20:10

MathematicalOrchid


there is absolutely no auto vectorization wrt SIMD in ghc at the moment. none

the current simd primops will trigger a GHC panic when used with the native code gen, though they will work with the -fllvm backend.

those simd primops crucially lack a good data model for data shuffling, the current data model will require a pretty substantial reworking to support simd shuffles properly.

the llvm backend MAY do certain auto vectorization optimizations on code, but i'd generally treat auto-vectorization as a bonus rather than a core assumption in how code gets optimized, it requires some careful auditing to validate!

like image 30
Carter Tazio Schonwald Avatar answered Oct 30 '22 22:10

Carter Tazio Schonwald