Skip to content

Remove io_serial #609

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions hls4ml/backends/vivado/passes/transform_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ def transform(self, model, node):
new_var = self.inplace_var_converter.convert(var, io_type)
if io_type == 'io_stream':
new_var = self.stream_var_converter.convert(var)
elif io_type == 'io_serial':
new_var = self.array_var_converter.convert(var, pragma='stream')
elif io_type == 'io_parallel':
if node.name in node.model.inputs:
new_var = self.array_var_converter.convert(var, pragma='reshape')
Expand Down
6 changes: 3 additions & 3 deletions hls4ml/converters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def convert_from_keras_model(model, output_dir='my-hls-test', project_name='mypr
clock_period (int, optional): Clock period of the design.
Defaults to 5.
io_type (str, optional): Type of implementation used. One of
'io_parallel' or 'io_serial'. Defaults to 'io_parallel'.
'io_parallel' or 'io_stream'. Defaults to 'io_parallel'.
hls_config (dict, optional): The HLS config.
kwargs** (dict, optional): Additional parameters that will be used to create the config of the specified backend
Raises:
Expand Down Expand Up @@ -246,7 +246,7 @@ def convert_from_pytorch_model(model, input_shape, output_dir='my-hls-test', pro
clock_period (int, optional): Clock period of the design.
Defaults to 5.
io_type (str, optional): Type of implementation used. One of
'io_parallel' or 'io_serial'. Defaults to 'io_parallel'.
'io_parallel' or 'io_stream'. Defaults to 'io_parallel'.
hls_config (dict, optional): The HLS config.
kwargs** (dict, optional): Additional parameters that will be used to create the config of the specified backend

Expand Down Expand Up @@ -319,7 +319,7 @@ def convert_from_onnx_model(model, output_dir='my-hls-test', project_name='mypro
clock_period (int, optional): Clock period of the design.
Defaults to 5.
io_type (str, optional): Type of implementation used. One of
'io_parallel' or 'io_serial'. Defaults to 'io_parallel'.
'io_parallel' or 'io_stream'. Defaults to 'io_parallel'.
hls_config (dict, optional): The HLS config.
kwargs** (dict, optional): Additional parameters that will be used to create the config of the specified backend

Expand Down
2 changes: 1 addition & 1 deletion hls4ml/templates/quartus/firmware/nnet_utils/nnet_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ typedef ac_fixed<16,6> table_default_t;
namespace nnet {

// Common type definitions
enum io_type {io_parallel = 0, io_serial};
enum io_type {io_parallel = 0, io_stream};

// Default data types (??) TODO: Deprecate
typedef ac_fixed<16,4> weight_t_def;
Expand Down
114 changes: 16 additions & 98 deletions hls4ml/templates/vivado/nnet_utils/nnet_activation.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,9 @@ struct activ_config
template<class data_T, class res_T, typename CONFIG_T>
void linear(data_T data[CONFIG_T::n_in], res_T res[CONFIG_T::n_in])
{
if (CONFIG_T::io_type == io_parallel){
#pragma HLS PIPELINE
}
#pragma HLS PIPELINE

for (int ii=0; ii<CONFIG_T::n_in; ii++) {
if (CONFIG_T::io_type == io_serial){
#pragma HLS PIPELINE
}
res[ii] = data[ii];
}
}
Expand All @@ -68,15 +63,10 @@ void linear(data_T data[CONFIG_T::n_in], res_T res[CONFIG_T::n_in])
template<class data_T, class res_T, typename CONFIG_T>
void relu(data_T data[CONFIG_T::n_in], res_T res[CONFIG_T::n_in])
{
if (CONFIG_T::io_type == io_parallel){
#pragma HLS PIPELINE
}
#pragma HLS PIPELINE

data_T datareg;
for (int ii=0; ii<CONFIG_T::n_in; ii++) {
if (CONFIG_T::io_type == io_serial){
#pragma HLS PIPELINE
}
datareg = data[ii];
if (datareg > 0) res[ii] = datareg;
else res[ii] = 0;
Expand All @@ -86,15 +76,10 @@ void relu(data_T data[CONFIG_T::n_in], res_T res[CONFIG_T::n_in])
template<class data_T, class res_T, int MAX_INT, typename CONFIG_T>
void relu_max(data_T data[CONFIG_T::n_in], res_T res[CONFIG_T::n_in])
{
if (CONFIG_T::io_type == io_parallel){
#pragma HLS PIPELINE
}
#pragma HLS PIPELINE

data_T datareg;
for (int ii=0; ii<CONFIG_T::n_in; ii++) {
if (CONFIG_T::io_type == io_serial){
#pragma HLS PIPELINE
}
datareg = data[ii];
if (datareg < 0) res[ii] = 0;
else if (datareg > MAX_INT) res[ii] = MAX_INT;
Expand Down Expand Up @@ -152,17 +137,12 @@ void sigmoid(data_T data[CONFIG_T::n_in], res_T res[CONFIG_T::n_in])
initialized = true;
}

if (CONFIG_T::io_type == io_parallel){
#pragma HLS PIPELINE
}
#pragma HLS PIPELINE

// Index into the lookup table based on data
int data_round;
int index;
for (int ii=0; ii<CONFIG_T::n_in; ii++) {
if (CONFIG_T::io_type == io_serial){
#pragma HLS PIPELINE
}
data_round = data[ii]*CONFIG_T::table_size/16;
index = data_round + 8*CONFIG_T::table_size/16;
if (index < 0) index = 0;
Expand Down Expand Up @@ -364,10 +344,7 @@ void softmax_legacy(data_T data[CONFIG_T::n_in], res_T res[CONFIG_T::n_in])
initialized = true;
}

if (CONFIG_T::io_type == io_parallel){
// Note: This is going to be a resource hog to run with pipeline, but hey, whatever
#pragma HLS PIPELINE
}
#pragma HLS PIPELINE

// Index into the lookup table based on data for exponentials
typename CONFIG_T::table_t exp_res[CONFIG_T::n_in];// different, independent, fixed point precision
Expand All @@ -381,9 +358,6 @@ void softmax_legacy(data_T data[CONFIG_T::n_in], res_T res[CONFIG_T::n_in])
}

for (int ii=0; ii<CONFIG_T::n_in; ii++) {
if (CONFIG_T::io_type == io_serial) {
#pragma HLS PIPELINE
}
for (int jj=0; jj<CONFIG_T::n_in; jj++) {
if (ii==jj) exp_diff_res = 1;
else {
Expand Down Expand Up @@ -458,17 +432,12 @@ void tanh(data_T data[CONFIG_T::n_in], res_T res[CONFIG_T::n_in])
initialized = true;
}

if (CONFIG_T::io_type == io_parallel){
#pragma HLS PIPELINE
}
#pragma HLS PIPELINE

// Index into the lookup table based on data
int data_round;
int index;
for (int ii=0; ii<CONFIG_T::n_in; ii++) {
if (CONFIG_T::io_type == io_serial){
#pragma HLS PIPELINE
}
data_round = data[ii]*CONFIG_T::table_size/8;
index = data_round + 4*CONFIG_T::table_size/8;
//std::cout << "Input: " << data[ii] << " Round: " << data_round << " Index: " << index << std::endl;
Expand All @@ -484,17 +453,12 @@ void tanh(data_T data[CONFIG_T::n_in], res_T res[CONFIG_T::n_in])
template<class data_T, class res_T, typename CONFIG_T>
void hard_sigmoid(data_T data[CONFIG_T::n_in], res_T res[CONFIG_T::n_in])
{
if (CONFIG_T::io_type == io_parallel){
#pragma HLS PIPELINE
}
#pragma HLS PIPELINE

data_T datareg;
data_T slope = (data_T) 0.2;
data_T shift = (data_T) 0.5;
for (int ii=0; ii<CONFIG_T::n_in; ii++) {
if (CONFIG_T::io_type == io_serial){
#pragma HLS PIPELINE
}
datareg = slope * data[ii] + shift;
if (datareg > 1) datareg = 1;
else if (datareg < 0) datareg = 0;
Expand All @@ -508,15 +472,10 @@ void hard_sigmoid(data_T data[CONFIG_T::n_in], res_T res[CONFIG_T::n_in])
template<class data_T, class res_T, typename CONFIG_T>
void leaky_relu(data_T data[CONFIG_T::n_in], data_T alpha, res_T res[CONFIG_T::n_in])
{
if (CONFIG_T::io_type == io_parallel){
#pragma HLS PIPELINE
}
#pragma HLS PIPELINE

data_T datareg;
for (int ii=0; ii<CONFIG_T::n_in; ii++) {
if (CONFIG_T::io_type == io_serial){
#pragma HLS PIPELINE
}
datareg = data[ii];
if (datareg > 0) res[ii] = datareg;
else res[ii] = alpha * datareg;
Expand All @@ -529,15 +488,10 @@ void leaky_relu(data_T data[CONFIG_T::n_in], data_T alpha, res_T res[CONFIG_T::
template<class data_T, class res_T, typename CONFIG_T>
void thresholded_relu(data_T data[CONFIG_T::n_in], data_T theta, res_T res[CONFIG_T::n_in])
{
if (CONFIG_T::io_type == io_parallel){
#pragma HLS PIPELINE
}
#pragma HLS PIPELINE

data_T datareg;
for (int ii=0; ii<CONFIG_T::n_in; ii++) {
if (CONFIG_T::io_type == io_serial){
#pragma HLS PIPELINE
}
datareg = data[ii];
if (datareg > theta) res[ii] = datareg;
else res[ii] = 0;
Expand Down Expand Up @@ -582,17 +536,12 @@ void softplus(data_T data[CONFIG_T::n_in], res_T res[CONFIG_T::n_in])
initialized = true;
}

if (CONFIG_T::io_type == io_parallel){
#pragma HLS PIPELINE
}
#pragma HLS PIPELINE

// Index into the lookup table based on data
int data_round;
int index;
for (int ii=0; ii<CONFIG_T::n_in; ii++) {
if (CONFIG_T::io_type == io_serial){
#pragma HLS PIPELINE
}
data_round = data[ii]*CONFIG_T::table_size/16;
index = data_round + 8*CONFIG_T::table_size/16;
if (index < 0) index = 0;
Expand Down Expand Up @@ -639,17 +588,12 @@ void softsign(data_T data[CONFIG_T::n_in], res_T res[CONFIG_T::n_in])
initialized = true;
}

if (CONFIG_T::io_type == io_parallel){
#pragma HLS PIPELINE
}
#pragma HLS PIPELINE

// Index into the lookup table based on data
int data_round;
int index;
for (int ii=0; ii<CONFIG_T::n_in; ii++) {
if (CONFIG_T::io_type == io_serial){
#pragma HLS PIPELINE
}
data_round = data[ii]*CONFIG_T::table_size/16;
index = data_round + 8*CONFIG_T::table_size/16;
if (index < 0) index = 0;
Expand Down Expand Up @@ -696,17 +640,12 @@ void elu(data_T data[CONFIG_T::n_in], const res_T alpha, res_T res[CONFIG_T::n_
initialized = true;
}

if (CONFIG_T::io_type == io_parallel){
#pragma HLS PIPELINE
}
#pragma HLS PIPELINE

data_T datareg;
// Index into the lookup table based on data
int index;
for (int ii=0; ii<CONFIG_T::n_in; ii++) {
if (CONFIG_T::io_type == io_serial){
#pragma HLS PIPELINE
}
datareg = data[ii];
if (datareg >= 0) {
res[ii] = datareg;
Expand Down Expand Up @@ -762,17 +701,12 @@ void selu(data_T data[CONFIG_T::n_in], res_T res[CONFIG_T::n_in])
initialized = true;
}

if (CONFIG_T::io_type == io_parallel){
#pragma HLS PIPELINE
}
#pragma HLS PIPELINE

data_T datareg;
// Index into the lookup table based on data
int index;
for (int ii=0; ii<CONFIG_T::n_in; ii++) {
if (CONFIG_T::io_type == io_serial){
#pragma HLS PIPELINE
}
datareg = data[ii];
if (datareg >= 0) {
res[ii] = res_T(1.0507009873554804934193349852946) * datareg;
Expand All @@ -790,15 +724,10 @@ void selu(data_T data[CONFIG_T::n_in], res_T res[CONFIG_T::n_in])
template<class data_T, class res_T, typename CONFIG_T>
void prelu(data_T data[CONFIG_T::n_in], data_T alpha[CONFIG_T::n_in], res_T res[CONFIG_T::n_in])
{
if (CONFIG_T::io_type == io_parallel){
#pragma HLS PIPELINE
}
#pragma HLS PIPELINE

data_T datareg;
for (int ii=0; ii<CONFIG_T::n_in; ii++) {
if (CONFIG_T::io_type == io_serial){
#pragma HLS PIPELINE
}
datareg = data[ii];
if (datareg > 0) res[ii] = datareg;
else res[ii] = alpha[ii] * datareg;
Expand All @@ -811,16 +740,11 @@ void prelu(data_T data[CONFIG_T::n_in], data_T alpha[CONFIG_T::n_in], res_T res
template<class data_T, class res_T, typename CONFIG_T>
void binary_tanh(data_T data[CONFIG_T::n_in], res_T res[CONFIG_T::n_in])
{
if (CONFIG_T::io_type == io_parallel){
#pragma HLS PIPELINE
}
#pragma HLS PIPELINE

data_T datareg;
res_T cache;
for (int ii=0; ii<CONFIG_T::n_in; ii++) {
if (CONFIG_T::io_type == io_serial){
#pragma HLS PIPELINE
}
datareg = data[ii];
if( datareg > 0 ) cache = 1;
else cache = -1;
Expand All @@ -835,17 +759,11 @@ void binary_tanh(data_T data[CONFIG_T::n_in], res_T res[CONFIG_T::n_in])
template<class data_T, class res_T, typename CONFIG_T>
void ternary_tanh(data_T data[CONFIG_T::n_in], res_T res[CONFIG_T::n_in])
{

if (CONFIG_T::io_type == io_parallel){
#pragma HLS PIPELINE
}
#pragma HLS PIPELINE

data_T datareg;
res_T cache;
for (int ii=0; ii<CONFIG_T::n_in; ii++) {
if (CONFIG_T::io_type == io_serial) {
#pragma HLS PIPELINE
}
datareg = 2*data[ii];
if( datareg > 1 ) cache = 1;
else if( datareg > -1 && datareg <= 1) cache=0;
Expand Down
Loading