| 1 |
{-# LANGUAGE TypeFamilies #-} |
| 2 |
{-# OPTIONS_GHC -fno-warn-orphans #-} |
| 3 |
|
| 4 |
-- | Converting 'MC' programs to 'MCMem'. |
| 5 |
module Futhark.Pass.ExplicitAllocations.MC (explicitAllocations) where |
| 6 |
|
| 7 |
import Futhark.IR.MC |
| 8 |
import Futhark.IR.MCMem |
| 9 |
import Futhark.Pass.ExplicitAllocations |
| 10 |
import Futhark.Pass.ExplicitAllocations.SegOp |
| 11 |
|
| 12 |
instance SizeSubst (MCOp rep op) |
| 13 |
|
| 14 |
handleSegOp :: SegOp () MC -> AllocM MC MCMem (SegOp () MCMem) |
| 15 |
handleSegOp op = do |
| 16 |
let num_threads = intConst Int64 256 -- FIXME |
| 17 |
mapSegOpM (mapper num_threads) op |
| 18 |
where |
| 19 |
scope = scopeOfSegSpace $ segSpace op |
| 20 |
mapper num_threads = |
| 21 |
identitySegOpMapper |
| 22 |
{ mapOnSegOpBody = |
| 23 |
localScope scope . allocInKernelBody, |
| 24 |
mapOnSegOpLambda = |
| 25 |
allocInBinOpLambda num_threads (segSpace op) |
| 26 |
} |
| 27 |
|
| 28 |
handleMCOp :: Op MC -> AllocM MC MCMem (Op MCMem) |
| 29 |
handleMCOp (ParOp par_op op) = |
| 30 |
Inner <$> (ParOp <$> traverse handleSegOp par_op <*> handleSegOp op) |
| 31 |
handleMCOp (OtherOp soac) = |
| 32 |
error $ "Cannot allocate memory in SOAC: " ++ prettyString soac |
| 33 |
|
| 34 |
-- | The pass from 'MC' to 'MCMem'. |
| 35 |
explicitAllocations :: Pass MC MCMem |
| 36 |
explicitAllocations = explicitAllocationsGeneric DefaultSpace handleMCOp defaultExpHints |