Hey Nic!
This is actually a really good question! You are completely right, I don’t think we have put anywhere how to get a minimal project set up and running, which we really should ):
From the site you linked, I guess you got stack
installed ok and are happy to use that (I recommend using stack
anyway).
Accelerate is on stackage now, so you’ll be able to get it if you switch to the nightly resolver.
$ stack new --resolver=nightly my-project
This will give you a stack.yaml
which looks like this (I just removed the comments for brevity):
resolver: nightly-2017-11-07
packages:
- .
extra-deps: []
flags: {}
In the my-project.cabal
file, you need to specify that your project will depend on (a) the Accelerate library, which defines the core language and “standard prelude”; and (b) one (or more) of the backends, which will actually run the code.
For example, in the library
stanza of the my-project.cabal
file, we can change the build-depends
field:
library
default-language: Haskell2010
hs-source-dirs: src
exposed-modules: Lib
build-depends:
base >= 4.7 && < 5
, accelerate
, accelerate-llvm-native
In the above, substitute accelerate-llvm-native
for accelerate-llvm-ptx
if you want to run with the CUDA GPU backend instead (if you have the right hardware that is.) You can also install and use both at once, if you like.
Build the project in the usual way:
$ stack setup
$ stack build
Now, in the src/Lib.hs
file, you can import Accelerate and start writing code with it:
module Lib where
import Data.Array.Accelerate as A -- the standard prelude
import Data.Array.Accelerate.LLVM.Native as CPU -- this is where `run` comes from
dotp :: Acc (Vector Float) -> Acc (Vector Float) -> Acc (Scalar Float)
dotp xs ys = A.sum (A.zipWith (*) xs ys)
To execute an Accelerate program (generate code for an Acc a
expression, compile, and execute it) use the run*
functions from one of the backends. Let’s try that out in ghci
:
$ stack ghci src/Lib.hs
> let xs = fromList (Z:.10) [0..] :: Vector Float
> let ys = fromList (Z:.10) [1,3..] :: Vector Float
> run $ dotp (use xs) (use ys)
Scalar Z [615.0]
I hope that helps get you started! Feel free to keep asking questions, no matter how newbie they might feel (we all have to start somewhere!) (:
All the best!
-Trev
--
You received this message because you are subscribed to the Google Groups "Accelerate" group.
To unsubscribe from this group and stop receiving emails from it, send an email to accelerate-hask...@googlegroups.com.
Visit this group at https://groups.google.com/group/accelerate-haskell.
For more options, visit https://groups.google.com/d/optout.