Skip to content

Commit 2e3ed49

Browse files
committed
Fixed ips to be synthetizable and added tb module
1 parent a051daa commit 2e3ed49

File tree

4 files changed

+282
-62
lines changed

4 files changed

+282
-62
lines changed

HLS/IpsFilterHLS/src/ips_filter.cpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,45 @@
33

44
#include "ips_filter.hpp"
55

6+
#define IPS_FILTER_KERNEL_SIZE 3
7+
68
void Filter::filter()
79
{
8-
while (true) {
10+
float result;
11+
12+
while(true) {
913
wait();
10-
sc_uint<8> result = 0;
11-
result = result + input_window_0.read();
12-
result = result + input_window_1.read();
13-
result = result + input_window_2.read();
14-
result = result + input_window_3.read();
15-
result = result + input_window_4.read();
16-
result = result + input_window_5.read();
17-
result = result + input_window_6.read();
18-
result = result + input_window_7.read();
19-
result = result + input_window_8.read();
14+
result = 0;
15+
result = input_window_0.read() + input_window_1.read() + input_window_2.read() + input_window_3.read() + input_window_4.read() + input_window_5.read() +input_window_6.read() + input_window_7.read() + input_window_8.read();
16+
17+
#pragma HLS RESOURCE variable=result core=FMul_nodsp
18+
result = result * (0.1111);
2019

2120
#ifndef __SYNTHESIS__
22-
cout << "Step: " << 1 << " Window Input = " << input_window_0 << " Result = " << (float) result/(N*N) << endl;
23-
cout << "Step: " << 2 << " Window Input = " << input_window_1 << " Result = " << (float) result/(N*N) << endl;
24-
cout << "Step: " << 3 << " Window Input = " << input_window_2 << " Result = " << (float) result/(N*N) << endl;
25-
cout << "Step: " << 4 << " Window Input = " << input_window_3 << " Result = " << (float) result/(N*N) << endl;
26-
cout << "Step: " << 5 << " Window Input = " << input_window_4 << " Result = " << (float) result/(N*N) << endl;
27-
cout << "Step: " << 6 << " Window Input = " << input_window_5 << " Result = " << (float) result/(N*N) << endl;
28-
cout << "Step: " << 7 << " Window Input = " << input_window_6 << " Result = " << (float) result/(N*N) << endl;
29-
cout << "Step: " << 8 << " Window Input = " << input_window_7 << " Result = " << (float) result/(N*N) << endl;
30-
cout << "Step: " << 9 << " Window Input = " << input_window_8 << " Result = " << (float) result/(N*N) << endl;
21+
cout << "Step: " << 1 << " Window Input = " << input_window_0.read() << endl;
22+
cout << "Step: " << 2 << " Window Input = " << input_window_1.read() << endl;
23+
cout << "Step: " << 3 << " Window Input = " << input_window_2.read() << endl;
24+
cout << "Step: " << 4 << " Window Input = " << input_window_3.read() << endl;
25+
cout << "Step: " << 5 << " Window Input = " << input_window_4.read() << endl;
26+
cout << "Step: " << 6 << " Window Input = " << input_window_5.read() << endl;
27+
cout << "Step: " << 7 << " Window Input = " << input_window_6.read() << endl;
28+
cout << "Step: " << 8 << " Window Input = " << input_window_7.read() << endl;
29+
cout << "Step: " << 9 << " Window Input = " << input_window_8.read() << endl;
30+
cout << "Result: " << (int) result << endl;
3131
#endif //__SYNTHESIS__
3232

3333
// // Perform the convolution
3434
// for (int i = 0; i < N; ++i) {
3535
// for (int j = 0; j < N; ++j) {
3636
// result += input_window[i * N + j];
3737
// #ifndef __SYNTHESIS__
38-
// cout << "Step: " << i * N + j << " Window Input = " << (int) input_window[i * N + j] << " Result = " << (float) result << endl;
38+
// cout << "Step: " << i * N + j << " Window Input = " << (int) input_window[i * N + j] << (float) result << endl;
3939
// #endif //__SYNTHESIS__
4040
// }
4141
// }
42-
result = result / (N*N);
4342

44-
output.write(result);
43+
output.write( (sc_uint<8>) result);
44+
4545
}
4646
}
4747

HLS/IpsFilterHLS/src/ips_filter.hpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,23 @@ SC_MODULE (Filter) {
2020
sc_out<sc_uint<8> > output;
2121

2222
sc_in<bool> clk;
23-
24-
25-
void filter();
26-
void init_kernel();
27-
23+
2824
SC_HAS_PROCESS(Filter);
29-
Filter(sc_module_name Filter)
30-
: sc_module(Filter)
25+
Filter(sc_module_name name)
3126
{
3227
SC_CTHREAD(filter, clk.pos());
33-
//sensitive << input_window_0 << input_window_1 << input_window_2 << input_window_3 << input_window_4 << input_window_5 << input_window_6 << input_window_7 << input_window_8;
34-
// for (int i = 0; i < N*N; i++){
28+
// SC_METHOD(filter);
29+
// sensitive << input_window_0 << input_window_1 << input_window_2 << input_window_3 << input_window_4 << input_window_5 << input_window_6 << input_window_7 << input_window_8;
30+
// for (int i = 0; i < N*N; is++){
3531
// kernel[i] = 1/N;
3632
// }
3733
}
34+
35+
36+
void filter();
37+
// void init_kernel();
38+
3839
};
3940

41+
4042
#endif // IPS_FILTER_HPP

HLS/IpsFilterHLS/src/tb_filter.cpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,17 @@
6969
//#endif // IPS_DUMP_EN
7070
//
7171
// // Variables
72-
// sc_uint<8> * img_window;
73-
// sc_uint<8> result;
72+
// sc_uint<8>* img_window;
73+
// sc_uint<8> result;
7474
//
7575
// int i, j;
7676
// int x, y;
7777
//
78-
// sc_signal<sc_uint<8> > s_img_window[IPS_FILTER_KERNEL_SIZE*IPS_FILTER_KERNEL_SIZE];
79-
// sc_signal<sc_uint<8> > s_result;
78+
// sc_signal<sc_uint<8>> s_img_window[IPS_FILTER_KERNEL_SIZE*IPS_FILTER_KERNEL_SIZE];
79+
// sc_signal<sc_uint<8>> s_result;
8080
//
8181
// // Initialize image window
82-
// img_window = new sc_uint<8> [IPS_FILTER_KERNEL_SIZE * IPS_FILTER_KERNEL_SIZE];
82+
// img_window = new sc_uint<8>[IPS_FILTER_KERNEL_SIZE * IPS_FILTER_KERNEL_SIZE];
8383
//
8484
// // Instantiate filter module and do the connection
8585
//#ifdef IPS_DUMP_EN
@@ -128,7 +128,7 @@
128128
// {
129129
// for (j = 0; j < IPS_FILTER_KERNEL_SIZE; ++j)
130130
// {
131-
// img_window[i * IPS_FILTER_KERNEL_SIZE + j] = sub_img.at<sc_uint<8> >(i, j);
131+
// img_window[i * IPS_FILTER_KERNEL_SIZE + j] = sub_img.at<sc_uint<8>>(i, j);
132132
//#ifdef IPS_DEBUG_EN
133133
// std::cout << "[" << img_window[i * IPS_FILTER_KERNEL_SIZE + j] << "]";
134134
//#endif // IPS_DEBUG_EN
@@ -146,10 +146,10 @@
146146
//
147147
// result = s_result.read();
148148
//
149-
// o_img.at<sc_uint<8> >(y, x) = result;
149+
// o_img.at<sc_uint<8>>(y, x) = result;
150150
//
151151
//#ifdef IPS_DEBUG_EN
152-
// std::cout << "Result[" << x << "][" << y << "] = " << o_img.at<sc_uint<8> >(y, x) << std::endl << std::endl;
152+
// std::cout << "Result[" << x << "][" << y << "] = " << o_img.at<sc_uint<8>>(y, x) << std::endl << std::endl;
153153
//#endif // IPS_DEBUG_EN
154154
// }
155155
// }
@@ -189,11 +189,11 @@
189189
//#endif // IPS_DEBUG_EN
190190
//
191191
// // Variables
192-
// sc_uint<8> * img_window;
193-
// sc_uint<8> result;
192+
// sc_uint<8>* img_window;
193+
// sc_uint<8> result;
194194
//
195-
// sc_signal<sc_uint<8> > s_img_window;
196-
// sc_signal<sc_uint<8> > s_result;
195+
// sc_signal<sc_uint<8>> s_img_window;
196+
// sc_signal<sc_uint<8>> s_result;
197197
//
198198
// // Instantiate filter module and do the connection
199199
//#ifdef IPS_DUMP_EN
@@ -221,20 +221,20 @@
221221
//#endif // IPS_DEBUG_EN
222222
//
223223
// // Initialize image window
224-
// img_window = new sc_uint<8> [IPS_FILTER_KERNEL_SIZE * IPS_FILTER_KERNEL_SIZE];
224+
// img_window = new sc_uint<8>[IPS_FILTER_KERNEL_SIZE * IPS_FILTER_KERNEL_SIZE];
225225
//
226226
// for (size_t i = 0; i < IPS_FILTER_KERNEL_SIZE; ++i)
227227
// {
228228
// for (size_t j = 0; j < IPS_FILTER_KERNEL_SIZE; ++j)
229229
// {
230-
// sc_uint<8> value;
230+
// sc_uint<8> value;
231231
//
232232
// #ifdef TEST_MODE_ONE_WINDOW_RANDOM
233-
// value = (sc_uint<8> ) (rand() % 256);
233+
// value = (sc_uint<8>) (rand() % 256);
234234
// #elif defined(TEST_MODE_ONE_WINDOW_NORMAL)
235-
// value = (sc_uint<8> ) (i * IPS_FILTER_KERNEL_SIZE + j);
235+
// value = (sc_uint<8>) (i * IPS_FILTER_KERNEL_SIZE + j);
236236
// #else
237-
// value = (sc_uint<8> ) i;
237+
// value = (sc_uint<8>) i;
238238
// #endif // TEST_MODE_ONE_WINDOW
239239
//
240240
// img_window[i * IPS_FILTER_KERNEL_SIZE + j] = value;
@@ -260,7 +260,7 @@
260260
// std::cout << "Iteration: " << i << " img_window = " << (int) img_window[i] << std::endl;
261261
//#endif // IPS_DEBUG_EN
262262
// s_img_window.write(img_window[i]);
263-
// sc_uint<8> value2 = s_img_window.read();
263+
// sc_uint<8> value2 = s_img_window.read();
264264
//
265265
//#ifdef IPS_DEBUG_EN
266266
// std::cout << "Iteration: " << i << " s_img_window = " << (int) value2 << std::endl;
@@ -289,10 +289,10 @@
289289

290290
int sc_main(int, char*[])
291291
{
292-
sc_report_handler::set_actions( "/IEEE_Std_1666/deprecated" , SC_DO_NOTHING);
293-
sc_report_handler::set_actions( SC_ID_LOGIC_X_TO_BOOL_, SC_LOG);
294-
sc_report_handler::set_actions( SC_ID_VECTOR_CONTAINS_LOGIC_VALUE_, SC_LOG);
295-
sc_report_handler::set_actions( SC_ID_OBJECT_EXISTS_, SC_LOG);
292+
// sc_report_handler::set_actions( "/IEEE_Std_1666/deprecated" , SC_DO_NOTHING);
293+
// sc_report_handler::set_actions( SC_ID_LOGIC_X_TO_BOOL_, SC_LOG);
294+
// sc_report_handler::set_actions( SC_ID_VECTOR_CONTAINS_LOGIC_VALUE_, SC_LOG);
295+
// sc_report_handler::set_actions( SC_ID_OBJECT_EXISTS_, SC_LOG);
296296
// Pass command linke arguments
297297
sc_argc();
298298
sc_argv();

0 commit comments

Comments
 (0)