Skip to content

Commit

Permalink
pre-commit formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
David Burnette committed Apr 18, 2024
1 parent 15cbb59 commit f207eeb
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 278 deletions.
3 changes: 0 additions & 3 deletions hls4ml/templates/catapult/build_prj_bup.tcl

This file was deleted.

246 changes: 0 additions & 246 deletions hls4ml/templates/catapult/build_prj_bup.yml

This file was deleted.

2 changes: 1 addition & 1 deletion hls4ml/templates/catapult/nnet_utils/nnet_conv2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct depthwiseconv2d_config {
static const unsigned filt_height = 1;
static const unsigned filt_width = 1;
static const unsigned kernel_size = filt_height * filt_width;
static const unsigned d_mult = 1;
static const unsigned d_mult = 1;
static const unsigned n_filt = 1;
static const unsigned stride_height = 1;
static const unsigned stride_width = 1;
Expand Down
5 changes: 3 additions & 2 deletions hls4ml/templates/catapult/nnet_utils/nnet_dense_latency.h
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ void dense_latency(data_T data[CONFIG_T::n_in], res_T res[CONFIG_T::n_out],
typename CONFIG_T::bias_t biases[CONFIG_T::n_out]) {
constexpr int ce_reuse_factor = CONFIG_T::reuse_factor;
// Partial unroll config
constexpr int prod1_unroll = (ce_reuse_factor<CONFIG_T::n_in) ? CONFIG_T::n_in : (int)(CONFIG_T::n_in*CONFIG_T::n_out)/ce_reuse_factor;
constexpr int prod2_unroll = (int)CONFIG_T::n_out/ce_reuse_factor;
constexpr int prod1_unroll =
(ce_reuse_factor < CONFIG_T::n_in) ? CONFIG_T::n_in : (int)(CONFIG_T::n_in * CONFIG_T::n_out) / ce_reuse_factor;
constexpr int prod2_unroll = (int)CONFIG_T::n_out / ce_reuse_factor;

(void)ce_reuse_factor; // to silence compiler warnings
(void)prod1_unroll;
Expand Down
13 changes: 6 additions & 7 deletions hls4ml/templates/catapult/nnet_utils/nnet_helpers.h
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -367,15 +367,14 @@ template <class data_T, size_t SIZE> void fill_zero(ac_channel<data_T> &data) {
}

// Fix for CAT-36531
template <class data_T, size_t SIZE> void fill_random(data_T data[SIZE])
{
// std::cout << "Fill_Random SIZE:"<< SIZE << std::endl;
template <class data_T, size_t SIZE> void fill_random(data_T data[SIZE]) {
// std::cout << "Fill_Random SIZE:"<< SIZE << std::endl;
data_T MAX_VALUE;
for (unsigned int i = 0; i < SIZE; i++) {
// Generate a random value (for example, between 0 and 1)
data_T random_value = (data_T)rand() / MAX_VALUE.template set_val<AC_VAL_MIN>();
data[i] = random_value;
}
// Generate a random value (for example, between 0 and 1)
data_T random_value = (data_T)rand() / MAX_VALUE.template set_val<AC_VAL_MIN>();
data[i] = random_value;
}
}

template <class data_T, size_t SIZE> void fill_random(ac_channel<data_T> &data) {
Expand Down
29 changes: 14 additions & 15 deletions hls4ml/templates/catapult/nnet_utils/nnet_sepconv2d_stream.h
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,9 @@ void depthwise_conv_2d_encoded_cl(

// Line Buffer Implementation (Phil's)
template <class data_T, class res_T, typename CONFIG_T>
void depthwise_conv_2d_buffer_cl(
ac_channel<data_T> &data, ac_channel<res_T> &res,
typename CONFIG_T::weight_t weights[CONFIG_T::kernel_size * CONFIG_T::n_filt],
typename CONFIG_T::bias_t biases[CONFIG_T::n_filt]) {
void depthwise_conv_2d_buffer_cl(ac_channel<data_T> &data, ac_channel<res_T> &res,
typename CONFIG_T::weight_t weights[CONFIG_T::kernel_size * CONFIG_T::n_filt],
typename CONFIG_T::bias_t biases[CONFIG_T::n_filt]) {
assert(CONFIG_T::pad_top == 0 && CONFIG_T::pad_bottom == 0 && CONFIG_T::pad_left == 0 && CONFIG_T::pad_right == 0);

static ap_shift_reg<typename data_T::value_type, CONFIG_T::in_width> line_buffer[CONFIG_T::filt_height - 1]
Expand Down Expand Up @@ -86,10 +85,9 @@ void depthwise_conv_2d_buffer_cl(

#pragma hls_design block
template <class data_T, class res_T, typename CONFIG_T>
void depthwise_conv_2d_cl(
ac_channel<data_T> &data, ac_channel<res_T> &res,
typename CONFIG_T::weight_t weights[CONFIG_T::kernel_size * CONFIG_T::n_filt],
typename CONFIG_T::bias_t biases[CONFIG_T::n_filt]) {
void depthwise_conv_2d_cl(ac_channel<data_T> &data, ac_channel<res_T> &res,
typename CONFIG_T::weight_t weights[CONFIG_T::kernel_size * CONFIG_T::n_filt],
typename CONFIG_T::bias_t biases[CONFIG_T::n_filt]) {
// #pragma HLS inline recursive
switch (CONFIG_T::implementation) {
case conv_implementation::linebuffer:
Expand Down Expand Up @@ -134,13 +132,14 @@ void pointwise_conv_2d_cl(ac_channel<data_T> &data, ac_channel<res_T> &res,

#pragma hls_design block
template <class data_T, class dw_res_T, class res_T, typename CONFIG_T>
void separable_conv_2d_cl(ac_channel<data_T> &data, ac_channel<res_T> &res,
typename CONFIG_T::depthwise_config::weight_t
depthwise_weights[CONFIG_T::depthwise_config::kernel_size * CONFIG_T::depthwise_config::n_filt],
typename CONFIG_T::pointwise_config::weight_t
pointwise_weights[CONFIG_T::pointwise_config::n_chan * CONFIG_T::pointwise_config::n_filt],
typename CONFIG_T::depthwise_config::bias_t depthwise_biases[CONFIG_T::depthwise_config::n_filt],
typename CONFIG_T::pointwise_config::bias_t pointwise_biases[CONFIG_T::pointwise_config::n_filt]) {
void separable_conv_2d_cl(
ac_channel<data_T> &data, ac_channel<res_T> &res,
typename CONFIG_T::depthwise_config::weight_t
depthwise_weights[CONFIG_T::depthwise_config::kernel_size * CONFIG_T::depthwise_config::n_filt],
typename CONFIG_T::pointwise_config::weight_t
pointwise_weights[CONFIG_T::pointwise_config::n_chan * CONFIG_T::pointwise_config::n_filt],
typename CONFIG_T::depthwise_config::bias_t depthwise_biases[CONFIG_T::depthwise_config::n_filt],
typename CONFIG_T::pointwise_config::bias_t pointwise_biases[CONFIG_T::pointwise_config::n_filt]) {
// #pragma HLS DATAFLOW

static ac_channel<dw_res_T> depthwise_res;
Expand Down
7 changes: 4 additions & 3 deletions hls4ml/templates/catapult/nnet_utils/nnet_sepconv_stream.h
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ void depthwise_product(data_T data[CONFIG_T::kernel_size * CONFIG_T::n_chan], re
//#pragma HLS ARRAY_PARTITION variable=mult complete

//#pragma HLS ALLOCATION operation instances=mul limit=CONFIG_T::multiplier_limit



// Do the matrix-multiply
#pragma hls_unroll
Product1:
Expand All @@ -43,7 +42,9 @@ void depthwise_product(data_T data[CONFIG_T::kernel_size * CONFIG_T::n_chan], re
Product2:
for (unsigned int jj = 0; jj < CONFIG_T::d_mult; jj++) {
int index = ii * CONFIG_T::d_mult + jj;
mult[index] = CONFIG_T::mult_config::template product<data_T, typename CONFIG_T::mult_config::weight_t>::product(data[ii], weights[index]);
mult[index] =
CONFIG_T::mult_config::template product<data_T, typename CONFIG_T::mult_config::weight_t>::product(
data[ii], weights[index]);
}
}

Expand Down
14 changes: 13 additions & 1 deletion scripts/hls4ml
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ def _build_quartus(args, extra_args):

os.chdir(curr_dir)


def _build_catapult(args, extra_args):
catapult_parser = argparse.ArgumentParser(prog=f'hls4ml build -p {args.project}', add_help=False)
catapult_parser.add_argument('-c', '--simulation', help='Run C simulation', action='store_true', default=False)
Expand Down Expand Up @@ -327,11 +328,22 @@ def _build_catapult(args, extra_args):
print('Catapult HLS installation not found. Make sure "catapult" is on PATH.')
sys.exit(1)

ccs_args = '"reset={reset} csim={csim} synth={synth} cosim={cosim} validation={validation} export={export} vsynth={vsynth} fifo_opt={fifo_opt} bitfile={bitfile}"'.format(reset=reset, csim=csim, synth=synth, cosim=cosim, validation=validation, export=export, vsynth=vsynth, fifo_opt=fifo_opt, bitfile=bitfile)
ccs_args = '"reset={reset} csim={csim} synth={synth} cosim={cosim} validation={validation} export={export} vsynth={vsynth} fifo_opt={fifo_opt} bitfile={bitfile}"'.format(
reset=reset,
csim=csim,
synth=synth,
cosim=cosim,
validation=validation,
export=export,
vsynth=vsynth,
fifo_opt=fifo_opt,
bitfile=bitfile,
)
ccs_invoke = catapult_exe + ' -shell -f build_prj.tcl -eval \'set ::argv ' + ccs_args + '\''
print(ccs_invoke)
os.system(ccs_invoke)


def _report(args, extra_args):
if args.project is None:
print('Project directory (-p or --project) must be provided.')
Expand Down

0 comments on commit f207eeb

Please sign in to comment.