Remove unnecessary copies

This commit is contained in:
Anton Reinhard 2023-08-18 10:21:40 +02:00
parent e591da10d3
commit ab38f618c3
3 changed files with 25 additions and 30 deletions

View File

@ -29,7 +29,7 @@ function import_bench()
bench_txt("AB->ABBB.txt")
bench_txt("AB->ABBBBB.txt")
bench_txt("AB->ABBBBBBB.txt")
bench_txt("AB->ABBBBBBBBB.txt", false)
#bench_txt("AB->ABBBBBBBBB.txt", false)
bench_txt("ABAB->ABAB.txt")
bench_txt("ABAB->ABC.txt")
end

View File

@ -60,8 +60,8 @@ end
# siblings = all children of any parents, no duplicates, does not include the node itself
function siblings(node::Node)
result = Set{Node}()
for parent in parents(node)
for sibling in children(parent)
for parent in node.parents
for sibling in parent.children
if (sibling != node)
push!(result, sibling)
end
@ -74,8 +74,8 @@ end
# partners = all parents of any children, no duplicates, does not include the node itself
function partners(node::Node)
result = Set{Node}()
for child in children(node)
for partner in parents(child)
for child in node.children
for partner in child.parents
if (partner != node)
push!(result, partner)
end
@ -85,8 +85,8 @@ function partners(node::Node)
return result
end
is_entry_node(node::Node) = length(children(node)) == 0
is_exit_node(node::Node) = length(parents(node)) == 0
is_entry_node(node::Node) = length(node.children) == 0
is_exit_node(node::Node) = length(node.parents) == 0
# function to invalidate the operation caches for a given operation
function invalidate_caches!(graph::DAG, operation::Operation)

View File

@ -124,20 +124,17 @@ function node_fusion!(graph::DAG, n1::ComputeTaskNode, n2::DataTaskNode, n3::Com
end
# save children and parents
n1_parents = parents(n1)
n1_children = children(n1)
n2_parents = parents(n2)
n2_children = children(n2)
n3_parents = parents(n3)
n3_children = children(n3)
if length(n2_parents) > 1
if length(n2.parents) > 1
error("[Node Fusion] The given data node has more than one parent")
end
if length(n2_children) > 1
if length(n2.children) > 1
error("[Node Fusion] The given data node has more than one child")
end
if length(n1_parents) > 1
if length(n1.parents) > 1
error("[Node Fusion] The given n1 has more than one parent")
end
@ -253,12 +250,12 @@ end
# function to find node fusions involving the given node if it's a data node
# pushes the found fusion everywhere it needs to be and returns nothing
function find_fusions!(graph::DAG, node::DataTaskNode)
if length(parents(node)) != 1 || length(children(node)) != 1
if length(node.parents) != 1 || length(node.children) != 1
return nothing
end
child_node = first(children(node))
parent_node = first(parents(node))
child_node = first(node.children)
parent_node = first(node.parents)
#=if !(child_node in graph) || !(parent_node in graph)
error("Parents/Children that are not in the graph!!!")
@ -283,14 +280,14 @@ function find_fusions!(graph::DAG, node::ComputeTaskNode)
# for loop that always runs once for a scoped block we can break out of
for _ in 1:1
# assume this node as child of the chain
if length(parents(node)) != 1
if length(node.parents) != 1
break
end
node2 = first(parents(node))
if length(parents(node2)) != 1 || length(children(node2)) != 1
node2 = first(node.parents)
if length(node2.parents) != 1 || length(node2.children) != 1
break
end
node3 = first(parents(node2))
node3 = first(node2.parents)
#=if !(node2 in graph) || !(node3 in graph)
error("Parents/Children that are not in the graph!!!")
@ -305,14 +302,14 @@ function find_fusions!(graph::DAG, node::ComputeTaskNode)
for _ in 1:1
# assume this node as parent of the chain
if length(children(node)) < 1
if length(node.children) < 1
break
end
node2 = first(children(node))
if length(parents(node2)) != 1 || length(children(node2)) != 1
node2 = first(node.children)
if length(node2.parents) != 1 || length(node2.children) != 1
break
end
node1 = first(children(node2))
node1 = first(node2.children)
if (length(node1.parents) > 1)
break
end
@ -388,19 +385,17 @@ function generate_options(graph::DAG)
# find possible node fusions
for node in graph.nodes
if (typeof(node) <: DataTaskNode)
node_parents = parents(node)
if length(node_parents) != 1
if length(node.parents) != 1
# data node can only have a single parent
continue
end
parent_node = pop!(node_parents)
parent_node = first(node.parents)
node_children = children(node)
if length(node_children) != 1
if length(node.children) != 1
# this node is an entry node or has multiple children which should not be possible
continue
end
child_node = pop!(node_children)
child_node = first(node.children)
if (length(child_node.parents) != 1)
continue
end