Skip to content

Commit cf1682a

Browse files
Simanneal baseline updates
1 parent be4d81b commit cf1682a

4 files changed

Lines changed: 40 additions & 14 deletions

File tree

accelforge/_deprecate/_simanneal/wrappers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def join_pmappings(
201201
)
202202
for _ in range(n_threads)
203203
],
204-
n_jobs=get_n_parallel_jobs()
204+
n_jobs=get_n_parallel_jobs(),
205205
)
206206
results = pd.concat([r[0] for r in results_and_trackers])
207207
break

accelforge/frontend/mapping/mapping.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -593,10 +593,14 @@ def _merge(self, other: "TensorHolder") -> "TensorHolder":
593593
f"Components do not match: {self.component} != {other.component}"
594594
)
595595

596+
if self._lower != other._lower:
597+
raise ValueError(f"Lower flags do not match: {self._lower} != {other._lower}")
598+
596599
new = type(self)(
597600
tensors=self.tensors + other.tensors,
598601
component=self.component,
599602
component_object=self.component_object,
603+
_lower=self._lower,
600604
)
601605
return new
602606

@@ -1185,7 +1189,7 @@ def compact_str(self) -> str:
11851189
if prev is not None:
11861190
result.append(prev)
11871191

1188-
return " ".join(node.compact_str() for node in result)
1192+
return " ".join(f"{node.compact_str()}" for node in result)
11891193

11901194
def _get_single_tensor_mapping(
11911195
self,
@@ -1519,18 +1523,33 @@ class Mapping(Nested):
15191523
def remove_reservations(self):
15201524
self.nodes = [n for n in self.nodes if not isinstance(n, Reservation)]
15211525

1522-
def split_loop_with_multiple_rank_variables(self):
1526+
def split_reservations(self):
15231527
new_nodes = []
15241528
for node in self.nodes:
1525-
if isinstance(node, Loop) and isinstance(node.rank_variable, set):
1526-
for rank_variable in node.rank_variable:
1529+
if isinstance(node, Reservation):
1530+
for purpose in node.purposes:
15271531
new_node = copy.copy(node)
1528-
new_node.rank_variable = rank_variable
1532+
new_node.purposes = [purpose]
15291533
new_nodes.append(new_node)
15301534
else:
15311535
new_nodes.append(node)
15321536
self.nodes = new_nodes
15331537

1538+
def split_loop_with_multiple_rank_variables(self, stride_and_halo: dict[str, tuple[int, int]]):
1539+
new_nodes = []
1540+
for node in self.nodes:
1541+
if isinstance(node, Loop) and isinstance(node.rank_variable, set):
1542+
ranks_in_stride_and_halo = {
1543+
r for r in node.rank_variable if r in stride_and_halo
1544+
}
1545+
assert len(ranks_in_stride_and_halo) == 1, f"Expected 1 rank in stride and halo, got {len(ranks_in_stride_and_halo)}"
1546+
new_node = copy.copy(node)
1547+
new_node.rank_variable = ranks_in_stride_and_halo.pop()
1548+
new_nodes.append(new_node)
1549+
else:
1550+
new_nodes.append(node)
1551+
self.nodes = new_nodes
1552+
15341553
def split_tensor_holders_with_multiple_tensors(self):
15351554
new_nodes = []
15361555
for node in self.nodes:

accelforge/mapper/_simanneal2/simanneal.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,9 @@ def _merge_next(
233233
live_tensors_with_right=live_tensors | right_tensors,
234234
aliased_tensors=self.mapspace_globals.aliased_tensors,
235235
compatibility_joined=joined.compatibility.merge_next(
236-
s.compatibility, live_tensors,
237-
mixable_ranks=self.mapspace_globals.mixable_ranks
236+
s.compatibility,
237+
live_tensors,
238+
mixable_ranks=self.mapspace_globals.mixable_ranks,
238239
),
239240
drop_valid_reservations=True,
240241
delay=False,
@@ -334,7 +335,7 @@ def _join_pmappings(
334335
aliased_tensors=spec.workload.get_tensor_copies(),
335336
objective_function=objective_function,
336337
tracker=tracker,
337-
mixable_ranks=spec.workload._get_ranks_that_share_indexing_rank_variables()
338+
mixable_ranks=spec.workload._get_ranks_that_share_indexing_rank_variables(),
338339
)
339340

340341
mappings = []
@@ -404,13 +405,17 @@ def join_pmappings(
404405
pop_size_per_thread = population_size // get_n_parallel_jobs()
405406

406407
# Multiply by the number of einsums
407-
print(f'Multiplying scale by {len(pmappings.einsum2pmappings)} for number of einsums')
408+
print(
409+
f"Multiplying scale by {len(pmappings.einsum2pmappings)} for number of einsums"
410+
)
408411
tracker._scale_by *= len(pmappings.einsum2pmappings)
409412

410413
# We allow FFM to query n_pareto_optimal_pmappings mappings from the mapspace, so we
411414
# scale by 1 / n_pareto_optimal_pmappings to get simanneal 1 evaluation = same
412415
# number of mappings as FFM
413-
print(f'Multiplying scale by {1 / pmappings.n_pareto_optimal_pmappings()} for Pareto-optimal mapspace size')
416+
print(
417+
f"Multiplying scale by {1 / pmappings.n_pareto_optimal_pmappings()} for Pareto-optimal mapspace size"
418+
)
414419
tracker._scale_by *= 1 / pmappings.n_pareto_optimal_pmappings()
415420

416421
for einsum_name, einsum_pmappings in pmappings.einsum2pmappings.items():
@@ -444,15 +449,17 @@ def join_pmappings(
444449
# Count mappings with fewer loops as separate choices
445450
for subset in list(subsets):
446451
for i in range(2 ** len(subset)):
447-
subsets.add(tuple(subset[j] for j in range(len(subset)) if i & (1 << j)))
452+
subsets.add(
453+
tuple(subset[j] for j in range(len(subset)) if i & (1 << j))
454+
)
448455

449456
n_total += len(subsets) * n_pmappings * get_n_tile_shapes(s)
450457

451458
# The pmapper does mappings with varied permutations, subsets of loops, and tile
452459
# shapes in one shot, which won't be the case if a simulated annealing mapper is
453460
# used to select the top part of the mapping. So scale to account for the number
454461
# that we get for free.
455-
print(f'Multiplying scale by {n_total / n_evaluated} for number of total pmappings')
462+
print(f"Multiplying scale by {n_total / n_evaluated} for number of total pmappings")
456463
tracker._scale_by *= n_total / n_evaluated
457464

458465
def parallel_join(

accelforge/mapper/_simanneal2/tracking.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def add_evaluation(self, n_evaluations: int, best_score: float):
2222
self.evaluations += n_evaluations * self._scale_by
2323
new_score = best_score * self._scale_score_by
2424
if new_score < self.score:
25-
print(f'New score {new_score} after evaluation {self.evaluations}')
25+
print(f"New score {new_score} after evaluation {self.evaluations}")
2626
self.score = min(self.score, best_score * self._scale_score_by)
2727
# Same score as before, remove the last entry
2828
if len(self.history) > 2 and self.history[-2][1] == self.score:

0 commit comments

Comments
 (0)