Skip to content

Commit 3b056d7

Browse files
Run Black
1 parent 10eb95e commit 3b056d7

8 files changed

Lines changed: 70 additions & 46 deletions

File tree

accelforge/frontend/arch/components.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,7 @@ class Network(Component, Leaf):
10071007
The routing is currently defined using the mapping, the routing follows the order
10081008
of the spatial nodes from top to bottom.
10091009
"""
1010+
10101011
bits_per_value_scale: EvalsTo[dict] = {"All": 1}
10111012
"""
10121013
A scaling factor for the bits per value of the tensors in this `TensorHolder`. If
@@ -1043,4 +1044,4 @@ def __call__(self, field, value, evaluated, symbol_table):
10431044
)
10441045
return evaluated
10451046

1046-
return super()._eval_expressions(*args, **kwargs, post_calls=(MyPostCall(),))
1047+
return super()._eval_expressions(*args, **kwargs, post_calls=(MyPostCall(),))

accelforge/frontend/arch/structure.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,7 @@ def is_above(self, node_a: str, node_b: str) -> bool:
8484
return any(p.name == node_a for p in parents)
8585

8686
def find_first_of_type_above(
87-
self,
88-
node_type: T,
89-
name: str,
90-
default: D = _FIND_SENTINEL
87+
self, node_type: T, name: str, default: D = _FIND_SENTINEL
9188
) -> T | D:
9289
"""
9390
Returns the first node with type `node_type` above `name`.
@@ -310,6 +307,7 @@ def _flatten(
310307
return_fanout: bool = False,
311308
):
312309
from accelforge.frontend.arch.components import Compute
310+
313311
nodes = []
314312

315313
for node in self.nodes:
@@ -351,10 +349,14 @@ def _parent2child_names(
351349
elif isinstance(node, Compute):
352350
# Compute nodes branch off to the side like a Fork
353351
if current_parent_name is not None:
354-
edges.append((current_parent_name, node._render_node_name(), "dashed"))
352+
edges.append(
353+
(current_parent_name, node._render_node_name(), "dashed")
354+
)
355355
else:
356356
if current_parent_name is not None:
357-
edges.append((current_parent_name, node._render_node_name(), "dashed"))
357+
edges.append(
358+
(current_parent_name, node._render_node_name(), "dashed")
359+
)
358360
return edges, self._render_node_name()
359361

360362
def _render_make_children(self) -> list[pydot.Node]:
@@ -416,9 +418,7 @@ def _flatten(
416418
break
417419
assert not isinstance(node, Fork)
418420
elif isinstance(node, Array):
419-
new_nodes = node._flatten(
420-
compute_node, fanout, return_fanout=False
421-
)
421+
new_nodes = node._flatten(compute_node, fanout, return_fanout=False)
422422
nodes.extend(new_nodes)
423423
nodes.append(node)
424424
fanout *= node.get_fanout()
@@ -472,10 +472,14 @@ def _parent2child_names(
472472
elif isinstance(node, Compute):
473473
# Compute nodes branch off to the side like a Fork
474474
if current_parent_name is not None:
475-
edges.append((current_parent_name, node._render_node_name(), "solid"))
475+
edges.append(
476+
(current_parent_name, node._render_node_name(), "solid")
477+
)
476478
else:
477479
if current_parent_name is not None:
478-
edges.append((current_parent_name, node._render_node_name(), "solid"))
480+
edges.append(
481+
(current_parent_name, node._render_node_name(), "solid")
482+
)
479483

480484
# Update parent for next iteration
481485
current_parent_name = node._render_node_name()

accelforge/frontend/spec.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@
33
from accelforge.frontend.mapper import FFM
44
from accelforge.frontend.renames import EinsumName, Renames
55
from accelforge.util._eval_expressions import EvaluationError, ParseExpressionsContext
6-
from accelforge.frontend.arch import Compute, Leaf, Component, Arch, Container, Spatialable
6+
from accelforge.frontend.arch import (
7+
Compute,
8+
Leaf,
9+
Component,
10+
Arch,
11+
Container,
12+
Spatialable,
13+
)
714

815
from accelforge.frontend.workload import Workload
916
from accelforge.frontend.variables import Variables

accelforge/model/_looptree/energy.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,23 @@ def compute_keyer(compute, action_name):
117117

118118
def _get_network_keyer(verbose, use_name, bindings):
119119
if not verbose:
120+
120121
def network_keyer(network: Network, action_name: str):
121122
component = network.component
122123
if not use_name:
123124
component = bindings[component]
124125
return ActionKey(component, action_name)
126+
125127
else:
128+
126129
def network_keyer(network: Network, action_name: str):
127130
component = network.component
128131
if not use_name:
129132
component = bindings[component]
130-
return VerboseActionKey(component, action_name, network.tensor, network.einsum)
133+
return VerboseActionKey(
134+
component, action_name, network.tensor, network.einsum
135+
)
136+
131137
return network_keyer
132138

133139

accelforge/model/_looptree/reuse/symbolic/mapping_utils.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22
Mapping,
33
)
44

5-
from accelforge.frontend.mapping import (
6-
Mapping,
7-
TensorHolder,
8-
Compute as ComputeSpec
9-
)
5+
from accelforge.frontend.mapping import Mapping, TensorHolder, Compute as ComputeSpec
106
from accelforge.frontend.workload import (
117
TensorName,
128
)
@@ -18,6 +14,7 @@ class DataMovementConnections:
1814
For querying connection between Buffet or Compute
1915
(e.g., which Buffet supplies this Compute).
2016
"""
17+
2118
def __init__(self):
2219
self.src_to_dst = {}
2320
self.dst_to_src = {}
@@ -77,4 +74,3 @@ def get_tensor_to_backer_id(mapping: Mapping):
7774
continue
7875
tensor_to_ids[tensor] = id(node)
7976
return tensor_to_ids
80-

accelforge/model/_looptree/reuse/symbolic/symbolic.py

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
from accelforge.model._looptree.types import Buffet, Compute, Network
4242
from accelforge.model._looptree.reuse.symbolic.mapping_utils import (
4343
DataMovementConnections,
44-
get_tensor_to_backer_id
44+
get_tensor_to_backer_id,
4545
)
4646

4747
from accelforge.mapper.FFM._make_pmappings.pmapper_job import Job
@@ -251,7 +251,7 @@ def net_max_per_unit_write_actions(self) -> Any:
251251
@classmethod
252252
def blank(cls):
253253
stats = cls()
254-
stats.n_loops_above = None # Inherit from whoever is added to this
254+
stats.n_loops_above = None # Inherit from whoever is added to this
255255
return stats
256256

257257

@@ -573,7 +573,9 @@ def analyze_reuse_and_add_reservations_to_mapping(
573573
tensor_to_backer_id=tensor_to_backer_id,
574574
is_copy_operation=is_copy_operation,
575575
job=job,
576-
data_movement_connections=DataMovementConnections.from_pmapping(cur_mapping.nodes),
576+
data_movement_connections=DataMovementConnections.from_pmapping(
577+
cur_mapping.nodes
578+
),
577579
)
578580
cur_result = analyze_node(0, job.rank_variable_bounds, info)
579581
if result is None:
@@ -826,7 +828,9 @@ def handle_repeated_value(repeated_shape):
826828
accumulated_stats.n_loops_above = stats.n_loops_above + 1
827829

828830
for network, network_stats in child_result.network_stats.items():
829-
result_accumulator.network_stats[network] = network_stats.repeat(shape_repeats)
831+
result_accumulator.network_stats[network] = network_stats.repeat(
832+
shape_repeats
833+
)
830834

831835
for einsum, child_steps in child_result.temporal_steps.items():
832836
if einsum not in result_accumulator.temporal_steps:
@@ -925,29 +929,31 @@ def handle_repeated_value(repeated_shape):
925929
result_accumulator.network_stats[network] = NetworkStats()
926930
accumulated_network_stats = result_accumulator.network_stats[network]
927931

928-
accumulated_network_stats.total_hops += \
929-
child_network_stats.total_hops*shape_repeats
932+
accumulated_network_stats.total_hops += (
933+
child_network_stats.total_hops * shape_repeats
934+
)
930935
accumulated_network_stats.max_hops = max(
931936
accumulated_network_stats.max_hops,
932937
child_network_stats.max_hops,
933938
)
934939
projection = info.einsum_tensor_to_projection[(einsum_name, network.tensor)]
935940
component_object = find_component_object(
936-
network.component,
937-
info.job.flattened_arch
941+
network.component, info.job.flattened_arch
938942
)
939943
bits_per_value_scale = component_object.bits_per_value_scale[network.tensor]
940944
bits_per_value = (
941945
bits_per_value_scale
942-
*
943-
info.job.einsum.tensor_accesses[network.tensor].bits_per_value
946+
* info.job.einsum.tensor_accesses[network.tensor].bits_per_value
944947
)
945948
bits_per_action = component_object.bits_per_action
946949
if bits_per_action is not None:
947-
actions_per_value = bits_per_value/bits_per_action
950+
actions_per_value = bits_per_value / bits_per_action
948951
else:
949952
actions_per_value = bits_per_value
950-
volume = compute_dense_tile_occupancy(projection, child_shape) * actions_per_value
953+
volume = (
954+
compute_dense_tile_occupancy(projection, child_shape)
955+
* actions_per_value
956+
)
951957

952958
if info.job.spec.arch.is_above(node.component, network.component):
953959
continue
@@ -956,27 +962,29 @@ def handle_repeated_value(repeated_shape):
956962
last_fanout = last_fanout.get(node.name, 1)
957963
if isinstance(relevancy, Irrelevant):
958964
# Cost of multicasting is the cost of delivering along the dimension
959-
multicast_hops = (shape_repeats-1)*last_fanout
965+
multicast_hops = (shape_repeats - 1) * last_fanout
960966
multicast_cost = multicast_hops * volume
961967
overall_max_hops += multicast_hops
962968

963969
accumulated_network_stats.total_hops += multicast_cost
964970
accumulated_network_stats.max_hops = max(
965971
accumulated_network_stats.max_hops,
966-
overall_max_hops + child_network_stats.max_hops
972+
overall_max_hops + child_network_stats.max_hops,
967973
)
968974
elif isinstance(relevancy, Relevant):
969975
# Cost of unicast is the cost of delivering to each point in
970976
# the dimension with shape as stride
971977
# TODO: we should use the actual stride
972-
total_unicast_cost = 0.5*(shape_repeats-1)*shape_repeats*last_fanout * volume
973-
max_unicast_hops = (shape_repeats-1)*last_fanout
978+
total_unicast_cost = (
979+
0.5 * (shape_repeats - 1) * shape_repeats * last_fanout * volume
980+
)
981+
max_unicast_hops = (shape_repeats - 1) * last_fanout
974982
overall_max_hops += max_unicast_hops
975983

976984
accumulated_network_stats.total_hops += total_unicast_cost
977985
accumulated_network_stats.max_hops = max(
978986
accumulated_network_stats.max_hops,
979-
overall_max_hops + child_network_stats.max_hops
987+
overall_max_hops + child_network_stats.max_hops,
980988
)
981989
elif isinstance(relevancy, PartiallyRelevant):
982990
raise NotImplementedError()
@@ -1256,17 +1264,15 @@ def analyze_reservation(node_idx, current_shape, info: AnalysisInfo):
12561264

12571265
# Reservation nodes are the first to produce stats for a network
12581266
network_node = info.job.spec.arch.find_first_of_type_above(
1259-
NetworkSpec,
1260-
buffet.level,
1261-
default=None
1267+
NetworkSpec, buffet.level, default=None
12621268
)
12631269
if network_node is not None:
12641270
network = Network(
12651271
tensor,
12661272
einsum_name,
12671273
info.data_movement_connections.get_src(buffet),
12681274
buffet,
1269-
component=network_node.name if network_node else network_node
1275+
component=network_node.name if network_node else network_node,
12701276
)
12711277
assert network not in child_result.network_stats
12721278
child_result.network_stats[network] = NetworkStats()
@@ -1313,17 +1319,15 @@ def analyze_compute(
13131319
result_accumulator.buffet_stats[buffet] = stats
13141320

13151321
network_node = info.job.spec.arch.find_first_of_type_above(
1316-
NetworkSpec,
1317-
node.component,
1318-
default=None
1322+
NetworkSpec, node.component, default=None
13191323
)
13201324
if network_node is not None:
13211325
network = Network(
13221326
tensor,
13231327
info.job.einsum_name,
13241328
info.data_movement_connections.get_src(buffet),
13251329
buffet,
1326-
component=network_node.name if network_node else network_node
1330+
component=network_node.name if network_node else network_node,
13271331
)
13281332
result_accumulator.network_stats[network] = NetworkStats()
13291333

accelforge/model/_looptree/types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class Network:
3737
"""
3838
A logical network that delivers a tensor.
3939
"""
40+
4041
tensor: TensorName
4142
"The tensor held by the buffet."
4243
einsum: EinsumName

accelforge/model/main.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,12 @@ def evaluate_mapping(
186186
einsum2pmappings[job.einsum_name] = [
187187
PmappingGroup(
188188
compatibility,
189-
PmappingDataframe(pd.DataFrame(df, columns=df.keys(), index=[0]), 1, 1),
189+
PmappingDataframe(
190+
data=pd.DataFrame(df, columns=df.keys(), index=[0]),
191+
n_total_pmappings=1,
192+
n_valid_pmappings=1,
193+
ignored_resources=set(),
194+
),
190195
)
191196
]
192197
pmapping_objects[job.einsum_name] = {pmapping_id: job.mapping}

0 commit comments

Comments
 (0)