Add bench script

This commit is contained in:
2023-08-22 10:29:59 +02:00
parent a7fb15c95b
commit 45e35dd526
6 changed files with 220 additions and 20 deletions

View File

@ -53,7 +53,6 @@ struct AppliedNodeSplit <: AppliedOperation
diff::Diff
end
mutable struct PossibleOperations
nodeFusions::Set{NodeFusion}
nodeReductions::Set{NodeReduction}
@ -68,7 +67,6 @@ function PossibleOperations()
)
end
# The actual state of the DAG is the initial state given by the set of nodes
# but with all the operations in appliedChain applied in order
mutable struct DAG

View File

@ -3,7 +3,6 @@
using Base.Threads
function insert_operation!(operations::PossibleOperations, nf::NodeFusion, locks::Dict{Node, SpinLock})
push!(operations.nodeFusions, nf)
n1 = nf.input[1]; n2 = nf.input[2]; n3 = nf.input[3]
lock(locks[n1]) do; push!(nf.input[1].operations, nf); end
@ -16,7 +15,7 @@ function insert_operation!(operations::PossibleOperations, nr::NodeReduction, lo
first = true
for n in nr.input
skip_duplicate = false
# careful here, this is a manual lock
# careful here, this is a manual lock (because of the break)
lock(locks[n])
if first
first = false
@ -40,35 +39,57 @@ function insert_operation!(operations::PossibleOperations, nr::NodeReduction, lo
end
function insert_operation!(operations::PossibleOperations, ns::NodeSplit, locks::Dict{Node, SpinLock})
push!(operations.nodeSplits, ns)
lock(locks[ns.input]) do; push!(ns.input.operations, ns); end
return nothing
end
function nr_insertion!(operations::PossibleOperations, nodeReductions::Vector{Vector{NodeReduction}}, locks::Dict{Node, SpinLock})
total_len = 0
for vec in nodeReductions
total_len += length(vec)
end
sizehint!(operations.nodeReductions, total_len)
@time for vec in nodeReductions
for op in vec
insert_operation!(operations, op, locks)
end
end
println(" Time for NR insertion")
return nothing
end
function nf_insertion!(operations::PossibleOperations, nodeFusions::Vector{Vector{NodeFusion}}, locks::Dict{Node, SpinLock})
total_len = 0
for vec in nodeFusions
total_len += length(vec)
end
sizehint!(operations.nodeFusions, total_len)
@time for vec in nodeFusions
union!(operations.nodeFusions, Set(vec))
for op in vec
insert_operation!(operations, op, locks)
end
end
println(" Time for NF insertion")
return nothing
end
function ns_insertion!(operations::PossibleOperations, nodeSplits::Vector{Vector{NodeSplit}}, locks::Dict{Node, SpinLock})
total_len = 0
for vec in nodeSplits
total_len += length(vec)
end
sizehint!(operations.nodeSplits, total_len)
@time for vec in nodeSplits
union!(operations.nodeSplits, Set(vec))
for op in vec
insert_operation!(operations, op, locks)
end
end
println(" Time for NS insertion")
return nothing
end
@ -89,14 +110,12 @@ function generate_options(graph::DAG)
nodeArray = collect(graph.nodes)
# sort all nodes
println("Sorting...")
@time @threads for node in nodeArray
@threads for node in nodeArray
sort_node!(node)
end
# --- find possible node reductions ---
println("Node Reductions...")
@time @threads for node in nodeArray
@threads for node in nodeArray
# we're looking for nodes with multiple parents, those parents can then potentially reduce with one another
if (length(node.parents) <= 1)
continue
@ -129,8 +148,7 @@ function generate_options(graph::DAG)
schedule(nr_task)
# --- find possible node fusions ---
println("Node Fusions...")
@time @threads for node in nodeArray
@threads for node in nodeArray
if (typeof(node) <: DataTaskNode)
if length(node.parents) != 1
# data node can only have a single parent
@ -156,8 +174,7 @@ function generate_options(graph::DAG)
schedule(nf_task)
# find possible node splits
println("Node Splits...")
@time @threads for node in nodeArray
@threads for node in nodeArray
if (can_split(node))
push!(generatedSplits[threadid()], NodeSplit(node))
end
@ -169,12 +186,9 @@ function generate_options(graph::DAG)
empty!(graph.dirtyNodes)
println("Waiting...")
@time begin
wait(nr_task)
wait(nf_task)
wait(ns_task)
end
wait(nr_task)
wait(nf_task)
wait(ns_task)
return nothing
end