.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/scheduling/memory_constrained_scheduling.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_scheduling_memory_constrained_scheduling.py: ========================================= Memory Constrained Scheduling ========================================= .. GENERATED FROM PYTHON SOURCE LINES 7-19 .. code-block:: Python from b_asic.architecture import Architecture, Memory, ProcessingElement from b_asic.core_operations import ConstantMultiplication from b_asic.fft_operations import R2Butterfly from b_asic.list_schedulers import HybridScheduler from b_asic.schedule import Schedule from b_asic.scheduler import ASAPScheduler from b_asic.sfg_generators import radix_2_dif_fft from b_asic.special_operations import Input, Output sfg = radix_2_dif_fft(points=16) .. GENERATED FROM PYTHON SOURCE LINES 20-21 The SFG is .. GENERATED FROM PYTHON SOURCE LINES 21-23 .. code-block:: Python sfg .. image-sg:: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_001.png :alt: memory constrained scheduling :srcset: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 24-25 Set latencies and execution times. .. GENERATED FROM PYTHON SOURCE LINES 25-35 .. code-block:: Python sfg.set_latency_of_type(R2Butterfly, 3) sfg.set_latency_of_type(ConstantMultiplication, 2) sfg.set_execution_time_of_type(R2Butterfly, 1) sfg.set_execution_time_of_type(ConstantMultiplication, 1) # # %% # Generate an ASAP schedule for reference schedule1 = Schedule(sfg, scheduler=ASAPScheduler()) schedule1 .. image-sg:: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_002.svg :alt: memory constrained scheduling :srcset: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_002.svg :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 36-37 Generate a PE constrained HybridSchedule .. GENERATED FROM PYTHON SOURCE LINES 37-41 .. code-block:: Python resources = {R2Butterfly.type_name(): 1, ConstantMultiplication.type_name(): 1} schedule2 = Schedule(sfg, scheduler=HybridScheduler(resources)) schedule2 .. image-sg:: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_003.svg :alt: memory constrained scheduling :srcset: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_003.svg :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 42-46 .. code-block:: Python direct, mem_vars = schedule2.get_memory_variables().split_on_length() print("Max read ports:", mem_vars.read_ports_bound()) print("Max write ports:", mem_vars.write_ports_bound()) .. rst-class:: sphx-glr-script-out .. code-block:: none Max read ports: 3 Max write ports: 3 .. GENERATED FROM PYTHON SOURCE LINES 47-71 .. code-block:: Python operations = schedule2.get_operations() bfs = operations.get_by_type_name(R2Butterfly.type_name()) bfs.show(title="R2Butterfly executions") const_muls = operations.get_by_type_name(ConstantMultiplication.type_name()) const_muls.show(title="ConstMul executions") inputs = operations.get_by_type_name(Input.type_name()) inputs.show(title="Input executions") outputs = operations.get_by_type_name(Output.type_name()) outputs.show(title="Output executions") bf_pe = ProcessingElement(bfs, entity_name="bf") mul_pe = ProcessingElement(const_muls, entity_name="mul") pe_in = ProcessingElement(inputs, entity_name='input') pe_out = ProcessingElement(outputs, entity_name='output') mem_vars = schedule2.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, strategy="greedy_graph_color" ) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_004.png :alt: R2Butterfly executions :srcset: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_004.png :class: sphx-glr-multi-img * .. image-sg:: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_005.png :alt: ConstMul executions :srcset: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_005.png :class: sphx-glr-multi-img * .. image-sg:: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_006.png :alt: Input executions :srcset: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_006.png :class: sphx-glr-multi-img * .. image-sg:: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_007.png :alt: Output executions :srcset: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_007.png :class: sphx-glr-multi-img * .. image-sg:: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_008.png :alt: All memory variables :srcset: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_008.png :class: sphx-glr-multi-img * .. image-sg:: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_009.png :alt: Non-zero time memory variables :srcset: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_009.png :class: sphx-glr-multi-img .. GENERATED FROM PYTHON SOURCE LINES 72-82 .. code-block:: Python 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}") memory.assign("greedy_graph_color") memory.show_content(title=f"Assigned {memory.entity_name}") direct.show(title="Direct interconnects") .. rst-class:: sphx-glr-horizontal * .. image-sg:: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_010.png :alt: memory0 :srcset: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_010.png :class: sphx-glr-multi-img * .. image-sg:: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_011.png :alt: Assigned memory0 :srcset: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_011.png :class: sphx-glr-multi-img * .. image-sg:: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_012.png :alt: memory1 :srcset: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_012.png :class: sphx-glr-multi-img * .. image-sg:: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_013.png :alt: Assigned memory1 :srcset: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_013.png :class: sphx-glr-multi-img * .. image-sg:: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_014.png :alt: memory2 :srcset: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_014.png :class: sphx-glr-multi-img * .. image-sg:: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_015.png :alt: Assigned memory2 :srcset: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_015.png :class: sphx-glr-multi-img * .. image-sg:: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_016.png :alt: Direct interconnects :srcset: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_016.png :class: sphx-glr-multi-img .. GENERATED FROM PYTHON SOURCE LINES 83-90 .. code-block:: Python arch = Architecture( {bf_pe, mul_pe, pe_in, pe_out}, memories, direct_interconnects=direct, ) arch .. image-sg:: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_017.png :alt: memory constrained scheduling :srcset: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_017.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 91-92 Generate another HybridSchedule but this time constrain the amount of reads and writes to reduce the amount of memories .. GENERATED FROM PYTHON SOURCE LINES 92-101 .. code-block:: Python resources = {R2Butterfly.type_name(): 1, ConstantMultiplication.type_name(): 1} schedule3 = Schedule( sfg, scheduler=HybridScheduler( resources, max_concurrent_reads=2, max_concurrent_writes=2 ), ) schedule3 .. image-sg:: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_018.svg :alt: memory constrained scheduling :srcset: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_018.svg :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 102-106 .. code-block:: Python direct, mem_vars = schedule3.get_memory_variables().split_on_length() print("Max read ports:", mem_vars.read_ports_bound()) print("Max write ports:", mem_vars.write_ports_bound()) .. rst-class:: sphx-glr-script-out .. code-block:: none Max read ports: 2 Max write ports: 2 .. GENERATED FROM PYTHON SOURCE LINES 107-128 .. code-block:: Python operations = schedule3.get_operations() bfs = operations.get_by_type_name(R2Butterfly.type_name()) bfs.show(title="R2Butterfly executions") const_muls = operations.get_by_type_name(ConstantMultiplication.type_name()) const_muls.show(title="ConstMul executions") inputs = operations.get_by_type_name(Input.type_name()) inputs.show(title="Input executions") outputs = operations.get_by_type_name(Output.type_name()) outputs.show(title="Output executions") bf_pe = ProcessingElement(bfs, entity_name="bf") mul_pe = ProcessingElement(const_muls, entity_name="mul") pe_in = ProcessingElement(inputs, entity_name='input') pe_out = ProcessingElement(outputs, entity_name='output') mem_vars.show(title="Non-zero time memory variables") mem_vars_set = mem_vars.split_on_ports( strategy="greedy_graph_color", read_ports=1, write_ports=1, total_ports=2 ) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_019.png :alt: R2Butterfly executions :srcset: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_019.png :class: sphx-glr-multi-img * .. image-sg:: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_020.png :alt: ConstMul executions :srcset: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_020.png :class: sphx-glr-multi-img * .. image-sg:: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_021.png :alt: Input executions :srcset: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_021.png :class: sphx-glr-multi-img * .. image-sg:: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_022.png :alt: Output executions :srcset: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_022.png :class: sphx-glr-multi-img * .. image-sg:: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_023.png :alt: Non-zero time memory variables :srcset: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_023.png :class: sphx-glr-multi-img .. GENERATED FROM PYTHON SOURCE LINES 129-139 .. code-block:: Python 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}") memory.assign("greedy_graph_color") memory.show_content(title=f"Assigned {memory.entity_name}") direct.show(title="Direct interconnects") .. rst-class:: sphx-glr-horizontal * .. image-sg:: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_024.png :alt: memory0 :srcset: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_024.png :class: sphx-glr-multi-img * .. image-sg:: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_025.png :alt: Assigned memory0 :srcset: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_025.png :class: sphx-glr-multi-img * .. image-sg:: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_026.png :alt: memory1 :srcset: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_026.png :class: sphx-glr-multi-img * .. image-sg:: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_027.png :alt: Assigned memory1 :srcset: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_027.png :class: sphx-glr-multi-img * .. image-sg:: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_028.png :alt: Direct interconnects :srcset: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_028.png :class: sphx-glr-multi-img .. GENERATED FROM PYTHON SOURCE LINES 140-146 .. code-block:: Python arch = Architecture( {bf_pe, mul_pe, pe_in, pe_out}, memories, direct_interconnects=direct, ) arch .. image-sg:: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_029.png :alt: memory constrained scheduling :srcset: /examples/scheduling/images/sphx_glr_memory_constrained_scheduling_029.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 8.100 seconds) .. _sphx_glr_download_examples_scheduling_memory_constrained_scheduling.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: memory_constrained_scheduling.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: memory_constrained_scheduling.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: memory_constrained_scheduling.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_