{-# LANGUAGE TemplateHaskell #-}
module Foreign.NVVM.Path (
nvvmDeviceLibraryPath
) where
import Foreign.CUDA.Path
import Language.Haskell.TH
import System.Directory
import System.FilePath
import Data.List
nvvmDeviceLibraryPath :: FilePath
nvvmDeviceLibraryPath :: FilePath
nvvmDeviceLibraryPath = $(do
path <- runIO $ do
let ubuntu = return "/usr/lib/nvidia-cuda-toolkit/libdevice"
nvidia = return (cudaInstallPath </> "nvvm" </> "libdevice")
orElse this other = do
path <- this
yes <- doesDirectoryExist path
if yes
then do
files <- getDirectoryContents path
let bc = filter (\f -> "libdevice" `isPrefixOf` f && takeExtension f == ".bc") files
if null bc
then other
else return path
else other
nvidia `orElse` ubuntu `orElse` error "could not locate libdevice directory"
stringE path
)