nvvm 0.7.5.2 → 0.8.0.0
raw patch · 3 files changed
+88/−192 lines, 3 filesdep ~cudasetup-changed
Dependency ranges changed: cuda
Files
- CHANGELOG.md +16/−6
- Setup.hs +60/−177
- nvvm.cabal +12/−9
CHANGELOG.md view
@@ -1,14 +1,24 @@ # Revision history for nvvm -## 0.7.5.2 -- 2017-04-10+Notable changes to the project will be documented in this file. -* Add support for c2hs < 0.26+The format is based on [Keep a Changelog](http://keepachangelog.com/). -## 0.7.5.1 -- 2016-11-08+## [0.8.0.0] - 2017-08-24+ * Build setup improvements -* Add support for Cabal-1.22+## [0.7.5.2] - 2017-04-10+ * Add support for c2hs < 0.26 -## 0.7.5.0 -- 2016-10-08+## [0.7.5.1] - 2016-11-08+ * Add support for Cabal-1.22 -* First version. Released on an unsuspecting world.+## [0.7.5.0] - 2016-10-08+ * First version. Released on an unsuspecting world.+++[0.8.0.0]: https://github.com/tmcdonell/nvvm/compare/v0.7.5.2...v0.8.0.0+[0.7.5.2]: https://github.com/tmcdonell/nvvm/compare/0.7.5.1...v0.7.5.2+[0.7.5.1]: https://github.com/tmcdonell/nvvm/compare/0.7.5.0...0.7.5.1+[0.7.5.0]: https://github.com/tmcdonell/nvvm/compare/953f6c0b99b8d667a8e261722a8daeeaba162435...0.7.5.0
Setup.hs view
@@ -1,6 +1,7 @@-{-# LANGUAGE CPP #-}-{-# LANGUAGE QuasiQuotes #-}-{-# LANGUAGE TemplateHaskell #-}+{-# LANGUAGE CPP #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE QuasiQuotes #-}+{-# LANGUAGE TemplateHaskell #-} -- This macro is only available when compiling with GHC-8 #ifndef MIN_VERSION_Cabal@@ -13,7 +14,7 @@ import Distribution.Simple.BuildPaths import Distribution.Simple.Command import Distribution.Simple.LocalBuildInfo-import Distribution.Simple.PreProcess hiding ( ppC2hs )+import Distribution.Simple.PreProcess import Distribution.Simple.Program import Distribution.Simple.Program.Db import Distribution.Simple.Program.Find@@ -27,13 +28,12 @@ import Distribution.Version #endif +import Foreign.CUDA.Path import Control.Applicative import Control.Exception import Control.Monad import System.Directory-import System.Environment import System.FilePath-import System.IO.Error import Text.Printf import Prelude @@ -49,7 +49,29 @@ generatedBuldInfoFilePath :: FilePath generatedBuldInfoFilePath = customBuildInfoFilePath <.> "generated" +-- Location of the NVVM library relative to the base CUDA installation+--+nvvmPath :: Platform -> FilePath+nvvmPath _ = cudaInstallPath </> "nvvm" +nvvmIncludePath :: Platform -> FilePath+nvvmIncludePath platform = nvvmPath platform </> "include"++nvvmLibraryPath :: Platform -> FilePath+nvvmLibraryPath platform@(Platform arch os) = nvvmPath platform </> libpath+ where+ libpath =+ case (os, arch) of+ (Windows, I386) -> "Win32"+ (Windows, X86_64) -> "x64"+ (OSX, _) -> "lib" -- MacOS does not distinguish 32- vs. 64-bit paths+ (_, X86_64) -> "lib64" -- treat all others similarly+ _ -> "lib"++nvvmLibrary :: Platform -> [String]+nvvmLibrary _ = ["nvvm"]++ -- Build setup -- ----------- @@ -60,6 +82,8 @@ noExtraFlags args getHookedBuildInfo (fromFlag (get_verbosity flags)) + preprocessors = hookedPreProcessors simpleUserHooks+ -- Our readHook implementation uses our getHookedBuildInfo. We can't rely on -- cabal's autoconfUserHooks since they don't handle user overwrites to -- buildinfo like we do.@@ -76,7 +100,7 @@ , preUnreg = readHook regVerbosity , postConf = postConfHook , postBuild = postBuildHook- , hookedPreProcessors = ("chs", ppC2hs) : filter (\x -> fst x /= "chs") (hookedPreProcessors simpleUserHooks)+ , hookedPreProcessors = ("chs", pp_c2hs) : filter (\x -> fst x /= "chs") preprocessors } -- The hook just loads the HookedBuildInfo generated by postConfHook, unless@@ -186,150 +210,32 @@ -- Runs CUDA detection procedure and stores .buildinfo to a file. -- generateAndStoreBuildInfo :: Verbosity -> Platform -> CompilerId -> FilePath -> IO ()-generateAndStoreBuildInfo verbosity platform (CompilerId _ghcFlavor ghcVersion) path = do- installPath <- findCUDAInstallPath verbosity platform- hbi <- libraryBuildInfo installPath platform ghcVersion- storeHookedBuildInfo verbosity path hbi----- Try to locate CUDA installation by checking (in order):------ 1. CUDA_PATH environment variable--- 2. Looking for `nvcc` in `PATH`--- 3. Checking /usr/local/cuda------ In case of failure, calls die with the pretty long message from below.----findCUDAInstallPath :: Verbosity -> Platform -> IO FilePath-findCUDAInstallPath verbosity platform = do- result <- findFirstValidLocation verbosity platform (candidateCUDAInstallPaths verbosity platform)- case result of- Just installPath -> do- notice verbosity $ printf "Found CUDA toolkit at: %s" installPath- return installPath- Nothing -> die cudaNotFoundMsg----- Function iterates over action yielding possible locations, evaluating them--- and returning the first valid one. Returns Nothing if no location matches.----findFirstValidLocation :: Verbosity -> Platform -> [(IO FilePath, String)] -> IO (Maybe FilePath)-findFirstValidLocation verbosity platform = go- where- go :: [(IO FilePath, String)] -> IO (Maybe FilePath)- go [] = return Nothing- go (x:xs) = do- let (path,desc) = x- info verbosity $ printf "checking for %s" desc- found <- validateIOLocation verbosity platform path- if found- then Just `fmap` path- else go xs----- Evaluates IO to obtain the path, handling any possible exceptions.--- If path is evaluable and points to valid CUDA toolkit returns True.----validateIOLocation :: Verbosity -> Platform -> IO FilePath -> IO Bool-validateIOLocation verbosity platform iopath =- let handler :: IOError -> IO Bool- handler err = do- info verbosity (show err)- return False- in- (iopath >>= validateLocation verbosity platform) `catch` handler----- Checks whether given location looks like a valid CUDA toolkit directory by--- testing whether the 'nvvm.h' file exists in the expected place.------ TODO: Ideally this should check also for 'libnvvm' and whether the library--- exports relevant symbols. This should be achievable with some `nm` trickery.----validateLocation :: Verbosity -> Platform -> FilePath -> IO Bool-validateLocation verbosity platform path = do- let nvvmHeader = nvvmIncludePath platform path </> "nvvm.h"- cudaHeader = cudaIncludePath platform path </> "cuda.h"- --- exists <- (&&) <$> doesFileExist nvvmHeader <*> doesFileExist cudaHeader- info verbosity $- if exists- then printf "Path accepted: %s" path- else printf "Path rejected: %s\nDoes not exist: %s or %s" path cudaHeader nvvmHeader- return exists----- Returns pairs of (action yielding candidate path, String description of that location)----candidateCUDAInstallPaths :: Verbosity -> Platform -> [(IO FilePath, String)]-candidateCUDAInstallPaths verbosity platform =- [ (getEnv "CUDA_PATH", "environment variable CUDA_PATH")- , (findInPath, "nvcc compiler executable in PATH")- , (return defaultPath, printf "default install location (%s)" defaultPath)- ]- where- findInPath :: IO FilePath- findInPath = do- nvccPath <- findProgramLocationOrError verbosity "nvcc"- -- The obtained path is likely TOOLKIT/bin/nvcc. We want to extract the- -- TOOLKIT part- return (takeDirectory $ takeDirectory nvccPath)-- defaultPath :: FilePath- defaultPath = defaultCUDAInstallPath platform---defaultCUDAInstallPath :: Platform -> FilePath-defaultCUDAInstallPath _ = "/usr/local/cuda" -- windows?----- NOTE: this function throws an exception when there is no `nvcc` in PATH.--- The exception contains a meaningful message.----findProgramLocationOrError :: Verbosity -> String -> IO FilePath-findProgramLocationOrError verbosity execName = do- location <- findProgram verbosity execName- case location of- Just path -> return path- Nothing -> ioError $ mkIOError doesNotExistErrorType ("not found: " ++ execName) Nothing Nothing+generateAndStoreBuildInfo verbosity platform (CompilerId _ghcFlavor ghcVersion) path =+ storeHookedBuildInfo verbosity path =<< libraryBuildInfo platform ghcVersion findProgram :: Verbosity -> FilePath -> IO (Maybe FilePath)-findProgram verbosity prog = do- result <- findProgramOnSearchPath verbosity defaultProgramSearchPath prog-#if MIN_VERSION_Cabal(1,25,0)- return (fmap fst result)-#else- $( case withinRange cabalVersion (orLaterVersion (Version [1,24] [])) of- True -> [| return (fmap fst result) |]- False -> [| return result |]- )-#endif+findProgram verbosity prog =+ findProgram_helper (findProgramOnSearchPath verbosity defaultProgramSearchPath prog) +class FindProgram f where+ findProgram_helper :: f -> IO (Maybe FilePath) -cudaNotFoundMsg :: String-cudaNotFoundMsg = unlines- [ "********************************************************************************"- , ""- , "The configuration process failed to locate your CUDA installation. Ensure that you have installed both the developer driver and toolkit, available from:"- , ""- , "> http://developer.nvidia.com/cuda-downloads"- , ""- , "and make sure that `nvcc` is available in your PATH, or set the CUDA_PATH environment variable appropriately. Check the above output log and run the command directly to ensure it can be located."- , ""- , "If you have a non-standard installation, you can add additional search paths using --extra-include-dirs and --extra-lib-dirs. Note that 64-bit Linux flavours often require both `lib64` and `lib` library paths, in that order."- , ""- , "********************************************************************************"- ]+instance FindProgram (IO (Maybe (FilePath, [FilePath]))) where+ findProgram_helper f = fmap fst `fmap` f +instance FindProgram (IO (Maybe FilePath)) where+ findProgram_helper f = f + -- Generates build info with flags needed for CUDA Toolkit to be properly -- visible to underlying build tools. ---libraryBuildInfo :: FilePath -> Platform -> Version -> IO HookedBuildInfo-libraryBuildInfo installPath platform@(Platform arch os) ghcVersion = do+libraryBuildInfo :: Platform -> Version -> IO HookedBuildInfo+libraryBuildInfo platform@(Platform arch os) ghcVersion = do let- libraryPaths = [nvvmLibraryPath platform installPath]- includePaths = [nvvmIncludePath platform installPath, cudaIncludePath platform installPath]+ -- XXX+ libraryPaths = [nvvmLibraryPath platform]+ includePaths = [nvvmIncludePath platform, cudaIncludePath] -- options for GHC extraLibDirs' = libraryPaths@@ -374,31 +280,6 @@ return (Just buildInfo', []) --- Location of the NVVM library relative to the base CUDA installation----nvvmPath :: Platform -> FilePath -> FilePath-nvvmPath _ base = base </> "nvvm"--nvvmIncludePath :: Platform -> FilePath -> FilePath-nvvmIncludePath platform base = nvvmPath platform base </> "include"--cudaIncludePath :: Platform -> FilePath -> FilePath-cudaIncludePath _ base = base </> "include"--nvvmLibraryPath :: Platform -> FilePath -> FilePath-nvvmLibraryPath platform@(Platform arch os) base = nvvmPath platform base </> libpath- where- libpath =- case (os, arch) of- (Windows, I386) -> "Win32"- (Windows, X86_64) -> "x64"- (OSX, _) -> "lib" -- MacOS does not distinguish 32- vs. 64-bit paths- (_, X86_64) -> "lib64" -- treat all others similarly- _ -> "lib"--nvvmLibrary :: Platform -> [String]-nvvmLibrary _ = ["nvvm"]- storeHookedBuildInfo :: Verbosity -> FilePath -> HookedBuildInfo -> IO () storeHookedBuildInfo verbosity path hbi = do notice verbosity $ "Storing parameters to " ++ path@@ -517,16 +398,18 @@ -- -- Everything below copied from Distribution.Simple.PreProcess ---#if MIN_VERSION_Cabal(1,25,0)-ppC2hs :: BuildInfo -> LocalBuildInfo -> ComponentLocalBuildInfo -> PreProcessor-ppC2hs bi lbi _clbi =-#else-ppC2hs :: BuildInfo -> LocalBuildInfo -> PreProcessor-ppC2hs bi lbi =-#endif- PreProcessor- { platformIndependent = False- , runPreProcessor = \(inBaseDir, inRelativeFile) (outBaseDir, outRelativeFile) verbosity ->+class PPC2HS f where+ pp_c2hs :: f++instance PPC2HS (BuildInfo -> LocalBuildInfo -> ComponentLocalBuildInfo -> PreProcessor) where+ pp_c2hs bi lbi _ = pp_c2hs bi lbi++instance PPC2HS (BuildInfo -> LocalBuildInfo -> PreProcessor) where+ pp_c2hs bi lbi =+ PreProcessor+ { platformIndependent = False+ , runPreProcessor = \(inBaseDir, inRelativeFile)+ (outBaseDir, outRelativeFile) verbosity -> rawSystemProgramConf verbosity c2hsProgram (withPrograms lbi) . filter (not . null) $ maybe [] words (lookup "x-extra-c2hs-options" (customFieldsBI bi)) ++ ["--include=" ++ outBaseDir]@@ -534,7 +417,7 @@ ++ ["--output-dir=" ++ outBaseDir, "--output=" ++ outRelativeFile, inBaseDir </> inRelativeFile]- }+ } getCppOptions :: BuildInfo -> LocalBuildInfo -> [String] getCppOptions bi lbi
nvvm.cabal view
@@ -1,5 +1,5 @@ name: nvvm-version: 0.7.5.2+version: 0.8.0.0 synopsis: FFI bindings to NVVM description: The NVVM library compiles NVVM IR (a subset of LLVM IR) into PTX code which@@ -17,11 +17,8 @@ . <https://developer.nvidia.com/cuda-toolkit> .- The configure step will look for your CUDA installation in the standard- places, and if the `nvcc` compiler is found in your `PATH`, relative to that.- .- This package tested with version 7.5 of the CUDA toolkit.- .+ See the <https://travis-ci.org/tmcdonell/nvvm travis-ci.org> build matrix+ for tested CUDA library versions. license: BSD3 license-file: LICENSE@@ -45,6 +42,7 @@ setup-depends: base >= 4.6 , Cabal >= 1.22+ , cuda >= 0.8 , directory >= 1.0 , filepath >= 1.0 , template-haskell@@ -52,7 +50,12 @@ library default-language: Haskell2010 include-dirs: .- ghc-options: -Wall -O2+ ghc-options:+ -Wall+ -O2+ -funbox-strict-fields+ -fwarn-tabs+ -fno-warn-unused-imports exposed-modules: Foreign.NVVM@@ -66,7 +69,7 @@ build-depends: base >= 4.6 && < 5 , bytestring- , cuda >= 0.7+ , cuda >= 0.8 , template-haskell build-tools:@@ -80,7 +83,7 @@ source-repository this type: git location: https://github.com/tmcdonell/nvvm- tag: v0.7.5.2+ tag: v0.8.0.0 -- vim: nospell