-- GENERATED by C->Haskell Compiler, version 0.28.2 Switcheroo, 1 April 2016 (Haskell)
-- Edit the ORIGNAL .chs file instead!


{-# LINE 1 "src/Foreign/CUDA/Driver/Profiler.chs" #-}
{-# LANGUAGE ForeignFunctionInterface #-}
--------------------------------------------------------------------------------
-- |
-- Module    : Foreign.CUDA.Driver.Profiler
-- Copyright : [2009..2017] Trevor L. McDonell
-- License   : BSD
--
-- Profiler control for low-level driver interface
--
--------------------------------------------------------------------------------

module Foreign.CUDA.Driver.Profiler (

  OutputMode(..),
  initialise,
  start, stop,

) where
import qualified Foreign.C.String as C2HSImp
import qualified Foreign.C.Types as C2HSImp
import qualified Foreign.Ptr as C2HSImp





{-# LINE 21 "src/Foreign/CUDA/Driver/Profiler.chs" #-}


-- friends
import Foreign.CUDA.Driver.Error
import Foreign.CUDA.Internal.C2HS

-- system
import Foreign
import Foreign.C


-- | Profiler output mode
--
data OutputMode = KeyValuePair
                | CSV
  deriving (Eq,Show)
instance Enum OutputMode where
  succ KeyValuePair = CSV
  succ CSV = error "OutputMode.succ: CSV has no successor"

  pred CSV = KeyValuePair
  pred KeyValuePair = error "OutputMode.pred: KeyValuePair 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 CSV

  fromEnum KeyValuePair = 0
  fromEnum CSV = 1

  toEnum 0 = KeyValuePair
  toEnum 1 = CSV
  toEnum unmatched = error ("OutputMode.toEnum: Cannot match " ++ show unmatched)

{-# LINE 37 "src/Foreign/CUDA/Driver/Profiler.chs" #-}



-- | Initialise the CUDA profiler.
--
-- The configuration file is used to specify profiling options and profiling
-- counters. Refer to the "Compute Command Line Profiler User Guide" for
-- supported profiler options and counters.
--
-- Note that the CUDA profiler can not be initialised with this function if
-- another profiling tool is already active.
--
-- <http://docs.nvidia.com/cuda/cuda-driver-api/group__CUDA__PROFILER.html#group__CUDA__PROFILER>
--
{-# INLINEABLE initialise #-}
initialise
    :: FilePath     -- ^ configuration file that itemises which counters and/or options to profile
    -> FilePath     -- ^ output file where profiling results will be stored
    -> OutputMode
    -> IO ()
initialise config output mode
  = nothingIfOk =<< cuProfilerInitialize config output mode

{-# INLINE cuProfilerInitialize #-}
cuProfilerInitialize :: (String) -> (String) -> (OutputMode) -> IO ((Status))
cuProfilerInitialize a1 a2 a3 =
  C2HSImp.withCString a1 $ \a1' -> 
  C2HSImp.withCString a2 $ \a2' -> 
  let {a3' = cFromEnum a3} in 
  cuProfilerInitialize'_ a1' a2' a3' >>= \res ->
  let {res' = cToEnum res} in
  return (res')

{-# LINE 66 "src/Foreign/CUDA/Driver/Profiler.chs" #-}



-- | Begin profiling collection by the active profiling tool for the current
-- context. If profiling is already enabled, then this has no effect.
--
-- 'start' and 'stop' can be used to programatically control profiling
-- granularity, by allowing profiling to be done only on selected pieces of
-- code.
--
-- <http://docs.nvidia.com/cuda/cuda-driver-api/group__CUDA__PROFILER.html#group__CUDA__PROFILER_1g8a5314de2292c2efac83ac7fcfa9190e>
--
{-# INLINEABLE start #-}
start :: IO ()
start = nothingIfOk =<< cuProfilerStart

{-# INLINE cuProfilerStart #-}
cuProfilerStart :: IO ((Status))
cuProfilerStart =
  cuProfilerStart'_ >>= \res ->
  let {res' = cToEnum res} in
  return (res')

{-# LINE 84 "src/Foreign/CUDA/Driver/Profiler.chs" #-}



-- | Stop profiling collection by the active profiling tool for the current
-- context, and force all pending profiler events to be written to the output
-- file. If profiling is already inactive, this has no effect.
--
-- <http://docs.nvidia.com/cuda/cuda-driver-api/group__CUDA__PROFILER.html#group__CUDA__PROFILER_1g4d8edef6174fd90165e6ac838f320a5f>
--
{-# INLINEABLE stop #-}
stop :: IO ()
stop = nothingIfOk =<< cuProfilerStop

{-# INLINE cuProfilerStop #-}
cuProfilerStop :: IO ((Status))
cuProfilerStop =
  cuProfilerStop'_ >>= \res ->
  let {res' = cToEnum res} in
  return (res')

{-# LINE 99 "src/Foreign/CUDA/Driver/Profiler.chs" #-}



foreign import ccall unsafe "Foreign/CUDA/Driver/Profiler.chs.h cuProfilerInitialize"
  cuProfilerInitialize'_ :: ((C2HSImp.Ptr C2HSImp.CChar) -> ((C2HSImp.Ptr C2HSImp.CChar) -> (C2HSImp.CInt -> (IO C2HSImp.CInt))))

foreign import ccall unsafe "Foreign/CUDA/Driver/Profiler.chs.h cuProfilerStart"
  cuProfilerStart'_ :: (IO C2HSImp.CInt)

foreign import ccall unsafe "Foreign/CUDA/Driver/Profiler.chs.h cuProfilerStop"
  cuProfilerStop'_ :: (IO C2HSImp.CInt)