Skip to content

Commit 2f7acf8

Browse files
author
Michael Gilbert
committed
[looptree] Temporary symbolic reuse analysis compiler
1 parent d1331ac commit 2f7acf8

File tree

4 files changed

+53
-13
lines changed

4 files changed

+53
-13
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
from .symbolic import SummarizedAnalysisOutput
1+
from .symbolic import SummarizedAnalysisOutput
2+
from .compiler import compile_analysis_result

pytimeloop/looptree/reuse/summarized/compiler.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,17 @@ def lambdify(d, tile_shapes):
1212
k: sympy.lambdify(tile_shapes, v)
1313
for k, v in d.items()
1414
}
15+
16+
17+
def compile_analysis_result(result, tile_shapes):
18+
lambdify_with_tile_shapes = lambda x: lambdify(x, tile_shapes)
19+
20+
result.ops = lambdify_with_tile_shapes(result.ops)
21+
result.temporal_steps = lambdify_with_tile_shapes(result.temporal_steps)
22+
result.fanout = lambdify_with_tile_shapes(result.fanout)
23+
result.occupancy = lambdify_with_tile_shapes(result.occupancy)
24+
result.fills = lambdify_with_tile_shapes(result.fills)
25+
result.reads_to_parent = lambdify_with_tile_shapes(result.reads_to_parent)
26+
result.op_intensity = lambdify_with_tile_shapes(result.op_intensity)
27+
28+
return result

pytimeloop/looptree/reuse/summarized/symbolic.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -232,15 +232,3 @@ def analyze_reuse(mapping,
232232
output.fanout = fanout
233233

234234
return tile_shapes, output
235-
236-
lambdify_with_tile_shapes = lambda x: lambdify(x, tile_shapes)
237-
238-
output.ops = lambdify_with_tile_shapes(output.ops)
239-
output.temporal_steps = lambdify_with_tile_shapes(output.temporal_steps)
240-
output.fanout = lambdify_with_tile_shapes(output.fanout)
241-
output.occupancy = lambdify_with_tile_shapes(output.occupancy)
242-
output.fills = lambdify_with_tile_shapes(output.fills)
243-
output.reads_to_parent = lambdify_with_tile_shapes(output.reads_to_parent)
244-
output.op_intensity = lambdify_with_tile_shapes(output.op_intensity)
245-
246-
return tile_shapes, output

tests/looptree/test_symbolic_reuse_analysis.py renamed to tests/looptree/reuse_analysis/test_symbolic.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import unittest
22
from sympy import ceiling
3+
from math import ceil
4+
from pprint import pp
35

46
from bindings.looptree import LooptreeWorkload, LooptreeWorkloadDependencyAnalyzer
57

68
from tests.load_config_mixin import LoadConfigMixin
79

810
from pytimeloop.looptree.reuse.summarized.symbolic import analyze_reuse
11+
from pytimeloop.looptree.reuse.summarized import compile_analysis_result
912

1013

1114
class TestSymbolicReuseAnalysis(unittest.TestCase, LoadConfigMixin):
@@ -37,3 +40,37 @@ def test_model_with_two_level_mm(self):
3740
self.assertEqual(result.fills[key],
3841
ref_value,
3942
f'fills for {key} do not match')
43+
44+
45+
class TestCompiler(unittest.TestCase, LoadConfigMixin):
46+
def test_model_with_two_level_mm(self):
47+
config, spec = self.load_config([
48+
'symbolic-mapping.yaml',
49+
'cascaded_mm.workload.yaml',
50+
'three_level.arch.yaml'
51+
])
52+
53+
mapping = spec['mapping']['nodes']
54+
workload = LooptreeWorkload.parse_cfg(config.root['problem'])
55+
analyzer = LooptreeWorkloadDependencyAnalyzer(workload)
56+
57+
tile_shapes, result = analyze_reuse(mapping, workload, analyzer)
58+
self.assertEqual(len(tile_shapes), 3)
59+
compiled_result = compile_analysis_result(result, tile_shapes)
60+
61+
for M1_tile_shape_val in [1, 2, 4]:
62+
63+
REFERENCE_FILLS = {
64+
('DRAM', 0, 0): 18,
65+
('DRAM', 1, 0): 8,
66+
('DRAM', 2, 0): 36,
67+
('GlobalBuffer', 0, 0): 18.0*ceil(4/M1_tile_shape_val),
68+
('GlobalBuffer', 1, 0): 8
69+
}
70+
71+
for key, ref_value in REFERENCE_FILLS.items():
72+
self.assertEqual(
73+
compiled_result.fills[key][1](1, 1, M1_tile_shape_val),
74+
ref_value,
75+
f'fills for {key} do not match'
76+
)

0 commit comments

Comments
 (0)