Skip to content

Commit

Permalink
For now bring cilk up and down each time, this seems to avoid issue #4
Browse files Browse the repository at this point in the history
  • Loading branch information
rrnewton committed Feb 12, 2014
1 parent 410617d commit 5e99ec2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
12 changes: 11 additions & 1 deletion icc-opencl/DEVLOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ like ICC cannot fail gracefully in this case. In this case would be
perfectly happy if I could have a __declspec(vector) fail to vectorize
but still compile.

[2014.02.12] {Segfaults may actually be a Cilk bug}
----------------------------------------------------

I doubt Cilk gets used much in this repeated-dlopen-mode. I started
seeing this error:

"Cilk runtime error: thread creation (3) failed: 11" #4

For which I filed issue #4:

https://github.com/AccelerateHS/accelerate-backend-kit/issues/4



13 changes: 9 additions & 4 deletions icc-opencl/Data/Array/Accelerate/Cilk/JITRuntime.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ module Data.Array.Accelerate.Cilk.JITRuntime (run, runNamed, rawRunIO) where

import Data.Array.Accelerate (Acc)
import qualified Data.Array.Accelerate.Array.Sugar as Sug
import qualified Data.Array.Accelerate.BackendKit.IRs.SimpleAcc as S
import Data.Array.Accelerate.BackendKit.IRs.SimpleAcc (Type(..), Const(..))
import qualified Data.Array.Accelerate.BackendKit.SimpleArray as SA
import Data.Array.Accelerate.BackendKit.Utils.Helpers (maybtrace, dbg)
import Data.Array.Accelerate.BackendKit.CompilerPipeline (phase0, phase1, phase2, repackAcc)
Expand Down Expand Up @@ -46,6 +44,8 @@ import Data.Array.Accelerate.BackendKit.Phase3.ToGPUIR (convertToGPUIR
import Data.Array.Accelerate.BackendKit.Phase3.DesugarGenerate (desugarGenerate)
import Data.Array.Accelerate.BackendKit.Phase3.FuseGenReduce (fuseGenReduce)
import Data.Array.Accelerate.BackendKit.CompilerPipeline (runPass)
import qualified Data.Array.Accelerate.BackendKit.IRs.SimpleAcc as S
import Data.Array.Accelerate.BackendKit.IRs.SimpleAcc (Type(..), Const(..))
import qualified Data.Array.Accelerate.BackendKit.IRs.CLike as C
import qualified Data.Array.Accelerate.BackendKit.IRs.GPUIR as G
import Data.Array.Accelerate.BackendKit.IRs.Metadata (ArraySizeEstimate, FreeVars)
Expand Down Expand Up @@ -136,7 +136,12 @@ rawRunIO pm name prog = do
CilkParallel -> pickCC (error "ICC not found! Need it for Cilk backend.")

let suppress = if dbg>0 then " -g " else " -w " -- No warnings leaking through to the user.
-- #define EXE_OUTPUT
#ifdef EXE_OUTPUT
ccCmd = cc++suppress++" -lcilkrts -std=c99 "++thisprog++".c -o "++thisprog++".exe"
#else
ccCmd = cc++suppress++" -shared -fPIC -std=c99 "++thisprog++".c -o "++thisprog++".so"
#endif
dbgPrint 2 $ "[JIT] Compiling with: "++ ccCmd

t1 <- getCurrentTime
Expand All @@ -148,10 +153,10 @@ rawRunIO pm name prog = do
ExitSuccess -> return ()
ExitFailure c -> error$"C Compiler failed with code "++show c
-- Run the program and capture its output:
#if 0
#ifdef EXE_OUTPUT
dbgPrint 1$ "[JIT] Invoking external executable: "++ thisprog++".exe"
result <- readProcess ("./"++thisprog++".exe") [] ""
let elts = tyToElts (S.progType prog)
let elts = tyToElts (C.progType prog)
dbgPrint 1$ "[JIT] Executable completed, parsing results, element types "++
show elts++", "++show (length result)++" characters:\n "++take 80 result
return$ parseMultiple result elts
Expand Down
11 changes: 10 additions & 1 deletion icc-opencl/Data/Array/Accelerate/Shared/EmitC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ instance EmitBackend CEmitter where
case e of
CEmitter Sequential _ -> return ()
CEmitter CilkParallel _ -> do include "cilk/cilk.h"
include "cilk/cilk_api_linux.h"
include "cilk/reducer.h"
mapM_ (emitLine . strToSyn) $ P.lines headerCode

Expand Down Expand Up @@ -247,7 +248,7 @@ mainBody isCMain e prog@GPUProg{progBinds, progResults, sizeEnv} = do
allResults = standardResultOrder (progResults)
allArrays = map P.fst allResults
allUses = S.fromList $ map (\(a,b,c) -> a) useBinds
body = do
body0 = do
comm "First we EXECUTE the program by executing each array op in order:"
mapM_ (execBind e prog) (L.zip [0..] progBinds)

Expand All @@ -274,6 +275,14 @@ mainBody isCMain e prog@GPUProg{progBinds, progResults, sizeEnv} = do
if S.member vr allUses P.|| elem vr allArrays
then return ()
else freeCStorage ty (varSyn vr)

-- [2014.02.12] For debugging purposes let's bring Cilk up and down explicitly each time:
body =
case e of
CEmitter Sequential _ -> body0
CEmitter CilkParallel _ -> do emitStmt$ function "__cilkrts_init" []
body0
emitStmt$ function "__cilkrts_end_cilk" []
_ <- if isCMain
then rawFunDef "int" "main" [] (do body; return_ 0)
else rawFunDef "void" "MainProg" [("struct ArgRecord*",globalArgs), ("struct ResultRecord*",globalResults)] body
Expand Down

0 comments on commit 5e99ec2

Please sign in to comment.