accelerate-io-serialise (empty) → 0.1.0.0
raw patch · 6 files changed
+258/−0 lines, 6 filesdep +acceleratedep +accelerate-io-bytestringdep +basesetup-changed
Dependencies added: accelerate, accelerate-io-bytestring, base, serialise
Files
- CHANGELOG.md +12/−0
- LICENSE +23/−0
- README.md +25/−0
- Setup.hs +2/−0
- accelerate-io-serialise.cabal +51/−0
- src/Data/Array/Accelerate/IO/Codec/Serialise.hs +145/−0
+ 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)++## [next]+### New+ * Initial release+
+ 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++[](https://github.com/tmcdonell/accelerate-io/actions)+[](https://gitter.im/AccelerateHS/Lobby)+<br>+[](https://stackage.org/lts/package/accelerate-io)+[](https://stackage.org/nightly/package/accelerate-io)+[](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-serialise.cabal view
@@ -0,0 +1,51 @@+name: accelerate-io-serialise+version: 0.1.0.0+cabal-version: >= 1.10+build-type: Simple++synopsis: Binary serialisation of Accelerate arrays using serialise+Description:+ This package provides efficient binary serialisation of Accelerate arrays+ via the serialise libary.+ .+ 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+ , accelerate-io-bytestring >= 0.1+ , serialise >= 0.2++ exposed-modules:+ Data.Array.Accelerate.IO.Codec.Serialise++ 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/Accelerate/IO/Codec/Serialise.hs view
@@ -0,0 +1,145 @@+{-# LANGUAGE GADTs #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TypeApplications #-}+{-# OPTIONS_GHC -fno-warn-orphans #-}+-- |+-- Module : Data.Array.Accelerate.IO.Codec.Serialise+-- Copyright : [2012..2021] The Accelerate Team+-- License : BSD3+--+-- Maintainer : Trevor L. McDonell <trevor.mcdonell@gmail.com>+-- Stability : experimental+-- Portability : non-portable (GHC extensions)+--+-- Orphan instance for binary serialisation of 'Array'+--++module Data.Array.Accelerate.IO.Codec.Serialise ()+ where++import Codec.Serialise+import Codec.Serialise.Decoding+import Codec.Serialise.Encoding++import Data.Array.Accelerate.Array.Data+import Data.Array.Accelerate.Representation.Shape ( ShapeR(..) )+import Data.Array.Accelerate.Representation.Type+import Data.Array.Accelerate.Sugar.Array+import Data.Array.Accelerate.Sugar.Elt+import Data.Array.Accelerate.Sugar.Shape+import Data.Array.Accelerate.Type+import qualified Data.Array.Accelerate.Representation.Array as R+import qualified Data.Array.Accelerate.Representation.Shape as R++import Data.Array.Accelerate.IO.Data.ByteString+++instance (Shape sh, Elt e) => Serialise (Array sh e) where+ {-# INLINE encode #-}+ encode arr@(Array arrR)+ = encodeListLen (fromIntegral (R.rank (shapeR @sh)) + fieldsArrayR (eltR @e))+ <> encodeShapeR (shapeR @sh) (R.shape arrR)+ <> encodeArrayR (eltR @e) (toByteStrings arr)+ where+ encodeShapeR :: ShapeR t -> t -> Encoding+ encodeShapeR ShapeRz () = mempty+ encodeShapeR (ShapeRsnoc shR) (sh, sz) = encodeShapeR shR sh <> encodeInt sz++ encodeArrayR :: TypeR t -> ByteStrings t -> Encoding+ encodeArrayR TupRunit () = mempty+ encodeArrayR (TupRpair aR1 aR2) (a1, a2) = encodeArrayR aR1 a1 <> encodeArrayR aR2 a2+ encodeArrayR (TupRsingle aR) a = scalar aR a+ where+ scalar :: ScalarType t -> ByteStrings t -> Encoding+ scalar (SingleScalarType t) = single t+ scalar (VectorScalarType t) = vector t++ vector :: VectorType t -> ByteStrings t -> Encoding+ vector (VectorType _ t)+ | SingleArrayDict <- singleArrayDict t+ = single t++ single :: SingleType t -> ByteStrings t -> Encoding+ single (NumSingleType t) = num t++ num :: NumType t -> ByteStrings t -> Encoding+ num (IntegralNumType t) = integral t+ num (FloatingNumType t) = floating t++ integral :: IntegralType t -> ByteStrings t -> Encoding+ integral TypeInt = encodeBytes+ integral TypeInt8 = encodeBytes+ integral TypeInt16 = encodeBytes+ integral TypeInt32 = encodeBytes+ integral TypeInt64 = encodeBytes+ integral TypeWord = encodeBytes+ integral TypeWord8 = encodeBytes+ integral TypeWord16 = encodeBytes+ integral TypeWord32 = encodeBytes+ integral TypeWord64 = encodeBytes++ floating :: FloatingType t -> ByteStrings t -> Encoding+ floating TypeHalf = encodeBytes+ floating TypeFloat = encodeBytes+ floating TypeDouble = encodeBytes++ fieldsArrayR :: TypeR t -> Word+ fieldsArrayR TupRunit = 0+ fieldsArrayR TupRsingle{} = 1+ fieldsArrayR (TupRpair eR1 eR2) = fieldsArrayR eR1 + fieldsArrayR eR2++ {-# INLINE decode #-}+ decode = do+ _ <- decodeListLen+ sh <- decodeShapeR (shapeR @sh)+ bs <- decodeArrayR (eltR @e)+ return $! fromByteStrings (toElt sh) bs+ where+ decodeShapeR :: ShapeR t -> Decoder s t+ decodeShapeR ShapeRz = return ()+ decodeShapeR (ShapeRsnoc shR) = do+ sh <- decodeShapeR shR+ sz <- decodeInt+ return (sh, sz)++ decodeArrayR :: TypeR t -> Decoder s (ByteStrings t)+ decodeArrayR TupRunit = return ()+ decodeArrayR (TupRpair aR1 aR2) = do+ a1 <- decodeArrayR aR1+ a2 <- decodeArrayR aR2+ return (a1, a2)+ decodeArrayR (TupRsingle aR) = scalar aR+ where+ scalar :: ScalarType t -> Decoder s (ByteStrings t)+ scalar (SingleScalarType t) = single t+ scalar (VectorScalarType t) = vector t++ vector :: VectorType t -> Decoder s (ByteStrings t)+ vector (VectorType _ t)+ | SingleArrayDict <- singleArrayDict t+ = single t++ single :: SingleType t -> Decoder s (ByteStrings t)+ single (NumSingleType t) = num t++ num :: NumType t -> Decoder s (ByteStrings t)+ num (IntegralNumType t) = integral t+ num (FloatingNumType t) = floating t++ integral :: IntegralType t -> Decoder s (ByteStrings t)+ integral TypeInt = decodeBytes+ integral TypeInt8 = decodeBytes+ integral TypeInt16 = decodeBytes+ integral TypeInt32 = decodeBytes+ integral TypeInt64 = decodeBytes+ integral TypeWord = decodeBytes+ integral TypeWord8 = decodeBytes+ integral TypeWord16 = decodeBytes+ integral TypeWord32 = decodeBytes+ integral TypeWord64 = decodeBytes++ floating :: FloatingType t -> Decoder s (ByteStrings t)+ floating TypeHalf = decodeBytes+ floating TypeFloat = decodeBytes+ floating TypeDouble = decodeBytes+