Add WIP functions for optimizations
This commit is contained in:
parent
264d5f834b
commit
e258a287d5
@ -49,8 +49,44 @@ is_exit_node(graph::DAG, node::Node) = size(parents(graph, node)) == 0
|
||||
|
||||
function insert_node(graph::DAG, node::Node)
|
||||
push!(graph.nodes, node)
|
||||
return nothing
|
||||
end
|
||||
|
||||
function insert_edge(graph::DAG, edge::Edge)
|
||||
push!(graph.edges, edge)
|
||||
return nothing
|
||||
end
|
||||
|
||||
function remove_node(graph::DAG, node::Node)
|
||||
deleteat!(graph.nodes, findall(x->x==node, graph.nodes))
|
||||
return nothing
|
||||
end
|
||||
|
||||
function remove_edge(graph::DAG, edge::Edge)
|
||||
deleteat!(graph.edges, findall(x->x==edge, graph.edges))
|
||||
return nothing
|
||||
end
|
||||
|
||||
function data(graph::DAG)
|
||||
data_sum::Int32 = 0
|
||||
for node in graph.nodes
|
||||
data_sum = data_sum + data(node.task)
|
||||
end
|
||||
return data_sum
|
||||
end
|
||||
|
||||
function compute_effort(graph::DAG)
|
||||
compute_effort_sum::Int32 = 0
|
||||
for node in graph.nodes
|
||||
compute_effort_sum = compute_effort_sum + compute_effort(node.task)
|
||||
end
|
||||
return compute_effort_sum
|
||||
end
|
||||
|
||||
function compute_intensity(graph::DAG)
|
||||
data_sum = data(graph)
|
||||
if data_sum == 0
|
||||
return typemax(UInt32)
|
||||
end
|
||||
return compute_effort(graph) / data_sum
|
||||
end
|
||||
|
41
src/graph_optimizations.jl
Normal file
41
src/graph_optimizations.jl
Normal file
@ -0,0 +1,41 @@
|
||||
|
||||
function node_fusion(graph::DAG, n1::ComputeTaskNode, n2::DataTaskNode, n3::ComputeTaskNode)
|
||||
if !(n1 in graph) || !(n2 in graph) || !(n3 in graph)
|
||||
error("[Node Fusion] Given nodes are not part of the given graph")
|
||||
end
|
||||
|
||||
required_edge1 = Edge(Tuple{ComputeTaskNode, DataTaskNode}(Ref(n1), Ref(n2)))
|
||||
required_edge2 = Edge(Tuple{DataTaskNode, ComputeTaskNode}(Ref(n2), Ref(n3)))
|
||||
|
||||
if !(required_edge1 in graph) || !(required_edge2 in graph)
|
||||
error("[Node Fusion] Given nodes are not connected by edges which is required for node fusion")
|
||||
end
|
||||
|
||||
# TODO: Perform node fusion
|
||||
end
|
||||
|
||||
function node_reduction(graph::DAG, n1::Node, n2::Node)
|
||||
if !(n1 in graph) || !(n2 in graph)
|
||||
error("[Node Reduction] Given nodes are not part of the given graph")
|
||||
end
|
||||
|
||||
prerequisite_nodes = children(graph, n1)
|
||||
if prerequisite_nodes != children(graph, n2)
|
||||
error("[Node Reduction] Given nodes do not have equal prerequisite nodes which is required for node reduction")
|
||||
end
|
||||
|
||||
# TODO: Perform node reduction
|
||||
end
|
||||
|
||||
function node_split(graph::DAG, n1::Node)
|
||||
if !(n1 in graph)
|
||||
error("[Node Split] Given node is not part of the given graph")
|
||||
end
|
||||
|
||||
subsequent_nodes = parents(graph, n1)
|
||||
if size(subsequent_nodes) <= 1
|
||||
error("[Node Split] Given node does not have multiple parents which is required for node split")
|
||||
end
|
||||
|
||||
# TODO: Perform node split
|
||||
end
|
@ -6,9 +6,11 @@ include("graph.jl")
|
||||
include("task_functions.jl")
|
||||
include("node_functions.jl")
|
||||
include("graph_functions.jl")
|
||||
include("graph_optimizations.jl")
|
||||
|
||||
export ==, in, Node, Edge, ComputeTaskNode, DataTaskNode, DAG
|
||||
export AbstractTask, AbstractComputeTask, AbstractDataTask, DataTask, ComputeTaskP, ComputeTaskS1, ComputeTaskS2, ComputeTaskV, ComputeTaskU
|
||||
export insert_node, insert_edge, is_entry_node, is_exit_node, parents, children
|
||||
export insert_node, insert_edge, is_entry_node, is_exit_node, parents, children, compute, data, compute_effort, compute_intensity
|
||||
export node_fusion, node_reduction, node_split
|
||||
|
||||
end # module metagraph_optimization
|
||||
|
@ -28,7 +28,7 @@ compute_effort(t::ComputeTaskP) = 15
|
||||
# actual compute functions for the tasks can stay undefined for now
|
||||
# compute(t::ComputeTaskU, data::Any) = mycomputation(data)
|
||||
|
||||
function computation_intensity(t::AbstractTask)::UInt32
|
||||
function compute_intensity(t::AbstractTask)::UInt32
|
||||
if data(t) == 0
|
||||
return typemax(UInt32)
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user