Skip to content

Commit a051daa

Browse files
committed
Test one window mode
1 parent b3dffbd commit a051daa

File tree

2 files changed

+89
-24
lines changed

2 files changed

+89
-24
lines changed

HLS/IpsFilterHLS/src/tb_filter.cpp

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -297,30 +297,35 @@ int sc_main(int, char*[])
297297
sc_argc();
298298
sc_argv();
299299

300-
sc_signal<sc_uint<8> > signal[10];
300+
sc_signal<sc_uint<8> > signal;
301+
sc_signal<sc_uint<8> > signal_bus[9];
301302
sc_clock clk("clk", 1, SC_NS);
302303

303304
testbench tb_module("tb_module");
304305
Filter filter("filter");
305306

306307
filter.clk(clk);
307-
filter.input_window_0(signal[0]);
308-
filter.input_window_1(signal[1]);
309-
filter.input_window_2(signal[2]);
310-
filter.input_window_3(signal[3]);
311-
filter.input_window_4(signal[4]);
312-
filter.input_window_5(signal[5]);
313-
filter.input_window_6(signal[6]);
314-
filter.input_window_7(signal[7]);
315-
filter.input_window_8(signal[8]);
308+
filter.input_window_0(signal_bus[0]);
309+
filter.input_window_1(signal_bus[1]);
310+
filter.input_window_2(signal_bus[2]);
311+
filter.input_window_3(signal_bus[3]);
312+
filter.input_window_4(signal_bus[4]);
313+
filter.input_window_5(signal_bus[5]);
314+
filter.input_window_6(signal_bus[6]);
315+
filter.input_window_7(signal_bus[7]);
316+
filter.input_window_8(signal_bus[8]);
316317

317318
for (int i = 0; i < 9; i++){
318-
tb_module.img_window[i](signal[i]);
319+
tb_module.img_window[i](signal_bus[i]);
319320
}
320-
filter.output(signal[9]);
321-
tb_module.mean(signal[9]);
321+
filter.output(signal);
322+
tb_module.mean(signal);
322323

323324
sc_start();
325+
#ifdef IPS_DEBUG_EN
326+
std::cout << "Test starting" << std::endl;
327+
std::cout << "@" << sc_time_stamp() << std::endl;
328+
#endif // IPS_DEBUG_EN
324329

325330

326331
// printf(" Signal is %0u\n", signal.read());

HLS/IpsFilterHLS/src/tb_module.cpp

Lines changed: 71 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,85 @@
11
#include <systemc.h>
2+
#include <cstdlib>
3+
4+
#define IPS_FILTER_KERNEL_SIZE 3
5+
#define DELAY_TIME (IPS_FILTER_KERNEL_SIZE * IPS_FILTER_KERNEL_SIZE * 1) + 4 + 2 + 1
26

37
SC_MODULE (testbench) {
4-
sc_out<sc_uint<8> > img_window[9];
8+
sc_out<sc_uint<8> > img_window[IPS_FILTER_KERNEL_SIZE*IPS_FILTER_KERNEL_SIZE];
59
sc_in<sc_uint<8> > mean;
610

711
SC_CTOR (testbench) {
812
SC_THREAD(process);
913
}
1014

1115
void process() {
12-
for (int i = 0; i < 9; i++){
13-
img_window[i] = 0;
16+
17+
#ifdef TEST_MODE_ONE_WINDOW
18+
run_one_window();
19+
#endif //TEST_MODE_ONE_WINDOW
20+
sc_stop();
21+
}
22+
23+
#ifdef TEST_MODE_ONE_WINDOW
24+
void run_one_window()
25+
{
26+
sc_uint<8> local_window[IPS_FILTER_KERNEL_SIZE * IPS_FILTER_KERNEL_SIZE];
27+
sc_uint<8> result;
28+
29+
#ifdef IPS_DEBUG_EN
30+
#ifdef TEST_MODE_ONE_WINDOW_RANDOM
31+
SC_REPORT_INFO("TEST_MODE_ONE_WINDOW_NORMAL", "Running test");
32+
#elif defined(TEST_MODE_ONE_WINDOW_NORMAL)
33+
SC_REPORT_INFO("TEST_MODE_ONE_WINDOW_NORMAL", "Running test");
34+
#else
35+
SC_REPORT_INFO("TEST_MODE_ONE_WINDOW_DEFAULT", "Running test");
36+
#endif // TEST_MODE_ONE_WINDOW_RANDOM
37+
SC_REPORT_INFO("Initialize window", "Window value");
38+
#endif // IPS_DEBUG_EN
39+
40+
// Initialize image window
41+
for (int i = 0; i < IPS_FILTER_KERNEL_SIZE; i++)
42+
{
43+
for (int j = 0; j < IPS_FILTER_KERNEL_SIZE; j++)
44+
{
45+
sc_uint<8> value;
46+
47+
#ifdef TEST_MODE_ONE_WINDOW_RANDOM
48+
value = (sc_uint<8> ) (rand() % 256);
49+
#elif defined(TEST_MODE_ONE_WINDOW_NORMAL)
50+
value = (sc_uint<8> ) (i * IPS_FILTER_KERNEL_SIZE + j);
51+
#else
52+
value = (sc_uint<8> ) i;
53+
#endif // TEST_MODE_ONE_WINDOW
54+
55+
local_window[i * IPS_FILTER_KERNEL_SIZE + j] = value;
56+
#ifdef IPS_DEBUG_EN
57+
std::cout << "[" << (int) local_window[i * IPS_FILTER_KERNEL_SIZE + j] << "]";
58+
#endif // IPS_DUMP_EN
59+
}
60+
61+
#ifdef IPS_DEBUG_EN
62+
std::cout << std::endl;
63+
#endif // IPS_DEBUG_EN
1464
}
15-
wait(10, SC_NS);
16-
std::cout << "Result: " << mean << std::endl;
17-
std::cout << "HERE" << std::endl;
18-
for (int i = 0; i < 9; i++){
19-
img_window[i] = i;
65+
66+
for (int i = 0; i < IPS_FILTER_KERNEL_SIZE*IPS_FILTER_KERNEL_SIZE; i++) {
67+
#ifdef IPS_DEBUG_EN
68+
SC_REPORT_INFO("[DEBUG]", "Writing to image window port the value:");
69+
std::cout << "Iteration: " << i << " local_window = " << local_window[i] << std::endl;
70+
#endif // IPS_DEBUG_EN
71+
img_window[i].write(local_window[i]); //Write to port
2072
}
21-
wait(10, SC_NS);
22-
std::cout << "Result: " << mean << std::endl;
23-
sc_stop();
73+
74+
wait(DELAY_TIME + 10, SC_NS);
75+
result = mean.read();
76+
77+
#ifdef IPS_DEBUG_EN
78+
SC_REPORT_INFO("TEST_MODE_ONE_WINDOW", "filtering");
79+
std::cout << "Result = " << result << std::endl;
80+
#endif // IPS_DEBUG_E
81+
82+
//delete [] img_window;
2483
}
84+
#endif //TEST_MODE_ONE_WINDOW
2585
};

0 commit comments

Comments
 (0)