{-# LINE 1 "./Foreign/CUDA/FFT/Plan.chs" #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE ForeignFunctionInterface #-}
module Foreign.CUDA.FFT.Plan (
Handle(..),
Type(..),
plan1D,
plan2D,
plan3D,
planMany,
destroy,
) where
import qualified Foreign.C.Types as C2HSImp
import qualified Foreign.Ptr as C2HSImp
import Foreign.CUDA.FFT.Error
import Foreign.CUDA.FFT.Internal.C2HS
import Foreign
import Foreign.C
import Control.Monad ( liftM )
import Data.Maybe
{-# LINE 36 "./Foreign/CUDA/FFT/Plan.chs" #-}
newtype Handle = Handle { useHandle :: (C2HSImp.CInt)}
data Type = C2C
| R2C
| C2R
| Z2Z
| D2Z
| Z2D
deriving (Eq,Show)
instance Enum Type where
succ C2C = R2C
succ R2C = C2R
succ C2R = Z2Z
succ Z2Z = D2Z
succ D2Z = Z2D
succ Z2D = error "Type.succ: Z2D has no successor"
pred R2C = C2C
pred C2R = R2C
pred Z2Z = C2R
pred D2Z = Z2Z
pred Z2D = D2Z
pred C2C = error "Type.pred: C2C has no predecessor"
enumFromTo from to = go from
where
end = fromEnum to
go v = case compare (fromEnum v) end of
LT -> v : go (succ v)
EQ -> [v]
GT -> []
enumFrom from = enumFromTo from Z2D
fromEnum C2C = 41
fromEnum R2C = 42
fromEnum C2R = 44
fromEnum Z2Z = 105
fromEnum D2Z = 106
fromEnum Z2D = 108
toEnum 41 = C2C
toEnum 42 = R2C
toEnum 44 = C2R
toEnum 105 = Z2Z
toEnum 106 = D2Z
toEnum 108 = Z2D
toEnum unmatched = error ("Type.toEnum: Cannot match " ++ show unmatched)
{-# LINE 62 "./Foreign/CUDA/FFT/Plan.chs" #-}
{-# INLINEABLE plan1D #-}
plan1D :: (Int)
-> (Type)
-> (Int)
-> IO ((Handle))
plan1D a2 a3 a4 =
alloca $ \a1' ->
let {a2' = fromIntegral a2} in
let {a3' = cFromEnum a3} in
let {a4' = fromIntegral a4} in
plan1D'_ a1' a2' a3' a4' >>= \res ->
checkStatus res >>
peekHdl a1'>>= \a1'' ->
return (a1'')
{-# LINE 84 "./Foreign/CUDA/FFT/Plan.chs" #-}
where
peekHdl = liftM Handle . peek
{-# INLINEABLE plan2D #-}
plan2D :: (Int)
-> (Int)
-> (Type)
-> IO ((Handle))
plan2D a2 a3 a4 =
alloca $ \a1' ->
let {a2' = fromIntegral a2} in
let {a3' = fromIntegral a3} in
let {a4' = cFromEnum a4} in
plan2D'_ a1' a2' a3' a4' >>= \res ->
checkStatus res >>
peekHdl a1'>>= \a1'' ->
return (a1'')
{-# LINE 100 "./Foreign/CUDA/FFT/Plan.chs" #-}
where
peekHdl = liftM Handle . peek
{-# INLINEABLE plan3D #-}
plan3D :: (Int)
-> (Int)
-> (Int)
-> (Type)
-> IO ((Handle))
plan3D a2 a3 a4 a5 =
alloca $ \a1' ->
let {a2' = fromIntegral a2} in
let {a3' = fromIntegral a3} in
let {a4' = fromIntegral a4} in
let {a5' = cFromEnum a5} in
plan3D'_ a1' a2' a3' a4' a5' >>= \res ->
checkStatus res >>
peekHdl a1'>>= \a1'' ->
return (a1'')
{-# LINE 117 "./Foreign/CUDA/FFT/Plan.chs" #-}
where
peekHdl = liftM Handle . peek
planMany :: [Int]
-> Maybe ([Int], Int, Int)
-> Maybe ([Int], Int, Int)
-> Type
-> Int
-> IO Handle
planMany n ilayout olayout t batch =
cufftPlanMany (length n) n inembed istride idist onembed ostride odist t batch
where
(inembed, istride, idist) = fromMaybe ([], 0, 0) ilayout
(onembed, ostride, odist) = fromMaybe ([], 0, 0) olayout
peekHdl = liftM Handle . peek
asArray [] f = f nullPtr
asArray xs f = withArray (map fromIntegral xs) f
cufftPlanMany :: (Int) -> ([Int]) -> ([Int]) -> (Int) -> (Int) -> ([Int]) -> (Int) -> (Int) -> (Type) -> (Int) -> IO ((Handle))
cufftPlanMany a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 =
alloca $ \a1' ->
let {a2' = fromIntegral a2} in
asArray a3 $ \a3' ->
asArray a4 $ \a4' ->
let {a5' = fromIntegral a5} in
let {a6' = fromIntegral a6} in
asArray a7 $ \a7' ->
let {a8' = fromIntegral a8} in
let {a9' = fromIntegral a9} in
let {a10' = cFromEnum a10} in
let {a11' = fromIntegral a11} in
cufftPlanMany'_ a1' a2' a3' a4' a5' a6' a7' a8' a9' a10' a11' >>= \res ->
checkStatus res >>
peekHdl a1'>>= \a1'' ->
return (a1'')
{-# LINE 167 "./Foreign/CUDA/FFT/Plan.chs" #-}
{-# INLINEABLE destroy #-}
destroy :: (Handle) -> IO ()
destroy a1 =
let {a1' = useHandle a1} in
destroy'_ a1' >>= \res ->
checkStatus res >>
return ()
{-# LINE 177 "./Foreign/CUDA/FFT/Plan.chs" #-}
foreign import ccall unsafe "Foreign/CUDA/FFT/Plan.chs.h cufftPlan1d"
plan1D'_ :: ((C2HSImp.Ptr C2HSImp.CInt) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (IO C2HSImp.CInt)))))
foreign import ccall unsafe "Foreign/CUDA/FFT/Plan.chs.h cufftPlan2d"
plan2D'_ :: ((C2HSImp.Ptr C2HSImp.CInt) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (IO C2HSImp.CInt)))))
foreign import ccall unsafe "Foreign/CUDA/FFT/Plan.chs.h cufftPlan3d"
plan3D'_ :: ((C2HSImp.Ptr C2HSImp.CInt) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (IO C2HSImp.CInt))))))
foreign import ccall unsafe "Foreign/CUDA/FFT/Plan.chs.h cufftPlanMany"
cufftPlanMany'_ :: ((C2HSImp.Ptr C2HSImp.CInt) -> (C2HSImp.CInt -> ((C2HSImp.Ptr C2HSImp.CInt) -> ((C2HSImp.Ptr C2HSImp.CInt) -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr C2HSImp.CInt) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (IO C2HSImp.CInt))))))))))))
foreign import ccall unsafe "Foreign/CUDA/FFT/Plan.chs.h cufftDestroy"
destroy'_ :: (C2HSImp.CInt -> (IO C2HSImp.CInt))