1818#include " vpr_error.h"
1919#include " vtr_assert.h"
2020
21+ #ifdef ANALYTICAL_PLACEMENT_TIMING
2122void AnalyticalSolver::print_timing () {
2223 for (const auto & p : time_counter)
2324 VTR_LOG (" %s: %f\n " , p.first .c_str (), p.second );
2425}
26+ #endif
2527
2628std::unique_ptr<AnalyticalSolver> make_analytical_solver (e_analytical_solver solver_type) {
2729 if (solver_type == e_analytical_solver::QP_HYBRID)
@@ -167,24 +169,31 @@ static inline void populate_hybrid_matrix(Eigen::SparseMatrix<double>& A_sparse,
167169}
168170
169171void QPHybridSolver::solve (unsigned iteration, PartialPlacement& p_placement) {
172+ #ifdef ANALYTICAL_PLACEMENT_TIMING
170173 auto timer1 = std::chrono::high_resolution_clock::now ();
174+ #endif
171175 if (iteration == 0 ) {
176+ #ifdef ANALYTICAL_PLACEMENT_TIMING
172177 time_counter[" update matrix" ] = 0 ;
173178 time_counter[" build matrix" ] = 0 ;
174179 time_counter[" solve matrix" ] = 0 ;
175180 time_counter[" total solve time" ] = 0 ;
181+ #endif
176182 populate_hybrid_matrix (A_sparse, b_x, b_y, p_placement);
177183 }
184+ #ifdef ANALYTICAL_PLACEMENT_TIMING
178185 auto timer2 = std::chrono::high_resolution_clock::now ();
186+ #endif
179187 Eigen::SparseMatrix<double > A_sparse_diff = Eigen::SparseMatrix<double >(A_sparse);
180188 Eigen::VectorXd b_x_diff = Eigen::VectorXd (b_x);
181189 Eigen::VectorXd b_y_diff = Eigen::VectorXd (b_y);
182190 if (iteration != 0 )
183191 populate_update_hybrid_matrix (A_sparse_diff, b_x_diff, b_y_diff, p_placement, iteration);
184192
185193 VTR_LOG (" Running Quadratic Solver\n " );
186-
194+ # ifdef ANALYTICAL_PLACEMENT_TIMING
187195 auto timer3 = std::chrono::high_resolution_clock::now ();
196+ #endif
188197 // Solve Ax=b and fills placement with x.
189198 Eigen::VectorXd x, y;
190199 Eigen::ConjugateGradient<Eigen::SparseMatrix<double >, Eigen::Lower | Eigen::Upper> cg;
@@ -197,16 +206,20 @@ void QPHybridSolver::solve(unsigned iteration, PartialPlacement& p_placement) {
197206 VTR_ASSERT (cg.info () == Eigen::Success && " Conjugate Gradient failed at solving b_x!" );
198207 y = cg.solve (b_y_diff);
199208 VTR_ASSERT (cg.info () == Eigen::Success && " Conjugate Gradient failed at solving b_y!" );
209+ #ifdef ANALYTICAL_PLACEMENT_TIMING
200210 auto timer4 = std::chrono::high_resolution_clock::now ();
211+ #endif
201212 for (size_t node_id = 0 ; node_id < p_placement.num_moveable_nodes ; node_id++) {
202213 p_placement.node_loc_x [node_id] = x[node_id];
203214 p_placement.node_loc_y [node_id] = y[node_id];
204215 }
216+ #ifdef ANALYTICAL_PLACEMENT_TIMING
205217 auto timer5 = std::chrono::high_resolution_clock::now ();
206218 time_counter[" build matrix" ] += std::chrono::duration_cast<std::chrono::duration<double >>(timer2 - timer1).count ();
207219 time_counter[" update matrix" ] += std::chrono::duration_cast<std::chrono::duration<double >>(timer3 - timer2).count ();
208220 time_counter[" solve matrix" ] += std::chrono::duration_cast<std::chrono::duration<double >>(timer4 - timer3).count ();
209221 time_counter[" total solve time" ] += std::chrono::duration_cast<std::chrono::duration<double >>(timer5 - timer1).count ();
222+ #endif
210223}
211224
212225void B2BSolver::initialize_placement_random_normal (PartialPlacement& p_placement) {
@@ -399,11 +412,15 @@ void B2BSolver::b2b_solve_loop(unsigned iteration, PartialPlacement& p_placement
399412 previous_hpwl = current_hpwl;
400413 VTR_LOG (" placement hpwl in b2b loop: %f\n " , p_placement.get_HPWL ());
401414 VTR_ASSERT_DEBUG (p_placement.is_valid_partial_placement () && " did not produce a valid placement in b2b solve loop" );
415+ #ifdef ANALYTICAL_PLACEMENT_TIMING
402416 auto timer1 = std::chrono::high_resolution_clock::now ();
417+ #endif
403418 populate_matrix (p_placement);
404419 if (iteration != 0 )
405420 populate_matrix_anchor (p_placement, iteration);
421+ #ifdef ANALYTICAL_PLACEMENT_TIMING
406422 auto timer2 = std::chrono::high_resolution_clock::now ();
423+ #endif
407424 Eigen::VectorXd x, y;
408425 Eigen::ConjugateGradient<Eigen::SparseMatrix<double >, Eigen::Lower | Eigen::Upper> cg_x;
409426 Eigen::ConjugateGradient<Eigen::SparseMatrix<double >, Eigen::Lower | Eigen::Upper> cg_y;
@@ -423,7 +440,9 @@ void B2BSolver::b2b_solve_loop(unsigned iteration, PartialPlacement& p_placement
423440 VTR_ASSERT_DEBUG (cg_y.info () == Eigen::Success && " Conjugate Gradient failed at compute for A_y!" );
424441 x = cg_x.solve (b_x);
425442 y = cg_y.solve (b_y);
443+ #ifdef ANALYTICAL_PLACEMENT_TIMING
426444 auto timer3 = std::chrono::high_resolution_clock::now ();
445+ #endif
427446 // These assertion are not valid because we do not need cg to converge. And often they do not converge with in default max iterations.
428447 // VTR_ASSERT(cg_x.info() == Eigen::Success && "Conjugate Gradient failed at solving b_x!");
429448 // VTR_ASSERT(cg_y.info() == Eigen::Success && "Conjugate Gradient failed at solving b_y!");
@@ -439,18 +458,24 @@ void B2BSolver::b2b_solve_loop(unsigned iteration, PartialPlacement& p_placement
439458 // }while(std::abs(current_hpwl - previous_hpwl) < 5 && counter < 100);
440459 // current_hpwl > previous_hpwl - 10 would not work when this tries to grow and converge to legalized solution
441460 // simplest one for now
461+ #ifdef ANALYTICAL_PLACEMENT_TIMING
442462 time_counter[" build matrix" ] += std::chrono::duration_cast<std::chrono::duration<double >>(timer2 - timer1).count ();
443463 time_counter[" solve matrix" ] += std::chrono::duration_cast<std::chrono::duration<double >>(timer3 - timer2).count ();
464+ #endif
444465 }
445466}
446467
447468void B2BSolver::solve (unsigned iteration, PartialPlacement& p_placement) {
469+ #ifdef ANALYTICAL_PLACEMENT_TIMING
448470 auto timer1 = std::chrono::high_resolution_clock::now ();
471+ #endif
449472 // Need an initial placement to decide who are the bounding nodes.
450473 if (iteration == 0 ) {
474+ #ifdef ANALYTICAL_PLACEMENT_TIMING
451475 time_counter[" build matrix" ] = 0 ;
452476 time_counter[" solve matrix" ] = 0 ;
453477 time_counter[" total solve time" ] = 0 ;
478+ #endif
454479
455480 initialize_placement_least_dense (p_placement);
456481 size_t ASize = p_placement.num_moveable_nodes ;
@@ -471,8 +496,10 @@ void B2BSolver::solve(unsigned iteration, PartialPlacement& p_placement) {
471496 p_placement.node_loc_x = node_loc_x_solved;
472497 p_placement.node_loc_y = node_loc_y_solved;
473498 b2b_solve_loop (iteration, p_placement);
499+ #ifdef ANALYTICAL_PLACEMENT_TIMING
474500 auto timer2 = std::chrono::high_resolution_clock::now ();
475501 time_counter[" total solve time" ] += std::chrono::duration_cast<std::chrono::duration<double >>(timer2 - timer1).count ();
502+ #endif
476503 // store solved position in data structure of this class
477504 // node_loc_x_solved = p_placement.node_loc_x;
478505 // node_loc_y_solved = p_placement.node_loc_y;
0 commit comments