71

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.)

Community
  • 1
  • 1
  • 1
    Something to try: recompile with `-threaded`. (Don't forget to make a trivial edit to your source code so ghc thinks it's worth its while.) – not my job Feb 07 '14 at 11:33
  • 8
    The GHC flag -fforce-recomp comes in handy when messing with compiler flags. – crockeea Feb 08 '14 at 04:13
  • 1
    @SeanD Did you try it? – not my job Feb 08 '14 at 10:42
  • 2
    @enoughreptocomment Sorry about the delay, I was away from my GPU box this week. Interestingly using `-threaded` makes it run successflly about 1/4 of the time, otherwise it just fails with the same error. It feels like there's some sort of race condition going on, I don't know if that's a bug with either of the libraries or GHC . *edit*: to make matters more confusing I've noticed that the error only seems to occur when I use `runghc` rather than `ghc` and the program directly. –  Feb 13 '14 at 14:08
  • 1
    Have you tried to strace the execution? Give it a go, a trace of a failing run should be quite illuminating. You may need the flag to follow through fork() calls. – Andrew McGregor Sep 03 '14 at 05:46
  • 2
    Could it be that gnuplot and accelerate are interfering with one another? Could you try fully evaluating `points` before calling plotList? – user2141650 Sep 11 '14 at 09:37
  • @AndrewMcGregor I tried `strace`ing successful and unsuccessful runs, but there was nothing that jumped out at me (not that I'm so familiar with reading them), I can post them if you think they'd be interesting. @user2141650 see edit. –  Sep 11 '14 at 11:06

1 Answers1

1

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

user2141650
  • 2,827
  • 1
  • 15
  • 23