|
54 | 54 | " tech_node_throughput,\n", |
55 | 55 | ")\n", |
56 | 56 | "\n", |
| 57 | + "\n", |
57 | 58 | "class TernaryMAC(ComponentModel):\n", |
58 | 59 | " \"\"\"\n", |
59 | 60 | "\n", |
|
74 | 75 | " The technology node in meters.\n", |
75 | 76 | " \"\"\"\n", |
76 | 77 | "\n", |
77 | | - " component_name: str | list[str] = 'TernaryMAC'\n", |
| 78 | + " component_name: str | list[str] = \"TernaryMAC\"\n", |
78 | 79 | " \"\"\" Name of the component. Must be a string or list/tuple of strings. \"\"\"\n", |
79 | 80 | "\n", |
80 | 81 | " priority = 0.3\n", |
|
87 | 88 | " def __init__(self, accum_n_bits: int, tech_node: int):\n", |
88 | 89 | " # Provide an area and leakage power for the component. All units are in\n", |
89 | 90 | " # standard units without any prefixes (Joules, Watts, meters, etc.).\n", |
90 | | - " super().__init__(\n", |
91 | | - " area=5e-12 * accum_n_bits,\n", |
92 | | - " leak_power=1e-3 * accum_n_bits\n", |
93 | | - " )\n", |
| 91 | + " super().__init__(area=5e-12 * accum_n_bits, leak_power=1e-3 * accum_n_bits)\n", |
94 | 92 | "\n", |
95 | 93 | " # Scale tech_node to the target from the 40nm reference.\n", |
96 | 94 | " self.tech_node = self.scale(\n", |
|
105 | 103 | " )\n", |
106 | 104 | " self.accum_n_bits = accum_n_bits\n", |
107 | 105 | "\n", |
108 | | - " assert 4 <= accum_n_bits <= 8, \\\n", |
109 | | - " f'Accumulation number of bits {accum_n_bits} outside supported range [4, 8]'\n", |
| 106 | + " assert (\n", |
| 107 | + " 4 <= accum_n_bits <= 8\n", |
| 108 | + " ), f\"Accumulation number of bits {accum_n_bits} outside supported range [4, 8]\"\n", |
110 | 109 | "\n", |
111 | 110 | " # The action decorator makes this function visible as an action. Return an\n", |
112 | 111 | " # ActionCost; throughput defaults to 1/latency if not given.\n", |
|
125 | 124 | " ActionCost\n", |
126 | 125 | " The cost of this action.\n", |
127 | 126 | " \"\"\"\n", |
128 | | - " self.logger.info(f'TernaryMAC Model is estimating energy for mac_random.')\n", |
| 127 | + " self.logger.info(f\"TernaryMAC Model is estimating energy for mac_random.\")\n", |
129 | 128 | " if clock_gated:\n", |
130 | 129 | " return ActionCost(energy=0.0, throughput=float(\"inf\"), latency=0.0)\n", |
131 | | - " return ActionCost(energy=0.002e-12 * (self.accum_n_bits + 0.25), throughput=float(\"inf\"), latency=0.0)\n", |
| 130 | + " return ActionCost(\n", |
| 131 | + " energy=0.002e-12 * (self.accum_n_bits + 0.25),\n", |
| 132 | + " throughput=float(\"inf\"),\n", |
| 133 | + " latency=0.0,\n", |
| 134 | + " )\n", |
| 135 | + "\n", |
132 | 136 | "\n", |
133 | | - "mac = TernaryMAC(accum_n_bits=8, tech_node=16e-9) # Scale the TernaryMAC to 16nm\n", |
| 137 | + "mac = TernaryMAC(accum_n_bits=8, tech_node=16e-9) # Scale the TernaryMAC to 16nm\n", |
134 | 138 | "cost = mac.mac()\n", |
135 | | - "print(f'TernaryMAC energy is {cost.energy:.2e}J (throughput {cost.throughput:.2e} actions/s). '\n", |
136 | | - " f'Area is {mac.area:.2e}m^2. Leak power is {mac.leak_power:.2e}W')" |
| 139 | + "print(\n", |
| 140 | + " f\"TernaryMAC energy is {cost.energy:.2e}J (throughput {cost.throughput:.2e} actions/s). \"\n", |
| 141 | + " f\"Area is {mac.area:.2e}m^2. Leak power is {mac.leak_power:.2e}W\"\n", |
| 142 | + ")" |
137 | 143 | ] |
138 | 144 | }, |
139 | 145 | { |
|
155 | 161 | "source": [ |
156 | 162 | "# < DOC_INCLUDE_MARKER > scaling_by_number_of_bits\n", |
157 | 163 | "\n", |
| 164 | + "\n", |
158 | 165 | "class LPDDR4(ComponentModel):\n", |
159 | 166 | " \"\"\"LPDDR4 DRAM energy model.\"\"\"\n", |
160 | 167 | "\n", |
|
228 | 235 | "from hwcomponents import ComponentModel, action\n", |
229 | 236 | "import math\n", |
230 | 237 | "\n", |
| 238 | + "\n", |
231 | 239 | "class SmartBufferSRAM(ComponentModel):\n", |
232 | 240 | " \"\"\"\n", |
233 | 241 | " An SRAM with an address generator that sequentially reads addresses in the SRAM.\n", |
|
240 | 248 | " n_rw_ports: The number of read/write ports.\n", |
241 | 249 | " n_banks: The number of banks.\n", |
242 | 250 | " \"\"\"\n", |
| 251 | + "\n", |
243 | 252 | " component_name = [\"smart_buffer_sram\", \"smartbuffer_sram\", \"smartbuffersram\"]\n", |
244 | 253 | " priority = 0.3\n", |
245 | 254 | "\n", |
246 | 255 | " def __init__(\n", |
247 | | - " self,\n", |
248 | | - " tech_node: float,\n", |
249 | | - " width: int,\n", |
250 | | - " depth: int,\n", |
251 | | - " n_rw_ports: int=1,\n", |
252 | | - " n_banks: int=1,\n", |
| 256 | + " self,\n", |
| 257 | + " tech_node: float,\n", |
| 258 | + " width: int,\n", |
| 259 | + " depth: int,\n", |
| 260 | + " n_rw_ports: int = 1,\n", |
| 261 | + " n_banks: int = 1,\n", |
253 | 262 | " ):\n", |
254 | 263 | " self.sram: SRAM = SRAM(\n", |
255 | 264 | " tech_node=tech_node,\n", |
|
268 | 277 | "\n", |
269 | 278 | " # If there are subcomponents, we can omit area and leak_power; their cost\n", |
270 | 279 | " # accumulates from the subcomponents.\n", |
271 | | - " super().__init__(subcomponents=[\n", |
| 280 | + " super().__init__(\n", |
| 281 | + " subcomponents=[\n", |
272 | 282 | " self.sram,\n", |
273 | 283 | " self.address_reg,\n", |
274 | 284 | " self.delta_reg,\n", |
275 | 285 | " self.adder,\n", |
276 | | - " ])\n", |
| 286 | + " ]\n", |
| 287 | + " )\n", |
277 | 288 | "\n", |
278 | 289 | " @action(bits_per_action=\"width\")\n", |
279 | 290 | " def read(self) -> ActionCost:\n", |
|
328 | 339 | "\n", |
329 | 340 | "r = smartbuffer_sram.read(bits_per_action=32)\n", |
330 | 341 | "w = smartbuffer_sram.write(bits_per_action=32)\n", |
331 | | - "print(f'Read energy: {r.energy} J, throughput: {r.throughput} actions/s')\n", |
332 | | - "print(f'Write energy: {w.energy} J, throughput: {w.throughput} actions/s')\n", |
333 | | - "print(f'Area: {smartbuffer_sram.area} m^2')\n", |
334 | | - "print(f'Leak power: {smartbuffer_sram.leak_power} W')" |
| 342 | + "print(f\"Read energy: {r.energy} J, throughput: {r.throughput} actions/s\")\n", |
| 343 | + "print(f\"Write energy: {w.energy} J, throughput: {w.throughput} actions/s\")\n", |
| 344 | + "print(f\"Area: {smartbuffer_sram.area} m^2\")\n", |
| 345 | + "print(f\"Leak power: {smartbuffer_sram.leak_power} W\")" |
335 | 346 | ] |
336 | 347 | } |
337 | 348 | ], |
|
0 commit comments