From 346e2cf549cbd030cadc2d735bb4053da25f751d Mon Sep 17 00:00:00 2001 From: qiuyi Date: Mon, 5 Jan 2026 15:31:27 +0800 Subject: support 'a' and 'f' suffix for arch > sm_90/compute_90 --- xmake/rules/cuda/gencodes/xmake.lua | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/xmake/rules/cuda/gencodes/xmake.lua b/xmake/rules/cuda/gencodes/xmake.lua index 0da3deb56..51b03468f 100644 --- a/xmake/rules/cuda/gencodes/xmake.lua +++ b/xmake/rules/cuda/gencodes/xmake.lua @@ -75,10 +75,21 @@ rule("cuda.gencodes") if not value:startswith(prefix) then return nil end - local arch = tonumber(value:sub(#prefix + 1)) or tonumber(value:sub(#prefix + 2)) + local arch_str = value:sub(#prefix + 1) + if arch_str:startswith("_") then + arch_str = arch_str:sub(2) + end + local arch_ver, suffix = arch_str:match("^(%d+)([af]?)$") + local arch = tonumber(arch_ver) if arch == nil then raise("unknown architecture: " .. value) end + if suffix == 'a' and arch < 90 then + raise("unknown architecture: " .. prefix .. "_" .. arch .. suffix) + end + if suffix == 'f' and arch < 100 then + raise("unknown architecture: " .. prefix .. "_" .. arch .. suffix) + end if not know_list:has(arch) then if arch <= table.maxn(know_list:data()) then raise("unknown architecture: " .. prefix .. "_" .. arch) @@ -86,6 +97,9 @@ rule("cuda.gencodes") utils.warning("unknown architecture: " .. prefix .. "_" .. arch) end end + if suffix and #suffix > 0 then + return arch .. suffix + end return arch end -- cgit v1.3.1 From 873bcdb3fefcee27023f356d24745815293a946d Mon Sep 17 00:00:00 2001 From: qiuyi Date: Mon, 5 Jan 2026 16:06:36 +0800 Subject: fix r_arch to v_arch convert failed when suffix is added --- xmake/rules/cuda/gencodes/xmake.lua | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/xmake/rules/cuda/gencodes/xmake.lua b/xmake/rules/cuda/gencodes/xmake.lua index 51b03468f..d27a3cb7c 100644 --- a/xmake/rules/cuda/gencodes/xmake.lua +++ b/xmake/rules/cuda/gencodes/xmake.lua @@ -136,7 +136,18 @@ rule("cuda.gencodes") if v_arch then table.insert(r_archs, v_arch) else - v_arch = math.min(table.unpack(r_archs)) + v_arch = r_archs[1] + local v_arch_ver = type(v_arch) == "string" and tonumber(v_arch:match("^(%d+)")) or v_arch + for i = 2, #r_archs do + local r_arch = r_archs[i] + local r_arch_ver = type(r_arch) == "string" and tonumber(r_arch:match("^(%d+)")) or r_arch + if r_arch_ver < v_arch_ver then + v_arch = r_arch + v_arch_ver = r_arch_ver + elseif r_arch_ver == v_arch_ver and type(r_arch) == "number" and type(v_arch) == "string" then + v_arch = r_arch + end + end end r_archs = table.unique(r_archs) -- cgit v1.3.1 From 9e8d38dd751c6bd3701df49ed1b7709331691f64 Mon Sep 17 00:00:00 2001 From: qiuyi Date: Mon, 5 Jan 2026 18:04:55 +0800 Subject: add some comments according to code review --- xmake/rules/cuda/gencodes/xmake.lua | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/xmake/rules/cuda/gencodes/xmake.lua b/xmake/rules/cuda/gencodes/xmake.lua index d27a3cb7c..bf2a52d27 100644 --- a/xmake/rules/cuda/gencodes/xmake.lua +++ b/xmake/rules/cuda/gencodes/xmake.lua @@ -71,6 +71,11 @@ rule("cuda.gencodes") local v_arch = nil local r_archs = {} + -- full legal value list could be found in nvcc docs + -- https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html#gpu-name-gpuname-arch + -- examples: sm_75, compute_75, sm_90a, compute_100, sm_100f, compute_100a, etc. + -- For robustness, xmake support a unoffical format: sm75, compute75, etc. New version still support it. + -- examples: sm75, compute75, sm90a, compute100, sm100f, compute100a, etc. local function parse_arch(value, prefix, know_list) if not value:startswith(prefix) then return nil @@ -79,6 +84,8 @@ rule("cuda.gencodes") if arch_str:startswith("_") then arch_str = arch_str:sub(2) end + + -- a legal arch_str should be like: 75, 90a, 100f, etc. local arch_ver, suffix = arch_str:match("^(%d+)([af]?)$") local arch = tonumber(arch_ver) if arch == nil then -- cgit v1.3.1