-
Notifications
You must be signed in to change notification settings - Fork 446
Expand file tree
/
Copy pathdraw_basic.cpp
More file actions
1376 lines (1133 loc) · 58.1 KB
/
Copy pathdraw_basic.cpp
File metadata and controls
1376 lines (1133 loc) · 58.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* draw_basic.cpp contains all functions that draw in the main graphics area
* that aren't RR nodes or muxes (they have their own file).
* All functions in this file contain the prefix draw_. */
#ifndef NO_GRAPHICS
#include <cstdio>
#include <numbers>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <array>
#include "physical_types_util.h"
#include "vtr_assert.h"
#include "vtr_ndoffsetmatrix.h"
#include "vtr_color_map.h"
#include "vpr_utils.h"
#include "vpr_error.h"
#include "globals.h"
#include "draw_color.h"
#include "draw.h"
#include "draw_rr.h"
#include "draw_rr_edges.h"
#include "draw_basic.h"
#include "draw_triangle.h"
#include "draw_global.h"
#include "move_utils.h"
#include "route_export.h"
#include "tatum/report/TimingPathCollector.hpp"
//To process key presses we need the X11 keysym definitions,
//which are unavailable when building with MINGW
#if defined(X11) && !defined(__MINGW32__)
#include <X11/keysym.h>
#endif
#include "route_utilization.h"
#include "place_macro.h"
/****************************** Define Macros *******************************/
#define DEFAULT_RR_NODE_COLOR ezgl::BLACK
#define OLD_BLK_LOC_COLOR blk_GOLD
#define NEW_BLK_LOC_COLOR blk_GREEN
constexpr float EMPTY_BLOCK_LIGHTEN_FACTOR = 0.20;
const std::vector<ezgl::color> kelly_max_contrast_colors = {
//ezgl::color(242, 243, 244), //white: skip white since it doesn't contrast well with VPR's light background
ezgl::color(34, 34, 34), //black
ezgl::color(243, 195, 0), //yellow
ezgl::color(135, 86, 146), //purple
ezgl::color(243, 132, 0), //orange
ezgl::color(161, 202, 241), //light blue
ezgl::color(190, 0, 50), //red
ezgl::color(194, 178, 128), //buf
ezgl::color(132, 132, 130), //gray
ezgl::color(0, 136, 86), //green
ezgl::color(230, 143, 172), //purplish pink
ezgl::color(0, 103, 165), //blue
ezgl::color(249, 147, 121), //yellowish pink
ezgl::color(96, 78, 151), //violet
ezgl::color(246, 166, 0), //orange yellow
ezgl::color(179, 68, 108), //purplish red
ezgl::color(220, 211, 0), //greenish yellow
ezgl::color(136, 45, 23), //redish brown
ezgl::color(141, 182, 0), //yellow green
ezgl::color(101, 69, 34), //yellowish brown
ezgl::color(226, 88, 34), //reddish orange
ezgl::color(43, 61, 38) //olive green
};
/* Draws the blocks placed on the proper clbs. Occupied blocks are darker colours *
* while empty ones are lighter colours and have a dashed border. */
void drawplace(ezgl::renderer* g) {
t_draw_state* draw_state = get_draw_state_vars();
t_draw_coords* draw_coords = get_draw_coords_vars();
const auto& device_ctx = g_vpr_ctx.device();
const auto& cluster_ctx = g_vpr_ctx.clustering();
const auto& grid_blocks = draw_state->get_graphics_blk_loc_registry_ref().grid_blocks();
ClusterBlockId bnum;
int num_sub_tiles;
int total_num_layers = device_ctx.grid.get_num_layers();
g->set_line_width(0);
for (int layer_num = 0; layer_num < total_num_layers; layer_num++) {
if (draw_state->draw_layer_display[layer_num].visible) {
for (int i = 0; i < (int)device_ctx.grid.width(); i++) {
for (int j = 0; j < (int)device_ctx.grid.height(); j++) {
/* Only the first block of a group should control drawing */
const auto& type = device_ctx.grid.get_physical_type({i, j, layer_num});
int width_offset = device_ctx.grid.get_width_offset({i, j, layer_num});
int height_offset = device_ctx.grid.get_height_offset({i, j, layer_num});
//The transparency level for the current layer being drawn (0-255)
// 0 - opaque, 255 - transparent
int transparency_factor = draw_state->draw_layer_display[layer_num].alpha;
if (width_offset > 0
|| height_offset > 0)
continue;
num_sub_tiles = type->capacity;
/* Don't draw if tile capacity is zero. eg-> corners. */
if (num_sub_tiles == 0) {
continue;
}
for (int k = 0; k < num_sub_tiles; ++k) {
/* Look at the tile at start of large block */
bnum = grid_blocks.block_at_location({i, j, k, layer_num});
/* Fill background for the clb. Do not fill if "show_blk_internal"
* is toggled.
*/
//Determine the block color and logical type
ezgl::color block_color;
t_logical_block_type_ptr logical_block_type = nullptr;
//flag whether the current location is highlighted with a special color or not
bool current_loc_is_highlighted = false;
if (placer_breakpoint_reached()) {
t_pl_loc curr_loc;
curr_loc.x = i;
curr_loc.y = j;
curr_loc.layer = layer_num;
current_loc_is_highlighted = highlight_loc_with_specific_color(curr_loc,
block_color);
}
// No color specified at this location; use the block color.
if (!current_loc_is_highlighted) {
if (bnum) {
block_color = draw_state->block_color(bnum);
} else {
block_color = get_block_type_color(type);
block_color = lighten_color(block_color,
EMPTY_BLOCK_LIGHTEN_FACTOR);
}
}
logical_block_type = pick_logical_type(type);
g->set_color(block_color, transparency_factor);
/* Get coords of current sub_tile */
ezgl::rectangle abs_clb_bbox = draw_coords->get_absolute_clb_bbox(layer_num,
i,
j,
k,
logical_block_type);
ezgl::point2d center = abs_clb_bbox.center();
g->fill_rectangle(abs_clb_bbox);
g->set_color(ezgl::BLACK, transparency_factor);
g->set_line_dash((bnum == ClusterBlockId::INVALID()) ? ezgl::line_dash::asymmetric_5_3 : ezgl::line_dash::none);
if (draw_state->draw_block_outlines) {
g->draw_rectangle(abs_clb_bbox);
}
if (draw_state->draw_block_text) {
/* Draw text if the space has parts of the netlist */
if (bnum) {
std::string name = cluster_ctx.clb_nlist.block_name(
bnum)
+ vtr::string_fmt(" (#%zu)", size_t(bnum));
g->draw_text(center, name.c_str(), abs_clb_bbox.width(),
abs_clb_bbox.height());
}
/* Draw text for block type so that user knows what block */
if (width_offset == 0
&& height_offset == 0) {
std::string block_type_loc = type->name;
block_type_loc += vtr::string_fmt(" (%d,%d)", i, j);
g->draw_text(
center
- ezgl::point2d(0,
abs_clb_bbox.height() / 4),
block_type_loc.c_str(), abs_clb_bbox.width(),
abs_clb_bbox.height());
}
}
}
}
}
}
}
}
/* This routine draws the nets on the placement. The nets have not *
* yet been routed, so we just draw a chain showing a possible path *
* for each net. This gives some idea of future congestion. */
void drawnets(ezgl::renderer* g) {
t_draw_state* draw_state = get_draw_state_vars();
t_draw_coords* draw_coords = get_draw_coords_vars();
const auto& cluster_ctx = g_vpr_ctx.clustering();
const auto& block_locs = draw_state->get_graphics_blk_loc_registry_ref().block_locs();
g->set_line_dash(ezgl::line_dash::none);
g->set_line_width(0);
int driver_block_layer_num = -1;
int sink_block_layer_num = -1;
/* Draw the net as a star from the source to each sink. Draw from centers of *
* blocks (or sub blocks in the case of IOs). */
for (ClusterNetId net_id : cluster_ctx.clb_nlist.nets()) {
if (cluster_ctx.clb_nlist.net_is_ignored(net_id)) {
continue; /* Don't draw */
}
if ((int)cluster_ctx.clb_nlist.net_pins(net_id).size() - 1 > draw_state->draw_net_max_fanout) {
continue;
}
ClusterBlockId b1 = cluster_ctx.clb_nlist.net_driver_block(net_id);
//The layer of the net driver block
driver_block_layer_num = block_locs[b1].loc.layer;
//To only show nets that are connected to currently active layers on the screen
if (!draw_state->draw_layer_display[driver_block_layer_num].visible) {
continue; /* Don't draw */
}
ezgl::point2d driver_center = draw_coords->get_absolute_clb_bbox(b1, cluster_ctx.clb_nlist.block_type(b1)).center();
for (ClusterPinId pin_id : cluster_ctx.clb_nlist.net_sinks(net_id)) {
ClusterBlockId b2 = cluster_ctx.clb_nlist.pin_block(pin_id);
//the layer of the pin block (net sinks)
sink_block_layer_num = block_locs[b2].loc.layer;
t_draw_layer_display element_visibility = get_element_visibility_and_transparency(driver_block_layer_num, sink_block_layer_num);
if (!element_visibility.visible) {
continue; /* Don't Draw */
}
// Take the highest of the 2 transparency values that the user can select from the UI
// Compare the current cross layer transparency to the overall Net transparency set by the user.
int transparency = std::min(element_visibility.alpha, draw_state->net_color[net_id].alpha * draw_state->net_alpha / 255);
g->set_color(draw_state->net_color[net_id], transparency);
ezgl::point2d sink_center = draw_coords->get_absolute_clb_bbox(b2, cluster_ctx.clb_nlist.block_type(b2)).center();
g->draw_line(driver_center, sink_center);
/* Uncomment to draw a chain instead of a star. */
/* driver_center = sink_center; */
}
}
}
/* Draws all the overused routing resources (i.e. congestion) in various contrasting colors showing congestion ratio. */
void draw_congestion(ezgl::renderer* g) {
t_draw_state* draw_state = get_draw_state_vars();
if (draw_state->show_congestion == DRAW_NO_CONGEST) {
return;
}
auto& device_ctx = g_vpr_ctx.device();
const auto& rr_graph = device_ctx.rr_graph;
auto& route_ctx = g_vpr_ctx.routing();
//Record min/max congestion
float min_congestion_ratio = 1.;
float max_congestion_ratio = min_congestion_ratio;
auto congested_rr_nodes = collect_congested_rr_nodes();
for (RRNodeId inode : congested_rr_nodes) {
short occ = route_ctx.rr_node_route_inf[inode].occ();
short capacity = rr_graph.node_capacity(inode);
float congestion_ratio = float(occ) / capacity;
max_congestion_ratio = std::max(max_congestion_ratio, congestion_ratio);
}
char msg[vtr::bufsize];
if (draw_state->show_congestion == DRAW_CONGESTED) {
sprintf(msg, "RR Node Overuse ratio range (%.2f, %.2f]", min_congestion_ratio, max_congestion_ratio);
} else {
VTR_ASSERT(draw_state->show_congestion == DRAW_CONGESTED_WITH_NETS);
sprintf(msg, "RR Node Overuse ratio range (%.2f, %.2f] (and congested nets)", min_congestion_ratio, max_congestion_ratio);
}
application.update_message(msg);
std::shared_ptr<vtr::ColorMap> cmap = std::make_shared<vtr::PlasmaColorMap>(min_congestion_ratio, max_congestion_ratio);
//Sort the nodes in ascending order of value for drawing, this ensures high
//valued nodes are not overdrawn by lower value ones (e.g-> when zoomed-out far)
auto cmp_ascending_acc_cost = [&](RRNodeId lhs_node, RRNodeId rhs_node) {
short lhs_occ = route_ctx.rr_node_route_inf[lhs_node].occ();
short lhs_capacity = rr_graph.node_capacity(lhs_node);
short rhs_occ = route_ctx.rr_node_route_inf[rhs_node].occ();
short rhs_capacity = rr_graph.node_capacity(rhs_node);
float lhs_cong_ratio = float(lhs_occ) / lhs_capacity;
float rhs_cong_ratio = float(rhs_occ) / rhs_capacity;
return lhs_cong_ratio < rhs_cong_ratio;
};
std::stable_sort(congested_rr_nodes.begin(), congested_rr_nodes.end(), cmp_ascending_acc_cost);
if (draw_state->show_congestion == DRAW_CONGESTED_WITH_NETS) {
auto rr_node_nets = collect_rr_node_nets();
for (RRNodeId inode : congested_rr_nodes) {
for (ClusterNetId net : rr_node_nets[inode]) {
ezgl::color color = kelly_max_contrast_colors[size_t(net) % kelly_max_contrast_colors.size()];
draw_state->net_color[net] = color;
}
}
g->set_line_width(0);
draw_route(HIGHLIGHTED, g);
//Reset colors
for (RRNodeId inode : congested_rr_nodes) {
for (ClusterNetId net : rr_node_nets[inode]) {
draw_state->net_color[net] = DEFAULT_RR_NODE_COLOR;
}
}
} else {
g->set_line_width(2);
}
//Draw each congested node
for (RRNodeId inode : congested_rr_nodes) {
int layer_num = rr_graph.node_layer(inode);
int transparency_factor = get_rr_node_transparency(inode);
if (!draw_state->draw_layer_display[layer_num].visible)
continue;
short occ = route_ctx.rr_node_route_inf[inode].occ();
short capacity = rr_graph.node_capacity(inode);
float congestion_ratio = float(occ) / capacity;
bool node_congested = (occ > capacity);
VTR_ASSERT(node_congested);
ezgl::color color = to_ezgl_color(cmap->color(congestion_ratio));
color.alpha = transparency_factor;
switch (rr_graph.node_type(inode)) {
case e_rr_type::CHANX: //fallthrough
case e_rr_type::CHANY:
draw_rr_chan(inode, color, g);
break;
case e_rr_type::IPIN: //fallthrough
case e_rr_type::OPIN:
draw_cluster_pin(inode, color, g);
break;
default:
break;
}
}
draw_state->color_map = std::move(cmap);
}
/* Draws routing resource nodes colored according to their congestion costs */
void draw_routing_costs(ezgl::renderer* g) {
t_draw_state* draw_state = get_draw_state_vars();
/* show_routing_costs controls whether the total/sum of the costs or individual
* cost components (base cost, accumulated cost, present cost) are shown, and
* whether colours are proportional to the node's cost or the logarithm of
* it's cost.*/
if (draw_state->show_routing_costs == DRAW_NO_ROUTING_COSTS) {
return;
}
auto& device_ctx = g_vpr_ctx.device();
auto& route_ctx = g_vpr_ctx.routing();
g->set_line_width(0);
VTR_ASSERT(!route_ctx.rr_node_route_inf.empty());
float min_cost = std::numeric_limits<float>::infinity();
float max_cost = -min_cost;
size_t node_count = device_ctx.rr_graph.nodes().size();
vtr::vector<RRNodeId, float> rr_node_costs(node_count, 0.);
for (const RRNodeId inode : device_ctx.rr_graph.nodes()) {
float cost = 0.;
if (draw_state->show_routing_costs == DRAW_TOTAL_ROUTING_COSTS
|| draw_state->show_routing_costs
== DRAW_LOG_TOTAL_ROUTING_COSTS) {
cost = get_single_rr_cong_cost(inode,
get_draw_state_vars()->pres_fac);
} else if (draw_state->show_routing_costs == DRAW_BASE_ROUTING_COSTS) {
cost = get_single_rr_cong_base_cost(inode);
} else if (draw_state->show_routing_costs == DRAW_ACC_ROUTING_COSTS
|| draw_state->show_routing_costs
== DRAW_LOG_ACC_ROUTING_COSTS) {
cost = get_single_rr_cong_acc_cost(inode);
} else {
VTR_ASSERT(
draw_state->show_routing_costs == DRAW_PRES_ROUTING_COSTS
|| draw_state->show_routing_costs
== DRAW_LOG_PRES_ROUTING_COSTS);
cost = get_single_rr_cong_pres_cost(inode,
get_draw_state_vars()->pres_fac);
}
if (draw_state->show_routing_costs == DRAW_LOG_TOTAL_ROUTING_COSTS
|| draw_state->show_routing_costs == DRAW_LOG_ACC_ROUTING_COSTS
|| draw_state->show_routing_costs
== DRAW_LOG_PRES_ROUTING_COSTS) {
cost = std::log(cost);
}
rr_node_costs[inode] = cost;
min_cost = std::min(min_cost, cost);
max_cost = std::max(max_cost, cost);
}
//Hide min value, draw_rr_costs() ignores NaN's
for (RRNodeId inode : device_ctx.rr_graph.nodes()) {
if (rr_node_costs[inode] == min_cost) {
rr_node_costs[inode] = NAN;
}
}
char msg[vtr::bufsize];
if (draw_state->show_routing_costs == DRAW_TOTAL_ROUTING_COSTS) {
sprintf(msg, "Total Congestion Cost Range [%g, %g]", min_cost,
max_cost);
} else if (draw_state->show_routing_costs == DRAW_LOG_TOTAL_ROUTING_COSTS) {
sprintf(msg, "Log Total Congestion Cost Range [%g, %g]", min_cost,
max_cost);
} else if (draw_state->show_routing_costs == DRAW_BASE_ROUTING_COSTS) {
sprintf(msg, "Base Congestion Cost Range [%g, %g]", min_cost, max_cost);
} else if (draw_state->show_routing_costs == DRAW_ACC_ROUTING_COSTS) {
sprintf(msg, "Accumulated (Historical) Congestion Cost Range [%g, %g]",
min_cost, max_cost);
} else if (draw_state->show_routing_costs == DRAW_LOG_ACC_ROUTING_COSTS) {
sprintf(msg,
"Log Accumulated (Historical) Congestion Cost Range [%g, %g]",
min_cost, max_cost);
} else if (draw_state->show_routing_costs == DRAW_PRES_ROUTING_COSTS) {
sprintf(msg, "Present Congestion Cost Range [%g, %g]", min_cost,
max_cost);
} else if (draw_state->show_routing_costs == DRAW_LOG_PRES_ROUTING_COSTS) {
sprintf(msg, "Log Present Congestion Cost Range [%g, %g]", min_cost,
max_cost);
} else {
sprintf(msg, "Cost Range [%g, %g]", min_cost, max_cost);
}
application.update_message(msg);
draw_rr_costs(g, rr_node_costs, true);
}
/* Draws bounding box (BB) in which legal RR node start/end points must be contained */
void draw_routing_bb(ezgl::renderer* g) {
t_draw_state* draw_state = get_draw_state_vars();
if (draw_state->show_routing_bb == OPEN) {
return;
}
auto& route_ctx = g_vpr_ctx.routing();
auto& cluster_ctx = g_vpr_ctx.clustering();
VTR_ASSERT(draw_state->show_routing_bb != OPEN);
VTR_ASSERT(draw_state->show_routing_bb < (int)route_ctx.route_bb.size());
t_draw_coords* draw_coords = get_draw_coords_vars();
auto net_id = ParentNetId(draw_state->show_routing_bb);
const t_bb* bb = &route_ctx.route_bb[net_id];
//The router considers an RR node to be 'within' the the bounding box if it
//is *loosely* greater (i.e. greater than or equal) the left/bottom edges, and
//it is *loosely* less (i.e. less than or equal) the right/top edges.
//
//In the graphics we represent this by drawing the BB so that legal RR node start/end points
//are contained within the drawn box. Since VPR associates each x/y channel location to
//the right/top of the tile with the same x/y cordinates, this means we draw the box so that:
// * The left edge is to the left of the channel at bb xmin (including the channel at xmin)
// * The bottom edge is to the below of the channel at bb ymin (including the channel at ymin)
// * The right edge is to the right of the channel at bb xmax (including the channel at xmax)
// * The top edge is to the right of the channel at bb ymax (including the channel at ymax)
//Since tile_x/tile_y correspond to the drawing coordinates the block at grid x/y's bottom-left corner
//this means we need to shift the top/right drawn co-ordinate one tile + channel width right/up so
//the drawn box contains the top/right channels
double draw_xlow = draw_coords->tile_x[bb->xmin];
double draw_ylow = draw_coords->tile_y[bb->ymin];
double draw_xhigh = draw_coords->tile_x[bb->xmax]
+ 2 * draw_coords->get_tile_width();
double draw_yhigh = draw_coords->tile_y[bb->ymax]
+ 2 * draw_coords->get_tile_height();
g->set_color(blk_RED);
g->draw_rectangle({draw_xlow, draw_ylow}, {draw_xhigh, draw_yhigh});
ezgl::color fill = blk_SKYBLUE;
fill.alpha *= 0.3;
g->set_color(fill);
g->fill_rectangle({draw_xlow, draw_ylow}, {draw_xhigh, draw_yhigh});
draw_routed_net(net_id, g);
std::string msg;
msg += "Showing BB";
msg += " (" + std::to_string(bb->xmin) + ", " + std::to_string(bb->ymin)
+ ", " + std::to_string(bb->xmax) + ", " + std::to_string(bb->ymax)
+ ")";
msg += " and routing for net '" + cluster_ctx.clb_nlist.net_name(convert_to_cluster_net_id(net_id))
+ "'";
msg += " (#" + std::to_string(size_t(net_id)) + ")";
application.update_message(msg.c_str());
}
/* Draws an X centered at (x,y). The width and height of the X are each 2 * size. */
void draw_x(float x, float y, float size, ezgl::renderer* g) {
g->draw_line({x - size, y + size}, {x + size, y - size});
g->draw_line({x - size, y - size}, {x + size, y + size});
}
/* Draws the nets in the positions fixed by the router. If draw_net_type is *
* ALL_NETS, draw all the nets. If it is HIGHLIGHTED, draw only the nets *
* that are not coloured black (useful for drawing over the rr_graph). */
void draw_route(enum e_draw_net_type draw_net_type, ezgl::renderer* g) {
/* Next free track in each channel segment if routing is GLOBAL */
auto& cluster_ctx = g_vpr_ctx.clustering();
const AtomContext& atom_ctx = g_vpr_ctx.atom();
t_draw_state* draw_state = get_draw_state_vars();
g->set_line_dash(ezgl::line_dash::none);
g->set_color(ezgl::BLACK, draw_state->net_alpha);
/* Now draw each net, one by one. */
if (draw_state->is_flat) {
for (AtomNetId net_id : atom_ctx.netlist().nets()) {
if (draw_net_type == HIGHLIGHTED
&& draw_state->net_color[net_id] == ezgl::BLACK)
continue;
draw_routed_net((ParentNetId&)net_id, g);
} /* End for (each net) */
} else {
for (ClusterNetId net_id : cluster_ctx.clb_nlist.nets()) {
if (draw_net_type == HIGHLIGHTED
&& draw_state->net_color[net_id] == ezgl::BLACK)
continue;
draw_routed_net((ParentNetId&)net_id, g);
} /* End for (each net) */
}
}
void draw_routed_net(ParentNetId net_id, ezgl::renderer* g) {
auto& route_ctx = g_vpr_ctx.routing();
t_draw_state* draw_state = get_draw_state_vars();
if (!route_ctx.route_trees[net_id]) // No routing -> Skip. (Allows me to draw partially complete routes)
return;
std::vector<RRNodeId> rr_nodes_to_draw;
for (auto& rt_node : route_ctx.route_trees[net_id].value().all_nodes()) {
RRNodeId inode = rt_node.inode;
if (draw_if_net_highlighted(net_id)) {
/* If a net has been highlighted, highlight the whole net in *
* the same color. */
draw_state->draw_rr_node[inode].color = draw_state->net_color[net_id];
draw_state->draw_rr_node[inode].node_highlighted = true;
} else {
/* If not highlighted, draw the node in default color. */
draw_state->draw_rr_node[inode].color = DEFAULT_RR_NODE_COLOR;
}
// When drawing a new branch, add the parent node to the vector to ensure that the conenction is drawn.
if (rr_nodes_to_draw.empty() && rt_node.parent().has_value()) {
rr_nodes_to_draw.push_back(rt_node.parent().value().inode);
}
rr_nodes_to_draw.push_back(inode);
if (rt_node.is_leaf()) { // End of branch
draw_partial_route(rr_nodes_to_draw, g);
rr_nodes_to_draw.clear();
}
} /* End loop over route tree. */
draw_partial_route(rr_nodes_to_draw, g);
}
//Draws the set of rr_nodes specified, using the colors set in draw_state
void draw_partial_route(const std::vector<RRNodeId>& rr_nodes_to_draw, ezgl::renderer* g) {
t_draw_state* draw_state = get_draw_state_vars();
auto& rr_graph = g_vpr_ctx.device().rr_graph;
// Draw RR Nodes
for (size_t i = 1; i < rr_nodes_to_draw.size(); ++i) {
RRNodeId inode = rr_nodes_to_draw[i];
ezgl::color color = draw_state->draw_rr_node[inode].color;
bool inter_cluster_node = is_inter_cluster_node(rr_graph, inode);
if (inter_cluster_node && !draw_state->draw_inter_cluster_nets) {
continue;
}
if (!inter_cluster_node && !draw_state->draw_intra_cluster_nets) {
continue;
}
draw_rr_node(inode, color, g);
}
// Draw Edges
for (size_t i = 1; i < rr_nodes_to_draw.size(); ++i) {
RRNodeId inode = rr_nodes_to_draw[i];
RRNodeId prev_node = rr_nodes_to_draw[i - 1];
bool inter_cluster_node = is_inter_cluster_node(rr_graph, inode);
bool prev_inter_cluster_node = is_inter_cluster_node(rr_graph, prev_node);
if ((inter_cluster_node && prev_inter_cluster_node) && !draw_state->draw_inter_cluster_nets) {
continue;
}
if ((!inter_cluster_node || !prev_inter_cluster_node) && !draw_state->draw_intra_cluster_nets) {
continue;
}
draw_rr_edge(inode, prev_node, draw_state->draw_rr_node[inode].color, g);
}
}
/* Helper function that checks whether the edges between the current and previous nodes can be drawn
* based on whether the cross-layer connections option is enabled and whether the layer on which the
* nodes are located are enabled.
*/
bool is_edge_valid_to_draw(RRNodeId current_node, RRNodeId prev_node) {
t_draw_state* draw_state = get_draw_state_vars();
auto& rr_graph = g_vpr_ctx.device().rr_graph;
int current_node_layer = rr_graph.node_layer(current_node);
int prev_node_layer = rr_graph.node_layer(prev_node);
if (!(is_inter_cluster_node(rr_graph, current_node)) || !(is_inter_cluster_node(rr_graph, prev_node))) {
return false;
}
if (current_node_layer != prev_node_layer) {
if (draw_state->cross_layer_display.visible && draw_state->draw_layer_display[current_node_layer].visible && draw_state->draw_layer_display[prev_node_layer].visible) {
return true; //if both layers are enabled and cross layer connections are enabled
} else {
return false; //if cross layer connections are disabled or if either the current or prev node's layers are disabled
}
} else {
return draw_state->draw_layer_display[current_node_layer].visible; //if both nodes are from the same layer
}
}
/* Draws any placement macros (e.g. carry chains, which require specific relative placements
* between some blocks) if the Placement Macros (in the GUI) is selected.
*/
void draw_placement_macros(ezgl::renderer* g) {
t_draw_state* draw_state = get_draw_state_vars();
if (draw_state->show_placement_macros == DRAW_NO_PLACEMENT_MACROS) {
return;
}
t_draw_coords* draw_coords = get_draw_coords_vars();
const auto& block_locs = draw_state->get_graphics_blk_loc_registry_ref().block_locs();
VTR_ASSERT(g_vpr_ctx.placement().place_macros);
const PlaceMacros& place_macros = *g_vpr_ctx.placement().place_macros;
for (const t_pl_macro& pl_macro : place_macros.macros()) {
//TODO: for now we just draw the bounding box of the macro, which is incorrect for non-rectangular macros...
int xlow = std::numeric_limits<int>::max();
int ylow = std::numeric_limits<int>::max();
int xhigh = std::numeric_limits<int>::min();
int yhigh = std::numeric_limits<int>::min();
int x_root = OPEN;
int y_root = OPEN;
for (size_t imember = 0; imember < pl_macro.members.size(); ++imember) {
const t_pl_macro_member& member = pl_macro.members[imember];
ClusterBlockId blk = member.blk_index;
if (imember == 0) {
x_root = block_locs[blk].loc.x;
y_root = block_locs[blk].loc.y;
}
int x = x_root + member.offset.x;
int y = y_root + member.offset.y;
xlow = std::min(xlow, x);
ylow = std::min(ylow, y);
xhigh = std::max(xhigh, x + physical_tile_type(block_locs[blk].loc)->width);
yhigh = std::max(yhigh, y + physical_tile_type(block_locs[blk].loc)->height);
}
double draw_xlow = draw_coords->tile_x[xlow];
double draw_ylow = draw_coords->tile_y[ylow];
double draw_xhigh = draw_coords->tile_x[xhigh];
double draw_yhigh = draw_coords->tile_y[yhigh];
g->set_color(blk_RED);
g->draw_rectangle({draw_xlow, draw_ylow},
{draw_xhigh, draw_yhigh});
ezgl::color fill = blk_SKYBLUE;
fill.alpha *= 0.3;
g->set_color(fill);
g->fill_rectangle({draw_xlow, draw_ylow},
{draw_xhigh, draw_yhigh});
}
}
/* Draws a heat map of routing wire utilization (i.e. fraction of wires used in each channel)
* when a routing is shown on-screen and Routing Util (on the GUI) is selected.
* Lighter colours (e.g. yellow) correspond to highly utilized
* channels, while darker colours (e.g. blue) correspond to lower utilization.*/
void draw_routing_util(ezgl::renderer* g) {
t_draw_state* draw_state = get_draw_state_vars();
if (draw_state->show_routing_util == DRAW_NO_ROUTING_UTIL) {
return;
}
t_draw_coords* draw_coords = get_draw_coords_vars();
auto& device_ctx = g_vpr_ctx.device();
auto chanx_usage = calculate_routing_usage(e_rr_type::CHANX, draw_state->is_flat, false);
auto chany_usage = calculate_routing_usage(e_rr_type::CHANY, draw_state->is_flat, false);
auto chanx_avail = calculate_routing_avail(e_rr_type::CHANX);
auto chany_avail = calculate_routing_avail(e_rr_type::CHANY);
float min_util = 0.;
float max_util = -std::numeric_limits<float>::infinity();
for (size_t x = 0; x < device_ctx.grid.width() - 1; ++x) {
for (size_t y = 0; y < device_ctx.grid.height() - 1; ++y) {
max_util = std::max(max_util,
routing_util(chanx_usage[x][y], chanx_avail[x][y]));
max_util = std::max(max_util,
routing_util(chany_usage[x][y], chany_avail[x][y]));
}
}
max_util = std::max(max_util, 1.f);
std::unique_ptr<vtr::ColorMap> cmap;
if (draw_state->clip_routing_util) {
cmap = std::make_unique<vtr::PlasmaColorMap>(0., 1.);
} else {
cmap = std::make_unique<vtr::PlasmaColorMap>(min_util, max_util);
}
float tile_width = draw_coords->get_tile_width();
float tile_height = draw_coords->get_tile_height();
float ALPHA = 0.95;
if (draw_state->show_routing_util == DRAW_ROUTING_UTIL_OVER_BLOCKS) {
ALPHA = 1.;
}
for (size_t x = 0; x < device_ctx.grid.width() - 1; ++x) {
for (size_t y = 0; y < device_ctx.grid.height() - 1; ++y) {
float sb_util = 0;
float chanx_util = 0;
float chany_util = 0;
int chan_count = 0;
if (x > 0) {
chanx_util = routing_util(chanx_usage[x][y], chanx_avail[x][y]);
if (draw_state->clip_routing_util) {
chanx_util = std::min(chanx_util, 1.f);
}
ezgl::color chanx_color = to_ezgl_color(
cmap->color(chanx_util));
chanx_color.alpha *= ALPHA;
g->set_color(chanx_color);
ezgl::rectangle bb(
{draw_coords->tile_x[x], draw_coords->tile_y[y]
+ 1 * tile_height},
{draw_coords->tile_x[x] + 1 * tile_width,
draw_coords->tile_y[y + 1]});
g->fill_rectangle(bb);
g->set_color(ezgl::BLACK);
if (draw_state->show_routing_util
== DRAW_ROUTING_UTIL_WITH_VALUE) {
g->draw_text(bb.center(),
vtr::string_fmt("%.2f", chanx_util).c_str(),
bb.width(), bb.height());
} else if (draw_state->show_routing_util
== DRAW_ROUTING_UTIL_WITH_FORMULA) {
g->draw_text(bb.center(),
vtr::string_fmt("%.2f = %.0f / %.0f", chanx_util,
chanx_usage[x][y], chanx_avail[x][y])
.c_str(),
bb.width(), bb.height());
}
sb_util += chanx_util;
++chan_count;
}
if (y > 0) {
chany_util = routing_util(chany_usage[x][y], chany_avail[x][y]);
if (draw_state->clip_routing_util) {
chany_util = std::min(chany_util, 1.f);
}
ezgl::color chany_color = to_ezgl_color(
cmap->color(chany_util));
chany_color.alpha *= ALPHA;
g->set_color(chany_color);
ezgl::rectangle bb({draw_coords->tile_x[x] + 1 * tile_width,
draw_coords->tile_y[y]},
{draw_coords->tile_x[x + 1], draw_coords->tile_y[y]
+ 1 * tile_height});
g->fill_rectangle(bb);
g->set_color(ezgl::BLACK);
if (draw_state->show_routing_util
== DRAW_ROUTING_UTIL_WITH_VALUE) {
g->draw_text(bb.center(),
vtr::string_fmt("%.2f", chany_util).c_str(),
bb.width(), bb.height());
} else if (draw_state->show_routing_util
== DRAW_ROUTING_UTIL_WITH_FORMULA) {
g->draw_text(bb.center(),
vtr::string_fmt("%.2f = %.0f / %.0f", chany_util,
chany_usage[x][y], chany_avail[x][y])
.c_str(),
bb.width(), bb.height());
}
sb_util += chany_util;
++chan_count;
}
//For now SB util is just average of surrounding channels
//TODO: calculate actual usage
sb_util += routing_util(chanx_usage[x + 1][y],
chanx_avail[x + 1][y]);
chan_count += 1;
sb_util += routing_util(chany_usage[x][y + 1],
chany_avail[x][y + 1]);
chan_count += 1;
VTR_ASSERT(chan_count > 0);
sb_util /= chan_count;
if (draw_state->clip_routing_util) {
sb_util = std::min(sb_util, 1.f);
}
ezgl::color sb_color = to_ezgl_color(cmap->color(sb_util));
sb_color.alpha *= ALPHA;
g->set_color(sb_color);
ezgl::rectangle bb(
{draw_coords->tile_x[x] + 1 * tile_width,
draw_coords->tile_y[y] + 1 * tile_height},
{draw_coords->tile_x[x + 1], draw_coords->tile_y[y + 1]});
g->fill_rectangle(bb);
//Draw over blocks
if (draw_state->show_routing_util
== DRAW_ROUTING_UTIL_OVER_BLOCKS) {
if (x < device_ctx.grid.width() - 2
&& y < device_ctx.grid.height() - 2) {
ezgl::rectangle bb2({draw_coords->tile_x[x + 1],
draw_coords->tile_y[y + 1]},
{draw_coords->tile_x[x + 1] + 1 * tile_width,
draw_coords->tile_y[y + 1] + 1 * tile_width});
g->fill_rectangle(bb2);
}
}
g->set_color(ezgl::BLACK);
if (draw_state->show_routing_util == DRAW_ROUTING_UTIL_WITH_VALUE
|| draw_state->show_routing_util
== DRAW_ROUTING_UTIL_WITH_FORMULA) {
g->draw_text(bb.center(),
vtr::string_fmt("%.2f", sb_util).c_str(), bb.width(),
bb.height());
}
}
}
draw_state->color_map = std::move(cmap);
}
/* Draws the critical path if Crit. Path (in the GUI) is selected. Each stage between primitive
* pins is shown in a different colour.
* User can toggle between two different visualizations:
* a) during placement, critical path only shown as flylines
* b) during routing, critical path is shown by both flylines and routed net connections.
*/
void draw_crit_path(ezgl::renderer* g) {
tatum::TimingPathCollector path_collector;
t_draw_state* draw_state = get_draw_state_vars();
auto& timing_ctx = g_vpr_ctx.timing();
if (draw_state->show_crit_path == DRAW_NO_CRIT_PATH) {
return;
}
if (!draw_state->setup_timing_info) {
return; //No timing to draw
}
//Get the worst timing path
auto paths = path_collector.collect_worst_setup_timing_paths(
*timing_ctx.graph,
*(draw_state->setup_timing_info->setup_analyzer()), 1);
tatum::TimingPath path = paths[0];
//Walk through the timing path drawing each edge
tatum::NodeId prev_node;
float prev_arr_time = std::numeric_limits<float>::quiet_NaN();
int i = 0;
for (tatum::TimingPathElem elem : path.data_arrival_path().elements()) {
tatum::NodeId node = elem.node();
float arr_time = elem.tag().time();
if (prev_node) {
//We draw each 'edge' in a different color, this allows users to identify the stages and
//any routing which corresponds to the edge
//
//We pick colors from the kelly max-contrast list, for long paths there may be repeats
ezgl::color color = kelly_max_contrast_colors[i++
% kelly_max_contrast_colors.size()];
float delay = arr_time - prev_arr_time;
int src_block_layer = get_timing_path_node_layer_num(node);
int sink_block_layer = get_timing_path_node_layer_num(prev_node);
t_draw_layer_display flyline_visibility = get_element_visibility_and_transparency(src_block_layer, sink_block_layer);
if (draw_state->show_crit_path == DRAW_CRIT_PATH_FLYLINES
|| draw_state->show_crit_path
== DRAW_CRIT_PATH_FLYLINES_DELAYS) {
// FLylines for critical path are drawn based on the layer visibility of the source and sink
if (flyline_visibility.visible) {
g->set_color(color, flyline_visibility.alpha);
g->set_line_dash(ezgl::line_dash::none);
g->set_line_width(4);
draw_flyline_timing_edge(tnode_draw_coord(prev_node),
tnode_draw_coord(node), delay, g);
g->set_line_width(0);
}
} else {
VTR_ASSERT(draw_state->show_crit_path != DRAW_NO_CRIT_PATH);
// Draws critical path shown by both flylines and routed net connections.
//Draw the routed version of the timing edge
draw_routed_timing_edge_connection(prev_node, node, color, g);
// FLylines for critical path are drawn based on the layer visibility of the source and sink
if (flyline_visibility.visible) {
g->set_line_dash(ezgl::line_dash::asymmetric_5_3);
g->set_line_width(3);
g->set_color(color, flyline_visibility.alpha);
draw_flyline_timing_edge((ezgl::point2d)tnode_draw_coord(prev_node),
(ezgl::point2d)tnode_draw_coord(node), (float)delay,
(ezgl::renderer*)g);
g->set_line_dash(ezgl::line_dash::none);
g->set_line_width(0);
}
}
}
prev_node = node;
prev_arr_time = arr_time;
}
}
/**
* @brief Draw critical path elements.
*
* This function draws critical path elements based on the provided timing paths
* and indexes map. It is primarily used in server mode, where items are drawn upon request.
*/