module TensorFlow.Internal.Raw where
import qualified Foreign.C.Types as C2HSImp
import qualified Foreign.Ptr as C2HSImp
import qualified Foreign.Storable as C2HSImp
import Foreign
import Foreign.C
data DataType = TF_FLOAT
| TF_DOUBLE
| TF_INT32
| TF_UINT8
| TF_INT16
| TF_INT8
| TF_STRING
| TF_COMPLEX64
| TF_COMPLEX
| TF_INT64
| TF_BOOL
| TF_QINT8
| TF_QUINT8
| TF_QINT32
| TF_BFLOAT16
| TF_QINT16
| TF_QUINT16
| TF_UINT16
| TF_COMPLEX128
| TF_HALF
| TF_RESOURCE
deriving (Show,Eq)
instance Enum DataType where
succ TF_FLOAT = TF_DOUBLE
succ TF_DOUBLE = TF_INT32
succ TF_INT32 = TF_UINT8
succ TF_UINT8 = TF_INT16
succ TF_INT16 = TF_INT8
succ TF_INT8 = TF_STRING
succ TF_STRING = TF_COMPLEX64
succ TF_COMPLEX64 = TF_INT64
succ TF_COMPLEX = TF_INT64
succ TF_INT64 = TF_BOOL
succ TF_BOOL = TF_QINT8
succ TF_QINT8 = TF_QUINT8
succ TF_QUINT8 = TF_QINT32
succ TF_QINT32 = TF_BFLOAT16
succ TF_BFLOAT16 = TF_QINT16
succ TF_QINT16 = TF_QUINT16
succ TF_QUINT16 = TF_UINT16
succ TF_UINT16 = TF_COMPLEX128
succ TF_COMPLEX128 = TF_HALF
succ TF_HALF = TF_RESOURCE
succ TF_RESOURCE = error "DataType.succ: TF_RESOURCE has no successor"
pred TF_DOUBLE = TF_FLOAT
pred TF_INT32 = TF_DOUBLE
pred TF_UINT8 = TF_INT32
pred TF_INT16 = TF_UINT8
pred TF_INT8 = TF_INT16
pred TF_STRING = TF_INT8
pred TF_COMPLEX64 = TF_STRING
pred TF_COMPLEX = TF_STRING
pred TF_INT64 = TF_COMPLEX64
pred TF_BOOL = TF_INT64
pred TF_QINT8 = TF_BOOL
pred TF_QUINT8 = TF_QINT8
pred TF_QINT32 = TF_QUINT8
pred TF_BFLOAT16 = TF_QINT32
pred TF_QINT16 = TF_BFLOAT16
pred TF_QUINT16 = TF_QINT16
pred TF_UINT16 = TF_QUINT16
pred TF_COMPLEX128 = TF_UINT16
pred TF_HALF = TF_COMPLEX128
pred TF_RESOURCE = TF_HALF
pred TF_FLOAT = error "DataType.pred: TF_FLOAT 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 TF_RESOURCE
fromEnum TF_FLOAT = 1
fromEnum TF_DOUBLE = 2
fromEnum TF_INT32 = 3
fromEnum TF_UINT8 = 4
fromEnum TF_INT16 = 5
fromEnum TF_INT8 = 6
fromEnum TF_STRING = 7
fromEnum TF_COMPLEX64 = 8
fromEnum TF_COMPLEX = 8
fromEnum TF_INT64 = 9
fromEnum TF_BOOL = 10
fromEnum TF_QINT8 = 11
fromEnum TF_QUINT8 = 12
fromEnum TF_QINT32 = 13
fromEnum TF_BFLOAT16 = 14
fromEnum TF_QINT16 = 15
fromEnum TF_QUINT16 = 16
fromEnum TF_UINT16 = 17
fromEnum TF_COMPLEX128 = 18
fromEnum TF_HALF = 19
fromEnum TF_RESOURCE = 20
toEnum 1 = TF_FLOAT
toEnum 2 = TF_DOUBLE
toEnum 3 = TF_INT32
toEnum 4 = TF_UINT8
toEnum 5 = TF_INT16
toEnum 6 = TF_INT8
toEnum 7 = TF_STRING
toEnum 8 = TF_COMPLEX64
toEnum 9 = TF_INT64
toEnum 10 = TF_BOOL
toEnum 11 = TF_QINT8
toEnum 12 = TF_QUINT8
toEnum 13 = TF_QINT32
toEnum 14 = TF_BFLOAT16
toEnum 15 = TF_QINT16
toEnum 16 = TF_QUINT16
toEnum 17 = TF_UINT16
toEnum 18 = TF_COMPLEX128
toEnum 19 = TF_HALF
toEnum 20 = TF_RESOURCE
toEnum unmatched = error ("DataType.toEnum: Cannot match " ++ show unmatched)
data Code = TF_OK
| TF_CANCELLED
| TF_UNKNOWN
| TF_INVALID_ARGUMENT
| TF_DEADLINE_EXCEEDED
| TF_NOT_FOUND
| TF_ALREADY_EXISTS
| TF_PERMISSION_DENIED
| TF_RESOURCE_EXHAUSTED
| TF_FAILED_PRECONDITION
| TF_ABORTED
| TF_OUT_OF_RANGE
| TF_UNIMPLEMENTED
| TF_INTERNAL
| TF_UNAVAILABLE
| TF_DATA_LOSS
| TF_UNAUTHENTICATED
deriving (Show,Eq)
instance Enum Code where
succ TF_OK = TF_CANCELLED
succ TF_CANCELLED = TF_UNKNOWN
succ TF_UNKNOWN = TF_INVALID_ARGUMENT
succ TF_INVALID_ARGUMENT = TF_DEADLINE_EXCEEDED
succ TF_DEADLINE_EXCEEDED = TF_NOT_FOUND
succ TF_NOT_FOUND = TF_ALREADY_EXISTS
succ TF_ALREADY_EXISTS = TF_PERMISSION_DENIED
succ TF_PERMISSION_DENIED = TF_RESOURCE_EXHAUSTED
succ TF_RESOURCE_EXHAUSTED = TF_FAILED_PRECONDITION
succ TF_FAILED_PRECONDITION = TF_ABORTED
succ TF_ABORTED = TF_OUT_OF_RANGE
succ TF_OUT_OF_RANGE = TF_UNIMPLEMENTED
succ TF_UNIMPLEMENTED = TF_INTERNAL
succ TF_INTERNAL = TF_UNAVAILABLE
succ TF_UNAVAILABLE = TF_DATA_LOSS
succ TF_DATA_LOSS = TF_UNAUTHENTICATED
succ TF_UNAUTHENTICATED = error "Code.succ: TF_UNAUTHENTICATED has no successor"
pred TF_CANCELLED = TF_OK
pred TF_UNKNOWN = TF_CANCELLED
pred TF_INVALID_ARGUMENT = TF_UNKNOWN
pred TF_DEADLINE_EXCEEDED = TF_INVALID_ARGUMENT
pred TF_NOT_FOUND = TF_DEADLINE_EXCEEDED
pred TF_ALREADY_EXISTS = TF_NOT_FOUND
pred TF_PERMISSION_DENIED = TF_ALREADY_EXISTS
pred TF_RESOURCE_EXHAUSTED = TF_PERMISSION_DENIED
pred TF_FAILED_PRECONDITION = TF_RESOURCE_EXHAUSTED
pred TF_ABORTED = TF_FAILED_PRECONDITION
pred TF_OUT_OF_RANGE = TF_ABORTED
pred TF_UNIMPLEMENTED = TF_OUT_OF_RANGE
pred TF_INTERNAL = TF_UNIMPLEMENTED
pred TF_UNAVAILABLE = TF_INTERNAL
pred TF_DATA_LOSS = TF_UNAVAILABLE
pred TF_UNAUTHENTICATED = TF_DATA_LOSS
pred TF_OK = error "Code.pred: TF_OK 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 TF_UNAUTHENTICATED
fromEnum TF_OK = 0
fromEnum TF_CANCELLED = 1
fromEnum TF_UNKNOWN = 2
fromEnum TF_INVALID_ARGUMENT = 3
fromEnum TF_DEADLINE_EXCEEDED = 4
fromEnum TF_NOT_FOUND = 5
fromEnum TF_ALREADY_EXISTS = 6
fromEnum TF_PERMISSION_DENIED = 7
fromEnum TF_RESOURCE_EXHAUSTED = 8
fromEnum TF_FAILED_PRECONDITION = 9
fromEnum TF_ABORTED = 10
fromEnum TF_OUT_OF_RANGE = 11
fromEnum TF_UNIMPLEMENTED = 12
fromEnum TF_INTERNAL = 13
fromEnum TF_UNAVAILABLE = 14
fromEnum TF_DATA_LOSS = 15
fromEnum TF_UNAUTHENTICATED = 16
toEnum 0 = TF_OK
toEnum 1 = TF_CANCELLED
toEnum 2 = TF_UNKNOWN
toEnum 3 = TF_INVALID_ARGUMENT
toEnum 4 = TF_DEADLINE_EXCEEDED
toEnum 5 = TF_NOT_FOUND
toEnum 6 = TF_ALREADY_EXISTS
toEnum 7 = TF_PERMISSION_DENIED
toEnum 8 = TF_RESOURCE_EXHAUSTED
toEnum 9 = TF_FAILED_PRECONDITION
toEnum 10 = TF_ABORTED
toEnum 11 = TF_OUT_OF_RANGE
toEnum 12 = TF_UNIMPLEMENTED
toEnum 13 = TF_INTERNAL
toEnum 14 = TF_UNAVAILABLE
toEnum 15 = TF_DATA_LOSS
toEnum 16 = TF_UNAUTHENTICATED
toEnum unmatched = error ("Code.toEnum: Cannot match " ++ show unmatched)
newtype Status = Status (C2HSImp.Ptr (Status))
newStatus :: IO Status
newStatus = tFNewStatus
deleteStatus :: Status -> IO ()
deleteStatus = tFDeleteStatus
setStatus :: Status -> Code -> CString -> IO ()
setStatus s c = tFSetStatus s (fromIntegral $ fromEnum c)
getCode :: Status -> IO Code
getCode s = toEnum . fromIntegral <$> tFGetCode s
message :: Status -> IO CString
message = tFMessage
data Buffer
type BufferPtr = C2HSImp.Ptr (Buffer)
getBufferData :: BufferPtr -> IO (Ptr ())
getBufferData = (\ptr -> do {C2HSImp.peekByteOff ptr 0 :: IO (C2HSImp.Ptr ())})
getBufferLength :: BufferPtr -> IO CULong
getBufferLength =(\ptr -> do {C2HSImp.peekByteOff ptr 8 :: IO C2HSImp.CULong})
newtype Tensor = Tensor (C2HSImp.Ptr (Tensor))
instance Storable Tensor where
sizeOf (Tensor t) = sizeOf t
alignment (Tensor t) = alignment t
peek p = fmap Tensor (peek (castPtr p))
poke p (Tensor t) = poke (castPtr p) t
type CInt64 = (C2HSImp.CLLong)
newTensor :: DataType
-> Ptr CInt64
-> CInt
-> Ptr ()
-> CULong
-> FunPtr (Ptr () -> CULong -> Ptr () -> IO ())
-> Ptr ()
-> IO Tensor
newTensor dt = tFNewTensor (fromIntegral $ fromEnum dt)
deleteTensor :: Tensor -> IO ()
deleteTensor = tFDeleteTensor
tensorType :: Tensor -> IO DataType
tensorType t = toEnum . fromIntegral <$> tFTensorType t
numDims :: Tensor -> IO CInt
numDims = tFNumDims
dim :: Tensor -> CInt -> IO CInt64
dim = tFDim
tensorByteSize :: Tensor -> IO CULong
tensorByteSize = tFTensorByteSize
tensorData :: Tensor -> IO (Ptr ())
tensorData = tFTensorData
newtype SessionOptions = SessionOptions (C2HSImp.Ptr (SessionOptions))
newSessionOptions :: IO SessionOptions
newSessionOptions = tFNewSessionOptions
setTarget :: SessionOptions -> CString -> IO ()
setTarget = tFSetTarget
setConfig :: SessionOptions -> Ptr () -> CULong -> Status -> IO ()
setConfig = tFSetConfig
deleteSessionOptions :: SessionOptions -> IO ()
deleteSessionOptions = tFDeleteSessionOptions
newtype Session = Session (C2HSImp.Ptr (Session))
newSession :: SessionOptions -> Status -> IO Session
newSession = tFNewDeprecatedSession
closeSession :: Session -> Status -> IO ()
closeSession = tFCloseDeprecatedSession
deleteSession :: Session -> Status -> IO ()
deleteSession = tFDeleteDeprecatedSession
extendGraph :: Session -> Ptr () -> CULong -> Status -> IO ()
extendGraph = tFExtendGraph
run :: Session
-> BufferPtr
-> Ptr CString -> Ptr Tensor -> CInt
-> Ptr CString -> Ptr Tensor -> CInt
-> Ptr CString -> CInt
-> BufferPtr
-> Status
-> IO ()
run = tFRun
type TensorDeallocFn = Ptr () -> CULong -> Ptr () -> IO ()
foreign import ccall "wrapper"
wrapTensorDealloc :: TensorDeallocFn -> IO (FunPtr TensorDeallocFn)
getAllOpList :: IO BufferPtr
getAllOpList = tFGetAllOpList
foreign import ccall "&TF_DeleteBuffer"
deleteBuffer :: FunPtr (BufferPtr -> IO ())
foreign import ccall safe "TensorFlow/Internal/Raw.chs.h TF_NewStatus"
tFNewStatus :: (IO (Status))
foreign import ccall safe "TensorFlow/Internal/Raw.chs.h TF_DeleteStatus"
tFDeleteStatus :: ((Status) -> (IO ()))
foreign import ccall safe "TensorFlow/Internal/Raw.chs.h TF_SetStatus"
tFSetStatus :: ((Status) -> (C2HSImp.CInt -> ((C2HSImp.Ptr C2HSImp.CChar) -> (IO ()))))
foreign import ccall safe "TensorFlow/Internal/Raw.chs.h TF_GetCode"
tFGetCode :: ((Status) -> (IO C2HSImp.CInt))
foreign import ccall safe "TensorFlow/Internal/Raw.chs.h TF_Message"
tFMessage :: ((Status) -> (IO (C2HSImp.Ptr C2HSImp.CChar)))
foreign import ccall safe "TensorFlow/Internal/Raw.chs.h TF_NewTensor"
tFNewTensor :: (C2HSImp.CInt -> ((C2HSImp.Ptr C2HSImp.CLLong) -> (C2HSImp.CInt -> ((C2HSImp.Ptr ()) -> (C2HSImp.CULong -> ((C2HSImp.FunPtr ((C2HSImp.Ptr ()) -> (C2HSImp.CULong -> ((C2HSImp.Ptr ()) -> (IO ()))))) -> ((C2HSImp.Ptr ()) -> (IO (Tensor)))))))))
foreign import ccall safe "TensorFlow/Internal/Raw.chs.h TF_DeleteTensor"
tFDeleteTensor :: ((Tensor) -> (IO ()))
foreign import ccall safe "TensorFlow/Internal/Raw.chs.h TF_TensorType"
tFTensorType :: ((Tensor) -> (IO C2HSImp.CInt))
foreign import ccall safe "TensorFlow/Internal/Raw.chs.h TF_NumDims"
tFNumDims :: ((Tensor) -> (IO C2HSImp.CInt))
foreign import ccall safe "TensorFlow/Internal/Raw.chs.h TF_Dim"
tFDim :: ((Tensor) -> (C2HSImp.CInt -> (IO C2HSImp.CLLong)))
foreign import ccall safe "TensorFlow/Internal/Raw.chs.h TF_TensorByteSize"
tFTensorByteSize :: ((Tensor) -> (IO C2HSImp.CULong))
foreign import ccall safe "TensorFlow/Internal/Raw.chs.h TF_TensorData"
tFTensorData :: ((Tensor) -> (IO (C2HSImp.Ptr ())))
foreign import ccall safe "TensorFlow/Internal/Raw.chs.h TF_NewSessionOptions"
tFNewSessionOptions :: (IO (SessionOptions))
foreign import ccall safe "TensorFlow/Internal/Raw.chs.h TF_SetTarget"
tFSetTarget :: ((SessionOptions) -> ((C2HSImp.Ptr C2HSImp.CChar) -> (IO ())))
foreign import ccall safe "TensorFlow/Internal/Raw.chs.h TF_SetConfig"
tFSetConfig :: ((SessionOptions) -> ((C2HSImp.Ptr ()) -> (C2HSImp.CULong -> ((Status) -> (IO ())))))
foreign import ccall safe "TensorFlow/Internal/Raw.chs.h TF_DeleteSessionOptions"
tFDeleteSessionOptions :: ((SessionOptions) -> (IO ()))
foreign import ccall safe "TensorFlow/Internal/Raw.chs.h TF_NewDeprecatedSession"
tFNewDeprecatedSession :: ((SessionOptions) -> ((Status) -> (IO (Session))))
foreign import ccall safe "TensorFlow/Internal/Raw.chs.h TF_CloseDeprecatedSession"
tFCloseDeprecatedSession :: ((Session) -> ((Status) -> (IO ())))
foreign import ccall safe "TensorFlow/Internal/Raw.chs.h TF_DeleteDeprecatedSession"
tFDeleteDeprecatedSession :: ((Session) -> ((Status) -> (IO ())))
foreign import ccall safe "TensorFlow/Internal/Raw.chs.h TF_ExtendGraph"
tFExtendGraph :: ((Session) -> ((C2HSImp.Ptr ()) -> (C2HSImp.CULong -> ((Status) -> (IO ())))))
foreign import ccall safe "TensorFlow/Internal/Raw.chs.h TF_Run"
tFRun :: ((Session) -> ((BufferPtr) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> ((C2HSImp.Ptr (Tensor)) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> ((C2HSImp.Ptr (Tensor)) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (C2HSImp.CInt -> ((BufferPtr) -> ((Status) -> (IO ())))))))))))))
foreign import ccall safe "TensorFlow/Internal/Raw.chs.h TF_GetAllOpList"
tFGetAllOpList :: (IO (BufferPtr))