Haskell Array.Accelerate - forkOS error

HaskellPlotGnuplotGpu

Haskell Problem Overview


Trying to plot the output of some Data.Array.Accelerate computations with gnuplot I encountered a strange problem. When run via the interpreter everything is fine, as is plotting straight Haskell data or just printing the Accelerate values, however trying to plot the Accelerate data fails. The error given is forkOS_entry: interrupted.

I've since realised I should just be more UNIXy and do one thing (well) in each program. But I'm interested in finding out why this fails. I include a minimum code sample below.

import Prelude hiding (zip,zipWith)

import Graphics.Gnuplot.Simple
import Data.Array.Accelerate
-- import Data.Array.Accelerate.Interpreter
import Data.Array.Accelerate.CUDA

f :: Vector Float -> Vector Float -> Acc (Vector Float)
f xs ys = let xs' = use xs
              ys' = use ys
          in
             (zipWith (*) xs' ys')
n=10::Int

points = toList.run $ f (fromList (Z:.n) [1..10]) (fromList (Z:.n) [-5..4])

main = plotList [] points

update 2014/09/11

Based on user2141650's suggestion (thanks!) changing the last line to

plotList [] $! points

fixes the problem. In fact it makes the plot actually appear, whereas without this the program would finish with or without error but would never actually display the plot. I suppose I'd accept this as an answer if it was written up, but it would still be nice to know what's going on.

Possibly related:

(By the way, please stop trying to edit for grammar. There isn't anything wrong with the question as is, I am a native speaker and write exactly what I mean. Thank you for your contribution though.)

Haskell Solutions


Solution 1 - Haskell

As I mentioned in a comment, this is likely because of the interleaved interaction of gnuplot and accelerate on the GPU, when the accelerate computation is called lazily. I can't say I know the details, but this [0] seems relevant. It may be that gnuplot can't use the GPU since Accelerate has already claimed it, but Accelerate won't release it until fully evaluated. Or else that gnuplot claims the GPU before Accelerate. Hairy-looking issue, and it might warrant a mention in the github issue tracker for Accelerate.

[0] https://github.com/AccelerateHS/accelerate/issues/48

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser328062View Question on Stackoverflow
Solution 1 - Haskelluser2141650View Answer on Stackoverflow