   , unsafeCoerce `a'
   ,              `Int'         } -> `Status' cToEnum #}
 
+
+-- |
+-- Return the device pointer associated with a mapped, pinned host buffer, which
+-- was allocated with the DEVICE_MAPPED option.
+--
+-- Currently, no options are supported and this must be empty.
+--
+getDevicePtr :: [AllocFlag] -> HostPtr a -> IO (Either String (DevicePtr a))
+getDevicePtr flags hptr = withHostPtr hptr $ \hp -> (resultIfOk `fmap` cuMemHostGetDevicePointer hp flags)
+
+{# fun unsafe cuMemHostGetDevicePointer
+  { alloca-         `DevicePtr a' dptr*
+  , castPtr         `Ptr a'
+  , combineBitMasks `[AllocFlag]'       } -> `Status' cToEnum #}
+  where dptr = liftM DevicePtr . peekIntConv
+


module Foreign.CUDA.Driver.Marshal
  (
    DevicePtr, HostPtr,
    malloc, free, mallocHost, freeHost,
    peekArray, peekArrayAsync, pokeArray, pokeArrayAsync, memset
  )
  where


import Control.Monad                            (liftM)
import Unsafe.Coerce

#c
typedef enum CUmemhostalloc_option_enum {
    CU_MEMHOSTALLOC_OPTION_PORTABLE       = CU_MEMHOSTALLOC_PORTABLE,
    CU_MEMHOSTALLOC_OPTION_DEVICE_MAPPED  = CU_MEMHOSTALLOC_DEVICEMAP,
    CU_MEMHOSTALLOC_OPTION_WRITE_COMBINED = CU_MEMHOSTALLOC_WRITECOMBINED
} CUmemhostalloc_option;
#endc

--------------------------------------------------------------------------------
-- Data Types
--------------------------------------------------------------------------------
