Skip to content

Commit 3e20639

Browse files
Mapper speedup
1 parent f9bb3f5 commit 3e20639

File tree

2 files changed

+38
-18
lines changed

2 files changed

+38
-18
lines changed

accelforge/mapper/FFM/_make_pmappings/make_pmappings_from_templates/make_tile_shapes.py

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -780,14 +780,23 @@ def latest(s=None):
780780
for s in formula.free_symbols:
781781
g = latest(s).goal if s in latest() else None
782782
if g in ["min", "max"]:
783+
log_message(
784+
"coalesce symbols", f"checking agreement with {s} and goal {g}"
785+
)
783786
diff_result = diff_geq_leq_zero(formula, s, bounds)
784787
if diff_result == ComparisonResult.ALWAYS_LEQ_THAN_ZERO:
785788
this_goal = (~goal).goal
789+
log_message("coalesce symbols", f"diff result for {s} <= 0")
786790
elif diff_result == ComparisonResult.ALWAYS_GEQ_THAN_ZERO:
787791
this_goal = (goal).goal
792+
log_message("coalesce symbols", f"diff result for {s} >= 0")
788793
elif diff_result == ComparisonResult.UNKNOWN:
794+
log_message(
795+
"coalesce symbols", f"diff result for {s} is unknown"
796+
)
789797
break
790798
elif diff_result == ComparisonResult.ALWAYS_EQUAL_TO_ZERO:
799+
log_message("coalesce symbols", f"diff result for {s} = 0")
791800
this_goal = g # Make it agree
792801
else:
793802
diff_geq_leq_zero(formula, s, bounds)
@@ -812,6 +821,10 @@ def latest(s=None):
812821
)
813822
update_symbol2goal(s, Goal("diff"), new_symbol2goal)
814823
continue
824+
log_message(
825+
"coalesce symbols",
826+
f"can't change formula: {formula}",
827+
)
815828
update_symbol2goal(formula, goal, new_symbol2goal)
816829

817830
changed = symbol2goal != new_symbol2goal
@@ -1153,7 +1166,6 @@ def update_symbol2goal(
11531166
# If there's a max value, then check for validity
11541167
# ==========================================================================
11551168
complete = objective.formula.free_symbols.issubset(sym_enumerated_set)
1156-
prev_size = choices_enumerated.shape[0]
11571169
if objective.max_value is not None:
11581170
try:
11591171
# minimize_for_objective may raise a TypeError if there's unknown
@@ -1211,22 +1223,23 @@ def update_symbol2goal(
12111223
except (TypeError, ValueError):
12121224
pass
12131225

1226+
if choices_enumerated.shape[0] < 1000:
1227+
continue
1228+
1229+
for objective in list(objectives):
1230+
# ==========================================================================
1231+
# If there's a max value, then check for validity
1232+
# ==========================================================================
1233+
complete = objective.formula.free_symbols.issubset(sym_enumerated_set)
1234+
prev_size = choices_enumerated.shape[0]
1235+
12141236
log_message(
12151237
"Partitioning formula", f"{objective.name}: {objective.formula}"
12161238
)
1239+
12171240
goals = partition_formula(
12181241
objective.formula, sym_enumerated_set, what_tiles_symbol.bounds
12191242
)
1220-
if any(g.goal == "diff" for g in goals.values()):
1221-
goals2 = partition_formula(
1222-
sympy.expand(objective.formula),
1223-
sym_enumerated_set,
1224-
what_tiles_symbol.bounds,
1225-
)
1226-
goals = min(
1227-
(goals, goals2),
1228-
key=lambda x: sum(g.goal == "diff" for g in x.values()),
1229-
)
12301243

12311244
porp = sum(valid) / max(1, choices_enumerated.shape[0])
12321245
job.log_porp_pmappings_kept(
@@ -1236,6 +1249,7 @@ def update_symbol2goal(
12361249
log_message(f"Valid check", f"{objective.name}", f"porp={porp:.2%}")
12371250
if complete:
12381251
objective.max_value = None # We don't care anymore
1252+
objective.min_value = None
12391253
if objective.only_care_if_valid:
12401254
objectives.remove(objective)
12411255
log_message(f"Removed {objective.name} because it is always valid")
@@ -1252,9 +1266,6 @@ def update_symbol2goal(
12521266
if not choices_enumerated.shape[0]:
12531267
return np.array([]).reshape(-1, len(symbols))
12541268

1255-
if choices_enumerated.shape[0] < 100:
1256-
continue
1257-
12581269
# ==============================================================================
12591270
# Coalesce symbols. This simplifies our tracked goals. It also breaks down
12601271
# partially-unknown goals into fully-known and/or fully-unknown goals.
@@ -1553,8 +1564,17 @@ def _make_tile_shapes(job: "Job"):
15531564
# If we only track for pmappings, we only care if it's valid. If we track for
15541565
# all, we care about the value too.
15551566

1567+
split = k.split("<SEP>")
1568+
assert split[0] == "usage", f"invalid {split}"
1569+
if split[1] == "spatial":
1570+
assert len(split) == 4
1571+
elif split[1] == "memory":
1572+
assert len(split) == 3
1573+
else:
1574+
assert False, f"invalid {split}"
1575+
15561576
only_care_if_valid = False
1557-
if k in job.memories_track_pmappings_only:
1577+
if split[2] in job.memories_track_pmappings_only:
15581578
only_care_if_valid = True
15591579

15601580
# TODO: Update check to see if we may be sharing usage with other

accelforge/plotting/roofline.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ def plot_roofline(
3030

3131
roofline_transition = _roofline_transition(bandwidth, computational_throughput)
3232
if max_computational_intensity is None:
33-
max_computational_intensity = 2*roofline_transition
33+
max_computational_intensity = 2 * roofline_transition
3434

3535
ax.plot(
3636
[min_computational_intensity, roofline_transition],
37-
[min_computational_intensity*bandwidth, computational_throughput],
37+
[min_computational_intensity * bandwidth, computational_throughput],
3838
)
3939
ax.plot(
4040
[roofline_transition, max_computational_intensity],
@@ -45,4 +45,4 @@ def plot_roofline(
4545

4646

4747
def _roofline_transition(bandwidth, computation_throughput):
48-
return computation_throughput/bandwidth
48+
return computation_throughput / bandwidth

0 commit comments

Comments
 (0)