Skip to content

Commit

Permalink
Merge branch 'master' of github.com:DDCSF/repa
Browse files Browse the repository at this point in the history
  • Loading branch information
benl23x5 committed Dec 13, 2017
2 parents 4a1c207 + cc754a5 commit 45154a1
Show file tree
Hide file tree
Showing 18 changed files with 261 additions and 127 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.stack-work
/stack.yaml
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule ".travis"]
path = .travis
url = https://github.com/tmcdonell/travis-scripts.git
1 change: 1 addition & 0 deletions .travis
Submodule .travis added at 3ec224
114 changes: 65 additions & 49 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,85 +1,101 @@
# vim: nospell
language: minimal
sudo: false
#
# Basic template to test with GHC=[7.8, 7.10, 8.0].
# Caches the 'stack' build directory to speed subsequent compilations.
#
language: generic
dist: trusty
sudo: required # not really, but these instances have more memory

cache:
timeout: 600
directories:
- $HOME/.stack
- $HOME/llvm
- .stack-work/install

before_cache:
- rm -vrf $(stack path --local-install-root)/bin

addons:
apt:
sources: &apt_sources
- hvr-ghc
- ubuntu-toolchain-r-test
- llvm-toolchain-trusty
- llvm-toolchain-precise-3.5
# - llvm-toolchain-precise-3.6
- llvm-toolchain-precise-3.7
# - llvm-toolchain-precise-3.8
# - llvm-toolchain-precise-3.9
# - llvm-toolchain-precise-4.0 # not white-listed yet
- sourceline: 'deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-4.0 main'
key_url: 'http://apt.llvm.org/llvm-snapshot.gpg.key'

packages: &apt_packages
- alex-3.1.7
- g++-4.8
- gcc-4.8
- happy-1.19.5
- libedit-dev
- libgmp-dev

matrix:
fast_finish: true
include:
- env: GHC=7.10.3 LLVM=3.5 CABAL=1.22
- env: GHC=7.10.3 CABAL=1.22 LLVM=3.5.1
compiler: "GHC 7.10"
addons:
apt:
sources:
- hvr-ghc
- llvm-toolchain-precise-3.5
- ubuntu-toolchain-r-test
sources: *apt_sources
packages:
- ghc-7.10.3
- *apt_packages
- cabal-install-1.22
- happy-1.19.5
- alex-3.1.4
- llvm-3.5-dev
- libedit-dev
- gcc-4.8
- g++-4.8

- env: GHC=head LLVM=3.7 CABAL=1.24
compiler: "GHC HEAD"
- env: GHC=8.0.2 CABAL=1.24 LLVM=3.7.1
compiler: "GHC 8.0"
addons:
apt:
sources:
- hvr-ghc
- llvm-toolchain-precise-3.7
- ubuntu-toolchain-r-test
sources: *apt_sources
packages:
- ghc-head
- *apt_packages
- cabal-install-1.24
- happy-1.19.5
- alex-3.1.4
- llvm-3.7-dev
- libedit-dev
- gcc-4.8
- g++-4.8

allow_failures:
- env: GHC=head LLVM=3.7 CABAL=1.24
- env: GHC=8.2.1 CABAL=2.0 LLVM=4.0.1
compiler: "GHC 8.2"
addons:
apt:
sources: *apt_sources
packages:
- *apt_packages
- cabal-install-2.0
- llvm-4.0-dev

before_install:
- export PATH=/opt/ghc/$GHC/bin:/opt/cabal/$CABAL/bin:/opt/alex/3.1.4/bin:/opt/happy/1.19.5/bin:/usr/lib/llvm-$LLVM/bin:$PATH

# cabal
- travis_retry cabal update
- sed -i 's/^jobs:/-- jobs:/' ${HOME}/.cabal/config

# stack
- mkdir $HOME/bin
- export PATH=$HOME/bin:$PATH
- travis_retry curl -L "https://www.stackage.org/stack/linux-x86_64" | gunzip | tar -x
- mv stack-*/stack $HOME/bin
- travis_retry stack setup
- travis_retry stack install hscolour
- export PATH=/opt/cabal/$CABAL/bin:/opt/alex/3.1.7/bin:/opt/happy/1.19.5/bin:$HOME/.cabal/bin:$PATH
- source .travis/install-stack.sh

install:
- echo "$(ghc --version) [$(ghc --print-project-git-commit-id 2> /dev/null || echo '?')]"
- stack --version
- echo "$(stack exec ghc -- --version) [$(stack exec ghc -- --print-project-git-commit-id 2> /dev/null || echo '?')]"
- cabal --version
- opt --version; true
- stack --version
- llc --version; true
- opt --version; true
- |
if [ ${GHC} == head ]; then
travis_retry cabal install --only-dependencies --allow-newer ./repa ./repa-io ./repa-algorithms ./repa-examples
if [ ${GHC} == head -o ! -e stack.yaml ]; then
travis_retry cabal install --only-dependencies || exit 1
else
travis_retry stack build --only-dependencies --no-terminal --no-haddock-deps -j2
travis_retry stack build --only-dependencies --fast --no-terminal --no-haddock-deps --ghc-options="-j +RTS -A128M -n4m -RTS" || exit 1
fi
script:
- |
if [ ${GHC} == head ]; then
cabal install --allow-newer ./repa ./repa-io ./repa-algorithms ./repa-examples
if [ ${GHC} == head -o ! -e stack.yaml ]; then
travis_retry cabal install || exit 1
travis_retry cabal haddock || exit 1
else
stack build --no-terminal --haddock --no-haddock-deps
travis_retry stack build --fast --no-terminal --haddock --no-haddock-deps --ghc-options="-j +RTS -A128M -n4m -RTS" || exit 1
fi
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
repa
====

[![Build Status](https://travis-ci.org/DDCSF/repa.svg?branch=master)](https://travis-ci.org/DDCSF/repa)
[![Build Status](https://travis-ci.org/tmcdonell/repa.svg?branch=master)](https://travis-ci.org/tmcdonell/repa)

Repa provides high performance, regular, multi-dimensional, shape polymorphic parallel arrays.
All numeric data is stored unboxed. Functions written with the Repa combinators are automatically
parallel provided you supply +RTS -Nwhatever on the command line when running the program.

* Home page and bug tracker are on a [separate site](http://repa.ouroborus.net/).

* PULL REQUESTS: If you want your pull request merged then send email to benl AT ouroborus.net. I don't pay attention to github notifications, but am happy to receive emails from people.
* PULL REQUESTS: If you want your pull request merged then send email to benl AT ouroborus.net. I don't pay attention to github notifications, but am happy to receive emails from people. Before raising your pull request make sure *all* the packages still build and that the examples still work.

* If you just want to bump a dependency version then get a package maintainer or Hackage trustee to edit the package information directly on Hackage. You don't need to raise a pull request here.
69 changes: 36 additions & 33 deletions repa-algorithms/Data/Array/Repa/Algorithms/FFT.hs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{-# LANGUAGE TypeOperators, PatternGuards, RankNTypes, ScopedTypeVariables, BangPatterns, FlexibleContexts #-}
{-# OPTIONS -fno-warn-incomplete-patterns #-}

-- | Fast computation of Discrete Fourier Transforms using the Cooley-Tuckey algorithm.
-- Time complexity is O(n log n) in the size of the input.
-- | Fast computation of Discrete Fourier Transforms using the Cooley-Tuckey algorithm.
-- Time complexity is O(n log n) in the size of the input.
--
-- This uses a naive divide-and-conquer algorithm, the absolute performance is about
-- 50x slower than FFTW in estimate mode.
Expand All @@ -14,10 +14,13 @@ module Data.Array.Repa.Algorithms.FFT
, fft2dP
, fft1dP)
where

import Data.Array.Repa.Algorithms.Complex
import Data.Array.Repa as R
import Data.Array.Repa.Eval as R
import Data.Array.Repa.Unsafe as R

import Data.Bits ((.&.))
import Prelude as P


Expand All @@ -37,13 +40,14 @@ signOfMode mode
{-# INLINE signOfMode #-}


-- | Check if an `Int` is a power of two.
-- | Check if an `Int` is a power of two. Assumes `n` is a natural number.

-- The implementation can be found in Henry S. Warren, Jr.'s book
-- Hacker's delight, Chapter 2.
isPowerOfTwo :: Int -> Bool
isPowerOfTwo n
| 0 <- n = True
| 2 <- n = True
| n `mod` 2 == 0 = isPowerOfTwo (n `div` 2)
| otherwise = False
isPowerOfTwo 0 = True
isPowerOfTwo 1 = False
isPowerOfTwo n = (n .&. (n-1)) == 0
{-# INLINE isPowerOfTwo #-}


Expand All @@ -56,29 +60,29 @@ fft3dP :: (Source r Complex, Monad m)
fft3dP mode arr
= let _ :. depth :. height :. width = extent arr
!sign = signOfMode mode
!scale = fromIntegral (depth * width * height)
!scale = fromIntegral (depth * width * height)

in if not (isPowerOfTwo depth && isPowerOfTwo height && isPowerOfTwo width)
then error $ unlines
[ "Data.Array.Repa.Algorithms.FFT: fft3d"
, " Array dimensions must be powers of two,"
, " but the provided array is "
, " but the provided array is "
P.++ show height P.++ "x" P.++ show width P.++ "x" P.++ show depth ]
else arr `deepSeqArray`

else arr `deepSeqArray`
case mode of
Forward -> now $ fftTrans3d sign $ fftTrans3d sign $ fftTrans3d sign arr
Reverse -> now $ fftTrans3d sign $ fftTrans3d sign $ fftTrans3d sign arr
Inverse -> computeP
$ R.map (/ scale)
$ R.map (/ scale)
$ fftTrans3d sign $ fftTrans3d sign $ fftTrans3d sign arr
{-# INLINE fft3dP #-}


fftTrans3d
fftTrans3d
:: Source r Complex
=> Double
-> Array r DIM3 Complex
-> Array r DIM3 Complex
-> Array U DIM3 Complex

fftTrans3d sign arr
Expand All @@ -87,7 +91,7 @@ fftTrans3d sign arr
{-# INLINE fftTrans3d #-}


rotate3d
rotate3d
:: Source r Complex
=> Array r DIM3 Complex -> Array D DIM3 Complex
rotate3d arr
Expand All @@ -107,15 +111,15 @@ fft2dP :: (Source r Complex, Monad m)
fft2dP mode arr
= let _ :. height :. width = extent arr
sign = signOfMode mode
scale = fromIntegral (width * height)
scale = fromIntegral (width * height)

in if not (isPowerOfTwo height && isPowerOfTwo width)
then error $ unlines
[ "Data.Array.Repa.Algorithms.FFT: fft2d"
, " Array dimensions must be powers of two,"
, " but the provided array is " P.++ show height P.++ "x" P.++ show width ]
else arr `deepSeqArray`

else arr `deepSeqArray`
case mode of
Forward -> now $ fftTrans2d sign $ fftTrans2d sign arr
Reverse -> now $ fftTrans2d sign $ fftTrans2d sign arr
Expand All @@ -126,7 +130,7 @@ fft2dP mode arr
fftTrans2d
:: Source r Complex
=> Double
-> Array r DIM2 Complex
-> Array r DIM2 Complex
-> Array U DIM2 Complex

fftTrans2d sign arr
Expand All @@ -138,20 +142,20 @@ fftTrans2d sign arr
-- Vector Transform -------------------------------------------------------------------------------
-- | Compute the DFT of a vector. Array dimensions must be powers of two else `error`.
fft1dP :: (Source r Complex, Monad m)
=> Mode
-> Array r DIM1 Complex
=> Mode
-> Array r DIM1 Complex
-> m (Array U DIM1 Complex)
fft1dP mode arr
= let _ :. len = extent arr
sign = signOfMode mode
scale = fromIntegral len

in if not $ isPowerOfTwo len
then error $ unlines
then error $ unlines
[ "Data.Array.Repa.Algorithms.FFT: fft1d"
, " Array dimensions must be powers of two, "
, " but the provided array is " P.++ show len ]

else arr `deepSeqArray`
case mode of
Forward -> now $ fftTrans1d sign arr
Expand All @@ -162,7 +166,7 @@ fft1dP mode arr

fftTrans1d
:: Source r Complex
=> Double
=> Double
-> Array r DIM1 Complex
-> Array U DIM1 Complex

Expand All @@ -174,7 +178,7 @@ fftTrans1d sign arr

-- Rank Generalised Worker ------------------------------------------------------------------------
fft :: (Shape sh, Source r Complex)
=> Double -> sh -> Int
=> Double -> sh -> Int
-> Array r (sh :. Int) Complex
-> Array U (sh :. Int) Complex

Expand All @@ -183,9 +187,9 @@ fft !sign !sh !lenVec !vec
where go !len !offset !stride
| len == 2
= suspendedComputeP $ fromFunction (sh :. 2) swivel

| otherwise
= combine len
= combine len
(go (len `div` 2) offset (stride * 2))
(go (len `div` 2) (offset + stride) (stride * 2))

Expand All @@ -197,7 +201,7 @@ fft !sign !sh !lenVec !vec
{-# INLINE combine #-}
combine !len' evens odds
= evens `deepSeqArray` odds `deepSeqArray`
let odds' = unsafeTraverse odds id (\get ix@(_ :. k) -> twiddle sign k len' * get ix)
let odds' = unsafeTraverse odds id (\get ix@(_ :. k) -> twiddle sign k len' * get ix)
in suspendedComputeP $ (evens +^ odds') R.++ (evens -^ odds')
{-# INLINE fft #-}

Expand All @@ -213,4 +217,3 @@ twiddle sign k' n'
where k = fromIntegral k'
n = fromIntegral n'
{-# INLINE twiddle #-}

2 changes: 1 addition & 1 deletion repa-algorithms/Data/Array/Repa/Algorithms/Matrix.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ mmultP arr brr
do trr <- transpose2P brr
let (Z :. h1 :. _) = extent arr
let (Z :. _ :. w2) = extent brr
computeP
trr `deepSeqArray` computeP
$ fromFunction (Z :. h1 :. w2)
$ \ix -> R.sumAllS
$ R.zipWith (*)
Expand Down
Loading

0 comments on commit 45154a1

Please sign in to comment.