 -- 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 ()))
+malloc       :: Int64 -> IO (Either String (DevicePtr a))
 malloc bytes = do
     (rv,ptr) <- cudaMalloc bytes
     case rv of
-        Success -> Right `fmap` newDevicePtr ptr
+        Success -> Right `fmap` newDevicePtr (castPtr ptr)
         _       -> return . Left . describe $ rv
 
 {# fun unsafe cudaMalloc

-- requirements are met. The actual allocation pitch is returned
--
malloc3D :: (Int64,Int64,Int64)         -- ^ allocation (width,height,depth) in bytes
         -> IO (Either String (DevicePtr (),Int64))
malloc3D = moduleErr "malloc3D" "not implemented yet"



memset2D ptr (width,height) pitch symbol = nothingIfOk `fmap` cudaMemset2D ptr pitch symbol width height

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


-- |
-- Initialise the elements of a 3D array to a given value
--
memset3D :: DevicePtr a                 -- ^ The device memory
         -> (Int64,Int64,Int64)         -- ^ The (width,height,depth) of the array in bytes
         -> Int64                       -- ^ The allocation pitch, as returned by 'malloc3D'
         -> Int                         -- ^ Value to set for each byte
