mirror of
https://github.com/epasveer/seer.git
synced 2026-08-29 16:40:42 +08:00
Cuda test program.
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
|
||||
Andrew Gontarek <notifications@github.com>
|
||||
Unsubscribe
|
||||
To:
|
||||
NVIDIA/cuda-gdb
|
||||
Cc:
|
||||
Ernie Pasveer
|
||||
,
|
||||
Author
|
||||
|
||||
Mon, Sep 18 at 11:18 AM
|
||||
|
||||
We have defined the following mi commands in the current cuda-gdb release:
|
||||
|
||||
add_mi_cmd_mi ("cuda-info-devices", mi_cmd_cuda_info_devices);
|
||||
add_mi_cmd_mi ("cuda-info-sms", mi_cmd_cuda_info_sms);
|
||||
add_mi_cmd_mi ("cuda-info-warps", mi_cmd_cuda_info_warps);
|
||||
add_mi_cmd_mi ("cuda-info-lanes", mi_cmd_cuda_info_lanes);
|
||||
add_mi_cmd_mi ("cuda-info-kernels", mi_cmd_cuda_info_kernels);
|
||||
add_mi_cmd_mi ("cuda-info-blocks", mi_cmd_cuda_info_blocks);
|
||||
add_mi_cmd_mi ("cuda-info-threads", mi_cmd_cuda_info_threads);
|
||||
add_mi_cmd_mi ("cuda-info-launch-trace", mi_cmd_cuda_info_launch_trace);
|
||||
add_mi_cmd_mi ("cuda-info-contexts", mi_cmd_cuda_info_contexts);
|
||||
add_mi_cmd_mi ("cuda-focus-query", mi_cmd_cuda_focus_query);
|
||||
add_mi_cmd_mi ("cuda-focus-switch", mi_cmd_cuda_focus_switch);
|
||||
These however just work as entry points to the associated command without needing to pass it in as a console command.
|
||||
|
||||
We plan on adding more robust GDB/MI support for both the cuda and info cuda commands in a future release.
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
hellopythonmi
|
||||
@@ -0,0 +1,13 @@
|
||||
|
||||
class HelloWorld (gdb.Command):
|
||||
|
||||
"""Greet the whole world."""
|
||||
|
||||
def __init__ (self):
|
||||
super (HelloWorld, self).__init__ ("hello-world", gdb.COMMAND_USER)
|
||||
|
||||
def invoke (self, arg, from_tty):
|
||||
print ("Hello, World!")
|
||||
|
||||
HelloWorld ()
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
|
||||
class MIEcho(gdb.MICommand):
|
||||
"""Echo arguments passed to the command."""
|
||||
|
||||
def __init__(self, name, mode):
|
||||
self._mode = mode
|
||||
super(MIEcho, self).__init__(name)
|
||||
|
||||
def invoke(self, argv):
|
||||
if self._mode == 'dict':
|
||||
return { 'dict': { 'argv' : argv } }
|
||||
elif self._mode == 'list':
|
||||
return { 'list': argv }
|
||||
else:
|
||||
return { 'string': ", ".join(argv) }
|
||||
|
||||
|
||||
MIEcho("-echo-dict", "dict")
|
||||
MIEcho("-echo-list", "list")
|
||||
MIEcho("-echo-string", "string")
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
.PHONY: all
|
||||
all: hellopythonmi
|
||||
|
||||
hellopythonmi: hellopythonmi.cpp
|
||||
g++ -g -o hellopythonmi hellopythonmi.cpp
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -f hellopythonmi hellopythonmi.o
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
|
||||
Online doc for writing mi commands in python.
|
||||
|
||||
https://sourceware.org/gdb/current/onlinedocs/gdb.html/GDB_002fMI-Commands-In-Python.html#GDB_002fMI-Commands-In-Python
|
||||
|
||||
The following code snippet shows how some trivial MI commands can be implemented in Python:
|
||||
|
||||
class MIEcho(gdb.MICommand):
|
||||
"""Echo arguments passed to the command."""
|
||||
|
||||
def __init__(self, name, mode):
|
||||
self._mode = mode
|
||||
super(MIEcho, self).__init__(name)
|
||||
|
||||
def invoke(self, argv):
|
||||
if self._mode == 'dict':
|
||||
return { 'dict': { 'argv' : argv } }
|
||||
elif self._mode == 'list':
|
||||
return { 'list': argv }
|
||||
else:
|
||||
return { 'string': ", ".join(argv) }
|
||||
|
||||
|
||||
MIEcho("-echo-dict", "dict")
|
||||
MIEcho("-echo-list", "list")
|
||||
MIEcho("-echo-string", "string")
|
||||
|
||||
The last three lines instantiate the class three times, creating three new GDB/MI commands -echo-dict, -echo-list, and -echo-string. Each time a subclass of gdb.MICommand is instantiated, the new command is automatically registered with GDB.
|
||||
|
||||
Source the py file at the gdb prompt.
|
||||
|
||||
(gdb) source MIEcho.py
|
||||
|
||||
Depending on how the Python code is read into GDB, you may need to import the gdb module explicitly.
|
||||
|
||||
The following example shows a GDB session in which the above commands have been added:
|
||||
|
||||
(gdb)
|
||||
-echo-dict abc def ghi
|
||||
^done,dict={argv=["abc","def","ghi"]}
|
||||
(gdb)
|
||||
-echo-list abc def ghi
|
||||
^done,list=["abc","def","ghi"]
|
||||
(gdb)
|
||||
-echo-string abc def ghi
|
||||
^done,string="abc, def, ghi"
|
||||
(gdb)
|
||||
|
||||
|
||||
|
||||
Here's a simple non-MI command added with python to gdb.
|
||||
|
||||
class HelloWorld (gdb.Command):
|
||||
|
||||
"""Greet the whole world."""
|
||||
|
||||
def __init__ (self):
|
||||
super (HelloWorld, self).__init__ ("hello-world", gdb.COMMAND_USER)
|
||||
|
||||
def invoke (self, arg, from_tty):
|
||||
print ("Hello, World!")
|
||||
|
||||
HelloWorld ()
|
||||
|
||||
Put it in a .py file and load it in gdb.
|
||||
|
||||
(gdb) source HelloWorld.py
|
||||
|
||||
Then execute it.
|
||||
|
||||
(gdb) hello-world
|
||||
Hello, World!
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
int main (int argc, char* argv[]) {
|
||||
|
||||
int j = 0;
|
||||
|
||||
for (int i=0; i<argc; i++) {
|
||||
std::cout << "XX: "
|
||||
<< i
|
||||
<< " "
|
||||
<< argv[i]
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
std::string message = "Hello, World!";
|
||||
|
||||
std::cout << std::endl;
|
||||
std::cout << message << std::endl;
|
||||
std::cout << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user