Skip to main content

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".

Metadata

Release files for pybondmachine 1.1.85

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

Source distribution (sdist)

Source distribution for pybondmachine 1.1.85
File Size Uploaded
pybondmachine-1.1.85.tar.gz 14.3 kB Details

Built distribution (wheel)

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

Total release size: 28.9 kB

Release files / pybondmachine-1.1.85.tar.gz

Download URL pybondmachine-1.1.85.tar.gz
Size 14.3 kB
Tags Source
SHA-256 checksum
How to use checksums
7f7632f92e52f524311b759df2b8816801d4ee6072841a763b322a78b61cd580
BLAKE2b-256 checksum
How to use checksums
807598f710c7ccf889fb0f71ecef68feb1b1433230e4da880ca89f2687781748
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.11

Release files / pybondmachine-1.1.85-py3-none-any.whl

Download URL pybondmachine-1.1.85-py3-none-any.whl
Size 14.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0d4e639d33617689f167e0e415bdeec3589fdaa83a0137d4bb8cbefd9b127e95
BLAKE2b-256 checksum
How to use checksums
4189d709a0221e22a8282b93838d918c48016f3a273c3811c6613ab923740819
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.11

Release history Release notifications | RSS feed

This release

1.1.85 This release

2 release files

1.1.74

2 release files

1.1.73

2 release files

1.1.72

2 release files

1.1.71

2 release files

1.1.70

2 release files

1.1.69

2 release files

1.1.68

2 release files

1.1.67

2 release files

1.1.65

2 release files

1.1.64

2 release files

1.1.63

2 release files

1.1.62

2 release files

1.1.55

2 release files

1.1.54

2 release files

1.1.53

2 release files

1.1.52

2 release files

1.1.51

2 release files

1.1.50

2 release files

1.1.49

2 release files

1.1.48

2 release files

1.1.47

2 release files

1.1.46

2 release files

1.1.45

2 release files

1.1.44

2 release files

1.1.43

2 release files

1.1.42

2 release files

1.1.41

2 release files

1.1.40

2 release files

1.1.39

2 release files

1.1.38

2 release files

1.1.37

2 release files

1.1.36

2 release files

1.1.35

2 release files

1.1.34

2 release files

1.1.33

2 release files

1.1.32

2 release files

1.1.31

2 release files

1.1.30

2 release files

1.1.29

2 release files

1.1.28

2 release files

1.1.27

2 release files

1.1.26

2 release files

1.1.25

2 release files

1.1.24

2 release files

1.1.23

2 release files

1.1.22

2 release files

1.1.21

2 release files

1.1.20

2 release files

1.1.19

2 release files

1.1.18

2 release files

1.1.17

2 release files

1.1.16

2 release files

1.1.15

2 release files

1.1.14

2 release files

1.1.13

2 release files

1.1.12

2 release files

1.1.11

2 release files

1.1.10

2 release files

1.1.9

2 release files

1.1.8

2 release files

1.1.7

2 release files

1.1.6

2 release files

1.1.5

2 release files

1.1.4

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.9

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

1 release file

1.0.2

1 release file

1.0.1

1 release file

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