packages feed

accelerate-io (empty) → 0.12.0.0

raw patch · 10 files changed

+713/−0 lines, 10 filesdep +acceleratedep +arraydep +basesetup-changed

Dependencies added: accelerate, array, base, bytestring, repa, vector

Files

+ Data/Array/Accelerate/IO.hs view
@@ -0,0 +1,38 @@+-- |+-- Module      : Data.Array.Accelerate.IO+-- Copyright   : [2010..2012] Sean Seefried, Trevor L. McDonell+-- License     : BSD3+--+-- Maintainer  : Manuel M T Chakravarty <chak@cse.unsw.edu.au>+-- Stability   : experimental+-- Portability : non-portable (GHC extensions)+--+-- This module provides efficient conversion routines between different array+-- types and Accelerate arrays.+--+-- The Repa interface provides an efficient non-copying instance for Repa to+-- read and write directly into arrays that can then be passed to Accelerate.+-- Additional copying conversions of low-level primitive arrays (i.e. one+-- dimensional, row-major blocks of contiguous memory) are provided, however 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+--++module Data.Array.Accelerate.IO (++  module Data.Array.Accelerate.IO.ByteString,+  module Data.Array.Accelerate.IO.Ptr,+  module Data.Array.Accelerate.IO.Repa,+  module Data.Array.Accelerate.IO.Vector,++) where++import Data.Array.Accelerate.IO.ByteString+import Data.Array.Accelerate.IO.Ptr+import Data.Array.Accelerate.IO.Repa+import Data.Array.Accelerate.IO.Vector
+ Data/Array/Accelerate/IO/BlockCopy.hs view
@@ -0,0 +1,189 @@+{-# LANGUAGE GADTs, MagicHash, ForeignFunctionInterface, TypeFamilies, ScopedTypeVariables #-}+-- |+-- Module      : Data.Array.Accelerate.IO.BlockCopy+-- Copyright   : [2010..2011] Sean Seefried+-- License     : BSD3+--+-- Maintainer  : Manuel M T Chakravarty <chak@cse.unsw.edu.au>+-- Stability   : experimental+-- Portability : non-portable (GHC extensions)+--++module Data.Array.Accelerate.IO.BlockCopy (++  -- * Types+  BlockCopyFun, BlockCopyFuns, BlockPtrs, ByteStrings,++  -- * The low-level machinery+  allocateArray, blockCopyFunGenerator++) where++-- standard libraries+import Foreign+import Foreign.C+import GHC.Base+import Data.Array.Base (bOOL_SCALE, wORD_SCALE, fLOAT_SCALE, dOUBLE_SCALE)+import Data.ByteString++-- friends+import Data.Array.Accelerate.Array.Data+import Data.Array.Accelerate.Array.Sugar+++-- | 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 BlockCopyFun e = Ptr e -> Int -> IO ()++-- | Represents a collection of "block copy functions" (see 'BlockCopyFun'). The+--   structure of the collection of 'BlockCopyFun's 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 ())@+--+type family BlockCopyFuns e++type instance BlockCopyFuns ()     = ()+type instance BlockCopyFuns Int    = BlockCopyFun Int+type instance BlockCopyFuns Int8   = BlockCopyFun Int8+type instance BlockCopyFuns Int16  = BlockCopyFun Int16+type instance BlockCopyFuns Int32  = BlockCopyFun Int32+type instance BlockCopyFuns Int64  = BlockCopyFun Int64+type instance BlockCopyFuns Word   = BlockCopyFun Word+type instance BlockCopyFuns Word8  = BlockCopyFun Word8+type instance BlockCopyFuns Word16 = BlockCopyFun Word16+type instance BlockCopyFuns Word32 = BlockCopyFun Word32+type instance BlockCopyFuns Word64 = BlockCopyFun Word64+type instance BlockCopyFuns Float  = BlockCopyFun Float+type instance BlockCopyFuns Double = BlockCopyFun Double+type instance BlockCopyFuns Bool   = BlockCopyFun Word8 -- Packed a bit vector+type instance BlockCopyFuns Char   = BlockCopyFun Char+type instance BlockCopyFuns (a,b)  = (BlockCopyFuns a, BlockCopyFuns b)++-- | 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)@+--+type family BlockPtrs e++type instance BlockPtrs ()     = ()+type instance BlockPtrs Int    = Ptr Int+type instance BlockPtrs Int8   = Ptr Int8+type instance BlockPtrs Int16  = Ptr Int16+type instance BlockPtrs Int32  = Ptr Int32+type instance BlockPtrs Int64  = Ptr Int64+type instance BlockPtrs Word   = Ptr Word+type instance BlockPtrs Word8  = Ptr Word8+type instance BlockPtrs Word16 = Ptr Word16+type instance BlockPtrs Word32 = Ptr Word32+type instance BlockPtrs Word64 = Ptr Word64+type instance BlockPtrs Float  = Ptr Float+type instance BlockPtrs Double = Ptr Double+type instance BlockPtrs Bool   = Ptr Word8 -- Packed as a bit vector+type instance BlockPtrs Char   = Ptr Char+type instance BlockPtrs (a,b)  = (BlockPtrs a, BlockPtrs b)++-- | A family of types that represents a collection of 'ByteString's. They are+--   the source data for function 'fromByteString' and the result data for+--   'toByteString'+--+type family ByteStrings e++type instance ByteStrings ()     = ()+type instance ByteStrings Int    = ByteString+type instance ByteStrings Int8   = ByteString+type instance ByteStrings Int16  = ByteString+type instance ByteStrings Int32  = ByteString+type instance ByteStrings Int64  = ByteString+type instance ByteStrings Word   = ByteString+type instance ByteStrings Word8  = ByteString+type instance ByteStrings Word16 = ByteString+type instance ByteStrings Word32 = ByteString+type instance ByteStrings Word64 = ByteString+type instance ByteStrings Float  = ByteString+type instance ByteStrings Double = ByteString+type instance ByteStrings Bool   = ByteString+type instance ByteStrings Char   = ByteString+type instance ByteStrings (a,b)  = (ByteStrings a, ByteStrings b)+++type GenFuns e = (( BlockPtrs e -> IO ()+                  , ByteStrings e -> IO ())+                 ,( BlockPtrs e -> IO ()+                  , IO (ByteStrings e))+                 , BlockCopyFuns e -> IO ())++base :: forall a b. Ptr b -> Int -> (( Ptr a -> IO (), ByteString -> IO ())+                                    ,( Ptr a -> IO (), IO ByteString)+                                    ,(Ptr b -> Int -> IO ()) -> IO ())+base accArrayPtr byteSize =+   ((blockPtrToArray, byteStringToArray)+   ,(arrayToBlockPtr, arrayToByteString)+   , blockCopyFunToOrFromArray)+  where+    blockPtrToArray :: Ptr a -> IO ()+    blockPtrToArray blockPtr = blockCopy blockPtr accArrayPtr byteSize+    arrayToBlockPtr :: Ptr a -> IO ()+    arrayToBlockPtr blockPtr = blockCopy accArrayPtr blockPtr byteSize+    blockCopyFunToOrFromArray :: (Ptr b -> Int -> IO ()) -> IO ()+    blockCopyFunToOrFromArray blockCopyFun = blockCopyFun accArrayPtr byteSize+    byteStringToArray :: ByteString -> IO ()+    byteStringToArray bs = useAsCString bs (blockPtrToArray . castPtr)+    arrayToByteString :: IO ByteString+    arrayToByteString = packCStringLen (castPtr accArrayPtr, byteSize)++blockCopyFunGenerator :: Array sh e -> GenFuns (EltRepr e)+blockCopyFunGenerator array@(Array _ arrayData) = aux arrayElt arrayData+  where+   sizeA = size (shape array)+   aux :: ArrayEltR e -> ArrayData e -> GenFuns e+   aux ArrayEltRunit _ = let f () = return () in ((f,f),(f,return ()),f)+   aux ArrayEltRint    ad = base (ptrsOfArrayData ad) (box wORD_SCALE sizeA)+   aux ArrayEltRint8   ad = base (ptrsOfArrayData ad) sizeA+   aux ArrayEltRint16  ad = base (ptrsOfArrayData ad) (sizeA * 2)+   aux ArrayEltRint32  ad = base (ptrsOfArrayData ad) (sizeA * 4)+   aux ArrayEltRint64  ad = base (ptrsOfArrayData ad) (sizeA * 8)+   aux ArrayEltRword   ad = base (ptrsOfArrayData ad) (box wORD_SCALE sizeA)+   aux ArrayEltRword8  ad = base (ptrsOfArrayData ad) sizeA+   aux ArrayEltRword16 ad = base (ptrsOfArrayData ad) (sizeA * 2)+   aux ArrayEltRword32 ad = base (ptrsOfArrayData ad) (sizeA * 4)+   aux ArrayEltRword64 ad = base (ptrsOfArrayData ad) (sizeA * 8)+   aux ArrayEltRfloat  ad = base (ptrsOfArrayData ad) (box fLOAT_SCALE sizeA)+   aux ArrayEltRdouble ad = base (ptrsOfArrayData ad) (box dOUBLE_SCALE sizeA)+   aux ArrayEltRbool   ad = base (ptrsOfArrayData ad) (box bOOL_SCALE sizeA)+   aux ArrayEltRchar   _ = error "not defined yet" -- base (castPtr $ ptrsOfArrayData ad) (sizeA * 4)+   aux (ArrayEltRpair a b) (AD_Pair ad1 ad2) = ((bpFromC, bsFromC), (bpToC, bsToC), toH)+     where+       ((bpFromC1, bsFromC1), (bpToC1, bsToC1), toH1) = aux a ad1+       ((bpFromC2, bsFromC2), (bpToC2, bsToC2), toH2) = aux b ad2+       toH (funs1, funs2)   = toH1 funs1    >> toH2 funs2+       bpToC (ptrA, ptrB)   = bpToC1 ptrA   >> bpToC2 ptrB+       bsToC                = do { bsA <- bsToC1; bsB <- bsToC2; return (bsA, bsB) }+       bpFromC (ptrA, ptrB) = bpFromC1 ptrA >> bpFromC2 ptrB+       bsFromC (bsA, bsB)   = bsFromC1 bsA  >> bsFromC2 bsB++blockCopy :: Ptr a -> Ptr b -> Int -> IO ()+blockCopy src dst byteSize = memcpy dst src (fromIntegral byteSize)+++-- Foreign imports+foreign import ccall memcpy :: Ptr a -> Ptr b -> CInt -> IO ()++-- Helpers+box :: (Int# -> Int#) -> Int -> Int+box f (I# x) = I# (f x)+
+ Data/Array/Accelerate/IO/ByteString.hs view
@@ -0,0 +1,49 @@+-- |+-- Module      : Data.Array.Accelerate.IO.ByteString+-- Copyright   : [2010..2011] Sean Seefried, Trevor L. McDonell+-- License     : BSD3+--+-- Maintainer  : Manuel M T Chakravarty <chak@cse.unsw.edu.au>+-- Stability   : experimental+-- Portability : non-portable (GHC extensions)+--++module Data.Array.Accelerate.IO.ByteString (++  -- * Copy to/from (strict) ByteString`s+  ByteStrings, fromByteString, toByteString++) where++import Data.Array.Accelerate.IO.BlockCopy+import Data.Array.Accelerate.Array.Sugar++++-- | Block copies bytes from a collection of 'ByteString's to freshly allocated+--   Accelerate array.+--+--   The type of elements (@e@) in the output Accelerate array determines the+--   structure of the collection of 'ByteString's that will be required as the+--   second argument to this function. See 'ByteStrings'+--+fromByteString :: (Shape sh, Elt e) => sh -> ByteStrings (EltRepr e) -> IO (Array sh e)+fromByteString sh byteStrings = do+  let arr    = allocateArray sh+      copier = let ((_,f),_,_) = blockCopyFunGenerator arr in f+  copier byteStrings+  return arr+++-- | Block copy from an Accelerate array to a collection of freshly allocated+--   'ByteString's.+--+--   The type of elements (@e@) in the input Accelerate array determines the+--   structure of the collection of 'ByteString's that will be output. See+--   'ByteStrings'+--+toByteString :: (Shape sh, Elt e) => Array sh e -> IO (ByteStrings (EltRepr e))+toByteString arr = do+  let copier = let (_,(_,f),_) = blockCopyFunGenerator arr in f+  copier+
+ Data/Array/Accelerate/IO/Ptr.hs view
@@ -0,0 +1,100 @@+-- |+-- Module      : Data.Array.Accelerate.IO.Ptr+-- Copyright   : [2010..2011] Sean Seefried, Trevor L. McDonell+-- License     : BSD3+--+-- Maintainer  : Manuel M T Chakravarty <chak@cse.unsw.edu.au>+-- Stability   : experimental+-- Portability : non-portable (GHC extensions)+--++module Data.Array.Accelerate.IO.Ptr (++  -- * Copying to/from raw pointers+  BlockPtrs, fromPtr, toPtr,++  -- * Direct copying into/from an Accelerate array+  BlockCopyFun, BlockCopyFuns, fromArray, toArray++) where++import Data.Array.Accelerate.IO.BlockCopy+import Data.Array.Accelerate.Array.Sugar++++-- | 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.).+--+fromPtr :: (Shape sh, Elt e) => sh -> BlockPtrs (EltRepr e) -> IO (Array sh e)+fromPtr sh blkPtrs = do+  let arr    = allocateArray sh+      copier = let ((f,_),_,_) = blockCopyFunGenerator arr in f+  copier blkPtrs+  return arr+++-- | 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.+--+toPtr :: (Shape sh, Elt e) => Array sh e -> BlockPtrs (EltRepr e) -> IO ()+toPtr arr blockPtrs = do+  let copier = let (_,(f,_),_) = blockCopyFunGenerator arr in f+  copier blockPtrs+  return ()+++-- | 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.+--+fromArray :: (Shape sh, Elt e) => Array sh e -> BlockCopyFuns (EltRepr e) -> IO ()+fromArray arr blockCopyFuns = do+   let copier = let (_,_,f) = blockCopyFunGenerator arr in f+   copier blockCopyFuns+   return ()+++-- | 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.+--+toArray :: (Shape sh, Elt e) => sh -> BlockCopyFuns (EltRepr e) -> IO (Array sh e)+toArray sh blockCopyFuns = do+  let arr    = allocateArray sh+      copier = let (_,_,f) = blockCopyFunGenerator arr in f+  copier blockCopyFuns+  return arr+
+ Data/Array/Accelerate/IO/Repa.hs view
@@ -0,0 +1,163 @@+{-# LANGUAGE ExplicitForAll         #-}+{-# LANGUAGE EmptyDataDecls         #-}+{-# LANGUAGE TypeFamilies           #-}+{-# LANGUAGE TypeOperators          #-}+{-# LANGUAGE FlexibleInstances      #-}+{-# LANGUAGE FlexibleContexts       #-}+{-# LANGUAGE UndecidableInstances   #-}+{-# LANGUAGE MultiParamTypeClasses  #-}+{-# LANGUAGE FunctionalDependencies #-}+-- |+-- Module      : Data.Array.Accelerate.IO.Repa+-- Copyright   : [2012] Trevor L. McDonell+-- License     : BSD3+--+-- Maintainer  : Manuel M T Chakravarty <chak@cse.unsw.edu.au>+-- Stability   : experimental+-- Portability : non-portable (GHC extensions)+--++module Data.Array.Accelerate.IO.Repa (++  A, Shapes,+  fromRepa, toRepa,+  computeAccS, computeAccP++) where++import Control.Monad+import Control.Monad.ST.Unsafe++import qualified Data.Array.Repa                        as R+import qualified Data.Array.Repa.Eval                   as R+import qualified Data.Array.Accelerate.Array.Data       as A+import qualified Data.Array.Accelerate.Array.Sugar      as 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.+--+class (R.Shape r, A.Shape a) => Shapes r a | a -> r, r -> a where+  -- these are really equivalent representations, so unsafeCoerce would probably+  -- work, but bad programmers get no cookies.+  toR   :: a -> r+  toA   :: r -> a++instance Shapes R.Z A.Z where+  {-# INLINE toR #-}+  toR A.Z = R.Z+  {-# INLINE toA #-}+  toA R.Z = A.Z++instance Shapes sr sa => Shapes (sr R.:. Int) (sa A.:. Int) where+  {-# INLINE toR #-}+  toR (sa A.:. sz) = toR sa R.:. sz+  {-# INLINE toA #-}+  toA (sr R.:. sz) = toA sr A.:. sz+++-- | An implementation based on `Data.Array.Accelerate` arrays. 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, example,+-- further parallel computation on the GPU.+--+data A+data instance R.Array A sh e+  = AAccelerate !sh !(A.ArrayData (A.EltRepr e))++-- Repr ------------------------------------------------------------------------++-- | Reading elements of the Accelerate array+--+instance A.Elt e => R.Repr A e where+  {-# INLINE extent #-}+  extent (AAccelerate sh _)+    = sh++  {-# INLINE linearIndex #-}+  linearIndex (AAccelerate sh adata) ix+    | ix >= 0 && ix < R.size sh+    = A.toElt (adata `A.indexArrayData` ix)++    | otherwise+    = error "Repa: accelerate array out of bounds"++  {-# INLINE unsafeLinearIndex #-}+  unsafeLinearIndex (AAccelerate _ adata) ix+    = A.toElt (adata `A.indexArrayData` ix)++  {-# INLINE deepSeqArray #-}+  deepSeqArray (AAccelerate sh adata) x+    = sh `R.deepSeq` adata `seq` x+++-- | Filling Accelerate arrays+--+instance A.Elt e => R.Fillable A e where+  data MArr A e+    = forall s. MAArr (A.MutableArrayData s (A.EltRepr e))++  {-# INLINE newMArr #-}+  newMArr n+    = MAArr `liftM` unsafeSTToIO (A.newArrayData n)++  {-# INLINE unsafeWriteMArr #-}+  unsafeWriteMArr (MAArr mad) n e+    = unsafeSTToIO+    $ A.writeArrayData mad n (A.fromElt e)++  {-# INLINE unsafeFreezeMArr #-}+  unsafeFreezeMArr sh (MAArr mad)+    = do adata  <- unsafeSTToIO $ A.unsafeFreezeArrayData mad+         return $! AAccelerate sh adata++  {-# INLINE deepSeqMArr #-}+  deepSeqMArr (MAArr arr) x             -- maybe?+    = arr `seq` x++  {-# INLINE touchMArr #-}+  touchMArr _                           -- maybe?+    = return ()+++-- Conversions -----------------------------------------------------------------++-- | /O(1)/. Wrap an Accelerate array.+--+toRepa+    :: Shapes sh sh'+    => A.Array sh' e -> R.Array A sh e+{-# INLINE toRepa #-}+toRepa arr@(A.Array _ adata)+  = AAccelerate (toR (A.shape arr)) adata++-- | /O(1)/. Unpack to an Accelerate array.+--+fromRepa+    :: (Shapes sh sh', A.Elt e)+    => R.Array A sh e -> A.Array sh' e+{-# INLINE fromRepa #-}+fromRepa (AAccelerate sh adata)+  = A.Array (A.fromElt (toA sh)) adata+++-- Computations ----------------------------------------------------------------++-- | Sequential computation of array elements+--+computeAccS+    :: R.Fill r A sh e+    => R.Array r sh e -> R.Array A sh e+{-# INLINE computeAccS #-}+computeAccS = R.computeS++-- | Parallel computation of array elements+--+computeAccP+    :: (R.Fill r A sh e, A.Elt e, Monad m)+    => R.Array r sh e+    -> m (R.Array A sh e)+{-# INLINE computeAccP #-}+computeAccP = R.computeP
+ Data/Array/Accelerate/IO/Vector.hs view
@@ -0,0 +1,55 @@+-- |+-- Module      : Data.Array.Accelerate.IO.Vector+-- Copyright   : [2012] Adam C. Foltzer+-- License     : BSD3+--+-- Maintainer  : Manuel M T Chakravarty <chak@cse.unsw.edu.au>+-- Stability   : experimental+-- Portability : non-portable (GHC extensions)+--+-- Helpers for fast conversion of 'Data.Vector.Storable' vectors into+-- Accelerate arrays.+module Data.Array.Accelerate.IO.Vector (+    -- * Vector conversions+    fromVector+  , toVector+  , fromVectorIO+  , toVectorIO+) where++import Data.Array.Accelerate ( arrayShape+                             , Array+                             , DIM1+                             , Elt+                             , Z(..)+                             , (:.)(..))+import Data.Array.Accelerate.Array.Sugar (EltRepr)+import Data.Array.Accelerate.IO.Ptr+import Data.Vector.Storable ( unsafeFromForeignPtr0+                            , unsafeToForeignPtr0+                            , Vector)++import Foreign (mallocForeignPtrArray, Ptr, Storable, withForeignPtr)++import System.IO.Unsafe++fromVectorIO :: (Storable a, Elt a, BlockPtrs (EltRepr a) ~ ((), Ptr a))+             => Vector a -> IO (Array DIM1 a)+fromVectorIO v = withForeignPtr fp $ \ptr -> fromPtr (Z :. len) ((), ptr)+  where (fp, len) = unsafeToForeignPtr0 v++toVectorIO :: (Storable a, Elt a, BlockPtrs (EltRepr a) ~ ((), Ptr a)) +           => Array DIM1 a -> IO (Vector a)+toVectorIO arr = do+  let (Z :. len) = arrayShape arr+  fp <- mallocForeignPtrArray len+  withForeignPtr fp $ \ptr -> toPtr arr ((), ptr)+  return $ unsafeFromForeignPtr0 fp len++fromVector :: (Storable a, Elt a, BlockPtrs (EltRepr a) ~ ((), Ptr a))+           => Vector a -> Array DIM1 a+fromVector v = unsafePerformIO $ fromVectorIO v++toVector :: (Storable a, Elt a, BlockPtrs (EltRepr a) ~ ((), Ptr a)) +         => Array DIM1 a -> Vector a+toVector arr = unsafePerformIO $ toVectorIO arr
+ LICENSE view
@@ -0,0 +1,23 @@+Copyright (c) [2007..2012] The Accelerate Team.  All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:+    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.+    * Redistributions in binary form must reproduce the above copyright+      notice, this list of conditions and the following disclaimer in the+      documentation and/or other materials provided with the distribution.+    * Neither the names of the contributors nor of their affiliations may +      be used to endorse or promote products derived from this software +      without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY+EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE+DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS BE LIABLE FOR ANY+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND+ON ANY 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.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ accelerate-io.cabal view
@@ -0,0 +1,69 @@+Name:                   accelerate-io+Version:                0.12.0.0+Cabal-version:          >= 1.6+Tested-with:            GHC >= 7.0.3+Build-type:             Simple++Synopsis:               Read and write Accelerate arrays in various formats+Description:            This package provides efficient conversion routines between a range of array types+                        and Accelerate arrays.++License:                BSD3+License-file:           LICENSE+Author:                 Manuel M T Chakravarty,+                        Gabriele Keller,+                        Sean Lee,+                        Trevor L. McDonell+Maintainer:             Manuel M T Chakravarty <chak@cse.unsw.edu.au>+Homepage:               http://www.cse.unsw.edu.au/~chak/project/accelerate/+Bug-reports:            https://github.com/AccelerateHS/accelerate/issues++Category:               Compilers/Interpreters, Concurrency, Data+Stability:              Experimental++Extra-source-files:     include/accelerate.h++Flag bounds-checks+  Description:          Enable bounds checking+  Default:              True++Flag unsafe-checks+  Description:          Enable bounds checking in unsafe operations+  Default:              False++Flag internal-checks+  Description:          Enable internal consistency checks+  Default:              False++Library+  Include-Dirs:         include+  Build-depends:        accelerate      >= 0.12,+                        array           >= 0.3,+                        base            == 4.*,+                        bytestring      >= 0.9,+                        repa            >= 3.1.2,+                        vector          >= 0.9++  Exposed-modules:      Data.Array.Accelerate.IO+  Other-modules:        Data.Array.Accelerate.IO.BlockCopy+                        Data.Array.Accelerate.IO.ByteString+                        Data.Array.Accelerate.IO.Ptr+                        Data.Array.Accelerate.IO.Repa+                        Data.Array.Accelerate.IO.Vector++  if flag(bounds-checks)+    cpp-options:        -DACCELERATE_BOUNDS_CHECKS++  if flag(unsafe-checks)+    cpp-options:        -DACCELERATE_UNSAFE_CHECKS++  if flag(internal-checks)+    cpp-options:        -DACCELERATE_INTERNAL_CHECKS++  ghc-options:          -O2 -Wall -funbox-strict-fields++  Extensions:           TypeFamilies++Source-repository head+  Type:                 git+  Location:             git://github.com/AccelerateHS/accelerate-io.git
+ include/accelerate.h view
@@ -0,0 +1,25 @@++#ifndef NOT_ACCELERATE_MODULE+import qualified Data.Array.Accelerate.Internal.Check as Ck+#endif++#define ERROR(f)  (Ck.f __FILE__ __LINE__)+#define ASSERT (Ck.assert __FILE__ __LINE__)+#define ENSURE (Ck.f __FILE__ __LINE__)+#define CHECK(f) (Ck.f __FILE__ __LINE__)++#define BOUNDS_ERROR(f) (ERROR(f) Ck.Bounds)+#define BOUNDS_ASSERT (ASSERT Ck.Bounds)+#define BOUNDS_ENSURE (ENSURE Ck.Bounds)+#define BOUNDS_CHECK(f) (CHECK(f) Ck.Bounds)++#define UNSAFE_ERROR(f) (ERROR(f) Ck.Unsafe)+#define UNSAFE_ASSERT (ASSERT Ck.Unsafe)+#define UNSAFE_ENSURE (ENSURE Ck.Unsafe)+#define UNSAFE_CHECK(f) (CHECK(f) Ck.Unsafe)++#define INTERNAL_ERROR(f) (ERROR(f) Ck.Internal)+#define INTERNAL_ASSERT (ASSERT Ck.Internal)+#define INTERNAL_ENSURE (ENSURE Ck.Internal)+#define INTERNAL_CHECK(f) (CHECK(f) Ck.Internal)+