{-# LINE 1 "src/Foreign/CUDA/Driver/Graph/Capture.chs" #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE EmptyDataDecls #-}
{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE EmptyCase #-}
module Foreign.CUDA.Driver.Graph.Capture (
Status(..), Mode(..),
start, stop, status, info, mode,
) where
import qualified Foreign.C.Types as C2HSImp
import qualified Foreign.Ptr as C2HSImp
{-# LINE 27 "src/Foreign/CUDA/Driver/Graph/Capture.chs" #-}
import Foreign.CUDA.Driver.Error hiding ( Status )
import Foreign.CUDA.Driver.Graph.Base
import Foreign.CUDA.Driver.Stream
import Foreign.CUDA.Internal.C2HS
import Control.Monad ( liftM )
import Foreign
import Foreign.C
data Status = None
| Active
| Invalidated
deriving (Eq,Show,Bounded)
instance Enum Status where
succ None = Active
succ Active = Invalidated
succ Invalidated = error "Status.succ: Invalidated has no successor"
pred Active = None
pred Invalidated = Active
pred None = error "Status.pred: None has no predecessor"
enumFromTo from to = go from
where
end = fromEnum to
go v = case compare (fromEnum v) end of
LT -> v : go (succ v)
EQ -> [v]
GT -> []
enumFrom from = enumFromTo from Invalidated
fromEnum None = 0
fromEnum Active = 1
fromEnum Invalidated = 2
toEnum 0 = None
toEnum 1 = Active
toEnum 2 = Invalidated
toEnum unmatched = error ("Status.toEnum: Cannot match " ++ show unmatched)
{-# LINE 53 "src/Foreign/CUDA/Driver/Graph/Capture.chs" #-}
data Mode
instance Enum Mode where
toEnum x = error ("Mode.toEnum: Cannot match " ++ show x)
fromEnum x = case x of {}
start :: Stream -> Mode -> IO ()
start s _ = cuStreamBeginCapture s
where
cuStreamBeginCapture :: (Stream) -> IO ()
cuStreamBeginCapture a1 =
let {a1' = useStream a1} in
cuStreamBeginCapture'_ a1' >>= \res ->
checkStatus res >>
return ()
{-# LINE 100 "src/Foreign/CUDA/Driver/Graph/Capture.chs" #-}
stop :: (Stream) -> IO ((Graph))
stop a1 =
let {a1' = useStream a1} in
alloca $ \a2' ->
stop'_ a1' a2' >>= \res ->
checkStatus res >>
peekGraph a2'>>= \a2'' ->
return (a2'')
{-# LINE 120 "src/Foreign/CUDA/Driver/Graph/Capture.chs" #-}
status :: (Stream) -> IO ((Status))
status a1 =
let {a1' = useStream a1} in
alloca $ \a2' ->
status'_ a1' a2' >>= \res ->
checkStatus res >>
peekEnum a2'>>= \a2'' ->
return (a2'')
{-# LINE 140 "src/Foreign/CUDA/Driver/Graph/Capture.chs" #-}
info :: Stream -> IO (Status, Int64)
info = requireSDK 'info 10.1
mode :: Mode -> IO Mode
mode = requireSDK 'mode 10.1
{-# INLINE peekGraph #-}
peekGraph :: Ptr ((C2HSImp.Ptr ())) -> IO Graph
peekGraph = liftM Graph . peek
foreign import ccall unsafe "Foreign/CUDA/Driver/Graph/Capture.chs.h cuStreamBeginCapture"
cuStreamBeginCapture'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt))
foreign import ccall unsafe "Foreign/CUDA/Driver/Graph/Capture.chs.h cuStreamEndCapture"
stop'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CInt)))
foreign import ccall unsafe "Foreign/CUDA/Driver/Graph/Capture.chs.h cuStreamIsCapturing"
status'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr C2HSImp.CInt) -> (IO C2HSImp.CInt)))