From 27c4b8ba34eab4b13446cad6628d0ff5e8585036 Mon Sep 17 00:00:00 2001 From: Anton Reinhard Date: Thu, 7 Sep 2023 18:46:41 +0200 Subject: [PATCH] Use real ABC-Model compute effort and data transfer numbers --- src/models/abc/compute.jl | 14 ++++++++- src/models/abc/parse.jl | 60 ++++++++++++++++++++++++++++-------- src/models/abc/particle.jl | 14 +++++++++ src/models/abc/properties.jl | 10 +++--- src/node/create.jl | 2 +- test/unit_tests_graph.jl | 12 ++++---- test/unit_tests_tasks.jl | 10 +++--- 7 files changed, 92 insertions(+), 30 deletions(-) diff --git a/src/models/abc/compute.jl b/src/models/abc/compute.jl index 3fd3250..03fc82a 100644 --- a/src/models/abc/compute.jl +++ b/src/models/abc/compute.jl @@ -3,7 +3,9 @@ using AccurateArithmetic """ compute(::ComputeTaskP, data::ParticleValue) -Return the particle and value as is. 0 FLOP. +Return the particle and value as is. + +0 FLOP. """ function compute(::ComputeTaskP, data::ParticleValue) return data @@ -13,6 +15,8 @@ end compute(::ComputeTaskU, data::ParticleValue) Compute an outer edge. Return the particle value with the same particle and the value multiplied by an outer_edge factor. + +1 FLOP. """ function compute(::ComputeTaskU, data::ParticleValue) return ParticleValue(data.p, data.v * outer_edge(data.p)) @@ -22,6 +26,8 @@ end compute(::ComputeTaskV, data1::ParticleValue, data2::ParticleValue) Compute a vertex. Preserve momentum and particle types (AB->C etc.) to create resulting particle, multiply values together and times a vertex factor. + +6 FLOP. """ function compute(::ComputeTaskV, data1::ParticleValue, data2::ParticleValue) p3 = preserve_momentum(data1.p, data2.p) @@ -35,6 +41,8 @@ end Compute a final inner edge (2 input particles, no output particle). For valid inputs, both input particles should have the same momenta at this point. + +12 FLOP. """ function compute(::ComputeTaskS2, data1::ParticleValue, data2::ParticleValue) return data1.v * inner_edge(data1.p) * data2.v @@ -44,6 +52,8 @@ end compute(::ComputeTaskS1, data::ParticleValue) Compute inner edge (1 input particle, 1 output particle). + +11 FLOP. """ function compute(::ComputeTaskS1, data::ParticleValue) return ParticleValue(data.p, data.v * inner_edge(data.p)) @@ -53,6 +63,8 @@ end compute(::ComputeTaskSum, data::Vector{Float64}) Compute a sum over the vector. Use an algorithm that accounts for accumulated errors in long sums with potentially large differences in magnitude of the summands. + +Linearly many FLOP with growing data. """ function compute(::ComputeTaskSum, data::Vector{Float64}) return sum_kbn(data) diff --git a/src/models/abc/parse.jl b/src/models/abc/parse.jl index 9afc23b..94e62f9 100644 --- a/src/models/abc/parse.jl +++ b/src/models/abc/parse.jl @@ -4,6 +4,9 @@ regex_c = r"^[A-C]\(([^']*),([^']*)\)$" # Regex for the combinations of 2 pa regex_m = r"^M\(([^']*),([^']*),([^']*)\)$" # Regex for the combinations of 3 particles regex_plus = r"^\+$" # Regex for the sum +const PARTICLE_VALUE_SIZE::Int = 48 +const FLOAT_SIZE::Int = 8 + """ parse_nodes(input::AbstractString) @@ -61,7 +64,8 @@ function parse_abc(filename::String, verbose::Bool = false) sizehint!(graph.nodes, estimate_no_nodes) sum_node = insert_node!(graph, make_node(ComputeTaskSum()), false, false) - global_data_out = insert_node!(graph, make_node(DataTask(10)), false, false) + global_data_out = + insert_node!(graph, make_node(DataTask(FLOAT_SIZE)), false, false) insert_edge!(graph, sum_node, global_data_out, false, false) # remember the data out nodes for connection @@ -88,16 +92,26 @@ function parse_abc(filename::String, verbose::Bool = false) # add nodes and edges for the state reading to u(P(Particle)) data_in = insert_node!( graph, - make_node(DataTask(4), string(node)), + make_node(DataTask(PARTICLE_VALUE_SIZE), string(node)), false, false, ) # read particle data node compute_P = insert_node!(graph, make_node(ComputeTaskP()), false, false) # compute P node - data_Pu = insert_node!(graph, make_node(DataTask(6)), false, false) # transfer data from P to u + data_Pu = insert_node!( + graph, + make_node(DataTask(PARTICLE_VALUE_SIZE)), + false, + false, + ) # transfer data from P to u (one ParticleValue object) compute_u = insert_node!(graph, make_node(ComputeTaskU()), false, false) # compute U node - data_out = insert_node!(graph, make_node(DataTask(3)), false, false) # transfer data out from u + data_out = insert_node!( + graph, + make_node(DataTask(PARTICLE_VALUE_SIZE)), + false, + false, + ) # transfer data out from u (one ParticleValue object) insert_edge!(graph, data_in, compute_P, false, false) insert_edge!(graph, compute_P, data_Pu, false, false) @@ -114,7 +128,12 @@ function parse_abc(filename::String, verbose::Bool = false) compute_v = insert_node!(graph, make_node(ComputeTaskV()), false, false) - data_out = insert_node!(graph, make_node(DataTask(5)), false, false) + data_out = insert_node!( + graph, + make_node(DataTask(PARTICLE_VALUE_SIZE)), + false, + false, + ) if (occursin(regex_c, in1)) # put an S node after this input @@ -124,8 +143,12 @@ function parse_abc(filename::String, verbose::Bool = false) false, false, ) - data_S_v = - insert_node!(graph, make_node(DataTask(5)), false, false) + data_S_v = insert_node!( + graph, + make_node(DataTask(PARTICLE_VALUE_SIZE)), + false, + false, + ) insert_edge!(graph, dataOutNodes[in1], compute_S, false, false) insert_edge!(graph, compute_S, data_S_v, false, false) @@ -144,8 +167,12 @@ function parse_abc(filename::String, verbose::Bool = false) false, false, ) - data_S_v = - insert_node!(graph, make_node(DataTask(5)), false, false) + data_S_v = insert_node!( + graph, + make_node(DataTask(PARTICLE_VALUE_SIZE)), + false, + false, + ) insert_edge!(graph, dataOutNodes[in2], compute_S, false, false) insert_edge!(graph, compute_S, data_S_v, false, false) @@ -168,7 +195,12 @@ function parse_abc(filename::String, verbose::Bool = false) # in2 + in3 with a v compute_v = insert_node!(graph, make_node(ComputeTaskV()), false, false) - data_v = insert_node!(graph, make_node(DataTask(5)), false, false) + data_v = insert_node!( + graph, + make_node(DataTask(PARTICLE_VALUE_SIZE)), + false, + false, + ) insert_edge!(graph, dataOutNodes[in2], compute_v, false, false) insert_edge!(graph, dataOutNodes[in3], compute_v, false, false) @@ -177,8 +209,12 @@ function parse_abc(filename::String, verbose::Bool = false) # combine with the v of the combined other input compute_S2 = insert_node!(graph, make_node(ComputeTaskS2()), false, false) - data_out = - insert_node!(graph, make_node(DataTask(10)), false, false) + data_out = insert_node!( + graph, + make_node(DataTask(FLOAT_SIZE)), + false, + false, + ) # output of a S2 task is only a float insert_edge!(graph, data_v, compute_S2, false, false) insert_edge!(graph, dataOutNodes[in1], compute_S2, false, false) diff --git a/src/models/abc/particle.jl b/src/models/abc/particle.jl index 7b125d3..b6807b5 100644 --- a/src/models/abc/particle.jl +++ b/src/models/abc/particle.jl @@ -17,6 +17,8 @@ const PARTICLE_MASSES = Particle A struct describing a particle of the ABC-Model. It has the 4 momentum parts P0...P3 and a [`ParticleType`](@ref). + +`sizeof(Particle())` = 40 Byte """ struct Particle P0::Float64 @@ -31,6 +33,8 @@ end ParticleValue A struct describing a particle during a calculation of a Feynman Diagram, together with the value that's being calculated. + +`sizeof(ParticleValue())` = 48 Byte """ struct ParticleValue p::Particle @@ -64,6 +68,8 @@ end square(p::Particle) Return the square of the particle's momentum as a `Float` value. + +Takes 7 effective FLOP. """ function square(p::Particle) return p.P0 * p.P0 - p.P1 * p.P1 - p.P2 * p.P2 - p.P3 * p.P3 @@ -73,6 +79,8 @@ end inner_edge(p::Particle) Return the factor of the inner edge with the given (virtual) particle. + +Takes 10 effective FLOP. (3 here + 10 in square(p)) """ function inner_edge(p::Particle) return 1.0 / (square(p) - mass(p.type) * mass(p.type)) @@ -82,6 +90,8 @@ end outer_edge(p::Particle) Return the factor of the outer edge with the given (real) particle. + +Takes 0 effective FLOP. """ function outer_edge(p::Particle) return 1.0 @@ -91,6 +101,8 @@ end vertex() Return the factor of a vertex. + +Takes 0 effective FLOP since it's constant. """ function vertex() i = 1.0 @@ -102,6 +114,8 @@ end preserve_momentum(p1::Particle, p2::Particle) Calculate and return a new particle from two given interacting ones at a vertex. + +Takes 4 effective FLOP. """ function preserve_momentum(p1::Particle, p2::Particle) p3 = Particle( diff --git a/src/models/abc/properties.jl b/src/models/abc/properties.jl index 73b6367..8e08e97 100644 --- a/src/models/abc/properties.jl +++ b/src/models/abc/properties.jl @@ -3,35 +3,35 @@ Return the compute effort of an S1 task. """ -compute_effort(t::ComputeTaskS1) = 10 +compute_effort(t::ComputeTaskS1) = 11 """ compute_effort(t::ComputeTaskS2) Return the compute effort of an S2 task. """ -compute_effort(t::ComputeTaskS2) = 10 +compute_effort(t::ComputeTaskS2) = 12 """ compute_effort(t::ComputeTaskU) Return the compute effort of a U task. """ -compute_effort(t::ComputeTaskU) = 6 +compute_effort(t::ComputeTaskU) = 1 """ compute_effort(t::ComputeTaskV) Return the compute effort of a V task. """ -compute_effort(t::ComputeTaskV) = 20 +compute_effort(t::ComputeTaskV) = 6 """ compute_effort(t::ComputeTaskP) Return the compute effort of a P task. """ -compute_effort(t::ComputeTaskP) = 15 +compute_effort(t::ComputeTaskP) = 0 """ compute_effort(t::ComputeTaskSum) diff --git a/src/node/create.jl b/src/node/create.jl index 1335eaa..1d28169 100644 --- a/src/node/create.jl +++ b/src/node/create.jl @@ -37,7 +37,7 @@ copy(n::DataTaskNode) = DataTaskNode( copy(n.nodeReduction), copy(n.nodeSplit), copy(n.nodeFusion), - copy(n.name), + n.name, ) """ diff --git a/test/unit_tests_graph.jl b/test/unit_tests_graph.jl index 77dd84c..9c835e6 100644 --- a/test/unit_tests_graph.jl +++ b/test/unit_tests_graph.jl @@ -143,9 +143,9 @@ import MetagraphOptimization.partners nf = first(operations.nodeFusions) properties = get_properties(graph) - @test properties.computeEffort == 134 + @test properties.computeEffort == 28 @test properties.data == 62 - @test properties.computeIntensity ≈ 134 / 62 + @test properties.computeIntensity ≈ 28 / 62 @test properties.noNodes == 26 @test properties.noEdges == 25 @@ -169,9 +169,9 @@ import MetagraphOptimization.partners @test length(graph.dirtyNodes) != 0 @test properties.noNodes == 24 @test properties.noEdges == 23 - @test properties.computeEffort == 134 + @test properties.computeEffort == 28 @test properties.data < 62 - @test properties.computeIntensity > 134 / 62 + @test properties.computeIntensity > 28 / 62 operations = get_operations(graph) @test length(graph.dirtyNodes) == 0 @@ -208,9 +208,9 @@ import MetagraphOptimization.partners properties = get_properties(graph) @test properties.noNodes == 26 @test properties.noEdges == 25 - @test properties.computeEffort == 134 + @test properties.computeEffort == 28 @test properties.data == 62 - @test properties.computeIntensity ≈ 134 / 62 + @test properties.computeIntensity ≈ 28 / 62 operations = get_operations(graph) @test length(operations) == diff --git a/test/unit_tests_tasks.jl b/test/unit_tests_tasks.jl index c039ece..1bc5bc8 100644 --- a/test/unit_tests_tasks.jl +++ b/test/unit_tests_tasks.jl @@ -10,11 +10,11 @@ Data10 = MetagraphOptimization.DataTask(10) Data20 = MetagraphOptimization.DataTask(20) - @test MetagraphOptimization.compute_effort(S1) == 10 - @test MetagraphOptimization.compute_effort(S2) == 10 - @test MetagraphOptimization.compute_effort(U) == 6 - @test MetagraphOptimization.compute_effort(V) == 20 - @test MetagraphOptimization.compute_effort(P) == 15 + @test MetagraphOptimization.compute_effort(S1) == 11 + @test MetagraphOptimization.compute_effort(S2) == 12 + @test MetagraphOptimization.compute_effort(U) == 1 + @test MetagraphOptimization.compute_effort(V) == 6 + @test MetagraphOptimization.compute_effort(P) == 0 @test MetagraphOptimization.compute_effort(Sum) == 1 @test MetagraphOptimization.compute_effort(Data10) == 0 @test MetagraphOptimization.compute_effort(Data20) == 0