.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/design_examples/matrix_inversion.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_matrix_inversion.py: ================ Matrix Inversion ================ In this example, the process of deriving a time-multiplexed architecture for matrix inversion is demonstrated. .. GENERATED FROM PYTHON SOURCE LINES 11-12 Create a signal-flow-graph (SFG) using a provided generator .. GENERATED FROM PYTHON SOURCE LINES 12-22 .. code-block:: Python from b_asic.sfg_generators.matrix_inversion import ldlt_matrix_inverse sfg = ldlt_matrix_inverse( N=4, mode="mult", pe="addsub", ) .. GENERATED FROM PYTHON SOURCE LINES 23-24 Display the number of operations in the SFG .. GENERATED FROM PYTHON SOURCE LINES 24-27 .. code-block:: Python sfg.operation_counter() .. GENERATED FROM PYTHON SOURCE LINES 28-29 Display the SFG .. GENERATED FROM PYTHON SOURCE LINES 29-32 .. code-block:: Python sfg.display() .. image-sg:: /examples/design_examples/images/sphx_glr_matrix_inversion_001.png :alt: matrix inversion :srcset: /examples/design_examples/images/sphx_glr_matrix_inversion_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 33-36 Schedule the operations from the SFG using a list-based scheduling heuristic Use 1 addsub PE, 1 mul PE, 1 reciprocal PE, 1 negation PE, 1 input port, and 1 output port. .. GENERATED FROM PYTHON SOURCE LINES 36-63 .. code-block:: Python from b_asic.list_schedulers import HybridScheduler from b_asic.schedule import Schedule sfg.set_latency_of_type_name("addsub", 9) sfg.set_latency_of_type_name("mul", 6) sfg.set_latency_of_type_name("rec", 19) sfg.set_latency_of_type_name("neg", 1) sfg.set_execution_time_of_type_name("addsub", 1) sfg.set_execution_time_of_type_name("mul", 1) sfg.set_execution_time_of_type_name("rec", 1) sfg.set_execution_time_of_type_name("neg", 1) resources = { "addsub": 1, "mul": 1, "rec": 1, "neg": 1, "in": 1, "out": 1, } scheduler = HybridScheduler(max_resources=resources) schedule = Schedule(sfg, scheduler=scheduler) schedule .. image-sg:: /examples/design_examples/images/sphx_glr_matrix_inversion_002.svg :alt: matrix inversion :srcset: /examples/design_examples/images/sphx_glr_matrix_inversion_002.svg :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 64-65 Derive an architecture with the minimal amount of PEs, memories, and minimal mux complexity .. GENERATED FROM PYTHON SOURCE LINES 65-84 .. code-block:: Python from b_asic.resource_assigner import assign_processing_elements_and_memories from b_asic.architecture import Architecture # Resource assignment pes, mems, direct = assign_processing_elements_and_memories( schedule, strategy="ilp_min_mux", memory_read_ports=1, memory_write_ports=1, memory_total_ports=2, memory_type="RAM", max_mux_size=4, # set the maximum number of multiplexer inputs ) # Create an architecture arch = Architecture(pes, mems, "matinv", direct) arch .. image-sg:: /examples/design_examples/images/sphx_glr_matrix_inversion_003.png :alt: matrix inversion :srcset: /examples/design_examples/images/sphx_glr_matrix_inversion_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 85-89 Generate VHDL code, targeting single-precision floating-point arithmetic and using AMD Floating-Point IP cores. Some additional options are specified to demonstrate the configurability of the code generation. .. GENERATED FROM PYTHON SOURCE LINES 89-116 .. code-block:: Python from b_asic.code_printer import VhdlPrinter from b_asic.data_type import DataType, NumRepresentation dt = DataType( wl=(8, 23), num_repr=NumRepresentation.FLOATING_POINT, ) printer = VhdlPrinter(dt) printer.print( arch, path="generated", pe_registers = { # only generate 2 pipeline stages, the rest are inside the used IP "addsub": (1, 1), "mul": (1, 1), "rec": (1, 1), }, fp_backend={ # specify backend for each floating-point operation "addsub0": "amd", "mul0": "amd", "rec0": "amd", }, io_registers=True, # add registers to input and output ports pipeline_control=True, # pipeline control signals ) .. rst-class:: sphx-glr-script-out .. code-block:: none /home/runner/work/b-asic/b-asic/galleries/examples/design_examples/matrix_inversion.py:99: UserWarning: pe_registers['mul'] requests 2 register(s) (1 input + 1 output) which is less than the operation latency of 'mul0' (6). printer.print( /home/runner/work/b-asic/b-asic/galleries/examples/design_examples/matrix_inversion.py:99: UserWarning: pe_registers['rec'] requests 2 register(s) (1 input + 1 output) which is less than the operation latency of 'rec0' (19). printer.print( /home/runner/work/b-asic/b-asic/galleries/examples/design_examples/matrix_inversion.py:99: UserWarning: pe_registers['addsub'] requests 2 register(s) (1 input + 1 output) which is less than the operation latency of 'addsub0' (9). printer.print( .. GENERATED FROM PYTHON SOURCE LINES 117-119 The VHDL code has been generated in the "generated" directory, with the PEs containing instantiated AMD Floating-Point IP cores. .. GENERATED FROM PYTHON SOURCE LINES 121-124 Derive another architecture from the same schedule, using register memories with two read ports and one write port. Three total ports allow both reads and the write to occur concurrently. .. GENERATED FROM PYTHON SOURCE LINES 124-137 .. code-block:: Python pes_2r, mems_2r, direct_2r = assign_processing_elements_and_memories( schedule, strategy="ilp_min_mux", memory_read_ports=2, memory_write_ports=1, memory_total_ports=3, memory_type="register", max_mux_size=4, ) arch_2r = Architecture(pes_2r, mems_2r, "matinv_2r", direct_2r) arch_2r .. image-sg:: /examples/design_examples/images/sphx_glr_matrix_inversion_004.png :alt: matrix inversion :srcset: /examples/design_examples/images/sphx_glr_matrix_inversion_004.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.168 seconds) .. _sphx_glr_download_examples_design_examples_matrix_inversion.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: matrix_inversion.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: matrix_inversion.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: matrix_inversion.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_