Skip to content

Instantly share code, notes, and snippets.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import hls4ml
from optparse import OptionParser
import pandas
import matplotlib.pyplot as plt
from matplotlib.ticker import MaxNLocator
from sklearn.metrics import roc_curve, auc, accuracy_score
from sklearn.preprocessing import OneHotEncoder
import numpy as np
import tensorflow as tf
from qkeras.utils import _add_supported_quantized_objects
@thesps
thesps / reduce.cpp
Created March 11, 2021 11:27
PR302-test
#include "ap_fixed.h"
#include <stdlib.h>
#include <iostream>
template<class T>
class Op_add{
public:
T operator()(T a, T b){
return a + b;
@thesps
thesps / environment.yml
Last active May 4, 2022 11:52
Plot power of 2 quantizer from QKeras
name: po2
channels:
- conda-forge
dependencies:
- python=3.7
- tensorflow
- matplotlib
- numpy
- pip
- pip:
def report(proj_dir):
data = {}
data['error'] = False
# Check for C Synthesis errors
if os.path.exists('{}/vivado_hls.log'.format(proj_dir)):
report = open('{}/vivado_hls.log'.format(proj_dir))
lines = np.array(report.readlines())
error = bool(np.sum(np.array(['ERROR' in line for line in lines])))
if error:
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
from hls4ml.model.profiling import weights_keras, activations_keras
from hls4ml.model.hls_model import Input, Dense, Activation
import numpy as np
from sklearn.metrics import accuracy_score
def inc_dir(hlsconfig):
directory = hlsconfig['OutputDir']
directory = directory.split('_')
n = int(directory[-1])
directory = '_'.join(directory[:-1]) + '_' + str(n+1)
@thesps
thesps / blockfactortable.md
Last active December 10, 2018 11:49
Tables of performance, for given block partition factors, for different resource reuse for the MaxPooling PR

fastmachinelearning/hls4ml#117

Input images are 32x32x1, pool size is 2x2x1, giving output images of 16x16x1 (256 pixels). Configurations which give the desired behaviour of II = reuse are in bold.

There is almost a reliable trend for the choice of block partition factor. For reuse <= 16 (only partitioning in the 1st image dimension) using block partition factor of 16 / reuse for both input and output image gives sensible performance. For reuse >= 32, the partition factor for the 1st dimension is set to 1, and now I scan over the factors for the second image dimension. Here sensible performance is obtained with image_dimension / (reuse / 16), or 16 / ((reuse / 16) / 2). So for reuse=128, for example, good performance is obtained with block factor 32 / (128 / 16) = 4 for the 1st dimension, and 16 / (128 / 16) = 2 for the 2nd dimension, or 16 / ((128 / 16) / 2) = 4 for both. Either way the calculation seems to need to change slightly when partitioning also in th