diff options
| author | ruki <[email protected]> | 2019-06-19 00:48:20 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-06-18 22:50:04 +0800 |
| commit | d6d53fa5696b012d435506d3b88edb5851c269f8 (patch) | |
| tree | f517fb5c82d58e47d4d8860907b80cdc70f2acc8 | |
| parent | 96bda12356f3d69edae33a31d384d28b1ef74274 (diff) | |
modify code style
| -rw-r--r-- | xmake/modules/core/tools/clang.lua | 2 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/find_nvcc.lua | 3 | ||||
| -rw-r--r-- | xmake/modules/lib/detect/find_cudadevices.lua | 20 | ||||
| -rw-r--r-- | xmake/rules/cuda/devlink/xmake.lua | 14 | ||||
| -rw-r--r-- | xmake/rules/cuda/env/xmake.lua | 4 |
5 files changed, 26 insertions, 17 deletions
diff --git a/xmake/modules/core/tools/clang.lua b/xmake/modules/core/tools/clang.lua index a57dd924f..76375bb67 100644 --- a/xmake/modules/core/tools/clang.lua +++ b/xmake/modules/core/tools/clang.lua @@ -27,6 +27,7 @@ function init(self) -- init super _super.init(self) + -- add cuflags if not is_plat("windows", "mingw") then self:add("shared.cuflags", "-fPIC") end @@ -37,6 +38,7 @@ function init(self) self:add("mxflags", "-Qunused-arguments") self:add("asflags", "-Qunused-arguments") + -- add cuda path local cuda = get_config("cuda") if cuda then local cuda_path = "--cuda-path=" .. os.args(path.translate(cuda)) diff --git a/xmake/modules/detect/tools/find_nvcc.lua b/xmake/modules/detect/tools/find_nvcc.lua index 5cd11e3dc..5b97f3dc9 100644 --- a/xmake/modules/detect/tools/find_nvcc.lua +++ b/xmake/modules/detect/tools/find_nvcc.lua @@ -43,9 +43,8 @@ function main(opt) opt = opt or {} opt.parse = opt.parse or "V(%d+%.?%d*%.?%d*.-)%s" - local program = nil - -- find program + local program = nil if opt.program then program = find_program(opt.program, opt) end diff --git a/xmake/modules/lib/detect/find_cudadevices.lua b/xmake/modules/lib/detect/find_cudadevices.lua index 63874685d..8e2a1ae64 100644 --- a/xmake/modules/lib/detect/find_cudadevices.lua +++ b/xmake/modules/lib/detect/find_cudadevices.lua @@ -40,13 +40,14 @@ function _get_lines(str) return result end - -- parse a single value +-- -- format: -- 1. a number: `2048` -- 2. an array: `(65536, 2048, 2048)` -- 3. bool value: `true` or `false` -- 4. string: `"string"` +-- function _parse_value(value) local num = tonumber(value) if num then return num end @@ -71,8 +72,10 @@ end -- parse single line +-- -- format: -- key = value +-- function _parse_line(line, device) local key = line:match("%s+(%g+) = .+") local value = line:match("%s+%g+ = (.+)") @@ -84,9 +87,9 @@ function _parse_line(line, device) end end - -- parse filtered lines function _parse_result(lines, verbose) + if #lines == 0 then -- not a failure, returns {} rather than nil utils.warning("no cuda devices was found") @@ -110,23 +113,25 @@ function _parse_result(lines, verbose) return devices end - -- find devices function _find_devices(verbose) + + -- find nvcc local nvcc = assert(find_tool("nvcc"), "nvcc not found") + -- trace if verbose then cprint("${dim}checking for cuda devices") end + -- get cuda devices 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 { function () + local args = { sourcefile, "-run", "-o", outfile , '-DPRINT_SUFFIX="' .. _PRINT_SUFFIX .. '"' } return os.iorunv(nvcc.program, args) end, catch @@ -167,7 +172,6 @@ function _find_devices(verbose) return devices end - -- get devices array form cache or via _find_devices function _get_devices(opt) @@ -219,7 +223,9 @@ function _min_sm_arch(devices, min_sm_arch) end function _order_by_flops(devices) - local ngpu_arch_cores_per_sm = { + + local ngpu_arch_cores_per_sm = + { [30] = 192 , [32] = 192 , [35] = 192 diff --git a/xmake/rules/cuda/devlink/xmake.lua b/xmake/rules/cuda/devlink/xmake.lua index 1cdfb2fb7..2854bc0d7 100644 --- a/xmake/rules/cuda/devlink/xmake.lua +++ b/xmake/rules/cuda/devlink/xmake.lua @@ -26,6 +26,13 @@ rule("cuda.devlink") -- @see https://devblogs.nvidia.com/separate-compilation-linking-cuda-device-code/ before_link(function (target, opt) + + -- imports + import("core.base.option") + import("core.theme.theme") + import("core.project.config") + import("core.project.depend") + import("core.tool.linker") import("core.platform.platform") -- disable devlink? @@ -39,13 +46,6 @@ rule("cuda.devlink") return end - -- imports - import("core.base.option") - import("core.theme.theme") - import("core.project.config") - import("core.project.depend") - import("core.tool.linker") - -- load linker instance local linkinst = linker.load("gpucode", "cu", {target = target}) diff --git a/xmake/rules/cuda/env/xmake.lua b/xmake/rules/cuda/env/xmake.lua index a78e13af1..a151f7fcb 100644 --- a/xmake/rules/cuda/env/xmake.lua +++ b/xmake/rules/cuda/env/xmake.lua @@ -22,8 +22,10 @@ rule("cuda.env") after_load(function (target) - -- get cuda sdk + -- imports import("detect.sdks.find_cuda") + + -- get cuda sdk local cuda = assert(find_cuda(nil, {verbose = true}), "Cuda SDK not found!") -- add arch |
