Skip to main content

Framework for functional hardware design approach

Project description

Welcome to PyGears

PyGears is an ambitious attempt to create a Python framework that facilitates describing digital hardware. It aims to augment current RTL methodology to drastically increase composability of hardware modules. Ease of composition leads to better reusability, since modules that compose better can be used in a wider variety of contexts. Set of reusable components can then form a well-tested and documented library that significantly speeds up the development process.

For an introductory PyGears example, checkout echo. A snippet is given below:

def echo(samples: Int, *, fifo_depth, feedback_gain, precision):
    dout = Intf(din.dtype)

    feedback = dout \
        | fifo(depth=fifo_depth, threshold=fifo_depth - 1) \
        | fill_void(fill=Int[16](0)) \
        | decoupler

    feedback_attenuated = (feedback * feedback_gain) >> precision

    dout |= (din + feedback_attenuated) | dout.dtype

    return dout

PyGears proposes a single generic interface for all modules (read about the hardware implementation of the interface here) and provides a way to use powerful features of Python language to compose modules written in an existing HDL (currently only supports SystemVerilog). Based on the Python description, PyGears generates functionally equivalent, synthesizable RTL code.

Furthermore, PyGears offers a way to write verification environment in high-level Python language and co-simulate the generated RTL with an external HDL simulator. PyGears features a completely free solution using Verilator simulator and standard SystemVerilog simulators via the DPI (tested on proprietary Questa and NCSim simulators).

PyGears also features a library of standard modules and the cookbook library that are ready to be used in a PyGears design.

In PyGears, each HDL module is considered a Python function, called the gear, hence the design is described in form of a functional (gear) composition. In order for HDL modules to be composable in this way, they need to be designed in accordance with the Gears methodology. You should probably read a short intro to Gears in order to understand this project from the hardware perspective.

PyGears supports also the hierarchical gears which do not have a HDL implementation, but are defined in terms of other gears. Each gear accepts and returns interface objects as arguments, which represents module connections. This allows for a module composition to be described in terms of powerful functional concepts, such as: partial application, higher-order functions, function polymorphism.

PyGears features a powerful system of generic types, which allows for generic modules to be described, as well as to perform type checking of the gear composition.


  • Kortiq’s AIScale Deep Learning Processor was completely developed using PyGears


Install with pip

PyGears requires Python3, so check if you need to run pip3 instead of pip on your distribution. Also consider using virtualenv or pyenv to manage your Python version.

pip install pygears

Obtain the examples:

git clone
cd pygears/examples

Alternative installation from source

git clone
cd pygears
python3 install

Warning might fail to install the necessary dependencies, so you might additionally need to run:

pip install jinja2

Installing Verilator

If you would like to run cosimulations with the Verilator, you need to make sure that it is available on the PATH. You can install it manually by following these instructions. As an alternative, PyGears offers a script that automatically compiles the latest Verilator. The script was tested on Ubuntu.

sudo apt install autoconf flex bison
pygears_tools_install verilator

The script will create bash file that should be sourced prior to running the cosimulation:

source ~/.pygears/tools/

Checkout examples

Echo: Hardware module that applies echo audio effect to a continuous audio stream.

Read the documentation

PyGears documentation

Checkout the test suite

Tests contain many examples on how individual PyGears components operate. Tests are located in the tests repository folder.


Special thanks to the people that helped develop this framework:

  • Andrea Erdeljan
  • Damjan Rakanović
  • Nemanja Kajtez
  • Risto Pejašinović
  • Stefan Tambur
  • Vladimir Nikić
  • Vladimir Vrbaški

In order to contribute, pull your copy from github repository and create a pull request.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for pygears, version 0.1
Filename, size File type Python version Upload date Hashes
Filename, size pygears-0.1-py3-none-any.whl (181.9 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size pygears-0.1.tar.gz (90.4 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page