 -- a given value
 --
 allocaBytesMemset :: Int64 -> Int -> (DevicePtr a -> IO b) -> IO b
-allocaBytesMemset bytes symbol f =
-    allocaBytes bytes $ \dptr ->
-    memset dptr bytes symbol >>= \rv ->
-      case rv of
-        Nothing -> f dptr
-        Just e  -> error e
+allocaBytesMemset bytes symbol action =
+  allocaBytes bytes $ \dptr ->
+  memset dptr bytes symbol  >>
+  action dptr
 
 
 --------------------------------------------------------------------------------

-- Allocate the specified number of bytes in linear memory on the device. The
-- memory is suitably aligned for any kind of variable, and is not cleared.
--
malloc       :: Int64 -> IO (Either String (DevicePtr a))
malloc bytes =  do
    (rv,ptr) <- cudaMalloc bytes
    case rv of
        Success -> Right `fmap` newDevicePtr (castPtr ptr)
        _       -> return . Left . describe $ rv

{# fun unsafe cudaMalloc
    { alloca'-  `Ptr ()' peek'* ,
      cIntConv  `Int64'         } -> `Status' cToEnum #}
    where alloca' = F.alloca
          peek'   = F.peek


-- |

         -> (Int64, Int64)              -- ^ The (width,height) of the matrix in bytes
         -> Int64                       -- ^ The allocation pitch, as returned by 'malloc2D'
         -> Int                         -- ^ Value to set for each byte
         -> IO ()
memset2D ptr (width,height) pitch symbol =
  nothingIfOk =<< cudaMemset2D ptr pitch symbol width height

{# fun unsafe cudaMemset2D
  { withDevPtrCast* `DevicePtr a'
  , cIntConv        `Int64'
  ,                 `Int'
  , cIntConv        `Int64'
  , cIntConv        `Int64'       } -> `Status' cToEnum #}
  where
    withDevPtrCast = withDevicePtr . castDevicePtr


-- |
