diff --git a/hls4ml/templates/vivado/nnet_utils/nnet_image_stream.h b/hls4ml/templates/vivado/nnet_utils/nnet_image_stream.h index e25f5fe723..42d2ce80e0 100644 --- a/hls4ml/templates/vivado/nnet_utils/nnet_image_stream.h +++ b/hls4ml/templates/vivado/nnet_utils/nnet_image_stream.h @@ -1,43 +1,64 @@ -#ifndef NNET_IMAGE_STREAM_H_ -#define NNET_IMAGE_STREAM_H_ - -#include "nnet_common.h" -#include "hls_stream.h" - -namespace nnet { - -template -void resize_nearest( - hls::stream &image, - hls::stream &resized -) { - assert(CONFIG_T::new_height % CONFIG_T::height == 0); - assert(CONFIG_T::new_width % CONFIG_T::width == 0); - constexpr unsigned ratio_height = CONFIG_T::new_height / CONFIG_T::height; - constexpr unsigned ratio_width = CONFIG_T::new_width / CONFIG_T::width; - constexpr unsigned ii = ratio_height * ratio_width; - - ResizeImage: for (unsigned i = 0; i < CONFIG_T::height * CONFIG_T::width; i++) { - #pragma HLS PIPELINE II=ii - - data_T in_data = image.read(); - - ResizeNew: for (unsigned j = 0; j < ratio_height * ratio_width; j++) { - #pragma HLS UNROLL - - data_T out_data; - #pragma HLS DATA_PACK variable=out_data - - ResizeChan: for (unsigned k = 0; k < CONFIG_T::n_chan; k++) { - #pragma HLS UNROLL - out_data[k] = in_data[k]; - } - - resized.write(out_data); - } - } -} - -} - -#endif +#ifndef NNET_IMAGE_STREAM_H_ +#define NNET_IMAGE_STREAM_H_ + +#include "nnet_common.h" +#include "hls_stream.h" + +namespace nnet { + +template +void resize_nearest( + hls::stream &image, + hls::stream &resized +) { + assert(CONFIG_T::new_height % CONFIG_T::height == 0); + assert(CONFIG_T::new_width % CONFIG_T::width == 0); + constexpr unsigned ratio_height = CONFIG_T::new_height / CONFIG_T::height; + constexpr unsigned ratio_width = CONFIG_T::new_width / CONFIG_T::width; + + + ImageHeight: for (unsigned h = 0; h < CONFIG_T::height; h++) { + #pragma HLS PIPELINE + + data_T data_in_row[CONFIG_T::width]; + + ImageWidth: for (unsigned i = 0; i < CONFIG_T::width; i++) { + #pragma HLS UNROLL + + data_T in_data = image.read(); + + ImageChan: for (unsigned j = 0; j < CONFIG_T::n_chan; j++) { + #pragma HLS UNROLL + + data_in_row[i][j] = in_data[j]; + } + } + + ResizeHeight: for (unsigned i = 0; i