diff options
| author | ruki <[email protected]> | 2019-06-18 22:39:36 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2019-06-18 22:39:36 +0800 |
| commit | 96bda12356f3d69edae33a31d384d28b1ef74274 (patch) | |
| tree | fe35918e6ddb0cfdaca7b5333becf9b19c007a38 /xmake/modules | |
| parent | b441b29b947c8d94c0642132383b4a7a67c189c9 (diff) | |
| parent | 98d4504577b586ef2398346a0db2743081cf03a8 (diff) | |
Merge pull request #455 from OpportunityLiu/clang-cuda
Support clang as cuda compiler
Diffstat (limited to 'xmake/modules')
| -rw-r--r-- | xmake/modules/core/tools/clang.lua | 23 | ||||
| -rw-r--r-- | xmake/modules/core/tools/nvcc.lua | 10 | ||||
| -rw-r--r-- | xmake/modules/detect/sdks/find_cuda.lua | 1 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/find_nvcc.lua | 13 | ||||
| -rw-r--r-- | xmake/modules/lib/detect/find_cudadevices.lua | 52 |
5 files changed, 67 insertions, 32 deletions
diff --git a/xmake/modules/core/tools/clang.lua b/xmake/modules/core/tools/clang.lua index b7291b285..a57dd924f 100644 --- a/xmake/modules/core/tools/clang.lua +++ b/xmake/modules/core/tools/clang.lua @@ -23,15 +23,26 @@ inherit("gcc") -- init it function init(self) - + -- init super _super.init(self) + if not is_plat("windows", "mingw") then + self:add("shared.cuflags", "-fPIC") + end + -- suppress warning self:add("cxflags", "-Qunused-arguments") + self:add("cuflags", "-Qunused-arguments") self:add("mxflags", "-Qunused-arguments") self:add("asflags", "-Qunused-arguments") + local cuda = get_config("cuda") + if cuda then + local cuda_path = "--cuda-path=" .. os.args(path.translate(cuda)) + self:add("cuflags", cuda_path) + end + -- init flags map self:set("mapflags", { @@ -44,6 +55,16 @@ function init(self) -- strip , ["-s"] = "-s" , ["-S"] = "-S" + + -- rdc + , ["-rdc=true"] = "-fcuda-rdc" + , ["-rdc true"] = "-fcuda-rdc" + , ["--relocatable-device-code=true"] = "-fcuda-rdc" + , ["--relocatable-device-code true"] = "-fcuda-rdc" + , ["-rdc=false"] = "" + , ["-rdc false"] = "" + , ["--relocatable-device-code=false"] = "" + , ["--relocatable-device-code false"] = "" }) end diff --git a/xmake/modules/core/tools/nvcc.lua b/xmake/modules/core/tools/nvcc.lua index 592634ac8..e72857a93 100644 --- a/xmake/modules/core/tools/nvcc.lua +++ b/xmake/modules/core/tools/nvcc.lua @@ -29,11 +29,17 @@ import("private.tools.nvcc.parse_deps") -- init it function init(self) - -- init flags - if not is_plat("windows") then + -- init cuflags + if not is_plat("windows", "mingw") then self:set("shared.cuflags", "-Xcompiler -fPIC") end + -- add -ccbin + local cu_ccbin = get_config("cu-ccbin") + if cu_ccbin then + self:add("cuflags", "-ccbin=" .. os.args(cu_ccbin)) + end + -- init flags map self:set("mapflags", { diff --git a/xmake/modules/detect/sdks/find_cuda.lua b/xmake/modules/detect/sdks/find_cuda.lua index f9077a485..b7fb4911e 100644 --- a/xmake/modules/detect/sdks/find_cuda.lua +++ b/xmake/modules/detect/sdks/find_cuda.lua @@ -37,6 +37,7 @@ function _find_sdkdir() else table.insert(pathes, "/usr/local/cuda*/bin") end + table.insert(pathes, "$(env PATH)") -- attempt to find nvcc local nvcc = find_file(os.host() == "windows" and "nvcc.exe" or "nvcc", pathes) diff --git a/xmake/modules/detect/tools/find_nvcc.lua b/xmake/modules/detect/tools/find_nvcc.lua index 5b00510c1..5cd11e3dc 100644 --- a/xmake/modules/detect/tools/find_nvcc.lua +++ b/xmake/modules/detect/tools/find_nvcc.lua @@ -43,8 +43,12 @@ function main(opt) opt = opt or {} opt.parse = opt.parse or "V(%d+%.?%d*%.?%d*.-)%s" + local program = nil + -- find program - local program = find_program(opt.program or "nvcc", opt) + if opt.program then + program = find_program(opt.program, opt) + end -- not found? attempt to find program from cuda toolchains if not program then @@ -54,9 +58,14 @@ function main(opt) end end + -- not found? attempt to find program from PATH + if not program then + program = find_program("nvcc", opt) + end + -- find program version local version = nil - if program and opt and opt.version then + if program and opt.version then version = find_programver(program, opt) end diff --git a/xmake/modules/lib/detect/find_cudadevices.lua b/xmake/modules/lib/detect/find_cudadevices.lua index aa44fe0fb..63874685d 100644 --- a/xmake/modules/lib/detect/find_cudadevices.lua +++ b/xmake/modules/lib/detect/find_cudadevices.lua @@ -23,6 +23,8 @@ import("core.base.option") import("core.platform.platform") import("core.project.config") import("lib.detect.cache") +import("lib.detect.find_tool") +import("detect.sdks.find_cuda") -- a magic string to filter output local _PRINT_SUFFIX = "<find_cudadevices>" @@ -30,7 +32,7 @@ local _PRINT_SUFFIX = "<find_cudadevices>" -- filter stdout and stderr with _PRINT_SUFFIX function _get_lines(str) local result = {} - for _, l in ipairs(str:split('\n')) do + for _, l in ipairs(str:split("\n")) do if l:startswith(_PRINT_SUFFIX) then table.insert(result, l:sub(#_PRINT_SUFFIX + 1)) end @@ -55,8 +57,8 @@ function _parse_value(value) return value:sub(2, -2) end - if value:startswith('(') and value:endswith(')') then - local values = value:sub(2, -2):split(',') + if value:startswith("(") and value:endswith(")") then + local values = value:sub(2, -2):split(",") local result = {} for _, v in ipairs(values) do table.insert(result, _parse_value(v:trim())) @@ -77,7 +79,7 @@ function _parse_line(line, device) if key and value then key = key:trim() value = value:trim() - assert(not device[key], 'duplicate key: ' .. key) + assert(not device[key], "duplicate key: " .. key) device[key] = _parse_value(value) end end @@ -99,7 +101,7 @@ function _parse_result(lines, verbose) end local devId = tonumber(l:match("%s*DEVICE #(%d+)")) if devId then - currentDevice = { ['$id'] = devId } + currentDevice = { ["$id"] = devId } table.insert(devices, currentDevice) elseif currentDevice then _parse_line(l, currentDevice) @@ -111,32 +113,28 @@ end -- find devices function _find_devices(verbose) - - local nvcc = platform.tool("cu") - if nvcc == nil then - raise('nvcc not found') - end + local nvcc = assert(find_tool("nvcc"), "nvcc not found") if verbose then cprint("${dim}checking for cuda devices") end - local sourcefile = path.join(os.programdir(), 'scripts', 'find_cudadevices.cpp') + local sourcefile = path.join(os.programdir(), "scripts", "find_cudadevices.cpp") local outfile = os.tmpfile() + local args = { sourcefile, "-run", "-o", outfile , '-DPRINT_SUFFIX="' .. _PRINT_SUFFIX .. '"' } + local compile_errors = nil - local results, errors = try - { + local results, errors = try + { function () - local archs = { i386 = "-m32", x86 = "-m32", x86_64 = "-m64", x64 = "-m64" } - local arch = archs[config.get("arch")] or "" - return os.iorunv(nvcc, { sourcefile, arch, '-run', '-o', outfile , '-DPRINT_SUFFIX="' .. _PRINT_SUFFIX .. '"' }) - end, - catch + return os.iorunv(nvcc.program, args) + end, + catch { - function (errs) - compile_errors = tostring(errs) + function (errs) + compile_errors = tostring(errs) end - } + } } if compile_errors then @@ -149,13 +147,13 @@ function _find_devices(verbose) -- clean up os.tryrm(outfile) - os.tryrm(outfile .. '.*') + os.tryrm(outfile .. ".*") -- get results local results_lines = _get_lines(results) local errors_lines = _get_lines(errors) if #errors_lines ~= 0 then - utils.warning("failed to find cuda devices: " .. table.concat(errors_lines, '\n')) + utils.warning("failed to find cuda devices: " .. table.concat(errors_lines, "\n")) return nil end @@ -163,7 +161,7 @@ function _find_devices(verbose) local devices = _parse_result(results_lines, option.get("diagnosis")) if verbose then for _, v in ipairs(devices) do - cprint("${dim}> found device #%d: ${green bright}%s${reset dim} with compute ${bright}%d.%d${reset dim} capability", v['$id'], v.name, v.major, v.minor) + cprint("${dim}> found device #%d: ${green bright}%s${reset dim} with compute ${bright}%d.%d${reset dim} capability", v["$id"], v.name, v.major, v.minor) end end return devices @@ -244,10 +242,10 @@ function _order_by_flops(devices) else sm_per_multiproc = ngpu_arch_cores_per_sm[dev.major * 10 + dev.minor] or 64; end - dev['$flops'] = dev.multiProcessorCount * sm_per_multiproc * dev.clockRate + dev["$flops"] = dev.multiProcessorCount * sm_per_multiproc * dev.clockRate end - table.sort(devices, function (a,b) return a['$flops'] > b['$flops'] end) + table.sort(devices, function (a,b) return a["$flops"] > b["$flops"] end) return devices end @@ -256,7 +254,7 @@ end -- @param opt the options -- e.g. { verbose = false, force = false, cachekey = "xxxx", min_sm_arch = 35, skip_compute_mode_prohibited = false, order_by_flops = true } -- --- @return { { ['$id'] = 0, name = "GeForce GTX 960M", major = 5, minor = 0, ... }, ... } +-- @return { { ["$id"] = 0, name = "GeForce GTX 960M", major = 5, minor = 0, ... }, ... } -- for all keys, see https://docs.nvidia.com/cuda/cuda-runtime-api/structcudaDeviceProp.html#structcudaDeviceProp -- keys might be differ as your cuda version varies -- |
