GithubHelp home page GithubHelp logo

danielchf2006 / pylog Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hst10/pylog

0.0 0.0 0.0 21.29 MB

PyLog: An Algorithm-Centric FPGA Programming and Synthesis Flow

Shell 0.11% JavaScript 0.48% C++ 35.42% Python 51.37% C 4.18% Tcl 0.03% CSS 0.14% Makefile 0.12% HTML 1.02% Jinja 7.12%

pylog's Introduction

PyLog

PyLog: An Algorithm-Centric FPGA Programming and Synthesis Flow

Test Environment

Getting Started

Setting paths

Before running PyLog, please add the path to your PyLog directory to PYTHONPATH. You can add the following line into your ~/.bashrc file:

export PYTHONPATH=/your/path/to/pylog:$PYTHONPATH

Also, please modify the paths at the beginning the following files:

  • tests/env.py: Modify PyLog path accordingly. env.py is imported by test code under tests (not necessary if you add PyLog path to PYTHONPATH)
  • config.py: Set the following addresses for your host system (used for compilation and synthesis) and target system (used for deployment, i.e., the FPGA system)
    • PYLOG_ROOT_DIR: The path to your local PyLog copy
    • WORKSPACE: Directory for generated Vitis/Vivado project files. By default, it is set to PYLOG_ROOT_DIR + /pylog_projects. If the directory doesn't exist, PyLog will create it. PyLog compilation and synthesis outputs will be written to this directory.
    • HOST_ADDR: (only used in deploy mode) The address of the host system (should be reachable from target system), used only in deploy mode to scp syntehsis results from host.
    • TARGET_ADDR: (only used in deploy mode) The address of the target system. Currently not used.
    • TARGET_BASE: (only used in deploy mode) The path to the workspace directory on the target system. If the directory doesn't exist, PyLog will create it. PyLog compilation outputs will be written to this directory. Bitstreams (*.bit) and hardware handoff files (*.hwh) will be copied to this directory from host system.

PyLog usage

To use PyLog, import pylog and simply add PyLog decorator @pylog to the function that you'd like to synthesize into an FPGA accelerator. Pass NumPy arrays to the decorated function and call the decorated function. Then run the whole Python program. In the following example, vecadd function will be compiled into HLS C code by PyLog.

import numpy as np
from pylog import *

@pylog
def vecadd(a, b, c):
    for i in range(1024):
        c[i] = a[i] + b[i]
    return 0

if __name__ == "__main__":
    length = 1024
    a = np.random.rand(length).astype(np.float32)
    b = np.random.rand(length).astype(np.float32)
    c = np.random.rand(length).astype(np.float32)
    
    vecadd(a, b, c)

You can also pass arguments to @pylog decorator to control the behavior of PyLog. The following arguments can be passed to @pylog:

  • mode: You can pass one of the following strings to control the action of PyLog. By default mode='cgen'.

    • 'cgen' or 'codegen': Generates HLS C code only;
    • 'hwgen': Generates HLS C code and call Vivado HLS and Vivado to generate hardware;
    • 'pysim': Run the code with standard Python interpreter. You need to add from pysim import * in your code to use pysim;
    • 'deploy' or 'run' or 'acc': Run PyLog in deploy mode. This will program FPGA, use PyLog runtime to invoke FPGA and collect results.
  • path: This overwrites the WORKSPACE string in pylog.py.

  • board: The target FPGA board. Currently PyLog support pynq-z2, pynq-z1, zedboard, and ultra96. By default board='pynq-z2'.

Here is one example of configuring PyLog:

@pylog(mode='deploy', board='pynq-z2')

In this example, PyLog will run in deploy mode, targeting PYNQ board (implying the current program is running on a PYNQ board).

Tests

Example PyLog code can be found under tests. To run a test, simply run it as a regular Python script:

python tests/matmul.py

pylog's People

Contributors

hst10 avatar k-wu avatar jeonghm9764 avatar jeffmy05 avatar yuanm2 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.