{-# LINE 1 "src/Foreign/CUDA/Driver/Stream.chs" #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE EmptyDataDecls #-}
{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE TemplateHaskell #-}
module Foreign.CUDA.Driver.Stream (
Stream(..), StreamFlag, StreamWriteFlag(..), StreamWaitFlag(..),
create, createWithPriority, destroy, finished, block, getPriority,
write, wait,
defaultStream,
) where
import qualified Foreign.C.Types as C2HSImp
import qualified Foreign.Ptr as C2HSImp
{-# LINE 27 "src/Foreign/CUDA/Driver/Stream.chs" #-}
import Foreign.CUDA.Types
import Foreign.CUDA.Driver.Error
import Foreign.CUDA.Internal.C2HS
import Foreign
import Foreign.C
import Control.Monad ( liftM )
import Control.Exception ( throwIO )
{-# INLINEABLE create #-}
create :: [StreamFlag] -> IO Stream
create !flags = resultIfOk =<< cuStreamCreate flags
{-# INLINE cuStreamCreate #-}
cuStreamCreate :: ([StreamFlag]) -> IO ((Status), (Stream))
cuStreamCreate a2 =
alloca $ \a1' ->
let {a2' = combineBitMasks a2} in
cuStreamCreate'_ a1' a2' >>= \res ->
let {res' = cToEnum res} in
peekStream a1'>>= \a1'' ->
return (res', a1'')
{-# LINE 57 "src/Foreign/CUDA/Driver/Stream.chs" #-}
where
peekStream = liftM Stream . peek
{-# INLINEABLE createWithPriority #-}
createWithPriority :: StreamPriority -> [StreamFlag] -> IO Stream
createWithPriority !priority !flags = resultIfOk =<< cuStreamCreateWithPriority flags priority
{-# INLINE cuStreamCreateWithPriority #-}
cuStreamCreateWithPriority :: ([StreamFlag]) -> (StreamPriority) -> IO ((Status), (Stream))
cuStreamCreateWithPriority a2 a3 =
alloca $ \a1' ->
let {a2' = combineBitMasks a2} in
let {a3' = cIntConv a3} in
cuStreamCreateWithPriority'_ a1' a2' a3' >>= \res ->
let {res' = cToEnum res} in
peekStream a1'>>= \a1'' ->
return (res', a1'')
{-# LINE 91 "src/Foreign/CUDA/Driver/Stream.chs" #-}
where
peekStream = liftM Stream . peek
{-# INLINEABLE destroy #-}
destroy :: Stream -> IO ()
destroy !st = nothingIfOk =<< cuStreamDestroy st
{-# INLINE cuStreamDestroy #-}
cuStreamDestroy :: (Stream) -> IO ((Status))
cuStreamDestroy a1 =
let {a1' = useStream a1} in
cuStreamDestroy'_ a1' >>= \res ->
let {res' = cToEnum res} in
return (res')
{-# LINE 111 "src/Foreign/CUDA/Driver/Stream.chs" #-}
{-# INLINEABLE finished #-}
finished :: Stream -> IO Bool
finished !st =
cuStreamQuery st >>= \rv ->
case rv of
Success -> return True
NotReady -> return False
_ -> throwIO (ExitCode rv)
{-# INLINE cuStreamQuery #-}
cuStreamQuery :: (Stream) -> IO ((Status))
cuStreamQuery a1 =
let {a1' = useStream a1} in
cuStreamQuery'_ a1' >>= \res ->
let {res' = cToEnum res} in
return (res')
{-# LINE 130 "src/Foreign/CUDA/Driver/Stream.chs" #-}
{-# INLINEABLE block #-}
block :: Stream -> IO ()
block !st = nothingIfOk =<< cuStreamSynchronize st
{-# INLINE cuStreamSynchronize #-}
cuStreamSynchronize :: (Stream) -> IO ((Status))
cuStreamSynchronize a1 =
let {a1' = useStream a1} in
cuStreamSynchronize'_ a1' >>= \res ->
let {res' = cToEnum res} in
return (res')
{-# LINE 144 "src/Foreign/CUDA/Driver/Stream.chs" #-}
{-# INLINEABLE getPriority #-}
getPriority :: Stream -> IO StreamPriority
getPriority !st = resultIfOk =<< cuStreamGetPriority st
{-# INLINE cuStreamGetPriority #-}
cuStreamGetPriority :: (Stream) -> IO ((Status), (StreamPriority))
cuStreamGetPriority a1 =
let {a1' = useStream a1} in
alloca $ \a2' ->
cuStreamGetPriority'_ a1' a2' >>= \res ->
let {res' = cToEnum res} in
peekIntConv a2'>>= \a2'' ->
return (res', a2'')
{-# LINE 167 "src/Foreign/CUDA/Driver/Stream.chs" #-}
data StreamWriteFlag = WriteValueDefault
| WriteValueNoMemoryBarrier
deriving (Eq,Show,Bounded)
instance Enum StreamWriteFlag where
succ WriteValueDefault = WriteValueNoMemoryBarrier
succ WriteValueNoMemoryBarrier = error "StreamWriteFlag.succ: WriteValueNoMemoryBarrier has no successor"
pred WriteValueNoMemoryBarrier = WriteValueDefault
pred WriteValueDefault = error "StreamWriteFlag.pred: WriteValueDefault 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 WriteValueNoMemoryBarrier
fromEnum WriteValueDefault = 0
fromEnum WriteValueNoMemoryBarrier = 1
toEnum 0 = WriteValueDefault
toEnum 1 = WriteValueNoMemoryBarrier
toEnum unmatched = error ("StreamWriteFlag.toEnum: Cannot match " ++ show unmatched)
{-# LINE 176 "src/Foreign/CUDA/Driver/Stream.chs" #-}
data StreamWaitFlag = WaitValueGeq
| WaitValueEq
| WaitValueAnd
| WaitValueFlush
deriving (Eq,Show,Bounded)
instance Enum StreamWaitFlag where
succ WaitValueGeq = WaitValueEq
succ WaitValueEq = WaitValueAnd
succ WaitValueAnd = WaitValueFlush
succ WaitValueFlush = error "StreamWaitFlag.succ: WaitValueFlush has no successor"
pred WaitValueEq = WaitValueGeq
pred WaitValueAnd = WaitValueEq
pred WaitValueFlush = WaitValueAnd
pred WaitValueGeq = error "StreamWaitFlag.pred: WaitValueGeq 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 WaitValueFlush
fromEnum WaitValueGeq = 0
fromEnum WaitValueEq = 1
fromEnum WaitValueAnd = 2
fromEnum WaitValueFlush = 1073741824
toEnum 0 = WaitValueGeq
toEnum 1 = WaitValueEq
toEnum 2 = WaitValueAnd
toEnum 1073741824 = WaitValueFlush
toEnum unmatched = error ("StreamWaitFlag.toEnum: Cannot match " ++ show unmatched)
{-# LINE 181 "src/Foreign/CUDA/Driver/Stream.chs" #-}
{-# INLINEABLE write #-}
write :: DevicePtr Int32 -> Int32 -> Stream -> [StreamWriteFlag] -> IO ()
write ptr val stream flags = nothingIfOk =<< cuStreamWriteValue32 stream ptr val flags
{-# INLINE cuStreamWriteValue32 #-}
cuStreamWriteValue32 :: (Stream) -> (DevicePtr Int32) -> (Int32) -> ([StreamWriteFlag]) -> IO ((Status))
cuStreamWriteValue32 a1 a2 a3 a4 =
let {a1' = useStream a1} in
let {a2' = useDeviceHandle a2} in
let {a3' = fromIntegral a3} in
let {a4' = combineBitMasks a4} in
cuStreamWriteValue32'_ a1' a2' a3' a4' >>= \res ->
let {res' = cToEnum res} in
return (res')
{-# LINE 206 "src/Foreign/CUDA/Driver/Stream.chs" #-}
where
useDeviceHandle = fromIntegral . ptrToIntPtr . useDevicePtr
{-# INLINEABLE wait #-}
wait :: DevicePtr Int32 -> Int32 -> Stream -> [StreamWaitFlag] -> IO ()
wait ptr val stream flags = nothingIfOk =<< cuStreamWaitValue32 stream ptr val flags
{-# INLINE cuStreamWaitValue32 #-}
cuStreamWaitValue32 :: (Stream) -> (DevicePtr Int32) -> (Int32) -> ([StreamWaitFlag]) -> IO ((Status))
cuStreamWaitValue32 a1 a2 a3 a4 =
let {a1' = useStream a1} in
let {a2' = useDeviceHandle a2} in
let {a3' = fromIntegral a3} in
let {a4' = combineBitMasks a4} in
cuStreamWaitValue32'_ a1' a2' a3' a4' >>= \res ->
let {res' = cToEnum res} in
return (res')
{-# LINE 232 "src/Foreign/CUDA/Driver/Stream.chs" #-}
where
useDeviceHandle = fromIntegral . ptrToIntPtr . useDevicePtr
foreign import ccall unsafe "Foreign/CUDA/Driver/Stream.chs.h cuStreamCreate"
cuStreamCreate'_ :: ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (C2HSImp.CUInt -> (IO C2HSImp.CInt)))
foreign import ccall unsafe "Foreign/CUDA/Driver/Stream.chs.h cuStreamCreateWithPriority"
cuStreamCreateWithPriority'_ :: ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (C2HSImp.CUInt -> (C2HSImp.CInt -> (IO C2HSImp.CInt))))
foreign import ccall unsafe "Foreign/CUDA/Driver/Stream.chs.h cuStreamDestroy"
cuStreamDestroy'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt))
foreign import ccall unsafe "Foreign/CUDA/Driver/Stream.chs.h cuStreamQuery"
cuStreamQuery'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt))
foreign import ccall safe "Foreign/CUDA/Driver/Stream.chs.h cuStreamSynchronize"
cuStreamSynchronize'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt))
foreign import ccall unsafe "Foreign/CUDA/Driver/Stream.chs.h cuStreamGetPriority"
cuStreamGetPriority'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr C2HSImp.CInt) -> (IO C2HSImp.CInt)))
foreign import ccall unsafe "Foreign/CUDA/Driver/Stream.chs.h cuStreamWriteValue32"
cuStreamWriteValue32'_ :: ((C2HSImp.Ptr ()) -> (C2HSImp.CULLong -> (C2HSImp.CUInt -> (C2HSImp.CUInt -> (IO C2HSImp.CInt)))))
foreign import ccall unsafe "Foreign/CUDA/Driver/Stream.chs.h cuStreamWaitValue32"
cuStreamWaitValue32'_ :: ((C2HSImp.Ptr ()) -> (C2HSImp.CULLong -> (C2HSImp.CUInt -> (C2HSImp.CUInt -> (IO C2HSImp.CInt)))))