diff options
| author | ruki <[email protected]> | 2019-07-17 15:02:03 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2019-07-17 15:02:03 +0800 |
| commit | 42fd31e85dfbb8f1e916394bb2497fd0ee78f0d4 (patch) | |
| tree | c90f60fa8d998a7542c128a20fb5899b56f418de | |
| parent | e0fbf9ffa3e809bd72afa6182f439db7cd6f4474 (diff) | |
| parent | e7bcde1188f02ac07e64f6b9a798e0b1ca1e049c (diff) | |
Merge pull request #491 from OpportunityLiu/cuda-debug
Cuda debug
| -rw-r--r-- | xmake/modules/detect/tools/find_cudagdb.lua | 39 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/find_cudamemcheck.lua | 39 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/find_nvcc.lua | 38 | ||||
| -rw-r--r-- | xmake/modules/devel/debugger/run.lua | 63 | ||||
| -rw-r--r-- | xmake/modules/private/detect/find_cudatool.lua | 75 | ||||
| -rw-r--r-- | xmake/rules/cuda/env/xmake.lua | 13 |
6 files changed, 227 insertions, 40 deletions
diff --git a/xmake/modules/detect/tools/find_cudagdb.lua b/xmake/modules/detect/tools/find_cudagdb.lua new file mode 100644 index 000000000..15d501ba4 --- /dev/null +++ b/xmake/modules/detect/tools/find_cudagdb.lua @@ -0,0 +1,39 @@ +--!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 find_cudagdb.lua +-- + +-- imports +import("private.detect.find_cudatool") + +-- find cudagdb +-- +-- @param opt the argument options, .e.g {version = true} +-- +-- @return program, version +-- +-- @code +-- +-- local cudagdb = find_cudagdb() +-- local cudagdb, version = find_cudagdb({program = "cuda-gdb", version = true}) +-- +-- @endcode +-- +function main(opt) + return find_cudatool("cuda-gdb", "(%d+%.?%d*%.?%d*.-)%s+release", opt) +end diff --git a/xmake/modules/detect/tools/find_cudamemcheck.lua b/xmake/modules/detect/tools/find_cudamemcheck.lua new file mode 100644 index 000000000..4c7de7469 --- /dev/null +++ b/xmake/modules/detect/tools/find_cudamemcheck.lua @@ -0,0 +1,39 @@ +--!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 find_cudamemcheck.lua +-- + +-- imports +import("private.detect.find_cudatool") + +-- find cudamemcheck +-- +-- @param opt the argument options, .e.g {version = true} +-- +-- @return program, version +-- +-- @code +-- +-- local cudamemcheck = find_cudamemcheck() +-- local cudamemcheck, version = find_cudamemcheck({program = "cuda-memcheck", version = true}) +-- +-- @endcode +-- +function main(opt) + return find_cudatool("cuda-memcheck", "version (%d+%.?%d*%.?%d*.-)", opt) +end diff --git a/xmake/modules/detect/tools/find_nvcc.lua b/xmake/modules/detect/tools/find_nvcc.lua index ce98c9a60..68db9fef5 100644 --- a/xmake/modules/detect/tools/find_nvcc.lua +++ b/xmake/modules/detect/tools/find_nvcc.lua @@ -19,10 +19,7 @@ -- -- imports -import("core.project.config") -import("lib.detect.find_program") -import("lib.detect.find_programver") -import("detect.sdks.find_cuda") +import("private.detect.find_cudatool") -- find nvcc -- @@ -38,36 +35,5 @@ import("detect.sdks.find_cuda") -- @endcode -- function main(opt) - - -- init options - opt = opt or {} - opt.parse = opt.parse or "V(%d+%.?%d*%.?%d*.-)%s" - - -- find program - local program = nil - if opt.program then - program = find_program(opt.program, opt) - end - - -- not found? attempt to find program from cuda toolchains - if not program then - local toolchains = find_cuda() - if toolchains and toolchains.bindir then - program = find_program(path.join(toolchains.bindir, "nvcc"), opt) - end - end - - -- not found? attempt to find program from PATH - if not program then - program = find_program("nvcc", opt) - end - - -- find program version - local version = nil - if program and opt.version then - version = find_programver(program, opt) - end - - -- ok? - return program, version + return find_cudatool("nvcc", "V(%d+%.?%d*%.?%d*.-)%s", opt) end diff --git a/xmake/modules/devel/debugger/run.lua b/xmake/modules/devel/debugger/run.lua index 8f4d0bcec..af87c351a 100644 --- a/xmake/modules/devel/debugger/run.lua +++ b/xmake/modules/devel/debugger/run.lua @@ -21,6 +21,8 @@ -- imports import("core.base.option") import("core.project.config") +import("detect.tools.find_cudagdb") +import("detect.tools.find_cudamemcheck") import("detect.tools.find_gdb") import("detect.tools.find_lldb") import("detect.tools.find_windbg") @@ -49,6 +51,27 @@ function _run_gdb(program, argv) return true end +-- run cuda-gdb +function _run_cudagdb(program, argv) + + -- find cudagdb + local gdb = find_cudagdb({program = config.get("debugger")}) + if not gdb then + return false + end + + -- patch arguments + argv = argv or {} + table.insert(argv, 1, program) + table.insert(argv, 1, "--args") + + -- run it + os.execv(gdb, argv) + + -- ok + return true +end + -- run lldb function _run_lldb(program, argv) @@ -95,6 +118,26 @@ function _run_windbg(program, argv) return true end +-- run cuda-memcheck +function _run_cudamemcheck(program, argv) + + -- find cudamemcheck + local cudamemcheck = find_cudamemcheck({program = config.get("debugger")}) + if not cudamemcheck then + return false + end + + -- patch arguments + argv = argv or {} + table.insert(argv, 1, program) + + -- run it + os.execv(cudamemcheck, argv) + + -- ok + return true +end + -- run x64dbg function _run_x64dbg(program, argv) @@ -172,10 +215,12 @@ end function main(program, argv) -- init debuggers - local debuggers = + local debuggers = { - {"lldb", _run_lldb} - , {"gdb", _run_gdb} + {"lldb" , _run_lldb} + , {"gdb" , _run_gdb} + , {"cudagdb" , _run_cudagdb} + , {"cudamemcheck", _run_cudamemcheck} } -- for windows target or on windows? @@ -190,10 +235,20 @@ function main(program, argv) local debugger = config.get("debugger") if debugger then debugger = debugger:lower() + local debuggername = path.basename(debugger) + -- try exactmatch first + for _, _debugger in ipairs(debuggers) do + if debuggername:startswith(_debugger[1]) then + if _debugger[2](program, argv) then + return + end + end + end + for _, _debugger in ipairs(debuggers) do if debugger:find(_debugger[1]) then if _debugger[2](program, argv) then - return + return end end end diff --git a/xmake/modules/private/detect/find_cudatool.lua b/xmake/modules/private/detect/find_cudatool.lua new file mode 100644 index 000000000..0583e3a6b --- /dev/null +++ b/xmake/modules/private/detect/find_cudatool.lua @@ -0,0 +1,75 @@ +--!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 find_cudatool.lua +-- + +-- imports +import("core.project.config") +import("lib.detect.find_program") +import("lib.detect.find_programver") +import("detect.sdks.find_cuda") + +-- find cuda tool +-- +-- @param toolname name of cuda tool, .e.g "nvcc" +-- parse default pattern for version string +-- opt the argument options, .e.g {version = true} +-- +-- @return program, version +-- +-- @code +-- +-- local nvcc = find_cudatool("nvcc", "V(%d+%.?%d*%.?%d*.-)%s") +-- local nvcc, version = find_cudatool("nvcc", "V(%d+%.?%d*%.?%d*.-)%s", {program = "nvcc", version = true}) +-- +-- @endcode +-- +function main(toolname, parse, opt) + + -- init options + opt = opt or {} + opt.parse = opt.parse or parse + + -- find program + local program = nil + if opt.program then + program = find_program(opt.program, opt) + end + + -- not found? attempt to find program from cuda toolchains + if not program then + local toolchains = find_cuda() + if toolchains and toolchains.bindir then + program = find_program(path.join(toolchains.bindir, toolname), opt) + end + end + + -- not found? attempt to find program from PATH + if not program then + program = find_program(toolname, opt) + end + + -- find program version + local version = nil + if program and opt.version then + version = find_programver(program, opt) + end + + -- ok? + return program, version +end diff --git a/xmake/rules/cuda/env/xmake.lua b/xmake/rules/cuda/env/xmake.lua index d14ebaa75..f69a1bea5 100644 --- a/xmake/rules/cuda/env/xmake.lua +++ b/xmake/rules/cuda/env/xmake.lua @@ -78,3 +78,16 @@ rule("cuda.env") target:add("includedirs", cuda.includedirs) end) + before_run(function (target) + import("core.project.config") + import("lib.detect.find_tool") + + local debugger = config.get("debugger") + if not debugger then + local cudagdb = find_tool("cudagdb") + if cudagdb then + config.set("debugger", cudagdb.program) + end + end + end) + |
