Skip to main content

pybondmachine is the Python library designed to streamline the development of FPGA accelerators through the use of the BondMachine framework.

Project description

pybondmachine

pybondmachine is the Python library designed to streamline the development of FPGA accelerators through the use of the BondMachine framework.

With this library you can:

  • (phase 1) Build a firmware starting from python code. You can use the BondMachine framework to create a neural network accelerator, or you can use the library to create a custom accelerator.
  • (phase 2) Interact with the firmware to perform low-latency inference or to use the custom accelerator.

Phase 1

Prerequisites

  • Python 3.6 or higher
  • pip
  • Vivado 2019.1 or higher (if you want to build the firmware)
  • Tensorflow (to train or load a model)
  • BondMachine framework (download it from here)

Install

pip3 install pybondmachine

Usage

imports

from pybondmachine.prjmanager.prjhandler import BMProjectHandler
from pybondmachine.converters.tensorflow2bm import mlp_tf2bm

Load your neural network model (or train it from scratch)

import tensorflow as tf
model = tf.keras.models.load_model(os.getcwd()+"/tests/model.h5")

Convert your neural network model for BondMachine

output_file = "modelBM.json"
output_path = os.getcwd()+"/tests/"

# dump the json input file for neuralbond, the BM module that will be used to build the firmware
mlp_tf2bm(model, output_file=output_file, output_path=output_path)

Create and initialize a BM project with the params you prefer

prjHandler = BMProjectHandler("sample_project", "neuralnetwork", "projects_tests")

prjHandler.check_dependencies()
prjHandler.create_project()

config = {
    "data_type": "float16",
    "register_size": "16",
    "source_neuralbond": output_path+output_file,
    "flavor": "axist",
    "board": "zedboard"
}

prjHandler.setup_project(config)

Build the firmware

prjHandler.build_firmware()

Phase 2

Prerequisites

  • Python 3.6 or higher
  • pip
  • Pynq (if you want to use the custom accelerator)
  • FPGA device

Load the predictor

from pybondmachine.overlay.predictor import Predictor

Set the model specs

model_specs = {
    "data_type": "fps16f6",
    "register_size": 16,
    "batch_size": 128,
    "flavor": "axist",
    "n_input": 4,
    "n_output": 2,
    "benchcore": True,
    "board": "zedboard"
}

Specify firmware name and firmware path

firmware_name = "firmware.bit"
firmware_path = "proj_zedboard_axist_fp16_6_expanded_01/"

Initialize the predictor

predictor = Predictor("firmware.bit", firmware_path, model_specs)

Load the data to be processed

predictor.load_data("proj_zedboard_axist_fp16_6_expanded_01/banknote-authentication_X_test.npy", 
                    "proj_zedboard_axist_fp16_6_expanded_01/banknote-authentication_y_test.npy")

Load the overlay i.e. program the FPGA Remember that it is necessary that you call predictor.load_data before loading the overlay

predictor.load_overlay()

Perform inference

status, predictions = predictor.predict()

Phase 1 details under the hood

This python package is basically a wrapper of the BondMachine helper tool. It allows you to create a project, to build the firmware and to convert a neural network model to a json file that can be used as input for the BondMachine framework. Or, if you prefer, you can use the library to create a custom accelerator. Under the hood, bmhelper create the project, modify all the parameters of the configuration files inside the project and it checks the dependencies. Indeed, you can use bmhelper from CLI if you have installed it. So, to use the python library bmhelper is necessary and you can get it from here: bmhelper under the section "Installation".

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

pybondmachine-1.1.77.tar.gz (12.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pybondmachine-1.1.77-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file pybondmachine-1.1.77.tar.gz.

File metadata

  • Download URL: pybondmachine-1.1.77.tar.gz
  • Upload date:
  • Size: 12.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for pybondmachine-1.1.77.tar.gz
Algorithm Hash digest
SHA256 68edcf6035294f52dc8c16c1f48dd56d60e131dcdff8b96d12502033ab8d7d16
MD5 a71777fababcea1fa68c63e335578c19
BLAKE2b-256 1b1c56d9b6a55953842a938ca417fa6e4d4d31225b75292244f5524bd918fbe4

See more details on using hashes here.

File details

Details for the file pybondmachine-1.1.77-py3-none-any.whl.

File metadata

  • Download URL: pybondmachine-1.1.77-py3-none-any.whl
  • Upload date:
  • Size: 13.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for pybondmachine-1.1.77-py3-none-any.whl
Algorithm Hash digest
SHA256 93ce21942268c234ed018bd03cfbe88d6657fff1cf828a37addf290f837a3fbc
MD5 e20ea39fafd61ea75f7444e0768d602a
BLAKE2b-256 41725d7fef392f0e8b3817c7cfb20ceb2a0658042f9cd964070ca5c21e9ebc40

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page