Skip to content

Commit 9852b76

Browse files
committed
implement NVTXT
1 parent 8a95e72 commit 9852b76

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed

src/extras/extras.jl

+3
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ include("loopinfo.jl")
44
using .LoopInfo
55
export @unroll
66

7+
include("timeline.jl")
8+
using .Timeline
9+
710
end # module

src/extras/timeline.jl

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
module Timeline
2+
3+
module NVTXT
4+
const LOG_FILE=Ref{IOStream}()
5+
const SHOULD_LOG=Ref{Bool}(false)
6+
7+
function __init__()
8+
if haskey(ENV, "KERNELABSTRACTIONS_TIMELINE")
9+
SHOULD_LOG[] = true
10+
else
11+
SHOULD_LOG[] = false
12+
return
13+
end
14+
pid = Libc.getpid()
15+
LOG_FILE[] = open("ka-$pid.nvtxt", "w")
16+
initialize()
17+
atexit() do
18+
close(LOG_FILE[])
19+
end
20+
end
21+
22+
function initialize()
23+
SHOULD_LOG[] || return
24+
io = LOG_FILE[]
25+
pid = Libc.getpid()
26+
print(io, """
27+
SetFileDisplayName, KernelAbstractions
28+
@RangeStartEnd, Start, End, ThreadId, Message
29+
ProcessId = $pid
30+
CategoryId = 1
31+
Color = Blue
32+
TimeBase = ClockMonotonicRaw
33+
@RangePush, Time, ThreadId, Message
34+
ProcessId = $pid
35+
CategoryId = 1
36+
Color = Blue
37+
TimeBase = ClockMonotonicRaw
38+
@RangePop, Time, ThreadId
39+
ProcessId = $pid
40+
TimeBase = ClockMonotonicRaw
41+
@Marker, Time, ThreadId, Message
42+
ProcessId = $pid
43+
CategoryId = 1
44+
Color = Blue
45+
TimeBase = ClockMonotonicRaw
46+
""")
47+
end
48+
49+
function push_range(msg)
50+
SHOULD_LOG[] || return
51+
time = time_ns()
52+
io = LOG_FILE[]
53+
print(io, "RangePush, ")
54+
print(io, time)
55+
println(io, ", ", Base.Threads.threadid(), ", \"", msg, "\"")
56+
end
57+
58+
function pop_range()
59+
SHOULD_LOG[] || return
60+
time = time_ns()
61+
io = LOG_FILE[]
62+
print(io, "RangePop, ")
63+
print(io, time)
64+
println(io, ", ", Base.Threads.threadid())
65+
end
66+
67+
struct Range
68+
start::UInt64
69+
msg::String
70+
end
71+
72+
start_range(msg::String) = Range(time_ns(), msg)
73+
function end_range(r::Range)
74+
SHOULD_LOG[] || return
75+
time = time_ns()
76+
io = LOG_FILE[]
77+
print(io, "RangeStartEnd, ")
78+
show(io, r.start)
79+
print(io, ", ")
80+
show(io, time)
81+
println(io, ", ", Base.Threads.threadid(), ", \"", r.msg, "\"")
82+
end
83+
84+
function mark(msg::String)
85+
SHOULD_LOG[] || return
86+
time = time_ns()
87+
io = LOG_FILE[]
88+
print(io, "Marker, ")
89+
show(io, time)
90+
println(io, ", ", Base.Threads.threadid(), ", \"", msg, "\"")
91+
end
92+
end # NVTXT
93+
94+
function range_push end
95+
function mark end
96+
97+
end

0 commit comments

Comments
 (0)