packages feed

accelerate-io-repa (empty) → 0.1.0.0

raw patch · 6 files changed

+292/−0 lines, 6 filesdep +acceleratedep +basedep +repasetup-changed

Dependencies added: accelerate, base, repa

Files

+ CHANGELOG.md view
@@ -0,0 +1,12 @@+# Change Log++Notable changes to the project will be documented in this file.++The format is based on [Keep a Changelog](http://keepachangelog.com/) and the+project adheres to the [Haskell Package Versioning+Policy (PVP)](https://pvp.haskell.org)++## [0.1.0.0] - 2020-08-27+### Changed+  * Split from the `accelerate-io` package+
+ 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.
+ README.md view
@@ -0,0 +1,25 @@+<div align="center">+<img width="450" src="https://github.com/AccelerateHS/accelerate/raw/master/images/accelerate-logo-text-v.png?raw=true" alt="henlo, my name is Theia"/>++# Array conversion components for the Accelerate language++[![GitHub CI](https://github.com/tmcdonell/accelerate-io/workflows/CI/badge.svg)](https://github.com/tmcdonell/accelerate-io/actions)+[![Gitter](https://img.shields.io/gitter/room/nwjs/nw.js.svg)](https://gitter.im/AccelerateHS/Lobby)+<br>+[![Stackage LTS](https://stackage.org/package/accelerate-io/badge/lts)](https://stackage.org/lts/package/accelerate-io)+[![Stackage Nightly](https://stackage.org/package/accelerate-io/badge/nightly)](https://stackage.org/nightly/package/accelerate-io)+[![Hackage](https://img.shields.io/hackage/v/accelerate-io.svg)](https://hackage.haskell.org/package/accelerate-io)++</div>++Efficient conversion routines between Accelerate arrays and a range of data+formats.++For details on Accelerate, refer to the [main repository][GitHub].++Contributions and bug reports are welcome!<br>+Please feel free to contact me through [GitHub][GitHub] or [gitter.im][gitter.im].++  [GitHub]:     https://github.com/AccelerateHS/accelerate+  [gitter.im]:  https://gitter.im/AccelerateHS/Lobby+
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ accelerate-io-repa.cabal view
@@ -0,0 +1,50 @@+name:                   accelerate-io-repa+version:                0.1.0.0+cabal-version:          >= 1.10+build-type:             Simple++synopsis:               Convert between Accelerate and Repa arrays+Description:+  This package provides efficient conversion routines between Accelerate and+  Repa arrays, and to use Accelerate arrays in Repa computations.+  .+  Refer to the main /Accelerate/ package for more information:+  <http://hackage.haskell.org/package/accelerate>++license:                BSD3+license-file:           LICENSE+author:                 The Accelerate Team+maintainer:             Trevor L. McDonell <trevor.mcdonell@gmail.com>+homepage:               https://github.com/AccelerateHS/accelerate-io#readme+bug-reports:            https://github.com/AccelerateHS/accelerate-io/issues+category:               Accelerate, Data++extra-source-files:+    README.md+    CHANGELOG.md++library+  build-depends:+          base            >= 4.8 && < 5+        , accelerate      >= 1.3+        , repa            >= 3.2++  exposed-modules:+        Data.Array.Repa.Repr.Accelerate++  ghc-options:+        -O2+        -Wall+        -funbox-strict-fields++  ghc-prof-options:+        -fprof-auto++  hs-source-dirs:   src+  default-language: Haskell2010++source-repository head+  type:     git+  location: https://github.com/AccelerateHS/accelerate-io++-- vim: nospell
+ src/Data/Array/Repa/Repr/Accelerate.hs view
@@ -0,0 +1,180 @@+{-# LANGUAGE EmptyDataDecls            #-}+{-# LANGUAGE ExistentialQuantification #-}+{-# LANGUAGE ExplicitForAll            #-}+{-# LANGUAGE FlexibleContexts          #-}+{-# LANGUAGE FlexibleInstances         #-}+{-# LANGUAGE FunctionalDependencies    #-}+{-# LANGUAGE MultiParamTypeClasses     #-}+{-# LANGUAGE ScopedTypeVariables       #-}+{-# LANGUAGE TypeApplications          #-}+{-# LANGUAGE TypeFamilies              #-}+{-# LANGUAGE TypeOperators             #-}+{-# LANGUAGE UndecidableInstances      #-}+-- |+-- Module      : Data.Array.Repa.Repr.Accelerate+-- Copyright   : [2012..2014] Trevor L. McDonell+-- License     : BSD3+--+-- Maintainer  : Trevor L. McDonell <trevor.mcdonell@gmail.com>+-- Stability   : experimental+-- Portability : non-portable (GHC extensions)+--+-- 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:+--+--  * If you want to have Repa 'R.computeP' directly into an Accelerate array,+--    the source array must have a delayed representation.+--+--  * If you want to copy between manifest arrays, use 'R.copyP' instead.+--++module Data.Array.Repa.Repr.Accelerate (++  A, Shapes,++  fromRepa, toRepa,+  computeAccS, computeAccP++) where++import Control.Monad++import qualified Data.Array.Accelerate.Array.Data                   as A+import qualified Data.Array.Accelerate.Sugar.Array                  as A+import qualified Data.Array.Accelerate.Sugar.Elt                    as A+import qualified Data.Array.Accelerate.Sugar.Shape                  as A+import qualified Data.Array.Accelerate.Representation.Array         as AR+import qualified Data.Array.Repa                                    as R+import qualified Data.Array.Repa.Eval                               as R+++-- | 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+++-- | 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.+--+data A++-- Repr ------------------------------------------------------------------------++-- | Reading elements of the Accelerate array+--+instance A.Elt e => R.Source A e where+  data Array A sh e+    = AAccelerate !sh !(A.ArrayData (A.EltR e))++  {-# INLINE extent #-}+  extent (AAccelerate sh _)+    = sh++  {-# INLINE linearIndex #-}+  linearIndex (AAccelerate sh adata) ix+    | ix >= 0 && ix < R.size sh+    = A.toElt (A.indexArrayData (A.eltR @e) adata ix)++    | otherwise+    = error "Repa: accelerate array out of bounds"++  {-# INLINE unsafeLinearIndex #-}+  unsafeLinearIndex (AAccelerate _ adata) ix+    = A.toElt (A.indexArrayData (A.eltR @e) adata ix)++  {-# INLINE deepSeqArray #-}+  deepSeqArray (AAccelerate sh adata) x+    = sh `R.deepSeq` adata `seq` x+++-- | Filling Accelerate arrays+--+instance A.Elt e => R.Target A e where+  data MVec A e+    = MAVec (A.MutableArrayData (A.EltR e))++  {-# INLINE newMVec #-}+  newMVec n+    = MAVec `liftM` A.newArrayData (A.eltR @e) n++  {-# INLINE unsafeWriteMVec #-}+  unsafeWriteMVec (MAVec mad) n e+    = A.writeArrayData (A.eltR @e) mad n (A.fromElt e)++  {-# INLINE unsafeFreezeMVec #-}+  unsafeFreezeMVec sh (MAVec mad)+    = return $! AAccelerate sh mad++  {-# INLINE deepSeqMVec #-}+  deepSeqMVec (MAVec arr) x             -- maybe?+    = arr `seq` x++  {-# INLINE touchMVec #-}+  touchMVec _                           -- 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 (AR.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 (AR.Array (A.fromElt (toA sh)) adata)+++-- Computations ----------------------------------------------------------------++-- | Sequential computation of array elements+--+computeAccS+    :: (R.Load r sh e, A.Elt e)+    => R.Array r sh e -> R.Array A sh e+{-# INLINE computeAccS #-}+computeAccS = R.computeS++-- | Parallel computation of array elements+--+computeAccP+    :: (R.Load r sh e, A.Elt e, Monad m)+    => R.Array r sh e+    -> m (R.Array A sh e)+{-# INLINE computeAccP #-}+computeAccP = R.computeP+