I've not been following this thread very closely, but it seems like what you're trying to do may be related to Geoffrey Mainland's work on SIMD support in GHC. See [1] for his "SIMD-enabled version of the vector library". He's also written some blog posts about this [2].<div>
<br></div><div>Reiner<br><div><br></div><div>[1] <a href="https://github.com/mainland/vector">https://github.com/mainland/vector</a></div><div>[2] <a href="http://ghc-simd.blogspot.com.au/">http://ghc-simd.blogspot.com.au/</a><br>
<br><div class="gmail_quote">On 8 July 2012 05:13, Nicolas Trangez <span dir="ltr"><<a href="mailto:nicolas@incubaid.com" target="_blank">nicolas@incubaid.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
All,<br>
<br>
After my message of yesterday [1] I got down to it and implemented<br>
something along those lines. I created a playground repository<br>
containing the code at [2]. Initial benchmark results at [3]. More about<br>
the benchmark at the end of this email.<br>
<br>
First some questions and requests for help:<br>
<br>
- I'm stuck with a typing issue related to 'sizeOf' calculation at [4].<br>
I tried a couple of things, but wasn't able to figure out how to fix it.<br>
- I'm using unsafePerformIO at [5], yet I'm not certain it's OK to do<br>
so. Are there better (safer/performant/...) ways to get this working?<br>
- Currently Alignment phantom types (e.g. A8 and A16) are not related to<br>
each other: a function (like Data.Vector.SIMD.Algorithms.unsafeXorSSE42)<br>
can have this signature:<br>
<br>
unsafeXorSSE42 :: Storable a => SV.Vector SV.A16 a -> SV.Vector SV.A16 a<br>
-> SV.Vector SV.A16 a<br>
<br>
Yet, imaging I'd have an "SV.Vector SV.A32 Word8" vector at hand, the<br>
function should accept it as well (a 32-byte aligned vector is also<br>
16-byte aligned). Is there any way to encode this at the type level?<br>
<br>
That's about it :-)<br>
<br>
As of now, I only implemented a couple of the vector API functions (the<br>
ones required to execute my benchmark). Adding the others should be<br>
trivial.<br>
<br>
The benchmark works with Data.Vector.{Unboxed|Storable}.Vector (UV and<br>
SV) vectors of Word8 values, as well as my custom<br>
Data.Vector.SIMD.Vector type (MV) using 16-byte alignment (MV.Vector<br>
MV.A16 Word8).<br>
<br>
benchUV, benchSV and benchMV all take 2 pre-calculated Word8 vectors of<br>
given size (1024 and 4096) and xor them pairwise into the result using<br>
"zipWith xor". benchMVA takes 2 suitable MV vectors and xor's them into<br>
a third using a rather simple and unoptimized C implementation using<br>
SSE4.2 intrinsics [6]. This could be enhanced quite a bit (I guess using<br>
the prim calling convention, FFI overhead can be reduced as well).<br>
Currently, only vectors of a multiple of 32 bytes are supported (mostly<br>
because of laziness on my part).<br>
<br>
As you can see, the zipWith Data.Vector.SIMD implementation is slightly<br>
slower than the Data.Vector.Storable based one. I didn't perform much<br>
profiling yet, but I suspect allocation and ForeignPtr creation is to<br>
blame, this seems to be highly optimized in<br>
GHC.ForeignPtr.mallocPlainForeignPtrBytes as used by<br>
Data.Vector.Storable.<br>
<br>
Thanks for any input,<br>
<br>
Nicolas<br>
<br>
[1] <a href="http://www.haskell.org/pipermail/haskell-cafe/2012-July/102167.html" target="_blank">http://www.haskell.org/pipermail/haskell-cafe/2012-July/102167.html</a><br>
[2] <a href="https://github.com/NicolasT/vector-simd/" target="_blank">https://github.com/NicolasT/vector-simd/</a><br>
[3] <a href="http://linode2.nicolast.be/files/vector-simd-xor1.html" target="_blank">http://linode2.nicolast.be/files/vector-simd-xor1.html</a><br>
[4]<br>
<a href="https://github.com/NicolasT/vector-simd/blob/master/src/Data/Vector/SIMD/Algorithms.hs#L46" target="_blank">https://github.com/NicolasT/vector-simd/blob/master/src/Data/Vector/SIMD/Algorithms.hs#L46</a><br>
[5]<br>
<a href="https://github.com/NicolasT/vector-simd/blob/master/src/Data/Vector/SIMD/Algorithms.hs#L43" target="_blank">https://github.com/NicolasT/vector-simd/blob/master/src/Data/Vector/SIMD/Algorithms.hs#L43</a><br>
[6]<br>
<a href="https://github.com/NicolasT/vector-simd/blob/master/cbits/vector-simd.c#L47" target="_blank">https://github.com/NicolasT/vector-simd/blob/master/cbits/vector-simd.c#L47</a><br>
<br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</blockquote></div><br></div></div>