From 6f0fcf160519cdbfe5b458d71aaeaf16fc7480fc Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Fri, 17 Jan 2025 18:02:32 +0100 Subject: [PATCH 1/3] setup: Allow fallback to /lib, even on x64 systems The CUDA packages on Nix (cudatoolkit + nvidia_x11) seem to provide only a /lib directory, not a /lib64. Let's enable this fallback generally on x64 systems, not only on Nix. --- Setup.hs | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/Setup.hs b/Setup.hs index 22d1c3b..6f203c4 100644 --- a/Setup.hs +++ b/Setup.hs @@ -139,8 +139,9 @@ libraryBuildInfo -> [FilePath] -> IO HookedBuildInfo libraryBuildInfo verbosity profile installPath platform@(Platform arch os) ghcVersion extraLibs extraIncludes = do + libPath <- cudaLibraryPath platform installPath let - libraryPaths = cudaLibraryPath platform installPath : extraLibs + libraryPaths = libPath : extraLibs includePaths = cudaIncludePath platform installPath : extraIncludes takeFirstExisting paths = do @@ -217,16 +218,24 @@ cudaIncludePath _ installPath = installPath "include" -- Return the location of the libraries relative to the base CUDA installation. -- -cudaLibraryPath :: Platform -> FilePath -> FilePath -cudaLibraryPath (Platform arch os) installPath = installPath libpath +cudaLibraryPath :: Platform -> FilePath -> IO FilePath +cudaLibraryPath (Platform arch os) installPath = + case libpaths of + [path] -> return $ installPath path + _ -> do + -- attempt to choose a directory that exists + candidates <- filterM doesDirectoryExist libpaths + case candidates of + [] -> return (installPath head libpaths) -- whatever + cand:_ -> return (installPath cand) where - libpath = + libpaths = case (os, arch) of - (Windows, I386) -> "lib/Win32" - (Windows, X86_64) -> "lib/x64" - (OSX, _) -> "lib" -- MacOS does not distinguish 32- vs. 64-bit paths - (_, X86_64) -> "lib64" -- treat all others similarly - _ -> "lib" + (Windows, I386) -> ["lib/Win32"] + (Windows, X86_64) -> ["lib/x64"] + (OSX, _) -> ["lib"] -- MacOS does not distinguish 32- vs. 64-bit paths + (_, X86_64) -> ["lib64", "lib"] -- prefer lib64 for 64-bit systems + _ -> ["lib"] -- On Windows and OSX we use different libraries depending on whether we are @@ -264,7 +273,8 @@ cudaGhciLibrariesWindows -> [FilePath] -> IO [FilePath] cudaGhciLibrariesWindows platform installPath libraries = do - candidates <- mapM (importLibraryToDLLFileName platform) [ cudaLibraryPath platform installPath lib <.> "lib" | lib <- libraries ] + libPath <- cudaLibraryPath platform installPath + candidates <- mapM (importLibraryToDLLFileName platform) [ libPath lib <.> "lib" | lib <- libraries ] return [ dropExtension dll | Just dll <- candidates ] From 2b39c30aa49b147040144d8c413d94e84e636806 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Fri, 17 Jan 2025 18:19:58 +0100 Subject: [PATCH 2/3] setup: Actually check the right paths --- Setup.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Setup.hs b/Setup.hs index 6f203c4..e35a217 100644 --- a/Setup.hs +++ b/Setup.hs @@ -224,7 +224,7 @@ cudaLibraryPath (Platform arch os) installPath = [path] -> return $ installPath path _ -> do -- attempt to choose a directory that exists - candidates <- filterM doesDirectoryExist libpaths + candidates <- filterM (\d -> doesDirectoryExist (installPath d)) libpaths case candidates of [] -> return (installPath head libpaths) -- whatever cand:_ -> return (installPath cand) From 0532c4f1313ee2719878e883a828207bb9e2aecc Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Fri, 17 Jan 2025 20:16:44 +0100 Subject: [PATCH 3/3] setup: Use the existing disambiguation logic --- Setup.hs | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/Setup.hs b/Setup.hs index e35a217..be0f945 100644 --- a/Setup.hs +++ b/Setup.hs @@ -139,9 +139,8 @@ libraryBuildInfo -> [FilePath] -> IO HookedBuildInfo libraryBuildInfo verbosity profile installPath platform@(Platform arch os) ghcVersion extraLibs extraIncludes = do - libPath <- cudaLibraryPath platform installPath let - libraryPaths = libPath : extraLibs + libraryPaths = cudaLibraryPaths platform installPath ++ extraLibs includePaths = cudaIncludePath platform installPath : extraIncludes takeFirstExisting paths = do @@ -216,18 +215,10 @@ cudaIncludePath :: Platform -> FilePath -> FilePath cudaIncludePath _ installPath = installPath "include" --- Return the location of the libraries relative to the base CUDA installation. +-- Return the potential locations of the libraries relative to the base CUDA installation. -- -cudaLibraryPath :: Platform -> FilePath -> IO FilePath -cudaLibraryPath (Platform arch os) installPath = - case libpaths of - [path] -> return $ installPath path - _ -> do - -- attempt to choose a directory that exists - candidates <- filterM (\d -> doesDirectoryExist (installPath d)) libpaths - case candidates of - [] -> return (installPath head libpaths) -- whatever - cand:_ -> return (installPath cand) +cudaLibraryPaths :: Platform -> FilePath -> [FilePath] +cudaLibraryPaths (Platform arch os) installPath = [ installPath path | path <- libpaths ] where libpaths = case (os, arch) of @@ -273,8 +264,9 @@ cudaGhciLibrariesWindows -> [FilePath] -> IO [FilePath] cudaGhciLibrariesWindows platform installPath libraries = do - libPath <- cudaLibraryPath platform installPath - candidates <- mapM (importLibraryToDLLFileName platform) [ libPath lib <.> "lib" | lib <- libraries ] + candidates <- mapM (importLibraryToDLLFileName platform) + [ libPath lib <.> "lib" | libPath <- cudaLibraryPaths platform installPath + , lib <- libraries ] return [ dropExtension dll | Just dll <- candidates ]