From 2a1919432128b99ff7623a55ba9d323cb6e10bab Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 7 Jun 2019 00:35:22 +0800 Subject: add cuda rules --- xmake/rules/cuda/device_link/xmake.lua | 32 ++++++++++++++++++++ xmake/rules/cuda/env/xmake.lua | 31 ++++++++++++++++++++ xmake/rules/cuda/xmake.lua | 53 ++++++++++++++++++++++++++++++++++ 3 files changed, 116 insertions(+) create mode 100644 xmake/rules/cuda/device_link/xmake.lua create mode 100644 xmake/rules/cuda/env/xmake.lua create mode 100644 xmake/rules/cuda/xmake.lua diff --git a/xmake/rules/cuda/device_link/xmake.lua b/xmake/rules/cuda/device_link/xmake.lua new file mode 100644 index 000000000..de2c47167 --- /dev/null +++ b/xmake/rules/cuda/device_link/xmake.lua @@ -0,0 +1,32 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2019, TBOOX Open Source Group. +-- +-- @author ruki +-- @file xmake.lua +-- + +-- define rule: device-link +rule("cuda.device_link") + + -- add rule: cuda environment + add_deps("cuda.env") + + -- on link + on_link(function (target, opt) + -- TODO + print("cuda: link ..") + end) + diff --git a/xmake/rules/cuda/env/xmake.lua b/xmake/rules/cuda/env/xmake.lua new file mode 100644 index 000000000..af6810d10 --- /dev/null +++ b/xmake/rules/cuda/env/xmake.lua @@ -0,0 +1,31 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2019, TBOOX Open Source Group. +-- +-- @author ruki +-- @file xmake.lua +-- + +-- define rule: environment +rule("cuda.env") + + -- before load + before_load(function (target) + + -- find cuda + -- TODO + print("find cuda..") + end) + diff --git a/xmake/rules/cuda/xmake.lua b/xmake/rules/cuda/xmake.lua new file mode 100644 index 000000000..54d3f4215 --- /dev/null +++ b/xmake/rules/cuda/xmake.lua @@ -0,0 +1,53 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2019, TBOOX Open Source Group. +-- +-- @author ruki +-- @file xmake.lua +-- + +-- define rule: cuda static library +rule("cuda.static") + + -- add rules + add_deps("cuda.device_link") + + -- we must set kind before target.on_load(), may we will use target in on_load() + before_load(function (target) + target:set("kind", "static") + end) + +-- define rule: cuda shared library +rule("cuda.shared") + + -- add rules + add_deps("cuda.device_link") + + -- we must set kind before target.on_load(), may we will use target in on_load() + before_load(function (target) + target:set("kind", "shared") + end) + +-- define rule: cuda console +rule("cuda.console") + + -- add rules + add_deps("cuda.device_link") + + -- we must set kind before target.on_load(), may we will use target in on_load() + before_load(function (target) + target:set("kind", "binary") + end) + -- cgit v1.3.1 From d1d8b6736904134159bc6271ca1cbd26d7796ca7 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 7 Jun 2019 00:37:22 +0800 Subject: move cuda gencodes rule --- xmake/includes/add_cugencodes.lua | 101 +-------------------------- xmake/rules/cuda/gencodes/xmake.lua | 131 ++++++++++++++++++++++++++++++++++++ xmake/rules/cuda/xmake.lua | 6 +- 3 files changed, 135 insertions(+), 103 deletions(-) create mode 100644 xmake/rules/cuda/gencodes/xmake.lua diff --git a/xmake/includes/add_cugencodes.lua b/xmake/includes/add_cugencodes.lua index d68517962..71e5f8b4e 100644 --- a/xmake/includes/add_cugencodes.lua +++ b/xmake/includes/add_cugencodes.lua @@ -34,110 +34,11 @@ -- e.g. -- includes("add_cugencodes.lua") -- target("test") --- set_kind("binary") +-- add_rules("cuda.console") -- add_files("src/*.cu") -- add_cugencodes("native", "compute_50,sm_50", "compute_70") -- - - --- define rule -rule("cuda.add_cugencodes") - before_load(function (target) - - local function set (list) - local result = {} - for _, l in ipairs(list) do result[l] = true end - return result - end - - -- sm_20 and compute_20 is supported until CUDA 8 - local knownVArchs = set { 20, 30, 32, 35, 37, 50, 52, 53, 60, 61, 62, 70, 72, 75, } - local knownRArchs = set { 20, 30, 32, 35, 37, 50, 52, 53, 60, 61, 62, 70, 72, 75, } - - local function nf_cugencode(archs) - - if type(archs) ~= 'string' then - return nil - end - archs = archs:trim():lower() - if archs == 'native' then - import("lib.detect.find_cudadevices") - local device = find_cudadevices({ skip_compute_mode_prohibited = true, order_by_flops = true })[1] - if device then - return nf_cugencode('sm_' .. device.major .. device.minor) - end - return nil - end - - local vArch = nil - local rArchs = {} - - local function parse_arch(value, prefix, knowList) - if not value:startswith(prefix) then - return nil - end - local arch = tonumber(value:sub(#prefix + 1)) or tonumber(value:sub(#prefix + 2)) - if arch == nil then - raise("Unknown architecture: " .. value) - end - if not knowList[arch] then - if arch <= table.maxn(knowList) then - raise("Unknown architecture: " .. prefix .. "_" .. arch) - else - utils.warning("Unknown architecture: " .. prefix .. "_" .. arch) - end - end - return arch - end - - for _, v in ipairs(archs:split(',')) do - local arch = v:trim() - local tempRArch = parse_arch(arch, 'sm', knownRArchs) - if tempRArch then - table.insert(rArchs, tempRArch) - end - - local tempVArch = parse_arch(arch, 'compute', knownVArchs) - if tempVArch then - if vArch ~= nil then - raise("More than one virtual architecture is defined in one gpu gencode option: compute_" .. vArch .. " and compute_" .. tempVArch) - end - vArch = tempVArch - end - if not (tempRArch or tempVArch) then - raise("Unknown architecture: " .. arch) - end - end - - if vArch == nil and #rArchs == 0 then - return nil - end - if #rArchs == 0 then - return '-gencode arch=compute_' .. vArch .. ',code=compute_' .. vArch - end - - rArchs = table.unique(rArchs) - vArch = vArch or math.min(unpack(rArchs)) - if #rArchs == 1 then - return '-gencode arch=compute_' .. vArch .. ',code=sm_' .. rArchs[1] - else - return '-gencode arch=compute_' .. vArch .. ',code=[sm_' .. table.concat(rArchs, ',sm_') .. ']' - end - end - - for _, v in ipairs(target:values("cuda.gencode")) do - local flag = nf_cugencode(v) - if flag then - target:add('cuflags', flag) - target:add('ldflags', flag) - end - end - end) -rule_end() - --- add cuda gencode to target function add_cugencodes(...) - add_rules("cuda.add_cugencodes") add_values("cuda.gencode", ...) end diff --git a/xmake/rules/cuda/gencodes/xmake.lua b/xmake/rules/cuda/gencodes/xmake.lua new file mode 100644 index 000000000..c00a79490 --- /dev/null +++ b/xmake/rules/cuda/gencodes/xmake.lua @@ -0,0 +1,131 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2019, TBOOX Open Source Group. +-- +-- @author ruki +-- @file xmake.lua +-- + +-- define rule: gencodes +rule("cuda.gencodes") + + -- add rule: cuda environment + add_deps("cuda.env") + + -- add cuda `-gencode` flags to target + -- + -- the gpu arch format syntax + -- - compute_xx --> `-gencode arch=compute_xx,code=compute_xx` + -- - sm_xx --> `-gencode arch=compute_xx,code=sm_xx` + -- - sm_xx,sm_yy --> `-gencode arch=compute_xx,code=[sm_xx,sm_yy]` + -- - compute_xx,sm_yy --> `-gencode arch=compute_xx,code=sm_yy` + -- - compute_xx,sm_yy,sm_zz --> `-gencode arch=compute_xx,code=[sm_yy,sm_zz]` + -- - native --> match the fastest cuda device on current host, + -- eg. for a Tesla P100, `-gencode arch=compute_60,code=sm_60` will be added, + -- if no available device is found, no `-gencode` flags will be added + -- @seealso xmake/modules/lib/detect/find_cudadevices + -- + before_load(function (target) + + local function set (list) + local result = {} + for _, l in ipairs(list) do result[l] = true end + return result + end + + -- sm_20 and compute_20 is supported until CUDA 8 + local knownVArchs = set { 20, 30, 32, 35, 37, 50, 52, 53, 60, 61, 62, 70, 72, 75, } + local knownRArchs = set { 20, 30, 32, 35, 37, 50, 52, 53, 60, 61, 62, 70, 72, 75, } + + local function nf_cugencode(archs) + + if type(archs) ~= 'string' then + return nil + end + archs = archs:trim():lower() + if archs == 'native' then + import("lib.detect.find_cudadevices") + local device = find_cudadevices({ skip_compute_mode_prohibited = true, order_by_flops = true })[1] + if device then + return nf_cugencode('sm_' .. device.major .. device.minor) + end + return nil + end + + local vArch = nil + local rArchs = {} + + local function parse_arch(value, prefix, knowList) + if not value:startswith(prefix) then + return nil + end + local arch = tonumber(value:sub(#prefix + 1)) or tonumber(value:sub(#prefix + 2)) + if arch == nil then + raise("Unknown architecture: " .. value) + end + if not knowList[arch] then + if arch <= table.maxn(knowList) then + raise("Unknown architecture: " .. prefix .. "_" .. arch) + else + utils.warning("Unknown architecture: " .. prefix .. "_" .. arch) + end + end + return arch + end + + for _, v in ipairs(archs:split(',')) do + local arch = v:trim() + local tempRArch = parse_arch(arch, 'sm', knownRArchs) + if tempRArch then + table.insert(rArchs, tempRArch) + end + + local tempVArch = parse_arch(arch, 'compute', knownVArchs) + if tempVArch then + if vArch ~= nil then + raise("More than one virtual architecture is defined in one gpu gencode option: compute_" .. vArch .. " and compute_" .. tempVArch) + end + vArch = tempVArch + end + if not (tempRArch or tempVArch) then + raise("Unknown architecture: " .. arch) + end + end + + if vArch == nil and #rArchs == 0 then + return nil + end + if #rArchs == 0 then + return '-gencode arch=compute_' .. vArch .. ',code=compute_' .. vArch + end + + rArchs = table.unique(rArchs) + vArch = vArch or math.min(unpack(rArchs)) + if #rArchs == 1 then + return '-gencode arch=compute_' .. vArch .. ',code=sm_' .. rArchs[1] + else + return '-gencode arch=compute_' .. vArch .. ',code=[sm_' .. table.concat(rArchs, ',sm_') .. ']' + end + end + + for _, v in ipairs(target:values("cuda.gencode")) do + local flag = nf_cugencode(v) + if flag then + target:add('cuflags', flag) + target:add('ldflags', flag) + end + end + end) +rule_end() diff --git a/xmake/rules/cuda/xmake.lua b/xmake/rules/cuda/xmake.lua index 54d3f4215..2f3564f63 100644 --- a/xmake/rules/cuda/xmake.lua +++ b/xmake/rules/cuda/xmake.lua @@ -22,7 +22,7 @@ rule("cuda.static") -- add rules - add_deps("cuda.device_link") + add_deps("cuda.device_link", "cuda.gencodes") -- we must set kind before target.on_load(), may we will use target in on_load() before_load(function (target) @@ -33,7 +33,7 @@ rule("cuda.static") rule("cuda.shared") -- add rules - add_deps("cuda.device_link") + add_deps("cuda.device_link", "cuda.gencodes") -- we must set kind before target.on_load(), may we will use target in on_load() before_load(function (target) @@ -44,7 +44,7 @@ rule("cuda.shared") rule("cuda.console") -- add rules - add_deps("cuda.device_link") + add_deps("cuda.device_link", "cuda.gencodes") -- we must set kind before target.on_load(), may we will use target in on_load() before_load(function (target) -- cgit v1.3.1 From 4b28a75f3cfd24d4b37af729db14925c1389c033 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 8 Jun 2019 00:30:43 +0800 Subject: ... --- xmake/rules/cuda/env/xmake.lua | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/xmake/rules/cuda/env/xmake.lua b/xmake/rules/cuda/env/xmake.lua index af6810d10..876b85ad7 100644 --- a/xmake/rules/cuda/env/xmake.lua +++ b/xmake/rules/cuda/env/xmake.lua @@ -23,9 +23,16 @@ rule("cuda.env") -- before load before_load(function (target) - - -- find cuda - -- TODO - print("find cuda..") + if not target:data("cuda") then + local cuda = get_config("cuda") + if not cuda then + -- TODO improve find_cuda + cache + local toolchain = import("detect.sdks.find_cuda")() + if toolchain then + cuda = toolchain.cudadir + end + end + target:data_set("cuda", assert(find_qt(nil, {verbose = true}), "Qt SDK not found!")) + end end) -- cgit v1.3.1 From 754f2510e5d521097ac15a15f6ec5912bc30358d Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 8 Jun 2019 00:37:49 +0800 Subject: improve to find_cuda --- xmake/modules/detect/sdks/find_cuda.lua | 85 ++++++++++++++++++++------- xmake/modules/private/platform/check_cuda.lua | 18 +----- xmake/platforms/linux/global.lua | 4 -- xmake/platforms/macosx/global.lua | 4 -- xmake/platforms/windows/global.lua | 4 -- xmake/rules/cuda/env/xmake.lua | 11 +--- 6 files changed, 68 insertions(+), 58 deletions(-) diff --git a/xmake/modules/detect/sdks/find_cuda.lua b/xmake/modules/detect/sdks/find_cuda.lua index 259f643fe..a75dfa9f5 100644 --- a/xmake/modules/detect/sdks/find_cuda.lua +++ b/xmake/modules/detect/sdks/find_cuda.lua @@ -19,10 +19,14 @@ -- -- imports +import("lib.detect.cache") import("lib.detect.find_file") +import("core.base.option") +import("core.base.global") +import("core.project.config") -- find cuda sdk directory -function _find_cudadir() +function _find_sdkdir() -- init the search directories local pathes = {} @@ -41,12 +45,41 @@ function _find_cudadir() end end +-- find cuda sdk toolchains +function _find_cuda(sdkdir) + + -- find cuda directory + if not sdkdir or not os.isdir(sdkdir) then + sdkdir = _find_sdkdir() + end + + -- not found? + if not sdkdir or not os.isdir(sdkdir) then + return nil + end + + -- get the bin directory + local bindir = path.join(sdkdir, "bin") + if not os.isexec(path.join(bindir, "nvcc")) then + return nil + end + + -- get linkdirs + local linkdirs = {path.join(sdkdir, "lib")} + + -- get includedirs + local includedirs = {path.join(sdkdir, "include")} + + -- get toolchains + return {sdkdir = sdkdir, bindir = bindir, linkdirs = linkdirs, includedirs = includedirs} +end + -- find cuda sdk toolchains -- --- @param cudadir the cuda directory +-- @param sdkdir the cuda sdk directory -- @param opt the argument options -- --- @return the cuda sdk toolchains. .e.g {cudadir = ..., bindir = .., linkdirs = ..., includedirs = ..., .. } +-- @return the cuda sdk toolchains. .e.g {sdkdir = ..., bindir = .., linkdirs = ..., includedirs = ..., .. } -- -- @code -- @@ -54,33 +87,41 @@ end -- -- @endcode -- -function main(cudadir, opt) +function main(sdkdir, opt) -- init arguments opt = opt or {} - -- find cuda directory - if not cudadir or not os.isdir(cudadir) then - cudadir = _find_cudadir() + -- attempt to load cache first + local key = "detect.sdks.find_cuda." .. (sdkdir or "") + local cacheinfo = cache.load(key) + if not opt.force and cacheinfo.cuda then + return cacheinfo.cuda end + + -- find cuda + local cuda = _find_cuda(sdkdir or config.get("cuda") or global.get("cuda") or config.get("sdk")) + if cuda then - -- not found? - if not cudadir or not os.isdir(cudadir) then - return nil - end + -- save to config + config.set("cuda", cuda.sdkdir, {force = true, readonly = true}) - -- get the bin directory - local bindir = path.join(cudadir, "bin") - if not os.isexec(path.join(bindir, "nvcc")) then - return nil - end + -- trace + if opt.verbose or option.get("verbose") then + cprint("checking for the Cuda SDK directory ... ${color.success}%s", cuda.sdkdir) + end + else - -- get linkdirs - local linkdirs = {path.join(cudadir, "lib")} + -- trace + if opt.verbose or option.get("verbose") then + cprint("checking for the Cuda SDK directory ... ${color.nothing}${text.nothing}") + end + end - -- get includedirs - local includedirs = {path.join(cudadir, "include")} + -- save to cache + cacheinfo.cuda = cuda or false + cache.save(key, cacheinfo) - -- get toolchains - return {cudadir = cudadir, bindir = bindir, linkdirs = linkdirs, includedirs = includedirs} + -- ok? + return cuda end diff --git a/xmake/modules/private/platform/check_cuda.lua b/xmake/modules/private/platform/check_cuda.lua index 0ab59a28b..ba86fbb01 100644 --- a/xmake/modules/private/platform/check_cuda.lua +++ b/xmake/modules/private/platform/check_cuda.lua @@ -24,21 +24,9 @@ import("detect.sdks.find_cuda") -- check the cuda sdk toolchains function main(config) - - -- get the cuda directory - local cuda_dir = config.get("cuda") - if not cuda_dir then - - -- check ok? update it - local toolchains = find_cuda() - if toolchains then - - -- save it - config.set("cuda", toolchains.cudadir) - - -- trace - cprint("checking for the Cuda SDK directory ... ${green}%s", toolchains.cudadir) - end + local cuda = find_cuda(config.get("cuda"), {verbose = true}) + if cuda then + config.set("cuda", cuda.sdkdir, {force = true, readonly = true}) end end diff --git a/xmake/platforms/linux/global.lua b/xmake/platforms/linux/global.lua index 4c8318a23..22aa9239a 100644 --- a/xmake/platforms/linux/global.lua +++ b/xmake/platforms/linux/global.lua @@ -20,7 +20,6 @@ -- imports import("core.base.global") -import("private.platform.check_cuda") -- check it function main(platform, name) @@ -29,8 +28,5 @@ function main(platform, name) if name then raise("we cannot check global." .. name) end - - -- check cuda - check_cuda(global) end diff --git a/xmake/platforms/macosx/global.lua b/xmake/platforms/macosx/global.lua index 5b8ac731b..1db907fa7 100644 --- a/xmake/platforms/macosx/global.lua +++ b/xmake/platforms/macosx/global.lua @@ -20,7 +20,6 @@ -- imports import("core.base.global") -import("private.platform.check_cuda") import("private.platform.check_xcode") -- check it @@ -33,8 +32,5 @@ function main(platform, name) -- check xcode check_xcode(global, true) - - -- check cuda - check_cuda(global) end diff --git a/xmake/platforms/windows/global.lua b/xmake/platforms/windows/global.lua index 3068b81b7..2c5d7afda 100644 --- a/xmake/platforms/windows/global.lua +++ b/xmake/platforms/windows/global.lua @@ -21,7 +21,6 @@ -- imports import("core.base.global") import("private.platform.check_arch") -import("private.platform.check_cuda") import("private.platform.check_vstudio") -- clean temporary global configs @@ -44,9 +43,6 @@ function main(platform, name) -- check vstudio check_vstudio(global) - -- check cuda - check_cuda(global) - -- clean temporary global configs _clean_global() end diff --git a/xmake/rules/cuda/env/xmake.lua b/xmake/rules/cuda/env/xmake.lua index 876b85ad7..713695e69 100644 --- a/xmake/rules/cuda/env/xmake.lua +++ b/xmake/rules/cuda/env/xmake.lua @@ -23,16 +23,9 @@ rule("cuda.env") -- before load before_load(function (target) + import("detect.sdks.find_cuda") if not target:data("cuda") then - local cuda = get_config("cuda") - if not cuda then - -- TODO improve find_cuda + cache - local toolchain = import("detect.sdks.find_cuda")() - if toolchain then - cuda = toolchain.cudadir - end - end - target:data_set("cuda", assert(find_qt(nil, {verbose = true}), "Qt SDK not found!")) + target:data_set("cuda", assert(find_cuda(), "Cuda SDK not found!")) end end) -- cgit v1.3.1 From 0ed447c7d5cf6002d21d1779b2605a982e4e3ec2 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 8 Jun 2019 21:38:45 +0800 Subject: impor device-link rule --- xmake/rules/cuda/device_link/xmake.lua | 76 +++++++++++++++++++++++++++++++--- xmake/rules/cuda/env/xmake.lua | 31 -------------- xmake/rules/cuda/gencodes/xmake.lua | 3 -- 3 files changed, 70 insertions(+), 40 deletions(-) delete mode 100644 xmake/rules/cuda/env/xmake.lua diff --git a/xmake/rules/cuda/device_link/xmake.lua b/xmake/rules/cuda/device_link/xmake.lua index de2c47167..f1aaa18d4 100644 --- a/xmake/rules/cuda/device_link/xmake.lua +++ b/xmake/rules/cuda/device_link/xmake.lua @@ -21,12 +21,76 @@ -- define rule: device-link rule("cuda.device_link") - -- add rule: cuda environment - add_deps("cuda.env") + -- before link + before_link(function (target, opt) - -- on link - on_link(function (target, opt) - -- TODO - print("cuda: link ..") + -- imports + import("core.base.option") + import("core.theme.theme") + import("core.project.config") + import("core.project.depend") + import("core.platform.platform") + + -- get nvcc + local nvcc = assert(platform.tool("cu"), "nvcc not found!") + + -- get link flags + local linkflags = {"-dlink"} + + -- get target file + local targetfile = target:objectfile(path.join(".cuda", "devlink", target:basename() .. "_gpucode.cu")) + + -- get object files + local objectfiles = nil + for sourcekind, sourcebatch in pairs(target:sourcebatches()) do + if sourcekind == "cu" then + objectfiles = sourcebatch.objectfiles + end + end + if not objectfiles then + return + end + + -- insert gpucode.o to the object files + table.insert(target:objectfiles(), targetfile) + + -- load dependent info + local dependfile = target:dependfile(targetfile) + local dependinfo = option.get("rebuild") and {} or (depend.load(dependfile) or {}) + + -- need build this target? + local depfiles = objectfiles + local depvalues = {nvcc, linkflags} + if not depend.is_changed(dependinfo, {lastmtime = os.mtime(target:targetfile()), values = depvalues, files = depfiles}) then + return + end + + -- is verbose? + local verbose = option.get("verbose") + + -- trace progress info + cprintf("${color.build.progress}" .. theme.get("text.build.progress_format") .. ":${clear} ", opt.progress) + if verbose then + cprint("${dim color.build.target}devlinking.$(mode) %s", path.filename(targetfile)) + else + 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) + end + + -- flush io buffer to update progress info + io.flush() + + -- link it + os.vrunv(nvcc, table.join(linkflags, objectfiles, "-o", targetfile)) + + -- update files and values to the dependent file + dependinfo.files = depfiles + dependinfo.values = depvalues + depend.save(dependinfo, dependfile) end) diff --git a/xmake/rules/cuda/env/xmake.lua b/xmake/rules/cuda/env/xmake.lua deleted file mode 100644 index 713695e69..000000000 --- a/xmake/rules/cuda/env/xmake.lua +++ /dev/null @@ -1,31 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015 - 2019, TBOOX Open Source Group. --- --- @author ruki --- @file xmake.lua --- - --- define rule: environment -rule("cuda.env") - - -- before load - before_load(function (target) - import("detect.sdks.find_cuda") - if not target:data("cuda") then - target:data_set("cuda", assert(find_cuda(), "Cuda SDK not found!")) - end - end) - diff --git a/xmake/rules/cuda/gencodes/xmake.lua b/xmake/rules/cuda/gencodes/xmake.lua index c00a79490..d7dedb197 100644 --- a/xmake/rules/cuda/gencodes/xmake.lua +++ b/xmake/rules/cuda/gencodes/xmake.lua @@ -21,9 +21,6 @@ -- define rule: gencodes rule("cuda.gencodes") - -- add rule: cuda environment - add_deps("cuda.env") - -- add cuda `-gencode` flags to target -- -- the gpu arch format syntax -- cgit v1.3.1 From 7a8d81f043060ace914fc13f3ca914419605ab27 Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 9 Jun 2019 21:09:24 +0800 Subject: improve os.vrunv --- xmake/core/sandbox/modules/os.lua | 2 +- xmake/rules/cuda/device_link/xmake.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/xmake/core/sandbox/modules/os.lua b/xmake/core/sandbox/modules/os.lua index c7ae6d8d3..2fc508fff 100644 --- a/xmake/core/sandbox/modules/os.lua +++ b/xmake/core/sandbox/modules/os.lua @@ -327,7 +327,7 @@ function sandbox_os.vrunv(program, argv, opt) -- echo command if option.get("verbose") then - print(vformat(program), table.concat(argv, " ")) + print(vformat(program) .. " " .. table.concat(argv, " ")) end -- run it diff --git a/xmake/rules/cuda/device_link/xmake.lua b/xmake/rules/cuda/device_link/xmake.lua index f1aaa18d4..4cd63646f 100644 --- a/xmake/rules/cuda/device_link/xmake.lua +++ b/xmake/rules/cuda/device_link/xmake.lua @@ -32,7 +32,7 @@ rule("cuda.device_link") import("core.platform.platform") -- get nvcc - local nvcc = assert(platform.tool("cu"), "nvcc not found!") + local nvcc = assert(platform.tool("cu-ld"), "nvcc not found!") -- get link flags local linkflags = {"-dlink"} -- cgit v1.3.1 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/core/tool/builder.lua | 2 +- xmake/core/tool/linker.lua | 8 +------ xmake/includes/add_cugencodes.lua | 44 ---------------------------------- xmake/languages/cuda/api.lua | 4 ++++ xmake/languages/cuda/xmake.lua | 9 +++++-- xmake/modules/core/tools/nvcc.lua | 3 --- xmake/platforms/linux/load.lua | 5 ---- xmake/platforms/macosx/load.lua | 6 ----- xmake/platforms/windows/load.lua | 4 ---- xmake/rules/cuda/device_link/xmake.lua | 29 +++++++++++++++------- xmake/rules/cuda/gencodes/xmake.lua | 8 +++++-- 11 files changed, 39 insertions(+), 83 deletions(-) delete mode 100644 xmake/includes/add_cugencodes.lua diff --git a/xmake/core/tool/builder.lua b/xmake/core/tool/builder.lua index f06f007e7..5a7dcf517 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) return args[name] end}) + self:_add_flags_from_language(flags, target, {[key] = function (name) print(name, args[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/core/tool/linker.lua b/xmake/core/tool/linker.lua index 78d6a85f1..a82b12918 100644 --- a/xmake/core/tool/linker.lua +++ b/xmake/core/tool/linker.lua @@ -132,7 +132,7 @@ function linker.load(targetkind, sourcekinds, target) local linkerinfo = linkerinfo_or_errors -- init cache key - local cachekey = linkerinfo.linkerkind .. (linkerinfo.program or "") .. (config.get("arch") or os.arch()) + local cachekey = targetkind .. "_" .. linkerinfo.linkerkind .. (linkerinfo.program or "") .. (config.get("arch") or os.arch()) -- get it directly from cache dirst builder._INSTANCES = builder._INSTANCES or {} @@ -242,12 +242,6 @@ function linker:linkflags(opt) -- add flags from the platform self:_add_flags_from_platform(flags, targetkind) - --[[ - -- add flags from the compiler - if target then - self:_add_flags_from_compiler(flags, target, targetkind) - end]] - -- add flags from the linker self:_add_flags_from_linker(flags) diff --git a/xmake/includes/add_cugencodes.lua b/xmake/includes/add_cugencodes.lua deleted file mode 100644 index 71e5f8b4e..000000000 --- a/xmake/includes/add_cugencodes.lua +++ /dev/null @@ -1,44 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015 - 2019, TBOOX Open Source Group. --- --- @author OpportunityLiu --- @file add_cugencodes.lua --- - --- add cuda `-gencode` flags to target --- --- the gpu arch format syntax --- - compute_xx --> `-gencode arch=compute_xx,code=compute_xx` --- - sm_xx --> `-gencode arch=compute_xx,code=sm_xx` --- - sm_xx,sm_yy --> `-gencode arch=compute_xx,code=[sm_xx,sm_yy]` --- - compute_xx,sm_yy --> `-gencode arch=compute_xx,code=sm_yy` --- - compute_xx,sm_yy,sm_zz --> `-gencode arch=compute_xx,code=[sm_yy,sm_zz]` --- - native --> match the fastest cuda device on current host, --- eg. for a Tesla P100, `-gencode arch=compute_60,code=sm_60` will be added, --- if no available device is found, no `-gencode` flags will be added --- @seealso xmake/modules/lib/detect/find_cudadevices --- --- e.g. --- includes("add_cugencodes.lua") --- target("test") --- add_rules("cuda.console") --- add_files("src/*.cu") --- add_cugencodes("native", "compute_50,sm_50", "compute_70") --- -function add_cugencodes(...) - add_values("cuda.gencode", ...) -end - diff --git a/xmake/languages/cuda/api.lua b/xmake/languages/cuda/api.lua index 589eb5579..f825c9b72 100644 --- a/xmake/languages/cuda/api.lua +++ b/xmake/languages/cuda/api.lua @@ -27,7 +27,9 @@ function apis() -- target.add_xxx "target.add_links" , "target.add_syslinks" + , "target.add_cugencodes" , "target.add_cuflags" + , "target.add_culdflags" , "target.add_ldflags" , "target.add_arflags" , "target.add_shflags" @@ -37,7 +39,9 @@ function apis() -- option.add_xxx , "option.add_links" , "option.add_syslinks" + , "option.add_cugencodes" , "option.add_cuflags" + , "option.add_culdflags" , "option.add_ldflags" , "option.add_arflags" , "option.add_shflags" diff --git a/xmake/languages/cuda/xmake.lua b/xmake/languages/cuda/xmake.lua index 46ba8f902..e73823818 100644 --- a/xmake/languages/cuda/xmake.lua +++ b/xmake/languages/cuda/xmake.lua @@ -28,10 +28,10 @@ language("cuda") set_sourceflags {cu = "cuflags"} -- set target kinds - set_targetkinds {binary = "cu-ld", static = "cu-ar", shared = "cu-sh"} + set_targetkinds {gpucode = "cu-ld", binary = "ld", static = "ar", shared = "sh"} -- set target flags - set_targetflags {binary = "ldflags", static = "arflags", shared = "shflags"} + set_targetflags {gpucode = "culdflags", binary = "ldflags", static = "arflags", shared = "shflags"} -- set language kinds set_langkinds {cu = "cu"} @@ -113,6 +113,11 @@ language("cuda") "target.strip" , "target.symbols" } + , gpucode = + { + "target.culdflags" + , "option.culdflags" + } } -- set menu diff --git a/xmake/modules/core/tools/nvcc.lua b/xmake/modules/core/tools/nvcc.lua index 568c6aef9..592634ac8 100644 --- a/xmake/modules/core/tools/nvcc.lua +++ b/xmake/modules/core/tools/nvcc.lua @@ -29,9 +29,6 @@ import("private.tools.nvcc.parse_deps") -- init it function init(self) - -- init shflags - self:set("cu-shflags", "-shared") - -- init flags if not is_plat("windows") then self:set("shared.cuflags", "-Xcompiler -fPIC") diff --git a/xmake/platforms/linux/load.lua b/xmake/platforms/linux/load.lua index b9ff210b1..4b49bec9a 100644 --- a/xmake/platforms/linux/load.lua +++ b/xmake/platforms/linux/load.lua @@ -81,14 +81,9 @@ function main(platform) -- init flags for cuda local cu_archs = { i386 = "-m32 -Xcompiler -m32", x86_64 = "-m64 -Xcompiler -m64" } platform:add("cuflags", cu_archs[arch] or "") - platform:add("cu-shflags", 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"))) - platform:add("cu-ldflags", "-L" .. os.args(path.join(cuda_dir, "lib"))) - platform:add("cu-shflags", "-L" .. os.args(path.join(cuda_dir, "lib"))) - platform:add("cu-ldflags", "-Xlinker -rpath=" .. os.args(path.join(cuda_dir, "lib"))) end local cu_cxx = config.get("cu-cxx") if cu_cxx then diff --git a/xmake/platforms/macosx/load.lua b/xmake/platforms/macosx/load.lua index f47e7a31d..79c179deb 100644 --- a/xmake/platforms/macosx/load.lua +++ b/xmake/platforms/macosx/load.lua @@ -91,16 +91,10 @@ function main(platform) -- init flags for cuda local cuflags_arch = { i386 = "-m32 -Xcompiler -arch -Xcompiler i386", x86_64 = "-m64 -Xcompiler -arch -Xcompiler x86_64" } - local ldflags_arch = { i386 = "-m32 -Xlinker -arch -Xlinker i386", x86_64 = "-m64 -Xlinker -arch -Xlinker x86_64" } platform:add("cuflags", cuflags_arch[arch] or "") - platform:add("cu-shflags", ldflags_arch[arch] or "") - platform:add("cu-ldflags", ldflags_arch[arch] or "") local cuda_dir = config.get("cuda") if cuda_dir then platform:add("cuflags", "-I" .. os.args(path.join(cuda_dir, "include"))) - platform:add("cu-ldflags", "-L" .. os.args(path.join(cuda_dir, "lib"))) - platform:add("cu-shflags", "-L" .. os.args(path.join(cuda_dir, "lib"))) - platform:add("cu-ldflags", "-Xlinker -rpath -Xlinker " .. os.args(path.join(cuda_dir, "lib"))) end local cu_cxx = config.get("cu-cxx") if cu_cxx then diff --git a/xmake/platforms/windows/load.lua b/xmake/platforms/windows/load.lua index 2de1a138e..12a6a3cfe 100644 --- a/xmake/platforms/windows/load.lua +++ b/xmake/platforms/windows/load.lua @@ -39,12 +39,8 @@ function main(platform) -- init flags for cuda local cu_archs = { x86 = "-m32", x64 = "-m64" } platform:add("cuflags", cu_archs[arch] or "") - platform:add("cu-shflags", 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"))) - platform:add("cu-ldflags", "-L" .. os.args(path.join(cuda_dir, "lib"))) - platform:add("cu-shflags", "-L" .. os.args(path.join(cuda_dir, "lib"))) end end 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 From e368bcfdb1e8326579a2ffb56e57ec6b316a29f0 Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 10 Jun 2019 21:00:49 +0800 Subject: patch rules for deprecated cuda link mode --- xmake/core/project/deprecated/project.lua | 33 +++++++++++++++++++++++++++++++ xmake/core/project/project.lua | 1 + 2 files changed, 34 insertions(+) diff --git a/xmake/core/project/deprecated/project.lua b/xmake/core/project/deprecated/project.lua index b55970c86..a7b285381 100644 --- a/xmake/core/project/deprecated/project.lua +++ b/xmake/core/project/deprecated/project.lua @@ -27,6 +27,7 @@ local path = require("base/path") local utils = require("base/utils") local table = require("base/table") local string = require("base/string") +local rule = require("project/rule") local config = require("project/config") local platform = require("platform/platform") local deprecated = require("base/deprecated") @@ -263,6 +264,38 @@ function deprecated_project._api_is_option(interp, ...) return config.has(...) end +-- patch target rules +function deprecated_project._patch_target_rules(target) + + -- TODO patch rules for the deprecated cuda link mode + -- we will remove this code in the future + local files = target:get("files") + if files and not target:rule("cuda.device_link") then + for _, sourcefile in ipairs(table.wrap(files)) do + if sourcefile:lower():endswith(".cu") then + local rules = {binary = "cuda.console", shared = "cuda.shared", static = "cuda.static"} + local rulename = rules[target:targetkind()] + if rulename then + local r = rule.rule(rulename) + if r then + target._RULES[rulename] = r + for _, deprule in ipairs(r:orderdeps()) do + local name = deprule:name() + if not target._RULES[name] then + target._RULES[name] = deprule + table.insert(target._ORDERULES, deprule) + end + end + table.insert(target._ORDERULES, r) + deprecated.add("add_rules(\"" .. rulename .. "\")", "set_kind(\"" .. target:targetkind() .. "\") for cuda") + end + end + break + end + end + end +end + -- register api function deprecated_project.api_register(interp) diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index 07fb6792f..ed9b87bb3 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -523,6 +523,7 @@ function project._load_targets() table.insert(t._ORDERULES, r) end end + deprecated_project._patch_target_rules(t) -- laod packages t._PACKAGES = t._PACKAGES or {} -- cgit v1.3.1 From c5fed632a287c2aedd335ba4e41f4347d2fe1956 Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 10 Jun 2019 22:32:56 +0800 Subject: add builtin rule for language --- xmake/core/language/language.lua | 7 +++++++ xmake/core/project/deprecated/project.lua | 32 ------------------------------- xmake/core/project/project.lua | 13 ++++++++++--- xmake/languages/cuda/xmake.lua | 3 +++ xmake/rules/cuda/xmake.lua | 31 ++---------------------------- 5 files changed, 22 insertions(+), 64 deletions(-) diff --git a/xmake/core/language/language.lua b/xmake/core/language/language.lua index a7fdddcc0..ee57172fe 100644 --- a/xmake/core/language/language.lua +++ b/xmake/core/language/language.lua @@ -103,6 +103,11 @@ function _instance:extensions() return extensions end +-- get the rules +function _instance:rules() + return self._INFO:get("rules") +end + -- get the source kinds function _instance:sourcekinds() return self._INFO:get("sourcekinds") @@ -221,6 +226,8 @@ function language._interpreter() { -- language.set_xxx "language.set_mixingkinds" + -- language.add_xxx + , "language.add_rules" } , script = { diff --git a/xmake/core/project/deprecated/project.lua b/xmake/core/project/deprecated/project.lua index a7b285381..85d05ed8f 100644 --- a/xmake/core/project/deprecated/project.lua +++ b/xmake/core/project/deprecated/project.lua @@ -264,38 +264,6 @@ function deprecated_project._api_is_option(interp, ...) return config.has(...) end --- patch target rules -function deprecated_project._patch_target_rules(target) - - -- TODO patch rules for the deprecated cuda link mode - -- we will remove this code in the future - local files = target:get("files") - if files and not target:rule("cuda.device_link") then - for _, sourcefile in ipairs(table.wrap(files)) do - if sourcefile:lower():endswith(".cu") then - local rules = {binary = "cuda.console", shared = "cuda.shared", static = "cuda.static"} - local rulename = rules[target:targetkind()] - if rulename then - local r = rule.rule(rulename) - if r then - target._RULES[rulename] = r - for _, deprule in ipairs(r:orderdeps()) do - local name = deprule:name() - if not target._RULES[name] then - target._RULES[name] = deprule - table.insert(target._ORDERULES, deprule) - end - end - table.insert(target._ORDERULES, r) - deprecated.add("add_rules(\"" .. rulename .. "\")", "set_kind(\"" .. target:targetkind() .. "\") for cuda") - end - end - break - end - end - end -end - -- register api function deprecated_project.api_register(interp) diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index ed9b87bb3..6e670ec3b 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -498,7 +498,7 @@ function project._load_targets() t._ORDERDEPS = t._ORDERDEPS or {} project._load_deps(t, targets, t._DEPS, t._ORDERDEPS) - -- load rules + -- load rules from target and language -- -- .e.g -- @@ -509,7 +509,15 @@ function project._load_targets() -- t._RULES = t._RULES or {} t._ORDERULES = t._ORDERULES or {} - for _, rulename in ipairs(table.wrap(t:get("rules"))) do + local rulenames = {} + table.join2(rulenames, t:get("rules")) + for _, sourcefile in ipairs(table.wrap(t:get("files"))) do + local lang = language.load_ex(path.extension(sourcefile)) + if lang and lang:rules() then + table.join2(rulenames, lang:rules()) + end + end + for _, rulename in ipairs(rulenames) do local r = project.rule(rulename) or rule.rule(rulename) if r then t._RULES[rulename] = r @@ -523,7 +531,6 @@ function project._load_targets() table.insert(t._ORDERULES, r) end end - deprecated_project._patch_target_rules(t) -- laod packages t._PACKAGES = t._PACKAGES or {} diff --git a/xmake/languages/cuda/xmake.lua b/xmake/languages/cuda/xmake.lua index e73823818..1d1f5b9d5 100644 --- a/xmake/languages/cuda/xmake.lua +++ b/xmake/languages/cuda/xmake.lua @@ -39,6 +39,9 @@ language("cuda") -- set mixing kinds set_mixingkinds("cu", "cc", "cxx", "as") + -- add rules + add_rules("cuda") + -- on load on_load("load") diff --git a/xmake/rules/cuda/xmake.lua b/xmake/rules/cuda/xmake.lua index 2f3564f63..0ec1ddaee 100644 --- a/xmake/rules/cuda/xmake.lua +++ b/xmake/rules/cuda/xmake.lua @@ -18,36 +18,9 @@ -- @file xmake.lua -- --- define rule: cuda static library -rule("cuda.static") +-- define rule: cuda +rule("cuda") -- add rules add_deps("cuda.device_link", "cuda.gencodes") - -- we must set kind before target.on_load(), may we will use target in on_load() - before_load(function (target) - target:set("kind", "static") - end) - --- define rule: cuda shared library -rule("cuda.shared") - - -- add rules - add_deps("cuda.device_link", "cuda.gencodes") - - -- we must set kind before target.on_load(), may we will use target in on_load() - before_load(function (target) - target:set("kind", "shared") - end) - --- define rule: cuda console -rule("cuda.console") - - -- add rules - add_deps("cuda.device_link", "cuda.gencodes") - - -- we must set kind before target.on_load(), may we will use target in on_load() - before_load(function (target) - target:set("kind", "binary") - end) - -- cgit v1.3.1 From 1907e99429956b1c31dee51f9510b6b176f75e82 Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 10 Jun 2019 22:33:09 +0800 Subject: modify test and template --- tests/projects/cuda/console/xmake.lua | 2 -- xmake/templates/cuda/console/project/xmake.lua | 5 +---- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/tests/projects/cuda/console/xmake.lua b/tests/projects/cuda/console/xmake.lua index 430ad7b6d..d7267fb0d 100644 --- a/tests/projects/cuda/console/xmake.lua +++ b/tests/projects/cuda/console/xmake.lua @@ -1,6 +1,4 @@ -includes('add_cugencodes.lua') - -- define target target("cuda_console") diff --git a/xmake/templates/cuda/console/project/xmake.lua b/xmake/templates/cuda/console/project/xmake.lua index 467ae7296..1c1c48cfb 100644 --- a/xmake/templates/cuda/console/project/xmake.lua +++ b/xmake/templates/cuda/console/project/xmake.lua @@ -2,9 +2,6 @@ -- add modes: debug and release add_rules("mode.debug", "mode.release") --- add helper function add_cugencodes -includes('add_cugencodes.lua') - -- define target target("[targetname]") @@ -24,4 +21,4 @@ target("[targetname]") -- add_cugencodes("sm_30", "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") \ No newline at end of file + -- add_cugencodes("compute_75") -- cgit v1.3.1 From 4fe121746da73e547d902cec6942b06681b385de Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 10 Jun 2019 22:39:56 +0800 Subject: modify comment --- xmake/rules/cuda/device_link/xmake.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xmake/rules/cuda/device_link/xmake.lua b/xmake/rules/cuda/device_link/xmake.lua index 43905f044..6c1d96983 100644 --- a/xmake/rules/cuda/device_link/xmake.lua +++ b/xmake/rules/cuda/device_link/xmake.lua @@ -33,7 +33,7 @@ rule("cuda.device_link") target:add("rpathdirs", path.join(cuda_dir, "lib")) end) - -- before link + -- @see https://devblogs.nvidia.com/separate-compilation-linking-cuda-device-code/ before_link(function (target, opt) -- imports -- cgit v1.3.1 From 9c2c26c81c8c43bc1a834522bc085392c766e7e0 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Mon, 10 Jun 2019 12:02:45 +0800 Subject: fix finddevice --- xmake/modules/lib/detect/find_cudadevices.lua | 9 +- xmake/scripts/find_cudadevices.cpp | 211 ++++++++++++++++++++++++++ xmake/scripts/find_cudadevices.cu | 207 ------------------------- 3 files changed, 217 insertions(+), 210 deletions(-) create mode 100644 xmake/scripts/find_cudadevices.cpp delete mode 100644 xmake/scripts/find_cudadevices.cu diff --git a/xmake/modules/lib/detect/find_cudadevices.lua b/xmake/modules/lib/detect/find_cudadevices.lua index 64a69f705..aa44fe0fb 100644 --- a/xmake/modules/lib/detect/find_cudadevices.lua +++ b/xmake/modules/lib/detect/find_cudadevices.lua @@ -21,6 +21,7 @@ -- imports import("core.base.option") import("core.platform.platform") +import("core.project.config") import("lib.detect.cache") -- a magic string to filter output @@ -120,13 +121,15 @@ function _find_devices(verbose) cprint("${dim}checking for cuda devices") end - local sourcefile = path.join(os.programdir(), 'scripts', 'find_cudadevices.cu') + local sourcefile = path.join(os.programdir(), 'scripts', 'find_cudadevices.cpp') local outfile = os.tmpfile() local compile_errors = nil local results, errors = try { - function () - return os.iorunv(nvcc, { sourcefile, '-run', '-o', outfile , '-DPRINT_SUFFIX="' .. _PRINT_SUFFIX .. '"' }) + function () + local archs = { i386 = "-m32", x86 = "-m32", x86_64 = "-m64", x64 = "-m64" } + local arch = archs[config.get("arch")] or "" + return os.iorunv(nvcc, { sourcefile, arch, '-run', '-o', outfile , '-DPRINT_SUFFIX="' .. _PRINT_SUFFIX .. '"' }) end, catch { diff --git a/xmake/scripts/find_cudadevices.cpp b/xmake/scripts/find_cudadevices.cpp new file mode 100644 index 000000000..fd002cc84 --- /dev/null +++ b/xmake/scripts/find_cudadevices.cpp @@ -0,0 +1,211 @@ +#include +#include +#include + +#ifndef PRINT_SUFFIX +#define PRINT_SUFFIX "" +#endif + +#define MY_CUDA_VER (__CUDACC_VER_MAJOR__ * 100 + __CUDACC_VER_MINOR__) + +inline void check(cudaError_t result) +{ + if (result) + { + fprintf(stderr, PRINT_SUFFIX "%s (%s)", cudaGetErrorName(result), cudaGetErrorString(result)); + cudaDeviceReset(); + // Make sure we call CUDA Device Reset before exiting + exit(0); + } +} + +inline void print_value(unsigned long long value) +{ + printf("%llu", value); +} + +inline void print_value(unsigned long value) +{ + printf("%lu", value); +} + +inline void print_value(unsigned int value) +{ + printf("%u", value); +} + +inline void print_value(bool value) +{ + printf(value ? "true" : "false"); +} + +inline void print_value(int value) +{ + printf("%d", value); +} + +template +inline void print_value(const T (&value)[len]) +{ + printf("("); + for (size_t i = 0; i < len - 1; i++) + { + print_value(value[i]); + printf(", "); + } + print_value(value[len - 1]); + printf(")"); +} + +inline void print_value(const void *value) +{ + printf("\"%s\"", (const char *)value); +} + +template +inline void print_value(const char (&value)[len]) +{ + printf("\""); + for (size_t i = 0; i < len; i++) + printf("%02hhx", value[i]); + printf("\""); +} + +template <> +inline void print_value<16>(const char (&value)[16]) +{ + // speicalized for uuid + printf("\"%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx\"", + value[0], value[1], value[2], value[3], + value[4], value[5], value[6], value[7], + value[8], value[9], value[10], value[11], + value[12], value[13], value[14], value[15]); +} + +#if MY_CUDA_VER >= 1000 +inline void print_value(const cudaUUID_t &value) +{ + print_value(value.bytes); +} +#endif + +template +inline void print_property(const char *name, const T &value) +{ + printf(PRINT_SUFFIX " %s = ", name); + print_value(value); + printf("\n"); +} + +inline void print_device(int id) +{ + cudaDeviceProp deviceProp; + check(cudaGetDeviceProperties(&deviceProp, id)); + +#define PRINT_PROPERTY(name) print_property(#name, deviceProp.name) +#define PRINT_BOOL_PROPERTY(name) print_property(#name, static_cast(deviceProp.name)) +#define PRINT_STR_PROPERTY(name) print_property(#name, static_cast(deviceProp.name)) + // cuda 8.0 + PRINT_STR_PROPERTY(name); + PRINT_PROPERTY(totalGlobalMem); + PRINT_PROPERTY(sharedMemPerBlock); + PRINT_PROPERTY(regsPerBlock); + PRINT_PROPERTY(warpSize); + PRINT_PROPERTY(memPitch); + PRINT_PROPERTY(maxThreadsPerBlock); + PRINT_PROPERTY(maxThreadsDim); + PRINT_PROPERTY(maxGridSize); + PRINT_PROPERTY(clockRate); + PRINT_PROPERTY(totalConstMem); + PRINT_PROPERTY(major); + PRINT_PROPERTY(minor); + PRINT_PROPERTY(textureAlignment); + PRINT_PROPERTY(texturePitchAlignment); + PRINT_BOOL_PROPERTY(deviceOverlap); + PRINT_PROPERTY(multiProcessorCount); + PRINT_BOOL_PROPERTY(kernelExecTimeoutEnabled); + PRINT_BOOL_PROPERTY(integrated); + PRINT_BOOL_PROPERTY(canMapHostMemory); + PRINT_PROPERTY(computeMode); + PRINT_PROPERTY(maxTexture1D); + PRINT_PROPERTY(maxTexture1DMipmap); + PRINT_PROPERTY(maxTexture1DLinear); + PRINT_PROPERTY(maxTexture2D); + PRINT_PROPERTY(maxTexture2DMipmap); + PRINT_PROPERTY(maxTexture2DLinear); + PRINT_PROPERTY(maxTexture2DGather); + PRINT_PROPERTY(maxTexture3D); + PRINT_PROPERTY(maxTexture3DAlt); + PRINT_PROPERTY(maxTextureCubemap); + PRINT_PROPERTY(maxTexture1DLayered); + PRINT_PROPERTY(maxTexture2DLayered); + PRINT_PROPERTY(maxTextureCubemapLayered); + PRINT_PROPERTY(maxSurface1D); + PRINT_PROPERTY(maxSurface2D); + PRINT_PROPERTY(maxSurface3D); + PRINT_PROPERTY(maxSurface1DLayered); + PRINT_PROPERTY(maxSurface2DLayered); + PRINT_PROPERTY(maxSurfaceCubemap); + PRINT_PROPERTY(maxSurfaceCubemapLayered); + PRINT_PROPERTY(surfaceAlignment); + PRINT_BOOL_PROPERTY(concurrentKernels); + PRINT_BOOL_PROPERTY(ECCEnabled); + PRINT_PROPERTY(pciBusID); + PRINT_PROPERTY(pciDeviceID); + PRINT_PROPERTY(pciDomainID); + PRINT_BOOL_PROPERTY(tccDriver); + PRINT_PROPERTY(asyncEngineCount); + PRINT_BOOL_PROPERTY(unifiedAddressing); + PRINT_PROPERTY(memoryClockRate); + PRINT_PROPERTY(memoryBusWidth); + PRINT_PROPERTY(l2CacheSize); + PRINT_PROPERTY(maxThreadsPerMultiProcessor); + PRINT_BOOL_PROPERTY(streamPrioritiesSupported); + PRINT_BOOL_PROPERTY(globalL1CacheSupported); + PRINT_BOOL_PROPERTY(localL1CacheSupported); + PRINT_PROPERTY(sharedMemPerMultiprocessor); + PRINT_PROPERTY(regsPerMultiprocessor); + PRINT_BOOL_PROPERTY(isMultiGpuBoard); + PRINT_PROPERTY(multiGpuBoardGroupID); + PRINT_PROPERTY(singleToDoublePrecisionPerfRatio); + PRINT_BOOL_PROPERTY(pageableMemoryAccess); + PRINT_BOOL_PROPERTY(concurrentManagedAccess); + PRINT_BOOL_PROPERTY(managedMemory); + +#if MY_CUDA_VER >= 900 + // Added in cuda 9.0 + PRINT_BOOL_PROPERTY(computePreemptionSupported); + PRINT_BOOL_PROPERTY(canUseHostPointerForRegisteredMem); + PRINT_BOOL_PROPERTY(cooperativeLaunch); + PRINT_BOOL_PROPERTY(cooperativeMultiDeviceLaunch); + PRINT_PROPERTY(sharedMemPerBlockOptin); +#endif + +#if MY_CUDA_VER >= 902 + // Added in cuda 9.2 + PRINT_BOOL_PROPERTY(pageableMemoryAccessUsesHostPageTables); + PRINT_BOOL_PROPERTY(directManagedMemAccessFromHost); +#endif + +#if MY_CUDA_VER >= 1000 + // Added in cuda 10.0 + PRINT_PROPERTY(uuid); + PRINT_PROPERTY(luid); + PRINT_PROPERTY(luidDeviceNodeMask); +#endif +} + +int main(int argc, char *argv[]) +{ + printf("\n"); + fprintf(stderr, "\n"); + + int count = 0; + check(cudaGetDeviceCount(&count)); + for (int i = 0; i < count; i++) + { + printf(PRINT_SUFFIX "DEVICE #%d\n", i); + print_device(i); + } + return 0; +} diff --git a/xmake/scripts/find_cudadevices.cu b/xmake/scripts/find_cudadevices.cu deleted file mode 100644 index 56d64ff2b..000000000 --- a/xmake/scripts/find_cudadevices.cu +++ /dev/null @@ -1,207 +0,0 @@ -#include -#include -#include - -#ifndef PRINT_SUFFIX -#define PRINT_SUFFIX "" -#endif - -#define MY_CUDA_VER (__CUDACC_VER_MAJOR__ * 100 + __CUDACC_VER_MINOR__) - -inline void check(cudaError_t result) -{ - if (result) - { - fprintf(stderr, PRINT_SUFFIX "%s (%s)", cudaGetErrorName(result), cudaGetErrorString(result)); - cudaDeviceReset(); - // Make sure we call CUDA Device Reset before exiting - exit(0); - } -} - -inline void print_value(size_t value) -{ - // in case we don't have '%zu' - printf("%llu", (unsigned long long)value); -} - -inline void print_value(bool value) -{ - printf(value ? "true" : "false"); -} - -inline void print_value(int value) -{ - printf("%d", value); -} - -template -inline void print_value(const T (&value)[len]) -{ - printf("("); - for (size_t i = 0; i < len - 1; i++) - { - print_value(value[i]); - printf(", "); - } - print_value(value[len - 1]); - printf(")"); -} - -inline void print_value(unsigned int value) -{ - printf("%u", value); -} - -inline void print_value(const void *value) -{ - printf("\"%s\"", (const char *)value); -} - -template -inline void print_value(const char (&value)[len]) -{ - printf("\""); - for (size_t i = 0; i < len; i++) - printf("%02hhx", value[i]); - printf("\""); -} - -template <> -inline void print_value<16>(const char (&value)[16]) -{ - // speicalized for uuid - printf("\"%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx\"", - value[0], value[1], value[2], value[3], - value[4], value[5], value[6], value[7], - value[8], value[9], value[10], value[11], - value[12], value[13], value[14], value[15]); -} - -#if MY_CUDA_VER >= 1000 -inline void print_value(const cudaUUID_t &value) -{ - print_value(value.bytes); -} -#endif - -template -inline void print_property(const char *name, const T &value) -{ - printf(PRINT_SUFFIX " %s = ", name); - print_value(value); - printf("\n"); -} - -inline void print_device(int id) -{ - cudaDeviceProp deviceProp; - check(cudaGetDeviceProperties(&deviceProp, id)); - -#define PRINT_PROPERTY(name) print_property(#name, deviceProp.name) -#define PRINT_BOOL_PROPERTY(name) print_property(#name, static_cast(deviceProp.name)) -#define PRINT_STR_PROPERTY(name) print_property(#name, static_cast(deviceProp.name)) - // cuda 8.0 - PRINT_STR_PROPERTY(name); - PRINT_PROPERTY(totalGlobalMem); - PRINT_PROPERTY(sharedMemPerBlock); - PRINT_PROPERTY(regsPerBlock); - PRINT_PROPERTY(warpSize); - PRINT_PROPERTY(memPitch); - PRINT_PROPERTY(maxThreadsPerBlock); - PRINT_PROPERTY(maxThreadsDim); - PRINT_PROPERTY(maxGridSize); - PRINT_PROPERTY(clockRate); - PRINT_PROPERTY(totalConstMem); - PRINT_PROPERTY(major); - PRINT_PROPERTY(minor); - PRINT_PROPERTY(textureAlignment); - PRINT_PROPERTY(texturePitchAlignment); - PRINT_BOOL_PROPERTY(deviceOverlap); - PRINT_PROPERTY(multiProcessorCount); - PRINT_BOOL_PROPERTY(kernelExecTimeoutEnabled); - PRINT_BOOL_PROPERTY(integrated); - PRINT_BOOL_PROPERTY(canMapHostMemory); - PRINT_PROPERTY(computeMode); - PRINT_PROPERTY(maxTexture1D); - PRINT_PROPERTY(maxTexture1DMipmap); - PRINT_PROPERTY(maxTexture1DLinear); - PRINT_PROPERTY(maxTexture2D); - PRINT_PROPERTY(maxTexture2DMipmap); - PRINT_PROPERTY(maxTexture2DLinear); - PRINT_PROPERTY(maxTexture2DGather); - PRINT_PROPERTY(maxTexture3D); - PRINT_PROPERTY(maxTexture3DAlt); - PRINT_PROPERTY(maxTextureCubemap); - PRINT_PROPERTY(maxTexture1DLayered); - PRINT_PROPERTY(maxTexture2DLayered); - PRINT_PROPERTY(maxTextureCubemapLayered); - PRINT_PROPERTY(maxSurface1D); - PRINT_PROPERTY(maxSurface2D); - PRINT_PROPERTY(maxSurface3D); - PRINT_PROPERTY(maxSurface1DLayered); - PRINT_PROPERTY(maxSurface2DLayered); - PRINT_PROPERTY(maxSurfaceCubemap); - PRINT_PROPERTY(maxSurfaceCubemapLayered); - PRINT_PROPERTY(surfaceAlignment); - PRINT_BOOL_PROPERTY(concurrentKernels); - PRINT_BOOL_PROPERTY(ECCEnabled); - PRINT_PROPERTY(pciBusID); - PRINT_PROPERTY(pciDeviceID); - PRINT_PROPERTY(pciDomainID); - PRINT_BOOL_PROPERTY(tccDriver); - PRINT_PROPERTY(asyncEngineCount); - PRINT_BOOL_PROPERTY(unifiedAddressing); - PRINT_PROPERTY(memoryClockRate); - PRINT_PROPERTY(memoryBusWidth); - PRINT_PROPERTY(l2CacheSize); - PRINT_PROPERTY(maxThreadsPerMultiProcessor); - PRINT_BOOL_PROPERTY(streamPrioritiesSupported); - PRINT_BOOL_PROPERTY(globalL1CacheSupported); - PRINT_BOOL_PROPERTY(localL1CacheSupported); - PRINT_PROPERTY(sharedMemPerMultiprocessor); - PRINT_PROPERTY(regsPerMultiprocessor); - PRINT_BOOL_PROPERTY(isMultiGpuBoard); - PRINT_PROPERTY(multiGpuBoardGroupID); - PRINT_PROPERTY(singleToDoublePrecisionPerfRatio); - PRINT_BOOL_PROPERTY(pageableMemoryAccess); - PRINT_BOOL_PROPERTY(concurrentManagedAccess); - PRINT_BOOL_PROPERTY(managedMemory); - -#if MY_CUDA_VER >= 900 - // Added in cuda 9.0 - PRINT_BOOL_PROPERTY(computePreemptionSupported); - PRINT_BOOL_PROPERTY(canUseHostPointerForRegisteredMem); - PRINT_BOOL_PROPERTY(cooperativeLaunch); - PRINT_BOOL_PROPERTY(cooperativeMultiDeviceLaunch); - PRINT_PROPERTY(sharedMemPerBlockOptin); -#endif - -#if MY_CUDA_VER >= 902 - // Added in cuda 9.2 - PRINT_BOOL_PROPERTY(pageableMemoryAccessUsesHostPageTables); - PRINT_BOOL_PROPERTY(directManagedMemAccessFromHost); -#endif - -#if MY_CUDA_VER >= 1000 - // Added in cuda 10.0 - PRINT_PROPERTY(uuid); - PRINT_PROPERTY(luid); - PRINT_PROPERTY(luidDeviceNodeMask); -#endif -} - -int main(int argc, char *argv[]) -{ - printf("\n"); - fprintf(stderr, "\n"); - - int count = 0; - check(cudaGetDeviceCount(&count)); - for (int i = 0; i < count; i++) - { - printf(PRINT_SUFFIX "DEVICE #%d\n", i); - print_device(i); - } - return 0; -} -- cgit v1.3.1 From eefa90347085c76301cb84920ed18321362bede4 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 11 Jun 2019 00:20:40 +0800 Subject: fix some device link issues --- xmake/core/tool/builder.lua | 2 +- xmake/languages/cuda/xmake.lua | 14 ++++++++++++-- xmake/platforms/linux/load.lua | 3 ++- xmake/platforms/macosx/load.lua | 5 +++-- xmake/platforms/windows/load.lua | 1 + xmake/rules/cuda/device_link/xmake.lua | 20 ++++++++++++++++---- 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) -- cgit v1.3.1 From 902a32984ed3b279068a9d17098e9c39056dce82 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 11 Jun 2019 00:21:03 +0800 Subject: fix device-link deps --- xmake/rules/cuda/device_link/xmake.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xmake/rules/cuda/device_link/xmake.lua b/xmake/rules/cuda/device_link/xmake.lua index dae37f32a..a5f09d8c3 100644 --- a/xmake/rules/cuda/device_link/xmake.lua +++ b/xmake/rules/cuda/device_link/xmake.lua @@ -84,7 +84,7 @@ rule("cuda.device_link") -- need build this target? local depfiles = objectfiles - local depvalues = {nvcc, linkflags} + local depvalues = {linkinst:program(), linkflags} if not depend.is_changed(dependinfo, {lastmtime = os.mtime(target:targetfile()), values = depvalues, files = depfiles}) then return end -- cgit v1.3.1 From 9535258191b9187e6ba9987391d6777a71f974bd Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 11 Jun 2019 00:21:59 +0800 Subject: fix device-link linkdirs for linux --- xmake/rules/cuda/device_link/xmake.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/xmake/rules/cuda/device_link/xmake.lua b/xmake/rules/cuda/device_link/xmake.lua index a5f09d8c3..989aabdea 100644 --- a/xmake/rules/cuda/device_link/xmake.lua +++ b/xmake/rules/cuda/device_link/xmake.lua @@ -36,6 +36,9 @@ rule("cuda.device_link") 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)) + elseif is_plat("linux") and is_arch("x86_64") then + target:add("linkdirs", path.join(cuda_dir, "lib64")) + target:add("rpathdirs", path.join(cuda_dir, "lib64")) else target:add("linkdirs", path.join(cuda_dir, "lib")) target:add("rpathdirs", path.join(cuda_dir, "lib")) -- cgit v1.3.1 From ae6f488393e8c327a467761bfe09076b38a62d5f Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 11 Jun 2019 00:26:45 +0800 Subject: move linkdirs to find_cuda --- xmake/modules/detect/sdks/find_cuda.lua | 13 ++++++++++++- xmake/rules/cuda/device_link/xmake.lua | 20 +++++++------------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/xmake/modules/detect/sdks/find_cuda.lua b/xmake/modules/detect/sdks/find_cuda.lua index a75dfa9f5..cdad64ac1 100644 --- a/xmake/modules/detect/sdks/find_cuda.lua +++ b/xmake/modules/detect/sdks/find_cuda.lua @@ -65,7 +65,18 @@ function _find_cuda(sdkdir) end -- get linkdirs - local linkdirs = {path.join(sdkdir, "lib")} + local linkdirs = {} + if is_plat("windows") then + local subdir = is_arch("x64") and "x64" or "Win32" + table.insert(linkdirs, path.join(sdkdir, "lib", subdir, "stubs")) + table.insert(linkdirs, path.join(sdkdir, "lib", subdir)) + elseif is_plat("linux") and is_arch("x86_64") then + table.insert(linkdirs, path.join(sdkdir, "lib64", "stubs")) + table.insert(linkdirs, path.join(sdkdir, "lib64")) + else + table.insert(linkdirs, path.join(sdkdir, "lib", "stubs")) + table.insert(linkdirs, path.join(sdkdir, "lib")) + end -- get includedirs local includedirs = {path.join(sdkdir, "include")} diff --git a/xmake/rules/cuda/device_link/xmake.lua b/xmake/rules/cuda/device_link/xmake.lua index 989aabdea..8489d8c83 100644 --- a/xmake/rules/cuda/device_link/xmake.lua +++ b/xmake/rules/cuda/device_link/xmake.lua @@ -24,25 +24,19 @@ 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!") + -- imports + import("detect.sdks.find_cuda") + + -- get cuda + local cuda = assert(find_cuda(nil, {verbose = true}), "Cuda SDK directory not found!") -- add links 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)) - elseif is_plat("linux") and is_arch("x86_64") then - target:add("linkdirs", path.join(cuda_dir, "lib64")) - target:add("rpathdirs", path.join(cuda_dir, "lib64")) - else - target:add("linkdirs", path.join(cuda_dir, "lib")) - target:add("rpathdirs", path.join(cuda_dir, "lib")) - end + target:add("linkdirs", cuda.linkdirs) + target:add("rpathdirs", cuda.linkdirs) end) -- @see https://devblogs.nvidia.com/separate-compilation-linking-cuda-device-code/ -- cgit v1.3.1 From f63112325a658b582b87428a1f78c7e89f3b074e Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 11 Jun 2019 00:29:12 +0800 Subject: rename --cu-cxx to --cu-ccbin --- xmake/languages/cuda/xmake.lua | 2 +- xmake/platforms/linux/config.lua | 10 +++++----- xmake/platforms/linux/load.lua | 7 ++++--- xmake/platforms/macosx/config.lua | 10 +++++----- xmake/platforms/macosx/load.lua | 7 ++++--- 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/xmake/languages/cuda/xmake.lua b/xmake/languages/cuda/xmake.lua index 1949708e6..75b4bf5b8 100644 --- a/xmake/languages/cuda/xmake.lua +++ b/xmake/languages/cuda/xmake.lua @@ -139,7 +139,7 @@ language("cuda") { {category = "Cross Complation Configuration/Compiler Configuration" } , {nil, "cu", "kv", nil, "The Cuda Compiler" } - , {nil, "cu-cxx", "kv", nil, "The Cuda Host C++ Compiler" } + , {nil, "cu-ccbin", "kv", nil, "The Cuda Host C++ Compiler" } , {category = "Cross Complation Configuration/Linker Configuration" } , {nil, "cu-ld", "kv", nil, "The Cuda Linker" } diff --git a/xmake/platforms/linux/config.lua b/xmake/platforms/linux/config.lua index 60cc98676..4cbed376d 100644 --- a/xmake/platforms/linux/config.lua +++ b/xmake/platforms/linux/config.lua @@ -78,13 +78,13 @@ function _toolchains() local cu = toolchain("the cuda compiler") local cu_ld = toolchain("the cuda linker") local cu_sh = toolchain("the cuda shared library linker") - local cu_cxx = toolchain("the cuda host c++ compiler") + local cu_ccbin = toolchain("the cuda host c++ compiler") local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, mm = mm, mxx = mxx, gc = gc, ["gc-ld"] = gc_ld, ["gc-ar"] = gc_ar, dc = dc, ["dc-ld"] = dc_ld, ["dc-sh"] = dc_sh, ["dc-ar"] = dc_ar, rc = rc, ["rc-ld"] = rc_ld, ["rc-sh"] = rc_sh, ["rc-ar"] = rc_ar, - cu = cu, ["cu-ld"] = cu_ld, ["cu-sh"] = cu_sh, ["cu-cxx"] = cu_cxx} + cu = cu, ["cu-ld"] = cu_ld, ["cu-sh"] = cu_sh, ["cu-ccbin"] = cu_ccbin} -- init the c compiler cc:add("$(env CC)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) @@ -151,7 +151,7 @@ function _toolchains() cu_ld:add("nvcc") cu_sh:add("nvcc") if not cross or cross == "" then - cu_cxx:add("$(env CXX)", "$(env CC)", "gcc", "clang", "g++", "clang++") + cu_ccbin:add("$(env CXX)", "$(env CC)", "gcc", "clang", "g++", "clang++") end return toolchains @@ -174,10 +174,10 @@ function main(platform, name) -- check cuda check_cuda(config) - -- check cu-cxx after checking arch + -- check cu-ccbin after checking arch if config.get("cuda") then local toolchains = singleton.get("linux.toolchains", _toolchains) - check_toolchain(config, "cu-cxx", toolchains["cu-cxx"]) + check_toolchain(config, "cu-ccbin", toolchains["cu-ccbin"]) end end end diff --git a/xmake/platforms/linux/load.lua b/xmake/platforms/linux/load.lua index 184c2fa64..65761d0ac 100644 --- a/xmake/platforms/linux/load.lua +++ b/xmake/platforms/linux/load.lua @@ -86,9 +86,10 @@ function main(platform) if cuda_dir then platform:add("cuflags", "-I" .. os.args(path.join(cuda_dir, "include"))) end - local cu_cxx = config.get("cu-cxx") - if cu_cxx then - platform:add("cuflags", "-ccbin", os.args(cu_cxx)) + local cu_ccbin = config.get("cu-ccbin") + if cu_ccbin then + platform:add("cuflags", "-ccbin", os.args(cu_ccbin)) + platform:add("cu-ldflags", "-ccbin", os.args(cu_ccbin)) end end diff --git a/xmake/platforms/macosx/config.lua b/xmake/platforms/macosx/config.lua index 59ad2d7bb..d2eaa807d 100644 --- a/xmake/platforms/macosx/config.lua +++ b/xmake/platforms/macosx/config.lua @@ -60,13 +60,13 @@ function _toolchains() local cu = toolchain("the cuda compiler") local cu_ld = toolchain("the cuda linker") local cu_sh = toolchain("the cuda shared library linker") - local cu_cxx = toolchain("the cuda host c++ compiler") + local cu_ccbin = toolchain("the cuda host c++ compiler") local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, mm = mm, mxx = mxx, sc = sc, ["sc-ld"] = sc_ld, ["sc-sh"] = sc_sh, gc = gc, ["gc-ld"] = gc_ld, ["gc-ar"] = gc_ar, dc = dc, ["dc-ld"] = dc_ld, ["dc-sh"] = dc_sh, ["dc-ar"] = dc_ar, rc = rc, ["rc-ld"] = rc_ld, ["rc-sh"] = rc_sh, ["rc-ar"] = rc_ar, - cu = cu, ["cu-ld"] = cu_ld, ["cu-sh"] = cu_sh, ["cu-cxx"] = cu_cxx} + cu = cu, ["cu-ld"] = cu_ld, ["cu-sh"] = cu_sh, ["cu-ccbin"] = cu_ccbin} -- init the c compiler cc:add("$(env CC)", {name = "clang", cross = cross}, "clang", "gcc") @@ -133,7 +133,7 @@ function _toolchains() cu:add("nvcc") cu_ld:add("nvcc") cu_sh:add("nvcc") - cu_cxx:add("$(env CXX)", "$(env CC)", "clang", "gcc") + cu_ccbin:add("$(env CXX)", "$(env CC)", "clang", "gcc") return toolchains end @@ -158,10 +158,10 @@ function main(platform, name) -- check cuda check_cuda(config) - -- check cu-cxx after checking arch + -- check cu-ccbin after checking arch if config.get("cuda") then local toolchains = singleton.get("macosx.toolchains." .. (config.get("arch") or os.arch()), _toolchains) - check_toolchain(config, "cu-cxx", toolchains["cu-cxx"]) + check_toolchain(config, "cu-ccbin", toolchains["cu-ccbin"]) end end end diff --git a/xmake/platforms/macosx/load.lua b/xmake/platforms/macosx/load.lua index 142d7997f..19c2182b9 100644 --- a/xmake/platforms/macosx/load.lua +++ b/xmake/platforms/macosx/load.lua @@ -97,9 +97,10 @@ function main(platform) if cuda_dir then platform:add("cuflags", "-I" .. os.args(path.join(cuda_dir, "include"))) end - local cu_cxx = config.get("cu-cxx") - if cu_cxx then - platform:add("cuflags", "-ccbin", os.args(cu_cxx)) + local cu_ccbin = config.get("cu-ccbin") + if cu_ccbin then + platform:add("cuflags", "-ccbin", os.args(cu_ccbin)) + platform:add("cu-ldflags", "-ccbin", os.args(cu_ccbin)) end end -- cgit v1.3.1 From 21fbe003a96514fe92106a6b8fb88fab7ed02fce Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 11 Jun 2019 00:31:15 +0800 Subject: move platform cuda setting to env rule --- xmake/platforms/linux/load.lua | 14 ---------- xmake/platforms/macosx/load.lua | 14 ---------- xmake/platforms/windows/load.lua | 9 ------- xmake/rules/cuda/device_link/xmake.lua | 8 +++--- xmake/rules/cuda/env/xmake.lua | 49 ++++++++++++++++++++++++++++++++++ 5 files changed, 53 insertions(+), 41 deletions(-) create mode 100644 xmake/rules/cuda/env/xmake.lua diff --git a/xmake/platforms/linux/load.lua b/xmake/platforms/linux/load.lua index 65761d0ac..dcdacd8c1 100644 --- a/xmake/platforms/linux/load.lua +++ b/xmake/platforms/linux/load.lua @@ -77,19 +77,5 @@ function main(platform) -- init flags for rust platform:set("rc-shflags", "") platform:set("rc-ldflags", "") - - -- init flags for cuda - 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"))) - end - local cu_ccbin = config.get("cu-ccbin") - if cu_ccbin then - platform:add("cuflags", "-ccbin", os.args(cu_ccbin)) - platform:add("cu-ldflags", "-ccbin", os.args(cu_ccbin)) - end end diff --git a/xmake/platforms/macosx/load.lua b/xmake/platforms/macosx/load.lua index 19c2182b9..e53dc1b8c 100644 --- a/xmake/platforms/macosx/load.lua +++ b/xmake/platforms/macosx/load.lua @@ -88,19 +88,5 @@ function main(platform) -- init flags for rust platform:set("rc-shflags", "") platform:set("rc-ldflags", "") - - -- init flags for cuda - 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"))) - end - local cu_ccbin = config.get("cu-ccbin") - if cu_ccbin then - platform:add("cuflags", "-ccbin", os.args(cu_ccbin)) - platform:add("cu-ldflags", "-ccbin", os.args(cu_ccbin)) - end end diff --git a/xmake/platforms/windows/load.lua b/xmake/platforms/windows/load.lua index 444b3feb6..f7789ddb9 100644 --- a/xmake/platforms/windows/load.lua +++ b/xmake/platforms/windows/load.lua @@ -35,13 +35,4 @@ function main(platform) platform:add("dcflags", dc_archs[arch]) platform:add("dc-shflags", dc_archs[arch]) platform:add("dc-ldflags", dc_archs[arch]) - - -- 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"))) - end end diff --git a/xmake/rules/cuda/device_link/xmake.lua b/xmake/rules/cuda/device_link/xmake.lua index 8489d8c83..90481c34b 100644 --- a/xmake/rules/cuda/device_link/xmake.lua +++ b/xmake/rules/cuda/device_link/xmake.lua @@ -21,14 +21,14 @@ -- define rule: device-link rule("cuda.device_link") + -- add rule: cuda environment + add_deps("cuda.env") + -- after load after_load(function (target) - -- imports - import("detect.sdks.find_cuda") - -- get cuda - local cuda = assert(find_cuda(nil, {verbose = true}), "Cuda SDK directory not found!") + local cuda = assert(target:data("cuda")) -- add links target:add("links", "cudadevrt", "cudart_static") diff --git a/xmake/rules/cuda/env/xmake.lua b/xmake/rules/cuda/env/xmake.lua new file mode 100644 index 000000000..a334bb200 --- /dev/null +++ b/xmake/rules/cuda/env/xmake.lua @@ -0,0 +1,49 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2019, TBOOX Open Source Group. +-- +-- @author ruki +-- @file xmake.lua +-- + +-- define rule: environment +rule("cuda.env") + after_load(function (target) + + -- get cuda sdk + import("detect.sdks.find_cuda") + local cuda = assert(find_cuda(nil, {verbose = true}), "Cuda SDK not found!") + target:data_set("cuda", cuda) + + -- add arch + if is_arch("x86_64", "x64") then + target:add("cuflags", "-m64", {force = true}) + target:add("culdflags", "-m64", {force = true}) + else + target:add("cuflags", "-m32", {force = true}) + target:add("culdflags", "-m32", {force = true}) + end + + -- add -ccbin + local cu_ccbin = get_config("cu-ccbin") + if cu_ccbin then + target:add("cuflags", "-ccbin", os.args(cu_ccbin), {force = true}) + target:add("culdflags", "-ccbin", os.args(cu_ccbin), {force = true}) + end + + -- add includedirs + target:add("includedirs", cuda.includedirs) + end) + -- cgit v1.3.1 From 9f81f22e0d241bfc6ddb2f5b55b75ddfbc3f6851 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 11 Jun 2019 00:37:14 +0800 Subject: improve cuda.env --- xmake/modules/detect/sdks/find_cuda.lua | 1 - xmake/rules/cuda/env/xmake.lua | 8 ++++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/xmake/modules/detect/sdks/find_cuda.lua b/xmake/modules/detect/sdks/find_cuda.lua index cdad64ac1..d87d5b3b0 100644 --- a/xmake/modules/detect/sdks/find_cuda.lua +++ b/xmake/modules/detect/sdks/find_cuda.lua @@ -68,7 +68,6 @@ function _find_cuda(sdkdir) local linkdirs = {} if is_plat("windows") then local subdir = is_arch("x64") and "x64" or "Win32" - table.insert(linkdirs, path.join(sdkdir, "lib", subdir, "stubs")) table.insert(linkdirs, path.join(sdkdir, "lib", subdir)) elseif is_plat("linux") and is_arch("x86_64") then table.insert(linkdirs, path.join(sdkdir, "lib64", "stubs")) diff --git a/xmake/rules/cuda/env/xmake.lua b/xmake/rules/cuda/env/xmake.lua index a334bb200..a4d408d2d 100644 --- a/xmake/rules/cuda/env/xmake.lua +++ b/xmake/rules/cuda/env/xmake.lua @@ -28,12 +28,12 @@ rule("cuda.env") target:data_set("cuda", cuda) -- add arch - if is_arch("x86_64", "x64") then - target:add("cuflags", "-m64", {force = true}) - target:add("culdflags", "-m64", {force = true}) - else + if is_arch("i386", "x86") then target:add("cuflags", "-m32", {force = true}) target:add("culdflags", "-m32", {force = true}) + else + target:add("cuflags", "-m64", {force = true}) + target:add("culdflags", "-m64", {force = true}) end -- add -ccbin -- cgit v1.3.1 From f42f1b5a97f5fdbac4d74a2e43a32fcc71cee0c3 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 11 Jun 2019 00:54:39 +0800 Subject: improve cuda.env and ignore static kind --- xmake/rules/cuda/device_link/xmake.lua | 21 ++++++--------------- xmake/rules/cuda/env/xmake.lua | 19 ++++++++++++++++++- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/xmake/rules/cuda/device_link/xmake.lua b/xmake/rules/cuda/device_link/xmake.lua index 90481c34b..068c8270f 100644 --- a/xmake/rules/cuda/device_link/xmake.lua +++ b/xmake/rules/cuda/device_link/xmake.lua @@ -24,24 +24,15 @@ rule("cuda.device_link") -- add rule: cuda environment add_deps("cuda.env") - -- after load - after_load(function (target) - - -- get cuda - local cuda = assert(target:data("cuda")) - - -- add links - target:add("links", "cudadevrt", "cudart_static") - if is_plat("linux") then - target:add("links", "rt", "pthread", "dl") - end - target:add("linkdirs", cuda.linkdirs) - target:add("rpathdirs", cuda.linkdirs) - end) - -- @see https://devblogs.nvidia.com/separate-compilation-linking-cuda-device-code/ before_link(function (target, opt) + -- only for binary/shared + local targetkind = target:targetkind() + if targetkind ~= "binary" and targetkind ~= "shared" then + return + end + -- imports import("core.base.option") import("core.theme.theme") diff --git a/xmake/rules/cuda/env/xmake.lua b/xmake/rules/cuda/env/xmake.lua index a4d408d2d..1acbc08ba 100644 --- a/xmake/rules/cuda/env/xmake.lua +++ b/xmake/rules/cuda/env/xmake.lua @@ -25,7 +25,6 @@ rule("cuda.env") -- get cuda sdk import("detect.sdks.find_cuda") local cuda = assert(find_cuda(nil, {verbose = true}), "Cuda SDK not found!") - target:data_set("cuda", cuda) -- add arch if is_arch("i386", "x86") then @@ -43,6 +42,24 @@ rule("cuda.env") target:add("culdflags", "-ccbin", os.args(cu_ccbin), {force = true}) end + -- add links + target:add("syslinks", "cudadevrt") + local cudart = false + for _, link in ipairs(table.join(target:get("links") or {}, target:get("syslinks"))) do + if link == "cudart" or link == "cudart_static" then + cudart = true + break + end + end + if not cudart then + target:add("syslinks", "cudart_static") + end + if is_plat("linux") then + target:add("syslinks", "rt", "pthread", "dl") + end + target:add("linkdirs", cuda.linkdirs) + target:add("rpathdirs", cuda.linkdirs) + -- add includedirs target:add("includedirs", cuda.includedirs) end) -- cgit v1.3.1 From a4958a1e1f62beff40d4df0c6634236583163707 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Tue, 11 Jun 2019 10:29:15 +0800 Subject: add some tests and templates --- tests/projects/cuda/shared/.gitignore | 2 + tests/projects/cuda/shared/inc/lib.cuh | 23 ++++ tests/projects/cuda/shared/src/lib.cu | 97 ++++++++++++++++ tests/projects/cuda/shared/src/main.cu | 34 ++++++ tests/projects/cuda/shared/xmake.lua | 22 ++++ tests/projects/cuda/static/.gitignore | 2 + tests/projects/cuda/static/inc/lib.cuh | 3 + tests/projects/cuda/static/src/lib.cu | 7 ++ tests/projects/cuda/static/src/main.cu | 127 +++++++++++++++++++++ tests/projects/cuda/static/xmake.lua | 24 ++++ xmake/templates/cuda/console/project/xmake.lua | 5 + .../cuda/shared_library/project/.gitignore | 2 + .../cuda/shared_library/project/inc/lib.cuh | 22 ++++ .../cuda/shared_library/project/src/lib.cu | 98 ++++++++++++++++ .../cuda/shared_library/project/xmake.lua | 35 ++++++ xmake/templates/cuda/shared_library/template.lua | 14 +++ .../cuda/static_library/project/.gitignore | 2 + .../cuda/static_library/project/inc/lib.cuh | 3 + .../cuda/static_library/project/src/lib.cu | 7 ++ .../cuda/static_library/project/xmake.lua | 35 ++++++ xmake/templates/cuda/static_library/template.lua | 14 +++ 21 files changed, 578 insertions(+) create mode 100644 tests/projects/cuda/shared/.gitignore create mode 100644 tests/projects/cuda/shared/inc/lib.cuh create mode 100644 tests/projects/cuda/shared/src/lib.cu create mode 100644 tests/projects/cuda/shared/src/main.cu create mode 100644 tests/projects/cuda/shared/xmake.lua create mode 100644 tests/projects/cuda/static/.gitignore create mode 100644 tests/projects/cuda/static/inc/lib.cuh create mode 100644 tests/projects/cuda/static/src/lib.cu create mode 100644 tests/projects/cuda/static/src/main.cu create mode 100644 tests/projects/cuda/static/xmake.lua create mode 100644 xmake/templates/cuda/shared_library/project/.gitignore create mode 100644 xmake/templates/cuda/shared_library/project/inc/lib.cuh create mode 100644 xmake/templates/cuda/shared_library/project/src/lib.cu create mode 100644 xmake/templates/cuda/shared_library/project/xmake.lua create mode 100644 xmake/templates/cuda/shared_library/template.lua create mode 100644 xmake/templates/cuda/static_library/project/.gitignore create mode 100644 xmake/templates/cuda/static_library/project/inc/lib.cuh create mode 100644 xmake/templates/cuda/static_library/project/src/lib.cu create mode 100644 xmake/templates/cuda/static_library/project/xmake.lua create mode 100644 xmake/templates/cuda/static_library/template.lua diff --git a/tests/projects/cuda/shared/.gitignore b/tests/projects/cuda/shared/.gitignore new file mode 100644 index 000000000..173fb6eaf --- /dev/null +++ b/tests/projects/cuda/shared/.gitignore @@ -0,0 +1,2 @@ +.xmake +build diff --git a/tests/projects/cuda/shared/inc/lib.cuh b/tests/projects/cuda/shared/inc/lib.cuh new file mode 100644 index 000000000..84d5db3ca --- /dev/null +++ b/tests/projects/cuda/shared/inc/lib.cuh @@ -0,0 +1,23 @@ +#pragma once + +#include "cuda_runtime.h" +#include "device_launch_parameters.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +#if defined(_WIN32) +#define __export __declspec(dllexport) +#elif defined(__GNUC__) && ((__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)) +#define __export __attribute__((visibility("default"))) +#else +#define __export +#endif + + __export cudaError_t addWithCuda(int *c, const int *a, const int *b, unsigned int size); + +#ifdef __cplusplus +} +#endif diff --git a/tests/projects/cuda/shared/src/lib.cu b/tests/projects/cuda/shared/src/lib.cu new file mode 100644 index 000000000..cd33b167b --- /dev/null +++ b/tests/projects/cuda/shared/src/lib.cu @@ -0,0 +1,97 @@ +#include +#include + +__global__ void addKernel(int *c, const int *a, const int *b) +{ + int i = threadIdx.x; + c[i] = a[i] + b[i]; +} + +// Helper function for using CUDA to add vectors in parallel. +cudaError_t addWithCuda(int *c, const int *a, const int *b, unsigned int size) +{ + int *dev_a = 0; + int *dev_b = 0; + int *dev_c = 0; + cudaError_t cudaStatus; + + // Choose which GPU to run on, change this on a multi-GPU system. + cudaStatus = cudaSetDevice(0); + if (cudaStatus != cudaSuccess) + { + fprintf(stderr, "cudaSetDevice failed! Do you have a CUDA-capable GPU installed?"); + goto Error; + } + + // Allocate GPU buffers for three vectors (two input, one output) . + cudaStatus = cudaMalloc((void **)&dev_c, size * sizeof(int)); + if (cudaStatus != cudaSuccess) + { + fprintf(stderr, "cudaMalloc failed!"); + goto Error; + } + + cudaStatus = cudaMalloc((void **)&dev_a, size * sizeof(int)); + if (cudaStatus != cudaSuccess) + { + fprintf(stderr, "cudaMalloc failed!"); + goto Error; + } + + cudaStatus = cudaMalloc((void **)&dev_b, size * sizeof(int)); + if (cudaStatus != cudaSuccess) + { + fprintf(stderr, "cudaMalloc failed!"); + goto Error; + } + + // Copy input vectors from host memory to GPU buffers. + cudaStatus = cudaMemcpy(dev_a, a, size * sizeof(int), cudaMemcpyHostToDevice); + if (cudaStatus != cudaSuccess) + { + fprintf(stderr, "cudaMemcpy failed!"); + goto Error; + } + + cudaStatus = cudaMemcpy(dev_b, b, size * sizeof(int), cudaMemcpyHostToDevice); + if (cudaStatus != cudaSuccess) + { + fprintf(stderr, "cudaMemcpy failed!"); + goto Error; + } + + // Launch a kernel on the GPU with one thread for each element. + addKernel<<<1, size>>>(dev_c, dev_a, dev_b); + + // Check for any errors launching the kernel + cudaStatus = cudaGetLastError(); + if (cudaStatus != cudaSuccess) + { + fprintf(stderr, "addKernel launch failed: %s\n", cudaGetErrorString(cudaStatus)); + goto Error; + } + + // cudaDeviceSynchronize waits for the kernel to finish, and returns + // any errors encountered during the launch. + cudaStatus = cudaDeviceSynchronize(); + if (cudaStatus != cudaSuccess) + { + fprintf(stderr, "cudaDeviceSynchronize returned error code %d after launching addKernel!\n", cudaStatus); + goto Error; + } + + // Copy output vector from GPU buffer to host memory. + cudaStatus = cudaMemcpy(c, dev_c, size * sizeof(int), cudaMemcpyDeviceToHost); + if (cudaStatus != cudaSuccess) + { + fprintf(stderr, "cudaMemcpy failed!"); + goto Error; + } + +Error: + cudaFree(dev_c); + cudaFree(dev_a); + cudaFree(dev_b); + + return cudaStatus; +} diff --git a/tests/projects/cuda/shared/src/main.cu b/tests/projects/cuda/shared/src/main.cu new file mode 100644 index 000000000..a33ec5c3e --- /dev/null +++ b/tests/projects/cuda/shared/src/main.cu @@ -0,0 +1,34 @@ + +#include "cuda_runtime.h" +#include +#include + +int main() +{ + const int arraySize = 5; + const int a[arraySize] = {1, 2, 3, 4, 5}; + const int b[arraySize] = {10, 20, 30, 40, 50}; + int c[arraySize] = {0}; + + // Add vectors in parallel. + cudaError_t cudaStatus = addWithCuda(c, a, b, arraySize); + if (cudaStatus != cudaSuccess) + { + fprintf(stderr, "addWithCuda failed!"); + return 1; + } + + printf("{1,2,3,4,5} + {10,20,30,40,50} = {%d,%d,%d,%d,%d}\n", + c[0], c[1], c[2], c[3], c[4]); + + // cudaDeviceReset must be called before exiting in order for profiling and + // tracing tools such as Nsight and Visual Profiler to show complete traces. + cudaStatus = cudaDeviceReset(); + if (cudaStatus != cudaSuccess) + { + fprintf(stderr, "cudaDeviceReset failed!"); + return 1; + } + + return 0; +} diff --git a/tests/projects/cuda/shared/xmake.lua b/tests/projects/cuda/shared/xmake.lua new file mode 100644 index 000000000..268f16dcd --- /dev/null +++ b/tests/projects/cuda/shared/xmake.lua @@ -0,0 +1,22 @@ + +-- add modes: debug and release +add_rules("mode.debug", "mode.release") + +add_includedirs("inc") + +-- generate PTX code for the virtual architecture to guarantee compatibility +add_cugencodes("compute_30") + +-- define target +target("lib") + + -- set kind + set_kind("shared") + + -- add files + add_files("src/lib.cu") + +target("bin") + add_deps("lib") + set_kind("binary") + add_files("src/main.cu") diff --git a/tests/projects/cuda/static/.gitignore b/tests/projects/cuda/static/.gitignore new file mode 100644 index 000000000..173fb6eaf --- /dev/null +++ b/tests/projects/cuda/static/.gitignore @@ -0,0 +1,2 @@ +.xmake +build diff --git a/tests/projects/cuda/static/inc/lib.cuh b/tests/projects/cuda/static/inc/lib.cuh new file mode 100644 index 000000000..35255e31e --- /dev/null +++ b/tests/projects/cuda/static/inc/lib.cuh @@ -0,0 +1,3 @@ +#pragma once + +__global__ void addKernel(int *c, const int *a, const int *b); \ No newline at end of file diff --git a/tests/projects/cuda/static/src/lib.cu b/tests/projects/cuda/static/src/lib.cu new file mode 100644 index 000000000..a5f054354 --- /dev/null +++ b/tests/projects/cuda/static/src/lib.cu @@ -0,0 +1,7 @@ +#include + +__global__ void addKernel(int *c, const int *a, const int *b) +{ + int i = threadIdx.x; + c[i] = a[i] + b[i]; +} \ No newline at end of file diff --git a/tests/projects/cuda/static/src/main.cu b/tests/projects/cuda/static/src/main.cu new file mode 100644 index 000000000..32844cd56 --- /dev/null +++ b/tests/projects/cuda/static/src/main.cu @@ -0,0 +1,127 @@ + +#include "cuda_runtime.h" +#include "device_launch_parameters.h" + +#include +#include + +cudaError_t addWithCuda(int *c, const int *a, const int *b, unsigned int size); + +int main() +{ + const int arraySize = 5; + const int a[arraySize] = {1, 2, 3, 4, 5}; + const int b[arraySize] = {10, 20, 30, 40, 50}; + int c[arraySize] = {0}; + + // Add vectors in parallel. + cudaError_t cudaStatus = addWithCuda(c, a, b, arraySize); + if (cudaStatus != cudaSuccess) + { + fprintf(stderr, "addWithCuda failed!"); + return 1; + } + + printf("{1,2,3,4,5} + {10,20,30,40,50} = {%d,%d,%d,%d,%d}\n", + c[0], c[1], c[2], c[3], c[4]); + + // cudaDeviceReset must be called before exiting in order for profiling and + // tracing tools such as Nsight and Visual Profiler to show complete traces. + cudaStatus = cudaDeviceReset(); + if (cudaStatus != cudaSuccess) + { + fprintf(stderr, "cudaDeviceReset failed!"); + return 1; + } + + return 0; +} + +// Helper function for using CUDA to add vectors in parallel. +cudaError_t addWithCuda(int *c, const int *a, const int *b, unsigned int size) +{ + int *dev_a = 0; + int *dev_b = 0; + int *dev_c = 0; + cudaError_t cudaStatus; + + // Choose which GPU to run on, change this on a multi-GPU system. + cudaStatus = cudaSetDevice(0); + if (cudaStatus != cudaSuccess) + { + fprintf(stderr, "cudaSetDevice failed! Do you have a CUDA-capable GPU installed?"); + goto Error; + } + + // Allocate GPU buffers for three vectors (two input, one output) . + cudaStatus = cudaMalloc((void **)&dev_c, size * sizeof(int)); + if (cudaStatus != cudaSuccess) + { + fprintf(stderr, "cudaMalloc failed!"); + goto Error; + } + + cudaStatus = cudaMalloc((void **)&dev_a, size * sizeof(int)); + if (cudaStatus != cudaSuccess) + { + fprintf(stderr, "cudaMalloc failed!"); + goto Error; + } + + cudaStatus = cudaMalloc((void **)&dev_b, size * sizeof(int)); + if (cudaStatus != cudaSuccess) + { + fprintf(stderr, "cudaMalloc failed!"); + goto Error; + } + + // Copy input vectors from host memory to GPU buffers. + cudaStatus = cudaMemcpy(dev_a, a, size * sizeof(int), cudaMemcpyHostToDevice); + if (cudaStatus != cudaSuccess) + { + fprintf(stderr, "cudaMemcpy failed!"); + goto Error; + } + + cudaStatus = cudaMemcpy(dev_b, b, size * sizeof(int), cudaMemcpyHostToDevice); + if (cudaStatus != cudaSuccess) + { + fprintf(stderr, "cudaMemcpy failed!"); + goto Error; + } + + // Launch a kernel on the GPU with one thread for each element. + addKernel<<<1, size>>>(dev_c, dev_a, dev_b); + + // Check for any errors launching the kernel + cudaStatus = cudaGetLastError(); + if (cudaStatus != cudaSuccess) + { + fprintf(stderr, "addKernel launch failed: %s\n", cudaGetErrorString(cudaStatus)); + goto Error; + } + + // cudaDeviceSynchronize waits for the kernel to finish, and returns + // any errors encountered during the launch. + cudaStatus = cudaDeviceSynchronize(); + if (cudaStatus != cudaSuccess) + { + fprintf(stderr, "cudaDeviceSynchronize returned error code %d after launching addKernel!\n", cudaStatus); + goto Error; + } + + // Copy output vector from GPU buffer to host memory. + cudaStatus = cudaMemcpy(c, dev_c, size * sizeof(int), cudaMemcpyDeviceToHost); + if (cudaStatus != cudaSuccess) + { + fprintf(stderr, "cudaMemcpy failed!"); + goto Error; + } + +Error: + cudaFree(dev_c); + cudaFree(dev_a); + cudaFree(dev_b); + + return cudaStatus; +} diff --git a/tests/projects/cuda/static/xmake.lua b/tests/projects/cuda/static/xmake.lua new file mode 100644 index 000000000..fd2143bfb --- /dev/null +++ b/tests/projects/cuda/static/xmake.lua @@ -0,0 +1,24 @@ + +-- add modes: debug and release +add_rules("mode.debug", "mode.release") + +add_includedirs("inc") + +-- generate PTX code for the virtual architecture to guarantee compatibility +add_cugencodes("compute_30") + +-- define target +target("lib") + + -- set kind + set_kind("static") + + add_cuflags("-rdc=true") + + -- add files + add_files("src/lib.cu") + +target("bin") + add_deps("lib") + set_kind("binary") + add_files("src/main.cu") diff --git a/xmake/templates/cuda/console/project/xmake.lua b/xmake/templates/cuda/console/project/xmake.lua index 1c1c48cfb..226488448 100644 --- a/xmake/templates/cuda/console/project/xmake.lua +++ b/xmake/templates/cuda/console/project/xmake.lua @@ -8,6 +8,11 @@ target("[targetname]") -- set kind set_kind("binary") + -- generate relocatable device code for device linker of dependents + -- if no __device__ and __global__ functions will be called cross file, + -- this instruction could be omitted + -- add_cuflags("-rdc=true") + -- add files add_files("src/*.cu") diff --git a/xmake/templates/cuda/shared_library/project/.gitignore b/xmake/templates/cuda/shared_library/project/.gitignore new file mode 100644 index 000000000..173fb6eaf --- /dev/null +++ b/xmake/templates/cuda/shared_library/project/.gitignore @@ -0,0 +1,2 @@ +.xmake +build diff --git a/xmake/templates/cuda/shared_library/project/inc/lib.cuh b/xmake/templates/cuda/shared_library/project/inc/lib.cuh new file mode 100644 index 000000000..5565e3eb5 --- /dev/null +++ b/xmake/templates/cuda/shared_library/project/inc/lib.cuh @@ -0,0 +1,22 @@ +#pragma once + +#include "cuda_runtime.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +#if defined(_WIN32) +#define __export __declspec(dllexport) +#elif defined(__GNUC__) && ((__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)) +#define __export __attribute__((visibility("default"))) +#else +#define __export +#endif + + __export cudaError_t addWithCuda(int *c, const int *a, const int *b, unsigned int size); + +#ifdef __cplusplus +} +#endif diff --git a/xmake/templates/cuda/shared_library/project/src/lib.cu b/xmake/templates/cuda/shared_library/project/src/lib.cu new file mode 100644 index 000000000..d2cff9ac2 --- /dev/null +++ b/xmake/templates/cuda/shared_library/project/src/lib.cu @@ -0,0 +1,98 @@ +#include +#include +#include "device_launch_parameters.h" + +__global__ void addKernel(int *c, const int *a, const int *b) +{ + int i = threadIdx.x; + c[i] = a[i] + b[i]; +} + +// Helper function for using CUDA to add vectors in parallel. +cudaError_t addWithCuda(int *c, const int *a, const int *b, unsigned int size) +{ + int *dev_a = 0; + int *dev_b = 0; + int *dev_c = 0; + cudaError_t cudaStatus; + + // Choose which GPU to run on, change this on a multi-GPU system. + cudaStatus = cudaSetDevice(0); + if (cudaStatus != cudaSuccess) + { + fprintf(stderr, "cudaSetDevice failed! Do you have a CUDA-capable GPU installed?"); + goto Error; + } + + // Allocate GPU buffers for three vectors (two input, one output) . + cudaStatus = cudaMalloc((void **)&dev_c, size * sizeof(int)); + if (cudaStatus != cudaSuccess) + { + fprintf(stderr, "cudaMalloc failed!"); + goto Error; + } + + cudaStatus = cudaMalloc((void **)&dev_a, size * sizeof(int)); + if (cudaStatus != cudaSuccess) + { + fprintf(stderr, "cudaMalloc failed!"); + goto Error; + } + + cudaStatus = cudaMalloc((void **)&dev_b, size * sizeof(int)); + if (cudaStatus != cudaSuccess) + { + fprintf(stderr, "cudaMalloc failed!"); + goto Error; + } + + // Copy input vectors from host memory to GPU buffers. + cudaStatus = cudaMemcpy(dev_a, a, size * sizeof(int), cudaMemcpyHostToDevice); + if (cudaStatus != cudaSuccess) + { + fprintf(stderr, "cudaMemcpy failed!"); + goto Error; + } + + cudaStatus = cudaMemcpy(dev_b, b, size * sizeof(int), cudaMemcpyHostToDevice); + if (cudaStatus != cudaSuccess) + { + fprintf(stderr, "cudaMemcpy failed!"); + goto Error; + } + + // Launch a kernel on the GPU with one thread for each element. + addKernel<<<1, size>>>(dev_c, dev_a, dev_b); + + // Check for any errors launching the kernel + cudaStatus = cudaGetLastError(); + if (cudaStatus != cudaSuccess) + { + fprintf(stderr, "addKernel launch failed: %s\n", cudaGetErrorString(cudaStatus)); + goto Error; + } + + // cudaDeviceSynchronize waits for the kernel to finish, and returns + // any errors encountered during the launch. + cudaStatus = cudaDeviceSynchronize(); + if (cudaStatus != cudaSuccess) + { + fprintf(stderr, "cudaDeviceSynchronize returned error code %d after launching addKernel!\n", cudaStatus); + goto Error; + } + + // Copy output vector from GPU buffer to host memory. + cudaStatus = cudaMemcpy(c, dev_c, size * sizeof(int), cudaMemcpyDeviceToHost); + if (cudaStatus != cudaSuccess) + { + fprintf(stderr, "cudaMemcpy failed!"); + goto Error; + } + +Error: + cudaFree(dev_c); + cudaFree(dev_a); + cudaFree(dev_b); + + return cudaStatus; +} diff --git a/xmake/templates/cuda/shared_library/project/xmake.lua b/xmake/templates/cuda/shared_library/project/xmake.lua new file mode 100644 index 000000000..8ffb8b7e9 --- /dev/null +++ b/xmake/templates/cuda/shared_library/project/xmake.lua @@ -0,0 +1,35 @@ + +-- add modes: debug and release +add_rules("mode.debug", "mode.release") + +-- define target +target("[targetname]") + + -- set kind + set_kind("shared") + + -- add modes: debug and release + add_rules("mode.debug", "mode.release") + + -- add include dirs + add_includedirs("inc") + + -- generate relocatable device code for device linker of dependents + -- if no __device__ and __global__ functions will be called cross file, + -- this instruction could be omitted + -- add_cuflags("-rdc=true") + + -- add files + add_files("src/**.cu") + + -- generate SASS code for SM architecture of current host + add_cugencodes("native") + + -- generate PTX code for the virtual architecture to guarantee compatibility + add_cugencodes("compute_30") + + -- -- 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") + + -- -- generate PTX code from the highest SM architecture to guarantee forward-compatibility + -- add_cugencodes("compute_75") diff --git a/xmake/templates/cuda/shared_library/template.lua b/xmake/templates/cuda/shared_library/template.lua new file mode 100644 index 000000000..ff9c56179 --- /dev/null +++ b/xmake/templates/cuda/shared_library/template.lua @@ -0,0 +1,14 @@ +-- set name +set_name("static") + +-- set description +set_description("The Static Library") + +-- set project directory +set_projectdir("project") + +-- add macros +add_macros("targetname", "$(targetname)") + +-- add macro files +add_macrofiles("xmake.lua") \ No newline at end of file diff --git a/xmake/templates/cuda/static_library/project/.gitignore b/xmake/templates/cuda/static_library/project/.gitignore new file mode 100644 index 000000000..173fb6eaf --- /dev/null +++ b/xmake/templates/cuda/static_library/project/.gitignore @@ -0,0 +1,2 @@ +.xmake +build diff --git a/xmake/templates/cuda/static_library/project/inc/lib.cuh b/xmake/templates/cuda/static_library/project/inc/lib.cuh new file mode 100644 index 000000000..35255e31e --- /dev/null +++ b/xmake/templates/cuda/static_library/project/inc/lib.cuh @@ -0,0 +1,3 @@ +#pragma once + +__global__ void addKernel(int *c, const int *a, const int *b); \ No newline at end of file diff --git a/xmake/templates/cuda/static_library/project/src/lib.cu b/xmake/templates/cuda/static_library/project/src/lib.cu new file mode 100644 index 000000000..a5f054354 --- /dev/null +++ b/xmake/templates/cuda/static_library/project/src/lib.cu @@ -0,0 +1,7 @@ +#include + +__global__ void addKernel(int *c, const int *a, const int *b) +{ + int i = threadIdx.x; + c[i] = a[i] + b[i]; +} \ No newline at end of file diff --git a/xmake/templates/cuda/static_library/project/xmake.lua b/xmake/templates/cuda/static_library/project/xmake.lua new file mode 100644 index 000000000..be08da0da --- /dev/null +++ b/xmake/templates/cuda/static_library/project/xmake.lua @@ -0,0 +1,35 @@ + +-- add modes: debug and release +add_rules("mode.debug", "mode.release") + +-- define target +target("[targetname]") + + -- set kind + set_kind("static") + + -- add modes: debug and release + add_rules("mode.debug", "mode.release") + + -- add include dirs + add_includedirs("inc") + + -- generate relocatable device code for device linker of dependents + -- if no __device__ and __global__ functions will be called cross file or be exported, + -- this instruction could be omitted + add_cuflags("-rdc=true") + + -- add files + add_files("src/**.cu") + + -- generate SASS code for SM architecture of current host + add_cugencodes("native") + + -- generate PTX code for the virtual architecture to guarantee compatibility + add_cugencodes("compute_30") + + -- -- 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") + + -- -- generate PTX code from the highest SM architecture to guarantee forward-compatibility + -- add_cugencodes("compute_75") diff --git a/xmake/templates/cuda/static_library/template.lua b/xmake/templates/cuda/static_library/template.lua new file mode 100644 index 000000000..ff9c56179 --- /dev/null +++ b/xmake/templates/cuda/static_library/template.lua @@ -0,0 +1,14 @@ +-- set name +set_name("static") + +-- set description +set_description("The Static Library") + +-- set project directory +set_projectdir("project") + +-- add macros +add_macros("targetname", "$(targetname)") + +-- add macro files +add_macrofiles("xmake.lua") \ No newline at end of file -- cgit v1.3.1 From 664dc2e0e8820eab96c2cae5f2e451894bc1fc4b Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Tue, 11 Jun 2019 10:30:08 +0800 Subject: fix --- xmake/templates/cuda/shared_library/template.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xmake/templates/cuda/shared_library/template.lua b/xmake/templates/cuda/shared_library/template.lua index ff9c56179..6df920968 100644 --- a/xmake/templates/cuda/shared_library/template.lua +++ b/xmake/templates/cuda/shared_library/template.lua @@ -1,8 +1,8 @@ -- set name -set_name("static") +set_name("shared") -- set description -set_description("The Static Library") +set_description("The Shared Library") -- set project directory set_projectdir("project") -- cgit v1.3.1 From 0708b41747a388e1d055de9cdba8b4a3d64203e0 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 11 Jun 2019 23:02:03 +0800 Subject: fix find_cuda --- xmake/modules/detect/sdks/find_cuda.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xmake/modules/detect/sdks/find_cuda.lua b/xmake/modules/detect/sdks/find_cuda.lua index d87d5b3b0..f9077a485 100644 --- a/xmake/modules/detect/sdks/find_cuda.lua +++ b/xmake/modules/detect/sdks/find_cuda.lua @@ -103,9 +103,9 @@ function main(sdkdir, opt) opt = opt or {} -- attempt to load cache first - local key = "detect.sdks.find_cuda." .. (sdkdir or "") + local key = "detect.sdks.find_cuda" local cacheinfo = cache.load(key) - if not opt.force and cacheinfo.cuda then + if not opt.force and cacheinfo.cuda and cacheinfo.cuda.sdkdir and os.isdir(cacheinfo.cuda.sdkdir) then return cacheinfo.cuda end -- cgit v1.3.1 From 62f4a6f00af4d3d2cc7b20e29ff931b1373e5570 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 11 Jun 2019 23:02:37 +0800 Subject: improve find_qt and wdk --- xmake/modules/detect/sdks/find_qt.lua | 4 ++-- xmake/modules/detect/sdks/find_wdk.lua | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/xmake/modules/detect/sdks/find_qt.lua b/xmake/modules/detect/sdks/find_qt.lua index 885198575..6ab39b254 100644 --- a/xmake/modules/detect/sdks/find_qt.lua +++ b/xmake/modules/detect/sdks/find_qt.lua @@ -153,9 +153,9 @@ function main(sdkdir, opt) opt = opt or {} -- attempt to load cache first - local key = "detect.sdks.find_qt." .. (sdkdir or "") + local key = "detect.sdks.find_qt" local cacheinfo = cache.load(key) - if not opt.force and cacheinfo.qt then + if not opt.force and cacheinfo.qt and cacheinfo.qt.sdkdir and os.isdir(cacheinfo.qt.sdkdir) then return cacheinfo.qt end diff --git a/xmake/modules/detect/sdks/find_wdk.lua b/xmake/modules/detect/sdks/find_wdk.lua index 513be1f88..e19befd02 100644 --- a/xmake/modules/detect/sdks/find_wdk.lua +++ b/xmake/modules/detect/sdks/find_wdk.lua @@ -160,9 +160,9 @@ function main(sdkdir, opt) opt = opt or {} -- attempt to load cache first - local key = "detect.sdks.find_wdk." .. (sdkdir or "") + local key = "detect.sdks.find_wdk" local cacheinfo = cache.load(key) - if not opt.force and cacheinfo.wdk then + if not opt.force and cacheinfo.wdk and cacheinfo.wdk.sdkdir and os.isdir(cacheinfo.wdk.sdkdir) then return cacheinfo.wdk end -- cgit v1.3.1 From 1a2c6dda0be99e448ec63966a4695b47679f3805 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 11 Jun 2019 23:11:23 +0800 Subject: switch to get.ps1 master in ci --- .appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.appveyor.yml b/.appveyor.yml index 48a726de3..428d65ecb 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -9,7 +9,7 @@ platform: - Win64 install: - - ps: ./scripts/get.ps1 -branch $env:APPVEYOR_REPO_BRANCH + - ps: ./scripts/get.ps1 -branch master build_script: - ps: Get-Command xmake -- cgit v1.3.1 From 62a558c85e80081f78d340410c4ba7185d42ca89 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 11 Jun 2019 13:10:57 +0800 Subject: Revert "switch to get.ps1 master in ci" This reverts commit 1a2c6dda0be99e448ec63966a4695b47679f3805. --- .appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.appveyor.yml b/.appveyor.yml index 428d65ecb..48a726de3 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -9,7 +9,7 @@ platform: - Win64 install: - - ps: ./scripts/get.ps1 -branch master + - ps: ./scripts/get.ps1 -branch $env:APPVEYOR_REPO_BRANCH build_script: - ps: Get-Command xmake -- cgit v1.3.1 From 35cfc8782c166bb1111472c4732f5c44d8939863 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Tue, 11 Jun 2019 13:12:47 +0800 Subject: clean up git ignore; fix test xmake.lua --- .gitignore | 57 ++++++---------------- tests/projects/cuda/shared/.gitignore | 2 - tests/projects/cuda/shared/xmake.lua | 4 +- tests/projects/cuda/static/.gitignore | 2 - tests/projects/cuda/static/xmake.lua | 4 +- xmake/scripts/gitignore | 27 ++-------- xmake/templates/c++/console/project/.gitignore | 27 ++-------- xmake/templates/c++/console_qt/project/.gitignore | 27 ++-------- .../templates/c++/console_tbox/project/.gitignore | 27 ++-------- .../c++/shared_library/project/.gitignore | 27 ++-------- .../c++/shared_library_qt/project/.gitignore | 27 ++-------- .../c++/shared_library_tbox/project/.gitignore | 27 ++-------- .../c++/static_library/project/.gitignore | 27 ++-------- .../c++/static_library_qt/project/.gitignore | 27 ++-------- .../c++/static_library_tbox/project/.gitignore | 27 ++-------- xmake/templates/c/console/project/.gitignore | 27 ++-------- xmake/templates/c/console_tbox/.gitignore | 27 ++-------- .../templates/c/shared_library/project/.gitignore | 27 ++-------- .../c/shared_library_tbox/project/.gitignore | 27 ++-------- .../templates/c/static_library/project/.gitignore | 27 ++-------- .../c/static_library_tbox/project/.gitignore | 27 ++-------- xmake/templates/cuda/console/project/.gitignore | 27 ++-------- xmake/templates/dlang/console/project/.gitignore | 27 ++-------- .../dlang/shared_library/project/.gitignore | 27 ++-------- .../dlang/static_library/project/.gitignore | 27 ++-------- xmake/templates/go/console/project/.gitignore | 27 ++-------- .../templates/go/static_library/project/.gitignore | 27 ++-------- xmake/templates/objc++/console/project/.gitignore | 27 ++-------- xmake/templates/objc/console/project/.gitignore | 27 ++-------- xmake/templates/rust/console/project/.gitignore | 27 ++-------- .../rust/static_library/project/.gitignore | 27 ++-------- xmake/templates/swift/console/project/.gitignore | 27 ++-------- 32 files changed, 153 insertions(+), 645 deletions(-) delete mode 100644 tests/projects/cuda/shared/.gitignore delete mode 100644 tests/projects/cuda/static/.gitignore diff --git a/.gitignore b/.gitignore index cd7ecbe72..11fe9ea9d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,44 +1,15 @@ -*.a -*.b -*.o -*.exe -*.obj -*.dll -*.lib -*.out -*.suo -*~ -*.swp -*.swo -*.bak -*.orig -*.pdb -*.idb -*.ilk -*.stackdump -*.manifest -.ccache -.demo -.svn -.DS_Store -.xmake -*.deb -*.zip -*.gch -*.gch.d -*.sys -cscope.* -gmon.out -tags -doc +.DS_Store/ +.xmake/ +build/ +winenv/ +xmake-ppa/ +.vscode/ +/*.exe +/*.zip +/xmake/*.exe +/xmake/*.zip +/scripts/*.exe +/scripts/*.zip install.log -build -core/bin -core/pre -core/tool/msys -core/xmake.config.h -core/.config.mak -winenv -xmake-ppa -!xmake/actions/build -.vscode/ \ No newline at end of file + +!/xmake/actions/build/ \ No newline at end of file diff --git a/tests/projects/cuda/shared/.gitignore b/tests/projects/cuda/shared/.gitignore deleted file mode 100644 index 173fb6eaf..000000000 --- a/tests/projects/cuda/shared/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -.xmake -build diff --git a/tests/projects/cuda/shared/xmake.lua b/tests/projects/cuda/shared/xmake.lua index 268f16dcd..e96999a13 100644 --- a/tests/projects/cuda/shared/xmake.lua +++ b/tests/projects/cuda/shared/xmake.lua @@ -2,8 +2,6 @@ -- add modes: debug and release add_rules("mode.debug", "mode.release") -add_includedirs("inc") - -- generate PTX code for the virtual architecture to guarantee compatibility add_cugencodes("compute_30") @@ -16,6 +14,8 @@ target("lib") -- add files add_files("src/lib.cu") + add_includedirs("inc", {public = true}) + target("bin") add_deps("lib") set_kind("binary") diff --git a/tests/projects/cuda/static/.gitignore b/tests/projects/cuda/static/.gitignore deleted file mode 100644 index 173fb6eaf..000000000 --- a/tests/projects/cuda/static/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -.xmake -build diff --git a/tests/projects/cuda/static/xmake.lua b/tests/projects/cuda/static/xmake.lua index fd2143bfb..55e1e5fd9 100644 --- a/tests/projects/cuda/static/xmake.lua +++ b/tests/projects/cuda/static/xmake.lua @@ -2,8 +2,6 @@ -- add modes: debug and release add_rules("mode.debug", "mode.release") -add_includedirs("inc") - -- generate PTX code for the virtual architecture to guarantee compatibility add_cugencodes("compute_30") @@ -15,6 +13,8 @@ target("lib") add_cuflags("-rdc=true") + add_includedirs("inc", {public = true}) + -- add files add_files("src/lib.cu") diff --git a/xmake/scripts/gitignore b/xmake/scripts/gitignore index 08ffbbd04..e4ede4aa6 100644 --- a/xmake/scripts/gitignore +++ b/xmake/scripts/gitignore @@ -1,22 +1,5 @@ -*.a -*.o -*.exe -*.obj -*.dll -*.lib -*.out -*.suo -*~ -*.swp -*.swo -*.bak -*.orig -*.pdb -*.idb -.svn -.DS_Store -.xmake -*.gch -*.gch.d -gmon.out -build +# xmake temp files +.xmake/ +# build result files +build/ + diff --git a/xmake/templates/c++/console/project/.gitignore b/xmake/templates/c++/console/project/.gitignore index 08ffbbd04..e4ede4aa6 100644 --- a/xmake/templates/c++/console/project/.gitignore +++ b/xmake/templates/c++/console/project/.gitignore @@ -1,22 +1,5 @@ -*.a -*.o -*.exe -*.obj -*.dll -*.lib -*.out -*.suo -*~ -*.swp -*.swo -*.bak -*.orig -*.pdb -*.idb -.svn -.DS_Store -.xmake -*.gch -*.gch.d -gmon.out -build +# xmake temp files +.xmake/ +# build result files +build/ + diff --git a/xmake/templates/c++/console_qt/project/.gitignore b/xmake/templates/c++/console_qt/project/.gitignore index 08ffbbd04..e4ede4aa6 100644 --- a/xmake/templates/c++/console_qt/project/.gitignore +++ b/xmake/templates/c++/console_qt/project/.gitignore @@ -1,22 +1,5 @@ -*.a -*.o -*.exe -*.obj -*.dll -*.lib -*.out -*.suo -*~ -*.swp -*.swo -*.bak -*.orig -*.pdb -*.idb -.svn -.DS_Store -.xmake -*.gch -*.gch.d -gmon.out -build +# xmake temp files +.xmake/ +# build result files +build/ + diff --git a/xmake/templates/c++/console_tbox/project/.gitignore b/xmake/templates/c++/console_tbox/project/.gitignore index 08ffbbd04..e4ede4aa6 100644 --- a/xmake/templates/c++/console_tbox/project/.gitignore +++ b/xmake/templates/c++/console_tbox/project/.gitignore @@ -1,22 +1,5 @@ -*.a -*.o -*.exe -*.obj -*.dll -*.lib -*.out -*.suo -*~ -*.swp -*.swo -*.bak -*.orig -*.pdb -*.idb -.svn -.DS_Store -.xmake -*.gch -*.gch.d -gmon.out -build +# xmake temp files +.xmake/ +# build result files +build/ + diff --git a/xmake/templates/c++/shared_library/project/.gitignore b/xmake/templates/c++/shared_library/project/.gitignore index 08ffbbd04..e4ede4aa6 100644 --- a/xmake/templates/c++/shared_library/project/.gitignore +++ b/xmake/templates/c++/shared_library/project/.gitignore @@ -1,22 +1,5 @@ -*.a -*.o -*.exe -*.obj -*.dll -*.lib -*.out -*.suo -*~ -*.swp -*.swo -*.bak -*.orig -*.pdb -*.idb -.svn -.DS_Store -.xmake -*.gch -*.gch.d -gmon.out -build +# xmake temp files +.xmake/ +# build result files +build/ + diff --git a/xmake/templates/c++/shared_library_qt/project/.gitignore b/xmake/templates/c++/shared_library_qt/project/.gitignore index 08ffbbd04..e4ede4aa6 100644 --- a/xmake/templates/c++/shared_library_qt/project/.gitignore +++ b/xmake/templates/c++/shared_library_qt/project/.gitignore @@ -1,22 +1,5 @@ -*.a -*.o -*.exe -*.obj -*.dll -*.lib -*.out -*.suo -*~ -*.swp -*.swo -*.bak -*.orig -*.pdb -*.idb -.svn -.DS_Store -.xmake -*.gch -*.gch.d -gmon.out -build +# xmake temp files +.xmake/ +# build result files +build/ + diff --git a/xmake/templates/c++/shared_library_tbox/project/.gitignore b/xmake/templates/c++/shared_library_tbox/project/.gitignore index 08ffbbd04..e4ede4aa6 100644 --- a/xmake/templates/c++/shared_library_tbox/project/.gitignore +++ b/xmake/templates/c++/shared_library_tbox/project/.gitignore @@ -1,22 +1,5 @@ -*.a -*.o -*.exe -*.obj -*.dll -*.lib -*.out -*.suo -*~ -*.swp -*.swo -*.bak -*.orig -*.pdb -*.idb -.svn -.DS_Store -.xmake -*.gch -*.gch.d -gmon.out -build +# xmake temp files +.xmake/ +# build result files +build/ + diff --git a/xmake/templates/c++/static_library/project/.gitignore b/xmake/templates/c++/static_library/project/.gitignore index 08ffbbd04..e4ede4aa6 100644 --- a/xmake/templates/c++/static_library/project/.gitignore +++ b/xmake/templates/c++/static_library/project/.gitignore @@ -1,22 +1,5 @@ -*.a -*.o -*.exe -*.obj -*.dll -*.lib -*.out -*.suo -*~ -*.swp -*.swo -*.bak -*.orig -*.pdb -*.idb -.svn -.DS_Store -.xmake -*.gch -*.gch.d -gmon.out -build +# xmake temp files +.xmake/ +# build result files +build/ + diff --git a/xmake/templates/c++/static_library_qt/project/.gitignore b/xmake/templates/c++/static_library_qt/project/.gitignore index 08ffbbd04..e4ede4aa6 100644 --- a/xmake/templates/c++/static_library_qt/project/.gitignore +++ b/xmake/templates/c++/static_library_qt/project/.gitignore @@ -1,22 +1,5 @@ -*.a -*.o -*.exe -*.obj -*.dll -*.lib -*.out -*.suo -*~ -*.swp -*.swo -*.bak -*.orig -*.pdb -*.idb -.svn -.DS_Store -.xmake -*.gch -*.gch.d -gmon.out -build +# xmake temp files +.xmake/ +# build result files +build/ + diff --git a/xmake/templates/c++/static_library_tbox/project/.gitignore b/xmake/templates/c++/static_library_tbox/project/.gitignore index 08ffbbd04..e4ede4aa6 100644 --- a/xmake/templates/c++/static_library_tbox/project/.gitignore +++ b/xmake/templates/c++/static_library_tbox/project/.gitignore @@ -1,22 +1,5 @@ -*.a -*.o -*.exe -*.obj -*.dll -*.lib -*.out -*.suo -*~ -*.swp -*.swo -*.bak -*.orig -*.pdb -*.idb -.svn -.DS_Store -.xmake -*.gch -*.gch.d -gmon.out -build +# xmake temp files +.xmake/ +# build result files +build/ + diff --git a/xmake/templates/c/console/project/.gitignore b/xmake/templates/c/console/project/.gitignore index 08ffbbd04..e4ede4aa6 100644 --- a/xmake/templates/c/console/project/.gitignore +++ b/xmake/templates/c/console/project/.gitignore @@ -1,22 +1,5 @@ -*.a -*.o -*.exe -*.obj -*.dll -*.lib -*.out -*.suo -*~ -*.swp -*.swo -*.bak -*.orig -*.pdb -*.idb -.svn -.DS_Store -.xmake -*.gch -*.gch.d -gmon.out -build +# xmake temp files +.xmake/ +# build result files +build/ + diff --git a/xmake/templates/c/console_tbox/.gitignore b/xmake/templates/c/console_tbox/.gitignore index 08ffbbd04..e4ede4aa6 100644 --- a/xmake/templates/c/console_tbox/.gitignore +++ b/xmake/templates/c/console_tbox/.gitignore @@ -1,22 +1,5 @@ -*.a -*.o -*.exe -*.obj -*.dll -*.lib -*.out -*.suo -*~ -*.swp -*.swo -*.bak -*.orig -*.pdb -*.idb -.svn -.DS_Store -.xmake -*.gch -*.gch.d -gmon.out -build +# xmake temp files +.xmake/ +# build result files +build/ + diff --git a/xmake/templates/c/shared_library/project/.gitignore b/xmake/templates/c/shared_library/project/.gitignore index 08ffbbd04..e4ede4aa6 100644 --- a/xmake/templates/c/shared_library/project/.gitignore +++ b/xmake/templates/c/shared_library/project/.gitignore @@ -1,22 +1,5 @@ -*.a -*.o -*.exe -*.obj -*.dll -*.lib -*.out -*.suo -*~ -*.swp -*.swo -*.bak -*.orig -*.pdb -*.idb -.svn -.DS_Store -.xmake -*.gch -*.gch.d -gmon.out -build +# xmake temp files +.xmake/ +# build result files +build/ + diff --git a/xmake/templates/c/shared_library_tbox/project/.gitignore b/xmake/templates/c/shared_library_tbox/project/.gitignore index 08ffbbd04..e4ede4aa6 100644 --- a/xmake/templates/c/shared_library_tbox/project/.gitignore +++ b/xmake/templates/c/shared_library_tbox/project/.gitignore @@ -1,22 +1,5 @@ -*.a -*.o -*.exe -*.obj -*.dll -*.lib -*.out -*.suo -*~ -*.swp -*.swo -*.bak -*.orig -*.pdb -*.idb -.svn -.DS_Store -.xmake -*.gch -*.gch.d -gmon.out -build +# xmake temp files +.xmake/ +# build result files +build/ + diff --git a/xmake/templates/c/static_library/project/.gitignore b/xmake/templates/c/static_library/project/.gitignore index 08ffbbd04..e4ede4aa6 100644 --- a/xmake/templates/c/static_library/project/.gitignore +++ b/xmake/templates/c/static_library/project/.gitignore @@ -1,22 +1,5 @@ -*.a -*.o -*.exe -*.obj -*.dll -*.lib -*.out -*.suo -*~ -*.swp -*.swo -*.bak -*.orig -*.pdb -*.idb -.svn -.DS_Store -.xmake -*.gch -*.gch.d -gmon.out -build +# xmake temp files +.xmake/ +# build result files +build/ + diff --git a/xmake/templates/c/static_library_tbox/project/.gitignore b/xmake/templates/c/static_library_tbox/project/.gitignore index 08ffbbd04..e4ede4aa6 100644 --- a/xmake/templates/c/static_library_tbox/project/.gitignore +++ b/xmake/templates/c/static_library_tbox/project/.gitignore @@ -1,22 +1,5 @@ -*.a -*.o -*.exe -*.obj -*.dll -*.lib -*.out -*.suo -*~ -*.swp -*.swo -*.bak -*.orig -*.pdb -*.idb -.svn -.DS_Store -.xmake -*.gch -*.gch.d -gmon.out -build +# xmake temp files +.xmake/ +# build result files +build/ + diff --git a/xmake/templates/cuda/console/project/.gitignore b/xmake/templates/cuda/console/project/.gitignore index 08ffbbd04..e4ede4aa6 100644 --- a/xmake/templates/cuda/console/project/.gitignore +++ b/xmake/templates/cuda/console/project/.gitignore @@ -1,22 +1,5 @@ -*.a -*.o -*.exe -*.obj -*.dll -*.lib -*.out -*.suo -*~ -*.swp -*.swo -*.bak -*.orig -*.pdb -*.idb -.svn -.DS_Store -.xmake -*.gch -*.gch.d -gmon.out -build +# xmake temp files +.xmake/ +# build result files +build/ + diff --git a/xmake/templates/dlang/console/project/.gitignore b/xmake/templates/dlang/console/project/.gitignore index 08ffbbd04..e4ede4aa6 100644 --- a/xmake/templates/dlang/console/project/.gitignore +++ b/xmake/templates/dlang/console/project/.gitignore @@ -1,22 +1,5 @@ -*.a -*.o -*.exe -*.obj -*.dll -*.lib -*.out -*.suo -*~ -*.swp -*.swo -*.bak -*.orig -*.pdb -*.idb -.svn -.DS_Store -.xmake -*.gch -*.gch.d -gmon.out -build +# xmake temp files +.xmake/ +# build result files +build/ + diff --git a/xmake/templates/dlang/shared_library/project/.gitignore b/xmake/templates/dlang/shared_library/project/.gitignore index 08ffbbd04..e4ede4aa6 100644 --- a/xmake/templates/dlang/shared_library/project/.gitignore +++ b/xmake/templates/dlang/shared_library/project/.gitignore @@ -1,22 +1,5 @@ -*.a -*.o -*.exe -*.obj -*.dll -*.lib -*.out -*.suo -*~ -*.swp -*.swo -*.bak -*.orig -*.pdb -*.idb -.svn -.DS_Store -.xmake -*.gch -*.gch.d -gmon.out -build +# xmake temp files +.xmake/ +# build result files +build/ + diff --git a/xmake/templates/dlang/static_library/project/.gitignore b/xmake/templates/dlang/static_library/project/.gitignore index 08ffbbd04..e4ede4aa6 100644 --- a/xmake/templates/dlang/static_library/project/.gitignore +++ b/xmake/templates/dlang/static_library/project/.gitignore @@ -1,22 +1,5 @@ -*.a -*.o -*.exe -*.obj -*.dll -*.lib -*.out -*.suo -*~ -*.swp -*.swo -*.bak -*.orig -*.pdb -*.idb -.svn -.DS_Store -.xmake -*.gch -*.gch.d -gmon.out -build +# xmake temp files +.xmake/ +# build result files +build/ + diff --git a/xmake/templates/go/console/project/.gitignore b/xmake/templates/go/console/project/.gitignore index 08ffbbd04..e4ede4aa6 100644 --- a/xmake/templates/go/console/project/.gitignore +++ b/xmake/templates/go/console/project/.gitignore @@ -1,22 +1,5 @@ -*.a -*.o -*.exe -*.obj -*.dll -*.lib -*.out -*.suo -*~ -*.swp -*.swo -*.bak -*.orig -*.pdb -*.idb -.svn -.DS_Store -.xmake -*.gch -*.gch.d -gmon.out -build +# xmake temp files +.xmake/ +# build result files +build/ + diff --git a/xmake/templates/go/static_library/project/.gitignore b/xmake/templates/go/static_library/project/.gitignore index 08ffbbd04..e4ede4aa6 100644 --- a/xmake/templates/go/static_library/project/.gitignore +++ b/xmake/templates/go/static_library/project/.gitignore @@ -1,22 +1,5 @@ -*.a -*.o -*.exe -*.obj -*.dll -*.lib -*.out -*.suo -*~ -*.swp -*.swo -*.bak -*.orig -*.pdb -*.idb -.svn -.DS_Store -.xmake -*.gch -*.gch.d -gmon.out -build +# xmake temp files +.xmake/ +# build result files +build/ + diff --git a/xmake/templates/objc++/console/project/.gitignore b/xmake/templates/objc++/console/project/.gitignore index 08ffbbd04..e4ede4aa6 100644 --- a/xmake/templates/objc++/console/project/.gitignore +++ b/xmake/templates/objc++/console/project/.gitignore @@ -1,22 +1,5 @@ -*.a -*.o -*.exe -*.obj -*.dll -*.lib -*.out -*.suo -*~ -*.swp -*.swo -*.bak -*.orig -*.pdb -*.idb -.svn -.DS_Store -.xmake -*.gch -*.gch.d -gmon.out -build +# xmake temp files +.xmake/ +# build result files +build/ + diff --git a/xmake/templates/objc/console/project/.gitignore b/xmake/templates/objc/console/project/.gitignore index 08ffbbd04..e4ede4aa6 100644 --- a/xmake/templates/objc/console/project/.gitignore +++ b/xmake/templates/objc/console/project/.gitignore @@ -1,22 +1,5 @@ -*.a -*.o -*.exe -*.obj -*.dll -*.lib -*.out -*.suo -*~ -*.swp -*.swo -*.bak -*.orig -*.pdb -*.idb -.svn -.DS_Store -.xmake -*.gch -*.gch.d -gmon.out -build +# xmake temp files +.xmake/ +# build result files +build/ + diff --git a/xmake/templates/rust/console/project/.gitignore b/xmake/templates/rust/console/project/.gitignore index 08ffbbd04..e4ede4aa6 100644 --- a/xmake/templates/rust/console/project/.gitignore +++ b/xmake/templates/rust/console/project/.gitignore @@ -1,22 +1,5 @@ -*.a -*.o -*.exe -*.obj -*.dll -*.lib -*.out -*.suo -*~ -*.swp -*.swo -*.bak -*.orig -*.pdb -*.idb -.svn -.DS_Store -.xmake -*.gch -*.gch.d -gmon.out -build +# xmake temp files +.xmake/ +# build result files +build/ + diff --git a/xmake/templates/rust/static_library/project/.gitignore b/xmake/templates/rust/static_library/project/.gitignore index 08ffbbd04..e4ede4aa6 100644 --- a/xmake/templates/rust/static_library/project/.gitignore +++ b/xmake/templates/rust/static_library/project/.gitignore @@ -1,22 +1,5 @@ -*.a -*.o -*.exe -*.obj -*.dll -*.lib -*.out -*.suo -*~ -*.swp -*.swo -*.bak -*.orig -*.pdb -*.idb -.svn -.DS_Store -.xmake -*.gch -*.gch.d -gmon.out -build +# xmake temp files +.xmake/ +# build result files +build/ + diff --git a/xmake/templates/swift/console/project/.gitignore b/xmake/templates/swift/console/project/.gitignore index 08ffbbd04..e4ede4aa6 100644 --- a/xmake/templates/swift/console/project/.gitignore +++ b/xmake/templates/swift/console/project/.gitignore @@ -1,22 +1,5 @@ -*.a -*.o -*.exe -*.obj -*.dll -*.lib -*.out -*.suo -*~ -*.swp -*.swo -*.bak -*.orig -*.pdb -*.idb -.svn -.DS_Store -.xmake -*.gch -*.gch.d -gmon.out -build +# xmake temp files +.xmake/ +# build result files +build/ + -- cgit v1.3.1 From 9d72f08afa253d83f042c72a35cc5a555c61f44b Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Tue, 11 Jun 2019 13:53:26 +0800 Subject: fix --- xmake/scripts/gitignore | 3 +++ xmake/templates/c++/console/project/.gitignore | 3 +++ xmake/templates/c++/console_qt/project/.gitignore | 3 +++ xmake/templates/c++/console_tbox/project/.gitignore | 3 +++ xmake/templates/c++/shared_library/project/.gitignore | 3 +++ xmake/templates/c++/shared_library_qt/project/.gitignore | 3 +++ xmake/templates/c++/shared_library_tbox/project/.gitignore | 3 +++ xmake/templates/c++/static_library/project/.gitignore | 3 +++ xmake/templates/c++/static_library_qt/project/.gitignore | 3 +++ xmake/templates/c++/static_library_tbox/project/.gitignore | 3 +++ xmake/templates/c/console/project/.gitignore | 3 +++ xmake/templates/c/console_tbox/.gitignore | 3 +++ xmake/templates/c/shared_library/project/.gitignore | 3 +++ xmake/templates/c/shared_library_tbox/project/.gitignore | 3 +++ xmake/templates/c/static_library/project/.gitignore | 3 +++ xmake/templates/c/static_library_tbox/project/.gitignore | 3 +++ xmake/templates/cuda/console/project/.gitignore | 3 +++ xmake/templates/dlang/console/project/.gitignore | 3 +++ xmake/templates/dlang/shared_library/project/.gitignore | 3 +++ xmake/templates/dlang/static_library/project/.gitignore | 3 +++ xmake/templates/go/console/project/.gitignore | 3 +++ xmake/templates/go/static_library/project/.gitignore | 3 +++ xmake/templates/objc++/console/project/.gitignore | 3 +++ xmake/templates/objc/console/project/.gitignore | 3 +++ xmake/templates/rust/console/project/.gitignore | 3 +++ xmake/templates/rust/static_library/project/.gitignore | 3 +++ xmake/templates/swift/console/project/.gitignore | 3 +++ 27 files changed, 81 insertions(+) diff --git a/xmake/scripts/gitignore b/xmake/scripts/gitignore index e4ede4aa6..b849bb8f7 100644 --- a/xmake/scripts/gitignore +++ b/xmake/scripts/gitignore @@ -3,3 +3,6 @@ # build result files build/ +.DS_Store/ + + diff --git a/xmake/templates/c++/console/project/.gitignore b/xmake/templates/c++/console/project/.gitignore index e4ede4aa6..b849bb8f7 100644 --- a/xmake/templates/c++/console/project/.gitignore +++ b/xmake/templates/c++/console/project/.gitignore @@ -3,3 +3,6 @@ # build result files build/ +.DS_Store/ + + diff --git a/xmake/templates/c++/console_qt/project/.gitignore b/xmake/templates/c++/console_qt/project/.gitignore index e4ede4aa6..b849bb8f7 100644 --- a/xmake/templates/c++/console_qt/project/.gitignore +++ b/xmake/templates/c++/console_qt/project/.gitignore @@ -3,3 +3,6 @@ # build result files build/ +.DS_Store/ + + diff --git a/xmake/templates/c++/console_tbox/project/.gitignore b/xmake/templates/c++/console_tbox/project/.gitignore index e4ede4aa6..b849bb8f7 100644 --- a/xmake/templates/c++/console_tbox/project/.gitignore +++ b/xmake/templates/c++/console_tbox/project/.gitignore @@ -3,3 +3,6 @@ # build result files build/ +.DS_Store/ + + diff --git a/xmake/templates/c++/shared_library/project/.gitignore b/xmake/templates/c++/shared_library/project/.gitignore index e4ede4aa6..b849bb8f7 100644 --- a/xmake/templates/c++/shared_library/project/.gitignore +++ b/xmake/templates/c++/shared_library/project/.gitignore @@ -3,3 +3,6 @@ # build result files build/ +.DS_Store/ + + diff --git a/xmake/templates/c++/shared_library_qt/project/.gitignore b/xmake/templates/c++/shared_library_qt/project/.gitignore index e4ede4aa6..b849bb8f7 100644 --- a/xmake/templates/c++/shared_library_qt/project/.gitignore +++ b/xmake/templates/c++/shared_library_qt/project/.gitignore @@ -3,3 +3,6 @@ # build result files build/ +.DS_Store/ + + diff --git a/xmake/templates/c++/shared_library_tbox/project/.gitignore b/xmake/templates/c++/shared_library_tbox/project/.gitignore index e4ede4aa6..b849bb8f7 100644 --- a/xmake/templates/c++/shared_library_tbox/project/.gitignore +++ b/xmake/templates/c++/shared_library_tbox/project/.gitignore @@ -3,3 +3,6 @@ # build result files build/ +.DS_Store/ + + diff --git a/xmake/templates/c++/static_library/project/.gitignore b/xmake/templates/c++/static_library/project/.gitignore index e4ede4aa6..b849bb8f7 100644 --- a/xmake/templates/c++/static_library/project/.gitignore +++ b/xmake/templates/c++/static_library/project/.gitignore @@ -3,3 +3,6 @@ # build result files build/ +.DS_Store/ + + diff --git a/xmake/templates/c++/static_library_qt/project/.gitignore b/xmake/templates/c++/static_library_qt/project/.gitignore index e4ede4aa6..b849bb8f7 100644 --- a/xmake/templates/c++/static_library_qt/project/.gitignore +++ b/xmake/templates/c++/static_library_qt/project/.gitignore @@ -3,3 +3,6 @@ # build result files build/ +.DS_Store/ + + diff --git a/xmake/templates/c++/static_library_tbox/project/.gitignore b/xmake/templates/c++/static_library_tbox/project/.gitignore index e4ede4aa6..b849bb8f7 100644 --- a/xmake/templates/c++/static_library_tbox/project/.gitignore +++ b/xmake/templates/c++/static_library_tbox/project/.gitignore @@ -3,3 +3,6 @@ # build result files build/ +.DS_Store/ + + diff --git a/xmake/templates/c/console/project/.gitignore b/xmake/templates/c/console/project/.gitignore index e4ede4aa6..b849bb8f7 100644 --- a/xmake/templates/c/console/project/.gitignore +++ b/xmake/templates/c/console/project/.gitignore @@ -3,3 +3,6 @@ # build result files build/ +.DS_Store/ + + diff --git a/xmake/templates/c/console_tbox/.gitignore b/xmake/templates/c/console_tbox/.gitignore index e4ede4aa6..b849bb8f7 100644 --- a/xmake/templates/c/console_tbox/.gitignore +++ b/xmake/templates/c/console_tbox/.gitignore @@ -3,3 +3,6 @@ # build result files build/ +.DS_Store/ + + diff --git a/xmake/templates/c/shared_library/project/.gitignore b/xmake/templates/c/shared_library/project/.gitignore index e4ede4aa6..b849bb8f7 100644 --- a/xmake/templates/c/shared_library/project/.gitignore +++ b/xmake/templates/c/shared_library/project/.gitignore @@ -3,3 +3,6 @@ # build result files build/ +.DS_Store/ + + diff --git a/xmake/templates/c/shared_library_tbox/project/.gitignore b/xmake/templates/c/shared_library_tbox/project/.gitignore index e4ede4aa6..b849bb8f7 100644 --- a/xmake/templates/c/shared_library_tbox/project/.gitignore +++ b/xmake/templates/c/shared_library_tbox/project/.gitignore @@ -3,3 +3,6 @@ # build result files build/ +.DS_Store/ + + diff --git a/xmake/templates/c/static_library/project/.gitignore b/xmake/templates/c/static_library/project/.gitignore index e4ede4aa6..b849bb8f7 100644 --- a/xmake/templates/c/static_library/project/.gitignore +++ b/xmake/templates/c/static_library/project/.gitignore @@ -3,3 +3,6 @@ # build result files build/ +.DS_Store/ + + diff --git a/xmake/templates/c/static_library_tbox/project/.gitignore b/xmake/templates/c/static_library_tbox/project/.gitignore index e4ede4aa6..b849bb8f7 100644 --- a/xmake/templates/c/static_library_tbox/project/.gitignore +++ b/xmake/templates/c/static_library_tbox/project/.gitignore @@ -3,3 +3,6 @@ # build result files build/ +.DS_Store/ + + diff --git a/xmake/templates/cuda/console/project/.gitignore b/xmake/templates/cuda/console/project/.gitignore index e4ede4aa6..b849bb8f7 100644 --- a/xmake/templates/cuda/console/project/.gitignore +++ b/xmake/templates/cuda/console/project/.gitignore @@ -3,3 +3,6 @@ # build result files build/ +.DS_Store/ + + diff --git a/xmake/templates/dlang/console/project/.gitignore b/xmake/templates/dlang/console/project/.gitignore index e4ede4aa6..b849bb8f7 100644 --- a/xmake/templates/dlang/console/project/.gitignore +++ b/xmake/templates/dlang/console/project/.gitignore @@ -3,3 +3,6 @@ # build result files build/ +.DS_Store/ + + diff --git a/xmake/templates/dlang/shared_library/project/.gitignore b/xmake/templates/dlang/shared_library/project/.gitignore index e4ede4aa6..b849bb8f7 100644 --- a/xmake/templates/dlang/shared_library/project/.gitignore +++ b/xmake/templates/dlang/shared_library/project/.gitignore @@ -3,3 +3,6 @@ # build result files build/ +.DS_Store/ + + diff --git a/xmake/templates/dlang/static_library/project/.gitignore b/xmake/templates/dlang/static_library/project/.gitignore index e4ede4aa6..b849bb8f7 100644 --- a/xmake/templates/dlang/static_library/project/.gitignore +++ b/xmake/templates/dlang/static_library/project/.gitignore @@ -3,3 +3,6 @@ # build result files build/ +.DS_Store/ + + diff --git a/xmake/templates/go/console/project/.gitignore b/xmake/templates/go/console/project/.gitignore index e4ede4aa6..b849bb8f7 100644 --- a/xmake/templates/go/console/project/.gitignore +++ b/xmake/templates/go/console/project/.gitignore @@ -3,3 +3,6 @@ # build result files build/ +.DS_Store/ + + diff --git a/xmake/templates/go/static_library/project/.gitignore b/xmake/templates/go/static_library/project/.gitignore index e4ede4aa6..b849bb8f7 100644 --- a/xmake/templates/go/static_library/project/.gitignore +++ b/xmake/templates/go/static_library/project/.gitignore @@ -3,3 +3,6 @@ # build result files build/ +.DS_Store/ + + diff --git a/xmake/templates/objc++/console/project/.gitignore b/xmake/templates/objc++/console/project/.gitignore index e4ede4aa6..b849bb8f7 100644 --- a/xmake/templates/objc++/console/project/.gitignore +++ b/xmake/templates/objc++/console/project/.gitignore @@ -3,3 +3,6 @@ # build result files build/ +.DS_Store/ + + diff --git a/xmake/templates/objc/console/project/.gitignore b/xmake/templates/objc/console/project/.gitignore index e4ede4aa6..b849bb8f7 100644 --- a/xmake/templates/objc/console/project/.gitignore +++ b/xmake/templates/objc/console/project/.gitignore @@ -3,3 +3,6 @@ # build result files build/ +.DS_Store/ + + diff --git a/xmake/templates/rust/console/project/.gitignore b/xmake/templates/rust/console/project/.gitignore index e4ede4aa6..b849bb8f7 100644 --- a/xmake/templates/rust/console/project/.gitignore +++ b/xmake/templates/rust/console/project/.gitignore @@ -3,3 +3,6 @@ # build result files build/ +.DS_Store/ + + diff --git a/xmake/templates/rust/static_library/project/.gitignore b/xmake/templates/rust/static_library/project/.gitignore index e4ede4aa6..b849bb8f7 100644 --- a/xmake/templates/rust/static_library/project/.gitignore +++ b/xmake/templates/rust/static_library/project/.gitignore @@ -3,3 +3,6 @@ # build result files build/ +.DS_Store/ + + diff --git a/xmake/templates/swift/console/project/.gitignore b/xmake/templates/swift/console/project/.gitignore index e4ede4aa6..b849bb8f7 100644 --- a/xmake/templates/swift/console/project/.gitignore +++ b/xmake/templates/swift/console/project/.gitignore @@ -3,3 +3,6 @@ # build result files build/ +.DS_Store/ + + -- cgit v1.3.1 From a929651257c7259546ff0bf72179067938a0f0ca Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Tue, 11 Jun 2019 13:55:49 +0800 Subject: fix --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 11fe9ea9d..b376a9207 100644 --- a/.gitignore +++ b/.gitignore @@ -4,12 +4,16 @@ build/ winenv/ xmake-ppa/ .vscode/ + /*.exe /*.zip /xmake/*.exe /xmake/*.zip /scripts/*.exe /scripts/*.zip + install.log +/core/xmake.config.h +/core/.config.mak !/xmake/actions/build/ \ No newline at end of file -- cgit v1.3.1 From c8b6f851b85cd8ac6e1ae4ed7993f6910f25df36 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Tue, 11 Jun 2019 13:56:30 +0800 Subject: fix --- .gitignore | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index b376a9207..f3bc8e161 100644 --- a/.gitignore +++ b/.gitignore @@ -5,12 +5,8 @@ winenv/ xmake-ppa/ .vscode/ -/*.exe -/*.zip -/xmake/*.exe -/xmake/*.zip -/scripts/*.exe -/scripts/*.zip +*.exe +*.zip install.log /core/xmake.config.h -- cgit v1.3.1 From 313992ad86b7e0e0cfb339dadb60f91000c08b92 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Tue, 11 Jun 2019 14:02:33 +0800 Subject: add comments --- .gitignore | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index f3bc8e161..1933f1582 100644 --- a/.gitignore +++ b/.gitignore @@ -1,14 +1,23 @@ .DS_Store/ + +# Xmake cache .xmake/ build/ -winenv/ -xmake-ppa/ + +# for VS Code .vscode/ +# for vim +*.swp +*.swo +/tags + +# Ignore packaging files +winenv/ *.exe *.zip -install.log +# Makefile generation /core/xmake.config.h /core/.config.mak -- cgit v1.3.1 From fddedb324fbff0546c2cbe304fe95c8e254da6fb Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Tue, 11 Jun 2019 14:13:59 +0800 Subject: fix --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 1933f1582..99bc3124f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +# MacOS Cache .DS_Store/ # Xmake cache @@ -10,7 +11,8 @@ build/ # for vim *.swp *.swo -/tags +tags +!tags/ # Ignore packaging files winenv/ -- cgit v1.3.1 From 67987b7da01fe4e2c4b5ae8527008dd854f16c26 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 12 Jun 2019 00:08:06 +0800 Subject: fix gitignore and clean files for devlink --- .gitignore | 5 ++++- xmake/rules/cuda/device_link/xmake.lua | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 99bc3124f..9fab162c8 100644 --- a/.gitignore +++ b/.gitignore @@ -22,5 +22,8 @@ winenv/ # Makefile generation /core/xmake.config.h /core/.config.mak +/core/**/*.o +/core/**/*.b +/core/**/*.a -!/xmake/actions/build/ \ No newline at end of file +!/xmake/actions/build/ diff --git a/xmake/rules/cuda/device_link/xmake.lua b/xmake/rules/cuda/device_link/xmake.lua index 068c8270f..0f390f0d9 100644 --- a/xmake/rules/cuda/device_link/xmake.lua +++ b/xmake/rules/cuda/device_link/xmake.lua @@ -24,6 +24,12 @@ rule("cuda.device_link") -- add rule: cuda environment add_deps("cuda.env") + -- clean files + after_clean(function (target) + os.tryrm(target:objectfile(path.join(".cuda", "devlink", target:basename() .. "_gpucode.cu"))) + os.tryrm(target:dependfile(targetfile)) + end) + -- @see https://devblogs.nvidia.com/separate-compilation-linking-cuda-device-code/ before_link(function (target, opt) -- cgit v1.3.1 From 46a694b347199ab39a6693a04a4bcdee00ade063 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 12 Jun 2019 00:09:20 +0800 Subject: add -fPIC to devlink --- xmake/rules/cuda/device_link/xmake.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/xmake/rules/cuda/device_link/xmake.lua b/xmake/rules/cuda/device_link/xmake.lua index 0f390f0d9..6921253a3 100644 --- a/xmake/rules/cuda/device_link/xmake.lua +++ b/xmake/rules/cuda/device_link/xmake.lua @@ -51,6 +51,12 @@ rule("cuda.device_link") -- init culdflags local culdflags = {"-dlink"} + if targetkind == "shared" then + table.insert(culdflags, "-shared") + if not is_plat("windows") then + table.insert(culdflags, "-Xcompiler -fPIC") + end + end -- get link flags local linkflags = linkinst:linkflags({target = target, configs = {force = {culdflags = culdflags}}}) -- cgit v1.3.1 From 5d6c236deed0d4cb3abea2cf5016c6ad88a33392 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 12 Jun 2019 00:21:07 +0800 Subject: remove -fPIC for devlink --- .gitignore | 2 +- xmake/rules/cuda/device_link/xmake.lua | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 9fab162c8..e85cd38da 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ # MacOS Cache -.DS_Store/ +.DS_Store # Xmake cache .xmake/ diff --git a/xmake/rules/cuda/device_link/xmake.lua b/xmake/rules/cuda/device_link/xmake.lua index 6921253a3..358c42d93 100644 --- a/xmake/rules/cuda/device_link/xmake.lua +++ b/xmake/rules/cuda/device_link/xmake.lua @@ -53,9 +53,6 @@ rule("cuda.device_link") local culdflags = {"-dlink"} if targetkind == "shared" then table.insert(culdflags, "-shared") - if not is_plat("windows") then - table.insert(culdflags, "-Xcompiler -fPIC") - end end -- get link flags -- cgit v1.3.1 From e4043f6851c5de222c27830f42c1134d7397e1cb Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 12 Jun 2019 00:36:36 +0800 Subject: fix cl deps --- xmake/modules/core/tools/cl.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xmake/modules/core/tools/cl.lua b/xmake/modules/core/tools/cl.lua index 3859358d3..4f3545988 100644 --- a/xmake/modules/core/tools/cl.lua +++ b/xmake/modules/core/tools/cl.lua @@ -313,10 +313,10 @@ function _include_deps(self, outdata) -- translate it local results = {} local uniques = {} - for _, line in ipairs(outdata:split("\r\n", {plain = true})) do + for _, line in ipairs(outdata:split("\n", {plain = true})) do -- get includefile - local includefile = _include_note(self, line) + local includefile = _include_note(self, line:trim()) if includefile then -- get the relative -- cgit v1.3.1 From 52f3bbe24e365b28f4bcd1e277d178a2561a1e8b Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 12 Jun 2019 00:38:40 +0800 Subject: generate template gitignore --- xmake/core/project/template.lua | 5 ++++- xmake/scripts/gitignore | 6 +++--- xmake/templates/c++/console/project/.gitignore | 8 -------- xmake/templates/c++/console_qt/project/.gitignore | 8 -------- xmake/templates/c++/console_tbox/project/.gitignore | 8 -------- xmake/templates/c++/shared_library/project/.gitignore | 8 -------- xmake/templates/c++/shared_library_qt/project/.gitignore | 8 -------- xmake/templates/c++/shared_library_tbox/project/.gitignore | 8 -------- xmake/templates/c++/static_library/project/.gitignore | 8 -------- xmake/templates/c++/static_library_qt/project/.gitignore | 8 -------- xmake/templates/c++/static_library_tbox/project/.gitignore | 8 -------- xmake/templates/c/console/project/.gitignore | 8 -------- xmake/templates/c/console_tbox/.gitignore | 8 -------- xmake/templates/c/shared_library/project/.gitignore | 8 -------- xmake/templates/c/shared_library_tbox/project/.gitignore | 8 -------- xmake/templates/c/static_library/project/.gitignore | 8 -------- xmake/templates/c/static_library_tbox/project/.gitignore | 8 -------- xmake/templates/cuda/console/project/.gitignore | 8 -------- xmake/templates/cuda/shared_library/project/.gitignore | 2 -- xmake/templates/cuda/static_library/project/.gitignore | 2 -- xmake/templates/dlang/console/project/.gitignore | 8 -------- xmake/templates/dlang/shared_library/project/.gitignore | 8 -------- xmake/templates/dlang/static_library/project/.gitignore | 8 -------- xmake/templates/go/console/project/.gitignore | 8 -------- xmake/templates/go/static_library/project/.gitignore | 8 -------- xmake/templates/objc++/console/project/.gitignore | 8 -------- xmake/templates/objc/console/project/.gitignore | 8 -------- xmake/templates/rust/console/project/.gitignore | 8 -------- xmake/templates/rust/static_library/project/.gitignore | 8 -------- xmake/templates/swift/console/project/.gitignore | 8 -------- 30 files changed, 7 insertions(+), 216 deletions(-) delete mode 100644 xmake/templates/c++/console/project/.gitignore delete mode 100644 xmake/templates/c++/console_qt/project/.gitignore delete mode 100644 xmake/templates/c++/console_tbox/project/.gitignore delete mode 100644 xmake/templates/c++/shared_library/project/.gitignore delete mode 100644 xmake/templates/c++/shared_library_qt/project/.gitignore delete mode 100644 xmake/templates/c++/shared_library_tbox/project/.gitignore delete mode 100644 xmake/templates/c++/static_library/project/.gitignore delete mode 100644 xmake/templates/c++/static_library_qt/project/.gitignore delete mode 100644 xmake/templates/c++/static_library_tbox/project/.gitignore delete mode 100644 xmake/templates/c/console/project/.gitignore delete mode 100644 xmake/templates/c/console_tbox/.gitignore delete mode 100644 xmake/templates/c/shared_library/project/.gitignore delete mode 100644 xmake/templates/c/shared_library_tbox/project/.gitignore delete mode 100644 xmake/templates/c/static_library/project/.gitignore delete mode 100644 xmake/templates/c/static_library_tbox/project/.gitignore delete mode 100644 xmake/templates/cuda/console/project/.gitignore delete mode 100644 xmake/templates/cuda/shared_library/project/.gitignore delete mode 100644 xmake/templates/cuda/static_library/project/.gitignore delete mode 100644 xmake/templates/dlang/console/project/.gitignore delete mode 100644 xmake/templates/dlang/shared_library/project/.gitignore delete mode 100644 xmake/templates/dlang/static_library/project/.gitignore delete mode 100644 xmake/templates/go/console/project/.gitignore delete mode 100644 xmake/templates/go/static_library/project/.gitignore delete mode 100644 xmake/templates/objc++/console/project/.gitignore delete mode 100644 xmake/templates/objc/console/project/.gitignore delete mode 100644 xmake/templates/rust/console/project/.gitignore delete mode 100644 xmake/templates/rust/static_library/project/.gitignore delete mode 100644 xmake/templates/swift/console/project/.gitignore diff --git a/xmake/core/project/template.lua b/xmake/core/project/template.lua index 8f6e959f1..27dc34e42 100644 --- a/xmake/core/project/template.lua +++ b/xmake/core/project/template.lua @@ -280,7 +280,7 @@ function template.create(language, templateid, targetname) -- append FAQ to xmake.lua local projectfile = path.join(projectdir, "xmake.lua") if os.isfile(projectfile) then - local file = io.open("xmake.lua", "a+") + local file = io.open(projectfile, "a+") if file then file:print("") file:print(template.faq()) @@ -288,6 +288,9 @@ function template.create(language, templateid, targetname) end end + -- generate .gitignore + os.cp(path.join(os.programdir(), "scripts", "gitignore"), path.join(projectdir, ".gitignore")) + -- ok return true end diff --git a/xmake/scripts/gitignore b/xmake/scripts/gitignore index b849bb8f7..152105761 100644 --- a/xmake/scripts/gitignore +++ b/xmake/scripts/gitignore @@ -1,8 +1,8 @@ -# xmake temp files +# Xmake cache .xmake/ -# build result files build/ -.DS_Store/ +# MacOS Cache +.DS_Store diff --git a/xmake/templates/c++/console/project/.gitignore b/xmake/templates/c++/console/project/.gitignore deleted file mode 100644 index b849bb8f7..000000000 --- a/xmake/templates/c++/console/project/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# xmake temp files -.xmake/ -# build result files -build/ - -.DS_Store/ - - diff --git a/xmake/templates/c++/console_qt/project/.gitignore b/xmake/templates/c++/console_qt/project/.gitignore deleted file mode 100644 index b849bb8f7..000000000 --- a/xmake/templates/c++/console_qt/project/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# xmake temp files -.xmake/ -# build result files -build/ - -.DS_Store/ - - diff --git a/xmake/templates/c++/console_tbox/project/.gitignore b/xmake/templates/c++/console_tbox/project/.gitignore deleted file mode 100644 index b849bb8f7..000000000 --- a/xmake/templates/c++/console_tbox/project/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# xmake temp files -.xmake/ -# build result files -build/ - -.DS_Store/ - - diff --git a/xmake/templates/c++/shared_library/project/.gitignore b/xmake/templates/c++/shared_library/project/.gitignore deleted file mode 100644 index b849bb8f7..000000000 --- a/xmake/templates/c++/shared_library/project/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# xmake temp files -.xmake/ -# build result files -build/ - -.DS_Store/ - - diff --git a/xmake/templates/c++/shared_library_qt/project/.gitignore b/xmake/templates/c++/shared_library_qt/project/.gitignore deleted file mode 100644 index b849bb8f7..000000000 --- a/xmake/templates/c++/shared_library_qt/project/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# xmake temp files -.xmake/ -# build result files -build/ - -.DS_Store/ - - diff --git a/xmake/templates/c++/shared_library_tbox/project/.gitignore b/xmake/templates/c++/shared_library_tbox/project/.gitignore deleted file mode 100644 index b849bb8f7..000000000 --- a/xmake/templates/c++/shared_library_tbox/project/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# xmake temp files -.xmake/ -# build result files -build/ - -.DS_Store/ - - diff --git a/xmake/templates/c++/static_library/project/.gitignore b/xmake/templates/c++/static_library/project/.gitignore deleted file mode 100644 index b849bb8f7..000000000 --- a/xmake/templates/c++/static_library/project/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# xmake temp files -.xmake/ -# build result files -build/ - -.DS_Store/ - - diff --git a/xmake/templates/c++/static_library_qt/project/.gitignore b/xmake/templates/c++/static_library_qt/project/.gitignore deleted file mode 100644 index b849bb8f7..000000000 --- a/xmake/templates/c++/static_library_qt/project/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# xmake temp files -.xmake/ -# build result files -build/ - -.DS_Store/ - - diff --git a/xmake/templates/c++/static_library_tbox/project/.gitignore b/xmake/templates/c++/static_library_tbox/project/.gitignore deleted file mode 100644 index b849bb8f7..000000000 --- a/xmake/templates/c++/static_library_tbox/project/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# xmake temp files -.xmake/ -# build result files -build/ - -.DS_Store/ - - diff --git a/xmake/templates/c/console/project/.gitignore b/xmake/templates/c/console/project/.gitignore deleted file mode 100644 index b849bb8f7..000000000 --- a/xmake/templates/c/console/project/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# xmake temp files -.xmake/ -# build result files -build/ - -.DS_Store/ - - diff --git a/xmake/templates/c/console_tbox/.gitignore b/xmake/templates/c/console_tbox/.gitignore deleted file mode 100644 index b849bb8f7..000000000 --- a/xmake/templates/c/console_tbox/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# xmake temp files -.xmake/ -# build result files -build/ - -.DS_Store/ - - diff --git a/xmake/templates/c/shared_library/project/.gitignore b/xmake/templates/c/shared_library/project/.gitignore deleted file mode 100644 index b849bb8f7..000000000 --- a/xmake/templates/c/shared_library/project/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# xmake temp files -.xmake/ -# build result files -build/ - -.DS_Store/ - - diff --git a/xmake/templates/c/shared_library_tbox/project/.gitignore b/xmake/templates/c/shared_library_tbox/project/.gitignore deleted file mode 100644 index b849bb8f7..000000000 --- a/xmake/templates/c/shared_library_tbox/project/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# xmake temp files -.xmake/ -# build result files -build/ - -.DS_Store/ - - diff --git a/xmake/templates/c/static_library/project/.gitignore b/xmake/templates/c/static_library/project/.gitignore deleted file mode 100644 index b849bb8f7..000000000 --- a/xmake/templates/c/static_library/project/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# xmake temp files -.xmake/ -# build result files -build/ - -.DS_Store/ - - diff --git a/xmake/templates/c/static_library_tbox/project/.gitignore b/xmake/templates/c/static_library_tbox/project/.gitignore deleted file mode 100644 index b849bb8f7..000000000 --- a/xmake/templates/c/static_library_tbox/project/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# xmake temp files -.xmake/ -# build result files -build/ - -.DS_Store/ - - diff --git a/xmake/templates/cuda/console/project/.gitignore b/xmake/templates/cuda/console/project/.gitignore deleted file mode 100644 index b849bb8f7..000000000 --- a/xmake/templates/cuda/console/project/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# xmake temp files -.xmake/ -# build result files -build/ - -.DS_Store/ - - diff --git a/xmake/templates/cuda/shared_library/project/.gitignore b/xmake/templates/cuda/shared_library/project/.gitignore deleted file mode 100644 index 173fb6eaf..000000000 --- a/xmake/templates/cuda/shared_library/project/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -.xmake -build diff --git a/xmake/templates/cuda/static_library/project/.gitignore b/xmake/templates/cuda/static_library/project/.gitignore deleted file mode 100644 index 173fb6eaf..000000000 --- a/xmake/templates/cuda/static_library/project/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -.xmake -build diff --git a/xmake/templates/dlang/console/project/.gitignore b/xmake/templates/dlang/console/project/.gitignore deleted file mode 100644 index b849bb8f7..000000000 --- a/xmake/templates/dlang/console/project/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# xmake temp files -.xmake/ -# build result files -build/ - -.DS_Store/ - - diff --git a/xmake/templates/dlang/shared_library/project/.gitignore b/xmake/templates/dlang/shared_library/project/.gitignore deleted file mode 100644 index b849bb8f7..000000000 --- a/xmake/templates/dlang/shared_library/project/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# xmake temp files -.xmake/ -# build result files -build/ - -.DS_Store/ - - diff --git a/xmake/templates/dlang/static_library/project/.gitignore b/xmake/templates/dlang/static_library/project/.gitignore deleted file mode 100644 index b849bb8f7..000000000 --- a/xmake/templates/dlang/static_library/project/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# xmake temp files -.xmake/ -# build result files -build/ - -.DS_Store/ - - diff --git a/xmake/templates/go/console/project/.gitignore b/xmake/templates/go/console/project/.gitignore deleted file mode 100644 index b849bb8f7..000000000 --- a/xmake/templates/go/console/project/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# xmake temp files -.xmake/ -# build result files -build/ - -.DS_Store/ - - diff --git a/xmake/templates/go/static_library/project/.gitignore b/xmake/templates/go/static_library/project/.gitignore deleted file mode 100644 index b849bb8f7..000000000 --- a/xmake/templates/go/static_library/project/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# xmake temp files -.xmake/ -# build result files -build/ - -.DS_Store/ - - diff --git a/xmake/templates/objc++/console/project/.gitignore b/xmake/templates/objc++/console/project/.gitignore deleted file mode 100644 index b849bb8f7..000000000 --- a/xmake/templates/objc++/console/project/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# xmake temp files -.xmake/ -# build result files -build/ - -.DS_Store/ - - diff --git a/xmake/templates/objc/console/project/.gitignore b/xmake/templates/objc/console/project/.gitignore deleted file mode 100644 index b849bb8f7..000000000 --- a/xmake/templates/objc/console/project/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# xmake temp files -.xmake/ -# build result files -build/ - -.DS_Store/ - - diff --git a/xmake/templates/rust/console/project/.gitignore b/xmake/templates/rust/console/project/.gitignore deleted file mode 100644 index b849bb8f7..000000000 --- a/xmake/templates/rust/console/project/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# xmake temp files -.xmake/ -# build result files -build/ - -.DS_Store/ - - diff --git a/xmake/templates/rust/static_library/project/.gitignore b/xmake/templates/rust/static_library/project/.gitignore deleted file mode 100644 index b849bb8f7..000000000 --- a/xmake/templates/rust/static_library/project/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# xmake temp files -.xmake/ -# build result files -build/ - -.DS_Store/ - - diff --git a/xmake/templates/swift/console/project/.gitignore b/xmake/templates/swift/console/project/.gitignore deleted file mode 100644 index b849bb8f7..000000000 --- a/xmake/templates/swift/console/project/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# xmake temp files -.xmake/ -# build result files -build/ - -.DS_Store/ - - -- cgit v1.3.1