Skip to content

Commit c554cf8

Browse files
Black format
1 parent d03b6e6 commit c554cf8

8 files changed

Lines changed: 166 additions & 106 deletions

File tree

notebooks/tutorials/component_energy_area.ipynb

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,15 @@
2828
"\n",
2929
"examples_dir = Path(\"../../examples\")\n",
3030
"\n",
31-
"display(Markdown(f\"\"\"\n",
31+
"display(\n",
32+
" Markdown(\n",
33+
" f\"\"\"\n",
3234
"```yaml\n",
3335
"{open(examples_dir / \"misc\" / \"component_annotated.yaml\").read()}\n",
3436
"```\n",
35-
"\"\"\"))"
37+
"\"\"\"\n",
38+
" )\n",
39+
")"
3640
]
3741
},
3842
{
@@ -53,6 +57,7 @@
5357
"\n",
5458
"# Create the component from the yaml file\n",
5559
"import accelforge as af\n",
60+
"\n",
5661
"global_buffer = af.arch.Memory.from_yaml(\n",
5762
" examples_dir / \"misc\" / \"component_annotated.yaml\"\n",
5863
")\n",
@@ -68,7 +73,7 @@
6873
"for action in global_buffer.actions:\n",
6974
" energy = action.energy\n",
7075
" latency = action.latency\n",
71-
" print(f'Action {action.name} energy {energy:.2e} J, latency {latency:.2e}s')"
76+
" print(f\"Action {action.name} energy {energy:.2e} J, latency {latency:.2e}s\")"
7277
]
7378
},
7479
{
@@ -127,7 +132,7 @@
127132
"source": [
128133
"# < DOC_INCLUDE_MARKER > hwcomponents\n",
129134
"component_model = global_buffer.component_model\n",
130-
"print(help(component_model)) # Get documentation for the model"
135+
"print(help(component_model)) # Get documentation for the model"
131136
]
132137
},
133138
{
@@ -155,11 +160,11 @@
155160
"component_model: SmartBufferSRAM = global_buffer.component_model\n",
156161
"\n",
157162
"# 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+
"print(f\"Area: {component_model.area:.2e} m^2\")\n",
164+
"print(f\"\\tSRAM area: {component_model.sram.area:.2e} m^2\")\n",
165+
"print(f\"\\tAdder area: {component_model.adder.area:.2e} m^2\")\n",
166+
"print(f\"\\tAddress register area: {component_model.address_reg.area:.2e} m^2\")\n",
167+
"print(f\"\\tDelta reg area: {component_model.delta_reg.area:.2e} m^2\")"
163168
]
164169
},
165170
{
@@ -176,11 +181,15 @@
176181
"metadata": {},
177182
"outputs": [],
178183
"source": [
179-
"display(Markdown(f\"\"\"\n",
184+
"display(\n",
185+
" Markdown(\n",
186+
" f\"\"\"\n",
180187
"```yaml\n",
181188
"{open(examples_dir / \"arches\" / \"eyeriss.yaml\").read()}\n",
182189
"```\n",
183-
"\"\"\"))"
190+
"\"\"\"\n",
191+
" )\n",
192+
")"
184193
]
185194
},
186195
{
@@ -207,13 +216,13 @@
207216
"spec = spec.calculate_component_area_energy_latency_leak()\n",
208217
"\n",
209218
"# 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",
219+
"print(f\"Total area of the design: {spec.arch.total_area:.2e} m^2\")\n",
220+
"print(f\"Area breakdown per component:\")\n",
212221
"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",
222+
" print(f\"\\t{component}: {area:.2e} m^2\")\n",
223+
"print(f\"Total leakage power of the design: {spec.arch.total_leak_power:.2e} W\")\n",
215224
"for component, leak_power in spec.arch.per_component_total_leak_power.items():\n",
216-
" print(f'\\t{component}: {leak_power:.2e} W')"
225+
" print(f\"\\t{component}: {leak_power:.2e} W\")"
217226
]
218227
},
219228
{
@@ -231,12 +240,12 @@
231240
"outputs": [],
232241
"source": [
233242
"mac = spec.arch.find(\"MAC\")\n",
234-
"print(f'MAC area: {mac.area:.2e} m^2')\n",
235-
"print(f'Total area of all MACs in the architecture: {mac.total_area:.2e} m^2')\n",
236-
"print(f'MAC leak power: {mac.leak_power:.2e} W')\n",
237-
"print(f'Total leak power of all MACs in the architecture: {mac.total_leak_power:.2e} W')\n",
243+
"print(f\"MAC area: {mac.area:.2e} m^2\")\n",
244+
"print(f\"Total area of all MACs in the architecture: {mac.total_area:.2e} m^2\")\n",
245+
"print(f\"MAC leak power: {mac.leak_power:.2e} W\")\n",
246+
"print(f\"Total leak power of all MACs in the architecture: {mac.total_leak_power:.2e} W\")\n",
238247
"for action in mac.actions:\n",
239-
" print(f'{action.name} energy: {action.energy:.2e} J, latency {action.latency:.2e}s')"
248+
" print(f\"{action.name} energy: {action.energy:.2e} J, latency {action.latency:.2e}s\")"
240249
]
241250
},
242251
{
@@ -268,33 +277,32 @@
268277
"# to make these!\n",
269278
"import hwcomponents as hwc\n",
270279
"\n",
280+
"\n",
271281
"class MyMac(hwc.ComponentModel):\n",
272282
" component_name: str = \"intmac\"\n",
273283
" priority: float = 0.5\n",
274284
"\n",
275285
" def __init__(self):\n",
276-
" super().__init__(\n",
277-
" area=5e-8,\n",
278-
" leak_power=1e-12 # Very low leakage power\n",
279-
" )\n",
286+
" super().__init__(area=5e-8, leak_power=1e-12) # Very low leakage power\n",
280287
"\n",
281288
" @hwc.action\n",
282289
" def compute(self) -> float:\n",
283-
" self.logger.info(f'*** Getting compute energy ***')\n",
290+
" self.logger.info(f\"*** Getting compute energy ***\")\n",
284291
" # 1pJ, 1ns\n",
285292
" return 1e-12, 1e-9\n",
286293
"\n",
294+
"\n",
287295
"# Initialize the spec and make the MAC use our custom model\n",
288296
"spec = af.Spec.from_yaml(examples_dir / \"arches\" / \"eyeriss.yaml\")\n",
289297
"mac = spec.arch.find(\"MAC\")\n",
290298
"mac.component_model = MyMac()\n",
291299
"\n",
292300
"# Calculate the energy and area of the MAC and print out the results\n",
293301
"mac = mac.calculate_area_energy_latency_leak()\n",
294-
"print(f'MAC area: {mac.area:.2e} m^2')\n",
295-
"print(f'MAC leak power: {mac.leak_power:.2e} W')\n",
302+
"print(f\"MAC area: {mac.area:.2e} m^2\")\n",
303+
"print(f\"MAC leak power: {mac.leak_power:.2e} W\")\n",
296304
"for action in mac.actions:\n",
297-
" print(f'{action.name} energy: {action.energy:.2e} J, latency {action.latency:.2e}s')\n",
305+
" print(f\"{action.name} energy: {action.energy:.2e} J, latency {action.latency:.2e}s\")\n",
298306
"\n",
299307
"# The energy and area log contain logs from the ComponentModel component.\n",
300308
"print(f\"Log messages: \")\n",
@@ -327,10 +335,11 @@
327335
"for model in hwc.get_models()[:5]:\n",
328336
" print(f\"{model} supports {model.component_name}\")\n",
329337
" for action in model.get_action_names():\n",
330-
" print(f'\\t{action}')\n",
338+
" print(f\"\\t{action}\")\n",
331339
"\n",
332340
"\n",
333341
"from hwcomponents_adc import ADC\n",
342+
"\n",
334343
"help(ADC)"
335344
]
336345
}

notebooks/tutorials/design_space_exploration.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@
5656
"metadata": {},
5757
"outputs": [],
5858
"source": [
59-
"size_start = 32 * 8 # 32 bytes\n",
60-
"size_end = 4 * 1024 * 1024 * 8 # 4MB\n",
61-
"n_sizes = 32 # Number of sizes to explore\n",
59+
"size_start = 32 * 8 # 32 bytes\n",
60+
"size_end = 4 * 1024 * 1024 * 8 # 4MB\n",
61+
"n_sizes = 32 # Number of sizes to explore\n",
6262
"sizes = [\n",
6363
" size_start * (size_end / size_start) ** (i / (n_sizes - 1)) for i in range(n_sizes)\n",
6464
"]"
@@ -83,8 +83,7 @@
8383
"def get_mapper_result(spec: af.Spec, global_buffer_size: int):\n",
8484
" spec.arch.find(\"GlobalBuffer\").size = global_buffer_size\n",
8585
" return spec.map_workload_to_arch(\n",
86-
" print_progress=False,\n",
87-
" print_number_of_pmappings=False\n",
86+
" print_progress=False, print_number_of_pmappings=False\n",
8887
" )"
8988
]
9089
},
@@ -236,6 +235,7 @@
236235
" spec.arch.find(\"GlobalBuffer\").size = size\n",
237236
" return spec.calculate_component_area_energy_latency_leak()\n",
238237
"\n",
238+
"\n",
239239
"areas = {k: delayed(get_area)(spec, k) for k in sizes}\n",
240240
"areas = parallel(areas, pbar=\"Calculating Area\")\n",
241241
"\n",

notebooks/tutorials/mapper.ipynb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"# memory, you may decrease this number. By default the number of threads is set to the\n",
3939
"# number of cores on your machine.\n",
4040
"import os\n",
41+
"\n",
4142
"af.set_n_parallel_jobs(os.cpu_count(), print_message=True)\n",
4243
"\n",
4344
"# Initialize the spec and show the workload.\n",
@@ -54,7 +55,7 @@
5455
"if not FUSE:\n",
5556
" for node in spec.arch.nodes:\n",
5657
" if isinstance(node, af.arch.Memory):\n",
57-
" print(f'Keeping all tensors in {node.name}')\n",
58+
" print(f\"Keeping all tensors in {node.name}\")\n",
5859
" node.tensors.keep = \"All\"\n",
5960
" break"
6061
]
@@ -133,7 +134,7 @@
133134
"# Commenting this will be slower, but may generate better mappings. Limits the number of\n",
134135
"# fused loops that can exist in a single pmapping.\n",
135136
"spec.mapper.max_fused_loops = 1\n",
136-
"mapping =spec.map_workload_to_arch()\n",
137+
"mapping = spec.map_workload_to_arch()\n",
137138
"\n",
138139
"# Render the mapping with mapping.render(), or in the last line of a notebook:\n",
139140
"mapping"
@@ -155,13 +156,13 @@
155156
"source": [
156157
"# < DOC_INCLUDE_MARKER > mapping_stats\n",
157158
"\n",
158-
"print(f'Energy: {mapping.energy()}J, {mapping.per_compute().energy()}J/compute')\n",
159+
"print(f\"Energy: {mapping.energy()}J, {mapping.per_compute().energy()}J/compute\")\n",
159160
"for k, v in mapping.per_compute().energy(per_component=True).items():\n",
160-
" print(f'\\t{k}: {v}J/compute')\n",
161+
" print(f\"\\t{k}: {v}J/compute\")\n",
161162
"\n",
162-
"print(f'Latency: {mapping.latency()}s, {mapping.per_compute().latency()}s/compute')\n",
163+
"print(f\"Latency: {mapping.latency()}s, {mapping.per_compute().latency()}s/compute\")\n",
163164
"for k, v in mapping.per_compute().latency(per_component=True).items():\n",
164-
" print(f'\\t{k}: {v}s/compute')"
165+
" print(f\"\\t{k}: {v}s/compute\")"
165166
]
166167
}
167168
],

notebooks/tutorials/model.ipynb

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
" \"M\": 64,\n",
4141
" \"KN\": 32,\n",
4242
" \"MainMemoryEnergy\": 10,\n",
43-
" \"GlobalBufferSize\": 1e5\n",
44-
" }\n",
43+
" \"GlobalBufferSize\": 1e5,\n",
44+
" },\n",
4545
")"
4646
]
4747
},
@@ -201,7 +201,13 @@
201201
" af.examples.arches.simple,\n",
202202
" af.examples.workloads.matmuls,\n",
203203
" af.examples.mappings.fused_matmuls_to_simple,\n",
204-
" jinja_parse_data={\"N_EINSUMS\": 2, \"M\": 64, \"KN\": 32, \"MainMemoryEnergy\": 10, \"GlobalBufferSize\": 1e5}\n",
204+
" jinja_parse_data={\n",
205+
" \"N_EINSUMS\": 2,\n",
206+
" \"M\": 64,\n",
207+
" \"KN\": 32,\n",
208+
" \"MainMemoryEnergy\": 10,\n",
209+
" \"GlobalBufferSize\": 1e5,\n",
210+
" },\n",
205211
")\n",
206212
"result = spec.evaluate_mapping()"
207213
]
@@ -312,7 +318,12 @@
312318
"metadata": {},
313319
"outputs": [],
314320
"source": [
315-
"plot_energy_breakdown([result, fused_result], separate_by=[\"component\"], stack_by=[\"tensor\"], labels=[\"Unfused\", \"Fused\"])"
321+
"plot_energy_breakdown(\n",
322+
" [result, fused_result],\n",
323+
" separate_by=[\"component\"],\n",
324+
" stack_by=[\"tensor\"],\n",
325+
" labels=[\"Unfused\", \"Fused\"],\n",
326+
")"
316327
]
317328
}
318329
],

tests/not_working/networks.ipynb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,7 @@
125125
}
126126
],
127127
"source": [
128-
"spec = af.Spec.from_yaml(\n",
129-
" af.examples.arches.networked.hierarchical\n",
130-
")\n",
128+
"spec = af.Spec.from_yaml(af.examples.arches.networked.hierarchical)\n",
131129
"spec.arch"
132130
]
133131
},
@@ -163,9 +161,7 @@
163161
}
164162
],
165163
"source": [
166-
"spec = af.Spec.from_yaml(\n",
167-
" af.examples.arches.networked.flat\n",
168-
")\n",
164+
"spec = af.Spec.from_yaml(af.examples.arches.networked.flat)\n",
169165
"spec.arch"
170166
]
171167
},
@@ -297,9 +293,7 @@
297293
}
298294
],
299295
"source": [
300-
"spec = af.Spec.from_yaml(\n",
301-
" af.examples.arches.networked.rack\n",
302-
")\n",
296+
"spec = af.Spec.from_yaml(af.examples.arches.networked.rack)\n",
303297
"spec.arch"
304298
]
305299
}

0 commit comments

Comments
 (0)