{-# LINE 1 "src/Foreign/CUDA/Driver/Graph/Exec.chs" #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE TemplateHaskell #-}
module Foreign.CUDA.Driver.Graph.Exec (
Executable(..),
launch,
instantiate,
destroy,
) where
import qualified Foreign.C.Types as C2HSImp
import qualified Foreign.Ptr as C2HSImp
{-# LINE 29 "src/Foreign/CUDA/Driver/Graph/Exec.chs" #-}
import Foreign.CUDA.Driver.Error
import Foreign.CUDA.Driver.Graph.Base
import Foreign.CUDA.Driver.Stream ( Stream(..) )
import Foreign.CUDA.Internal.C2HS
import Foreign
import Foreign.C
import Control.Monad ( liftM )
import Data.ByteString.Char8 ( ByteString )
import qualified Data.ByteString.Char8 as B
import qualified Data.ByteString.Internal as B
{-# INLINEABLE launch #-}
launch :: (Executable) -> (Stream) -> IO ()
launch a1 a2 =
let {a1' = useExecutable a1} in
let {a2' = useStream a2} in
launch'_ a1' a2' >>= \res ->
checkStatus res >>
return ()
{-# LINE 69 "src/Foreign/CUDA/Driver/Graph/Exec.chs" #-}
{-# INLINEABLE instantiate #-}
instantiate :: Graph -> IO Executable
instantiate !g = do
let logSize = 2048
allocaArray logSize $ \p_elog -> do
(s, e, n) <- cuGraphInstantiate g p_elog logSize
case s of
Success -> return e
_ -> do
errLog <- peekCStringLen (p_elog, logSize)
cudaErrorIO (unlines [describe s, "phErrorNode = " ++ show n, errLog])
{-# INLINE cuGraphInstantiate #-}
cuGraphInstantiate :: (Graph) -> (CString) -> (Int) -> IO ((Status), (Executable), (Maybe Node))
cuGraphInstantiate a2 a4 a5 =
alloca $ \a1' ->
let {a2' = useGraph a2} in
alloca $ \a3' ->
let {a4' = castPtr a4} in
let {a5' = fromIntegral a5} in
cuGraphInstantiate'_ a1' a2' a3' a4' a5' >>= \res ->
let {res' = cToEnum res} in
peekExecutable a1'>>= \a1'' ->
peekErrNode a3'>>= \a3'' ->
return (res', a1'', a3'')
{-# LINE 105 "src/Foreign/CUDA/Driver/Graph/Exec.chs" #-}
where
peekExecutable = liftM Executable . peek
peekErrNode p = if p == nullPtr
then return Nothing
else liftM (Just . Node) (peek p)
{-# INLINEABLE destroy #-}
destroy :: (Executable) -> IO ()
destroy a1 =
let {a1' = useExecutable a1} in
destroy'_ a1' >>= \res ->
checkStatus res >>
return ()
{-# LINE 131 "src/Foreign/CUDA/Driver/Graph/Exec.chs" #-}
foreign import ccall unsafe "Foreign/CUDA/Driver/Graph/Exec.chs.h cuGraphLaunch"
launch'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt)))
foreign import ccall unsafe "Foreign/CUDA/Driver/Graph/Exec.chs.h cuGraphInstantiate"
cuGraphInstantiate'_ :: ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> ((C2HSImp.Ptr C2HSImp.CChar) -> (C2HSImp.CULong -> (IO C2HSImp.CInt))))))
foreign import ccall unsafe "Foreign/CUDA/Driver/Graph/Exec.chs.h cuGraphExecDestroy"
destroy'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt))