accelforge 0.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (258) hide show
  1. accelforge/__init__.py +21 -0
  2. accelforge/_accelerated_imports.py +16 -0
  3. accelforge/_deprecate/_simanneal/evalmapping.py +271 -0
  4. accelforge/_deprecate/_simanneal/mapspaceglobals.py +298 -0
  5. accelforge/_deprecate/_simanneal/simanneal.py +666 -0
  6. accelforge/_deprecate/_simanneal/tracking.py +105 -0
  7. accelforge/_deprecate/_simanneal/wrappers.py +218 -0
  8. accelforge/_deprecate/_simanneal2/__init__.py +7 -0
  9. accelforge/_deprecate/_simanneal2/simanneal.py +493 -0
  10. accelforge/_deprecate/_simanneal2/tracking.py +116 -0
  11. accelforge/_deprecate/compatibility_util.py +181 -0
  12. accelforge/_deprecate/layerdeduplication/__init__.py +2 -0
  13. accelforge/_deprecate/layerdeduplication/group_similar_einsums.py +160 -0
  14. accelforge/_deprecate/layerdeduplication/grouped_einsums.py +84 -0
  15. accelforge/_deprecate/mapping_filter_tags/__init__.py +2 -0
  16. accelforge/_deprecate/mapping_filter_tags/ffmt.py +212 -0
  17. accelforge/_deprecate/mapping_filter_tags/onesplit.py +24 -0
  18. accelforge/_deprecate/mapping_filter_tags/util.py +24 -0
  19. accelforge/_deprecate/tags.py +69 -0
  20. accelforge/_deprecate/viz/__init__.py +0 -0
  21. accelforge/_deprecate/viz/interactive.py +159 -0
  22. accelforge/_deprecate/viz/reservationtree.py +307 -0
  23. accelforge/_deprecate/viz/ski_slope.py +88 -0
  24. accelforge/_version.py +15 -0
  25. accelforge/examples.py +39 -0
  26. accelforge/frontend/__init__.py +10 -0
  27. accelforge/frontend/_binding.py +129 -0
  28. accelforge/frontend/_workload_isl/__init__.py +2 -0
  29. accelforge/frontend/_workload_isl/_isl.py +149 -0
  30. accelforge/frontend/_workload_isl/_symbolic.py +141 -0
  31. accelforge/frontend/arch copy.py +1544 -0
  32. accelforge/frontend/arch.py +1642 -0
  33. accelforge/frontend/config.py +63 -0
  34. accelforge/frontend/mapper/__init__.py +5 -0
  35. accelforge/frontend/mapper/ffm.py +126 -0
  36. accelforge/frontend/mapper/mapper.py +7 -0
  37. accelforge/frontend/mapper/metrics.py +30 -0
  38. accelforge/frontend/mapping/__init__.py +1 -0
  39. accelforge/frontend/mapping/mapping.py +1736 -0
  40. accelforge/frontend/model.py +14 -0
  41. accelforge/frontend/renames.py +150 -0
  42. accelforge/frontend/spec copy.py +230 -0
  43. accelforge/frontend/spec.py +301 -0
  44. accelforge/frontend/variables.py +12 -0
  45. accelforge/frontend/workload.py +952 -0
  46. accelforge/mapper/FFM/__init__.py +9 -0
  47. accelforge/mapper/FFM/_join_pmappings/__init__.py +0 -0
  48. accelforge/mapper/FFM/_join_pmappings/compatibility.py +653 -0
  49. accelforge/mapper/FFM/_join_pmappings/compress_pmappings.py +140 -0
  50. accelforge/mapper/FFM/_join_pmappings/join_pmappings.py +703 -0
  51. accelforge/mapper/FFM/_join_pmappings/pmapping_dataframe.py +901 -0
  52. accelforge/mapper/FFM/_join_pmappings/pmapping_group.py +337 -0
  53. accelforge/mapper/FFM/_make_pmappings/contraints/__init__.py +0 -0
  54. accelforge/mapper/FFM/_make_pmappings/contraints/constraints.py +360 -0
  55. accelforge/mapper/FFM/_make_pmappings/make_pmapping_templates/__init__.py +1 -0
  56. accelforge/mapper/FFM/_make_pmappings/make_pmapping_templates/make_loops.py +373 -0
  57. accelforge/mapper/FFM/_make_pmappings/make_pmapping_templates/make_pmapping_templates.py +463 -0
  58. accelforge/mapper/FFM/_make_pmappings/make_pmapping_templates/make_reservations.py +95 -0
  59. accelforge/mapper/FFM/_make_pmappings/make_pmapping_templates/make_storage_order.py +382 -0
  60. accelforge/mapper/FFM/_make_pmappings/make_pmapping_templates/make_storages.py +155 -0
  61. accelforge/mapper/FFM/_make_pmappings/make_pmappings.py +411 -0
  62. accelforge/mapper/FFM/_make_pmappings/make_pmappings_from_templates/__init__.py +1 -0
  63. accelforge/mapper/FFM/_make_pmappings/make_pmappings_from_templates/make_pmappings_from_templates.py +407 -0
  64. accelforge/mapper/FFM/_make_pmappings/make_pmappings_from_templates/make_tile_shapes.py +1681 -0
  65. accelforge/mapper/FFM/_make_pmappings/make_pmappings_from_templates/run_model.py +170 -0
  66. accelforge/mapper/FFM/_make_pmappings/make_pmappings_from_templates/symbol_relations.py +174 -0
  67. accelforge/mapper/FFM/_make_pmappings/pmapper_job.py +282 -0
  68. accelforge/mapper/FFM/_pareto_df/df_convention.py +273 -0
  69. accelforge/mapper/FFM/_pareto_df/pareto copy.py +836 -0
  70. accelforge/mapper/FFM/_pareto_df/pareto.py +508 -0
  71. accelforge/mapper/FFM/data.py +61 -0
  72. accelforge/mapper/FFM/main copy.py +236 -0
  73. accelforge/mapper/FFM/main.py +208 -0
  74. accelforge/mapper/FFM/mappings.py +510 -0
  75. accelforge/mapper/FFM/pmappings.py +310 -0
  76. accelforge/mapper/__init__.py +4 -0
  77. accelforge/mapper.py +0 -0
  78. accelforge/model/__init__.py +1 -0
  79. accelforge/model/_looptree/__init__.py +0 -0
  80. accelforge/model/_looptree/accesses.py +335 -0
  81. accelforge/model/_looptree/capacity/__init__.py +1 -0
  82. accelforge/model/_looptree/capacity/aggregators.py +36 -0
  83. accelforge/model/_looptree/capacity/capacity.py +47 -0
  84. accelforge/model/_looptree/energy.py +150 -0
  85. accelforge/model/_looptree/equivalent_ranks.py +29 -0
  86. accelforge/model/_looptree/latency/__init__.py +1 -0
  87. accelforge/model/_looptree/latency/latency.py +98 -0
  88. accelforge/model/_looptree/latency/memory.py +120 -0
  89. accelforge/model/_looptree/latency/processors.py +92 -0
  90. accelforge/model/_looptree/mapping_utilities.py +71 -0
  91. accelforge/model/_looptree/reuse/__init__.py +4 -0
  92. accelforge/model/_looptree/reuse/isl/__init__.py +1 -0
  93. accelforge/model/_looptree/reuse/isl/des.py +59 -0
  94. accelforge/model/_looptree/reuse/isl/isl_functions.py +374 -0
  95. accelforge/model/_looptree/reuse/isl/mapping_to_isl/__init__.py +4 -0
  96. accelforge/model/_looptree/reuse/isl/mapping_to_isl/analyze_mapping.py +297 -0
  97. accelforge/model/_looptree/reuse/isl/mapping_to_isl/skews_from_mapping.py +236 -0
  98. accelforge/model/_looptree/reuse/isl/mapping_to_isl/tiling.py +685 -0
  99. accelforge/model/_looptree/reuse/isl/mapping_to_isl/types.py +188 -0
  100. accelforge/model/_looptree/reuse/isl/spatial.py +260 -0
  101. accelforge/model/_looptree/reuse/isl/temporal.py +182 -0
  102. accelforge/model/_looptree/reuse/symbolic/__init__.py +1 -0
  103. accelforge/model/_looptree/reuse/symbolic/symbolic copy 2.py +1346 -0
  104. accelforge/model/_looptree/reuse/symbolic/symbolic copy.py +1408 -0
  105. accelforge/model/_looptree/reuse/symbolic/symbolic.py +1396 -0
  106. accelforge/model/_looptree/run.py +122 -0
  107. accelforge/model/_looptree/types.py +26 -0
  108. accelforge/model/_looptree/visualization/__init__.py +0 -0
  109. accelforge/model/_looptree/visualization/occupancy.py +11 -0
  110. accelforge/model/main.py +222 -0
  111. accelforge/plotting/__init__.py +2 -0
  112. accelforge/plotting/mappings.py +219 -0
  113. accelforge/plotting/specs.py +57 -0
  114. accelforge/util/__init__.py +4 -0
  115. accelforge/util/_base_analysis_types.py +24 -0
  116. accelforge/util/_basetypes.py +1089 -0
  117. accelforge/util/_frozenset.py +36 -0
  118. accelforge/util/_isl.py +29 -0
  119. accelforge/util/_itertools.py +14 -0
  120. accelforge/util/_mathfuncs.py +57 -0
  121. accelforge/util/_parse_expressions.py +339 -0
  122. accelforge/util/_picklecache.py +32 -0
  123. accelforge/util/_setexpressions.py +268 -0
  124. accelforge/util/_sympy/__init__.py +0 -0
  125. accelforge/util/_sympy/broadcast_max.py +18 -0
  126. accelforge/util/_visualization.py +112 -0
  127. accelforge/util/_yaml.py +579 -0
  128. accelforge/util/parallel.py +193 -0
  129. accelforge-0.0.1.dist-info/METADATA +64 -0
  130. accelforge-0.0.1.dist-info/RECORD +258 -0
  131. accelforge-0.0.1.dist-info/WHEEL +5 -0
  132. accelforge-0.0.1.dist-info/licenses/LICENSE +19 -0
  133. accelforge-0.0.1.dist-info/top_level.txt +5 -0
  134. docs/_build/html/_sources/fastfusion.frontend.mapper.rst.txt +37 -0
  135. docs/_build/html/_sources/fastfusion.frontend.rst.txt +70 -0
  136. docs/_build/html/_sources/fastfusion.frontend.workload.rst.txt +21 -0
  137. docs/_build/html/_sources/fastfusion.mapper.FFM.rst.txt +37 -0
  138. docs/_build/html/_sources/fastfusion.mapper.rst.txt +18 -0
  139. docs/_build/html/_sources/fastfusion.rst.txt +20 -0
  140. docs/_build/html/_sources/fastfusion.util.rst.txt +21 -0
  141. docs/_build/html/_sources/index.rst.txt +87 -0
  142. docs/_build/html/_sources/modules.rst.txt +7 -0
  143. docs/_build/html/_sources/notes/citation.rst.txt +45 -0
  144. docs/_build/html/_sources/notes/definitions.rst.txt +43 -0
  145. docs/_build/html/_sources/notes/faqs.rst.txt +39 -0
  146. docs/_build/html/_sources/notes/modeling/accelerator_energy_latency.rst.txt +72 -0
  147. docs/_build/html/_sources/notes/modeling/component_energy_area.rst.txt +96 -0
  148. docs/_build/html/_sources/notes/modeling/mapping.rst.txt +100 -0
  149. docs/_build/html/_sources/notes/modeling.rst.txt +33 -0
  150. docs/_build/html/_sources/notes/parsing/arithmetic_parsing.rst.txt +136 -0
  151. docs/_build/html/_sources/notes/parsing/setexpressions.rst.txt +63 -0
  152. docs/_build/html/_sources/notes/parsing/yaml_parsing.rst.txt +176 -0
  153. docs/_build/html/_sources/notes/quickstart_and_installation.rst.txt +9 -0
  154. docs/_build/html/_sources/notes/spec/architecture.rst.txt +133 -0
  155. docs/_build/html/_sources/notes/spec/mapping.rst.txt +12 -0
  156. docs/_build/html/_sources/notes/spec/workload.rst.txt +83 -0
  157. docs/_build/html/_sources/notes/spec.rst.txt +36 -0
  158. docs/source/_ext/include_attrs.py +213 -0
  159. docs/source/_ext/include_docstring.py +364 -0
  160. docs/source/_ext/include_functions.py +154 -0
  161. docs/source/_ext/include_notebook.py +131 -0
  162. docs/source/_ext/include_yaml.py +119 -0
  163. docs/source/_ext/inherited_attributes.py +222 -0
  164. docs/source/_ext/paths.py +4 -0
  165. docs/source/conf.py +79 -0
  166. examples/arches/compute_in_memory/_include.yaml +74 -0
  167. examples/arches/compute_in_memory/_include_functions.py +229 -0
  168. examples/arches/compute_in_memory/_load_spec.py +57 -0
  169. examples/arches/compute_in_memory/components/c2c_multiplier.py +181 -0
  170. examples/arches/compute_in_memory/components/dac_c2c_r2r.py +605 -0
  171. examples/arches/compute_in_memory/components/misc.py +195 -0
  172. examples/arches/compute_in_memory/components/util/bit_functions.py +51 -0
  173. examples/arches/compute_in_memory/components/zero_comparator.py +92 -0
  174. examples/arches/compute_in_memory/isaac.yaml +233 -0
  175. examples/arches/compute_in_memory/memory_cells/ecram_demo.yaml +63 -0
  176. examples/arches/compute_in_memory/memory_cells/rram_example.yaml +63 -0
  177. examples/arches/compute_in_memory/memory_cells/rram_isaac_isca_2016.yaml +64 -0
  178. examples/arches/compute_in_memory/memory_cells/rram_neurosim_default.yaml +63 -0
  179. examples/arches/compute_in_memory/memory_cells/rram_raella_isca_2023.yaml +70 -0
  180. examples/arches/compute_in_memory/memory_cells/rram_wan_nature_2022.yaml +63 -0
  181. examples/arches/compute_in_memory/memory_cells/sram_colonnade_jssc_2021.yaml +63 -0
  182. examples/arches/compute_in_memory/memory_cells/sram_example.yaml +63 -0
  183. examples/arches/compute_in_memory/memory_cells/sram_jia_jssc_2020.yaml +63 -0
  184. examples/arches/compute_in_memory/memory_cells/sram_sinangil_jssc_2021.yaml +63 -0
  185. examples/arches/compute_in_memory/memory_cells/sram_wang_vlsi_2022.yaml +63 -0
  186. examples/arches/compute_in_memory/wang_vlsi_2022.yaml +289 -0
  187. examples/arches/eyeriss.yaml +68 -0
  188. examples/arches/fanout_variations/at_glb.yaml +31 -0
  189. examples/arches/fanout_variations/at_glb_with_fanout_node.yaml +34 -0
  190. examples/arches/fanout_variations/at_mac.yaml +31 -0
  191. examples/arches/fanout_variations/at_mac_with_constraints.yaml +38 -0
  192. examples/arches/fanout_variations/at_mac_with_fanout_node.yaml +34 -0
  193. examples/arches/nvdla.yaml +47 -0
  194. examples/arches/simple.yaml +28 -0
  195. examples/arches/tpu_v4i.yaml +67 -0
  196. examples/mappings/unfused_matmuls_to_simple.yaml +33 -0
  197. examples/misc/component_annotated.yaml +33 -0
  198. examples/workloads/gpt3_6.7B.yaml +124 -0
  199. examples/workloads/matmuls.yaml +20 -0
  200. examples/workloads/mobilenet_28.yaml +81 -0
  201. examples/workloads/mobilenet_various_separate.yaml +106 -0
  202. examples/workloads/three_matmuls_annotated.yaml +59 -0
  203. notebooks/.ipynb_checkpoints/fastfusion_arch_study_michael-checkpoint.ipynb +359 -0
  204. notebooks/compute_in_memory/_scripts.py +339 -0
  205. notebooks/compute_in_memory/isaac.guide.ipynb +270 -0
  206. notebooks/compute_in_memory/wang_vlsi_2022.ipynb +602 -0
  207. notebooks/paths.py +4 -0
  208. notebooks/tutorials/.ipynb_checkpoints/1_FFM-checkpoint.ipynb +3110 -0
  209. notebooks/tutorials/FFM.ipynb +3498 -0
  210. notebooks/tutorials/_include.py +48 -0
  211. notebooks/tutorials/component_energy_area.ipynb +363 -0
  212. tests/Q_mapping.yaml +38 -0
  213. tests/__init__.py +0 -0
  214. tests/conv.mapping.yaml +27 -0
  215. tests/conv.workload.yaml +13 -0
  216. tests/conv_sym.mapping.yaml +43 -0
  217. tests/copy.mapping.yaml +35 -0
  218. tests/copy.workload.yaml +15 -0
  219. tests/distribuffers/__init__.py +0 -0
  220. tests/distribuffers/multicast/test_cases.yaml +482 -0
  221. tests/distribuffers/spec/binding/valid_bindings.yaml +97 -0
  222. tests/distribuffers/spec/distributed.yaml +100 -0
  223. tests/distribuffers/spec/logical_arch.yaml +32 -0
  224. tests/distribuffers/spec/physical_arch.yaml +69 -0
  225. tests/distribuffers/test_binding.py +48 -0
  226. tests/frontend/__init__.py +0 -0
  227. tests/frontend/test_mapping_viz.py +52 -0
  228. tests/mapper/__init__.py +0 -0
  229. tests/mapper/configs/conv1d/conv1d.mapping.yaml +31 -0
  230. tests/mapper/configs/conv1d/conv1d.workload.yaml +11 -0
  231. tests/mapper/configs/two_conv1d/two_conv1d.expected.yaml +38 -0
  232. tests/mapper/configs/two_conv1d/two_conv1d.mapping.yaml +54 -0
  233. tests/mapper/configs/two_conv1d/two_conv1d.workload.yaml +19 -0
  234. tests/mapper/test_mapping_to_isl.py +90 -0
  235. tests/mapper/test_spatial_reuse_analysis.py +67 -0
  236. tests/mapper/test_temporal_reuse_analysis.py +56 -0
  237. tests/mapper/util.py +58 -0
  238. tests/matmul.mapping.yaml +29 -0
  239. tests/matmul.workload.yaml +12 -0
  240. tests/matmul_spatial.mapping.yaml +44 -0
  241. tests/mha.renames.yaml +65 -0
  242. tests/mha.workload.yaml +67 -0
  243. tests/mha.yaml +59 -0
  244. tests/mha_full.workload.yaml +67 -0
  245. tests/mobilenet.workload.yaml +35 -0
  246. tests/mobilenet_long.workload.yaml +64 -0
  247. tests/pmappingcache.py +24 -0
  248. tests/processing_stage.arch.yaml +40 -0
  249. tests/snowcat.arch.yaml +36 -0
  250. tests/test_ffm_join_pmappings.py +106 -0
  251. tests/test_ffm_make_pmappings.py +82 -0
  252. tests/test_ffm_make_tile_shapes.py +49 -0
  253. tests/test_mapper.py +100 -0
  254. tests/test_model.py +37 -0
  255. tests/test_plotting.py +72 -0
  256. tests/test_processing_stage.py +46 -0
  257. tests/test_symbolic_model.py +248 -0
  258. tests/test_workload.py +141 -0
@@ -0,0 +1,48 @@
1
+ import re
2
+
3
+ def grab_from_yaml_file(
4
+ yaml_file: str,
5
+ startfrom: str | None = None,
6
+ same_indent: bool = True,
7
+ include_lines_before: int = 0,
8
+ ) -> str:
9
+ """
10
+ Grab a section from a YAML file.
11
+
12
+ Args:
13
+ yaml_file:
14
+ The path to the YAML file.
15
+ startfrom:
16
+ The string to start from. If None, return the entire file.
17
+ same_indent:
18
+ Whether to include lines with the same indentation as the startfrom line, or
19
+ only lines with >= indentation.
20
+ include_lines_before:
21
+ The number of lines to include before the startfrom line.
22
+
23
+ Returns:
24
+ The section of the YAML file as a string.
25
+ """
26
+ with open(yaml_file, "r") as f:
27
+ contents = f.readlines()
28
+ start, end = 0, len(contents)
29
+ n_whitespace = 0
30
+
31
+ if startfrom is not None:
32
+ for i, line in enumerate(contents):
33
+ if re.findall(r"\b\s*" + startfrom + r"\b", line):
34
+ start = i
35
+ n_whitespace = len(re.findall(r"^\s*", line)[0])
36
+ break
37
+ else:
38
+ raise ValueError(f"{startfrom} not found in {yaml_file}")
39
+ for i, line in enumerate(contents[start + 1 :]):
40
+ if not line.strip():
41
+ continue
42
+ ws = len(re.findall(r"^\s*", line)[0])
43
+ if ws < n_whitespace or (not same_indent and ws == n_whitespace):
44
+ end = start + i + 1
45
+ break
46
+
47
+ contents = [c[n_whitespace:] for c in contents[start - include_lines_before : end]]
48
+ return "".join(contents)
@@ -0,0 +1,363 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "metadata": {},
6
+ "source": [
7
+ "# Modeling Component Area, Energy, Latency, and Leak Power\n",
8
+ "\n",
9
+ "This notebook shows how to integrate component models from the `hwcomponents` library to\n",
10
+ "model area, energy, latency, and leak power.\n",
11
+ "\n",
12
+ "Before reading this notebook, you should be familiar with the `hwcomponents` library.\n",
13
+ "Ensure you've installed it and been through all of the notebooks in the [hwcomponents\n",
14
+ "documentation](https://accelergy-project.github.io/hwcomponents/).\n",
15
+ "\n",
16
+ "We'll be using the `component_example.yaml` file, which is annotated explaining what\n",
17
+ "each attribute means."
18
+ ]
19
+ },
20
+ {
21
+ "cell_type": "code",
22
+ "execution_count": null,
23
+ "metadata": {},
24
+ "outputs": [],
25
+ "source": [
26
+ "from pathlib import Path\n",
27
+ "from IPython.display import Markdown\n",
28
+ "\n",
29
+ "examples_dir = Path(\"../../examples\")\n",
30
+ "\n",
31
+ "display(Markdown(f\"\"\"\n",
32
+ "```yaml\n",
33
+ "{open(examples_dir / \"misc\" / \"component_annotated.yaml\").read()}\n",
34
+ "```\n",
35
+ "\"\"\"))"
36
+ ]
37
+ },
38
+ {
39
+ "cell_type": "markdown",
40
+ "metadata": {},
41
+ "source": [
42
+ "Now we'll create a global buffer component and model its area, energy, latency, and leak\n",
43
+ "power."
44
+ ]
45
+ },
46
+ {
47
+ "cell_type": "code",
48
+ "execution_count": null,
49
+ "metadata": {},
50
+ "outputs": [],
51
+ "source": [
52
+ "# < DOC_INCLUDE_MARKER > single_component_energy_area\n",
53
+ "\n",
54
+ "# Create the component from the yaml file\n",
55
+ "import accelforge as af\n",
56
+ "global_buffer = af.arch.Memory.from_yaml(\n",
57
+ " examples_dir / \"misc\" / \"component_annotated.yaml\"\n",
58
+ ")\n",
59
+ "\n",
60
+ "# Calculate the energy and area of the component\n",
61
+ "global_buffer = global_buffer.calculate_area_energy_latency_leak()\n",
62
+ "\n",
63
+ "# Print out the area, leak power, and energy for each action\n",
64
+ "area = global_buffer.attributes.area\n",
65
+ "leak_power = global_buffer.attributes.leak_power\n",
66
+ "print(f\"Area: {area:.2e} m^2\")\n",
67
+ "print(f\"Leak power: {leak_power:.2e} W\")\n",
68
+ "for action in global_buffer.actions:\n",
69
+ " energy = action.arguments.energy\n",
70
+ " latency = action.arguments.latency\n",
71
+ " print(f'Action {action.name} energy {energy:.2e} J, latency {latency:.2e}s')"
72
+ ]
73
+ },
74
+ {
75
+ "cell_type": "markdown",
76
+ "metadata": {},
77
+ "source": [
78
+ "Calculating area, energy, latency, and leak power for a component fills out more\n",
79
+ "attributes as well! We can inspect what is available by looking at the __doc__ or by\n",
80
+ "looking at this project's documentation website."
81
+ ]
82
+ },
83
+ {
84
+ "cell_type": "code",
85
+ "execution_count": null,
86
+ "metadata": {},
87
+ "outputs": [],
88
+ "source": [
89
+ "print(global_buffer.calculate_area_energy_latency_leak.__doc__)"
90
+ ]
91
+ },
92
+ {
93
+ "cell_type": "markdown",
94
+ "metadata": {},
95
+ "source": [
96
+ "As we can see in the doc, this function also fills out the `component_modeling_log`\n",
97
+ "attribute of the component, which contains messages from the component modeling\n",
98
+ "calculations."
99
+ ]
100
+ },
101
+ {
102
+ "cell_type": "code",
103
+ "execution_count": null,
104
+ "metadata": {},
105
+ "outputs": [],
106
+ "source": [
107
+ "# < DOC_INCLUDE_MARKER > hwcomponents\n",
108
+ "for message in global_buffer.component_modeling_log:\n",
109
+ " print(message)"
110
+ ]
111
+ },
112
+ {
113
+ "cell_type": "markdown",
114
+ "metadata": {},
115
+ "source": [
116
+ "To get more details on the specific model used, we can also look at the\n",
117
+ "`component_model` attribute of the component, which has the\n",
118
+ "`hwcomponents.ComponentModel` object that was used to calculate the energy and area. We\n",
119
+ "can use `help()` on this object to get more details on the model."
120
+ ]
121
+ },
122
+ {
123
+ "cell_type": "code",
124
+ "execution_count": null,
125
+ "metadata": {},
126
+ "outputs": [],
127
+ "source": [
128
+ "# < DOC_INCLUDE_MARKER > hwcomponents\n",
129
+ "component_model = global_buffer.component_model\n",
130
+ "print(help(component_model)) # Get documentation for the model"
131
+ ]
132
+ },
133
+ {
134
+ "cell_type": "markdown",
135
+ "metadata": {},
136
+ "source": [
137
+ "We can see that the global buffer is an instance of\n",
138
+ "`hwcomponents_library.SmartBufferSRAM`, and it contains four subcomponents: an SRAM\n",
139
+ "buffer, an address register, a delta register, and an addder. We can look at each of\n",
140
+ "these components to see the area breakdown of our buffer."
141
+ ]
142
+ },
143
+ {
144
+ "cell_type": "code",
145
+ "execution_count": null,
146
+ "metadata": {},
147
+ "outputs": [],
148
+ "source": [
149
+ "# < DOC_INCLUDE_MARKER > hwcomponents\n",
150
+ "\n",
151
+ "# The model is a hwcomponents_library.SmartBufferSRAM object!\n",
152
+ "from hwcomponents_library import SmartBufferSRAM\n",
153
+ "\n",
154
+ "# Type hint it for our IDE\n",
155
+ "component_model: SmartBufferSRAM = global_buffer.component_model\n",
156
+ "\n",
157
+ "# Inspect the area of each of its subcomponents\n",
158
+ "print(f'Area: {component_model.area:.2e} m^2')\n",
159
+ "print(f'\\tSRAM area: {component_model.sram.area:.2e} m^2')\n",
160
+ "print(f'\\tAdder area: {component_model.adder.area:.2e} m^2')\n",
161
+ "print(f'\\tAddress register area: {component_model.address_reg.area:.2e} m^2')\n",
162
+ "print(f'\\tDelta reg area: {component_model.delta_reg.area:.2e} m^2')"
163
+ ]
164
+ },
165
+ {
166
+ "cell_type": "markdown",
167
+ "metadata": {},
168
+ "source": [
169
+ "Now we'll model the components for a larger design using the `eyeriss_like`\n",
170
+ "architecture."
171
+ ]
172
+ },
173
+ {
174
+ "cell_type": "code",
175
+ "execution_count": null,
176
+ "metadata": {},
177
+ "outputs": [],
178
+ "source": [
179
+ "display(Markdown(f\"\"\"\n",
180
+ "```yaml\n",
181
+ "{open(examples_dir / \"arches\" / \"eyeriss_like.arch.yaml\").read()}\n",
182
+ "```\n",
183
+ "\"\"\"))"
184
+ ]
185
+ },
186
+ {
187
+ "cell_type": "markdown",
188
+ "metadata": {},
189
+ "source": [
190
+ "The top-level specification object has a `calculate_area_energy_latency_leak` method\n",
191
+ "that can be used to calculate the area, energy, latency, and leak power of all\n",
192
+ "components in the design. Additionally, when called from the top-level specification,\n",
193
+ "this method parses expressions in the architecture, letting you express attributes as\n",
194
+ "functions of other attributes."
195
+ ]
196
+ },
197
+ {
198
+ "cell_type": "code",
199
+ "execution_count": null,
200
+ "metadata": {},
201
+ "outputs": [],
202
+ "source": [
203
+ "# < DOC_INCLUDE_MARKER > spec_energy_area\n",
204
+ "\n",
205
+ "# Load the spec and calculate the energy and area of the entire design\n",
206
+ "spec = af.Spec.from_yaml(examples_dir / \"arches\" / \"eyeriss_like.arch.yaml\")\n",
207
+ "spec = spec.calculate_component_area_energy_latency_leak()\n",
208
+ "\n",
209
+ "# Print out the total area and leakage power of the entire design\n",
210
+ "print(f'Total area of the design: {spec.arch.total_area:.2e} m^2')\n",
211
+ "print(f'Area breakdown per component:')\n",
212
+ "for component, area in spec.arch.per_component_total_area.items():\n",
213
+ " print(f'\\t{component}: {area:.2e} m^2')\n",
214
+ "print(f'Total leakage power of the design: {spec.arch.total_leak_power:.2e} W')\n",
215
+ "for component, leak_power in spec.arch.per_component_total_leak_power.items():\n",
216
+ " print(f'\\t{component}: {leak_power:.2e} W')"
217
+ ]
218
+ },
219
+ {
220
+ "cell_type": "markdown",
221
+ "metadata": {},
222
+ "source": [
223
+ "Once the area, energy, latency, and leak power of the architecture are calculated, we can\n",
224
+ "look at any individual component and analyze it like we analyzed the global buffer."
225
+ ]
226
+ },
227
+ {
228
+ "cell_type": "code",
229
+ "execution_count": null,
230
+ "metadata": {},
231
+ "outputs": [],
232
+ "source": [
233
+ "mac = spec.arch.find(\"MAC\")\n",
234
+ "print(f'MAC area: {mac.attributes.area:.2e} m^2')\n",
235
+ "print(f'Total area of all MACs in the architecture: {mac.attributes.total_area:.2e} m^2')\n",
236
+ "print(f'MAC leak power: {mac.attributes.leak_power:.2e} W')\n",
237
+ "print(f'Total leak power of all MACs in the architecture: {mac.attributes.total_leak_power:.2e} W')\n",
238
+ "for action in mac.actions:\n",
239
+ " energy = action.arguments.energy\n",
240
+ " latency = action.arguments.latency\n",
241
+ " print(f'{action.name} energy: {energy:.2e} J, latency {latency:.2e}s')"
242
+ ]
243
+ },
244
+ {
245
+ "cell_type": "markdown",
246
+ "metadata": {},
247
+ "source": [
248
+ "We can also force the design to use a specific model for a component by passing in our\n",
249
+ "own `ComponentModel` object. Here we'll create a custom MAC model that has lower\n",
250
+ "leakage power than the default model.\n",
251
+ "\n",
252
+ "\n",
253
+ "\n",
254
+ "\n",
255
+ "\n",
256
+ "\n",
257
+ "\n",
258
+ "\n",
259
+ "\n",
260
+ "\n"
261
+ ]
262
+ },
263
+ {
264
+ "cell_type": "code",
265
+ "execution_count": null,
266
+ "metadata": {},
267
+ "outputs": [],
268
+ "source": [
269
+ "# Create a hwcomponents model. See the hwcomponents tutorial for ore information on how\n",
270
+ "# to make these!\n",
271
+ "import hwcomponents as hwc\n",
272
+ "\n",
273
+ "class MyMac(hwc.ComponentModel):\n",
274
+ " component_name: str = \"intmac\"\n",
275
+ " priority: float = 0.5\n",
276
+ "\n",
277
+ " def __init__(self):\n",
278
+ " super().__init__(\n",
279
+ " area=5e-8,\n",
280
+ " leak_power=1e-12 # Very low leakage power\n",
281
+ " )\n",
282
+ "\n",
283
+ " @hwc.action\n",
284
+ " def compute(self) -> float:\n",
285
+ " self.logger.info(f'*** Getting compute energy ***')\n",
286
+ " # 1pJ, 1ns\n",
287
+ " return 1e-12, 1e-9\n",
288
+ "\n",
289
+ "# Initialize the spec and make the MAC use our custom model\n",
290
+ "spec = af.Spec.from_yaml(examples_dir / \"arches\" / \"eyeriss_like.arch.yaml\")\n",
291
+ "mac = spec.arch.find(\"MAC\")\n",
292
+ "mac.component_model = MyMac()\n",
293
+ "\n",
294
+ "# Calculate the energy and area of the MAC and print out the results\n",
295
+ "mac = mac.calculate_area_energy_latency_leak()\n",
296
+ "print(f'MAC area: {mac.attributes.area:.2e} m^2')\n",
297
+ "print(f'MAC leak power: {mac.attributes.leak_power:.2e} W')\n",
298
+ "for action in mac.actions:\n",
299
+ " energy = action.arguments.energy\n",
300
+ " latency = action.arguments.latency\n",
301
+ " print(f'{action.name} energy: {energy:.2e} J, latency {latency:.2e}s')\n",
302
+ "\n",
303
+ "# The energy and area log contain logs from the ComponentModel component.\n",
304
+ "print(f\"Log messages: \")\n",
305
+ "for message in mac.component_modeling_log:\n",
306
+ " print(f\"\\t{message}\")"
307
+ ]
308
+ },
309
+ {
310
+ "cell_type": "markdown",
311
+ "metadata": {},
312
+ "source": [
313
+ "The `hwcomponents` library has plenty of other component models to use! These can be\n",
314
+ "listed with the `hwcomponents.get_models` function.\n",
315
+ "\n",
316
+ "If you're interested in a specific model, use the `help()` function to get more\n",
317
+ "information on it.\n",
318
+ "\n",
319
+ "For more information, see the [hwcomponents\n",
320
+ "documentation](https://accelergy-project.github.io/hwcomponents/)."
321
+ ]
322
+ },
323
+ {
324
+ "cell_type": "code",
325
+ "execution_count": null,
326
+ "metadata": {},
327
+ "outputs": [],
328
+ "source": [
329
+ "import hwcomponents as hwc\n",
330
+ "\n",
331
+ "for model in hwc.get_models()[:5]:\n",
332
+ " print(f\"{model} supports {model.component_name}\")\n",
333
+ " for action in model.get_action_names():\n",
334
+ " print(f'\\t{action}')\n",
335
+ "\n",
336
+ "\n",
337
+ "from hwcomponents_adc import ADC\n",
338
+ "help(ADC)"
339
+ ]
340
+ }
341
+ ],
342
+ "metadata": {
343
+ "kernelspec": {
344
+ "display_name": "Python 3",
345
+ "language": "python",
346
+ "name": "python3"
347
+ },
348
+ "language_info": {
349
+ "codemirror_mode": {
350
+ "name": "ipython",
351
+ "version": 3
352
+ },
353
+ "file_extension": ".py",
354
+ "mimetype": "text/x-python",
355
+ "name": "python",
356
+ "nbconvert_exporter": "python",
357
+ "pygments_lexer": "ipython3",
358
+ "version": "3.12.11"
359
+ }
360
+ },
361
+ "nbformat": 4,
362
+ "nbformat_minor": 2
363
+ }
tests/Q_mapping.yaml ADDED
@@ -0,0 +1,38 @@
1
+ # d=4, all others = 2
2
+ # - name: Q
3
+ # tensor_accesses:
4
+ # - {name: I, projection: [ b, m, d ]}
5
+ # - {name: WQ, projection: [ h, e, d ]}
6
+ # - {name: Q, projection: [ b, m, h, e ], output: True}
7
+
8
+ mapping:
9
+ nodes:
10
+ - !Storage
11
+ tensors: [I, WQ, Q]
12
+ component: MainMemory
13
+ - !Temporal
14
+ rank_variable: b
15
+ tile_shape: 1
16
+ - !Temporal
17
+ rank_variable: h
18
+ tile_shape: 1
19
+ - !Temporal
20
+ rank_variable: e
21
+ tile_shape: 1
22
+ - !Spatial
23
+ rank_variable: d
24
+ tile_shape: 1
25
+ name: 0
26
+ component: LocalBuffer
27
+ - !Storage
28
+ tensors: [Q]
29
+ component: LocalBuffer
30
+ - !Temporal
31
+ rank_variable: m
32
+ tile_shape: 1
33
+ - !Storage
34
+ tensors: [I]
35
+ component: LocalBuffer
36
+ - !Compute
37
+ einsum: Q
38
+ compute: MAC
tests/__init__.py ADDED
File without changes
@@ -0,0 +1,27 @@
1
+ mapping:
2
+ nodes:
3
+ - !Storage
4
+ tensors: [I, W, O]
5
+ component: MainMemory
6
+ - !Temporal
7
+ rank_variable: c
8
+ tile_shape: 1
9
+ - !Spatial
10
+ rank_variable: r
11
+ tile_shape: 1
12
+ name: 0
13
+ component: LocalBuffer
14
+ - !Spatial
15
+ rank_variable: m
16
+ tile_shape: 1
17
+ name: 0
18
+ component: LocalBuffer
19
+ - !Storage
20
+ tensors: [I]
21
+ component: LocalBuffer
22
+ - !Temporal
23
+ rank_variable: p
24
+ tile_shape: 1
25
+ - !Compute
26
+ einsum: conv
27
+ compute: MAC
@@ -0,0 +1,13 @@
1
+ workload:
2
+ shape:
3
+ p: 0 <= p < 5
4
+ r: 0 <= r < 3
5
+ m: 0 <= m < 4
6
+ c: 0 <= c < 2
7
+
8
+ einsums:
9
+ - name: conv
10
+ tensor_accesses:
11
+ - {name: I, projection: { C: c, H: p+r }}
12
+ - {name: W, projection: [ m, c, r ]}
13
+ - {name: O, projection: [ m, p ], output: True}
@@ -0,0 +1,43 @@
1
+ mapping:
2
+ nodes:
3
+ - !Storage
4
+ tensors: [I, W, O]
5
+ component: MainMemory
6
+ - !Temporal
7
+ rank_variable: c
8
+ tile_shape: symbol
9
+ - !Spatial
10
+ rank_variable: r
11
+ tile_shape: symbol
12
+ name: X
13
+ component: LocalBuffer
14
+ - !Spatial
15
+ rank_variable: m
16
+ tile_shape: symbol
17
+ name: X
18
+ component: LocalBuffer
19
+ - !Storage
20
+ tensors: [I]
21
+ component: LocalBuffer
22
+ - !Temporal
23
+ rank_variable: m
24
+ tile_shape: symbol
25
+ - !Temporal
26
+ rank_variable: p
27
+ tile_shape: symbol
28
+ - !Temporal
29
+ rank_variable: p
30
+ tile_shape: symbol
31
+ - !Temporal
32
+ rank_variable: p
33
+ tile_shape: 4
34
+ assume_perfect_factor: false
35
+ - !Temporal
36
+ rank_variable: p
37
+ tile_shape: symbol
38
+ - !Temporal
39
+ rank_variable: p
40
+ tile_shape: symbol
41
+ - !Compute
42
+ einsum: conv
43
+ compute: MAC
@@ -0,0 +1,35 @@
1
+ # I: Moves from local buffer to register
2
+ # O1: Stays in local buffer
3
+ # O2: Moves from local buffer to global buffer
4
+ # O3: Moves from global buffer to main memory
5
+ # O4: Moves from local buffer to register
6
+
7
+ mapping:
8
+ nodes:
9
+ - !Storage
10
+ tensors: [O3]
11
+ component: Disk
12
+ - !Storage
13
+ tensors: [O3]
14
+ component: MainMemory
15
+ - !Temporal
16
+ rank_variable: a
17
+ tile_shape: 1
18
+ - !Storage
19
+ tensors: []
20
+ component: GlobalBuffer
21
+ - !Temporal
22
+ rank_variable: b
23
+ tile_shape: 1
24
+ - !Storage
25
+ tensors: [I, O1]
26
+ component: LocalBuffer
27
+ - !Temporal
28
+ rank_variable: c
29
+ tile_shape: 1
30
+ - !Storage
31
+ tensors: [O4]
32
+ component: Register
33
+ - !Compute
34
+ einsum: copy
35
+ compute: MAC
@@ -0,0 +1,15 @@
1
+ workload:
2
+ shape:
3
+ a: 0 <= a < 2
4
+ b: 0 <= b < 2
5
+ c: 0 <= c < 2
6
+
7
+ einsums:
8
+ - name: copy
9
+ is_copy_operation: True
10
+ tensor_accesses:
11
+ - {name: I, projection: [ a, b, c ]}
12
+ - {name: O1, projection: [ a, b, c ], output: True}
13
+ - {name: O2, projection: [ a, b, c ], output: True}
14
+ - {name: O3, projection: [ a, b, c ], output: True}
15
+ - {name: O4, projection: [ a, b, c ], output: True}
File without changes