OpenCL 1.0.2.2 → 1.0.2.3
raw patch · 4 files changed
+37/−36 lines, 4 files
Files
- OpenCL.cabal +8/−7
- README.org +16/−20
- src/System/GPU/OpenCL/Program.chs +8/−5
- src/System/GPU/OpenCL/Types.chs +5/−4
OpenCL.cabal view
@@ -1,9 +1,9 @@ Name: OpenCL-Version: 1.0.2.2+Version: 1.0.2.3 License: BSD3 License-File: LICENSE Author: Luis Cabellos-Copyright: (c) 2011 Luis Cabellos+Copyright: (c) 2011 Luis Cabellos, at The Institute of Physics of Cantabria (IFCA) Category: GPU, FFI, Graphics Build-Type: Simple Stability: Experimental@@ -15,10 +15,10 @@ Tested-With: GHC Description: Haskell FFI binding to OpenCL library. It includes high-level wrappers to- help development. Based on OpenCLRaw package.+ help development. Based on the OpenCLRaw package. .- Most of the functions can throw a 'CLError' Exception. Using the module- 'Control.Exception' helps to work with this package Exceptions.+ Most of the functions can throw a 'CLError' exception. Using the module+ 'Control.Exception' helps to work with this package's exceptions. Extra-source-files: README.org examples/example01.hs@@ -46,12 +46,13 @@ cpp-options: "-DCALLCONV=stdcall" else cpp-options: "-DCALLCONV=ccall"- extra-libraries: OpenCL + cpp-options: -I include+ source-repository this type: git location: https://zhensydow@github.com/zhensydow/opencl.git- tag: 1.0.2.2+ tag: 1.0.2.3 branch: master source-repository head
README.org view
@@ -1,37 +1,33 @@-* Introduction-OpenCL highlevel wrapper for Haskell.--Based on Jeff Heard OpenCLRaw.+#+STARTUP: showall+* OpenCL+ A high-level OpenCL library for Haskell. -* Install the package+ Based on the [[http://hackage.haskell.org/package/OpenCLRaw][OpenCLRaw]] package by J.R. Heard. - Requisite: c2hs installed.+** Installation+ *Requirements:* [[http://hackage.haskell.org/package/c2hs][c2hs]] must be installed. (Try ~cabal install c2hs~.) - In order to install the package. You need the CL/cl.h include file in a knowed- path. With the usual commands to install as a user library:+ With the usual commands to install as a user library: - : runhaskell Setup configure --user- : runhaskell Setup build- : runhaskell Setup install+ : cabal install --user - The programs that use the library, need to link against OpenCL+ Programs using the library must link against OpenCL; for example, by+ passing ~-lOpenCL~ to GHC. ** Optional Requisites- Some OpenCL libraries required also numa libs. E.g, on Ubuntu 11.04:- - : install libnuma1 libnuma-dev+ Some OpenCL libraries require additional NUMA libraries. For instance,+ on Ubuntu 11.04: + : sudo apt-get install libnuma1 libnuma-dev+ ** Example- There is an simple working example in the examples folder. You can create an executable using: : ghc --make -lOpenCL examples/example01.hs -** Executing on ghci+** Using ghci - It's possible to execute the command line interface of ghc linking with- OpenCL, e.g:+ It's possible to use GHCi with OpenCL, e.g.: : ghci -lOpenCL examples/example01.hs-
src/System/GPU/OpenCL/Program.chs view
@@ -183,17 +183,20 @@ -} clCreateProgramWithBinary :: CLContext -> [CLDeviceID] -> [[Word8]] -> IO (CLProgram, [CLError])-clCreateProgramWithBinary ctx devs bins = wrapPError $ \perr -> do withArray-devs $ \pdevs -> do withArray lbins $ \plbins -> do buffs <- forM bins $ \bs ->-do buff <- mallocArray (length bs) :: IO (Ptr Word8) pokeArray buff bs return-buff+clCreateProgramWithBinary ctx devs bins = wrapPError $ \perr ->+ withArray devs $ \pdevs ->+ withArray lbins $ \plbins -> do+ buffs <- forM bins $ \bs -> do+ buff <- mallocArray (length bs) :: IO (Ptr Word8)+ pokeArray buff bs+ return buff ret <- withArray buffs $ \(pbuffs :: Ptr (Ptr Word8)) -> do allocaArray ndevs $ \(perrs :: Ptr CLint) -> do prog <- raw_clCreateProgramWithBinary ctx (fromIntegral ndevs) pdevs plbins pbuffs perrs perr errs <- peekArray ndevs perrs return (prog, map getEnumCL errs)- + mapM_ free buffs return ret
src/System/GPU/OpenCL/Types.chs view
@@ -58,7 +58,8 @@ import Foreign.C.Types import Data.List( foldl' ) import Data.Typeable( Typeable(..) )-import Control.Exception( Exception(..), throw )+import Control.Applicative( (<$>) )+import Control.Exception( Exception(..), throwIO ) #include <CL/cl.h> @@ -322,15 +323,15 @@ instance Exception CLError throwCLError :: CLint -> IO a-throwCLError = throw . (getEnumCL :: CLint -> CLError)+throwCLError = throwIO . (getEnumCL :: CLint -> CLError) wrapPError :: (Ptr CLint -> IO a) -> IO a wrapPError f = alloca $ \perr -> do v <- f perr- errcode <- peek perr >>= return . getEnumCL+ errcode <- getEnumCL <$> peek perr if errcode == CL_SUCCESS then return v- else throw errcode+ else throwIO errcode wrapCheckSuccess :: IO CLint -> IO Bool wrapCheckSuccess f = f >>= return . (==CL_SUCCESS) . getEnumCL