Skip to content

Commit

Permalink
Quartus Clone Optimizer
Browse files Browse the repository at this point in the history
  • Loading branch information
bo3z committed Jul 26, 2022
1 parent d600882 commit 1b17b3b
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from hls4ml.model.optimizer import OptimizerPass

from hls4ml.model.layers import Layer, register_layer
from hls4ml.backends import get_backend
from hls4ml.backends.template import FunctionCallTemplate

class Clone(Layer):
Expand Down
20 changes: 8 additions & 12 deletions hls4ml/backends/quartus/quartus_backend.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
import numpy as np
import math
import os
import copy
import webbrowser
from calmjs.parse import es5
from calmjs.parse import asttypes
from tabulate import tabulate
from ast import literal_eval
from contextlib import contextmanager

from hls4ml.model.types import NamedType, IntegerPrecisionType, FixedPrecisionType
from hls4ml.model.layers import Embedding, Layer, Dense, BatchNormalization, Activation, ParametrizedActivation, PReLU, Softmax
from hls4ml.model.optimizer import get_backend_passes, layer_optimizer, model_optimizer
from hls4ml.model.layers import Layer, Dense, Activation, Softmax, Embedding
from hls4ml.model.optimizer import get_backend_passes, layer_optimizer
from hls4ml.model.flow import register_flow
from hls4ml.backends import FPGABackend
from hls4ml.report import parse_quartus_report
Expand All @@ -34,6 +26,11 @@ def _register_flows(self):
initializers = self._get_layer_initializers()
init_flow = register_flow('init_layers', initializers, requires=['optimize'], backend=self.name)

streaming_passes = [
'quartus:clone_output'
]
streaming_flow = register_flow('streaming', streaming_passes, requires=[init_flow], backend=self.name)

quartus_types = [
'quartus:transform_types',
]
Expand All @@ -46,7 +43,6 @@ def _register_flows(self):
]
quantization_flow = register_flow('quantization', quantization_passes, requires=[init_flow], backend=self.name)


templates = self._get_layer_templates()
template_flow = register_flow('apply_templates', templates, requires=[init_flow], backend=self.name)

Expand All @@ -69,7 +65,7 @@ def _register_flows(self):
else:
extras_flow = None

ip_flow_requirements = ['optimize', init_flow, quantization_flow, quartus_types_flow, extras_flow, template_flow]
ip_flow_requirements = ['optimize', init_flow, streaming_flow, quantization_flow, quartus_types_flow, extras_flow, template_flow]
ip_flow_requirements = list(filter(None, ip_flow_requirements))

self._default_flow = register_flow('ip', None, requires=ip_flow_requirements, backend=self.name)
Expand Down
4 changes: 0 additions & 4 deletions hls4ml/templates/quartus/firmware/nnet_utils/nnet_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ typedef ac_fixed<16,6> table_default_t;
namespace nnet {

// Common type definitions
<<<<<<< HEAD
enum io_type {io_parallel = 0, io_stream};
=======
enum io_type {io_parallel = 0, io_serial, io_stream};
>>>>>>> ea9eb66a (Quartus Stream Variable Converter & Backend io_stream enabled)

// Default data types (??) TODO: Deprecate
typedef ac_fixed<16,4> weight_t_def;
Expand Down
36 changes: 36 additions & 0 deletions hls4ml/templates/quartus/firmware/nnet_utils/nnet_stream.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#ifndef NNET_STREAM_H
#define NNET_STREAM_H

namespace nnet {

struct broadcast_config {
static const unsigned in_height = 10;
static const unsigned in_width = 10;
static const unsigned n_chan = 1;
static const unsigned n_dupl = 2;
};

template<class data_T, class res_T, int N>
void clone_stream(stream<data_T> &data, stream<res_T> &res1, stream<res_T> &res2) {
CloneLoop:
#pragma ii 1
for (int i = 0; i < N / data_T::size; i++) {
data_T in_data = data.read();
res_T out_data1;
res_T out_data2;

ClonePack:
#pragma unroll
for (int j = 0; j < data_T::size; j++) {
out_data1[j] = in_data[j];
out_data2[j] = in_data[j];
}

res1.write(out_data1);
res2.write(out_data2);
}
}

}

#endif

0 comments on commit 1b17b3b

Please sign in to comment.