Skip to content

Switch to version Dagger 0.18.11 #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 68 additions & 27 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,27 +1,68 @@
# Files generated by invoking Julia with --code-coverage
*.jl.cov
*.jl.*.cov

# Files generated by invoking Julia with --track-allocation
*.jl.mem

# System-specific files and directories generated by the BinaryProvider and BinDeps packages
# They contain absolute paths specific to the host computer, and so should not be committed
deps/deps.jl
deps/build.log
deps/downloads/
deps/usr/
deps/src/

# Build artifacts for creating documentation generated by the Documenter package
docs/build/
docs/site/

# File generated by Pkg, the package manager, based on a corresponding Project.toml
# It records a fixed state of all packages used by the project. As such, it should not be
# committed for packages, but should be committed for applications that require a static
# environment.
Manifest.toml

# IDE files
.vscode
# Files generated by invoking Julia with --code-coverage
*.jl.cov
*.jl.*.cov

# Files generated by invoking Julia with --track-allocation
*.jl.mem

# System-specific files and directories generated by the BinaryProvider and BinDeps packages
# They contain absolute paths specific to the host computer, and so should not be committed
deps/deps.jl
deps/build.log
deps/downloads/
deps/usr/
deps/src/

# Build artifacts for creating documentation generated by the Documenter package
docs/build/
docs/site/

# File generated by Pkg, the package manager, based on a corresponding Project.toml
# It records a fixed state of all packages used by the project. As such, it should not be
# committed for packages, but should be committed for applications that require a static
# environment.
Manifest.toml

# IDE files
.vscode

# Test scripts
# graphs_scheduling/test/test_scripts/

# Data/results/output files

backup

graphs_scheduling/results/logs/out *
graphs_scheduling/results/parsed_graphs/graph1 *
graphs_scheduling/results/parsed_graphs/graph2 *
graphs_scheduling/results/parsed_graphs/graph3 *
graphs_scheduling/results/parsed_graphs/graph4 *
graphs_scheduling/results/parsed_graphs/parsed_graph *
graphs_scheduling/results/parsed_graphs_images/graph1 *
graphs_scheduling/results/parsed_graphs_images/graph2 *
graphs_scheduling/results/parsed_graphs_images/graph3 *
graphs_scheduling/results/parsed_graphs_images/graph4 *
graphs_scheduling/results/parsed_graphs_images/parsed_graph *
graphs_scheduling/results/scheduler_images/DAG *

examples/examples_results/parsed_graphs/graph* *.dot
examples/examples_results/parsed_graphs_images/graph* *.png
examples/examples_results/logs/out *.dot

examples/examples_results/log_sink/viz_oldAPI_multieventlog *
examples/examples_results/log_sink/viz_modernAPI_multieventlog *
examples/examples_results/log_sink/viz_oldAPI_localeventlog *
examples/examples_results/log_sink/viz_modernAPI_localeventlog *

examples/examples_results/enable_logging/viz_enable_logging_modernAPI *
examples/examples_results/enable_logging/viz_enable_logging_oldAPI *
examples/examples_results/enable_logging/viz_raw_enable_logging_oldAPI *

examples/examples_results/render_logs/render_graphviz_complex *
examples/examples_results/render_logs/render_graphviz_simple *


*API_*eventlog *.dot

DAG *.png
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "parsing_graphs/GraphMLReader.jl"]
path = parsing_graphs/GraphMLReader.jl
[submodule "utilities/GraphMLReader.jl"]
path = utilities/GraphMLReader.jl
url = https://github.com/SmalRat/GraphMLReader.jl
402 changes: 201 additions & 201 deletions LICENSE

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[deps]
Cairo = "159f3aea-2a34-519c-b102-8c37f9878175"
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
Dagger = "d58978e5-989f-55fb-8d15-ea34adc7bf54"
DaggerWebDash = "cfc5aa84-1a2a-41ab-b391-ede92ecae40c"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
EzXML = "8f5d6c58-4d21-5cfd-889c-e3ad7ee6a615"
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
GraphViz = "f526b714-d49f-11e8-06ff-31ed36ee7ee0"
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
LightGraphs = "093fc24a-ae57-5d10-9952-331d41423f4d"
MetaGraphs = "626554b9-1ddb-594c-aa3c-2596fe9399a5"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
TimespanLogging = "a526e669-04d3-4846-9525-c66122c55f63"

[compat]
Dagger = "=0.18.11"
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# How to start?

```
git clone <path>
cd key4hep-julia-fwk
git submodule update --init --recursive
julia --project=.
julia> using Pkg
julia> Pkg.instantiate()
julia> include("./graphs_scheduling/src/main.jl")
```
225 changes: 225 additions & 0 deletions dagger_exts/GraphVizExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
module GraphVizExt

if isdefined(Base, :get_extension)
using GraphViz
else
using ..GraphViz
end

import Dagger
import Dagger: DTask, Chunk, Processor
import Dagger.TimespanLogging: Timespan
import Graphs: SimpleDiGraph, add_edge!, add_vertex!, inneighbors, outneighbors, vertices, is_directed, edges, nv, src, dst

function pretty_time(t; digits=3)
r(t) = round(t; digits)
if t > 1000^3
"$(r(t/(1000^3))) s"
elseif t > 1000^2
"$(r(t/(1000^2))) ms"
elseif t > 1000
"$(r(t/1000)) us"
else
"$(r(t)) ns"
end
end

"""
Dagger.render_logs(logs::Dict, ::Val{:graphviz}; disconnected=false,
color_by=:fn, layout_engine="dot",
times::Bool=true, times_digits::Integer=3)

Render a graph of the task dependencies and data dependencies in `logs` using GraphViz.

Requires the following events enabled in `enable_logging!`: `taskdeps`, `tasknames`, `taskargs`, `taskargmoves`

Options:
- `disconnected`: If `true`, render disconnected vertices (tasks or arguments without upstream/downstream dependencies)
- `color_by`: How to color tasks; if `:fn`, then color by unique function name, if `:proc`, then color by unique processor
- `layout_engine`: The layout engine to use for GraphViz
- `times`: If `true`, annotate each task with its start and finish times
- `times_digits`: Number of digits to display in the time annotations
"""
function Dagger.render_logs(logs::Dict, ::Val{:graphviz}; disconnected=false,
color_by=:fn, layout_engine="dot",
times::Bool=true, times_digits::Integer=3)
# Lookup all relevant task/argument dependencies and values in logs
g = SimpleDiGraph()
tid_to_vertex = Dict{Int,Int}()
task_names = String[]
tid_to_proc = Dict{Int,Processor}()
arg_names = Dict{UInt,String}()
task_args = Dict{Int,Vector{Pair{Union{Int,Symbol},UInt}}}()
arg_moves = Dict{Int,Vector{Pair{Union{Int,Symbol},Tuple{UInt,UInt}}}}()
for w in keys(logs)
for idx in 1:length(logs[w][:core])
category = logs[w][:core][idx].category
kind = logs[w][:core][idx].kind
id = logs[w][:id][idx]
if category == :add_thunk && kind == :start
id::NamedTuple
taskdeps = logs[w][:taskdeps][idx]::Pair{Int,Vector{Int}}
taskname = logs[w][:tasknames][idx]::String
tid, deps = taskdeps
add_vertex!(g)
tid_to_vertex[tid] = nv(g)
push!(task_names, taskname)
for dep in deps
add_edge!(g, tid_to_vertex[dep], nv(g))
end
if haskey(logs[w], :taskargs)
id, args = logs[w][:taskargs][idx]::Pair{Int,<:Vector}
append!(get!(Vector{Pair{Union{Int,Symbol},UInt}}, task_args, id), args)
end
elseif category == :compute && kind == :start
id::NamedTuple
tid = id.thunk_id
proc = id.processor
tid_to_proc[tid] = proc
elseif category == :move && kind == :finish
if haskey(logs[w], :taskargmoves)
move_info = logs[w][:taskargmoves][idx]
move_info === nothing && continue
tid, pos, pre_objid, post_objid = move_info
v = get!(Vector{Pair{Union{Int,Symbol},Tuple{UInt,UInt}}}, arg_moves, tid)
push!(v, pos => (pre_objid, post_objid))
end
elseif category == :data_annotation && kind == :start
id::NamedTuple
objid = id.objectid
name = id.name
arg_names[objid] = name
end
end
end
tids_sorted = map(first, sort(collect(tid_to_vertex); by=last))
task_procs = Processor[tid_to_proc[tid] for tid in tids_sorted]

# Find all connected and disconnected vertices
if !disconnected
discon_vs = filter(v->isempty(inneighbors(g, v)) && isempty(outneighbors(g, v)), vertices(g))
con_vs = filter(v->!in(v, discon_vs), vertices(g))
else
con_vs = vertices(g)
end

# Assign colors
labels = task_names
all_fns = unique(map(label->first(split(label, " ")), labels[con_vs]))
all_procs = unique(task_procs)
all_colors = ("red", "orange", "green", "blue", "purple", "pink", "silver")
if color_by == :fn
_colors = [all_colors[mod1(i, length(all_colors))] for i in 1:length(all_fns)]
colors = Dict(v=>_colors[findfirst(fn->occursin(fn, labels[v]), all_fns)] for v in con_vs)
elseif color_by == :proc
_colors = [all_colors[mod1(i, length(all_colors))] for i in 1:length(all_procs)]
colors = Dict(v=>_colors[findfirst(proc->proc==task_procs[v], all_procs)] for v in con_vs)
else
throw(ArgumentError("Unknown `color_by` value: $color_by\nAllowed: :fn, :proc"))
end

str = is_directed(g) ? "digraph mygraph {\n" : "graph mygraph {\n"

# Add raw arguments
for (id, name) in arg_names
str *= "a$id [label=\"$name\", shape=box]\n"
end

if times
vertex_to_tid = Dict{Int,Int}(v=>k for (k,v) in tid_to_vertex)

# Determine per-worker start times
worker_start_times = Dict{Int,UInt64}()
for w in keys(logs)
start = typemax(UInt64)
for idx in 1:length(logs[w][:core])
if logs[w][:core][idx].category == :compute && logs[w][:core][idx].kind == :start
tid = logs[w][:id][idx].thunk_id
haskey(tid_to_vertex, tid) || continue
id = tid_to_vertex[tid]
id in con_vs || continue
start = min(start, logs[w][:core][idx].timestamp)
end
end
worker_start_times[w] = start
end

# Determine per-task start and finish times
start_times = Dict{Int,UInt64}()
finish_times = Dict{Int,UInt64}()
for w in keys(logs)
start = typemax(UInt64)
for idx in 1:length(logs[w][:core])
if logs[w][:core][idx].category == :compute
tid = logs[w][:id][idx].thunk_id
if logs[w][:core][idx].kind == :start
start_times[tid] = logs[w][:core][idx].timestamp - worker_start_times[w]
else
finish_times[tid] = logs[w][:core][idx].timestamp - worker_start_times[w]
end
end
end
end
end

# Add argument moves
for (tid, moves) in arg_moves
for (pos, (pre_objid, post_objid)) in moves
move_str = "a$pre_objid -> a$post_objid [label=\"move\"]\n"
str *= move_str
end
end

# Add tasks
for v in con_vs
if !disconnected && (v in discon_vs)
continue
end
label = labels[v]
color = colors[v]
proc = task_procs[v]
proc_str = '(' * Dagger.short_name(task_procs[v]) * ')'
label_str = "$label\\n$proc_str"
if times
tid = vertex_to_tid[v]
start_time = pretty_time(start_times[tid]; digits=times_digits)
finish_time = pretty_time(finish_times[tid]; digits=times_digits)
label_str *= "\\n[+$start_time -> +$finish_time]"
end
str *= "v$v [label=\"$label_str\", color=\"$color\", penwidth=2.0]\n"
end

# Add task dependencies
edge_sep = is_directed(g) ? "->" : "--"
for edge in edges(g)
# FIXME: Label syncdeps with associated arguments and datadeps directions
str *= "v$(src(edge)) $edge_sep v$(dst(edge)) [label=\"syncdep\"]\n"
end

# Add task arguments
con_args = Vector{UInt}(collect(keys(arg_names)))
for moves in values(arg_moves)
for (_, (pre_objid, post_objid)) in moves
push!(con_args, pre_objid)
push!(con_args, post_objid)
end
end
for (tid, args) in task_args
id = tid_to_vertex[tid]
id in con_vs || continue
for (pos, arg) in args
if !disconnected && !(arg in con_args)
continue
end
arg_str = pos isa Int ? "arg $pos" : "kwarg $pos"
str *= "a$arg $edge_sep v$id [label=\"$arg_str\"]\n"
end
end

str *= "}\n"
gv = GraphViz.Graph(str)
GraphViz.layout!(gv; engine=layout_engine)
return gv
end

end
Loading