 -- System
 import Foreign
 import Foreign.C
-import Foreign.ForeignPtr
 import Control.Monad                    (liftM)
 
 

-- Create a new CUDA context and associate it with the calling thread
--
create :: Device -> [ContextFlag] -> IO (Either String Context)
create dev flags =
  newContext              >>= \ctx -> withContext ctx $ \p ->
  cuCtxCreate p flags dev >>= \rv  ->
    return $ case nothingIfOk rv of
      Nothing -> Right ctx
      Just e  -> Left  e

{# fun unsafe cuCtxCreate
  { id              `Ptr Context'
  , combineBitMasks `[ContextFlag]'
  , useDevice       `Device'         } -> `Status' cToEnum #}


-- |

-- context must be floating (via `pop'), i.e. not attached to any thread.
--
push :: Context -> IO (Maybe String)
push ctx = nothingIfOk `fmap` cuCtxPushCurrent ctx

{# fun unsafe cuCtxPushCurrent
  { useContext `Context' } -> `Status' cToEnum #}


-- |
