OpenCores
URL https://opencores.org/ocsvn/an-fpga-implementation-of-low-latency-noc-based-mpsoc/an-fpga-implementation-of-low-latency-noc-based-mpsoc/trunk

Subversion Repositories an-fpga-implementation-of-low-latency-noc-based-mpsoc

[/] [an-fpga-implementation-of-low-latency-noc-based-mpsoc/] [trunk/] [mpsoc/] [perl_gui/] [lib/] [perl/] [trace_gen.pl] - Blame information for rev 48

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 38 alirezamon
#!/usr/bin/perl
2
use strict;
3
use warnings;
4
 
5 48 alirezamon
use constant::boolean;
6
 
7
 
8 38 alirezamon
use Data::Dumper;
9
use List::Util 'shuffle';
10
use File::Path;
11
use File::Copy;
12
use POSIX qw(ceil floor);
13
use Cwd 'abs_path';
14 48 alirezamon
use List::MoreUtils qw(uniq);
15 38 alirezamon
 
16
 
17
use base 'Class::Accessor::Fast';
18
require "widget.pl";
19
require "diagram.pl";
20 48 alirezamon
require "orcc.pl";
21
require "drag_drop.pl";
22 38 alirezamon
 
23
__PACKAGE__->mk_accessors(qw{
24
        window
25
        sourceview
26
        buffer
27
        filename
28
        search_regexp
29
        search_case
30
        search_entry
31
        regexp
32
        highlighted
33
 
34
});
35
 
36
my $NAME = 'Trace_gen';
37
 
38
 
39
exit trace_gen_main() unless caller;
40
 
41
 
42
sub trace_gen_main {
43 48 alirezamon
        my ($mode,$ref,$w)=@_;
44 38 alirezamon
        my $app = __PACKAGE__->new();
45 48 alirezamon
        my $table=$app->build_trace_gui($mode,$ref,$w);
46 38 alirezamon
 
47
        return $table;
48
}
49
 
50
 
51
 
52
########
53
#  trace_ctr
54
########
55
 
56
sub trace_pad_ctrl{
57 48 alirezamon
        my ($self,$tview,$mode)=@_;
58 38 alirezamon
 
59
        my $table= def_table(2,10,FALSE);
60 48 alirezamon
 
61 38 alirezamon
        my $row=0;
62
        my $col=0;
63
        #$table->attach ($separator , 0, 10 , $row, $row+1,'fill','fill',2,2);  $row++; 
64
 
65
        my $add = def_image_button('icons/import.png');
66 48 alirezamon
        set_tip($add,'Load Task Graph') if($mode eq "task");
67
        set_tip($add,'Load ORCC source files') if($mode eq "orcc");
68 38 alirezamon
        my $remove = def_image_button('icons/cancel.png');
69
        set_tip($remove,'Remove Selected Trace(s)');
70
        my $draw = def_image_button('icons/diagram.png');
71
        set_tip($draw,'View Task Graph');
72
        my $auto = def_image_button('icons/refresh.png');
73 48 alirezamon
        set_tip($auto,'Automatically calculate the traces burst size and injection ratio according to their bandwidth');
74 38 alirezamon
        my $box=def_pack_hbox(FALSE,FALSE,$add,$draw,$remove,$auto);
75
 
76
        #my $auto = def_image_button('icons/setting.png');
77
        #set_tip($auto,'Automatically set the burst size and injection ratio according to the packet size and bandwidth');
78
 
79
 
80
        $col=0;
81
        $table->attach ($box,$col, $col+1,  $row, $row+1,'shrink','shrink',2,2);$col++;
82
 
83
        $row++;
84
        $col=0;
85
        my $info="Automatically set the burst size and injection ratio according to the packet size and bandwidth";
86
        #add_param_widget($self,"Auto inject rate \& burst size",'Auto_inject', 0,"Check-box",1,$info, $table,$row,$col,1,'Auto',0,'ref',"vertical");
87 48 alirezamon
        $row++;
88
        $col=0;
89
        my $info1="If hard-build QoS is enabled in NoC by using Weighted round robin arbiter (WRRA) instead of RRA, then the initial weights allow QoS support in NoC as in presence of contention, packets with higher initial weights receive higher bandwidth and lower worst case delay compared to others." ;
90 38 alirezamon
 
91 48 alirezamon
        #my $selects="tornado,transposed 1,transposed 2,bit reverse,bit complement,random,hot spot"; 
92 38 alirezamon
        my $min=$self->object_get_attribute('select_multiple','min_pck_size');
93
        my $max=$self->object_get_attribute('select_multiple','max_pck_size');
94
        $min=$max=5 if(!defined $min);
95
 
96
        my @selectedinfo;
97
        $self->object_add_attribute('Auto','Auto_inject',"1\'b0" );
98
        my $a= $self->object_get_attribute('Auto','Auto_inject');
99 48 alirezamon
 
100 38 alirezamon
        if ($a eq "1\'b0"){
101
                @selectedinfo = (
102
                { label=>" Initial weight ", param_name=>'init_weight', type=>'Spin-button', default_val=>1, content=>"1,16,1", info=>$info1, param_parent=>'select_multiple', ref_delay=> undef, new_status=>undef},
103
                { label=>" Min pck size ", param_name=>'min_pck_size', type=>'Spin-button', default_val=>5, content=>"2,$max,1", info=>undef, param_parent=>'select_multiple', ref_delay=> 10, new_status=>'ref'},
104
                { label=>" Max pck size ",param_name=>'max_pck_size', type=>'Spin-button', default_val=>5, content=>"$min,1024,1", info=>undef, param_parent=>'select_multiple', ref_delay=> 10, new_status=>'ref'},
105
                { label=>" Burst_size ", param_name=>'burst_size', type=>'Spin-button', default_val=>1, content=>"1,1024,1", info=>undef, param_parent=>'select_multiple', ref_delay=> undef, new_status=>undef},
106
                { label=>" Inject rate(%) ", param_name=>'injct_rate', type=>'Spin-button', default_val=>10, content=>"1,100,1", info=>undef, param_parent=>'select_multiple', ref_delay=> undef, new_status=>undef},
107
                { label=>" Inject rate variation(%) ", param_name=>'injct_rate_var', type=>'Spin-button', default_val=>20, content=>"0,100,1", info=>undef, param_parent=>'select_multiple', ref_delay=> undef, new_status=>undef},
108
 
109
        );
110
 
111
 
112
        }else{
113
                @selectedinfo = (
114
                { label=>" Initial weight ", param_name=>'init_weight', type=>'Spin-button', default_val=>1, content=>"1,16,1", info=>undef, param_parent=>'select_multiple', ref_delay=> undef, new_status=>undef},
115
                { label=>" Min pck size ", param_name=>'min_pck_size', type=>'Spin-button', default_val=>5, content=>"2,$max,1", info=>undef, param_parent=>'select_multiple', ref_delay=> 10, new_status=>'ref'},
116
                { label=>" Max pck size ",param_name=>'max_pck_size', type=>'Spin-button', default_val=>5, content=>"$min,1024,1", info=>undef, param_parent=>'select_multiple', ref_delay=> 10, new_status=>'ref'},
117
 
118
        );
119 48 alirezamon
        }
120
        if($mode eq "orcc"){
121
                my $v_val= $self->object_get_attribute('noc_param','V');
122
                my $v_max=$v_val-1;
123
                my $c_val= $self->object_get_attribute('noc_param','C');
124
                my $c_max=($c_val==0)? 0 : $c_val-1;
125
 
126
                @selectedinfo = (
127
                { label=>" Initial weight ", param_name=>'init_weight', type=>'Spin-button', default_val=>1, content=>"1,16,1", info=>undef, param_parent=>'select_multiple', ref_delay=> undef, new_status=>undef},
128
                { label=>" Virtual chanel#", param_name=>'vc', type=>'Spin-button', default_val=>0, content=>"0,$v_max,1", info=>undef, param_parent=>'select_multiple', ref_delay=> undef, new_status=>undef},
129
                { label=>" Message class# ", param_name=>'class', type=>'Spin-button', default_val=>0, content=>"0,$c_max,1", info=>undef, param_parent=>'select_multiple', ref_delay=> undef, new_status=>undef}
130
                );
131 38 alirezamon
 
132
        }
133
 
134
 
135 48 alirezamon
        my @traces= get_trace_list($self,'raw');
136 38 alirezamon
        my $any_selected=0;
137
        foreach my $p (@traces) {
138 48 alirezamon
                my ($src,$dst, $Mbytes, $file_id, $file_name)=get_trace($self,'raw',$p);
139
                $any_selected=1 if($self->object_get_attribute("raw_$p",'selected')==1);
140 38 alirezamon
 
141
        }
142
 
143
        if($any_selected){
144 48 alirezamon
        add_Hsep_to_table($table,0, 10,  $row);$row++;
145 38 alirezamon
                $table->attach (gen_label_in_center('Apply to all selected traces'),0, 10,  $row, $row+1,'fill','fill',2,2);$row++;
146
        }
147
 
148
        foreach my $d (@selectedinfo) {
149
                my $apply= def_image_button("icons/enter.png",undef);
150
                $apply->signal_connect( 'clicked'=> sub{
151
                        $self->object_add_attribute('select_multiple','action',$d->{param_name});
152
                        $self->set_gui_status('ref',0);
153
                });
154
                if($any_selected){
155 48 alirezamon
                        ($row,$col)=add_param_widget ($self, $d->{label}, $d->{param_name}, $d->{default_val}, $d->{type}, $d->{content}, $d->{info}, $table,$row,$col,1, $d->{param_parent}, $d->{ref_delay},$d->{new_status},"horizontal");
156 38 alirezamon
                        $table->attach  ($apply , $col, $col+1,  $row,$row+1,'shrink','shrink',2,2);$row++;$col=0;
157
                #       $row=noc_param_widget ($self, $d->{label}, $d->{param_name}, $d->{default_val}, $d->{type}, $d->{content}, $d->{info}, $table,$row,1, $d->{param_parent}, $d->{ref_delay}, $d->{new_status});
158
                }
159
                }
160
 
161
 
162
 
163
 
164
 
165
        my $dir = Cwd::getcwd();
166
        my $project_dir   = abs_path("$dir/.."); #mpsoc directory address
167
 
168
 
169
        $add->signal_connect ( 'clicked'=> sub{
170 48 alirezamon
                load_task_file($self,$project_dir,$tview) if($mode eq 'task');
171
                load_orcc_file($self,$tview) if($mode eq 'orcc');
172 38 alirezamon
        });
173
 
174
        $draw->signal_connect ( 'clicked'=> sub{
175
                show_trace_diagram($self,'trace');
176
        });
177
 
178
        $remove->signal_connect ( 'clicked'=> sub{
179 48 alirezamon
                $self->remove_selected_traces('raw');
180 38 alirezamon
        });
181
 
182
        $auto->signal_connect ( 'clicked'=> sub{
183 48 alirezamon
                $self->auto_generate_injtratio('raw');
184 38 alirezamon
        });
185
 
186
 
187 48 alirezamon
        my $sc_win = add_widget_to_scrolled_win($table);
188 38 alirezamon
 
189
 
190
        return $sc_win;
191
 
192
}
193
 
194 48 alirezamon
sub load_task_file{
195
        my($self,$project_dir,$tview)=@_;
196
        my $file;
197
        my $dialog = gen_file_dialog(undef,'app');
198
        my $open_in       = abs_path("${project_dir}/perl_gui/lib/simulate/embedded_app_graphs");
199
        $dialog->set_current_folder ($open_in);
200
        if ( "ok" eq $dialog->run ) {
201
                $file = $dialog->get_filename;
202
                $self->load_tarce_file($file,$tview);
203
        }
204
        $dialog->destroy;
205
}
206 38 alirezamon
 
207
######
208
# map_ctr
209
######  
210
 
211
sub trace_map_ctrl{
212
 
213 48 alirezamon
        my ($self,$tview,$mode,$NE)=@_;
214 38 alirezamon
        my $table= def_table(2,10,FALSE);
215
 
216
        my $run_map= def_image_button("icons/enter.png",undef);
217 48 alirezamon
        my $drawmap = def_image_button('icons/trace.png');
218
        my $diagram = def_image_button('icons/diagram.png');
219
        set_tip($drawmap,'View actor Mapping Diagram') if($mode eq 'orcc');
220
        set_tip($drawmap,'View Task Mapping Diagram') if($mode eq 'task');
221
        set_tip($diagram,'View Topology Diagram') if($mode eq 'task');
222
        set_tip($diagram,'View actor connection Diagram') if($mode eq 'orcc');
223
 
224 38 alirezamon
        my $auto = def_image_button('icons/refresh.png');
225 48 alirezamon
        set_tip($auto,'Automatically set the network dimensions according to the task number');
226 38 alirezamon
        my $clean = def_image_button('icons/clear.png');
227 48 alirezamon
        set_tip($clean,'Remove mapping');
228 38 alirezamon
 
229 48 alirezamon
        my $box;
230
        $box=def_pack_hbox(FALSE,FALSE,$drawmap,$diagram,$clean,$auto) if($mode eq 'task');
231
        $box=def_pack_hbox(FALSE,FALSE,$drawmap,$diagram,$clean) if($mode eq 'orcc');
232 38 alirezamon
 
233 48 alirezamon
        my $col=0;
234
        my $row=0;
235
        $table->attach ($box,$col, $col+1,  $row, $row+1,'shrink','shrink',2,2);$row++;
236 38 alirezamon
 
237
 
238 48 alirezamon
        if($mode eq 'task'){
239
                ($row,$col) =noc_topology_setting_gui($self,$table,$tview,$row,1);
240
 
241
                $diagram-> signal_connect("clicked" => sub{
242
                show_topology_diagram ($self) ;
243
        });
244
 
245
 
246
        }
247 38 alirezamon
 
248 48 alirezamon
        if($mode eq 'orcc'){
249
 
250
                $diagram-> signal_connect("clicked" => sub{
251
 
252
                show_trace_diagram ($self,'merge-actor');
253
        });
254
 
255
 
256
        }
257 38 alirezamon
 
258 48 alirezamon
        #my $credit =$self->object_get_attribute('map_param',"credit_en");
259
        #if(defined $credit){
260
        #       if($credit eq '1\'b0'){
261
        #       $self->object_add_attribute('map_param',"receive_int",'1\'b0'); 
262
        #}}
263 38 alirezamon
 
264
 
265
 
266 48 alirezamon
        my @info = ($mode eq 'task')? (
267
        { label=>"Mapping Algorithm", param_name=>"Map_Algrm", type=>"Combo-box", default_val=>'Random', content=>"Nmap,Random,Reverse-NMAP,Direct", info=>undef, param_parent=>'map_param',ref_delay=>undef,placement=>'horizontal'},
268
        ) :
269 38 alirezamon
 
270 48 alirezamon
        (
271
        { label=>"Mapping Algorithm", param_name=>"Map_Algrm", type=>"Combo-box", default_val=>'Random', content=>"Nmap,Random,Reverse-NMAP,Direct", info=>undef, param_parent=>'map_param',ref_delay=>undef,placement=>'horizontal'},
272
        { label=>"ORCC FIFO Debug", param_name=>"add_debug", type=>"Check-box", default_val=>'1\'b0', content=>1, info=>"Add Actor FIFO debugging code to generated C codes to make sure FIFOs handshakings signals are handeled correctly between the source and destination cores", param_parent=>'map_param',ref_delay=>undef,placement=>'vertical'},
273
        { label=>"Sent packet interrupt", param_name=>"sent_int", type=>"Check-box", default_val=>'1\'b1', content=>1, info=>"If the sent inttrupt is enabled, once a packet is completely sent out from the NI, the cpu is informed by intrrupt.", param_parent=>'map_param',ref_delay=>undef,placement=>'vertical'},
274
        { label=>"Receive packet interrupt", param_name=>"receive_int", type=>"Check-box", default_val=>'1\'b1', content=>1, info=>"This flag enables receive-interrupt. Hence, the CPU can collect the received packet immediately from the NI. This interrupt avoids the NoC to be blocked by long packets.", param_parent=>'map_param',ref_delay=>1,placement=>'vertical'},
275
        { label=>"Got NI error interrupt", param_name=>"got_err_int", type=>"Check-box", default_val=>'1\'b1', content=>1, info=>"Enable the inttrupt once any of NI error flags is asserted.", param_parent=>'map_param',ref_delay=>undef,placement=>'vertical'},
276
        #{ label=>"ORCC FIFO Credit", param_name=>"credit_en", type=>"Check-box", default_val=>'1\'b1', content=>1, info=>"If this flag is enabled, the credit availbility of destination FIFOs are transfered to source FIFOs. The source FIFOs adapts the sent data size with the available space in destination FIFO. This makes sure the destination FIFO can collet whole of the packet and perevent the NoC resources to be blocked by long packets", param_parent=>'map_param',ref_delay=>1,placement=>'vertical'},
277 38 alirezamon
        );
278
 
279 48 alirezamon
        #push(@info,{ label=>"Recieve FIFO extra space (%)", param_name=>"rsv_extra", type=>"Spin-button",content=>"1,100,1", default_val=>10, info=>"If ORCC FIFO Credit flag is not enabled, additional space is added to receive FIFOs to avoid FIFO overflow. The receiver FIFO only collects the NI's incoming packet if its occupied size is smaller than this additional space. This memory overhead could be avoided if the packet size is added to the header pre-captured data. However, it is not yet supported.", param_parent=>'map_param',ref_delay=>1,placement=>'vertical'},
280
        #) if($credit eq '1\'b0');
281 38 alirezamon
 
282
        foreach my $d (@info) {
283
                ($row,$col)=add_param_widget ($self, $d->{label}, $d->{param_name}, $d->{default_val}, $d->{type}, $d->{content}, $d->{info}, $table,$row,$col,1, $d->{param_parent}, $d->{ref_delay},'ref',$d->{placement});
284 48 alirezamon
                if($d->{param_name} eq "Map_Algrm"){
285
                        $table->attach  ($run_map , $col, $col+1,  $row,$row+1,'shrink','shrink',2,2);$row++;$col=0;
286
                        $table->attach  (gen_label_in_center  ("Enable/Disable flags:") , $col, $col+1,  $row,$row+1,'shrink','shrink',2,2);$row++;$col=0;
287
                }
288 38 alirezamon
        }
289 48 alirezamon
 
290 38 alirezamon
 
291
 
292
        $run_map->signal_connect( 'clicked'=> sub{
293
                my $alg=$self->object_get_attribute('map_param','Map_Algrm');
294 48 alirezamon
                update_merge_actor_list($self,$tview);
295 38 alirezamon
                $self->random_map() if ($alg eq 'Random');
296
                $self->worst_map_algorithm() if ($alg eq 'Reverse-NMAP');
297
                $self->nmap_algorithm() if ($alg eq 'Nmap');
298
                $self->direct_map() if ($alg eq 'Direct');
299
 
300
 
301
        });
302
 
303
        $drawmap->signal_connect ( 'clicked'=> sub{
304
                show_trace_diagram($self,'map');
305
        });
306
 
307
        $auto->signal_connect ( 'clicked'=> sub{
308 48 alirezamon
                my @tasks = $self->get_all_merged_tasks();
309 38 alirezamon
                my $task_num= scalar @tasks;
310
                return if($task_num ==0);
311 48 alirezamon
                my $topology = $self->object_get_attribute('noc_param','TOPOLOGY');
312
                if ($topology eq '"MESH"' || $topology eq '"TORUS"' ){
313
                        my ($nx,$ny) =network_dim_cal($task_num);
314
                        $self->object_add_attribute('noc_param','T1',$nx);
315
                        $self->object_add_attribute('noc_param','T2',$ny);
316
                        $self->object_add_attribute('noc_param','T3',1);
317
                        set_gui_status($self,"ref",1);
318
                }elsif ($topology eq '"RING"' || $topology eq '"LINE"'){
319
                        $self->object_add_attribute('noc_param','T1',$task_num);
320
                        $self->object_add_attribute('noc_param','T2',1);
321
                        $self->object_add_attribute('noc_param','T3',1);
322
                        set_gui_status($self,"ref",1);
323
                }
324 38 alirezamon
        });
325
 
326
        $clean->signal_connect ( 'clicked'=> sub{
327
                remove_mapping($self);
328
                set_gui_status($self,"ref",1);
329
        });
330
 
331 48 alirezamon
        return add_widget_to_scrolled_win($table);
332 38 alirezamon
 
333
 
334 48 alirezamon
}
335
 
336
 
337
######
338
# map_ctr
339
######          
340
sub trace_group_ctrl{
341 38 alirezamon
 
342 48 alirezamon
        my ($self,$tview,$mode,$NE)=@_;
343
        my $table= def_table(2,10,FALSE);
344
 
345
 
346
 
347
 
348
        my $clean = def_image_button('icons/clear.png');
349
        set_tip($clean,'Ungroup all actors');
350
 
351
        my $box;
352
        $box=def_pack_hbox(FALSE,FALSE,$clean);
353
 
354
        my $col=0;
355
        my $row=0;
356
 
357
 
358
 
359
 
360
        $table->attach ($box,$col, $col+1,  $row, $row+1,'shrink','shrink',2,2);$row++;
361
 
362
        #$self->object_add_attribute('grouping','map_limit',$NE);
363
        #add_param_widget ($self,'Max actors in a group:','map_limit', 4,"Spin-button","1,1024,1","The maximum number of actors that can be grouped to be run in one tile", $table,$row,$col,1,'grouping',undef,undef);
364
 
365
 
366
 
367
        $clean->signal_connect ( 'clicked'=> sub{
368
                my $group_num=$self->object_get_attribute('grouping','group_num');
369
                my $gname=$self->object_get_attribute('grouping','group_name_root');
370
                for(my $i=0;$i<$group_num;$i=$i+1){
371
                        $self->object_add_attribute('grouping',"$gname($i)",\());
372
                }
373
                set_gui_status($self,"ref",1);
374
        });
375
 
376
 
377
        return add_widget_to_scrolled_win($table);
378
 
379
 
380
 
381 38 alirezamon
}
382 48 alirezamon
 
383
 
384
 
385
 
386
 
387
 
388
 
389
 
390 38 alirezamon
 
391
#########
392
# trace
393
#########
394
 
395
sub trace_pad{
396 48 alirezamon
        my ($self,$tview,$mode)=@_;
397 38 alirezamon
        my $table= def_table(10,10,FALSE);
398 48 alirezamon
 
399 38 alirezamon
        my $row=0;
400
        my $col=0;
401
 
402
 
403
        my @selectedinfo = (
404
                { label=>" Initial weight ", param_name=>'init_weight', type=>'Spin-button', default_val=>1, content=>"1,16,1", info=>undef, param_parent=>'select_multiple', ref_delay=> undef, new_status=>undef},
405
                { label=>" Min pck size ", param_name=>'min_pck_size', type=>'Spin-button', default_val=>5, content=>"2,1024,1", info=>undef, param_parent=>'select_multiple', ref_delay=> 10, new_status=>'ref'},
406
                { label=>" Max pck size ",param_name=>'max_pck_size', type=>'Spin-button', default_val=>5, content=>"2,1024,1", info=>undef, param_parent=>'select_multiple', ref_delay=> 10, new_status=>'ref'},
407
                { label=>" Burst_size ", param_name=>'burst_size', type=>'Spin-button', default_val=>1, content=>"1,1024,1", info=>undef, param_parent=>'select_multiple', ref_delay=> undef, new_status=>undef},
408
                { label=>" Inject rate(%) ", param_name=>'injct_rate', type=>'Spin-button', default_val=>10, content=>"1,100,1", info=>undef, param_parent=>'select_multiple', ref_delay=> undef, new_status=>undef},
409
            { label=>" Inject rate variation (%) ", param_name=>'injct_rate_var', type=>'Spin-button', default_val=>20, content=>"0,100,1", info=>undef, param_parent=>'select_multiple', ref_delay=> undef, new_status=>undef},
410
        );
411
 
412 48 alirezamon
        my $v_val= $self->object_get_attribute('noc_param','V');
413
        my $v_max=$v_val-1;
414 38 alirezamon
 
415 48 alirezamon
        my $c_val= $self->object_get_attribute('noc_param','C');
416
        my $c_max=($c_val==0)? 0 : $c_val-1;
417
 
418
 
419
        if($mode eq "orcc"){
420
 
421
                @selectedinfo = (
422
                        { label=>" Initial weight ", param_name=>'init_weight', type=>'Spin-button', default_val=>1, content=>"1,16,1", info=>undef, param_parent=>'select_multiple', ref_delay=> undef, new_status=>undef},
423
                        { label=>" Virtual chanel# ", param_name=>'vc', type=>'Spin-button', default_val=>0, content=>"0,$v_max,1", info=>undef, param_parent=>'select_multiple', ref_delay=> undef, new_status=>undef},
424
                        { label=>" Message class# ", param_name=>'class', type=>'Spin-button', default_val=>0, content=>"0,$c_max,1", info=>undef, param_parent=>'select_multiple', ref_delay=> undef, new_status=>undef}
425
                );
426
        }
427
 
428
 
429
        my @traces= get_trace_list($self,'raw');
430 38 alirezamon
        my %f;
431
 
432
 
433
        my $sel=$self->object_get_attribute('select_multiple','action');
434
 
435
        foreach my $p (@traces) {
436 48 alirezamon
                my ($src,$dst, $Mbytes, $file_id, $file_name)=get_trace($self,'raw',$p);
437 38 alirezamon
                $f{$file_id}=$file_id.'*';
438 48 alirezamon
                $self->object_add_attribute("raw_$p",'selected', 1 ) if ($sel eq  'All');
439
                $self->object_add_attribute("raw_$p",'selected', 0 ) if ($sel eq  'None');
440
                $self->object_add_attribute("raw_$p",'selected', 1 ) if ($sel eq  "All-$file_id*");
441
                $self->object_add_attribute("raw_$p",'selected', 0 ) if ($sel eq  "None-$file_id*");
442 38 alirezamon
 
443 48 alirezamon
                my $seleceted =$self->object_get_attribute("raw_$p",'selected');
444 38 alirezamon
                foreach my $d (@selectedinfo) {
445
                        my $val=$self->object_get_attribute($d->{param_parent},$d->{param_name}) if ($sel eq  $d->{param_name} && $seleceted);
446 48 alirezamon
                        $self->object_add_attribute("raw_$p",$d->{param_name}, $val ) if ($sel eq  $d->{param_name}&& $seleceted);
447 38 alirezamon
 
448
                }
449
        }
450
        my $sel_options= "Select,All,None";
451
        if( keys %f > 1){
452
                foreach my $p (sort keys %f) {
453
                        $sel_options="$sel_options,All-$f{$p}";
454
                        $sel_options="$sel_options,None-$f{$p}";
455
                }
456
        }
457
        $self->object_add_attribute('select_multiple','action',"Select");
458
        my $selcombo = $self-> gen_combobox_object ('select_multiple',"action", $sel_options,'-','ref',1);
459
 
460
 
461
        if(scalar @traces ){$table-> attach  ($selcombo, $col, $col+1,  $row, $row+1,'shrink','shrink',2,2);  $col++;}
462
 
463
 
464 48 alirezamon
        my @titles;
465
        #print "******************$mode*******************\n";
466
        if($mode eq 'task'){
467
                @titles = (scalar @traces ) ? (" # "," Source "," Destination "," Bandwidth(MB) ", " Initial weight ", " Min pck size ",  " Max pck size "):
468 38 alirezamon
        ("Load a task graph");
469 48 alirezamon
        }
470
        else{
471
                @titles = (scalar @traces ) ? (" # "," Source "," Destination "," Bandwidth(MB) ", " Initial weight#", "Virtual chanel#", "Message class#"):
472
        ("Load an ORCC file");
473
        }
474 38 alirezamon
 
475
        my $auto=$self->object_get_attribute('Auto','Auto_inject');
476
 
477 48 alirezamon
        push (@titles, (" Burst_size ", " Inject rate(%) ", " Inject rate variation(%) ")) if ($auto eq "1\'b0" && $mode eq 'task');
478 38 alirezamon
        foreach my $p (@titles){
479
                $table-> attach  (gen_label_in_left($p), $col, $col+1,  $row, $row+1,'shrink','shrink',2,2);
480
                $col++;
481
        }
482
                $row++;
483
 
484
        my $i=0;
485
        #my @t=sort { $a cmp $b } @traces;
486
 
487
        foreach my $p (@traces) {
488
                $col=0;
489 48 alirezamon
                my ($src,$dst, $Mbytes, $file_id, $file_name)=get_trace($self,'raw',$p);
490 38 alirezamon
 
491
 
492 48 alirezamon
                my $check = gen_check_box_object ($self,"raw_$p",'selected',0,'ref',0);
493
                my $weight= gen_spin_object ($self,"raw_$p",'init_weight',"1,16,1", 1,undef,undef);
494
                my $vc= gen_spin_object ($self,"raw_$p",'vc',"0,$v_max,1", 0,undef,undef);
495
                my $class= gen_spin_object ($self,"raw_$p",'class',"0,$c_max,1", 0,undef,undef);
496 38 alirezamon
 
497 48 alirezamon
                my $min=$self->object_get_attribute("raw_$p",'min_pck_size');
498
                my $max=$self->object_get_attribute("raw_$p",'max_pck_size');
499 38 alirezamon
                $min=$max=5 if(!defined $min);
500 48 alirezamon
                my $min_pck_size= gen_spin_object ($self,"raw_$p",'min_pck_size',"2,$max,1", 5,'ref',10);
501
                my $max_pck_size= gen_spin_object ($self,"raw_$p",'max_pck_size',"$min,1024,1", 5,'ref',10);
502 38 alirezamon
 
503 48 alirezamon
                my $burst_size  = gen_spin_object ($self,"raw_$p",'burst_size',"1,1024,1", 1,undef,undef);
504
                my $injct_rate  = gen_spin_object ($self,"raw_$p",'injct_rate',"1,100,1", 10,undef,undef);
505
                my $injct_rate_var  = gen_spin_object ($self,"raw_$p",'injct_rate_var',"0,100,1", 20,undef,undef);
506 38 alirezamon
 
507
                #my $weight=  trace_$trace_id",'init_weight'
508
 
509
                $table-> attach  ($check, $col, $col+1,  $row, $row+1,'shrink','shrink',2,2);  $col++;
510
 
511
                $table-> attach (gen_label_in_left($i), $col, $col+1,  $row, $row+1,'shrink','shrink',2,2);  $col++;
512
                $table-> attach (gen_label_in_left("$src") ,$col, $col+1,  $row, $row+1,'shrink','shrink',2,2);  $col++;
513
                $table-> attach (gen_label_in_left("$dst") , $col, $col+1,  $row, $row+1,'shrink','shrink',2,2);  $col++;
514
                $table-> attach (gen_label_in_left("$Mbytes") ,$col, $col+1,  $row, $row+1,'shrink','shrink',2,2);  $col++;
515
                $table-> attach ($weight ,$col, $col+1,  $row, $row+1,'shrink','shrink',2,2);  $col++;
516 48 alirezamon
                if($mode eq 'task'){
517
                        $table-> attach ($min_pck_size, $col, $col+1,  $row, $row+1,'shrink','shrink',2,2);  $col++;
518
                    $table-> attach ($max_pck_size, $col, $col+1,  $row, $row+1,'shrink','shrink',2,2);  $col++;
519
                    if ($auto eq "1\'b0"){
520
                                $table-> attach ($burst_size ,$col, $col+1,  $row, $row+1,'shrink','shrink',2,2);  $col++;
521
                                $table-> attach ($injct_rate ,$col, $col+1,  $row, $row+1,'shrink','shrink',2,2);  $col++;
522
                                $table-> attach ($injct_rate_var ,$col, $col+1,  $row, $row+1,'shrink','shrink',2,2);  $col++;
523
                    }
524
                }else{
525
                        $table-> attach ($vc ,$col, $col+1,  $row, $row+1,'shrink','shrink',2,2);  $col++;
526
                        $table-> attach ($class ,$col, $col+1,  $row, $row+1,'shrink','shrink',2,2);  $col++;
527 38 alirezamon
                }
528
 
529
                $row++;
530
 
531
        }
532
 
533
        my $sc_win = gen_scr_win_with_adjst($self,'trace_pad');
534 48 alirezamon
        $sc_win=add_widget_to_scrolled_win($table,$sc_win);
535 38 alirezamon
 
536
        return $sc_win;
537
}
538
 
539
 
540
 
541
sub load_tarce_file{
542
        my ($self,$file,$tview)=@_;
543
        #open file
544
        my @x;
545
        my %traces;
546
        if (!defined $file) {return; }
547
        if (-e $file) {
548
                my $f_id=$self->object_get_attribute("file_id",undef);
549
                my $t_id=$self->object_get_attribute("trace_id",undef);
550
                open(my $fh, '<:encoding(UTF-8)', $file) or die "Could not open file '$file' $!";
551
                while (my $row = <$fh>) {
552
                        chomp $row;
553
                        my @data =      split (/\s/,$row);
554
 
555
                        next if (! defined $data[0]);
556
                        next if ($data[0] eq '#' || scalar @data < 3);
557
 
558 48 alirezamon
                        $self->add_trace($f_id,'raw',$t_id,$data[0],$data[1],$data[2],$file);
559 38 alirezamon
                        $t_id++;
560
                }
561
                $f_id++;
562
                $self->object_add_attribute("trace_id",undef,$t_id);
563
                $self->object_add_attribute("file_id",undef,$f_id);
564
        }
565
        set_gui_status($self,"ref",1);
566
 
567
}
568
 
569
 
570
 
571
 
572
########
573
# map
574
#######
575
 
576
 
577 48 alirezamon
sub group_info {
578
        my ($self,$tview,$mode)=@_;
579 38 alirezamon
        my $table= def_table(10,10,FALSE);
580
 
581
 
582
        my $sc_win = gen_scr_win_with_adjst($self,'trace_map');
583 48 alirezamon
        $sc_win=add_widget_to_scrolled_win($table,$sc_win);
584 38 alirezamon
 
585
        my $row=0;
586
        my $col=0;
587
 
588 48 alirezamon
        my $lab= ($mode eq 'task')? "Task-name" :"Actor-name";
589
 
590
        my @titles = (" # "," $lab ", " Internal" , " Sent ", " Resvd ", " Sent+Resvd ");
591 38 alirezamon
        foreach my $p (@titles){
592
                $table-> attach  (gen_label_in_left($p), $col, $col+1,  $row, $row+1,'shrink','shrink',2,2); $col++;
593
        }
594
        $col=0;
595
        $row++;
596
 
597
 
598
 
599
        my $i=0;
600 48 alirezamon
        my @tasks=get_all_merged_tasks($self);
601 38 alirezamon
 
602
 
603
 
604
 
605
        #print "tils=@tiles \nass=@assigned  \nlist=@list\n";
606 48 alirezamon
        my %com_tasks= $self->get_communication_task('merge');
607
        #print Dumper(\%com_tasks);
608 38 alirezamon
        foreach my $p (@tasks){
609
 
610
 
611
                $table-> attach  (gen_label_in_left($i), $col, $col+1,  $row, $row+1,'shrink','shrink',2,2); $col++;
612
                $table-> attach  (gen_label_in_left($p), $col, $col+1,  $row, $row+1,'shrink','shrink',2,2); $col++;
613 48 alirezamon
 
614
                my @a=('internal' , 'sent','rsv','total');
615 38 alirezamon
                foreach my $q (@a){
616
                        my $s = (defined $com_tasks{$p}{$q}) ? $com_tasks{$p}{$q} : '-';
617
                        $table-> attach  (gen_label_in_left($s), $col, $col+1,  $row, $row+1,'shrink','shrink',2,2); $col++;
618
 
619
                }
620
 
621
 
622
 
623
 
624
 
625
                $i++;
626
                $col=0;
627
                $row++;
628
        }
629 48 alirezamon
 
630
 
631
 
632 38 alirezamon
 
633
 
634
        return $sc_win;
635
 
636
}
637
 
638
 
639
 
640 48 alirezamon
 
641
 
642
 
643
 
644
 
645 38 alirezamon
########
646
# map_info
647
#######
648
 
649
 
650 48 alirezamon
 
651
########
652
# map_info
653
#######
654
 
655
 
656 38 alirezamon
sub map_info {
657
        my ($self)=@_;
658
        my $sc_win = gen_scr_win_with_adjst($self,'map_info');
659
        my $table= def_table(10,10,FALSE);
660
 
661 48 alirezamon
 
662 38 alirezamon
        my $row=0;
663
        my $col=0;
664
        my ($avg,$max,$min,$norm)=get_map_info($self);
665
 
666
 
667
        my @data = (
668 48 alirezamon
  {0 => "Average distance", 1 =>"$avg"},
669
  {0 => "Max distance"    , 1 =>"$max" },
670
  {0 => "Min distance"    , 1 => "$min"},
671
  {0 => "Normalized data per hop", 1 =>"$norm" }
672 38 alirezamon
  );
673
 
674
 
675
 
676 48 alirezamon
        # create list store
677
        my @clmn_type =  ('Glib::String',  'Glib::String');
678
        my @clmns = ("Mapping Summary", " ");
679
        add_widget_to_scrolled_win(gen_list_store (\@data,\@clmn_type,\@clmns),$sc_win);
680
        $sc_win->show_all;
681 38 alirezamon
        return $sc_win;
682
 
683
}
684
 
685
 
686
 
687
 
688 48 alirezamon
 
689 38 alirezamon
sub get_map_info {
690
        my $self=shift;
691
        my ($avg,$max,$min,$norm)=(0,0,999999,0);
692
        my $sum=0;
693
        my $num=0;
694
 
695
        my $data=0;
696
        my $comtotal=0;
697
 
698 48 alirezamon
        my @traces= get_trace_list($self,'merge');
699
 
700 38 alirezamon
        foreach my $p (@traces) {
701 48 alirezamon
                my ($src, $dst, $Mbytes, $file_id, $file_name)=get_trace($self,'merge',$p);
702
                #my $src_tile = $self->object_get_attribute('MAP_TILE',"$src");
703
                my  $src_tile = get_task_give_tile($self,"$src");
704
                #my $dst_tile = $self->object_get_attribute('MAP_TILE',"$dst");
705
                my $dst_tile  = get_task_give_tile($self,"$dst");
706 38 alirezamon
                next if(!defined $src_tile || !defined  $dst_tile );
707
                next if($src_tile eq '-' || $dst_tile eq "-" );
708 48 alirezamon
                #my ($src_x,$src_y)= tile_id_to_loc($src_tile);
709 38 alirezamon
 
710 48 alirezamon
                #my ($dst_x,$dst_y)= tile_id_to_loc($dst_tile);         
711 38 alirezamon
                #print" ($dst_x,$dst_y)= tile_id_to_loc($dst_tile)\n";
712
 
713 48 alirezamon
                my $mah_distance=get_endpoints_mah_distance($self,tile_id_number($src_tile),tile_id_number($dst_tile));
714 38 alirezamon
                #print "$mah_distance=get_mah_distance($src_x,$src_y,$dst_x,$dst_y);\n";
715
                $min = $mah_distance if($min> $mah_distance);
716
                $max = $mah_distance if($max< $mah_distance);
717
                $sum+=$mah_distance;
718
                $num++;
719
 
720
                $data+=($Mbytes*$mah_distance);
721
            $comtotal+=$Mbytes;
722
 
723
        }
724
 
725
        $avg=$sum/$num if($num!=0);
726
        $min = 0 if $min == 999999;
727
        $norm = $data/$comtotal if ($comtotal !=0);
728
        return ($avg,$max,$min,$norm);
729
 
730
}
731
 
732
 
733
 
734
 
735
 
736
sub map_combobox {
737
        my ($object,$task_name,$content,$default)=@_;
738
        my @combo_list=@{$content};
739 48 alirezamon
        #my $value=$object->object_get_attribute("MAP_TILE",$task_name);
740
        my $value=get_task_give_tile($object,$task_name);
741 38 alirezamon
        my $pos;
742
        $pos=get_pos($value, @combo_list) if (defined $value);
743
        if(!defined $pos && defined $default){
744 48 alirezamon
                #$object->object_add_attribute("MAP_TILE",$task_name,$default); 
745 38 alirezamon
                $pos=get_item_pos($default, @combo_list);
746
        }
747
        #print " my $pos=get_item_pos($value, @combo_list);\n";
748
        my $widget=gen_combo(\@combo_list, $pos);
749
        $widget-> signal_connect("changed" => sub{
750
                my $new_tile=$widget->get_active_text();
751
                $object->map_task($task_name,$new_tile);
752
 
753
                set_gui_status($object,'ref',1);
754
         });
755
        return $widget;
756
}
757
 
758
 
759
##########
760
#       save_as
761
##########
762
sub save_as{
763
        my ($self)=@_;
764
        # read emulation name
765
        my $name=$self->object_get_attribute ("save_as",undef);
766
        my $s= (!defined $name)? 0 : (length($name)==0)? 0 :1;
767
        if ($s == 0){
768
                message_dialog("Please define file name!");
769
                return 0;
770
        }
771
        # Write object file
772
        open(FILE,  ">lib/simulate/$name.TRC") || die "Can not open: $!";
773
        print FILE perl_file_header("$name.TRC");
774
        print FILE Data::Dumper->Dump([\%$self],['Trace']);
775
        close(FILE) || die "Error closing file: $!";
776
        message_dialog("workspace has been saved as lib/simulate/$name.TRC!");
777
        return 1;
778
}
779
 
780
 
781
 
782
 
783
#############
784
#       load_workspace
785
############
786
 
787
sub load_workspace {
788
        my $self=shift;
789 48 alirezamon
        my $mpsoc_name=$self->object_get_attribute('mpsoc_name');
790
 
791 38 alirezamon
        my $file;
792 48 alirezamon
        my $dialog = gen_file_dialog(undef,'TRC');
793 38 alirezamon
        my $dir = Cwd::getcwd();
794
        $dialog->set_current_folder ("$dir/lib/simulate");
795 48 alirezamon
 
796 38 alirezamon
        if ( "ok" eq $dialog->run ) {
797
                $file = $dialog->get_filename;
798
                my ($name,$path,$suffix) = fileparse("$file",qr"\..[^.]*$");
799 48 alirezamon
                if($suffix eq '.TRC'){
800
 
801 43 alirezamon
                        my ($pp,$r,$err) = regen_object($file);
802
                        if ($r){
803 48 alirezamon
                                message_dialog("Error reading  $file file: $err\n",'error');
804 38 alirezamon
                                 $dialog->destroy;
805
                                return;
806
                        }
807
 
808 48 alirezamon
                        my ($tmp,$r1,$err1) = regen_object($file);
809
 
810
 
811
                        clone_obj($tmp,$self);
812
 
813
 
814 38 alirezamon
                        clone_obj($self,$pp);
815 48 alirezamon
 
816
                        #update current parameter 
817
                        my @pnames=('soc_name','ni_name','noc_param');
818
                        foreach my $n (@pnames){
819
                                my $param=$tmp->object_get_attribute($n);
820
                                if( defined $param){
821
                                        my %params=%{$param};
822
                                        foreach my $p (sort keys %params){
823
                                                $self->{$n}{$p}=$params{$p};
824
                                        }
825
                                }
826
                        }
827
 
828
                        #update mpsocname
829
                        $self->object_add_attribute('mpsoc_name',undef,$mpsoc_name) if (defined $mpsoc_name);
830
 
831
 
832
 
833
 
834
 
835
 
836
                        #print Dumper($self);
837
 
838 38 alirezamon
                        #message_dialog("done!");                               
839
                }
840
     }
841
     $dialog->destroy;
842
}
843
 
844
 
845
########
846 48 alirezamon
# genereate_output_tasks
847 38 alirezamon
########
848
 
849 48 alirezamon
sub genereate_output_tasks{
850 38 alirezamon
        my $self=shift;
851
        my $name= $self->object_get_attribute('out_name');
852
        my $size= (defined $name)? length($name) :0;
853
        if ($size ==0) {
854
                message_dialog("Please define the output file name!");
855
                return 0;
856
        }
857
 
858
 
859
 
860
        # make target dir
861
        my $dir = Cwd::getcwd();
862
        my $target_dir  = "$ENV{'PRONOC_WORK'}/traffic_pattern";
863
        mkpath("$target_dir",1,0755);
864
 
865 48 alirezamon
        my @tasks=get_all_merged_tasks($self);
866 38 alirezamon
        foreach my $p (@tasks) {
867 48 alirezamon
                #my $tile=$self->object_get_attribute("MAP_TILE",$p);
868
                my $tile= get_task_give_tile($self,$p);
869 38 alirezamon
                if ( $tile eq "-" ){
870
                        message_dialog("Error: unmapped task. Please map task $p to a tile", 'error' );
871
                        return;
872
                }
873
 
874
        }
875
        #creat output file
876
    open(FILE,  ">$target_dir/$name.cfg") || die "Can not open: $!";
877
        print FILE get_cfg_content($self);
878
        close(FILE) || die "Error closing file: $!";
879
        message_dialog("The traffic pattern is saved as $target_dir/$name.cfg" );
880
 
881
}
882
 
883
sub get_cfg_content{
884
        my $self=shift;
885
        my $file="% source tile, destination tile, bytes, initial_weight, min_pck_size, max_pck_size, burst_size, injection_rate(%), injection_rate variation(%)\n";
886
 
887
 
888
 
889 48 alirezamon
        my @tasks= get_trace_list($self,'merge');
890
        my @traces= get_trace_list($self,'raw');
891
 
892
        foreach my $p (@traces){
893
                my ($src_r,$dst_r, $Mbytes_r, $file_id_r, $file_name_r,$init_weight_r,$min_pck_r, $max_pck_r,  $burst_r, $injct_rate_r, $injct_rate_var_r)=get_trace($self,'raw',$p);
894
 
895 38 alirezamon
 
896 48 alirezamon
                my $src =$self->get_item_group_name('grouping',$src_r);
897
                my $dst =$self->get_item_group_name('grouping',$dst_r);
898
            if  ($src eq  $dst){
899
                # source-destination is merged to one tile so ommit it
900
                next;
901
 
902
            }else{
903 38 alirezamon
 
904 48 alirezamon
                        my $minpck = $self->object_get_attribute("raw_$p",'min_pck_size');
905
                        my $maxpck = $self->object_get_attribute("raw_$p",'max_pck_size');
906
                        my $avg_pck_size =($minpck+ $maxpck)/2;
907
                        my $pck_num = ($Mbytes_r*8) /($avg_pck_size*64);
908
                        $pck_num= 1 if($pck_num==0);
909
 
910
                        my  $src_tile = tile_id_number(get_task_give_tile($self,"$src"));
911
                        my  $dst_tile = tile_id_number(get_task_give_tile($self,"$dst"));
912 38 alirezamon
 
913 48 alirezamon
                        my $auto=$self->object_get_attribute('Auto','Auto_inject');
914 38 alirezamon
 
915 48 alirezamon
                        my $bytes = $Mbytes_r * 1000000;
916
 
917
                        $file=$file."$src_tile, $dst_tile, $bytes, $init_weight_r, $min_pck_r, $max_pck_r";
918
                        $file=$file.", $burst_r, $injct_rate_r, $injct_rate_var_r \n" if ($auto eq "1\'b0");
919
                        $file=$file." \n" if ($auto eq "1\'b1");
920
 
921
 
922
            }
923
        }
924 38 alirezamon
 
925 48 alirezamon
 
926
 
927 38 alirezamon
        return $file;
928
}
929
 
930
 
931
 
932 48 alirezamon
sub add_trace{
933
        my ($self, $file_id,$category,$trace_id, $source,$dest, $Mbytes, $file_name,$src_port,$dst_port,$buff_size,$chanel,$vc,$class)=@_;
934
        $self->object_add_attribute("${category}_$trace_id",'file',$file_id);
935
        $self->object_add_attribute("${category}_$trace_id",'source',"${source}");
936
        $self->object_add_attribute("${category}_$trace_id",'destination',"${dest}");
937
        $self->object_add_attribute("${category}_$trace_id",'Mbytes', $Mbytes);
938
        $self->object_add_attribute("${category}_$trace_id",'file_name', $file_name);
939
        $self->object_add_attribute("${category}_$trace_id",'selected', 0);
940
        $self->object_add_attribute("${category}_$trace_id",'init_weight', 1);
941
        $self->object_add_attribute("${category}_$trace_id",'scr_port',$src_port);
942
        $self->object_add_attribute("${category}_$trace_id",'dst_port',$dst_port);
943
        $self->object_add_attribute("${category}_$trace_id",'buff_size',$buff_size);
944
        $self->object_add_attribute("${category}_$trace_id",'chanel',$chanel);
945
        $self->object_add_attribute("${category}_$trace_id",'vc',$vc);
946
        $self->object_add_attribute("${category}_$trace_id",'class',$class);
947
        $self->{"${category}_traces"}{$trace_id}=1;
948
 
949 38 alirezamon
}
950
 
951 48 alirezamon
sub add_trace_extra {
952
        my ($self, $file_id,$category,$trace_id,$min_pck, $max_pck,$burst, $injct_rate, $injct_rate_var)=@_;
953
        $self->object_add_attribute("${category}_$trace_id",'min_pck_size',$min_pck);
954
        $self->object_add_attribute("${category}_$trace_id",'max_pck_size',$max_pck);
955
        $self->object_add_attribute("${category}_$trace_id",'burst_size',$burst);
956
        $self->object_add_attribute("${category}_$trace_id",'injct_rate',$injct_rate);
957
        $self->object_add_attribute("${category}_$trace_id",'injct_rate_var',$injct_rate_var);
958
}
959 38 alirezamon
 
960
 
961 48 alirezamon
sub remove_trace{
962
        my ($self,$category, $trace_id)=@_;
963
        delete $self->{"${category}_$trace_id"};
964
        delete $self->{"${category}_traces"}{$trace_id};
965 38 alirezamon
}
966
 
967 48 alirezamon
sub get_trace_list{
968
        my ($self,$category)=@_;
969
        #print "($self,$category)\n";
970
        return sort (keys %{$self->{"${category}_traces"}});
971 38 alirezamon
}
972
 
973 48 alirezamon
sub remove_all_traces{
974
        my ($self,$category)=@_;
975
        my @all =get_trace_list($self,$category);
976
        foreach my $trace_id (@all ){
977
                remove_trace ($self,$category, $trace_id);
978 38 alirezamon
        }
979
}
980
 
981
 
982
sub get_trace{
983 48 alirezamon
        my ($self,$category,$trace_id)=@_;
984
        my $file_id             = $self->object_get_attribute("${category}_$trace_id",'file');
985
        my $source              = $self->object_get_attribute("${category}_$trace_id",'source');
986
        my $dest                = $self->object_get_attribute("${category}_$trace_id",'destination');
987
        my $Mbytes      = $self->object_get_attribute("${category}_$trace_id",'Mbytes');
988
        my $file_name   = $self->object_get_attribute("${category}_$trace_id",'file_name');
989
        my $init_weight = $self->object_get_attribute("${category}_$trace_id",'init_weight');
990
        my $min_pck_size= $self->object_get_attribute("${category}_$trace_id",'min_pck_size');
991
        my $max_pck_size= $self->object_get_attribute("${category}_$trace_id",'max_pck_size');
992
        my $burst_size  = $self->object_get_attribute("${category}_$trace_id",'burst_size');
993
        my $injct_rate  = $self->object_get_attribute("${category}_$trace_id",'injct_rate');
994
        my $injct_rate_var = $self->object_get_attribute("${category}_$trace_id",'injct_rate_var');
995
        my $src_port = $self->object_get_attribute("${category}_$trace_id",'scr_port');
996
        my $dst_port = $self->object_get_attribute("${category}_$trace_id",'dst_port');
997
        my $buff_size= $self->object_get_attribute("${category}_$trace_id",'buff_size');
998
        my $chanel = $self->object_get_attribute("${category}_$trace_id",'chanel');
999
        my $vc= $self->object_get_attribute("${category}_$trace_id",'vc');
1000
        my $class= $self->object_get_attribute("${category}_$trace_id",'class');
1001
        return ($source,$dest, $Mbytes, $file_id,$file_name,$init_weight,$min_pck_size, $max_pck_size, $burst_size, $injct_rate, $injct_rate_var, $src_port,$dst_port,$buff_size,$chanel,$vc,$class);
1002 38 alirezamon
}
1003
 
1004
sub get_all_tasks{
1005 48 alirezamon
        my ($self,$category)=@_;
1006
        my @traces= get_trace_list($self,$category);
1007 38 alirezamon
        my @x;
1008
        foreach my $p (@traces){
1009 48 alirezamon
                my ($src,$dst, $Mbytes, $file_id, $file_name)=get_trace($self,$category,$p);
1010 38 alirezamon
                push(@x,$src);
1011
                push(@x,$dst);
1012
        }
1013
        my @x2 =  uniq(sort  @x) if (scalar @x);
1014
        return @x2;
1015
}
1016
 
1017
 
1018
sub remove_mapping{
1019
        my $self=shift;
1020
        $self->object_add_attribute('MAP_TASK',undef,undef);
1021 48 alirezamon
        $self->object_add_attribute('mapping',undef,undef);
1022
        #$self->object_add_attribute('MAP_TILE',undef,undef);
1023 38 alirezamon
}
1024
 
1025
 
1026
 
1027
sub remove_nlock_mapping{
1028
        my $self=shift;
1029 48 alirezamon
        my @tasks=get_all_merged_tasks($self);
1030 38 alirezamon
 
1031
        foreach my $p (@tasks){
1032
                my $lock=$self->object_get_attribute("MAP_LOCK",$p);
1033
                $lock = 0 if (!defined $lock);
1034
                if($lock == 0){
1035 48 alirezamon
                        #my $tile=$self->object_get_attribute("MAP_TILE",$p);
1036
                        my $tile=get_task_give_tile($self,$p);
1037
                        #$self->object_add_attribute("MAP_TILE",$p,undef);
1038 38 alirezamon
                        $self->object_add_attribute("MAP_TASK",$tile,undef);
1039 48 alirezamon
                        $self->object_add_attribute("mapping",$tile,undef);
1040 38 alirezamon
 
1041 48 alirezamon
 
1042 38 alirezamon
                }
1043
        }
1044
}
1045
 
1046
 
1047
sub get_nlock_tasks {
1048
        #my ($self,$taskref,$tileref)=shift;
1049
        my $self=shift;
1050
        my @unluck_tasks;
1051 48 alirezamon
        my @tasks=get_all_merged_tasks($self);
1052 38 alirezamon
 
1053
        foreach my $p (@tasks){
1054
                my $lock=$self->object_get_attribute("MAP_LOCK",$p);
1055
                $lock = 0 if (!defined $lock);
1056
                if($lock == 0){
1057
                        push(@unluck_tasks,$p);
1058
                }
1059
 
1060
        }
1061
        return  @unluck_tasks;
1062
}
1063
 
1064
sub get_nlock_tiles {
1065
        #my ($self,$taskref,$tileref)=shift;
1066
        my $self=shift;
1067
        my @luck_tiles;
1068 48 alirezamon
        my @tasks=get_all_merged_tasks($self);
1069 38 alirezamon
 
1070
        foreach my $task (@tasks){
1071
                my $lock=$self->object_get_attribute("MAP_LOCK",$task);
1072
                $lock = 0 if (!defined $lock);
1073
                if($lock == 1){
1074 48 alirezamon
                        #my $tile=$self->object_get_attribute('MAP_TILE',"$task");
1075
                        my $tile=get_task_give_tile($self,"$task");
1076 38 alirezamon
                        push(@luck_tiles,$tile);
1077
                }
1078
 
1079
        }
1080
        my @tiles=get_tiles_name($self);
1081
 
1082
        #a-b
1083
        return get_diff_array(\@tiles,\@luck_tiles);
1084
}
1085
 
1086
 
1087
sub get_locked_map {
1088
        my $self=shift;
1089
        my %map;
1090 48 alirezamon
        my @tasks=get_all_merged_tasks($self);
1091 38 alirezamon
 
1092
        foreach my $task (@tasks){
1093
                my $lock=$self->object_get_attribute("MAP_LOCK",$task);
1094
 
1095
                $lock = 0 if (!defined $lock);
1096
                if($lock == 1){
1097 48 alirezamon
                        #my $tile=$self->object_get_attribute('MAP_TILE',"$task");
1098
                        my $tile=get_task_give_tile($self,"$task");
1099 38 alirezamon
                        $map{$task}=$tile;
1100
                }
1101
 
1102
        }
1103
        return  %map;
1104
}
1105
 
1106
 
1107
#########
1108
#       Mapping algorithm
1109
#########
1110
sub random_map{
1111
        my $self=shift;
1112
 
1113
 
1114
 
1115 43 alirezamon
        my $nx=$self->object_get_attribute('noc_param','T1');
1116
        my $ny=$self->object_get_attribute('noc_param','T2');
1117 38 alirezamon
        my $nc= $nx * $ny;
1118
 
1119
 
1120
 
1121
        my @tasks=get_nlock_tasks($self);
1122
        my @tiles=get_nlock_tiles($self);
1123
        $self->remove_nlock_mapping() ;
1124
 
1125
 
1126
        my @rnd= shuffle @tiles;
1127
 
1128
        my $i=0;
1129
        foreach my $task (@tasks){
1130
                if($i>=scalar @rnd){
1131
                        last;
1132
                };
1133
                my $tile=$rnd[$i];
1134 48 alirezamon
                #$self->object_add_attribute('MAP_TILE',"$task",$tile);
1135 38 alirezamon
                $self->object_add_attribute('MAP_TASK',"$tile",$task);
1136 48 alirezamon
                my @l=($task);
1137
                $self->object_add_attribute("mapping","$tile",\@l);
1138
 
1139 38 alirezamon
                $i++;
1140
 
1141
        }
1142
 
1143
        set_gui_status($self,"ref",1);
1144
 
1145
}
1146
 
1147
sub direct_map {
1148
        my $self=shift;
1149
 
1150 48 alirezamon
 
1151 38 alirezamon
        my @tasks=get_nlock_tasks($self);
1152
        my @tiles=get_nlock_tiles($self);
1153
        $self->remove_nlock_mapping() ;
1154
 
1155
        my @sort_tiles;
1156
        my %tilenum;
1157
        foreach my $tile (@tiles){
1158 48 alirezamon
                #my ($x,$y)=tile_id_to_loc($tile);
1159
                #my $id= $y*$nx+$x;
1160
                my $id=tile_id_number($tile);
1161 38 alirezamon
                $tilenum{$id}=$tile;
1162
        }
1163
 
1164 48 alirezamon
        foreach my $id  (sort  {$a <=> $b} keys %tilenum){
1165 38 alirezamon
 
1166
                push(@sort_tiles, $tilenum{$id});
1167
        }
1168
 
1169
 
1170
        my @sort_tasks = sort @tasks;
1171
 
1172
 
1173
        my $i=0;
1174
        foreach my $task (@sort_tasks){
1175
                if($i>=scalar @sort_tiles){
1176
                        last;
1177
                };
1178
                my $tile=$sort_tiles[$i];
1179 48 alirezamon
                #$self->object_add_attribute('MAP_TILE',"$task",$tile);
1180 38 alirezamon
                $self->object_add_attribute('MAP_TASK',"$tile",$task);
1181 48 alirezamon
                my @l = ($task);
1182
                $self->object_add_attribute("mapping","$tile",\@l);
1183 38 alirezamon
 
1184
                $i++;
1185
 
1186
        }
1187
 
1188
        set_gui_status($self,"ref",1);
1189
 
1190
 
1191
}
1192
 
1193
 
1194 48 alirezamon
sub get_task_give_tile{
1195
        my ($self,$task)=@_;
1196
        my @tiles=get_tiles_name($self);
1197
        foreach my $p (@tiles){
1198
                my $r=$self->object_get_attribute("mapping","$p");
1199
 
1200
                my @l=@{$r} if(defined $r);
1201
                if(defined $l[0] ){
1202
                        return $p       if($l[0] eq $task );
1203
                }
1204
        }
1205
        return undef;
1206
}
1207 38 alirezamon
 
1208
 
1209 48 alirezamon
sub network_3dim_cal{
1210
        my $n_tasks= shift;
1211 38 alirezamon
 
1212 48 alirezamon
        my $dim_x = floor($n_tasks**(1/3));
1213 38 alirezamon
 
1214 48 alirezamon
        my ($dim_y,$dim_z)=network_dim_cal(ceil($n_tasks/$dim_x));
1215
 
1216
 
1217
 
1218
        return ($dim_x,$dim_y,$dim_z);
1219 38 alirezamon
 
1220 48 alirezamon
 
1221
}
1222
 
1223 38 alirezamon
 
1224
 
1225
 
1226 48 alirezamon
 
1227 38 alirezamon
sub network_dim_cal{
1228
        my $n_tasks= shift;
1229
 
1230
        my $dim_y = floor(sqrt($n_tasks));
1231
 
1232
        my $dim_x = ceil($n_tasks/$dim_y);
1233
 
1234
        return ($dim_x,$dim_y);
1235
 
1236
        #cout << "dim_x = " << dim_x << "; dim_y = " << dim_y << endl;
1237
}
1238
 
1239
 
1240
sub get_tiles_name{
1241
        my $self=shift;
1242
        my @tiles;
1243 48 alirezamon
    my ($NE, $NR, $RAw, $EAw, $Fw)=get_topology_info($self);
1244
    #print " my ($NE, $NR, $RAw, $EAw, $Fw)=get_topology_info($self)\n";
1245
        for (my $tile_num=0;$tile_num<$NE;$tile_num++){
1246
                push(@tiles,"tile($tile_num)");
1247
        }
1248
 
1249 38 alirezamon
        return @tiles;
1250
}
1251
 
1252
 
1253 48 alirezamon
sub tile_id_number{
1254
        my $tile=shift;
1255
        my ($x) =  $tile =~ /(\d+)/g;
1256
        return $x;
1257 38 alirezamon
}
1258
 
1259
 
1260
 
1261
sub get_communication_task{
1262 48 alirezamon
        my ($self,$category)=@_;
1263 38 alirezamon
        my %com_tasks;
1264 48 alirezamon
        my @tasks=get_all_merged_tasks($self);
1265
        my @traces= get_trace_list($self,'raw');
1266
 
1267
 
1268
 
1269 38 alirezamon
        foreach my $p (@tasks){
1270
                $com_tasks{$p}{'total'}= 0;
1271 48 alirezamon
 
1272 38 alirezamon
                foreach my $q (@tasks){
1273
                        $com_tasks{$p}{$q}= 0;
1274
 
1275
                }
1276
        }
1277
 
1278
        foreach my $p (@traces){
1279 48 alirezamon
                my ($src,$dst, $Mbytes, $file_id, $file_name)=get_trace($self,'raw',$p);
1280
                $src =$self->get_item_group_name('grouping',$src);
1281
                $dst =$self->get_item_group_name('grouping',$dst);
1282
            if  ($src eq  $dst){
1283
                $com_tasks{$src}{'internal'} += $Mbytes;
1284
 
1285
            }else{
1286 38 alirezamon
 
1287 48 alirezamon
                        $com_tasks{$src}{'sent'} += $Mbytes;
1288
                        $com_tasks{$dst}{'rsv'} += $Mbytes;
1289
 
1290
                        $com_tasks{$src}{'total'} += $Mbytes;
1291
                        $com_tasks{$dst}{'total'} += $Mbytes;
1292
                        $com_tasks{$src}{$dst} += $Mbytes;
1293
                        $com_tasks{$file_id}{'maxsent'} = $com_tasks{$src}{'sent'} if(!defined $com_tasks{$file_id}{'maxsent'});
1294
                        $com_tasks{$file_id}{'maxsent'} = $com_tasks{$src}{'sent'} if( $com_tasks{$file_id}{'maxsent'}<$com_tasks{$src}{'sent'});
1295
 
1296
 
1297
 
1298
                        my $minpck = $self->object_get_attribute("raw_$p",'min_pck_size');
1299
                        my $maxpck = $self->object_get_attribute("raw_$p",'max_pck_size');
1300
                        my $avg_pck_size =($minpck+ $maxpck)/2;
1301
                        my $pck_num = ($Mbytes*8) /($avg_pck_size*64);
1302
                        $pck_num= 1 if($pck_num==0);
1303
                        $com_tasks{$src}{'min_pck_num'} =$pck_num if(!defined $com_tasks{$src}{'min_pck_num'});
1304
                        $com_tasks{$src}{'min_pck_num'} =$pck_num if( $com_tasks{$src}{'min_pck_num'} > $pck_num);
1305
            }
1306 38 alirezamon
 
1307
        }
1308
        return %com_tasks;
1309
}
1310
 
1311
 
1312 48 alirezamon
sub find_max_neighbor_tile_old{
1313 38 alirezamon
        my $self=shift;
1314 48 alirezamon
        #Select the tile located in center as the max-neighbor if its not locked for any other task
1315
        my ($NE,$NR) = get_topology_info($self);
1316
 
1317
        my $ne_mid = floor($NE/2);
1318
        print "$ne_mid = $ne_mid\n";
1319
 
1320
 
1321 38 alirezamon
        #my $centered_tile= get_tile_name($self,$x_mid ,$y_mid);
1322
        #Select the tile located in center as the max-neighbor if its not locked for any other task
1323
        #therwise select the tile with the min manhatan distance to center tile
1324
        my @tiles=get_nlock_tiles($self);
1325
        my $min=1000000;
1326
        my $max_neighbors_tile_id;
1327
        foreach my $tile (@tiles){
1328 48 alirezamon
                #my ($x,$y)=tile_id_to_loc($tile);
1329
                my $tile_num = tile_id_number($tile);
1330
                my $mah_distance=get_endpoints_mah_distance($self,$ne_mid,$tile_num);
1331
 
1332 38 alirezamon
                if($min > $mah_distance ){
1333
                        $min = $mah_distance;
1334
                        $max_neighbors_tile_id=$tile;
1335
                }
1336
 
1337
        }
1338
 
1339
        return $max_neighbors_tile_id;
1340
}
1341
 
1342
 
1343 48 alirezamon
sub find_max_neighbor_tile{
1344
        my $self=shift;
1345
        #Select the tile with the list manhatan distance from all endpoints
1346
        my ($NE,$NR) = get_topology_info($self);
1347
        my $min_manth_dist_acum;
1348
        my $max_neighbors_tile_id;
1349
 
1350
        for (my $i=0; $i<$NE; $i++){
1351
                my $c=0;
1352
                for (my $j=0; $j<$NE; $j++){
1353
                        next if($i==$j);
1354
                        my $d=get_endpoints_mah_distance($self,$i,$j);
1355
                        $c+=$d*$d;
1356
                }
1357
                $min_manth_dist_acum=$c if(!defined $min_manth_dist_acum);
1358
                if($c <= $min_manth_dist_acum){
1359
                        $min_manth_dist_acum=$c;
1360
                        $max_neighbors_tile_id="tile($i)";
1361
                }
1362
 
1363
        }
1364
 
1365
 
1366
        return $max_neighbors_tile_id;
1367
}
1368
 
1369
 
1370
 
1371 38 alirezamon
sub find_min_neighbor_tile      {
1372
        my $self=shift;
1373 48 alirezamon
 
1374
        my $ne_mid = 0;
1375
 
1376 38 alirezamon
        #my $centered_tile= get_tile_name($self,$x_mid ,$y_mid);
1377
        #Select the tile located in center as the max-neighbor if its not locked for any other task
1378 48 alirezamon
        #otherwise select the tile with the min Manhattan distance to center tile
1379 38 alirezamon
        my @tiles=get_nlock_tiles($self);
1380
        my $min=1000000;
1381
        my $min_neighbors_tile_id;
1382
        foreach my $tile (@tiles){
1383 48 alirezamon
                #my ($x,$y)=tile_id_to_loc($tile);
1384
                my $tile_num = tile_id_number($tile);
1385
                my $mah_distance=get_endpoints_mah_distance($self,$ne_mid,$tile_num );
1386 38 alirezamon
                if($min > $mah_distance ){
1387
                        $min = $mah_distance;
1388
                        $min_neighbors_tile_id=$tile;
1389
                }
1390
 
1391
        }
1392
 
1393
        return $min_neighbors_tile_id;
1394
}
1395
 
1396
 
1397
 
1398
sub nmap_algorithm{
1399 48 alirezamon
        my $self=shift;
1400 43 alirezamon
        my $nx=$self->object_get_attribute('noc_param','T1');
1401
        my $ny=$self->object_get_attribute('noc_param','T2');
1402 38 alirezamon
        my $nc= $nx * $ny;
1403
 
1404 48 alirezamon
        my @tasks=get_all_merged_tasks($self);
1405
        my @tiles= get_tiles_name($self);
1406 38 alirezamon
        my $n_tasks = scalar  @tasks;
1407
 
1408
 
1409
        my @unmapped_tasks_set=@tasks; # unmapped set of tasks
1410
        my @unallocated_tiles_set=@tiles;       # tile ids which are not allocated yet
1411
 
1412 48 alirezamon
#       print "@unmapped_tasks_set *** @unallocated_tiles_set\n";
1413 38 alirezamon
 
1414
 
1415
        #------ step 1: find the task with highest weighted communication volume
1416
        # find the max of com_vol
1417
        # consider all incoming and outgoing connections of each tasks
1418
 
1419 48 alirezamon
        my %com_tasks= $self->get_communication_task('merge');
1420 38 alirezamon
        #print  Data::Dumper->Dump([\%com_tasks],['mpsoc']);    
1421
 
1422
        my $max_com_task;
1423
        my $max_com =0;
1424
        foreach my $p (sort keys %com_tasks){
1425 48 alirezamon
                #print "**$p\n";
1426 38 alirezamon
                if(defined $com_tasks{$p}{'total'}){
1427
                if ($com_tasks{$p}{'total'} >$max_com){
1428
                        $max_com = $com_tasks{$p}{'total'};
1429
                        $max_com_task = $p;
1430
                }}
1431
        }
1432
 
1433 48 alirezamon
        #print "m=$max_com      t=$max_com_task\n";
1434 38 alirezamon
 
1435
 
1436
        #------ step 2: find the tile with max number of neighbors
1437
        # normally, this tile is in the middle of the array
1438
        my $max_neighbors_tile_id = find_max_neighbor_tile($self);
1439
 
1440 48 alirezamon
        print "\$max_neighbors_tile_id = $max_neighbors_tile_id\n";
1441 38 alirezamon
 
1442
 
1443
 
1444
        my %map=get_locked_map ($self);
1445
        $self->remove_nlock_mapping();
1446
        foreach my $mapped_task (sort keys %map){
1447
                        my $mapped_tile=$map{$mapped_task};
1448
                        @unmapped_tasks_set=remove_scolar_from_array(\@unmapped_tasks_set,$mapped_task);
1449
                        @unallocated_tiles_set=remove_scolar_from_array(\@unallocated_tiles_set,$mapped_tile);
1450
        }
1451
 
1452
 
1453
 
1454
 
1455
        # add this task with highest weighted communication volume to the mapped task set
1456
        #push(@mapped_tasks_set,$max_com_task);
1457
        #task_mapping[max_com_task] = max_neighbors_tile_id;
1458
 
1459
        if(!defined $map{$max_com_task}){
1460
                $map{$max_com_task}=$max_neighbors_tile_id;
1461
                @unmapped_tasks_set=remove_scolar_from_array(\@unmapped_tasks_set,$max_com_task);
1462
                @unallocated_tiles_set=remove_scolar_from_array(\@unallocated_tiles_set,$max_neighbors_tile_id);
1463
        }
1464
 
1465
 
1466
 
1467
        #------ step 3: map all unmapped tasks
1468
        while(scalar @unmapped_tasks_set){
1469
                $max_com =0;
1470
                my $max_com_unmapped_task;
1471
                my $max_overall_com=0;
1472
                #--------- step 3.1:
1473
                # find the unmapped task which communicates most with mapped_tasks_set
1474
                # among many tasks which have the same communication volume with mapped_tasks,
1475
                # choose the task with highest communication volume with others
1476
 
1477
                foreach my $unmapped_task (@unmapped_tasks_set){
1478
 
1479
                        my $com_vol=0;
1480
                        foreach my $mapped_task (sort keys %map){
1481
                                $com_vol += $com_tasks{$unmapped_task}{$mapped_task};
1482
                                $com_vol += $com_tasks{$mapped_task}{$unmapped_task};
1483
                        }
1484
 
1485
                        my $overall_com_vol = 0;
1486
                        foreach my $p (@tasks){
1487
                                $overall_com_vol += $com_tasks{$unmapped_task}{$p};
1488
                                $overall_com_vol += $com_tasks{$p}{$unmapped_task};
1489
                        }
1490
 
1491
 
1492
                        if ($com_vol > $max_com){
1493
                                $max_com = $com_vol;
1494
                                $max_com_unmapped_task = $unmapped_task;
1495
                                $max_overall_com = $overall_com_vol;
1496
                        }
1497
                        elsif ($com_vol == $max_com){ # choose if it have higher comm volume
1498
                                if ($overall_com_vol > $max_overall_com){
1499
                                        $max_com_unmapped_task = $unmapped_task;
1500
                                        $max_overall_com = $overall_com_vol;
1501
                                }
1502
                        }
1503
                }#foreach my $unmapped_task (@unmapped_tasks_set)
1504
 
1505
                #--------- step 3.2, find the unallocated tile with lowest communication cost to/from allocated_tile_set
1506
                my $min_com_cost;
1507
                my $min_com_cost_tile_id;
1508
 
1509
 
1510
                foreach my $unallocated_tile(@unallocated_tiles_set){
1511
                        my $com_cost = 0;
1512 48 alirezamon
                        #my ($unallocated_x,$unallocated_y)=tile_id_to_loc($unallocated_tile);
1513
                        my $unallocated_tile_num = tile_id_number($unallocated_tile);
1514 38 alirezamon
                        # scan all mapped tasks
1515
                        foreach my $mapped_task (sort keys %map){
1516
                                # get location of this mapped task
1517
                                my $mapped_tile=$map{$mapped_task};
1518 48 alirezamon
                                #my ($allocated_x,$allocated_y)=tile_id_to_loc($mapped_tile);
1519
                                my $mapped_tile_num = tile_id_number($mapped_tile);
1520 38 alirezamon
                                # mahattan distance of 2 tiles
1521 48 alirezamon
                                my $mah_distance=get_endpoints_mah_distance($self,$unallocated_tile_num,$mapped_tile_num);
1522 38 alirezamon
 
1523
 
1524
                                $com_cost += $com_tasks{$max_com_unmapped_task}{$mapped_task} * $mah_distance;
1525
                                $com_cost += $com_tasks{$mapped_task}{$max_com_unmapped_task} * $mah_distance;
1526
 
1527
                        }
1528
                        $min_com_cost = $com_cost+1 if(!defined $min_com_cost);
1529
                        if ($com_cost < $min_com_cost){
1530
                                $min_com_cost = $com_cost;
1531
                                $min_com_cost_tile_id = $unallocated_tile;
1532
                        }
1533
                }
1534
 
1535
                # add max_com_unmapped_task to the mapped_tasks_set set
1536
                #task_mapping[max_com_unmapped_task] = min_com_cost_tile_id;
1537
                $map{$max_com_unmapped_task}=$min_com_cost_tile_id;
1538
                @unmapped_tasks_set=remove_scolar_from_array(\@unmapped_tasks_set,$max_com_unmapped_task);
1539
                @unallocated_tiles_set=remove_scolar_from_array(\@unallocated_tiles_set,$min_com_cost_tile_id);
1540
 
1541
        }
1542
 
1543
 
1544
        foreach my $mapped_task (sort keys %map){
1545
                        my $mapped_tile=$map{$mapped_task};
1546
                        #print "$mapped_tile=\$map{$mapped_task};\n";
1547 48 alirezamon
                        #$self->object_add_attribute('MAP_TILE',"$mapped_task", $mapped_tile) if(defined $mapped_tile);
1548 38 alirezamon
                        $self->object_add_attribute('MAP_TASK',"$mapped_tile",$mapped_task) if(defined $mapped_tile);
1549 48 alirezamon
                        my @l = ($mapped_task);
1550
                        $self->object_add_attribute('mapping',"$mapped_tile",\@l) if(defined $mapped_tile);
1551
                        #print "\$self->object_add_attribute('mapping',$mapped_tile,@l) if(defined $mapped_tile);\n";
1552 38 alirezamon
        }
1553
        set_gui_status($self,"ref",1);
1554
 
1555
}
1556
 
1557
 
1558
 
1559
 
1560
 
1561
 
1562
 
1563
 
1564
sub worst_map_algorithm{
1565
 
1566
        my $self=shift;
1567
 
1568
 
1569 43 alirezamon
        my $nx=$self->object_get_attribute('noc_param','T1');
1570
        my $ny=$self->object_get_attribute('noc_param','T2');
1571 38 alirezamon
        my $nc= $nx * $ny;
1572
 
1573 48 alirezamon
        my @tasks=get_all_merged_tasks($self);
1574 38 alirezamon
        my @tiles= get_tiles_name($self);
1575
 
1576
        my $n_tasks = scalar  @tasks;
1577
 
1578
 
1579
 
1580
 
1581
        my @unmapped_tasks_set=@tasks; # unmapped set of tasks
1582
        my @unallocated_tiles_set=@tiles;       # tile ids which are not allocated yet
1583
 
1584
 
1585
 
1586
 
1587
        #------ step 1: find the task with highest weighted communication volume
1588
        # find the max of com_vol
1589
        # consider all incoming and outgoing connections of each tasks
1590
 
1591 48 alirezamon
        my %com_tasks= $self->get_communication_task('merge');
1592 38 alirezamon
        #print  Data::Dumper->Dump([\%com_tasks],['mpsoc']);    
1593
 
1594
        my $max_com_task;
1595
        my $max_com =0;
1596
        foreach my $p (sort keys %com_tasks){
1597
                #print "$p\n";
1598
                if(defined $com_tasks{$p}{'total'}){
1599
                if ($com_tasks{$p}{'total'} >$max_com){
1600
                        $max_com = $com_tasks{$p}{'total'};
1601
                        $max_com_task = $p;
1602
                }}
1603
        }
1604
 
1605
 
1606
 
1607
 
1608
        #------ step 2: find the tile with min number of neighbors
1609
        # normally, this tile is in the corners 
1610
        my $min_neighbors_tile_id = find_min_neighbor_tile($self);
1611
 
1612
 
1613
 
1614
 
1615
        my %map=get_locked_map ($self);
1616
        $self->remove_nlock_mapping();
1617
        foreach my $mapped_task (sort keys %map){
1618
                        my $mapped_tile=$map{$mapped_task};
1619
                        @unmapped_tasks_set=remove_scolar_from_array(\@unmapped_tasks_set,$mapped_task);
1620
                        @unallocated_tiles_set=remove_scolar_from_array(\@unallocated_tiles_set,$mapped_tile);
1621
        }
1622
 
1623
 
1624
 
1625
 
1626
        # add this task with highest weighted communication volume to the mapped task set
1627
        #push(@mapped_tasks_set,$max_com_task);
1628
        #task_mapping[max_com_task] = max_neighbors_tile_id;
1629
 
1630
        if(!defined $map{$max_com_task}){
1631
                $map{$max_com_task}=$min_neighbors_tile_id;
1632
                @unmapped_tasks_set=remove_scolar_from_array(\@unmapped_tasks_set,$max_com_task);
1633
                @unallocated_tiles_set=remove_scolar_from_array(\@unallocated_tiles_set,$min_neighbors_tile_id);
1634
        }
1635
 
1636
 
1637
 
1638
 
1639
 
1640
 
1641
 
1642
        #------ step 3: map all unmapped tasks
1643
        while(scalar @unmapped_tasks_set){
1644
                $max_com =0;
1645
                my $max_com_unmapped_task;
1646
                my $max_overall_com=0;
1647
                #--------- step 3.1:
1648
                # find the unmapped task which communicates most with mapped_tasks_set
1649
                # among many tasks which have the same communication volume with mapped_tasks,
1650
                # choose the task with highest communication volume with others
1651
 
1652
                foreach my $unmapped_task (@unmapped_tasks_set){
1653
 
1654
                        my $com_vol=0;
1655
                        foreach my $mapped_task (sort keys %map){
1656
                                $com_vol += $com_tasks{$unmapped_task}{$mapped_task};
1657
                                $com_vol += $com_tasks{$mapped_task}{$unmapped_task};
1658
                        }
1659
 
1660
                        my $overall_com_vol = 0;
1661
                        foreach my $p (@tasks){
1662
                                $overall_com_vol += $com_tasks{$unmapped_task}{$p};
1663
                                $overall_com_vol += $com_tasks{$p}{$unmapped_task};
1664
                        }
1665
 
1666
 
1667
                        if ($com_vol > $max_com){
1668
                                $max_com = $com_vol;
1669
                                $max_com_unmapped_task = $unmapped_task;
1670
                                $max_overall_com = $overall_com_vol;
1671
                        }
1672
                        elsif ($com_vol == $max_com){ # choose if it have higher comm volume
1673
                                if ($overall_com_vol > $max_overall_com){
1674
                                        $max_com_unmapped_task = $unmapped_task;
1675
                                        $max_overall_com = $overall_com_vol;
1676
                                }
1677
                        }
1678
                }#foreach my $unmapped_task (@unmapped_tasks_set)
1679
 
1680
                #--------- step 3.2, find the unallocated tile with highest communication cost to/from allocated_tile_set
1681
                my $max_com_cost;
1682
                my $max_com_cost_tile_id;
1683
 
1684
 
1685
                foreach my $unallocated_tile(@unallocated_tiles_set){
1686
                        my $com_cost = 0;
1687 48 alirezamon
                        #my ($unallocated_x,$unallocated_y)=tile_id_to_loc($unallocated_tile);
1688
                        my $unallocated_tile_num = tile_id_number($unallocated_tile);
1689 38 alirezamon
                        # scan all mapped tasks
1690
                        foreach my $mapped_task (sort keys %map){
1691
                                # get location of this mapped task
1692
                                my $mapped_tile=$map{$mapped_task};
1693 48 alirezamon
                                #my ($allocated_x,$allocated_y)=tile_id_to_loc($mapped_tile);
1694
                                my $mapped_tile_num = tile_id_number($mapped_tile);
1695
                                # mahattan distance of 2 tiles                          
1696
                                my $mah_distance=get_endpoints_mah_distance($self,$unallocated_tile_num,$mapped_tile_num);
1697 38 alirezamon
 
1698
                                $com_cost += $com_tasks{$max_com_unmapped_task}{$mapped_task} * $mah_distance;
1699
                                $com_cost += $com_tasks{$mapped_task}{$max_com_unmapped_task} * $mah_distance;
1700
 
1701
                        }
1702
                        $max_com_cost = $com_cost-1 if(!defined $max_com_cost);
1703
                        if ($com_cost > $max_com_cost){
1704
                                $max_com_cost = $com_cost;
1705
                                $max_com_cost_tile_id = $unallocated_tile;
1706
                        }
1707
                }
1708
 
1709
                # add max_com_unmapped_task to the mapped_tasks_set set
1710
                #task_mapping[max_com_unmapped_task] = min_com_cost_tile_id;
1711
                $map{$max_com_unmapped_task}=$max_com_cost_tile_id;
1712
                @unmapped_tasks_set=remove_scolar_from_array(\@unmapped_tasks_set,$max_com_unmapped_task);
1713
                @unallocated_tiles_set=remove_scolar_from_array(\@unallocated_tiles_set,$max_com_cost_tile_id);
1714
 
1715
        }
1716
 
1717
 
1718
        foreach my $mapped_task (sort keys %map){
1719
                        my $mapped_tile=$map{$mapped_task};
1720
                        #print "$mapped_tile=\$map{$mapped_task};\n";
1721 48 alirezamon
                        #$self->object_add_attribute('MAP_TILE',"$mapped_task", $mapped_tile) if(defined $mapped_tile);
1722
 
1723 38 alirezamon
                        $self->object_add_attribute('MAP_TASK',"$mapped_tile",$mapped_task) if(defined $mapped_tile);
1724 48 alirezamon
                        my @l=($mapped_task);
1725
                        $self->object_add_attribute("mapping","$mapped_tile",\@l) if(defined $mapped_tile);
1726
                        #print "$self->object_add_attribute(\"mapping\",\"$mapped_tile\",$mapped_task);\n"; 
1727 38 alirezamon
        }
1728
        set_gui_status($self,"ref",1);
1729
 
1730
}
1731
 
1732
 
1733
 
1734
 
1735
 
1736
sub get_task_assigned_to_tile {
1737 48 alirezamon
        my ($self,$i)=@_;
1738
        #my $p= $self->object_get_attribute("MAP_TASK","tile($i)");
1739
        my $r=$self->object_get_attribute("mapping","tile($i)");
1740
        return undef if(!defined $r);
1741
        my @l=@{$r};
1742
        return $l[0];
1743 38 alirezamon
}
1744
 
1745
 
1746
 
1747
sub get_assigned_tiles{
1748
        my $self=shift;
1749 48 alirezamon
        my @assigned_tiles;
1750
        my @tiles=get_tiles_name($self);
1751
        foreach my $p (@tiles){
1752
                my @l=@{$self->object_get_attribute("mapping","$p")};
1753
                push(@assigned_tiles,$p)if(defined $l[0] );
1754
        }
1755
        #my @assigned_tiles = sort keys %{$self->{'MAP_TASK'}};
1756
        return @assigned_tiles;
1757 38 alirezamon
}
1758
 
1759
sub map_task {
1760
        my ($self,$task,$tile)=@_;
1761 48 alirezamon
        #my $oldtile= $self->{"MAP_TILE"}{$task};
1762
        my $oldtile=get_task_give_tile($self,$task);
1763 38 alirezamon
        if($tile eq "-"){
1764 48 alirezamon
                #delete $self->{"MAP_TILE"}{$task};             
1765 38 alirezamon
        }else{
1766 48 alirezamon
                #$self->{"MAP_TILE"}{$task}= $tile;
1767 38 alirezamon
                $self->{'MAP_TASK'}{$tile}= $task;
1768 48 alirezamon
                my @l=($task);
1769
                $self->object_add_attribute("mapping","$tile",\@l);
1770 38 alirezamon
        }
1771 48 alirezamon
        delete $self->{"MAP_TASK"}{$oldtile} if(defined $oldtile);
1772
        $self->object_add_attribute("mapping",$oldtile,undef) if(defined $oldtile);
1773 38 alirezamon
}
1774
 
1775
sub remove_selected_traces{
1776 48 alirezamon
        my ($self,$category)=@_;
1777
        my @traces= get_trace_list($self,$category);
1778 38 alirezamon
        foreach my $p (@traces) {
1779 48 alirezamon
                my $select=$self->object_get_attribute("${category}_$p",'selected', 0);
1780 38 alirezamon
 
1781
                if($select){
1782 48 alirezamon
                        $self->remove_trace($category,"$p");
1783 38 alirezamon
 
1784
                }
1785
        }
1786
        set_gui_status($self,"ref",1);
1787
}
1788
 
1789
 
1790
 
1791
sub auto_generate_injtratio{
1792 48 alirezamon
        my ($self,$category)=@_;
1793
        my %com_tasks= $self->get_communication_task($category);
1794
        my @traces= get_trace_list($self,'raw');
1795 38 alirezamon
        foreach my $p (@traces) {
1796 48 alirezamon
                my ($src,$dst, $Mbytes, $file_id, $file_name)=get_trace($self,$category,$p);
1797 38 alirezamon
                my $max= $com_tasks{$file_id}{'maxsent'};
1798
                my $sent= $com_tasks{$src}{'sent'};
1799
                my $ratio = ($sent*100)/$max;
1800 48 alirezamon
                $self->object_add_attribute("raw_$p",'injct_rate',$ratio);
1801 38 alirezamon
 
1802 48 alirezamon
                my $minpck = $self->object_get_attribute("raw_$p",'min_pck_size');
1803
                my $maxpck = $self->object_get_attribute("raw_$p",'max_pck_size' );
1804 38 alirezamon
                my $avg_pck_size =($minpck+ $maxpck)/2;
1805
                my $pck_num = ($Mbytes*8) /($avg_pck_size*64);
1806
 
1807
 
1808
                my $burst =$pck_num/ $com_tasks{$src}{'min_pck_num'} ;
1809 48 alirezamon
                $self->object_add_attribute("raw_$p",'burst_size',ceil($burst));
1810 38 alirezamon
 
1811 48 alirezamon
                #my $burst_size = gen_spin_object ($self,"raw_$p",'burst_size',"1,1024,1", 1,undef,undef);
1812 38 alirezamon
 
1813
 
1814
 
1815
        }
1816
        set_gui_status($self,"ref",1);
1817
 
1818
 
1819
}
1820 48 alirezamon
 
1821
 
1822
sub trace_merger{
1823
        my ($self,$tview,$mode)=@_;
1824
        my $table= def_table(2,10,FALSE);
1825
        my $row=0;
1826
        my $col=0;
1827 38 alirezamon
 
1828 48 alirezamon
        my $m= ($mode eq 'task')? "Task" :"Actor";
1829
 
1830
 
1831
        my $label = gen_label_in_center(' ');
1832
    $label->set_markup ("<u>Group ${m}s</u>      ");
1833
        $table->attach ($label,$col, $col+5,  $row, $row+1,'shrink','shrink',2,2);$col+=5;
1834
        my ($Ebox,$entry)=def_h_labeled_entry ("New group name:",undef);
1835
        $table->attach ($Ebox,$col, $col+4,  $row, $row+1,'shrink','shrink',2,2);$col+=5;
1836
        my $add=def_image_button('icons/plus.png');
1837
        $table->attach ($add,$col, $col+1,  $row, $row+1,'shrink','shrink',2,2);$col+=1;
1838
 
1839
        $row++;
1840
        $col=0;
1841
 
1842
        #my @info =  (
1843
        #{ label=>'Number of Group', param_name=>'GROUP_NUM', type=>"Spin-button", default_val=>1, content=>"1,1000,1", info=>"Several  ${m}s can be grouped and mapped on the same tile. Define the number of groups which ${m} can be categorized to.", param_parent=>'noc_param', ref_delay=>1,placement=>'vertical'}
1844
        #);
1845
 
1846
        #foreach my $d (@info) {
1847
        #       ($row,$col)=add_param_widget ($self, $d->{label}, $d->{param_name}, $d->{default_val}, $d->{type}, $d->{content}, $d->{info}, $table,$row,$col,1, $d->{param_parent}, $d->{ref_delay},'ref',$d->{placement});
1848
        #}
1849
 
1850
 
1851
        return add_widget_to_scrolled_win($table);
1852
 
1853
}
1854
 
1855
 
1856
 
1857
 
1858
sub select_trace_file {
1859
        my ($self,$tview,$mode)=@_;
1860
        my $traces=trace_pad($self,$tview,$mode);
1861
        my $traces_ctrl=trace_pad_ctrl($self,$tview,$mode);
1862
        my $h=gen_hpaned_adj($self,$traces_ctrl,.20,$traces,'trace-hpan');
1863
        return $h;
1864
}
1865
 
1866
 
1867
sub trace_maker_notebook{
1868
        my ($self,$mode,$tview)=@_;
1869
        my $notebook = gen_notebook();
1870
        my $lb= ($mode eq 'orcc')?  'Actor' : 'Trace';
1871
        my $group_num=16;
1872
 
1873
 
1874
        $notebook->set_tab_pos ('left');
1875
        $notebook->set_scrollable(TRUE);
1876
 
1877
        my $page1=select_trace_file($self,$tview,$mode);
1878
        $notebook->append_page ($page1,gen_label_in_center  ("1-Select $mode file"));
1879
 
1880
        my ($NE, $NR, $RAw, $EAw, $Fw)=get_topology_info($self);
1881
 
1882
        #group tasks
1883
        $self->object_add_attribute('grouping','group_name_root','group');
1884
        $self->object_add_attribute('grouping','group_name_editble','YES');
1885
        $self->object_add_attribute('grouping','trace_icon','icons/cd.png');
1886
        $self->object_add_attribute('grouping','group_num',$NE);
1887
        $self->object_add_attribute('grouping','map_limit',1024);
1888
        $self->object_add_attribute('grouping','lable',"${lb}s: Drag and drop ${lb}s to bottom group list");
1889
        my $group_ctrl =gen_group_ctrl_box($self,$tview,$mode);
1890
 
1891
        my @tasks=get_all_tasks($self,'raw');
1892
        my $page2=drag_and_drop_page($self,$tview,'grouping',\@tasks,$group_ctrl);
1893
        $notebook->append_page ($page2,gen_label_in_center  ("2-Group ${lb}s   "));
1894
 
1895
        #map tasks      
1896
        $self->object_add_attribute('mapping','group_name_root','tile');
1897
        $self->object_add_attribute('mapping','group_name_editble','NO');
1898
        $self->object_add_attribute('mapping','trace_icon','icons/cd2.png');
1899
        $self->object_add_attribute('mapping','lable',"${lb}s: Drag and drop ${lb}s/grouped ${lb}s to bottom tile list");
1900
        $self->object_add_attribute('mapping','map_limit',1);
1901
        $self->object_add_attribute('mapping','group_num',$NE);
1902
 
1903
        #get list of non-empty groups   
1904
        my @merged_tasks=get_all_merged_tasks($self);
1905
        my $map_ctrl =gen_mapping_ctrl_box($self,$tview,$mode);
1906
 
1907
        # check task names to be uniq 
1908
        my @r= return_not_unique_names_in_array(@merged_tasks);
1909
    foreach my $p (@r){
1910
        add_colored_info($tview,"$lb name $p is not unique!\n",'red');
1911
    }
1912
 
1913
 
1914
        my $page3=drag_and_drop_page($self,$tview,'mapping',\@merged_tasks,$map_ctrl);
1915
        $notebook->append_page ($page3,gen_label_in_center  ("3-Map ${lb}s"));
1916
 
1917
 
1918
 
1919
 
1920
        #my $page4=routing_page($self,$tview);
1921
        #$notebook->append_page ($page4,gen_label_in_center ("Route Selection"));
1922
 
1923
 
1924
 
1925
        $notebook->show_all;
1926
 
1927
        my $first=1;
1928
        my $page_num=$self->object_get_attribute ("process_notebook","currentpage");
1929
        $notebook->set_current_page ($page_num) if(defined $page_num);
1930
        $notebook->signal_connect( 'switch-page'=> sub{
1931
                $self->object_add_attribute ("process_notebook","currentpage",$_[2]);   #save the new pagenumber
1932
        });
1933
        $notebook->signal_connect("switch-page" => sub{
1934
                if(!$first){
1935
 
1936
                        set_gui_status($self,"ref",1);
1937
                }else {
1938
                        set_gui_status($self,"ref",1);
1939
                }
1940
                $first=0;
1941
        });
1942
 
1943
        return $notebook;
1944
 
1945
}
1946
 
1947
sub get_all_merged_tasks {
1948
        my($self)=@_;
1949
        my @merged;
1950
        my $group_num=$self->object_get_attribute('mapping','group_num');
1951
        $group_num = 0 if(!defined $group_num);
1952
        for(my $i=0;$i<$group_num;$i=$i+1){
1953
                my $gref = $self->object_get_attribute('grouping',"group($i)");
1954
                next if(! defined $gref);
1955
                next if (scalar @{$gref} == 0);
1956
 
1957
                my $label =  $self->object_get_attribute('grouping',"group($i)"."_name");
1958
                $label = "group($i)" if(!defined $label);
1959
                push (@merged,"$label");
1960
        }
1961
        my $uref= $self->object_get_attribute('grouping','ungrouped');
1962
        push (@merged, @{$uref}) if(defined  $uref);
1963
        return @merged;
1964
}
1965
 
1966
 
1967
 
1968
sub gen_mapping_ctrl_box{
1969
        my ($self,$tview,$mode)=@_;
1970
        my $map_ctrl= trace_map_ctrl($self,$tview,$mode);
1971
        my $map_info=map_info($self);
1972
        my $v_paned=gen_vpaned($map_ctrl,.4,$map_info);
1973
        return $v_paned;
1974
}
1975
 
1976
sub gen_group_ctrl_box{
1977
        my ($self,$tview,$mode)=@_;
1978
        my $group_ctrl= trace_group_ctrl($self,$tview,$mode);
1979
        #my $map_info=map_info($self);
1980
        #my $v_paned=gen_vpaned($map_ctrl,.5,$map_info);
1981
        #return $v_paned; 
1982
 
1983
        my $group_info = group_info ($self,$tview,$mode);
1984
        my $v_paned=gen_vpaned($group_ctrl,0.2,$group_info);
1985
        return $v_paned;
1986
 
1987
        #return $group_ctrl;
1988
}
1989
 
1990
 
1991
 
1992
 
1993
 
1994
sub build_trace_gui {
1995
        my ($self,$mode,$ref,$w) = @_;
1996
        set_gui_status($self,"ideal",0);
1997
        $self->object_add_attribute ("process_notebook","currentpage",0);
1998
        if($mode eq 'task'){
1999
                $self->object_add_attribute('noc_param','T1',2);
2000
                $self->object_add_attribute('noc_param','T2',2);
2001
                $self->object_add_attribute('noc_param','T3',1);
2002
                $self->object_add_attribute('noc_param','Fpay',32);
2003
                $self->object_add_attribute('noc_param','V',1);
2004
                $self->object_add_attribute('noc_param','C',1);
2005
                $self->object_add_attribute('noc_param','TOPOLOGY','"MESH"');
2006
        }
2007
 
2008
        $self->object_add_attribute("file_id",undef,'a');
2009
        $self->object_add_attribute("trace_id",undef,0);
2010
        $self->object_add_attribute('select_multiple','action',"_");
2011
        $self->object_add_attribute('Auto','Auto_inject',"1\'b1");
2012
        if(defined $ref){
2013
           # add noc parameters
2014
                my %params=%{$ref};
2015
                foreach my $p (sort keys %params){
2016
                        $self->{$p}=$params{$p};
2017
 
2018
                }
2019
 
2020
        }
2021
 
2022
 
2023
        my ($scwin_info,$tview)= create_txview();
2024
        my $notebook = trace_maker_notebook($self,$mode,$tview);
2025
        my $tt = ($mode eq 'task') ? 0.65 : 0.55;
2026
 
2027
        my $v2=gen_vpaned($notebook,$tt,$scwin_info);
2028
 
2029
 
2030
 
2031
 
2032
 
2033
 
2034
 
2035
 
2036
        set_gui_status($self,"ideal",0);
2037
 
2038
        my $main_table= def_table(2,10,FALSE);
2039
 
2040
 
2041
 
2042
 
2043
        my $generate = def_image_button('icons/gen.png','Generate');
2044
        my $open = def_image_button('icons/browse.png','Load');
2045
        my ($entrybox,$entry) = def_h_labeled_entry('Save as:',undef);
2046
        $entry->signal_connect( 'changed'=> sub{
2047
                my $name=$entry->get_text();
2048
                $self->object_add_attribute ("save_as",undef,$name);
2049
        });
2050
 
2051
        my $entry2=gen_entry_object($self,'out_name',undef,undef,undef,undef);
2052
        my $entrybox2=gen_label_info(" Output file name:",$entry2);
2053
 
2054
        my $save = def_image_button('icons/save.png','Save');
2055
        $entrybox->pack_end($save,   FALSE, FALSE,0);
2056
 
2057
        $main_table->attach_defaults ($v2  , 0, 12, 0,24);
2058
        $main_table->attach ($open,0, 3, 24,25,'expand','shrink',2,2);
2059
        $main_table->attach ($entrybox,3, 5, 24,25,'expand','shrink',2,2);
2060
        $main_table->attach ($entrybox2,5,6 , 24,25,'expand','shrink',2,2) if ($mode eq 'task');
2061
        $main_table->attach ($generate, 6, 9, 24,25,'expand','shrink',2,2);
2062
 
2063
 
2064
        my $sc_win =add_widget_to_scrolled_win($main_table);
2065
 
2066
 
2067
 
2068
        $open-> signal_connect("clicked" => sub{
2069
 
2070
                load_workspace($self);
2071
                set_gui_status($self,"ref",5);
2072
 
2073
        });
2074
 
2075
        $save-> signal_connect("clicked" => sub{
2076
                save_as($self);
2077
                set_gui_status($self,"ref",5);
2078
 
2079
 
2080
        });
2081
 
2082
        $generate->signal_connect("clicked" => sub{
2083
                genereate_output_tasks($self) if ($mode eq 'task');
2084
                genereate_output_orcc ($self,$tview,$w) if ($mode eq 'orcc');
2085
 
2086
        });
2087
 
2088
 
2089
 
2090
 
2091
 
2092
 
2093
        #check soc status every 0.5 second. refresh device table if there is any changes 
2094
        Glib::Timeout->add (100, sub{
2095
 
2096
                my ($state,$timeout)= get_gui_status($self);
2097
 
2098
                if ($timeout>0){
2099
                        $timeout--;
2100
                        set_gui_status($self,$state,$timeout);
2101
                        return TRUE;
2102
 
2103
                }
2104
                if($state eq "ideal"){
2105
                        return TRUE;
2106
 
2107
                }
2108
 
2109
 
2110
 
2111
                #refresh GUI
2112
                my $saved_name=$self->object_get_attribute('save_as');
2113
                if(defined $saved_name) {$entry->set_text($saved_name);}
2114
 
2115
                $saved_name=$self->object_get_attribute('out_name');
2116
                if(defined $saved_name) {$entry2->set_text($saved_name);}
2117
 
2118
 
2119
                $notebook->destroy;
2120
                $notebook = trace_maker_notebook($self,$mode,$tview);
2121
                $v2 -> pack1($notebook, TRUE, TRUE);
2122
 
2123
                set_gui_status($self,"ideal",0);
2124
 
2125
                return TRUE;
2126
 
2127
        } );
2128
 
2129
        return $sc_win;
2130
 
2131
}
2132
 
2133
 
2134
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.