Move import to abc_model/ and rename to parse

This commit is contained in:
Anton Reinhard 2023-08-18 10:05:01 +02:00
parent 95da0b1063
commit e591da10d3
7 changed files with 10 additions and 117 deletions

View File

@ -1,108 +0,0 @@
using MetagraphOptimization
import MetagraphOptimization.insert_node!
import MetagraphOptimization.insert_edge!
import MetagraphOptimization.make_node
import MetagraphOptimization.make_edge
function main()
graph = DAG()
# s to output (exit node)
d_exit = insert_node!(graph, make_node(DataTask(10)))
# final s compute
s0 = insert_node!(graph, make_node(ComputeTaskS2()))
# data from v0 and v1 to s0
d_v0_s0 = insert_node!(graph, make_node(DataTask(5)))
d_v1_s0 = insert_node!(graph, make_node(DataTask(5)))
# v0 and v1 compute
v0 = insert_node!(graph, make_node(ComputeTaskV()))
v1 = insert_node!(graph, make_node(ComputeTaskV()))
# data from uB, uA, uBp and uAp to v0 and v1
d_uB_v0 = insert_node!(graph, make_node(DataTask(3)))
d_uA_v0 = insert_node!(graph, make_node(DataTask(3)))
d_uBp_v1 = insert_node!(graph, make_node(DataTask(3)))
d_uAp_v1 = insert_node!(graph, make_node(DataTask(3)))
# uB, uA, uBp and uAp computes
uB = insert_node!(graph, make_node(ComputeTaskU()))
uA = insert_node!(graph, make_node(ComputeTaskU()))
uBp = insert_node!(graph, make_node(ComputeTaskU()))
uAp = insert_node!(graph, make_node(ComputeTaskU()))
# data from PB, PA, PBp and PAp to uB, uA, uBp and uAp
d_PB_uB = insert_node!(graph, make_node(DataTask(6)))
d_PA_uA = insert_node!(graph, make_node(DataTask(6)))
d_PBp_uBp = insert_node!(graph, make_node(DataTask(6)))
d_PAp_uAp = insert_node!(graph, make_node(DataTask(6)))
# P computes PB, PA, PBp and PAp
PB = insert_node!(graph, make_node(ComputeTaskP()))
PA = insert_node!(graph, make_node(ComputeTaskP()))
PBp = insert_node!(graph, make_node(ComputeTaskP()))
PAp = insert_node!(graph, make_node(ComputeTaskP()))
# entry nodes getting data for P computes
d_PB = insert_node!(graph, make_node(DataTask(4)))
d_PA = insert_node!(graph, make_node(DataTask(4)))
d_PBp = insert_node!(graph, make_node(DataTask(4)))
d_PAp = insert_node!(graph, make_node(DataTask(4)))
# now for all the edgese
insert_edge!(graph, make_edge(d_PB, PB))
insert_edge!(graph, make_edge(d_PA, PA))
insert_edge!(graph, make_edge(d_PBp, PBp))
insert_edge!(graph, make_edge(d_PAp, PAp))
insert_edge!(graph, make_edge(PB, d_PB_uB))
insert_edge!(graph, make_edge(PA, d_PA_uA))
insert_edge!(graph, make_edge(PBp, d_PBp_uBp))
insert_edge!(graph, make_edge(PAp, d_PAp_uAp))
insert_edge!(graph, make_edge(d_PB_uB, uB))
insert_edge!(graph, make_edge(d_PA_uA, uA))
insert_edge!(graph, make_edge(d_PBp_uBp, uBp))
insert_edge!(graph, make_edge(d_PAp_uAp, uAp))
insert_edge!(graph, make_edge(uB, d_uB_v0))
insert_edge!(graph, make_edge(uA, d_uA_v0))
insert_edge!(graph, make_edge(uBp, d_uBp_v1))
insert_edge!(graph, make_edge(uAp, d_uAp_v1))
insert_edge!(graph, make_edge(d_uB_v0, v0))
insert_edge!(graph, make_edge(d_uA_v0, v0))
insert_edge!(graph, make_edge(d_uBp_v1, v1))
insert_edge!(graph, make_edge(d_uAp_v1, v1))
insert_edge!(graph, make_edge(v0, d_v0_s0))
insert_edge!(graph, make_edge(v1, d_v1_s0))
insert_edge!(graph, make_edge(d_v0_s0, s0))
insert_edge!(graph, make_edge(d_v1_s0, s0))
insert_edge!(graph, make_edge(s0, d_exit))
print(graph)
println("Available optimizations from here:")
println(generate_options(graph))
# fuse some things
fuse1 = node_fusion!(graph, PB, d_PB_uB, uB)
fuse2 = node_fusion!(graph, PA, d_PA_uA, uA)
fuse3 = node_fusion!(graph, PBp, d_PBp_uBp, uBp)
fuse4 = node_fusion!(graph, PAp, d_PAp_uAp, uAp)
# on this graph, nothing can be reduced
println("Same graph after node fusion")
print(graph)
println("Available optimizations from here:")
println(generate_options(graph))
end
main()

View File

@ -14,12 +14,12 @@ function bench_txt(filepath::String, bench::Bool = true)
end
println(name, ":")
g = import_txt(filepath)
g = parse_abc(filepath)
print(g)
println(" Graph size in memory: ", bytes_to_human_readable(Base.summarysize(g)))
if (bench)
@btime import_txt($filepath)
@btime parse_abc($filepath)
println()
end
end

View File

@ -12,7 +12,7 @@ function gen_plot(filepath)
return
end
g = import_txt(filepath)
g = parse_abc(filepath)
Random.seed!(1)

View File

@ -12,7 +12,7 @@ function gen_plot(filepath)
return
end
g = import_txt(filepath)
g = parse_abc(filepath)
Random.seed!(1)

View File

@ -1,10 +1,10 @@
module MetagraphOptimization
export Node, Edge, ComputeTaskNode, DataTaskNode, DAG
export AbstractTask, AbstractComputeTask, AbstractDataTask, DataTask, ComputeTaskP, ComputeTaskS1, ComputeTaskS2, ComputeTaskV, ComputeTaskU, ComputeTaskSum, FusedComputeTask
export AbstractTask, AbstractComputeTask, AbstractDataTask, DataTask, FusedComputeTask
export make_node, make_edge, insert_node, insert_edge, is_entry_node, is_exit_node, parents, children, compute, graph_properties, get_exit_node, is_valid
export NodeFusion, NodeReduction, NodeSplit, push_operation!, pop_operation!, can_pop, reset_graph!, get_operations
export import_txt
export parse_abc, ComputeTaskP, ComputeTaskS1, ComputeTaskS2, ComputeTaskV, ComputeTaskU, ComputeTaskSum
export ==, in, show, isempty, delete!, length
@ -27,10 +27,10 @@ include("task_functions.jl")
include("node_functions.jl")
include("graph_functions.jl")
include("graph_operations.jl")
include("import.jl")
include("utility.jl")
include("abc_model/tasks.jl")
include("abc_model/task_functions.jl")
include("abc_model/parse.jl")
end # module MetagraphOptimization

View File

@ -20,7 +20,8 @@ function parse_edges(input::AbstractString)
return output
end
function import_txt(filename::String, verbose::Bool = false)
# reads an abc-model process from the given file
function parse_abc(filename::String, verbose::Bool = false)
file = open(filename, "r")
if (verbose) println("Opened file") end

View File

@ -2,7 +2,7 @@ using Random
function test_known_graph(name::String, n, fusion_test=true)
@testset "Test $name Graph ($n)" begin
graph = import_txt(joinpath(@__DIR__, "..", "examples", "$name.txt"))
graph = parse_abc(joinpath(@__DIR__, "..", "examples", "$name.txt"))
props = graph_properties(graph)
if (fusion_test)