HsOpenCL-0.0.1: A binding to the OpenCL parallel computing framework.

System.HsOpenCL.Memory

Contents

Synopsis

Buffers

data Buffer a

A region of memory on an OpenCL device.

bufferSize :: forall e. Storable e => Buffer e -> Int

Number of elements in the buffer.

mallocBuffer

Arguments

:: forall a m . (Storable a, MonadQueue m) 
=> MemAccessFlag 
-> MemInitFlag a 
-> Int

The number of elements in the buffer.

-> m (Buffer a) 

Allocate memory on the device associated with this queue. The returned Buffer must later be released with freeBuffer.

freeBuffer :: MonadIO m => Buffer a -> m ()

Release the given Buffer. The OpenCL runtime will delete it once all Commands using the Buffer have completed.

allocaBuffer

Arguments

:: (Storable a, MonadQueue m) 
=> MemAccessFlag 
-> MemInitFlag a 
-> Int

The number of elements in the buffer.

-> (Buffer a -> m b) 
-> m b 

Allocate memory on the device associated with this queue, and execute the given action. The Buffer will be released once the action has completed and all Commands associated with it have finished.

Note that it is unsafe to use the Buffer after this function has completed.

Reading, writing and copying

class CopyTo a b where

Reads, writes and copies between device and host memory can all be performed using the CopyTo class.

For example, if a :: Buffer Float and c :: Ptr Float, then waitForCommand (a := c) copies bufferSize a elements (i.e., Floats) from c to a.

This class can also be used to copy to/from subregions of device memory. For example, waitForCommand (slice 2 10 a =: slice 0 10 b) copies the first 10 elements of b into indices [2..11] of a.

All CopyTo operations are unblocking. As a result, when QueueOutOfOrderExecModeEnable has been set, the runtime may copy data simultaneously or out of order from other Commands.

The module System.HsOpenCL.Instances.CArray exports instances for copying to and from CArrays, which may be more convenient to use than pointers.

Methods

(=:) :: Storable e => a e -> b e -> Command

A copy between host and device memory, or between two device memory objects.

class BufferLike b where

This class represents objects of which we can select a subregion; namely, Buffer and Slice.

Methods

asSlice :: Storable e => b e -> Slice e

data Slice e

A subregion of a Buffer.

Instances

slice :: Storable e => BufferLike b => Int -> Int -> b e -> Slice e

Select a subregion of the given Buffer or Slice.

sizeS :: Slice e -> Int

data SlicedPtr a

A slice of the data contained in a ForeignPtr. The CopyTo instance for this type ensures that the ForeignPtr will be retained until the copy has completed.

An error will be thrown when copying between a SlicedPtr and a Buffer of unequal sizes.

Constructors

SlicedPtr 

copyToVector :: (Storable e, MonadQueue m, BufferLike b) => b e -> m (Vector e)

Buffer operations

This section provides an API for buffer operations which is closer to the actual OpenCL API.

data IsBlocking

Constructors

Blocking 
NonBlocking 

readBuffer

Arguments

:: forall a . Storable a 
=> Buffer a 
-> IsBlocking 
-> Int

The offset index.

-> Int

The number of elements to copy.

-> Ptr a 
-> Command 

writeBuffer

Arguments

:: forall a . Storable a 
=> Buffer a 
-> IsBlocking 
-> Int

The offset index.

-> Int

The number of elements to copy.

-> Ptr a 
-> Command 

copyBuffer

Arguments

:: forall a . Storable a 
=> Buffer a

The source buffer

-> Buffer a

The destination buffer.

-> Int

The offset index in the source buffer.

-> Int

The offset index in the destination.

-> Int

The number of elements to copy.

-> Command 

Properties

class MemObject m

A memory region on the device.

Instances

memSize :: MemObject m => m -> Int

Size of the data store, in bytes.