Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tic
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wenyuanbo
tic
Commits
c5a7b743
Commit
c5a7b743
authored
Mar 29, 2019
by
Andrew Tulloch
Committed by
Tianqi Chen
Mar 29, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
TVM debugresult dump to Chrome Tracing (#2922)
parent
608cdeeb
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
68 additions
and
2 deletions
+68
-2
python/tvm/contrib/debugger/debug_result.py
+49
-1
python/tvm/contrib/debugger/debug_runtime.py
+3
-1
tests/python/unittest/test_runtime_graph_debug.py
+16
-0
No files found.
python/tvm/contrib/debugger/debug_result.py
View file @
c5a7b743
"""Graph debug results dumping class."""
import
o
s
import
collection
s
import
json
import
os
import
numpy
as
np
import
tvm
GRAPH_DUMP_FILE_NAME
=
'_tvmdbg_graph_dump.json'
CHROME_TRACE_FILE_NAME
=
"_tvmdbg_execution_trace.json"
ChromeTraceEvent
=
collections
.
namedtuple
(
'ChromeTraceEvent'
,
[
'ts'
,
'tid'
,
'pid'
,
'name'
,
'ph'
]
)
class
DebugResult
(
object
):
"""Graph debug data module.
...
...
@@ -127,6 +136,45 @@ class DebugResult(object):
with
open
(
os
.
path
.
join
(
self
.
_dump_path
,
"output_tensors.params"
),
"wb"
)
as
param_f
:
param_f
.
write
(
save_tensors
(
output_tensors
))
def
dump_chrome_trace
(
self
):
"""Dump the trace to the Chrome trace.json format.
"""
def
s_to_us
(
t
):
return
t
*
10
**
6
starting_times
=
np
.
zeros
(
len
(
self
.
_time_list
)
+
1
)
starting_times
[
1
:]
=
np
.
cumsum
([
times
[
0
]
for
times
in
self
.
_time_list
])
def
node_to_events
(
node
,
times
,
starting_time
):
return
[
ChromeTraceEvent
(
ts
=
s_to_us
(
starting_time
),
tid
=
1
,
pid
=
1
,
ph
=
'B'
,
name
=
node
[
'name'
],
),
ChromeTraceEvent
(
# Use start + duration instead of end to ensure precise timings.
ts
=
s_to_us
(
times
[
0
]
+
starting_time
),
tid
=
1
,
pid
=
1
,
ph
=
'E'
,
name
=
node
[
'name'
],
),
]
events
=
[
e
for
(
node
,
times
,
starting_time
)
in
zip
(
self
.
_nodes_list
,
self
.
_time_list
,
starting_times
)
for
e
in
node_to_events
(
node
,
times
,
starting_time
)]
result
=
dict
(
displayTimeUnit
=
'ns'
,
traceEvents
=
[
e
.
_asdict
()
for
e
in
events
]
)
with
open
(
os
.
path
.
join
(
self
.
_dump_path
,
CHROME_TRACE_FILE_NAME
),
"w"
)
as
trace_f
:
json
.
dump
(
result
,
trace_f
)
def
dump_graph_json
(
self
,
graph
):
"""Dump json formatted graph.
...
...
python/tvm/contrib/debugger/debug_runtime.py
View file @
c5a7b743
...
...
@@ -220,7 +220,9 @@ class GraphModuleDebug(graph_runtime.GraphModule):
self
.
_run_debug
()
# Step 2. Dump the output tensors to the dump folder
self
.
debug_datum
.
dump_output_tensor
()
# Step 3. Display the collected information
# Step 3. Dump the Chrome trace to the dump folder
self
.
debug_datum
.
dump_chrome_trace
()
# Step 4. Display the collected information
self
.
debug_datum
.
display_debug_result
()
def
run_individual
(
self
,
number
,
repeat
=
1
,
min_repeat_ms
=
0
):
...
...
tests/python/unittest/test_runtime_graph_debug.py
View file @
c5a7b743
...
...
@@ -64,6 +64,22 @@ def test_graph_simple():
#Verify the tensors are dumped
assert
(
len
(
os
.
listdir
(
directory
))
>
1
)
CHROME_TRACE_FILE_NAME
=
'_tvmdbg_execution_trace.json'
assert
(
os
.
path
.
exists
(
os
.
path
.
join
(
directory
,
CHROME_TRACE_FILE_NAME
)))
with
open
(
os
.
path
.
join
(
directory
,
CHROME_TRACE_FILE_NAME
))
as
f
:
trace
=
json
.
load
(
f
)
assert
trace
[
"displayTimeUnit"
]
==
"ns"
events
=
trace
[
"traceEvents"
]
assert
len
(
events
)
==
4
assert
all
(
event
[
"ph"
]
in
(
'B'
,
'E'
)
for
event
in
events
)
assert
all
(
event
[
"pid"
]
==
1
for
event
in
events
)
assert
all
(
event
[
"tid"
]
==
1
for
event
in
events
)
assert
all
(
event
[
"name"
]
==
'x'
for
event
in
events
[:
2
])
assert
all
(
event
[
"name"
]
==
'add'
for
event
in
events
[
2
:])
assert
events
[
0
][
"ts"
]
==
0
assert
events
[
0
][
"ph"
]
==
'B'
#verify the output is correct
out
=
mod
.
get_output
(
0
,
tvm
.
nd
.
empty
((
n
,)))
np
.
testing
.
assert_equal
(
out
.
asnumpy
(),
a
+
1
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment