.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/design_examples/fivepointwinograddft.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_design_examples_fivepointwinograddft.py: ======================= Five-point Winograd DFT ======================= First, define the SFG/block diagram .. GENERATED FROM PYTHON SOURCE LINES 8-64 .. code-block:: Python from math import cos, pi, sin import matplotlib.pyplot as plt import networkx as nx from b_asic.architecture import Architecture, Memory, ProcessingElement from b_asic.core_operations import AddSub, ConstantMultiplication from b_asic.fft_operations import R2Butterfly from b_asic.schedule import Schedule from b_asic.sfg import SFG from b_asic.special_operations import Input, Output u = -2 * pi / 5 c50 = (cos(u) + cos(2 * u)) / 2 - 1 c51 = (cos(u) - cos(2 * u)) / 2 c52 = 1j * (sin(u) + sin(2 * u)) / 2 c53 = 1j * (sin(2 * u)) c54 = 1j * (sin(u) - sin(2 * u)) in0 = Input("x0") in1 = Input("x1") in2 = Input("x2") in3 = Input("x3") in4 = Input("x4") bf0 = R2Butterfly(in1, in3) bf1 = R2Butterfly(in4, in2) bf2 = R2Butterfly(bf0.output(0), bf1.output(0)) a0 = AddSub(True, bf0.output(1), bf1.output(0)) a1 = AddSub(True, bf2.output(0), in0) # Should overload float*OutputPort as well m0 = ConstantMultiplication(c50, bf2.output(0)) m1 = ConstantMultiplication(c51, bf0.output(1)) m2 = c52 * a0 m3 = ConstantMultiplication(c53, bf2.output(1)) m4 = ConstantMultiplication(c54, bf1.output(1)) a2 = AddSub(True, m0, a1) a3 = AddSub(False, m3, m2) a4 = AddSub(True, m3, m4) bf3 = R2Butterfly(a2, m1) bf4 = R2Butterfly(bf3.output(0), a3) bf5 = R2Butterfly(bf3.output(1), a4) out0 = Output(a1, "X0") out1 = Output(bf4.output(0), "X1") out2 = Output(bf4.output(1), "X2") out4 = Output(bf5.output(0), "X4") out3 = Output(bf5.output(1), "X3") sfg = SFG( inputs=[in0, in1, in2, in3, in4], outputs=[out0, out1, out2, out3, out4], name="5-point Winograd DFT", ) .. GENERATED FROM PYTHON SOURCE LINES 65-66 The SFG looks like .. GENERATED FROM PYTHON SOURCE LINES 66-68 .. code-block:: Python sfg .. image-sg:: /examples/design_examples/images/sphx_glr_fivepointwinograddft_001.png :alt: fivepointwinograddft :srcset: /examples/design_examples/images/sphx_glr_fivepointwinograddft_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 69-70 Set latencies and execution times .. GENERATED FROM PYTHON SOURCE LINES 70-77 .. code-block:: Python sfg.set_latency_of_type(ConstantMultiplication, 2) sfg.set_latency_of_type(AddSub, 1) sfg.set_latency_of_type(R2Butterfly, 1) sfg.set_execution_time_of_type(ConstantMultiplication, 1) sfg.set_execution_time_of_type(AddSub, 1) sfg.set_execution_time_of_type(R2Butterfly, 1) .. GENERATED FROM PYTHON SOURCE LINES 78-79 Generate schedule .. GENERATED FROM PYTHON SOURCE LINES 79-82 .. code-block:: Python schedule = Schedule(sfg, cyclic=True) schedule .. image-sg:: /examples/design_examples/images/sphx_glr_fivepointwinograddft_002.svg :alt: fivepointwinograddft :srcset: /examples/design_examples/images/sphx_glr_fivepointwinograddft_002.svg :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 83-85 Reschedule to only use one AddSub, one R2Butterfly, and one ConstantMultiplication per time unit .. GENERATED FROM PYTHON SOURCE LINES 85-137 .. code-block:: Python schedule.set_schedule_time(10) schedule.move_operation("out4", 12) schedule.move_operation("out3", 11) schedule.move_operation("out2", 10) schedule.move_operation("out1", 9) schedule.move_operation("out0", 12) schedule.move_operation("r2bfly3", 10) schedule.move_operation("r2bfly2", 9) schedule.move_operation("r2bfly1", 7) schedule.move_operation("addsub4", 5) schedule.move_operation("addsub2", 5) schedule.move_operation("addsub1", 5) schedule.move_operation("cmul4", 4) schedule.move_operation("cmul2", 4) schedule.move_operation("cmul0", 5) schedule.move_operation("addsub0", 6) schedule.move_operation("cmul1", 6) schedule.move_operation("addsub3", 4) schedule.move_operation("r2bfly0", 4) schedule.move_operation("cmul3", 6) schedule.move_operation("r2bfly5", 4) schedule.move_operation("r2bfly4", 4) schedule.move_operation("in1", 1) schedule.move_operation("in2", 2) schedule.move_operation("in3", 3) schedule.move_operation("in4", 4) schedule.move_operation("r2bfly5", -1) schedule.move_operation("r2bfly3", 1) schedule.move_operation("cmul2", 1) schedule.move_operation("cmul4", 1) schedule.move_operation("r2bfly0", 1) schedule.move_operation("addsub0", -1) schedule.move_operation("cmul1", -3) schedule.move_operation("cmul3", -2) schedule.move_operation("cmul4", -1) schedule.move_operation("addsub4", 1) schedule.move_operation("addsub1", 2) schedule.move_operation("cmul0", 1) schedule.move_operation("r2bfly0", -1) schedule.move_operation("addsub0", -1) schedule.move_operation("r2bfly2", -1) schedule.move_operation("cmul2", -1) schedule.move_operation("cmul4", 1) schedule.move_operation("addsub2", -1) schedule.move_operation("addsub4", -1) schedule.move_operation("addsub1", -1) schedule.move_operation("r2bfly1", -1) schedule.move_operation("r2bfly2", -2) schedule.move_operation("r2bfly3", -1) schedule .. image-sg:: /examples/design_examples/images/sphx_glr_fivepointwinograddft_003.svg :alt: fivepointwinograddft :srcset: /examples/design_examples/images/sphx_glr_fivepointwinograddft_003.svg :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 138-139 Extract memory variables and operation executions .. GENERATED FROM PYTHON SOURCE LINES 139-176 .. code-block:: Python operations = schedule.get_operations() adders = operations.get_by_type_name(AddSub.type_name()) adders.show(title="AddSub executions") mults = operations.get_by_type_name("cmul") mults.show(title="Multiplier executions") butterflies = operations.get_by_type_name(R2Butterfly.type_name()) butterflies.show(title="R2Butterfly executions") inputs = operations.get_by_type_name("in") inputs.show(title="Input executions") outputs = operations.get_by_type_name("out") outputs.show(title="Output executions") addsub = ProcessingElement(adders, entity_name="addsub") butterfly = ProcessingElement(butterflies, entity_name="butterfly") multiplier = ProcessingElement(mults, entity_name="multiplier") pe_in = ProcessingElement(inputs, entity_name="input") pe_out = ProcessingElement(outputs, entity_name="output") mem_vars = schedule.get_memory_variables() mem_vars.show(title="All memory variables") direct, mem_vars = mem_vars.split_on_length() mem_vars.show(title="Non-zero time memory variables") direct.show(title="Direct interconnects") mem_vars_set = mem_vars.split_on_ports(read_ports=1, write_ports=1, total_ports=2) memories = [] for i, mem in enumerate(mem_vars_set): memory = Memory(mem, memory_type="RAM", entity_name=f"memory{i}") memories.append(memory) mem.show(title=f"{memory.entity_name} variables") memory.assign("left_edge") memory.show_content(title=f"Assigned {memory.entity_name}") fig, ax = plt.subplots() fig.suptitle("Exclusion graph based on ports") nx.draw(mem_vars.exclusion_graph_from_ports(1, 1, 2), ax=ax) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /examples/design_examples/images/sphx_glr_fivepointwinograddft_004.png :alt: AddSub executions :srcset: /examples/design_examples/images/sphx_glr_fivepointwinograddft_004.png :class: sphx-glr-multi-img * .. image-sg:: /examples/design_examples/images/sphx_glr_fivepointwinograddft_005.png :alt: Multiplier executions :srcset: /examples/design_examples/images/sphx_glr_fivepointwinograddft_005.png :class: sphx-glr-multi-img * .. image-sg:: /examples/design_examples/images/sphx_glr_fivepointwinograddft_006.png :alt: R2Butterfly executions :srcset: /examples/design_examples/images/sphx_glr_fivepointwinograddft_006.png :class: sphx-glr-multi-img * .. image-sg:: /examples/design_examples/images/sphx_glr_fivepointwinograddft_007.png :alt: Input executions :srcset: /examples/design_examples/images/sphx_glr_fivepointwinograddft_007.png :class: sphx-glr-multi-img * .. image-sg:: /examples/design_examples/images/sphx_glr_fivepointwinograddft_008.png :alt: Output executions :srcset: /examples/design_examples/images/sphx_glr_fivepointwinograddft_008.png :class: sphx-glr-multi-img * .. image-sg:: /examples/design_examples/images/sphx_glr_fivepointwinograddft_009.png :alt: All memory variables :srcset: /examples/design_examples/images/sphx_glr_fivepointwinograddft_009.png :class: sphx-glr-multi-img * .. image-sg:: /examples/design_examples/images/sphx_glr_fivepointwinograddft_010.png :alt: Non-zero time memory variables :srcset: /examples/design_examples/images/sphx_glr_fivepointwinograddft_010.png :class: sphx-glr-multi-img * .. image-sg:: /examples/design_examples/images/sphx_glr_fivepointwinograddft_011.png :alt: Direct interconnects :srcset: /examples/design_examples/images/sphx_glr_fivepointwinograddft_011.png :class: sphx-glr-multi-img * .. image-sg:: /examples/design_examples/images/sphx_glr_fivepointwinograddft_012.png :alt: memory0 variables :srcset: /examples/design_examples/images/sphx_glr_fivepointwinograddft_012.png :class: sphx-glr-multi-img * .. image-sg:: /examples/design_examples/images/sphx_glr_fivepointwinograddft_013.png :alt: Assigned memory0 :srcset: /examples/design_examples/images/sphx_glr_fivepointwinograddft_013.png :class: sphx-glr-multi-img * .. image-sg:: /examples/design_examples/images/sphx_glr_fivepointwinograddft_014.png :alt: memory1 variables :srcset: /examples/design_examples/images/sphx_glr_fivepointwinograddft_014.png :class: sphx-glr-multi-img * .. image-sg:: /examples/design_examples/images/sphx_glr_fivepointwinograddft_015.png :alt: Assigned memory1 :srcset: /examples/design_examples/images/sphx_glr_fivepointwinograddft_015.png :class: sphx-glr-multi-img * .. image-sg:: /examples/design_examples/images/sphx_glr_fivepointwinograddft_016.png :alt: memory2 variables :srcset: /examples/design_examples/images/sphx_glr_fivepointwinograddft_016.png :class: sphx-glr-multi-img * .. image-sg:: /examples/design_examples/images/sphx_glr_fivepointwinograddft_017.png :alt: Assigned memory2 :srcset: /examples/design_examples/images/sphx_glr_fivepointwinograddft_017.png :class: sphx-glr-multi-img * .. image-sg:: /examples/design_examples/images/sphx_glr_fivepointwinograddft_018.png :alt: memory3 variables :srcset: /examples/design_examples/images/sphx_glr_fivepointwinograddft_018.png :class: sphx-glr-multi-img * .. image-sg:: /examples/design_examples/images/sphx_glr_fivepointwinograddft_019.png :alt: Assigned memory3 :srcset: /examples/design_examples/images/sphx_glr_fivepointwinograddft_019.png :class: sphx-glr-multi-img * .. image-sg:: /examples/design_examples/images/sphx_glr_fivepointwinograddft_020.png :alt: memory4 variables :srcset: /examples/design_examples/images/sphx_glr_fivepointwinograddft_020.png :class: sphx-glr-multi-img * .. image-sg:: /examples/design_examples/images/sphx_glr_fivepointwinograddft_021.png :alt: Assigned memory4 :srcset: /examples/design_examples/images/sphx_glr_fivepointwinograddft_021.png :class: sphx-glr-multi-img * .. image-sg:: /examples/design_examples/images/sphx_glr_fivepointwinograddft_022.png :alt: Exclusion graph based on ports :srcset: /examples/design_examples/images/sphx_glr_fivepointwinograddft_022.png :class: sphx-glr-multi-img .. GENERATED FROM PYTHON SOURCE LINES 177-178 Create architecture .. GENERATED FROM PYTHON SOURCE LINES 178-186 .. code-block:: Python arch = Architecture( [addsub, butterfly, multiplier, pe_in, pe_out], memories, direct_interconnects=direct, ) arch .. image-sg:: /examples/design_examples/images/sphx_glr_fivepointwinograddft_023.png :alt: fivepointwinograddft :srcset: /examples/design_examples/images/sphx_glr_fivepointwinograddft_023.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 187-188 Move memory variables to optimize architecture .. GENERATED FROM PYTHON SOURCE LINES 188-196 .. code-block:: Python arch.move_process("addsub2.0", "memory3", "memory2") arch.move_process("r2bfly2.0", "memory2", "memory3") arch.move_process("cmul2.0", "memory1", "memory0") arch.move_process("r2bfly3.0", "memory0", "memory1") arch.move_process("r2bfly3.1", "memory4", "memory0") arch.assign_resources() .. GENERATED FROM PYTHON SOURCE LINES 197-198 Memory 4 is now empty, so remove it. .. GENERATED FROM PYTHON SOURCE LINES 198-205 .. code-block:: Python arch.remove_resource("memory4") for memory in arch.memories: memory.show_content(title=f"Improved {memory.entity_name}") arch .. image-sg:: /examples/design_examples/images/sphx_glr_fivepointwinograddft_024.png :alt: fivepointwinograddft :srcset: /examples/design_examples/images/sphx_glr_fivepointwinograddft_024.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-horizontal * .. image-sg:: /examples/design_examples/images/sphx_glr_fivepointwinograddft_025.png :alt: Improved memory0 :srcset: /examples/design_examples/images/sphx_glr_fivepointwinograddft_025.png :class: sphx-glr-multi-img * .. image-sg:: /examples/design_examples/images/sphx_glr_fivepointwinograddft_026.png :alt: Improved memory1 :srcset: /examples/design_examples/images/sphx_glr_fivepointwinograddft_026.png :class: sphx-glr-multi-img * .. image-sg:: /examples/design_examples/images/sphx_glr_fivepointwinograddft_027.png :alt: Improved memory2 :srcset: /examples/design_examples/images/sphx_glr_fivepointwinograddft_027.png :class: sphx-glr-multi-img * .. image-sg:: /examples/design_examples/images/sphx_glr_fivepointwinograddft_028.png :alt: Improved memory3 :srcset: /examples/design_examples/images/sphx_glr_fivepointwinograddft_028.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 2.705 seconds) .. _sphx_glr_download_examples_design_examples_fivepointwinograddft.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: fivepointwinograddft.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: fivepointwinograddft.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: fivepointwinograddft.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_