Skip to content

Commit

Permalink
Remove Yield Node (#159)
Browse files Browse the repository at this point in the history
- Improved optimizer, reducing cycles across the board
  • Loading branch information
WorldofKerry authored Oct 5, 2023
1 parent 8f3774d commit ef74de2
Show file tree
Hide file tree
Showing 27 changed files with 473 additions and 488 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
if: ${{ !github.event.pull_request.draft }}
strategy:
matrix:
python-version: ["3.11"]
python-version: ["3.x"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/packaging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.11"]
python-version: ["3.x"]

steps:
- uses: actions/checkout@v3
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.11"]
python-version: ["3.12"]
steps:
- uses: actions/checkout@v3
with:
Expand Down Expand Up @@ -56,7 +56,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.11"]
python-version: ["3.12"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
Expand Down Expand Up @@ -94,7 +94,7 @@ jobs:
matrix:
pytest-args: ["", "-RS", "-FRS", "-F"]
pytest-opti-levels: ["-L 0 1 2 4 8", "-L 16"]
python-version: ["3.9", "3.10", "3.11"]
python-version: ["3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "python2verilog"
version = "0.2.5"
version = "0.2.6"
authors = [{ name = "Kerry Wang", email = "[email protected]" }]
description = "Converts a subset of python generator functions into synthesizable sequential SystemVerilog"
readme = "README.md"
Expand Down
16 changes: 11 additions & 5 deletions python2verilog/api/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from python2verilog import ir
from python2verilog.backend import verilog
from python2verilog.backend.verilog.config import CodegenConfig, TestbenchConfig
from python2verilog.frontend.generator2ir import Generator2Graph
from python2verilog.optimizer.optimizer import OptimizeGraph
from python2verilog.frontend.generator import FromGenerator
from python2verilog.optimizer import IncreaseWorkPerClockCycle
from python2verilog.utils.typed import typed


Expand All @@ -22,12 +22,18 @@ def context_to_codegen(context: ir.Context):
:return: (codegen, ir)
"""
context = copy.deepcopy(context) # context should be changed to frozened
ir_root, context = Generator2Graph(context).results
logging.info("Running %s", FromGenerator.__name__)
ir_root, context = FromGenerator(context).results
logging.debug(
f"context to codegen {ir_root.unique_id} {context.name} -O{context.optimization_level}"
"context to codegen %s %s -O%s",
ir_root.unique_id,
context.name,
context.optimization_level,
)
if context.optimization_level > 0:
OptimizeGraph(ir_root, threshold=context.optimization_level - 1)
logging.info("Running %s", IncreaseWorkPerClockCycle.__name__)
IncreaseWorkPerClockCycle(ir_root, threshold=context.optimization_level - 1)
logging.info("Running %s", verilog.CodeGen.__name__)
return verilog.CodeGen(ir_root, context), ir_root


Expand Down
3 changes: 0 additions & 3 deletions python2verilog/api/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
from python2verilog.api.context import context_to_codegen
from python2verilog.api.modes import Modes
from python2verilog.api.namespace import get_namespace
from python2verilog.backend import verilog
from python2verilog.backend.verilog.config import CodegenConfig, TestbenchConfig
from python2verilog.frontend.generator2ir import Generator2Graph
from python2verilog.optimizer.optimizer import OptimizeGraph
from python2verilog.utils.typed import typed, typed_list


Expand Down
37 changes: 3 additions & 34 deletions python2verilog/backend/verilog/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from typing import Generator, Iterator, cast

from python2verilog.backend.verilog.config import TestbenchConfig
from python2verilog.optimizer.optimizer import backwards_replace
from python2verilog.optimizer import backwards_replace
from python2verilog.utils.lines import Lines

from ... import ir
Expand All @@ -29,10 +29,6 @@ def __init__(self, root: ir.Node, context: ir.Context):
typed(context, ir.Context)
self.context = context
root_case = CaseBuilder(root, context).get_case()
logging.debug(
f"{self.__class__.__name__} "
f"{[case.condition.ver_name for case in root_case.case_items]}" # type: ignore
)

for item in root_case.case_items:
self.context.add_state_weak(
Expand Down Expand Up @@ -316,7 +312,7 @@ def get_testbench(self, config: TestbenchConfig):
:param random_ready: whether or not to have random ready signal in the while loop
"""
logging.debug(f"{config}")
logging.debug("%s", config)
if len(self.context.input_vars) == 0:
raise RuntimeError(
f"Input var names not deduced for {self.context.name}, "
Expand Down Expand Up @@ -548,7 +544,7 @@ def new_caseitem(self, root: ir.Node):
Creates a new case item with the root's unique id as identifier
"""
stmts = self.do_vertex(root)
logging.debug(f"new caseitem {root.unique_id}")
logging.debug("new caseitem %s", root.unique_id)
item = ver.CaseItem(condition=ir.State(root.unique_id), statements=stmts)

return item
Expand Down Expand Up @@ -582,33 +578,6 @@ def do_vertex(self, vertex: ir.Node):
)
)

elif isinstance(vertex, ir.YieldNode):
outputs: list[ver.Statement] = []
outputs += [
ver.NonBlockingSubsitution(var, expr)
for var, expr in zip(self.context.output_vars, vertex.stmts)
]
outputs += [
ver.NonBlockingSubsitution(self.context.signals.valid, ir.UInt(1))
]
state_change: list[ver.Statement] = []

if isinstance(vertex.optimal_child.optimal_child, ir.DoneNode):
outputs.append(self.create_quick_done(self.context))

state_change.append(
ver.NonBlockingSubsitution(
self.context.state_var,
ir.State(vertex.optimal_child.optimal_child.unique_id),
)
)
if vertex.optimal_child.optimal_child.unique_id not in self.visited:
self.case.case_items.append(
self.new_caseitem(vertex.optimal_child.optimal_child)
)

stmts += outputs + state_change

else:
raise TypeError(type(vertex))

Expand Down
2 changes: 1 addition & 1 deletion python2verilog/frontend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Python to IR Parsers
"""

from .generator2ir import Generator2Graph
from .generator import FromGenerator
Loading

0 comments on commit ef74de2

Please sign in to comment.