 getPtr :: Module -> String -> IO (DevicePtr a, Int)
 getPtr mdl name = do
   (status,dptr,bytes) <- cuModuleGetGlobal mdl name
-  resultIfOk (status,(dptr,bytes))
+  resultIfFound "global" name (status,(dptr,bytes))
 
 {# fun unsafe cuModuleGetGlobal
   { alloca-      `DevicePtr a' peekDeviceHandle*

-- Return a handle to a texture reference
--
getTex :: Module -> String -> IO Texture
getTex mdl name = resultIfOk =<< cuModuleGetTexRef mdl name

{# fun unsafe cuModuleGetTexRef
  { alloca-      `Texture' peekTex*

-- Internal
--------------------------------------------------------------------------------

resultIfFound :: String -> String -> (Status, a) -> IO a
resultIfFound kind name (status,result) =
  case status of
       Success  -> return result
       NotFound -> cudaError (kind ++ ' ' : describe status ++ ": " ++ name)
       _        -> throwIO (ExitCode status)

peekMod :: Ptr {# type CUmodule #} -> IO Module
peekMod = liftM Module . peek

