.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/design_examples/threepointwinograddft.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_threepointwinograddft.py: ======================== Three-point Winograd DFT ======================== .. GENERATED FROM PYTHON SOURCE LINES 8-47 .. code-block:: Python import math import matplotlib.pyplot as plt import networkx as nx from b_asic.architecture import Architecture, Memory, ProcessingElement from b_asic.core_operations import AddSub, Addition, ConstantMultiplication, Subtraction from b_asic.schedule import Schedule from b_asic.sfg import SFG from b_asic.special_operations import Input, Output c30 = -1/2 c31 = -1j * math.sqrt(3)/2 in0 = Input("x0") in1 = Input("x1") in2 = Input("x2") a0 = in1 + in2 a1 = in1 - in2 a2 = in0 + a0 m0 = c30 * a0 m1 = c31 * a1 a3 = a2 + m0 a4 = a3 + m1 a5 = a3 - m1 out0 = Output(a2, "X0") out1 = Output(a4, "X1") out2 = Output(a5, "X2") sfg = SFG( inputs=[in0, in1, in2], outputs=[out0, out1, out2], name="3-point Winograd DFT", ) .. GENERATED FROM PYTHON SOURCE LINES 48-49 The SFG looks like .. GENERATED FROM PYTHON SOURCE LINES 49-51 .. code-block:: Python sfg .. image-sg:: /examples/design_examples/images/sphx_glr_threepointwinograddft_001.png :alt: threepointwinograddft :srcset: /examples/design_examples/images/sphx_glr_threepointwinograddft_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 52-53 Replace Addition and Subtraction with AddSub operations .. GENERATED FROM PYTHON SOURCE LINES 53-56 .. code-block:: Python targets = [op for op in sfg.operations if isinstance(op, (Addition, Subtraction))] sfg = sfg.rewrite(AddSub, targets) .. image-sg:: /examples/design_examples/images/sphx_glr_threepointwinograddft_002.png :alt: threepointwinograddft :srcset: /examples/design_examples/images/sphx_glr_threepointwinograddft_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 57-58 The new SFG looks like .. GENERATED FROM PYTHON SOURCE LINES 58-60 .. code-block:: Python sfg .. image-sg:: /examples/design_examples/images/sphx_glr_threepointwinograddft_003.png :alt: threepointwinograddft :srcset: /examples/design_examples/images/sphx_glr_threepointwinograddft_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 61-62 Set latencies and execution times .. GENERATED FROM PYTHON SOURCE LINES 62-67 .. code-block:: Python sfg.set_latency_of_type(ConstantMultiplication, 2) sfg.set_latency_of_type(AddSub, 1) sfg.set_execution_time_of_type(ConstantMultiplication, 1) sfg.set_execution_time_of_type(AddSub, 1) .. GENERATED FROM PYTHON SOURCE LINES 68-69 Generate initial schedule .. GENERATED FROM PYTHON SOURCE LINES 69-72 .. code-block:: Python schedule = Schedule(sfg, cyclic=True) schedule .. image-sg:: /examples/design_examples/images/sphx_glr_threepointwinograddft_004.svg :alt: threepointwinograddft :srcset: /examples/design_examples/images/sphx_glr_threepointwinograddft_004.svg :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 73-74 Reschedule to only use one AddSub and one ConstantMultiplication per time unit .. GENERATED FROM PYTHON SOURCE LINES 74-104 .. code-block:: Python schedule.set_schedule_time(10) schedule.move_operation('out0', 11) schedule.move_operation('out1', 9) schedule.move_operation('out2', 10) schedule.move_operation('addsub4', 2) schedule.move_operation('addsub3', 3) schedule.move_operation('addsub2', 2) schedule.move_operation('cmul1', 2) schedule.move_operation('cmul0', 2) schedule.move_operation('addsub0', 3) schedule.move_operation('addsub5', 2) schedule.move_operation('addsub1', 2) schedule.move_operation('in1', 1) schedule.move_operation('in2', 2) schedule.move_operation('cmul1', 1) schedule.move_operation('addsub5', 1) schedule.move_operation('addsub3', 6) schedule.move_operation('addsub4', 8) schedule.move_operation('cmul1', 6) schedule.move_operation('addsub2', 5) schedule.set_schedule_time(6) schedule.move_operation('addsub0', 1) schedule.move_operation('addsub3', -1) schedule.move_operation('cmul1', -2) schedule.move_operation('addsub3', -1) schedule.move_operation('addsub0', -1) schedule.move_operation('addsub2', -1) schedule.move_operation('addsub4', -4) schedule .. image-sg:: /examples/design_examples/images/sphx_glr_threepointwinograddft_005.svg :alt: threepointwinograddft :srcset: /examples/design_examples/images/sphx_glr_threepointwinograddft_005.svg :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 105-106 Extract memory variables and operation executions .. GENERATED FROM PYTHON SOURCE LINES 106-140 .. 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") 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") 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") mem_vars_set = mem_vars.split_on_ports(read_ports=1, write_ports=1, total_ports=2) direct.show(title="Direct interconnects") fig, ax = plt.subplots() fig.suptitle('Exclusion graph based on ports') nx.draw(mem_vars.exclusion_graph_from_ports(1, 1, 2), ax=ax) 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}") .. image-sg:: /examples/design_examples/images/sphx_glr_threepointwinograddft_006.svg :alt: threepointwinograddft :srcset: /examples/design_examples/images/sphx_glr_threepointwinograddft_006.svg :class: sphx-glr-single-img .. rst-class:: sphx-glr-horizontal * .. image-sg:: /examples/design_examples/images/sphx_glr_threepointwinograddft_007.png :alt: AddSub executions :srcset: /examples/design_examples/images/sphx_glr_threepointwinograddft_007.png :class: sphx-glr-multi-img * .. image-sg:: /examples/design_examples/images/sphx_glr_threepointwinograddft_008.png :alt: Multiplier executions :srcset: /examples/design_examples/images/sphx_glr_threepointwinograddft_008.png :class: sphx-glr-multi-img * .. image-sg:: /examples/design_examples/images/sphx_glr_threepointwinograddft_009.png :alt: Input executions :srcset: /examples/design_examples/images/sphx_glr_threepointwinograddft_009.png :class: sphx-glr-multi-img * .. image-sg:: /examples/design_examples/images/sphx_glr_threepointwinograddft_010.png :alt: Output executions :srcset: /examples/design_examples/images/sphx_glr_threepointwinograddft_010.png :class: sphx-glr-multi-img * .. image-sg:: /examples/design_examples/images/sphx_glr_threepointwinograddft_011.png :alt: All memory variables :srcset: /examples/design_examples/images/sphx_glr_threepointwinograddft_011.png :class: sphx-glr-multi-img * .. image-sg:: /examples/design_examples/images/sphx_glr_threepointwinograddft_012.png :alt: Non-zero time memory variables :srcset: /examples/design_examples/images/sphx_glr_threepointwinograddft_012.png :class: sphx-glr-multi-img * .. image-sg:: /examples/design_examples/images/sphx_glr_threepointwinograddft_013.png :alt: Direct interconnects :srcset: /examples/design_examples/images/sphx_glr_threepointwinograddft_013.png :class: sphx-glr-multi-img * .. image-sg:: /examples/design_examples/images/sphx_glr_threepointwinograddft_014.png :alt: Exclusion graph based on ports :srcset: /examples/design_examples/images/sphx_glr_threepointwinograddft_014.png :class: sphx-glr-multi-img * .. image-sg:: /examples/design_examples/images/sphx_glr_threepointwinograddft_015.png :alt: memory0 variables :srcset: /examples/design_examples/images/sphx_glr_threepointwinograddft_015.png :class: sphx-glr-multi-img * .. image-sg:: /examples/design_examples/images/sphx_glr_threepointwinograddft_016.png :alt: Assigned memory0 :srcset: /examples/design_examples/images/sphx_glr_threepointwinograddft_016.png :class: sphx-glr-multi-img * .. image-sg:: /examples/design_examples/images/sphx_glr_threepointwinograddft_017.png :alt: memory1 variables :srcset: /examples/design_examples/images/sphx_glr_threepointwinograddft_017.png :class: sphx-glr-multi-img * .. image-sg:: /examples/design_examples/images/sphx_glr_threepointwinograddft_018.png :alt: Assigned memory1 :srcset: /examples/design_examples/images/sphx_glr_threepointwinograddft_018.png :class: sphx-glr-multi-img * .. image-sg:: /examples/design_examples/images/sphx_glr_threepointwinograddft_019.png :alt: memory2 variables :srcset: /examples/design_examples/images/sphx_glr_threepointwinograddft_019.png :class: sphx-glr-multi-img * .. image-sg:: /examples/design_examples/images/sphx_glr_threepointwinograddft_020.png :alt: Assigned memory2 :srcset: /examples/design_examples/images/sphx_glr_threepointwinograddft_020.png :class: sphx-glr-multi-img .. GENERATED FROM PYTHON SOURCE LINES 141-142 Create architecture .. GENERATED FROM PYTHON SOURCE LINES 142-148 .. code-block:: Python arch = Architecture( {addsub, multiplier, pe_in, pe_out}, memories, direct_interconnects=direct ) arch .. image-sg:: /examples/design_examples/images/sphx_glr_threepointwinograddft_021.png :alt: threepointwinograddft :srcset: /examples/design_examples/images/sphx_glr_threepointwinograddft_021.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 149-150 Move memory variables to reduce the size of memory1 .. GENERATED FROM PYTHON SOURCE LINES 150-158 .. code-block:: Python arch.move_process('addsub1.0', memories[2], memories[1]) arch.move_process('addsub3.0', memories[1], memories[2], assign=True) memories[1].assign() memories[1].show_content(title="Assigned memory1") memories[2].show_content(title="Assigned memory2") arch .. image-sg:: /examples/design_examples/images/sphx_glr_threepointwinograddft_022.png :alt: threepointwinograddft :srcset: /examples/design_examples/images/sphx_glr_threepointwinograddft_022.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-horizontal * .. image-sg:: /examples/design_examples/images/sphx_glr_threepointwinograddft_023.png :alt: Assigned memory1 :srcset: /examples/design_examples/images/sphx_glr_threepointwinograddft_023.png :class: sphx-glr-multi-img * .. image-sg:: /examples/design_examples/images/sphx_glr_threepointwinograddft_024.png :alt: Assigned memory2 :srcset: /examples/design_examples/images/sphx_glr_threepointwinograddft_024.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.721 seconds) .. _sphx_glr_download_examples_design_examples_threepointwinograddft.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: threepointwinograddft.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: threepointwinograddft.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: threepointwinograddft.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_