88// for comparing floats
99#include " vtr_math.h"
1010
11+ #include < limits>
12+
1113namespace {
1214
1315void set_type_tile_to_empty (const int x, const int y,
@@ -46,6 +48,7 @@ void set_tile_type_at_loc(const int x_anchor, const int y_anchor,
4648 }
4749}
4850
51+
4952TEST_CASE (" test_compressed_grid" , " [vpr_compressed_grid]" ) {
5053 // test device grid name
5154 std::string device_grid_name = " test" ;
@@ -64,54 +67,86 @@ TEST_CASE("test_compressed_grid", "[vpr_compressed_grid]") {
6467 // create the test device grid (10x10)
6568 auto test_grid = vtr::NdMatrix<t_grid_tile, 3 >({1 , test_grid_width, test_grid_height});
6669
67- t_logical_block_type EMPTY_LOGICAL_BLOCK_TYPE = get_empty_logical_type ();
68- EMPTY_LOGICAL_BLOCK_TYPE.index = 0 ;
70+ auto & logical_block_types = g_vpr_ctx.mutable_device ().logical_block_types ;
71+ logical_block_types.clear ();
72+
6973
7074 t_physical_tile_type empty_tile;
7175 empty_tile.name = empty_tile_name;
7276 empty_tile.height = 1 ;
7377 empty_tile.width = 1 ;
78+ empty_tile.sub_tiles .emplace_back ();
79+
80+ t_logical_block_type EMPTY_LOGICAL_BLOCK_TYPE = get_empty_logical_type ();
81+ EMPTY_LOGICAL_BLOCK_TYPE.index = 0 ;
82+ EMPTY_LOGICAL_BLOCK_TYPE.equivalent_tiles .push_back (&empty_tile);
83+ logical_block_types.push_back (EMPTY_LOGICAL_BLOCK_TYPE);
7484
7585 g_vpr_ctx.mutable_device ().EMPTY_PHYSICAL_TILE_TYPE = &empty_tile;
7686
87+ empty_tile.sub_tiles .back ().index = 0 ;
88+ empty_tile.sub_tiles .back ().equivalent_sites .push_back (&EMPTY_LOGICAL_BLOCK_TYPE);
89+
90+
7791 // create an io physical tile and assign its parameters
7892 t_physical_tile_type io_tile;
7993 io_tile.name = io_tile_name;
8094 io_tile.height = 1 ;
8195 io_tile.width = 1 ;
96+ io_tile.sub_tiles .emplace_back ();
8297
8398 t_logical_block_type io_logical_type;
8499 io_logical_type.index = 1 ;
85100 io_logical_type.equivalent_tiles .push_back (&io_tile);
101+ logical_block_types.push_back (io_logical_type);
102+
103+ io_tile.sub_tiles .back ().index = 0 ;
104+ io_tile.sub_tiles .back ().equivalent_sites .push_back (&io_logical_type);
86105
87106 // create a small tile and assign its parameters
88107 t_physical_tile_type small_tile;
89108 small_tile.name = small_tile_name;
90109 small_tile.height = 1 ;
91110 small_tile.width = 1 ;
111+ small_tile.sub_tiles .emplace_back ();
92112
93113 t_logical_block_type small_logical_type;
94114 small_logical_type.index = 2 ;
95115 small_logical_type.equivalent_tiles .push_back (&small_tile);
116+ logical_block_types.push_back (small_logical_type);
117+
118+ small_tile.sub_tiles .back ().index = 0 ;
119+ small_tile.sub_tiles .back ().equivalent_sites .push_back (&small_logical_type);
96120
97121 // create a small tile and assign its parameters
98122 t_physical_tile_type tall_tile;
99123 tall_tile.name = tall_tile_name;
100124 tall_tile.height = 4 ;
101125 tall_tile.width = 1 ;
126+ tall_tile.sub_tiles .emplace_back ();
102127
103128 t_logical_block_type tall_logical_type;
104129 tall_logical_type.index = 3 ;
105130 tall_logical_type.equivalent_tiles .push_back (&tall_tile);
131+ logical_block_types.push_back (tall_logical_type);
132+
133+
134+ tall_tile.sub_tiles .back ().index = 0 ;
135+ tall_tile.sub_tiles .back ().equivalent_sites .push_back (&tall_logical_type);
106136
107137 t_physical_tile_type large_tile;
108138 large_tile.name = large_tile_name;
109139 large_tile.height = 3 ;
110140 large_tile.width = 3 ;
141+ large_tile.sub_tiles .emplace_back ();
111142
112143 t_logical_block_type large_logical_type;
113144 large_logical_type.index = 4 ;
114145 large_logical_type.equivalent_tiles .push_back (&large_tile);
146+ logical_block_types.push_back (large_logical_type);
147+
148+ large_tile.sub_tiles .back ().index = 0 ;
149+ large_tile.sub_tiles .back ().equivalent_sites .push_back (&large_logical_type);
115150
116151
117152 for (int x = 0 ; x < test_grid_width; x++) {
@@ -140,19 +175,92 @@ TEST_CASE("test_compressed_grid", "[vpr_compressed_grid]") {
140175 }
141176 }
142177
143- auto & logical_block_types = g_vpr_ctx.mutable_device ().logical_block_types ;
144- logical_block_types.clear ();
145-
146178 auto & grid = g_vpr_ctx.mutable_device ().grid ;
147179 grid = DeviceGrid (" test_device_grid" , test_grid);
148180
149181 std::vector<t_compressed_block_grid> compressed_grids = create_compressed_block_grids ();
150182
151- echo_compressed_grids (" havij" , compressed_grids);
183+ SECTION (" Check compressed grid sizes" ) {
184+ REQUIRE (compressed_grids[io_logical_type.index ].compressed_to_grid_x [0 ].size () == 100 );
185+ REQUIRE (compressed_grids[io_logical_type.index ].compressed_to_grid_y [0 ].size () == 100 );
186+
187+ REQUIRE (compressed_grids[small_logical_type.index ].compressed_to_grid_x [0 ].size () == 98 );
188+ REQUIRE (compressed_grids[small_logical_type.index ].compressed_to_grid_y [0 ].size () == 98 );
152189
153- // SECTION("All routers are seperated by one or more grid spaces") {
154- // // in this test, the routers will be on the 4 corners of the FPGA
155- // }
190+ REQUIRE (compressed_grids[tall_logical_type.index ].compressed_to_grid_x [0 ].size () == 9 );
191+ REQUIRE (compressed_grids[tall_logical_type.index ].compressed_to_grid_y [0 ].size () == 18 );
192+
193+ REQUIRE (compressed_grids[large_logical_type.index ].compressed_to_grid_x [0 ].size () == 5 );
194+ REQUIRE (compressed_grids[large_logical_type.index ].compressed_to_grid_y [0 ].size () == 7 );
195+ }
196+
197+ SECTION (" Exact mapped locations in the compressed grids" ) {
198+ t_physical_tile_loc comp_loc = compressed_grids[large_logical_type.index ].grid_loc_to_compressed_loc_approx ({25 , 33 , 0 });
199+ t_physical_tile_loc grid_loc = compressed_grids[large_logical_type.index ].compressed_loc_to_grid_loc (comp_loc);
200+ REQUIRE (grid_loc == t_physical_tile_loc{25 , 33 , 0 });
201+
202+ comp_loc = compressed_grids[large_logical_type.index ].grid_loc_to_compressed_loc_approx ({76 , 7 , 0 });
203+ grid_loc = compressed_grids[large_logical_type.index ].compressed_loc_to_grid_loc (comp_loc);
204+ REQUIRE (grid_loc == t_physical_tile_loc{76 , 7 , 0 });
205+
206+ comp_loc = compressed_grids[large_logical_type.index ].grid_loc_to_compressed_loc_approx ({59 , 85 , 0 });
207+ grid_loc = compressed_grids[large_logical_type.index ].compressed_loc_to_grid_loc (comp_loc);
208+ REQUIRE (grid_loc == t_physical_tile_loc{59 , 85 , 0 });
209+
210+ comp_loc = compressed_grids[tall_logical_type.index ].grid_loc_to_compressed_loc_approx ({7 , 5 , 0 });
211+ grid_loc = compressed_grids[tall_logical_type.index ].compressed_loc_to_grid_loc (comp_loc);
212+ REQUIRE (grid_loc == t_physical_tile_loc{7 , 5 , 0 });
213+
214+ comp_loc = compressed_grids[tall_logical_type.index ].grid_loc_to_compressed_loc_approx ({77 , 40 , 0 });
215+ grid_loc = compressed_grids[tall_logical_type.index ].compressed_loc_to_grid_loc (comp_loc);
216+ REQUIRE (grid_loc == t_physical_tile_loc{77 , 40 , 0 });
217+
218+ comp_loc = compressed_grids[tall_logical_type.index ].grid_loc_to_compressed_loc_approx ({37 , 85 , 0 });
219+ grid_loc = compressed_grids[tall_logical_type.index ].compressed_loc_to_grid_loc (comp_loc);
220+ REQUIRE (grid_loc == t_physical_tile_loc{37 , 85 , 0 });
221+
222+ comp_loc = compressed_grids[small_logical_type.index ].grid_loc_to_compressed_loc_approx ({2 , 3 , 0 });
223+ grid_loc = compressed_grids[small_logical_type.index ].compressed_loc_to_grid_loc (comp_loc);
224+ REQUIRE (grid_loc == t_physical_tile_loc{2 , 3 , 0 });
225+
226+ comp_loc = compressed_grids[small_logical_type.index ].grid_loc_to_compressed_loc_approx ({17 , 3 , 0 });
227+ grid_loc = compressed_grids[small_logical_type.index ].compressed_loc_to_grid_loc (comp_loc);
228+ REQUIRE (grid_loc == t_physical_tile_loc{17 , 3 , 0 });
229+ }
230+
231+ SECTION (" Closest mapped location in the compressed grids" ) {
232+ t_physical_tile_loc comp_loc = compressed_grids[large_logical_type.index ].grid_loc_to_compressed_loc_approx ({25 , 33 , 0 });
233+ t_physical_tile_loc grid_loc = compressed_grids[large_logical_type.index ].compressed_loc_to_grid_loc (comp_loc);
234+ REQUIRE (grid_loc == t_physical_tile_loc{25 , 33 , 0 });
235+
236+ comp_loc = compressed_grids[large_logical_type.index ].grid_loc_to_compressed_loc_approx ({99 , 10 , 0 });
237+ grid_loc = compressed_grids[large_logical_type.index ].compressed_loc_to_grid_loc (comp_loc);
238+ REQUIRE (grid_loc == t_physical_tile_loc{76 , 7 , 0 });
239+
240+ comp_loc = compressed_grids[large_logical_type.index ].grid_loc_to_compressed_loc_approx ({51 , 79 , 0 });
241+ grid_loc = compressed_grids[large_logical_type.index ].compressed_loc_to_grid_loc (comp_loc);
242+ REQUIRE (grid_loc == t_physical_tile_loc{59 , 85 , 0 });
243+
244+ comp_loc = compressed_grids[tall_logical_type.index ].grid_loc_to_compressed_loc_approx ({1 , 6 , 0 });
245+ grid_loc = compressed_grids[tall_logical_type.index ].compressed_loc_to_grid_loc (comp_loc);
246+ REQUIRE (grid_loc == t_physical_tile_loc{7 , 5 , 0 });
247+
248+ comp_loc = compressed_grids[tall_logical_type.index ].grid_loc_to_compressed_loc_approx ({81 , 38 , 0 });
249+ grid_loc = compressed_grids[tall_logical_type.index ].compressed_loc_to_grid_loc (comp_loc);
250+ REQUIRE (grid_loc == t_physical_tile_loc{77 , 40 , 0 });
251+
252+ comp_loc = compressed_grids[tall_logical_type.index ].grid_loc_to_compressed_loc_approx ({34 , 83 , 0 });
253+ grid_loc = compressed_grids[tall_logical_type.index ].compressed_loc_to_grid_loc (comp_loc);
254+ REQUIRE (grid_loc == t_physical_tile_loc{37 , 85 , 0 });
255+
256+ comp_loc = compressed_grids[small_logical_type.index ].grid_loc_to_compressed_loc_approx ({0 , 0 , 0 });
257+ grid_loc = compressed_grids[small_logical_type.index ].compressed_loc_to_grid_loc (comp_loc);
258+ REQUIRE (grid_loc == t_physical_tile_loc{1 , 1 , 0 });
259+
260+ comp_loc = compressed_grids[small_logical_type.index ].grid_loc_to_compressed_loc_approx ({99 , 99 , 0 });
261+ grid_loc = compressed_grids[small_logical_type.index ].compressed_loc_to_grid_loc (comp_loc);
262+ REQUIRE (grid_loc == t_physical_tile_loc{98 , 98 , 0 });
263+ }
156264
157265}
158266
0 commit comments