diff options
| author | ruki <[email protected]> | 2019-06-11 00:20:40 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-06-10 20:04:05 +0800 |
| commit | eefa90347085c76301cb84920ed18321362bede4 (patch) | |
| tree | ce0686f60978f82824eba380a5bdd1011e459493 | |
| parent | 5c6aa211362c4ab0d115a3987dc9ce054082f872 (diff) | |
fix some device link issues
| -rw-r--r-- | xmake/core/tool/builder.lua | 2 | ||||
| -rw-r--r-- | xmake/languages/cuda/xmake.lua | 14 | ||||
| -rw-r--r-- | xmake/platforms/linux/load.lua | 3 | ||||
| -rw-r--r-- | xmake/platforms/macosx/load.lua | 5 | ||||
| -rw-r--r-- | xmake/platforms/windows/load.lua | 1 | ||||
| -rw-r--r-- | xmake/rules/cuda/device_link/xmake.lua | 20 | ||||
| -rw-r--r-- | xmake/rules/cuda/gencodes/xmake.lua | 2 |
7 files changed, 36 insertions, 11 deletions
diff --git a/xmake/core/tool/builder.lua b/xmake/core/tool/builder.lua index 5a7dcf517..f06f007e7 100644 --- a/xmake/core/tool/builder.lua +++ b/xmake/core/tool/builder.lua @@ -361,7 +361,7 @@ function builder:_add_flags_from_argument(flags, target, args) -- add flags (named) from the language if target then local key = target:type() - self:_add_flags_from_language(flags, target, {[key] = function (name) print(name, args[name]); return args[name] end}) + self:_add_flags_from_language(flags, target, {[key] = function (name) return args[name] end}) else self:_add_flags_from_language(flags, nil, {target = function (name) return args[name] end}) end diff --git a/xmake/languages/cuda/xmake.lua b/xmake/languages/cuda/xmake.lua index 1d1f5b9d5..1949708e6 100644 --- a/xmake/languages/cuda/xmake.lua +++ b/xmake/languages/cuda/xmake.lua @@ -118,8 +118,18 @@ language("cuda") } , gpucode = { - "target.culdflags" - , "option.culdflags" + "config.linkdirs" + , "target.linkdirs" + , "option.linkdirs" + , "platform.linkdirs" + , "config.links" + , "target.links" + , "option.links" + , "platform.links" + , "config.syslinks" + , "target.syslinks" + , "option.syslinks" + , "platform.syslinks" } } diff --git a/xmake/platforms/linux/load.lua b/xmake/platforms/linux/load.lua index 4b49bec9a..184c2fa64 100644 --- a/xmake/platforms/linux/load.lua +++ b/xmake/platforms/linux/load.lua @@ -79,8 +79,9 @@ function main(platform) platform:set("rc-ldflags", "") -- init flags for cuda - local cu_archs = { i386 = "-m32 -Xcompiler -m32", x86_64 = "-m64 -Xcompiler -m64" } + local cu_archs = { i386 = "-m32", x86_64 = "-m64" } platform:add("cuflags", cu_archs[arch] or "") + platform:add("cu-ldflags", cu_archs[arch] or "") local cuda_dir = config.get("cuda") if cuda_dir then platform:add("cuflags", "-I" .. os.args(path.join(cuda_dir, "include"))) diff --git a/xmake/platforms/macosx/load.lua b/xmake/platforms/macosx/load.lua index 79c179deb..142d7997f 100644 --- a/xmake/platforms/macosx/load.lua +++ b/xmake/platforms/macosx/load.lua @@ -90,8 +90,9 @@ function main(platform) platform:set("rc-ldflags", "") -- init flags for cuda - local cuflags_arch = { i386 = "-m32 -Xcompiler -arch -Xcompiler i386", x86_64 = "-m64 -Xcompiler -arch -Xcompiler x86_64" } - platform:add("cuflags", cuflags_arch[arch] or "") + local cu_archs = { i386 = "-m32", x86_64 = "-m64" } + platform:add("cuflags", cu_archs[arch] or "") + platform:add("cu-ldflags", cu_archs[arch] or "") local cuda_dir = config.get("cuda") if cuda_dir then platform:add("cuflags", "-I" .. os.args(path.join(cuda_dir, "include"))) diff --git a/xmake/platforms/windows/load.lua b/xmake/platforms/windows/load.lua index 12a6a3cfe..444b3feb6 100644 --- a/xmake/platforms/windows/load.lua +++ b/xmake/platforms/windows/load.lua @@ -39,6 +39,7 @@ function main(platform) -- init flags for cuda local cu_archs = { x86 = "-m32", x64 = "-m64" } platform:add("cuflags", cu_archs[arch] or "") + platform:add("cu-ldflags", cu_archs[arch] or "") local cuda_dir = config.get("cuda") if cuda_dir then platform:add("cuflags", "-I" .. os.args(path.join(cuda_dir, "include"))) diff --git a/xmake/rules/cuda/device_link/xmake.lua b/xmake/rules/cuda/device_link/xmake.lua index 6c1d96983..dae37f32a 100644 --- a/xmake/rules/cuda/device_link/xmake.lua +++ b/xmake/rules/cuda/device_link/xmake.lua @@ -28,9 +28,18 @@ rule("cuda.device_link") 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")) + target:add("links", "cudadevrt", "cudart_static") + if is_plat("linux") then + target:add("links", "rt", "pthread", "dl") + end + if is_plat("windows") then + local subdir = is_arch("x64") and "x64" or "Win32" + target:add("linkdirs", path.join(cuda_dir, "lib", subdir)) + target:add("rpathdirs", path.join(cuda_dir, "lib", subdir)) + else + target:add("linkdirs", path.join(cuda_dir, "lib")) + target:add("rpathdirs", path.join(cuda_dir, "lib")) + end end) -- @see https://devblogs.nvidia.com/separate-compilation-linking-cuda-device-code/ @@ -46,8 +55,11 @@ rule("cuda.device_link") -- load linker instance local linkinst = linker.load("gpucode", "cu", {target = target}) + -- init culdflags + local culdflags = {"-dlink"} + -- get link flags - local linkflags = linkinst:linkflags({target = target, configs = {force = {culdflags = "-dlink"}}}) + local linkflags = linkinst:linkflags({target = target, configs = {force = {culdflags = culdflags}}}) -- get target file local targetfile = target:objectfile(path.join(".cuda", "devlink", target:basename() .. "_gpucode.cu")) diff --git a/xmake/rules/cuda/gencodes/xmake.lua b/xmake/rules/cuda/gencodes/xmake.lua index 1cd92fa5a..9fcdbcd3a 100644 --- a/xmake/rules/cuda/gencodes/xmake.lua +++ b/xmake/rules/cuda/gencodes/xmake.lua @@ -119,7 +119,7 @@ rule("cuda.gencodes") local cugencodes = table.wrap(target:get("cugencodes")) for _, opt in ipairs(target:orderopts()) do - table.join2(gencodes, opt:get("cugencodes")) + table.join2(cugencodes, opt:get("cugencodes")) end for _, v in ipairs(cugencodes) do local flag = nf_cugencode(v) |
