Skip to content
This repository has been archived by the owner on Jun 28, 2022. It is now read-only.

Fixing warnings and adding compatibility with cabal v2 builds. #50

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
# Build System #
################
dist/
*_stub.[cho]
dist
dist-*
cabal-dev
*.o
*.hi
*.chi
*.chs.h
*.dyn_o
*.dyn_hi
.hpc
.hsenv
.cabal-sandbox/
cabal.sandbox.config
*.prof
*.aux
*.hp
*.eventlog
.stack-work/
cabal.project.local
cabal.project.local~
.HTF/
.ghc.environment.*
8 changes: 4 additions & 4 deletions OpenCL.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Synopsis: Haskell high-level wrapper for OpenCL
bug-reports: https://github.com/IFCA/opencl/issues
Cabal-Version: >=1.8
Tested-With: GHC
Description:
Description:
Haskell FFI binding to OpenCL library. It includes high-level wrappers to
help development. Based on the OpenCLRaw package.
.
Expand All @@ -28,22 +28,22 @@ Extra-source-files:
examples/example04.hs
include/CL/*.h
include/CL/*.hpp
src/test/*.hs
src/test/*.hs

Library
Build-tools: c2hs
hs-Source-Dirs: src
ghc-options: -Wall
Build-Depends: base >=4.0 && < 5, bytestring -any, mtl>=2
Exposed-Modules:
Exposed-Modules:
Control.Parallel.OpenCL
Control.Parallel.OpenCL.Query
Control.Parallel.OpenCL.Context
Control.Parallel.OpenCL.CommandQueue
Control.Parallel.OpenCL.Memory
Control.Parallel.OpenCL.Event
Control.Parallel.OpenCL.Program
Other-Modules:
Other-Modules:
Control.Parallel.OpenCL.Types

if os(linux)
Expand Down
32 changes: 15 additions & 17 deletions examples/example02.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-}
import Control.Parallel.OpenCL
import Control.Parallel.OpenCL
import Foreign( castPtr, nullPtr, sizeOf )
import Foreign.C.Types( CFloat )
import Foreign.Marshal.Array( peekArray, withArray )
Expand All @@ -49,59 +49,57 @@ main = do
(dev:_) <- clGetDeviceIDs platform CL_DEVICE_TYPE_ALL
context <- clCreateContext [] [dev] print
q <- clCreateCommandQueue context dev [CL_QUEUE_PROFILING_ENABLE]

-- Initialize Kernel
program <- clCreateProgramWithSource context programSource
clBuildProgram program [dev] ""
kernel <- clCreateKernel program "duparray"

-- run tests
forM_ [100,200..30000] $ \s -> do
let original = [0 .. s] :: [CFloat]
n = 50 :: Double
res <- forM [0..n] $ \_ -> do
(t1,t2,t3,_) <- executeArray original context q kernel
return (t1,t2,t3)

let (t1,t2,t3) = foldl' sumres (0,0,0) res

putStrLn $ show s ++ "\t" ++ show (fromIntegral t1/n) ++ "\t" ++ show (fromIntegral t2/n) ++ "\t" ++ show (fromIntegral t3/n)

return ()
putStrLn $ show s ++ "\t" ++ show (fromIntegral t1/n) ++ "\t" ++ show (fromIntegral t2/n) ++ "\t" ++ show (fromIntegral t3/n)

executeArray :: [CFloat] -> CLContext -> CLCommandQueue -> CLKernel -> IO (CLulong, CLulong, CLulong, [CFloat])
executeArray original ctx q krn = withArray original $ \input -> do
mem_in <- clCreateBuffer ctx [CL_MEM_READ_ONLY] (vecSize, nullPtr)
mem_in <- clCreateBuffer ctx [CL_MEM_READ_ONLY] (vecSize, nullPtr)
mem_out <- clCreateBuffer ctx [CL_MEM_WRITE_ONLY] (vecSize, nullPtr)

clSetKernelArgSto krn 0 mem_in
clSetKernelArgSto krn 1 mem_out

-- Put Input
eventWrite <- clEnqueueWriteBuffer q mem_in True 0 vecSize (castPtr input) []

-- Execute Kernel
eventExec <- clEnqueueNDRangeKernel q krn [length original] [] [eventWrite]

-- Get Result
eventRead <- clEnqueueReadBuffer q mem_out True 0 vecSize (castPtr input) [eventExec]

_ <- clWaitForEvents [eventRead]

t_start0 <- clGetEventProfilingInfo eventWrite CL_PROFILING_COMMAND_START
t_end0 <- clGetEventProfilingInfo eventWrite CL_PROFILING_COMMAND_END
let t_write = t_end0 - t_start0

t_start1 <- clGetEventProfilingInfo eventExec CL_PROFILING_COMMAND_START
t_end1 <- clGetEventProfilingInfo eventExec CL_PROFILING_COMMAND_END
let t_exec = t_end1 - t_start1

t_start2 <- clGetEventProfilingInfo eventRead CL_PROFILING_COMMAND_START
t_end2 <- clGetEventProfilingInfo eventRead CL_PROFILING_COMMAND_END
let t_read = t_end2 - t_start2

result <- peekArray (length original) input

return (t_write,t_exec,t_read,result)
where
elemSize = sizeOf (0 :: CFloat)
Expand Down
Loading