diff options
| author | ruki <[email protected]> | 2022-02-14 16:18:48 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-02-14 16:18:48 +0800 |
| commit | 8c0b564b4f3cdb62680dc70b91bc39a335f5d429 (patch) | |
| tree | 90f289b2e6146bf3b5e2e81488a203b2c5a1b261 | |
| parent | 496204b4285a78456d54d26e34f0c70dfa5fe7e0 (diff) | |
| parent | 5bcd2bbb668d73d4619be28e601b9c8d1b109175 (diff) | |
Merge pull request #2057 from xq114/dev
improve cuda detection
| -rw-r--r-- | xmake/modules/detect/sdks/find_cuda.lua | 75 | ||||
| -rw-r--r-- | xmake/modules/lib/detect/find_cudadevices.lua | 2 | ||||
| -rw-r--r-- | xmake/modules/private/detect/find_cudatool.lua | 23 | ||||
| -rw-r--r-- | xmake/plugins/project/vsxmake/getinfo.lua | 3 |
4 files changed, 70 insertions, 33 deletions
diff --git a/xmake/modules/detect/sdks/find_cuda.lua b/xmake/modules/detect/sdks/find_cuda.lua index 0f2b28cef..6189ca58e 100644 --- a/xmake/modules/detect/sdks/find_cuda.lua +++ b/xmake/modules/detect/sdks/find_cuda.lua @@ -20,41 +20,73 @@ -- imports import("lib.detect.find_file") +import("lib.detect.find_programver") import("core.base.option") import("core.base.global") import("core.project.config") import("core.cache.detectcache") -- find cuda sdk directory -function _find_sdkdir() +function _find_sdkdir(version) -- init the search directories local paths = {} - if os.host() == "macosx" then - table.insert(paths, "/Developer/NVIDIA/CUDA/bin") - table.insert(paths, "/Developer/NVIDIA/CUDA*/bin") - elseif os.host() == "windows" then - table.insert(paths, "$(env CUDA_PATH)/bin") + if version then + if is_host("macosx") then + table.insert(paths, format("/Developer/NVIDIA/CUDA-%s/bin", version)) + elseif is_host("windows") then + table.insert(paths, format("$(env CUDA_PATH_V%s)/bin", version:gsub("%.", "_"))) + table.insert(paths, format("C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v%s\\bin", version)) + else + table.insert(paths, format("/usr/local/cuda-%s/bin", version)) + end else - -- find from default symbol link dir - table.insert(paths, "/usr/local/cuda/bin") - table.insert(paths, "/usr/local/cuda*/bin") + if is_host("macosx") then + table.insert(paths, "/Developer/NVIDIA/CUDA/bin") + table.insert(paths, "/Developer/NVIDIA/CUDA*/bin") + elseif is_host("windows") then + table.insert(paths, "$(env CUDA_PATH)/bin") + table.insert(paths, "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\*\\bin") + else + -- find from default symbol link dir + table.insert(paths, "/usr/local/cuda/bin") + table.insert(paths, "/usr/local/cuda*/bin") + end + table.insert(paths, "$(env PATH)") end - table.insert(paths, "$(env PATH)") -- attempt to find nvcc - local nvcc = find_file(os.host() == "windows" and "nvcc.exe" or "nvcc", paths) + local nvcc = find_file(is_host("windows") and "nvcc.exe" or "nvcc", paths) if nvcc then return path.directory(path.directory(nvcc)) end end +-- find cuda msbuild extensions +function _find_msbuildextensionsdir(sdkdir) + local props = find_file("CUDA *.props", {path.join(sdkdir, "extras", "visual_studio_integration", "MSBuildExtensions")}) + if props then + return path.directory(props) + end +end + -- find cuda sdk toolchains function _find_cuda(sdkdir) + -- check sdkdir + if sdkdir and not os.isdir(sdkdir) and not sdkdir:match("^[%d*]+%.[%d*]+$") then + raise("invalid cuda version/location: " .. sdkdir) + end + -- find cuda directory - if not sdkdir or not os.isdir(sdkdir) then + if not sdkdir then sdkdir = _find_sdkdir() + elseif sdkdir:match("^[%d*]+%.[%d*]+$") then + local cudaversion = sdkdir + sdkdir = _find_sdkdir(cudaversion) + if not sdkdir then + raise("cuda version %s not found!", cudaversion) + end end -- not found? @@ -70,10 +102,10 @@ function _find_cuda(sdkdir) -- get linkdirs local linkdirs = {} - if is_plat("windows") then + if is_host("windows") then local subdir = is_arch("x64") and "x64" or "Win32" table.insert(linkdirs, path.join(sdkdir, "lib", subdir)) - elseif is_plat("linux") and is_arch("x86_64") then + elseif is_host("linux") and is_arch("x86_64") then table.insert(linkdirs, path.join(sdkdir, "lib64", "stubs")) table.insert(linkdirs, path.join(sdkdir, "lib64")) else @@ -84,13 +116,22 @@ function _find_cuda(sdkdir) -- get includedirs local includedirs = {path.join(sdkdir, "include")} + -- get version + local version = find_programver(path.join(bindir, "nvcc"), {parse = "release (%d+%.%d+),"}) + + -- find msbuildextensionsdir on windows + local msbuildextensionsdir + if is_host("windows") then + msbuildextensionsdir = _find_msbuildextensionsdir(sdkdir) + end + -- get toolchains - return {sdkdir = sdkdir, bindir = bindir, linkdirs = linkdirs, includedirs = includedirs} + return {sdkdir = sdkdir, bindir = bindir, version = version, linkdirs = linkdirs, includedirs = includedirs, msbuildextensionsdir = msbuildextensionsdir} end -- find cuda sdk toolchains -- --- @param sdkdir the cuda sdk directory +-- @param sdkdir the cuda sdk directory or version -- @param opt the argument options -- -- @return the cuda sdk toolchains. e.g. {sdkdir = ..., bindir = .., linkdirs = ..., includedirs = ..., .. } @@ -98,6 +139,8 @@ end -- @code -- -- local toolchains = find_cuda("/Developer/NVIDIA/CUDA-9.1") +-- local toolchains = find_cuda("9.1") +-- local toolchains = find_cuda("9.*") -- -- @endcode -- diff --git a/xmake/modules/lib/detect/find_cudadevices.lua b/xmake/modules/lib/detect/find_cudadevices.lua index d2c83c663..dcf4a4229 100644 --- a/xmake/modules/lib/detect/find_cudadevices.lua +++ b/xmake/modules/lib/detect/find_cudadevices.lua @@ -240,6 +240,8 @@ function _order_by_flops(devices) , [72] = 64 , [75] = 64 , [80] = 64 + , [86] = 128 + , [87] = 128 } for _, dev in ipairs(devices) do diff --git a/xmake/modules/private/detect/find_cudatool.lua b/xmake/modules/private/detect/find_cudatool.lua index 6b0630ece..b5e211d14 100644 --- a/xmake/modules/private/detect/find_cudatool.lua +++ b/xmake/modules/private/detect/find_cudatool.lua @@ -45,23 +45,16 @@ function main(toolname, parse, opt) opt = opt or {} opt.parse = opt.parse or parse - -- find program - local program = nil - if opt.program then - program = find_program(opt.program, opt) - end - - -- not found? attempt to find program from cuda toolchains - if not program then - local toolchains = find_cuda() - if toolchains and toolchains.bindir then - program = find_program(path.join(toolchains.bindir, toolname), opt) - end + -- always keep consistency with cuda cache + local toolchains = find_cuda() + if toolchains and toolchains.bindir then + program = find_program(path.join(toolchains.bindir, opt.program or toolname), opt) end - -- not found? attempt to find program from PATH - if not program then - program = find_program(toolname, opt) + -- not found? attempt to find program only + local program = nil + if opt.program then + program = find_program(opt.program or toolname, opt) end -- find program version diff --git a/xmake/plugins/project/vsxmake/getinfo.lua b/xmake/plugins/project/vsxmake/getinfo.lua index 2b0264021..37afb8dd2 100644 --- a/xmake/plugins/project/vsxmake/getinfo.lua +++ b/xmake/plugins/project/vsxmake/getinfo.lua @@ -351,11 +351,10 @@ function main(outputdir, vsinfo) vsinfo.projectdir = project.directory() vsinfo.sln_projectfile = path.relative(project.rootfile(), vsinfo.solution_dir) local projectfile = path.filename(project.rootfile()) - vsinfo.slnfile = path.filename(project.directory()) + vsinfo.slnfile = project.name() or path.filename(project.directory()) -- write only if not default if projectfile ~= "xmake.lua" then vsinfo.projectfile = projectfile - vsinfo.slnfile = path.basename(projectfile) end vsinfo.xmake_info = format("xmake version %s", xmake.version()) |
