Skip to main content

Welcome to PyGears

HW Design: A Functional Approach

PyGears is a free framework that lets you design hardware using high-level Python constructs and compile it to synthesizable SystemVerilog or Verilog code. There is a built-in simulator that lets you use arbitrary Python code with its vast set of libraries to verify your hardware modules. PyGears makes connecting modules easy, and has built-in synchronization mechanisms that help you build correct parallel systems.

@gear
def echo(samples: Fixp, *, feedback_gain, sample_rate, delay):

    sample_dly_len = round(sample_rate * delay)
    fifo_depth = ceil_pow2(sample_dly_len)
    feedback_gain_fixp = samples.dtype(feedback_gain)

    dout = Intf(samples.dtype)

    feedback = decouple(dout, depth=fifo_depth) \
        | prefill(dtype=samples.dtype, num=sample_dly_len)

    feedback_attenuated = (feedback * feedback_gain_fixp) \
        | samples.dtype

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

    return dout

Python functions model hardware modules, where function arguments represent module inputs and parameters. Example echo module has a single input port called samples where data of arbitrary signed fixed-point type Fixp can be received. Other three parameters feedback_gain, sample_rate and delay are compile time parameters.

@gear
def echo(samples: Fixp, *, feedback_gain, sample_rate, delay):
    ...

Arbitrary Python code can be used in modules at compile time, for an example to transform input parameters:

sample_dly_len = round(sample_rate * delay)
fifo_depth = ceil_pow2(sample_dly_len)
feedback_gain_fixp = samples.dtype(feedback_gain)

Rest of the echo function code describes the hardware module for applying echo audio effect to the input stream.

images/echo.png

Modules are instantiated using function calls: decouple(dout, depth=fifo_depth), which return module output interfaces that can in turn be passed as arguments to other module functions in order to make a connection between the modules. For conveniance the pipe "|" operator can be used to pass output of one function as argument to the next one. This was used to connect the output of decouple to prefill ("\" is used just to split the line visually):

feedback = decouple(dout, depth=fifo_depth) \
    | prefill(dtype=samples.dtype, num=sample_dly_len)

Again, the echo function returns its output interfaces which is then used to establish the connection with the next module that received the echo output stream:

@gear
def echo(...):
    ...
    return dout

Built-in simulator makes it easy to test and verify the modules while drawing power from the Python vast ecosystem of libraries. For an example, use Python built-in audioop library to read WAV files into an input samples stream for the echo module, and then visualise the input and output waveforms using matplotlib:

images/echo_plot.png

Speedup the simulation by configuring PyGears simulator to use open-source Verilator to simulate hardware modules, or some of the proprietary simulators like Questa, NCSim or Xsim. Implement any part of the system in a standard HDL and debug your design by inspecting the waveforms for an example in open-source wave viewer GTKWave

images/echo_vcd.png

Checkout Echo example description for more in depth information about the echo example.

Installation instructions

Install PyGears package with the Python package manager. On Linux distributions, depending on how your Python was installed you might get an error and need to prefix the command with sudo:

pip3 install pygears

For more detailed installation instructions (including how to install additional software) checkout Installation page.

Read the documentation

PyGears documentation

Checkout the examples

Library of standard modules

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

RISC-V processor: PyGears implementation. Checkout also the RISC-V implementation blog series.

Tests: Contain many examples on how individual PyGears components operate

Contributions

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.

Metadata

Release files for pygears 0.3.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pygears 0.3.4
File Size Uploaded Provenance Actions
pygears-0.3.4.tar.gz 296.2 kB Without provenance Details for pygears-0.3.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pygears 0.3.4
File Interpreter ABI Platform Actions
pygears-0.3.4-py3-none-any.whl Python 3 none any Details for pygears-0.3.4-py3-none-any.whl

Total release size: 747.1 kB

Release files / pygears-0.3.4.tar.gz

Download URL pygears-0.3.4.tar.gz
Size 296.2 kB
Tags Source
SHA-256 checksum
How to use checksums
3d893cb69b607c5224f7b03d7599233ca9e5f2785750e69625b4197f60273f3f
BLAKE2b-256 checksum
How to use checksums
7934904e70803364292cf5bf699be098c292892348fabc4c1c9b33344f92908a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/3.10.1 pkginfo/1.8.2 requests/2.27.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.5

Release files / pygears-0.3.4-py3-none-any.whl

Download URL pygears-0.3.4-py3-none-any.whl
Size 450.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
843b6cb201f4336cb4b561bb5c81ea7730a2b5fff357f28a97b37f1b24fe267d
BLAKE2b-256 checksum
How to use checksums
9ecd4209d5d0ef8cbd63b59534cf327b82e12f2b94358bd82ee25b1a3ec56163
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/3.10.1 pkginfo/1.8.2 requests/2.27.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.5

Security for pygears 0.3.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page