summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOpportunityLiu <[email protected]>2019-07-13 17:04:38 +0800
committerOpportunityLiu <[email protected]>2019-07-13 17:04:38 +0800
commit7cff50433386d8c7793884cddd1eb6e1c3c2681e (patch)
treee67b0271c5a9d1fe2a3ba26af613abe92d8e89a3
parent78de198d8b1dc94fce77680b219f9f512849992d (diff)
imporve hashset
-rw-r--r--xmake/core/base/hashset.lua26
-rw-r--r--xmake/rules/cuda/gencodes/xmake.lua15
2 files changed, 27 insertions, 14 deletions
diff --git a/xmake/core/base/hashset.lua b/xmake/core/base/hashset.lua
index 7ec5bd4a0..4e3b1975e 100644
--- a/xmake/core/base/hashset.lua
+++ b/xmake/core/base/hashset.lua
@@ -37,7 +37,7 @@ end
-- make a new hashset
function hashset.new()
- return setmetatable({ _DATA = {} }, hashset)
+ return setmetatable({ _DATA = {}, _SIZE = 0 }, hashset)
end
-- construct from list of items
@@ -45,7 +45,7 @@ function hashset.of(...)
local result = hashset.new()
local data = table.pack(...)
for i = 1, data.n do
- result._DATA[hashset._to_key(data[i])] = true
+ result:insert(data[i])
end
return result
end
@@ -65,9 +65,10 @@ end
-- insert value to hashset, returns false if value has already in the hashset
function hashset_impl:insert(value)
value = hashset._to_key(value)
- local result = self._DATA[value] or false
- if not result then
+ local result = not (self._DATA[value] or false)
+ if result then
self._DATA[value] = true
+ self._SIZE = self._SIZE + 1
end
return result
end
@@ -78,6 +79,7 @@ function hashset_impl:remove(value)
local result = self._DATA[value] or false
if result then
self._DATA[value] = nil
+ self._SIZE = self._SIZE - 1
end
return result
end
@@ -93,6 +95,22 @@ function hashset_impl:to_array()
return result
end
+-- get size of hashset
+function hashset_impl:size()
+ return self._SIZE
+end
+
+-- get data of hashset
+function hashset_impl:data()
+ return self._DATA
+end
+
+-- clear hashset
+function hashset_impl:clear()
+ self._DATA = {}
+ self._SIZE = 0
+end
+
-- return module
hashset.__index = hashset_impl
return hashset
diff --git a/xmake/rules/cuda/gencodes/xmake.lua b/xmake/rules/cuda/gencodes/xmake.lua
index cecf83694..785b60d30 100644
--- a/xmake/rules/cuda/gencodes/xmake.lua
+++ b/xmake/rules/cuda/gencodes/xmake.lua
@@ -38,16 +38,11 @@ rule("cuda.gencodes")
import("core.platform.platform")
import("lib.detect.find_cudadevices")
-
- local function set (list)
- local result = {}
- for _, l in ipairs(list) do result[l] = true end
- return result
- end
+ import("core.base.hashset")
-- sm_20 and compute_20 is supported until CUDA 8
- local known_v_archs = set { 20, 30, 32, 35, 37, 50, 52, 53, 60, 61, 62, 70, 72, 75, }
- local known_r_archs = set { 20, 30, 32, 35, 37, 50, 52, 53, 60, 61, 62, 70, 72, 75, }
+ 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)
local function nf_cugencode(archs)
if type(archs) ~= 'string' then
@@ -73,8 +68,8 @@ rule("cuda.gencodes")
if arch == nil then
raise("Unknown architecture: " .. value)
end
- if not know_list[arch] then
- if arch <= table.maxn(know_list) then
+ if not know_list:has(arch) then
+ if arch <= table.maxn(know_list:data()) then
raise("Unknown architecture: " .. prefix .. "_" .. arch)
else
utils.warning("Unknown architecture: " .. prefix .. "_" .. arch)