1+ #define int64 systemc_int64
2+ #define uint64 systemc_uint64
3+ #include < systemc.h>
14#ifdef TEST_MODE_ONE_WINDOW_RANDOM
25#include < cstdlib>
3- #endif // TEST_MODE_ONE_WINDOW_RANDOM
6+ #elif defined(TEST_MODE_IMAGE)
7+ #include < cstdlib>
8+ #undef int64
9+ #undef uint64
10+ #define int64 opencv_int64
11+ #define uint64 opencv_uint64
12+ #include < opencv2/opencv.hpp>
13+ #undef int64
14+ #undef uint64
15+ #define SYSTEMC_TYPES_ALREADY_DEFINED
16+ #endif // TEST_MODE
417#ifdef IPS_DUMP_EN
518#include < sstream>
619#endif // IPS_DUMP_EN
7- #include < systemc.h>
820
921#ifndef IPS_FILTER_KERNEL_SIZE
1022#define IPS_FILTER_KERNEL_SIZE 3
1527#ifndef IPS_OUT_TYPE_TB
1628#define IPS_OUT_TYPE_TB float
1729#endif // IPS_OUT_TYPE_TB
30+ #ifndef IPS_IMG_PATH_TB
31+ #define IPS_IMG_PATH_TB " ../../tools/datagen/src/imgs/car_noisy_image.png"
32+ #endif // IPS_IMG_PATH_TB
1833
1934#ifndef IPS_FILTER_PV_EN
2035// N * N * copy_pixel_to_mem_time + mult + redux + copy_pixel_to_mem_time
3348#endif // IPS_FILTER_XX_EN
3449
3550
51+ #ifdef TEST_MODE_IMAGE
52+ #ifdef IPS_DUMP_EN
53+ void run_image (sc_trace_file* wf)
54+ #else
55+ void run_image ()
56+ #endif // IPS_DUMP_EN
57+ {
58+ #ifdef IPS_DEBUG_EN
59+ SC_REPORT_INFO (" TEST_MODE_IMAGE" , " Running test" );
60+ #endif // IPS_DEBUG_EN
61+
62+ const std::string img_path = IPS_IMG_PATH_TB;
63+ cv::Mat read_image = cv::imread (img_path, cv::IMREAD_GRAYSCALE);
64+ cv::Mat image;
65+ read_image.convertTo (image, CV_32F);
66+
67+ #ifdef IPS_DUMP_EN
68+ std::cout << " Loading image: " << img_path << std::endl;
69+ #endif // IPS_DUMP_EN
70+
71+ // Check if the image is loaded successfully
72+ if (image.empty ())
73+ {
74+ std::cerr << " Error: Could not open or find the image!" << std::endl;
75+ exit (EXIT_FAILURE);
76+ }
77+
78+ #ifdef IPS_DUMP_EN
79+ std::cout << " Image info: " ;
80+ std::cout << " rows = " << image.rows ;
81+ std::cout << " cols = " << image.cols ;
82+ std::cout << " channels = " << image.channels () << std::endl;
83+ #endif // IPS_DUMP_EN
84+
85+ // Variables
86+ IPS_IN_TYPE_TB* img_window;
87+ IPS_OUT_TYPE_TB result;
88+
89+ int i, j;
90+ int x, y;
91+
92+ #ifdef IPS_FILTER_AT_EN
93+ sc_signal<IPS_IN_TYPE_TB*> s_img_window;
94+ sc_signal<IPS_OUT_TYPE_TB> s_result;
95+ #endif // IPS_FILTER_AT_EN
96+
97+ // Initialize image window
98+ img_window = new IPS_IN_TYPE_TB[IPS_FILTER_KERNEL_SIZE * IPS_FILTER_KERNEL_SIZE];
99+
100+ // Instantiate filter module and do the connection
101+ #ifdef IPS_DUMP_EN
102+ for (i = 0 ; i < IPS_FILTER_KERNEL_SIZE; ++i)
103+ {
104+ for (j = 0 ; j < IPS_FILTER_KERNEL_SIZE; ++j)
105+ {
106+ std::ostringstream var_name;
107+ var_name << " img_window_" << i << " _" << j;
108+ sc_trace (wf, img_window[i * IPS_FILTER_KERNEL_SIZE + j], var_name.str ());
109+ }
110+ }
111+
112+ Filter<IPS_IN_TYPE_TB, IPS_OUT_TYPE_TB, IPS_FILTER_KERNEL_SIZE> filter (" filter" , wf);
113+ sc_trace (wf, result, " result" );
114+ #else
115+ Filter<IPS_IN_TYPE_TB, IPS_OUT_TYPE_TB, IPS_FILTER_KERNEL_SIZE> filter (" filter" );
116+ #endif // IPS_DUMP_EN
117+
118+ sc_start ();
119+
120+ #ifdef IPS_DEBUG_EN
121+ std::cout << " Test starting" << std::endl;
122+ std::cout << " @" << sc_time_stamp () << std::endl;
123+ #endif // IPS_DEBUG_EN
124+
125+ // Create each window
126+ for (y = 0 ; y < image.rows - IPS_FILTER_KERNEL_SIZE; ++y)
127+ {
128+ for (x = 0 ; x < image.cols - IPS_FILTER_KERNEL_SIZE; ++x)
129+ {
130+ #ifdef IPS_DEBUG_EN
131+ // SC_REPORT_INFO("TEST_MODE_IMAGE", "filtering");
132+ #endif // IPS_DEBUG_EN
133+
134+ // Define the ROI
135+ cv::Rect roi (x, y, IPS_FILTER_KERNEL_SIZE, IPS_FILTER_KERNEL_SIZE);
136+ cv::Mat sub_img = image (roi);
137+
138+ for (i = 0 ; i < IPS_FILTER_KERNEL_SIZE; ++i)
139+ {
140+ for (j = 0 ; j < IPS_FILTER_KERNEL_SIZE; ++j)
141+ {
142+ img_window[i * IPS_FILTER_KERNEL_SIZE + j] = sub_img.at <IPS_IN_TYPE_TB>(i, j);
143+ #ifdef IPS_DEBUG_EN
144+ // std::cout << "[" << img_window[i * IPS_FILTER_KERNEL_SIZE + j] << "]";
145+ #endif // IPS_DEBUG_EN
146+ }
147+
148+ #ifdef IPS_DEBUG_EN
149+ // std::cout << std::endl;
150+ #endif // IPS_DEBUG_EN
151+ }
152+
153+ // Apply convolution
154+ #ifdef IPS_FILTER_PV_EN
155+ filter.filter (img_window, result);
156+ #elif defined(IPS_FILTER_LT_EN)
157+ filter.filter (img_window, &result);
158+ sc_start (DELAY_TIME + 10 , SC_NS);
159+ #elif defined(IPS_FILTER_AT_EN)
160+ filter.filter ();
161+ sc_start (DELAY_TIME + 10 , SC_NS);
162+
163+ result = s_result.read ();
164+ #endif // IPS_FILTER_XX_EN
165+
166+ #ifdef IPS_DEBUG_EN
167+ // std::cout << "Result[" << x << "][" << y << "] = " << result << std::endl << std::endl;
168+ #endif // IPS_DEBUG_EN
169+ }
170+ }
171+
172+ #ifdef IPS_DUMP_EN
173+ sc_start (1 , SC_NS);
174+ #endif // IPS_DUMP_EN
175+
176+ delete [] img_window;
177+ }
178+ #endif // TEST_MODE_IMAGE
179+
36180#ifdef TEST_MODE_ONE_WINDOW
37181#ifdef IPS_DUMP_EN
38182void run_one_window (sc_trace_file* wf)
@@ -52,7 +196,7 @@ void run_one_window()
52196#endif
53197
54198 // Variables
55- IPS_IN_TYPE_TB * img_window;
199+ IPS_IN_TYPE_TB* img_window;
56200 IPS_OUT_TYPE_TB result;
57201
58202#ifdef IPS_FILTER_AT_EN
@@ -155,8 +299,18 @@ int sc_main(int, char*[])
155299#endif // IPS_DUMP_EN
156300
157301#ifdef TEST_MODE_ONE_WINDOW
302+ #ifdef IPS_DUMP_EN
158303 run_one_window (wf);
159- #endif // TEST_MODE_ONE_WINDOW
304+ #else
305+ run_one_window ();
306+ #endif // IPS_DUMP_EN
307+ #elif defined(TEST_MODE_IMAGE)
308+ #ifdef IPS_DUMP_EN
309+ run_image (wf);
310+ #else
311+ run_image ();
312+ #endif // IPS_DUMP_EN
313+ #endif // TEST_MODE
160314
161315#ifdef IPS_DUMP_EN
162316 std::cout << " @" << sc_time_stamp () << " Terminating simulation" << std::endl;
0 commit comments