Skip to content

Commit

Permalink
implement NVTXT
Browse files Browse the repository at this point in the history
  • Loading branch information
vchuravy committed Mar 11, 2020
1 parent f81d8e1 commit 97567a3
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/extras/extras.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ include("loopinfo.jl")
using .LoopInfo
export @unroll

include("timeline.jl")
using .Timeline

end # module
97 changes: 97 additions & 0 deletions src/extras/timeline.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
module Timeline

module NVTXT
const LOG_FILE=Ref{IOStream}()
const SHOULD_LOG=Ref{Bool}(false)

function __init__()
if haskey(ENV, "KERNELABSTRACTIONS_TIMELINE")
SHOULD_LOG[] = true
else
SHOULD_LOG[] = false
return
end
pid = Libc.getpid()
LOG_FILE[] = open("ka-$pid.nvtxt", "w")
initialize()
atexit() do
close(LOG_FILE[])
end
end

function initialize()
SHOULD_LOG[] || return
io = LOG_FILE[]
pid = Libc.getpid()
print(io, """
SetFileDisplayName, KernelAbstractions
@RangeStartEnd, Start, End, ThreadId, Message
ProcessId = $pid
CategoryId = 1
Color = Blue
TimeBase = ClockMonotonicRaw
@RangePush, Time, ThreadId, Message
ProcessId = $pid
CategoryId = 1
Color = Blue
TimeBase = ClockMonotonicRaw
@RangePop, Time, ThreadId
ProcessId = $pid
TimeBase = ClockMonotonicRaw
@Marker, Time, ThreadId, Message
ProcessId = $pid
CategoryId = 1
Color = Blue
TimeBase = ClockMonotonicRaw
""")
end

function push_range(msg)
SHOULD_LOG[] || return
time = time_ns()
io = LOG_FILE[]
print(io, "RangePush, ")
print(io, time)
println(io, ", ", Base.Threads.threadid(), ", \"", msg, "\"")
end

function pop_range()
SHOULD_LOG[] || return
time = time_ns()
io = LOG_FILE[]
print(io, "RangePop, ")
print(io, time)
println(io, ", ", Base.Threads.threadid())
end

struct Range
start::UInt64
msg::String
end

start_range(msg::String) = Range(time_ns(), msg)
function end_range(r::Range)
SHOULD_LOG[] || return
time = time_ns()
io = LOG_FILE[]
print(io, "RangeStartEnd, ")
show(io, r.start)
print(io, ", ")
show(io, time)
println(io, ", ", Base.Threads.threadid(), ", \"", r.msg, "\"")
end

function mark(msg::String)
SHOULD_LOG[] || return
time = time_ns()
io = LOG_FILE[]
print(io, "Marker, ")
show(io, time)
println(io, ", ", Base.Threads.threadid(), ", \"", msg, "\"")
end
end # NVTXT

function range_push end
function mark end

end

0 comments on commit 97567a3

Please sign in to comment.