From 60ddb4c5a6725d11a7821d691dfd53c23df282bc Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 9 Jun 2019 23:15:08 +0800 Subject: improve to the device link for cuda --- xmake/rules/cuda/device_link/xmake.lua | 29 ++++++++++++++++++++--------- xmake/rules/cuda/gencodes/xmake.lua | 8 ++++++-- 2 files changed, 26 insertions(+), 11 deletions(-) (limited to 'xmake/rules') diff --git a/xmake/rules/cuda/device_link/xmake.lua b/xmake/rules/cuda/device_link/xmake.lua index 4cd63646f..43905f044 100644 --- a/xmake/rules/cuda/device_link/xmake.lua +++ b/xmake/rules/cuda/device_link/xmake.lua @@ -21,6 +21,18 @@ -- define rule: device-link rule("cuda.device_link") + -- after load + after_load(function (target) + + -- get cuda directory + local cuda_dir = assert(get_config("cuda"), "Cuda SDK directory not found!") + + -- add links + target:add("links", "cudart") + target:add("linkdirs", path.join(cuda_dir, "lib")) + target:add("rpathdirs", path.join(cuda_dir, "lib")) + end) + -- before link before_link(function (target, opt) @@ -29,13 +41,13 @@ rule("cuda.device_link") import("core.theme.theme") import("core.project.config") import("core.project.depend") - import("core.platform.platform") + import("core.tool.linker") - -- get nvcc - local nvcc = assert(platform.tool("cu-ld"), "nvcc not found!") + -- load linker instance + local linkinst = linker.load("gpucode", "cu", {target = target}) -- get link flags - local linkflags = {"-dlink"} + local linkflags = linkinst:linkflags({target = target, configs = {force = {culdflags = "-dlink"}}}) -- get target file local targetfile = target:objectfile(path.join(".cuda", "devlink", target:basename() .. "_gpucode.cu")) @@ -76,17 +88,16 @@ rule("cuda.device_link") cprint("${color.build.target}devlinking.$(mode) %s", path.filename(targetfile)) end - -- ensure the target directory - local targetdir = path.directory(targetfile) - if not os.isdir(targetdir) then - os.mkdir(targetdir) + -- trace verbose info + if verbose then + print(linkinst:linkcmd(objectfiles, targetfile, {linkflags = linkflags})) end -- flush io buffer to update progress info io.flush() -- link it - os.vrunv(nvcc, table.join(linkflags, objectfiles, "-o", targetfile)) + assert(linkinst:link(objectfiles, targetfile, {linkflags = linkflags})) -- update files and values to the dependent file dependinfo.files = depfiles diff --git a/xmake/rules/cuda/gencodes/xmake.lua b/xmake/rules/cuda/gencodes/xmake.lua index d7dedb197..1cd92fa5a 100644 --- a/xmake/rules/cuda/gencodes/xmake.lua +++ b/xmake/rules/cuda/gencodes/xmake.lua @@ -117,11 +117,15 @@ rule("cuda.gencodes") end end - for _, v in ipairs(target:values("cuda.gencode")) do + local cugencodes = table.wrap(target:get("cugencodes")) + for _, opt in ipairs(target:orderopts()) do + table.join2(gencodes, opt:get("cugencodes")) + end + for _, v in ipairs(cugencodes) do local flag = nf_cugencode(v) if flag then target:add('cuflags', flag) - target:add('ldflags', flag) + target:add('culdflags', flag) end end end) -- cgit v1.3.1