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/] [traffic_pattern.pl] - Blame information for rev 43

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

Line No. Rev Author Line
1 43 alirezamon
#!/usr/bin/perl -w
2
use Glib qw/TRUE FALSE/;
3
use strict;
4
use warnings;
5
 
6
use FindBin;
7
use lib $FindBin::Bin;
8
 
9
sub get_sample_emulation_param {
10
        my ($emulate,$sample)=@_;
11
        my $ref=$emulate->object_get_attribute($sample,"noc_info");
12
        my %noc_info= %$ref;
13
        my $topology=$noc_info{'TOPOLOGY'};
14
        my $C=$noc_info{C};
15
        my $T1=$noc_info{'T1'};
16
        my $T2=$noc_info{'T2'};
17
        my $T3=$noc_info{'T3'};
18
        my $V =$noc_info{'V'};
19
        my $Fpay = $noc_info{'Fpay'};
20
        return ($topology, $T1, $T2, $T3, $V, $Fpay);
21
}
22
 
23
 
24
 
25
sub getBit{
26
        my ($num, $b, $W)=@_;
27
        while($b<0) {$b=$b+$W; }
28
        $b=$b % $W;
29
        return ($num >> $b) & 1;
30
}
31
 
32
# number; b:bit location;  W: number width log2(num); v: 1 assert the bit, 0 deassert the bit; 
33
sub setBit{
34
        my ($num ,$b,$W,$v)=@_;
35
        while($b<0) {$b=$b+$W;}
36
        $b=$b % $W;
37
 
38
    my $mask = 1 << $b;
39
    if ($v == 0) {$$num  = $$num & ~$mask;} # assert bit
40
    else {$$num = $$num | $mask;} #deassert bit      
41
}
42
 
43
sub pck_dst_gen_2D {
44
        my ($self,$sample,$traffic,$core_num,$line_num,$rnd)=@_;
45
        my ($topology, $T1, $T2, $T3, $V, $Fpay) = get_sample_emulation_param($self,$sample);
46
        my ($NE, $NR, $RAw, $EAw, $Fw) = get_topology_info_sub ($topology, $T1, $T2, $T3, $V, $Fpay);
47
 
48
        my $NEw=log2($NE);
49
        #for mesh-tori
50
        my  ($current_l,$current_x, $current_y);
51
        my  ($dest_l,$dest_x,$dest_y);
52
 
53
        ($current_x,$current_y,$current_l)=mesh_tori_addrencod_sep($core_num,$T1, $T2,$T3);
54
 
55
        if( $traffic eq "random") {
56
                my @randoms=@{$rnd};
57
                my $tmp = @{$randoms[$core_num]}[$line_num-1];
58
                return endp_addr_encoder($self,$tmp);
59
        }
60
 
61
        if( $traffic eq "transposed 1"){
62
                 $dest_x = $T1-$current_y-1;
63
                 $dest_y = $T2-$current_x-1;
64
                 $dest_l = $T3-$current_l-1;
65
                 return mesh_tori_addr_join($dest_x,$dest_y,$dest_l,$T1, $T2,$T3);
66
        }
67
 
68
        if( $traffic eq "transposed 2"){
69
                $dest_x = $current_y;
70
                $dest_y = $current_x;
71
                $dest_l = $current_l;
72
                return mesh_tori_addr_join($dest_x,$dest_y,$dest_l,$T1, $T2,$T3);
73
        }
74
 
75
        if( $traffic eq "bit reverse"){
76
                #di = sb−i−1
77
                my $tmp=0;
78
                for(my $i=0; $i< $NEw; $i++) {setBit(\$tmp, $i, $NEw, getBit($core_num, $NEw-$i-1, $NEw));}
79
                return endp_addr_encoder($self,$tmp);
80
        }
81
 
82
        if( $traffic  eq "bit complement") {
83
                my $tmp=0;
84
                for(my $i=0; $i< $NEw; $i++) {  setBit(\$tmp, $i, $NEw, getBit($core_num, $i, $NEw)==0)};
85
                return endp_addr_encoder($self,$tmp);
86
        }
87
 
88
        if( $traffic eq "tornado") {
89
                #[(x+(k/2-1)) mod k, (y+(k/2-1)) mod k],
90
                        $dest_x = (($current_x + (int($T1/2)-1)) % $T1);
91
                        $dest_y = (($current_y + (int($T2/2)-1)) % $T2);
92
                        $dest_l = $current_l;
93
                        return mesh_tori_addr_join($dest_x,$dest_y,$dest_l,$T1, $T2,$T3);
94
     }
95
 
96
    if($traffic eq "shuffle"){
97
                #di = si−1 mod b
98
                my $tmp=0;
99
                for(my $i=0; $i< $NEw; $i++) { setBit(\$tmp, $i, $NEw, getBit($core_num, $i-1, $NEw));}
100
                return endp_addr_encoder($self,$tmp);
101
     }
102
 
103
    if($traffic eq "bit rotation"){
104
                #di = si+1 mod b
105
                my $tmp=0;
106
                for(my $i=0; $i< $NEw; $i++) { setBit(\$tmp, $i, $NEw, getBit($core_num, $i+1, $NEw));}
107
                return endp_addr_encoder($self,$tmp);
108
     }
109
 
110
     if($traffic eq "neighbor"){
111
                #dx = sx + 1 mod k
112
                #if ($current_x==0 && $current_y==0 && $current_l ==0) {
113
            #   $dest_x = 2;
114
                #       $dest_y = 2;
115
                #       $dest_l = 0;            
116
                #}else {
117
                #       $dest_x = $current_x;
118
                #       $dest_y = $current_y;
119
                #       $dest_l = $current_l;                   
120
                #}
121
                #return mesh_tori_addr_join($dest_x,$dest_y,$dest_l,$T1, $T2,$T3);
122
 
123
                 $dest_x = ($current_x + 1) % $T1;
124
                 $dest_y = ($current_y + 1) % $T2;
125
                 $dest_l = $current_l;
126
                 return mesh_tori_addr_join($dest_x,$dest_y,$dest_l,$T1, $T2,$T3);
127
     }
128
 
129
                 print ("$traffic is an unsupported traffic pattern\n");
130
                 $dest_x = $current_x;
131
                 $dest_y = $current_y;
132
                 $dest_l = $current_l;
133
                 return mesh_tori_addr_join($dest_x,$dest_y,$dest_l,$T1, $T2,$T3);
134
}
135
 
136
 
137
 
138
 
139
sub pck_dst_gen_1D {
140
        my ($self,$sample,$traffic,$core_num,$line_num,$rnd)=@_;
141
        my ($topology, $T1, $T2, $T3, $V, $Fpay) = get_sample_emulation_param($self,$sample);
142
        my ($NE, $NR, $RAw, $EAw, $Fw) = get_topology_info_sub ($topology, $T1, $T2, $T3, $V, $Fpay);
143
        my $NEw=log2($NE);
144
 
145
        if( $traffic eq "random") {
146
                my @randoms=@{$rnd};
147
                my $tmp = @{$randoms[$core_num]}[$line_num-1];
148
                return endp_addr_encoder($self,$tmp);
149
        }
150
 
151
        if( $traffic eq "transposed 1"){
152
                  return endp_addr_encoder($self,$NE-$core_num-1);
153
        }
154
 
155
        if( $traffic eq "transposed 2"){
156
                  return endp_addr_encoder($self,$NE-$core_num-1);
157
        }
158
 
159
        if( $traffic eq "bit reverse"){
160
                my $tmp=0;
161
                for(my $i=0; $i< $NEw; $i++) {setBit(\$tmp, $i, $NEw, getBit($core_num, $NEw-$i-1, $NEw));}
162
                return endp_addr_encoder($self,$tmp);
163
         }
164
 
165
         if( $traffic  eq "bit complement") {
166
                my $tmp=0;
167
                for(my $i=0; $i< $NEw; $i++) {  setBit(\$tmp, $i, $NEw, getBit($core_num, $i, $NEw)==0)};
168
                return endp_addr_encoder($self,$tmp);
169
        }
170
 
171
        if( $traffic eq "tornado") {
172
                #[(x+(k/2-1)) mod k, (y+(k/2-1)) mod k],
173
                 return endp_addr_encoder($self, ($core_num + (int($NE/2)-1)) % $NE);
174
     }
175
 
176
      if($traffic eq "shuffle"){
177
                #di = si−1 mod b
178
                my $tmp=0;
179
                for(my $i=0; $i< $NEw; $i++) { setBit(\$tmp, $i, $NEw, getBit($core_num, $i-1, $NEw));}
180
                return endp_addr_encoder($self,$tmp);
181
     }
182
 
183
    if($traffic eq "bit rotation"){
184
                #di = si+1 mod b
185
                my $tmp=0;
186
                for(my $i=0; $i< $NEw; $i++) { setBit(\$tmp, $i, $NEw, getBit($core_num, $i+1, $NEw));}
187
                return endp_addr_encoder($self,$tmp);
188
     }
189
 
190
     if($traffic eq "neighbor"){
191
                #dx = sx + 1 mod k
192
                 return endp_addr_encoder($self,($core_num + 1) % $NE);
193
         }
194
 
195
         printf ("$traffic is an unsupported traffic pattern\n");
196
         return  endp_addr_encoder($self,$core_num);
197
}
198
 
199
 
200
sub pck_dst_gen{
201
        my ($self,$sample,$traffic,$core_num,$line_num,$rnd)=@_;
202
        my ($topology, $T1, $T2, $T3, $V, $Fpay) = get_sample_emulation_param($self,$sample);
203
        return  pck_dst_gen_2D ($self,$sample,$traffic,$core_num,$line_num,$rnd) if(( $topology eq '"MESH"') ||( $topology eq '"TORUS"'));
204
        return  pck_dst_gen_1D ($self,$sample,$traffic,$core_num,$line_num,$rnd);
205
}
206
 
207
 1;
208
 

powered by: WebSVN 2.1.0

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