diff options
| author | ruki <[email protected]> | 2019-06-08 21:38:45 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-06-08 23:05:38 +0800 |
| commit | 0ed447c7d5cf6002d21d1779b2605a982e4e3ec2 (patch) | |
| tree | bb809439b36b09de292a9d8f0407b142a882d15f | |
| parent | 754f2510e5d521097ac15a15f6ec5912bc30358d (diff) | |
impor device-link rule
| -rw-r--r-- | xmake/rules/cuda/device_link/xmake.lua | 76 | ||||
| -rw-r--r-- | xmake/rules/cuda/env/xmake.lua | 31 | ||||
| -rw-r--r-- | xmake/rules/cuda/gencodes/xmake.lua | 3 |
3 files changed, 70 insertions, 40 deletions
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 |
