Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
USING GPUS
Manuel M. T. Chakravarty
University of New South Wales
or e
d s/c
re a
o f th
e ds
n dr
hu
100
Time (milliseconds)
10
0.1
0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Number of non-zero elements (million)
Plain Haskell, CPU only (AMD Sempron) Plain Haskell, CPU only (Intel Xeon)
Haskell EDSL on a GPU (GeForce 8800GTS) Haskell EDSL on a GPU (Tesla S1070 x1)
‣ No function pointers
‣ Very limited recursion
Software-managed cache, memory-access
patterns, etc.
Portability...
Embedded DSL
Multiple backends
Monday, 7 September 2009
Data.Array.Accelerate
e l i sm
tarall
a p
ve d a
Collective operations on multi-dimensional regular
a s si
m
arrays ✓
Embedded DSL
Multiple backends
Monday, 7 September 2009
Data.Array.Accelerate
e l i sm
t a p arall
ve d a
Collective operations on multi-dimensional regular
a s si
m
arrays ✓
Embedded DSL
u re s
‣ Restricted controloflow l st ruct
ntro
d c
imit e
l
✓ GPU code
‣ First-order
Generative approach based on combinator
templates
Multiple backends
Monday, 7 September 2009
Data.Array.Accelerate
e l i sm
t a p arall
ve d a
Collective operations on multi-dimensional regular
a s si
m
arrays ✓
Embedded DSL
u re s
‣ Restricted controloflow l st ruct
ntro
d c
imit e
l
✓ GPU code
‣ First-order e r ns
e s s patt
d ac c
Generative approach - tu based
n e on combinator
n d
templates ✓ ha
Multiple backends
Monday, 7 September 2009
Data.Array.Accelerate
e l i sm
t a p arall
ve d a
Collective operations on multi-dimensional regular
a s si
m
arrays ✓
Embedded DSL
u re s
‣ Restricted controloflow l st ruct
ntro d c
imit e
l
✓ GPU code
‣ First-order e r ns
e s s patt
d ac c
Generative approach - tu based
n e on combinator
n d
templates ✓ ha
b i li t y
Multiple backends
p o r ta
✓
Monday, 7 September 2009
import Data.Array.Accelerate
Dot product
HaskellDot product
array
dotp :: Vector Float -> Vector Float
-> Acc (Scalar Float)
dotp xs ys
= let
xs' = use xs
ys' = use ys
in
fold (+) 0 (zipWith (*) xs' ys')
HaskellDot product
array
dotp :: Vector Float -> Vector Float
-> Acc (Scalar Float)
dotp xs ys
EDSL array =
= let
desc. of array comps
xs' = use xs
ys' = use ys
in
fold (+) 0 (zipWith (*) xs' ys')
HaskellDot product
array
dotp :: Vector Float -> Vector Float
-> Acc (Scalar Float)
dotp xs ys
EDSL array =
= let
desc. of array comps
xs' = use xs
ys' = use ys
in Lift Haskell arrays into
fold (+) 0 (zipWith (*) xs' ys') EDSL — may trigger
host➙device transfer
HaskellDot product
array
dotp :: Vector Float -> Vector Float
-> Acc (Scalar Float)
dotp xs ys
EDSL array =
= let
desc. of array comps
xs' = use xs
ys' = use ys
in Lift Haskell arrays into
fold (+) 0 (zipWith (*) xs' ys') EDSL — may trigger
host➙device transfer
EDSL array
computations
d e Br u ijn
f y & H OAS ->
R e i
d e Br u ijn
f y & H OAS ->
R e i
Recover
sharing
(CSE or O
bserve)
d e Br u ijn
f y & H OAS ->
R e i
Recover t i o n
sharing m is a
(CSE or O Op t i
bserve) s io n )
(Fu
d e Br u ijn
f y & H OAS ->
R e i
Recover t i o n
sharing m is a
(CSE or O Op t i
bserve) s io n )
(Fu
Code generation
d e Br u ijn
f y & H OAS ->
R e i
Recover t i o n
sharing m is a
(CSE or O Op t i
bserve) s io n )
(Fu
Code generation
d e Br u ijn
f y & H OAS ->
R e i
Recover t i o n
sharing m is a
(CSE or O Op t i
bserve) s io n ) e
(Fu c ka g
a
p gins
plu
Code generation
type DIM0 = ()
type DIM1 = Int
type DIM2 = (Int, Int)
⟨and so on⟩
type DIM0 = ()
type DIM1 = Int
type DIM2 = (Int, Int)
⟨and so on⟩
EDSL forms
data Exp e — scalar expression form
data Acc a — array expression form
type DIM0 = ()
type DIM1 = Int
type DIM2 = (Int, Int)
⟨and so on⟩
EDSL forms
data Exp e — scalar expression form
data Acc a — array expression form
Classes
class Elem e — scalar and tuples types
class Elem ix => Ix ix — unit and integer tuples
— create a singleton
unit :: Elem e => Exp e -> Acc (Scalar e)
— multi-dimensional replication
replicate :: (SliceIx slix, Elem e)
=> Exp slix
-> Acc (Array (Slice slix) e)
-> Acc (Array (SliceDim slix) e)
— slice extraction
slice :: (SliceIx slix, Elem e)
=> Acc (Array (SliceDim slix) e)
-> Exp slix
-> Acc (Array (Slice slix) e)
scan :: Elem a
=> (Exp a -> Exp a -> Exp a) — associative
-> Exp a
-> Acc (Vector a)
-> (Acc (Vector a), Acc (Scalar a))
100000
Time (milliseconds)
10000
1000
100
10
1
128 256 512 1024
size of square NxN matrix
Status: