{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TupleSections #-}
module Data.Array.Accelerate.LLVM.PTX.Compile.Libdevice.Load (
nvvmReflect, libdevice,
) where
import LLVM.Context
import LLVM.Module as LLVM
import LLVM.AST as AST ( Module(..) )
import Data.Array.Accelerate.Error
import Data.Array.Accelerate.LLVM.PTX.Compile.Libdevice.TH
import Data.Array.Accelerate.LLVM.PTX.Execute.Event ( )
import Data.Array.Accelerate.LLVM.PTX.Execute.Stream ( )
import Foreign.CUDA.Analysis
import Data.ByteString ( ByteString )
import System.IO.Unsafe
class NVVMReflect a where
nvvmReflect :: a
instance NVVMReflect AST.Module where
nvvmReflect = nvvmReflectModule
instance NVVMReflect (String, ByteString) where
nvvmReflect = $$( nvvmReflectBitcode nvvmReflectModule )
class Libdevice a where
libdevice :: Compute -> a
instance Libdevice AST.Module where
libdevice (Compute n m) =
case (n,m) of
(2,_) -> libdevice_20_mdl
(3,x) | x < 5 -> libdevice_30_mdl
| otherwise -> libdevice_35_mdl
(5,_) -> libdevice_50_mdl
(6,_) -> libdevice_50_mdl
_ -> $internalError "libdevice" "no binary for this architecture"
instance Libdevice (String, ByteString) where
libdevice (Compute n m) =
case (n,m) of
(2,_) -> libdevice_20_bc
(3,x) | x < 5 -> libdevice_30_bc
| otherwise -> libdevice_35_bc
(5,_) -> libdevice_50_bc
(6,_) -> libdevice_50_bc
_ -> $internalError "libdevice" "no binary for this architecture"
{-# NOINLINE libdevice_20_mdl #-}
{-# NOINLINE libdevice_30_mdl #-}
{-# NOINLINE libdevice_35_mdl #-}
{-# NOINLINE libdevice_50_mdl #-}
libdevice_20_mdl, libdevice_30_mdl, libdevice_35_mdl, libdevice_50_mdl :: AST.Module
libdevice_20_mdl = unsafePerformIO $ libdeviceModule (Compute 2 0)
libdevice_30_mdl = unsafePerformIO $ libdeviceModule (Compute 3 0)
libdevice_35_mdl = unsafePerformIO $ libdeviceModule (Compute 3 5)
libdevice_50_mdl = unsafePerformIO $ libdeviceModule (Compute 5 0)
libdevice_20_bc, libdevice_30_bc, libdevice_35_bc, libdevice_50_bc :: (String,ByteString)
libdevice_20_bc = $$( libdeviceBitcode (Compute 2 0) )
libdevice_30_bc = $$( libdeviceBitcode (Compute 3 0) )
libdevice_35_bc = $$( libdeviceBitcode (Compute 3 5) )
libdevice_50_bc = $$( libdeviceBitcode (Compute 5 0) )
libdeviceModule :: Compute -> IO AST.Module
libdeviceModule arch = do
let bc :: (String, ByteString)
bc = libdevice arch
withContext $ \ctx ->
withModuleFromBitcode ctx bc moduleAST