Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,21 @@ set_app_option
set_app_option --name router.flat_routing --value true
set_app_option --name place.place_algorithm --value bounding_box

.. _reset_app_option:

reset_app_option
~~~~~~~~~~~~~~~~

Give an application option its default value back, with the same effect on the stages as :ref:`set_app_option <set_app_option>` has when the value changes. It is the way to take away an option whose default is empty, e.g., a file, as ``set_app_option`` cannot be given an empty value.

.. option:: --name <string>

Name of the option, e.g., ``filename.sdc_file``

.. code-block::

reset_app_option --name filename.sdc_file

.. _report_app_option:

report_app_option
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The session report commands tell what the flow that is run stage by stage has do

In Python, the ``Session`` class gives the answers as objects, see :ref:`openfpga_python_session`.

The reports read, and never change, the data of the session. The schema of each answer is in ``openfpga_flow/schemas``.
The reports read, and never change, the data of the session. ``report_run`` needs the inputs to be read (the stage ``DEVICE``), and names the commands to run first when they are not. The schema of each answer is in ``openfpga_flow/schemas``.

report_session
~~~~~~~~~~~~~~
Expand All @@ -20,8 +20,59 @@ report_session

- ``reached``: the stages that are valid, in the order of the flow (``DEVICE``, ``PACKED``, ``PLACED``, ``ROUTED``, ``ANALYZED``, ...). A stage that an option or an input made out of date is not in it. The list is empty when the data of VPR that the session worked with was replaced, e.g., by ``vpr`` or by another shell
- ``inputs``: ``vpr_arch`` (``file`` and ``layout``), ``openfpga_arch`` and ``circuit`` (``file``): where each was read from, as a whole path. ``null`` for an input that is not read
- ``failed``: ``stage`` and ``message`` of the stage (``PACKED``, ``PLACED`` or ``ROUTED``) that failed last and left what it made, e.g., a route that found no legal routing; ``null`` otherwise, and once the stage runs again or is dropped
- ``results``: ``packing``, ``placement`` and ``routing``: the file of the results of a stage that is reached, which is the one that VPR wrote, or the one that ``read_packing``, ``read_placement`` or ``read_routing`` read instead of running the stage. ``null`` for the other stages. The path is whole, from the current directory of the process

.. code-block::

report_session

report_stage
~~~~~~~~~~~~

Answer with what can be changed for each stage of the flow: kind ``stage_info``, from the table of the application options. It is a bounded list, for the question "what can I change after ``place``?". It reads the session only, so it works at any time and needs no data of VPR.

For each stage (``DEVICE``, ``PACKED``, ``PLACED``, ``ROUTED``, ``ANALYZED``, ``REPACKED``, ``BITSTREAM``):

- ``requires``: the stage before it in the flow, and ``commands``: the commands that reach it
- ``reached`` and ``failed`` (the message, if the stage failed and left its data): as in ``report_session``
- ``dropped_by_change``: the stages that are dropped when an option of this stage changes, i.e., this one and the ones that depend on it. The earlier stages are kept
- ``options``: ``total`` (the options of the stage), ``matched`` (by the filters), ``returned``, ``truncated`` and ``items``, which are the entries of ``report_app_option --json`` (name, type, value, default, ``is_default``, help, choices and stage)

.. option:: --stage <string>

Only this stage: its name in any case (``PLACED``), or a command that reaches it (``place``, ``read_routing``). An unknown stage is refused, with the names that exist. Default: all

.. option:: --changed

Only the options that do not have their default value

.. option:: --query <string>

Only the options whose name matches this shell-style pattern, e.g., ``place.*``

.. option:: --limit <int>

Most options to list for each stage. Default: 1000. The list says that it stopped at the limit with ``truncated``, so that the answer cannot grow without bounds

.. code-block::

report_stage --stage place --query "place.*" --limit 20
report_stage --changed

report_run
~~~~~~~~~~

Answer with what each stage of the flow did, in one place: kind ``run_report``, read from the stage ``DEVICE`` (it works as soon as the inputs are read, and the parts of the stages that are not reached are ``null``). It reads the data of VPR, and for what only the log of VPR says, what the stage printed when a command of the session ran it.

- ``stages``: the stages that are reached (``PACKED``, ``PLACED``, ``ROUTED``, ``ANALYZED``) with the ``seconds`` that the command took, ``null`` if the results were read from a file
- ``packing``: the number of ``clusters``, ``atoms`` (the blocks of the circuit) and ``nets``, and the ``blocks`` of each type
- ``placement``: ``half_perimeter``, the sum over the nets of the half perimeter of the box around their blocks, from the data. From the log of the placement: ``cost``, ``bb_cost``, ``td_cost``, the ``estimated_critical_path_delay_ns`` and ``estimated_fmax_mhz`` that the placer ends with, ``num_temperatures`` and ``swap_attempts``
- ``routing``: the ``channel_width``, the ``wirelength`` (the tiles that the wires span, which is what VPR adds up) and the number of ``wires``, from the data. From the log of the routing: ``iterations`` and ``critical_path_delay_ns``
- ``failed``: the stage that failed last, as in ``report_session``

What comes from a log is ``null`` when the stage was not run by a command (e.g., ``read_placement``), and the tests compare each number with the log of VPR, so that a change of the log is noticed.

.. code-block::

report_run
136 changes: 133 additions & 3 deletions docs/source/manual/openfpga_shell/python_session.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ The module is built from the source of OpenFPGA (a checkout with its submodules)

The build uses ``scikit-build-core``, which ``pip`` fetches, and builds only the Python module (not the ``openfpga`` executable, Yosys or the tests). It needs a C++17 compiler, CMake, SWIG, the Python development headers and the Tcl development headers (``tcl-dev`` or ``tcl-devel``, which VPR's SDC parser uses). CMake takes the compiler that is first in the ``PATH``: set ``CC`` and ``CXX`` for another one, e.g., ``CC=gcc-12 CXX=g++-12 pip install .``. The result is ``import openfpga``. The build is kept in ``build/python``, so that the next ``pip install .`` only builds what changed.

``session_quickstart.py`` runs a small design through the four stages in a worker process, and prints the stages reached, the time of each and the files of the results. Its ``--in-process`` option runs a ``Session`` instead, and ``--help`` lists the files that it takes.
``session_quickstart.py`` runs a small design through the four stages in a worker process, and prints the stages reached, the time of each, the critical path delay, the wirelength and the blocks of each type (from ``run_report()``), and the files of the results. Its ``--in-process`` option runs a ``Session`` instead, and ``--help`` lists the files that it takes.

Commands
~~~~~~~~
Expand All @@ -48,10 +48,140 @@ Options

``session.options`` gives the application options (see :ref:`openfpga_basic_commands`). ``options["place.seed"]`` is the value, with the type of the option (``str``, ``int``, ``float`` or ``bool``), and ``options["place.seed"] = 3`` sets it. A ``bool`` is written ``true`` or ``false``, and a path is accepted for a file. ``get(name)`` gives an ``AppOption`` with the ``default``, the ``help``, the ``choices`` of a selection and the ``stage`` that the option changes. ``list()`` and ``changed()`` give all the options, and those that do not have their default value, and ``reset(name)`` gives an option its default. An option that does not exist, or a value that it refuses, raises ``OpenfpgaError``.

What went wrong
~~~~~~~~~~~~~~~

A failure is text in the log of a command. ``OpenfpgaError.diagnostics`` (and ``errors``, which keeps the errors) reads it into ``Diagnostic`` objects, so that a program does not have to:

.. code-block:: python

try:
session.read_vpr_arch("bad.xml", layout="2x2")
except openfpga.OpenfpgaError as error:
found = error.errors[0]
found.kind # 'xml_syntax'
found.file # 'bad.xml'
found.line # 1
found.hint # "Fix the XML of 'bad.xml' at the line that the message gives"

A ``Diagnostic`` has a ``severity`` (``error`` or ``warning``; the errors come first, and at most ten warnings are kept), a ``kind``, the ``message`` as it is in the log, the ``file`` and ``line`` of the user that the message names (``None`` if it names none), the ``source`` (where VPR raised an error, for a report of a bug), a ``hint`` on what to try (``None`` when there is nothing to say), and ``data``, the facts that the message contains. The kinds do not change with the wording of a message:

.. list-table::
:header-rows: 1

* - ``kind``
- Meaning, and its ``data``
* - ``input_not_read``
- An input is missing: ``input``, ``command`` to run
* - ``stage_not_reached``
- The stage that a command needs is not valid: ``stage``, ``command`` to run
* - ``stage_failed``
- The stage that a command needs ran and failed (see :ref:`failed_stages`): ``stage``, ``command`` to run again, ``reason``
* - ``no_vpr_data``
- A report of the results of the flow was asked before any flow
* - ``file_not_found``
- A file cannot be opened; ``file`` is set when the log says which
* - ``xml_syntax``
- An XML file cannot be parsed, with its ``file`` and ``line``
* - ``option_unknown``, ``option_value_invalid``
- An application option that does not exist, or a value it refuses: ``option``, ``type``, ``reason``
* - ``command_unknown``, ``command_option_missing``
- A command that does not exist, or an option that it requires: ``command`` or ``option``
* - ``layout_not_found``
- The device layout is not in the architecture: ``layout``, ``valid_layouts``
* - ``route_failed``, ``route_unroutable``
- The routing failed; for ``route_unroutable``, ``channel_width`` is the width that did not route
* - ``worker_crashed``, ``worker_timeout``, ``worker_cancelled``, ``worker_not_running``
- Failures of a ``RemoteSession`` worker (``WorkerError.diagnostics``); ``worker_crashed`` has the ``exitcode`` and the ``signal``, and its diagnostics go on with what the worker wrote before it ended
* - ``vpr_<type>``
- An error that VPR gave a type, e.g., ``vpr_architecture_file``, that no rule knows
* - ``error``, ``warning``
- Anything else

A new failure of a known kind needs a rule in ``openfpga_python_diagnostics.py`` and a test with the text that it comes from.

.. _session_constraints:

Constraints and options that change a flow
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The inputs that VPR takes besides the architecture and the circuit are options of the flow, and ``Session`` has a method for each. They return a ``Change``: the ``option``, its value ``before`` and ``after``, and the stages that were reached and are not any more (``dropped``, in the order of the flow). The next command of a stage that was dropped runs with the new value.

.. code-block:: python

session.read_vpr_constraints("floorplan.xml") # Change(option='filename.read_vpr_constraints_file', ..., dropped=['DEVICE', 'PACKED', 'PLACED'])
session.read_sdc("timing.sdc")
session.set_route_chan_width(24)
session.set_option("place.seed", 3) # any option; dropped=['PLACED', 'ROUTED', 'ANALYZED']
session.read_sdc(None) # take the timing constraints away
session.clear_constraints() # the floorplan and the timing constraints

- ``read_vpr_constraints(file)``: the floorplan of VPR (XML), i.e., the atoms of a partition and the regions where they must be packed and placed. ``None`` takes it away
- ``read_sdc(file)``: the timing constraints of VPR, i.e., the clocks and their periods, and the input and output delays. They set what a path requires (the ``data required time`` of the timing reports of VPR). ``None`` takes them away
- ``set_route_chan_width(width)``: route with this channel width instead of looking for the smallest
- ``set_option(name, value)``: any option, as ``options[name] = value``, with its ``Change``

VPR reads these when the device is made, so the options belong to the stage ``DEVICE`` and the whole flow runs again. A file is written as a whole path in the option, and a file that does not exist raises ``FileNotFoundError`` before anything changes. The constraints are not checked until VPR reads them: a constraint that VPR refuses makes the next command fail, with the message of VPR.

The pin constraints of OpenFPGA are not inputs of a stage: they are options of the commands that follow the stages, e.g., ``route_clock_rr_graph`` and ``pcf2place``. Give them with ``session.command("route_clock_rr_graph", pin_constraints_file="pcf.xml")``, which the journal records.

.. _journal_and_replay:

Journal and replay
~~~~~~~~~~~~~~~~~~

``Session(journal="run.journal")`` writes the commands that changed the flow, in the order they ran, in two files of that directory:

- ``replay.py``: a Python script, ``session.options["router.route_chan_width"] = 20``, ``session.command("pack")``, ...
- ``replay.openfpga``: a script of the shell, ``set_app_option --name router.route_chan_width --value 20``, ``pack``, ... It ends with ``exit``, as the shell does not stop at the end of a script, and runs with ``openfpga -f replay.openfpga``

.. code-block:: python

session = openfpga.Session(journal="run.journal")
session.options["router.route_chan_width"] = 20
session.read_vpr_arch("arch.xml", layout="2x2")
...

# Later, in another directory or process, or by hand: python run.journal/replay.py
session = openfpga.Session.replay("run.journal")

What is written:

- the commands that the Session runs: the options, the inputs, the stages, the files of the results that are read (``read_packing``, ...), and any command that is run with ``session.command()``. Files are written as whole paths, so that a replay in another directory reads the same files. The files of the flow are written in the current directory of the replay
- not the commands that only answer (``Session.READ_ONLY_COMMANDS``: ``help``, ``report_session``, ``report_app_option``, ...), nor what is run with ``session.shell``: that is the way to ask, and to run what has no method, without a mark in the journal. A subclass of ``Session`` that adds commands that only answer extends the set: ``READ_ONLY_COMMANDS = Session.READ_ONLY_COMMANDS | {...}``
- a command that failed is a comment, ``# Failed, not replayed: route (...)``, with the reason
- the files are written again when a command ends, so that a run that stops leaves scripts that run. A new Session with the same ``journal`` starts the files again
- ``Session.restore(directory, journal=...)`` writes the commands that restore does: the options, the inputs and the results that are read from the checkpoint

``Session.replay(path)`` takes the directory of the journal or one of its two files, runs the commands of ``replay.openfpga`` (a person can edit it: blank lines and ``#`` comments are skipped) and returns the Session, which goes on from there. The other arguments are those of ``Session``, e.g., ``journal=``, to journal the replay. A command that fails raises ``ReplayError``, with its ``line`` and its ``number``. A ``RemoteSession`` has no journal yet.

.. _failed_stages:

Stages that fail
~~~~~~~~~~~~~~~~

When the packing, the placement or the routing fails (the circuit does not fit the device, the router finds no legal routing), the stage is not reached, and what VPR made until then is kept, so that it can be read to tell why it failed:

.. code-block:: python

session.options["router.route_chan_width"] = 8
try:
session.route()
except openfpga.OpenfpgaError:
pass
session.state().failed # StageFailure(stage='ROUTED', message='Routing failed: ...')

- ``state().failed`` has the ``stage`` and the ``message``. It is ``None`` once the stage is run again, or an option or an input that made it out of date is set
- the results of the stages before it stay: ``state().results`` lists their files, and the commands that read their data work as they did before
- the commands that need the stage that failed, e.g., ``repack`` after a failed route, raise ``OpenfpgaError`` with the diagnostic ``stage_failed``, which has the stage, the reason and the command to run again
- the next command of a stage starts again from fresh data of VPR, and gives the results it gives without the failure. ``checkpoint()`` does not save the stage that failed

A router that cannot reach a pin at all, e.g., with a channel width that is too small for the architecture, stops at once, and its routing has no shared wires: the log of VPR says ``Cannot route from ...``.

State and checkpoints
~~~~~~~~~~~~~~~~~~~~~

``state()`` gives what the flow has done (``SessionState``, from ``report_session``, see :ref:`openfpga_session_report_commands`): the stages that are ``reached``, the ``inputs`` (the files they were read from) and the ``results`` (the files of the packing, the placement and the routing).
``state()`` gives what the flow has done (``SessionState``, from ``report_session``, see :ref:`openfpga_session_report_commands`): the stages that are ``reached``, the ``inputs`` (the files they were read from), the ``results`` (the files of the packing, the placement and the routing) and ``failed``, the stage that failed last and left its data, see :ref:`failed_stages`.

``checkpoint(directory)`` saves the flow, and ``Session.restore(directory)`` makes a session that is at the same point, in this process or in another one:

Expand All @@ -72,7 +202,7 @@ A new checkpoint in the same directory replaces the old one, and the manifest is
Answers
~~~~~~~

A command that answers in JSON (see :ref:`query_answers`) gives its answer to the session as an object (an immutable dataclass) instead of JSON. The fields are the ones of the answer, and ``stage`` tells which stage the answer was read from, for the classes that have it. Values that are not finite are ``None``.
A command that answers in JSON (see :ref:`query_answers`) gives its answer to the session as an object (an immutable dataclass) instead of JSON. The session reports of :ref:`openfpga_session_report_commands` are methods: ``state()`` (``SessionState``, from ``report_session``) , ``run_report()`` (``RunReport``, from ``report_run``) and ``stage_info(stage, changed, query, limit)`` (``StageReport``, from ``report_stage``). The fields are the ones of the answer, and ``stage`` tells which stage the answer was read from, for the classes that have it. Values that are not finite are ``None``.

An answer of another kind, or of a version of its schema that the module does not know, raises ``AnswerError``. A field that an answer gains without a new version is skipped. A command that a plugin adds can answer with a kind of its own: ``openfpga.register_answer_kind(kind, version)`` makes the module read it, and a subclass of ``Session`` reads the answer with ``self._query(command, answer_kind, cls, **options)``.

Expand Down
Loading
Loading