Skip to content

Commit

Permalink
Renaming of member variables
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonReinhard committed Nov 27, 2024
1 parent 68a7945 commit ee213a3
Show file tree
Hide file tree
Showing 22 changed files with 143 additions and 138 deletions.
32 changes: 16 additions & 16 deletions src/estimator/global_metric.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,40 @@ Representation of a [`DAG`](@ref)'s cost as estimated by the [`GlobalMetricEstim
# Fields:
`.data`: The total data transfer.\\
`.computeEffort`: The total compute effort.\\
`.computeIntensity`: The compute intensity, will always equal `.computeEffort / .data`.
`.compute_effort`: The total compute effort.\\
`.compute_intensity`: The compute intensity, will always equal `.compute_effort / .data`.
!!! note
Note that the `computeIntensity` doesn't necessarily make sense in the context of only operation costs.
Note that the `compute_intensity` doesn't necessarily make sense in the context of only operation costs.
It will still work as intended when adding/subtracting to/from a `graph_cost` estimate.
"""
const CDCost = NamedTuple{
(:data, :computeEffort, :computeIntensity),Tuple{Float64,Float64,Float64}
(:data, :compute_effort, :compute_intensity),Tuple{Float64,Float64,Float64}
}

function Base.:+(cost1::CDCost, cost2::CDCost)::CDCost
d = cost1.data + cost2.data
ce = computeEffort = cost1.computeEffort + cost2.computeEffort
return (data=d, computeEffort=ce, computeIntensity=ce / d)::CDCost
ce = compute_effort = cost1.compute_effort + cost2.compute_effort
return (data=d, compute_effort=ce, compute_intensity=ce / d)::CDCost
end

function Base.:-(cost1::CDCost, cost2::CDCost)::CDCost
d = cost1.data - cost2.data
ce = computeEffort = cost1.computeEffort - cost2.computeEffort
return (data=d, computeEffort=ce, computeIntensity=ce / d)::CDCost
ce = compute_effort = cost1.compute_effort - cost2.compute_effort
return (data=d, compute_effort=ce, compute_intensity=ce / d)::CDCost
end

function Base.isless(cost1::CDCost, cost2::CDCost)::Bool
return cost1.data + cost1.computeEffort < cost2.data + cost2.computeEffort
return cost1.data + cost1.compute_effort < cost2.data + cost2.compute_effort
end

function Base.zero(type::Type{CDCost})
return (data=0.0, computeEffort=0.0, computeIntensity=0.0)::CDCost
return (data=0.0, compute_effort=0.0, compute_intensity=0.0)::CDCost
end

function Base.typemax(type::Type{CDCost})
return (data=Inf, computeEffort=Inf, computeIntensity=0.0)::CDCost
return (data=Inf, compute_effort=Inf, compute_intensity=0.0)::CDCost
end

"""
Expand All @@ -56,8 +56,8 @@ function graph_cost(estimator::GlobalMetricEstimator, graph::DAG)
properties = get_properties(graph)
return (
data=properties.data,
computeEffort=properties.computeEffort,
computeIntensity=properties.computeIntensity,
compute_effort=properties.compute_effort,
compute_intensity=properties.compute_intensity,
)::CDCost
end

Expand All @@ -67,8 +67,8 @@ function operation_effect(
s = length(operation.input) - 1
return (
data=s * -data(task(operation.input[1])),
computeEffort=s * -compute_effort(task(operation.input[1])),
computeIntensity=typeof(operation.input) <: DataTaskNode ? 0.0 : Inf,
compute_effort=s * -compute_effort(task(operation.input[1])),
compute_intensity=typeof(operation.input) <: DataTaskNode ? 0.0 : Inf,
)::CDCost
end

Expand All @@ -78,7 +78,7 @@ function operation_effect(
s::Float64 = length(parents(operation.input)) - 1
d::Float64 = s * data(task(operation.input))
ce::Float64 = s * compute_effort(task(operation.input))
return (data=d, computeEffort=ce, computeIntensity=ce / d)::CDCost
return (data=d, compute_effort=ce, compute_intensity=ce / d)::CDCost
end

function String(::GlobalMetricEstimator)
Expand Down
13 changes: 7 additions & 6 deletions src/graph/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ See also: [`DAG`](@ref), [`pop_operation!`](@ref)
"""
function push_operation!(graph::DAG, operation::Operation)
# 1.: Add the operation to the DAG
push!(graph.operationsToApply, operation)
push!(graph.operations_to_apply, operation)

return nothing
end
Expand All @@ -21,10 +21,10 @@ See also: [`DAG`](@ref), [`push_operation!`](@ref)
"""
function pop_operation!(graph::DAG)
# 1.: Remove the operation from the appliedChain of the DAG
if !isempty(graph.operationsToApply)
pop!(graph.operationsToApply)
elseif !isempty(graph.appliedOperations)
appliedOp = pop!(graph.appliedOperations)
if !isempty(graph.operations_to_apply)
pop!(graph.operations_to_apply)
elseif !isempty(graph.applied_operations)
appliedOp = pop!(graph.applied_operations)
revert_operation!(graph, appliedOp)
else
error("No more operations to pop!")
Expand All @@ -38,7 +38,8 @@ end
Return `true` if [`pop_operation!`](@ref) is possible, `false` otherwise.
"""
can_pop(graph::DAG) = !isempty(graph.operationsToApply) || !isempty(graph.appliedOperations)
can_pop(graph::DAG) =
!isempty(graph.operations_to_apply) || !isempty(graph.applied_operations)

"""
reset_graph!(graph::DAG)
Expand Down
16 changes: 8 additions & 8 deletions src/graph/mute.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function _insert_node!(graph::DAG, node::Node; track=true, invalidate_cache=true
if (!invalidate_cache)
return node
end
push!(graph.dirtyNodes, node)
push!(graph.dirty_nodes, node)

return node
end
Expand Down Expand Up @@ -110,8 +110,8 @@ function _insert_edge!(
invalidate_operation_caches!(graph, node1)
invalidate_operation_caches!(graph, node2)

push!(graph.dirtyNodes, node1)
push!(graph.dirtyNodes, node2)
push!(graph.dirty_nodes, node1)
push!(graph.dirty_nodes, node2)

return nothing
end
Expand Down Expand Up @@ -145,7 +145,7 @@ function _remove_node!(graph::DAG, node::Node; track=true, invalidate_cache=true
end

invalidate_operation_caches!(graph, node)
delete!(graph.dirtyNodes, node)
delete!(graph.dirty_nodes, node)

return nothing
end
Expand Down Expand Up @@ -207,10 +207,10 @@ function _remove_edge!(
invalidate_operation_caches!(graph, node1)
invalidate_operation_caches!(graph, node2)
if (node1 in graph)
push!(graph.dirtyNodes, node1)
push!(graph.dirty_nodes, node1)
end
if (node2 in graph)
push!(graph.dirtyNodes, node2)
push!(graph.dirty_nodes, node2)
end

return removed_node_index
Expand All @@ -235,7 +235,7 @@ Invalidate the operation caches for a given [`NodeReduction`](@ref).
This deletes the operation from the graph's possible operations and from the involved nodes' own operation caches.
"""
function invalidate_caches!(graph::DAG, operation::NodeReduction)
delete!(graph.possibleOperations, operation)
delete!(graph.possible_operations, operation)

for node in operation.input
node.nodeReduction = missing
Expand All @@ -252,7 +252,7 @@ Invalidate the operation caches for a given [`NodeSplit`](@ref).
This deletes the operation from the graph's possible operations and from the involved nodes' own operation caches.
"""
function invalidate_caches!(graph::DAG, operation::NodeSplit)
delete!(graph.possibleOperations, operation)
delete!(graph.possible_operations, operation)

# delete the operation from all caches of nodes involved in the operation
# for node split there is only one node
Expand Down
10 changes: 5 additions & 5 deletions src/graph/print.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ function Base.show(io::IO, graph::DAG)
print(io, " Nodes: ")

nodeDict = Dict{Type,Int64}()
noEdges = 0
number_of_edges = 0
for node in graph.nodes
if haskey(nodeDict, typeof(task(node)))
nodeDict[typeof(task(node))] = nodeDict[typeof(task(node))] + 1
else
nodeDict[typeof(task(node))] = 1
end
noEdges += length(parents(node))
number_of_edges += length(parents(node))
end

if length(graph.nodes) <= 20
Expand All @@ -58,9 +58,9 @@ function Base.show(io::IO, graph::DAG)
end
end
println(io)
println(io, " Edges: ", noEdges)
println(io, " Edges: ", number_of_edges)
properties = get_properties(graph)
println(io, " Total Compute Effort: ", properties.computeEffort)
println(io, " Total Compute Effort: ", properties.compute_effort)
println(io, " Total Data Transfer: ", properties.data)
return println(io, " Total Compute Intensity: ", properties.computeIntensity)
return println(io, " Total Compute Intensity: ", properties.compute_intensity)
end
4 changes: 2 additions & 2 deletions src/graph/properties.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function get_properties(graph::DAG)
apply_all!(graph)

# TODO: tests stop working without the if condition, which means there is probably a bug in the lazy evaluation and in the tests
if (graph.properties.computeEffort <= 0.0)
if (graph.properties.compute_effort <= 0.0)
graph.properties = GraphProperties(graph)
end

Expand Down Expand Up @@ -51,5 +51,5 @@ end
Return the number of operations applied to the graph.
"""
function operation_stack_length(graph::DAG)
return length(graph.appliedOperations) + length(graph.operationsToApply)
return length(graph.applied_operations) + length(graph.operations_to_apply)
end
12 changes: 6 additions & 6 deletions src/graph/type.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ A struct storing all possible operations on a [`DAG`](@ref).
To get the [`PossibleOperations`](@ref) on a [`DAG`](@ref), use [`get_operations`](@ref).
"""
mutable struct PossibleOperations
nodeReductions::Set{NodeReduction}
nodeSplits::Set{NodeSplit}
node_reductions::Set{NodeReduction}
node_splits::Set{NodeSplit}
end

"""
Expand All @@ -24,16 +24,16 @@ mutable struct DAG
nodes::Set{Union{DataTaskNode,ComputeTaskNode}}

# The operations currently applied to the set of nodes
appliedOperations::Stack{AppliedOperation}
applied_operations::Stack{AppliedOperation}

# The operations not currently applied but part of the current state of the DAG
operationsToApply::Deque{Operation}
operations_to_apply::Deque{Operation}

# The possible operations at the current state of the DAG
possibleOperations::PossibleOperations
possible_operations::PossibleOperations

# The set of nodes whose possible operations need to be reevaluated
dirtyNodes::Set{Union{DataTaskNode,ComputeTaskNode}}
dirty_nodes::Set{Union{DataTaskNode,ComputeTaskNode}}

# "snapshot" system: keep track of added/removed nodes/edges since last snapshot
# these are muted in insert_node! etc.
Expand Down
8 changes: 4 additions & 4 deletions src/graph/validate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ function is_valid(graph::DAG)
@assert is_valid(graph, node)
end

for op in graph.operationsToApply
for op in graph.operations_to_apply
@assert is_valid(graph, op)
end

for nr in graph.possibleOperations.nodeReductions
for nr in graph.possible_operations.node_reductions
@assert is_valid(graph, nr)
end
for ns in graph.possibleOperations.nodeSplits
for ns in graph.possible_operations.node_splits
@assert is_valid(graph, ns)
end

for node in graph.dirtyNodes
for node in graph.dirty_nodes
@assert node in graph "Dirty Node is not part of the graph!"
@assert ismissing(node.nodeReduction) "Dirty Node has a NodeReduction!"
@assert ismissing(node.nodeSplit) "Dirty Node has a NodeSplit!"
Expand Down
8 changes: 4 additions & 4 deletions src/operation/apply.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
Apply all unapplied operations in the DAG. Is automatically called in all functions that require the latest state of the [`DAG`](@ref).
"""
function apply_all!(graph::DAG)
while !isempty(graph.operationsToApply)
while !isempty(graph.operations_to_apply)
# get next operation to apply from front of the deque
op = popfirst!(graph.operationsToApply)
op = popfirst!(graph.operations_to_apply)

# apply it
appliedOp = apply_operation!(graph, op)

# push to the end of the appliedOperations deque
push!(graph.appliedOperations, appliedOp)
# push to the end of the applied_operations deque
push!(graph.applied_operations, appliedOp)
end
return nothing
end
Expand Down
6 changes: 3 additions & 3 deletions src/operation/clean.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ function find_reductions!(graph::DAG, node::Node)

if reductionVector !== nothing
nr = NodeReduction(reductionVector)
push!(graph.possibleOperations.nodeReductions, nr)
push!(graph.possible_operations.node_reductions, nr)
for node in reductionVector
if !ismissing(node.nodeReduction)
# it can happen that the dirty node becomes part of an existing NodeReduction and overrides those ones now
# this is only a problem insofar the existing NodeReduction has to be deleted and replaced also in the possibleOperations
# this is only a problem insofar the existing NodeReduction has to be deleted and replaced also in the possible_operations
invalidate_caches!(graph, node.nodeReduction)
end
node.nodeReduction = nr
Expand All @@ -56,7 +56,7 @@ function find_splits!(graph::DAG, node::Node)

if (can_split(node))
ns = NodeSplit(node)
push!(graph.possibleOperations.nodeSplits, ns)
push!(graph.possible_operations.node_splits, ns)
node.nodeSplit = ns
end

Expand Down
Loading

0 comments on commit ee213a3

Please sign in to comment.