From 47755e46178eadda96613d2095d1d551c6033753 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Sat, 8 Aug 2020 18:23:32 +0800 Subject: add cuda11 support --- README.md | 2 +- README_zh.md | 2 +- tests/projects/cuda/console/xmake.lua | 4 ++-- tests/projects/cuda/console_2/xmake.lua | 2 +- xmake/modules/lib/detect/find_cudadevices.lua | 1 + xmake/rules/cuda/gencodes/xmake.lua | 5 +++-- xmake/templates/cuda/console/project/xmake.lua | 4 ++-- 7 files changed, 11 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index c05ab20fa..1846cb1c9 100644 --- a/README.md +++ b/README.md @@ -278,7 +278,7 @@ target("test") set_kind("binary") add_files("src/*.cu") add_cugencodes("native") - add_cugencodes("compute_30") + add_cugencodes("compute_35") ``` WDK/UMDF Driver Program: diff --git a/README_zh.md b/README_zh.md index cd4b639f1..7ee83a15e 100644 --- a/README_zh.md +++ b/README_zh.md @@ -280,7 +280,7 @@ target("test") set_kind("binary") add_files("src/*.cu") add_cugencodes("native") - add_cugencodes("compute_30") + add_cugencodes("compute_35") ``` WDK/UMDF驱动程序: diff --git a/tests/projects/cuda/console/xmake.lua b/tests/projects/cuda/console/xmake.lua index bf69c8c1e..d6137c9d8 100644 --- a/tests/projects/cuda/console/xmake.lua +++ b/tests/projects/cuda/console/xmake.lua @@ -14,9 +14,9 @@ target("cuda_console") add_files("src/*.cu") -- generate SASS code for each SM architecture - add_cugencodes("sm_30", "sm_35", "sm_37", "sm_50", "sm_52", "sm_60", "sm_61", "sm_70") + add_cugencodes("sm_35", "sm_37", "sm_50", "sm_52", "sm_60", "sm_61", "sm_70", "sm_75") -- generate PTX code from the highest SM architecture to guarantee forward-compatibility - add_cugencodes("compute_70") + add_cugencodes("compute_75") diff --git a/tests/projects/cuda/console_2/xmake.lua b/tests/projects/cuda/console_2/xmake.lua index 2c445d7e3..08cc430d8 100644 --- a/tests/projects/cuda/console_2/xmake.lua +++ b/tests/projects/cuda/console_2/xmake.lua @@ -3,7 +3,7 @@ add_rules("mode.debug", "mode.release") -- generate PTX code for the virtual architecture to guarantee compatibility -add_cugencodes("compute_30") +add_cugencodes("compute_35") -- define target target("bin") diff --git a/xmake/modules/lib/detect/find_cudadevices.lua b/xmake/modules/lib/detect/find_cudadevices.lua index bd1bb72bc..98ae81e6d 100644 --- a/xmake/modules/lib/detect/find_cudadevices.lua +++ b/xmake/modules/lib/detect/find_cudadevices.lua @@ -238,6 +238,7 @@ function _order_by_flops(devices) , [70] = 64 , [72] = 64 , [75] = 64 + , [80] = 64 } for _, dev in ipairs(devices) do diff --git a/xmake/rules/cuda/gencodes/xmake.lua b/xmake/rules/cuda/gencodes/xmake.lua index e03626c6d..91af885ba 100644 --- a/xmake/rules/cuda/gencodes/xmake.lua +++ b/xmake/rules/cuda/gencodes/xmake.lua @@ -42,8 +42,9 @@ rule("cuda.gencodes") import("core.base.hashset") -- sm_20 and compute_20 is supported until CUDA 8 - local known_v_archs = hashset.of(20, 30, 32, 35, 37, 50, 52, 53, 60, 61, 62, 70, 72, 75) - local known_r_archs = hashset.of(20, 30, 32, 35, 37, 50, 52, 53, 60, 61, 62, 70, 72, 75) + -- sm_30 and compute_30 is supported until CUDA 10 + local known_v_archs = hashset.of(20, 30, 32, 35, 37, 50, 52, 53, 60, 61, 62, 70, 72, 75, 80) + local known_r_archs = hashset.of(20, 30, 32, 35, 37, 50, 52, 53, 60, 61, 62, 70, 72, 75, 80) local function nf_cugencode(archs) if type(archs) ~= 'string' then diff --git a/xmake/templates/cuda/console/project/xmake.lua b/xmake/templates/cuda/console/project/xmake.lua index 6521e605c..eec69685f 100644 --- a/xmake/templates/cuda/console/project/xmake.lua +++ b/xmake/templates/cuda/console/project/xmake.lua @@ -21,10 +21,10 @@ target("${TARGETNAME}") add_cugencodes("native") -- generate PTX code for the virtual architecture to guarantee compatibility - add_cugencodes("compute_30") + add_cugencodes("compute_35") -- -- generate SASS code for each SM architecture - -- add_cugencodes("sm_30", "sm_35", "sm_37", "sm_50", "sm_52", "sm_60", "sm_61", "sm_70", "sm_75") + -- add_cugencodes("sm_35", "sm_37", "sm_50", "sm_52", "sm_60", "sm_61", "sm_70", "sm_75") -- -- generate PTX code from the highest SM architecture to guarantee forward-compatibility -- add_cugencodes("compute_75") -- cgit v1.3.1 From cf488b53e48788b735a4da614e951bd424c677fc Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Sat, 8 Aug 2020 18:56:23 +0800 Subject: check flags --- xmake/modules/detect/tools/nvcc/has_flags.lua | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/xmake/modules/detect/tools/nvcc/has_flags.lua b/xmake/modules/detect/tools/nvcc/has_flags.lua index 8cbffc010..0ab430b20 100644 --- a/xmake/modules/detect/tools/nvcc/has_flags.lua +++ b/xmake/modules/detect/tools/nvcc/has_flags.lua @@ -112,12 +112,19 @@ function _check_try_running(flags, opt, islinker) io.writefile(sourcefile, "int main(int argc, char** argv)\n{return 0;}") end - -- check flags - if islinker then - return _try_running(opt.program, table.join(flags, "-o", os.nuldev(), sourcefile)) - else - return _try_running(opt.program, table.join(flags, "-c", "-o", os.nuldev(), sourcefile)) + local args = table.join(flags, "-o", os.nuldev(), sourcefile) + + if not islinker then + table.insert(args, 2, "-c") + end + + local allow_unsupported_compiler = main("-allow-unsupported-compiler", opt) + if allow_unsupported_compiler then + table.insert(args, 1, "-allow-unsupported-compiler") end + + -- check flags + return _try_running(opt.program, args) end -- has_flags(flags)? -- cgit v1.3.1 From 42034f35e7dba6d680ad82ab326b9dc95f3e41ba Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Sat, 8 Aug 2020 19:13:42 +0800 Subject: fix has_flags --- xmake/modules/detect/tools/nvcc/has_flags.lua | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/xmake/modules/detect/tools/nvcc/has_flags.lua b/xmake/modules/detect/tools/nvcc/has_flags.lua index 0ab430b20..40ec2e504 100644 --- a/xmake/modules/detect/tools/nvcc/has_flags.lua +++ b/xmake/modules/detect/tools/nvcc/has_flags.lua @@ -112,19 +112,21 @@ function _check_try_running(flags, opt, islinker) io.writefile(sourcefile, "int main(int argc, char** argv)\n{return 0;}") end - local args = table.join(flags, "-o", os.nuldev(), sourcefile) + local args = table.join("-o", os.nuldev(), sourcefile) if not islinker then - table.insert(args, 2, "-c") + table.insert(args, 1, "-c") end - local allow_unsupported_compiler = main("-allow-unsupported-compiler", opt) - if allow_unsupported_compiler then - table.insert(args, 1, "-allow-unsupported-compiler") + if flags[1] ~= "-allow-unsupported-compiler" then + local allow_unsupported_compiler = main({"-allow-unsupported-compiler"}, opt) + if allow_unsupported_compiler then + table.insert(args, 1, "-allow-unsupported-compiler") + end end -- check flags - return _try_running(opt.program, args) + return _try_running(opt.program, table.join(flags, args)) end -- has_flags(flags)? -- cgit v1.3.1 From 052278ef2744328d6e6d1b2620bdbbf343540708 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Sat, 8 Aug 2020 19:21:16 +0800 Subject: PIE --- xmake/modules/core/tools/nvcc.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/xmake/modules/core/tools/nvcc.lua b/xmake/modules/core/tools/nvcc.lua index 6aab1225d..24209e228 100644 --- a/xmake/modules/core/tools/nvcc.lua +++ b/xmake/modules/core/tools/nvcc.lua @@ -33,6 +33,7 @@ function init(self) -- init cuflags if not is_plat("windows", "mingw") then self:set("shared.cuflags", "-Xcompiler -fPIC") + self:set("binary.cuflags", "-Xcompiler -fPIE") end -- add -ccbin -- cgit v1.3.1 From 084e01a6ac7961fa650aba9cdc06502e4bd88b2c Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Mon, 10 Aug 2020 00:59:02 +0800 Subject: fix code style --- xmake/modules/detect/tools/nvcc/has_flags.lua | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/xmake/modules/detect/tools/nvcc/has_flags.lua b/xmake/modules/detect/tools/nvcc/has_flags.lua index 40ec2e504..2929f67bd 100644 --- a/xmake/modules/detect/tools/nvcc/has_flags.lua +++ b/xmake/modules/detect/tools/nvcc/has_flags.lua @@ -118,8 +118,11 @@ function _check_try_running(flags, opt, islinker) table.insert(args, 1, "-c") end + -- avoid recursion if flags[1] ~= "-allow-unsupported-compiler" then - local allow_unsupported_compiler = main({"-allow-unsupported-compiler"}, opt) + -- add -allow-unsupported-compiler if supported to suppress error of unsupported compiler, + -- which caused all checks failed. + local allow_unsupported_compiler = _has_flags({"-allow-unsupported-compiler"}, opt) if allow_unsupported_compiler then table.insert(args, 1, "-allow-unsupported-compiler") end @@ -135,7 +138,7 @@ end -- -- @return true or false -- -function main(flags, opt) +function _has_flags(flags, opt) -- is linker? local islinker = _islinker(flags, opt) @@ -149,3 +152,7 @@ function main(flags, opt) return _check_try_running(flags, opt, islinker) end +function main(...) + return _has_flags(...) +end + -- cgit v1.3.1