|
1 |
| -#ifndef NNET_IMAGE_STREAM_H_ |
2 |
| -#define NNET_IMAGE_STREAM_H_ |
3 |
| - |
4 |
| -#include "nnet_common.h" |
5 |
| -#include "hls_stream.h" |
6 |
| - |
7 |
| -namespace nnet { |
8 |
| - |
9 |
| -template<class data_T, typename CONFIG_T> |
10 |
| -void resize_nearest( |
11 |
| - hls::stream<data_T> &image, |
12 |
| - hls::stream<data_T> &resized |
13 |
| -) { |
14 |
| - assert(CONFIG_T::new_height % CONFIG_T::height == 0); |
15 |
| - assert(CONFIG_T::new_width % CONFIG_T::width == 0); |
16 |
| - constexpr unsigned ratio_height = CONFIG_T::new_height / CONFIG_T::height; |
17 |
| - constexpr unsigned ratio_width = CONFIG_T::new_width / CONFIG_T::width; |
18 |
| - constexpr unsigned ii = ratio_height * ratio_width; |
19 |
| - |
20 |
| - ResizeImage: for (unsigned i = 0; i < CONFIG_T::height * CONFIG_T::width; i++) { |
21 |
| - #pragma HLS PIPELINE II=ii |
22 |
| - |
23 |
| - data_T in_data = image.read(); |
24 |
| - |
25 |
| - ResizeNew: for (unsigned j = 0; j < ratio_height * ratio_width; j++) { |
26 |
| - #pragma HLS UNROLL |
27 |
| - |
28 |
| - data_T out_data; |
29 |
| - #pragma HLS DATA_PACK variable=out_data |
30 |
| - |
31 |
| - ResizeChan: for (unsigned k = 0; k < CONFIG_T::n_chan; k++) { |
32 |
| - #pragma HLS UNROLL |
33 |
| - out_data[k] = in_data[k]; |
34 |
| - } |
35 |
| - |
36 |
| - resized.write(out_data); |
37 |
| - } |
38 |
| - } |
39 |
| -} |
40 |
| - |
41 |
| -} |
42 |
| - |
43 |
| -#endif |
| 1 | +#ifndef NNET_IMAGE_STREAM_H_ |
| 2 | +#define NNET_IMAGE_STREAM_H_ |
| 3 | + |
| 4 | +#include "nnet_common.h" |
| 5 | +#include "hls_stream.h" |
| 6 | + |
| 7 | +namespace nnet { |
| 8 | + |
| 9 | +template<class data_T, typename CONFIG_T> |
| 10 | +void resize_nearest( |
| 11 | + hls::stream<data_T> &image, |
| 12 | + hls::stream<data_T> &resized |
| 13 | +) { |
| 14 | + assert(CONFIG_T::new_height % CONFIG_T::height == 0); |
| 15 | + assert(CONFIG_T::new_width % CONFIG_T::width == 0); |
| 16 | + constexpr unsigned ratio_height = CONFIG_T::new_height / CONFIG_T::height; |
| 17 | + constexpr unsigned ratio_width = CONFIG_T::new_width / CONFIG_T::width; |
| 18 | + |
| 19 | + |
| 20 | + ImageHeight: for (unsigned h = 0; h < CONFIG_T::height; h++) { |
| 21 | + #pragma HLS PIPELINE |
| 22 | + |
| 23 | + data_T data_in_row[CONFIG_T::width]; |
| 24 | + |
| 25 | + ImageWidth: for (unsigned i = 0; i < CONFIG_T::width; i++) { |
| 26 | + #pragma HLS UNROLL |
| 27 | + |
| 28 | + data_T in_data = image.read(); |
| 29 | + |
| 30 | + ImageChan: for (unsigned j = 0; j < CONFIG_T::n_chan; j++) { |
| 31 | + #pragma HLS UNROLL |
| 32 | + |
| 33 | + data_in_row[i][j] = in_data[j]; |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + ResizeHeight: for (unsigned i = 0; i <ratio_height; i++) { |
| 38 | + #pragma HLS UNROLL |
| 39 | + |
| 40 | + ImageWidth2: for (unsigned l = 0; l < CONFIG_T::width; l++) { |
| 41 | + #pragma HLS UNROLL |
| 42 | + |
| 43 | + ResizeWidth: for (unsigned j = 0; j < ratio_width; j++) { |
| 44 | + #pragma HLS UNROLL |
| 45 | + |
| 46 | + data_T out_data; |
| 47 | + #pragma HLS DATA_PACK variable=out_data |
| 48 | + |
| 49 | + ResizeChan: for (unsigned k = 0; k < CONFIG_T::n_chan; k++) { |
| 50 | + #pragma HLS UNROLL |
| 51 | + |
| 52 | + out_data[k] = data_in_row[l][k]; |
| 53 | + } |
| 54 | + |
| 55 | + resized.write(out_data); |
| 56 | + } |
| 57 | + } |
| 58 | + } |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +} |
| 63 | + |
| 64 | +#endif |
0 commit comments