| Copyright | [2010..2012] Sean Seefried [2010..2016] Trevor L. McDonell |
|---|---|
| License | BSD3 |
| Maintainer | Trevor L. McDonell <tmcdonell@cse.unsw.edu.au> |
| Stability | experimental |
| Portability | non-portable (GHC extensions) |
| Safe Haskell | None |
| Language | Haskell98 |
Data.Array.Accelerate.IO
Contents
Description
This module provides efficient conversion routines between different array types and Accelerate arrays.
- data A
- class (Shape r, Shape a) => Shapes r a | a -> r, r -> a
- fromRepa :: (Shapes sh sh', Elt e) => Array A sh e -> Array sh' e
- toRepa :: Shapes sh sh' => Array sh' e -> Array A sh e
- computeAccS :: (Load r sh e, Elt e) => Array r sh e -> Array A sh e
- computeAccP :: (Load r sh e, Elt e, Monad m) => Array r sh e -> m (Array A sh e)
- type family Vectors e
- toVectors :: (Shape sh, Elt e) => Array sh e -> Vectors (EltRepr e)
- fromVectors :: (Shape sh, Elt e) => sh -> Vectors (EltRepr e) -> Array sh e
- fromIArray :: (IxShapeRepr (EltRepr ix) ~ EltRepr sh, IArray a e, Ix ix, Shape sh, Elt ix, Elt e) => a ix e -> Array sh e
- toIArray :: (IxShapeRepr (EltRepr ix) ~ EltRepr sh, IArray a e, Ix ix, Shape sh, Elt ix) => Array sh e -> a ix e
- type RGBA32 = Word32
- readImageFromBMP :: FilePath -> IO (Either Error (Array DIM2 RGBA32))
- writeImageToBMP :: FilePath -> Array DIM2 RGBA32 -> IO ()
- type family ByteStrings e
- fromByteString :: (Shape sh, Elt e) => sh -> ByteStrings (EltRepr e) -> IO (Array sh e)
- toByteString :: (Shape sh, Elt e) => Array sh e -> IO (ByteStrings (EltRepr e))
- type family BlockPtrs e
- fromPtr :: (Shape sh, Elt e) => sh -> BlockPtrs (EltRepr e) -> IO (Array sh e)
- toPtr :: (Shape sh, Elt e) => Array sh e -> BlockPtrs (EltRepr e) -> IO ()
- type BlockCopyFun e = Ptr e -> Int -> IO ()
- type family BlockCopyFuns e
- fromArray :: (Shape sh, Elt e) => Array sh e -> BlockCopyFuns (EltRepr e) -> IO ()
- toArray :: (Shape sh, Elt e) => sh -> BlockCopyFuns (EltRepr e) -> IO (Array sh e)
Array libraries
Data.Array.Repa
This provides an efficient non-copying Repa manifest array representation that can be passed directly to Accelerate.
The standard rules for dealing with manifest Repa arrays apply:
The representation tag for manifest arrays based on Data.Array.Accelerate.
The Accelerate array implementation is based on type families and picks an efficient, unboxed representation for every element type. Moreover, these arrays can be handed efficiently (without copying) to Accelerate programs for further computation.
class (Shape r, Shape a) => Shapes r a | a -> r, r -> a #
Index conversion and equivalence statement between Repa and Accelerate array shapes. That is, a n-dimensional Repa array will produce an n-dimensional Accelerate array of the same extent, and vice-versa.
Minimal complete definition
toR, toA
fromRepa :: (Shapes sh sh', Elt e) => Array A sh e -> Array sh' e #
O(1). Unpack to an Accelerate array.
computeAccS :: (Load r sh e, Elt e) => Array r sh e -> Array A sh e #
Sequential computation of array elements
computeAccP :: (Load r sh e, Elt e, Monad m) => Array r sh e -> m (Array A sh e) #
Parallel computation of array elements
Data.Vector.Storable
This provides an efficient non-copying conversion between storable vectors and Accelerate arrays.
A family of types that represents a collection of storable Vectors. The
structure of the collection depends on the element type e.
For example:
- if
e :: Int, thenVectors (EltRepr e) :: ((), Vector Int) - if
e :: (Double, Float), thenVectors (EltRepr e) :: (((), Vector Double), Vector Float)
Instances
| type Vectors Bool # | |
| type Vectors Char # | |
| type Vectors Double # | |
| type Vectors Float # | |
| type Vectors Int # | |
| type Vectors Int8 # | |
| type Vectors Int16 # | |
| type Vectors Int32 # | |
| type Vectors Int64 # | |
| type Vectors Word # | |
| type Vectors Word8 # | |
| type Vectors Word16 # | |
| type Vectors Word32 # | |
| type Vectors Word64 # | |
| type Vectors () # | |
| type Vectors CDouble # | |
| type Vectors CFloat # | |
| type Vectors CULLong # | |
| type Vectors CLLong # | |
| type Vectors CULong # | |
| type Vectors CLong # | |
| type Vectors CUInt # | |
| type Vectors CInt # | |
| type Vectors CUShort # | |
| type Vectors CShort # | |
| type Vectors CUChar # | |
| type Vectors CSChar # | |
| type Vectors CChar # | |
| type Vectors (a, b) # | |
fromVectors :: (Shape sh, Elt e) => sh -> Vectors (EltRepr e) -> Array sh e #
O(1). Treat a set of storable vectors as Accelerate arrays. The type of
elements e in the output Accelerate array determines the structure of the
collection that will be required as the second argument. See Vectors.
Data will be consumed from the vector in row-major order. You must make sure that each of the input vectors contains the right number of elements
IArray
fromIArray :: (IxShapeRepr (EltRepr ix) ~ EltRepr sh, IArray a e, Ix ix, Shape sh, Elt ix, Elt e) => a ix e -> Array sh e #
Convert an IArray to an accelerated array.
While the type signature mentions Accelerate internals that are not exported,
in practice satisfying the type equality is straight forward. The index type
ix must be the unit type () for singleton arrays, or an Int or tuple of
Int's for multidimensional arrays.
toIArray :: (IxShapeRepr (EltRepr ix) ~ EltRepr sh, IArray a e, Ix ix, Shape sh, Elt ix) => Array sh e -> a ix e #
Convert an accelerated array to an IArray.
Specialised file IO
Bitmap images
Reading and writing arrays as uncompressed 24 or 32-bit Windows BMP files.
readImageFromBMP :: FilePath -> IO (Either Error (Array DIM2 RGBA32)) #
Read RGBA components from a BMP file.
Low-level conversions
Copying conversions of low-level primitive data, stored in one-dimensional row-major blocks of contiguous memory. To use these, you should really know what you are doing. Potential pitfalls include:
- copying from memory your program doesn't have access to (e.g. it may be unallocated, or not enough memory is allocated)
- memory alignment errors
Data.ByteString
type family ByteStrings e #
A family of types that represents a collection of ByteStrings. They are
the source data for function fromByteString and the result data for
toByteString
Instances
| type ByteStrings Bool # | |
| type ByteStrings Char # | |
| type ByteStrings Double # | |
| type ByteStrings Float # | |
| type ByteStrings Int # | |
| type ByteStrings Int8 # | |
| type ByteStrings Int16 # | |
| type ByteStrings Int32 # | |
| type ByteStrings Int64 # | |
| type ByteStrings Word # | |
| type ByteStrings Word8 # | |
| type ByteStrings Word16 # | |
| type ByteStrings Word32 # | |
| type ByteStrings Word64 # | |
| type ByteStrings () # | |
| type ByteStrings CDouble # | |
| type ByteStrings CFloat # | |
| type ByteStrings CULLong # | |
| type ByteStrings CLLong # | |
| type ByteStrings CULong # | |
| type ByteStrings CLong # | |
| type ByteStrings CUInt # | |
| type ByteStrings CInt # | |
| type ByteStrings CUShort # | |
| type ByteStrings CShort # | |
| type ByteStrings CShort # | |
| type ByteStrings CUChar # | |
| type ByteStrings CSChar # | |
| type ByteStrings CChar # | |
| type ByteStrings (a, b) # | |
fromByteString :: (Shape sh, Elt e) => sh -> ByteStrings (EltRepr e) -> IO (Array sh e) #
Block copies bytes from a collection of ByteStrings to freshly allocated
Accelerate array.
The type of elements (e) in the output Accelerate array determines the
structure of the collection of ByteStrings that will be required as the
second argument to this function. See ByteStrings
toByteString :: (Shape sh, Elt e) => Array sh e -> IO (ByteStrings (EltRepr e)) #
Block copy from an Accelerate array to a collection of freshly allocated
ByteStrings.
The type of elements (e) in the input Accelerate array determines the
structure of the collection of ByteStrings that will be output. See
ByteStrings
Raw pointers
A family of types that represents a collection of pointers that are the
source/destination addresses for a block copy. The structure of the
collection of pointers depends on the element type e.
e.g.
If e :: Int, then BlockPtrs (EltRepr e) :: ((), Ptr Int)
If e :: (Double, Float) then BlockPtrs (EltRepr e) :: (((), Ptr Double), Ptr Float)
Instances
| type BlockPtrs Bool # | |
| type BlockPtrs Char # | |
| type BlockPtrs Double # | |
| type BlockPtrs Float # | |
| type BlockPtrs Int # | |
| type BlockPtrs Int8 # | |
| type BlockPtrs Int16 # | |
| type BlockPtrs Int32 # | |
| type BlockPtrs Int64 # | |
| type BlockPtrs Word # | |
| type BlockPtrs Word8 # | |
| type BlockPtrs Word16 # | |
| type BlockPtrs Word32 # | |
| type BlockPtrs Word64 # | |
| type BlockPtrs () # | |
| type BlockPtrs CDouble # | |
| type BlockPtrs CFloat # | |
| type BlockPtrs CULLong # | |
| type BlockPtrs CLLong # | |
| type BlockPtrs CULong # | |
| type BlockPtrs CLong # | |
| type BlockPtrs CUInt # | |
| type BlockPtrs CInt # | |
| type BlockPtrs CUShort # | |
| type BlockPtrs CShort # | |
| type BlockPtrs CUChar # | |
| type BlockPtrs CSChar # | |
| type BlockPtrs CChar # | |
| type BlockPtrs (a, b) # | |
fromPtr :: (Shape sh, Elt e) => sh -> BlockPtrs (EltRepr e) -> IO (Array sh e) #
Block copy regions of memory into a freshly allocated Accelerate array. The
type of elements (e) in the output Accelerate array determines the
structure of the collection of pointers that will be required as the second
argument to this function. See BlockPtrs
Each one of these pointers points to a block of memory that is the source
of data for the Accelerate array (unlike function toArray where one
passes in function which copies data to a destination address.).
toPtr :: (Shape sh, Elt e) => Array sh e -> BlockPtrs (EltRepr e) -> IO () #
Block copy from Accelerate array to pre-allocated regions of memory. The
type of element of the input Accelerate array (e) determines the
structure of the collection of pointers that will be required as the second
argument to this function. See BlockPtrs
The memory associated with the pointers must have already been allocated.
Direct copying functions
type BlockCopyFun e = Ptr e -> Int -> IO () #
Functions of this type are passed as arguments to toArray. A function of
this type should copy a number of bytes (equal to the value of the
parameter of type Int) to the destination memory pointed to by Ptr e.
type family BlockCopyFuns e #
Represents a collection of "block copy functions" (see BlockCopyFun). The
structure of the collection of BlockCopyFuns depends on the element type
e.
e.g.
If e :: Float
then BlockCopyFuns (EltRepr e) :: ((), Ptr Float -> Int -> IO ())
If e :: (Double, Float)
then BlockCopyFuns (EltRepr e) :: (((), Ptr Double -> Int -> IO ()), Ptr Float -> Int -> IO ())
Instances
| type BlockCopyFuns Bool # | |
| type BlockCopyFuns Char # | |
| type BlockCopyFuns Double # | |
| type BlockCopyFuns Float # | |
| type BlockCopyFuns Int # | |
| type BlockCopyFuns Int8 # | |
| type BlockCopyFuns Int16 # | |
| type BlockCopyFuns Int32 # | |
| type BlockCopyFuns Int64 # | |
| type BlockCopyFuns Word # | |
| type BlockCopyFuns Word8 # | |
| type BlockCopyFuns Word16 # | |
| type BlockCopyFuns Word32 # | |
| type BlockCopyFuns Word64 # | |
| type BlockCopyFuns () # | |
| type BlockCopyFuns CDouble # | |
| type BlockCopyFuns CFloat # | |
| type BlockCopyFuns CULLong # | |
| type BlockCopyFuns CLLong # | |
| type BlockCopyFuns CULong # | |
| type BlockCopyFuns CLong # | |
| type BlockCopyFuns CUInt # | |
| type BlockCopyFuns CInt # | |
| type BlockCopyFuns CUShort # | |
| type BlockCopyFuns CShort # | |
| type BlockCopyFuns CUChar # | |
| type BlockCopyFuns CSChar # | |
| type BlockCopyFuns CChar # | |
| type BlockCopyFuns (a, b) # | |
fromArray :: (Shape sh, Elt e) => Array sh e -> BlockCopyFuns (EltRepr e) -> IO () #
Copy values from an Accelerate array using a collection of functions that
have type BlockCopyFun. The argument of type Ptr e in each of these
functions refers to the address of the source block of memory in the
Accelerate Array. The destination address is implicit. e.g. the
BlockCopyFun could be the result of partially application to a Ptr e
pointing to the destination block.
The structure of this collection of functions depends on the elemente type
e. Each function (of type BlockCopyFun) copies data to a destination
address (pointed to by the argument of type Ptr ()).
Unless there is a particularly pressing reason to use this function, the
fromPtr function is sufficient as it uses an efficient low-level call to
libc's memcpy to perform the copy.
toArray :: (Shape sh, Elt e) => sh -> BlockCopyFuns (EltRepr e) -> IO (Array sh e) #
Copy values to a freshly allocated Accelerate array using a collection of
functions that have type BlockCopyFun. The argument of type Ptr e in
each of these functions refers to the address of the destination block of
memory in the Accelerate Array. The source address is implicit. e.g. the
BlockCopyFun could be the result of a partial application to a Ptr e
pointing to the source block.
The structure of this collection of functions depends on the elemente type
e. Each function (of type BlockCopyFun) copies data to a destination
address (pointed to by the argument of type Ptr ()).
Unless there is a particularly pressing reason to use this function, the
fromPtr function is sufficient as it uses an efficient low-level call to
libc's memcpy to perform the copy.