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 48

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 43 alirezamon
#!/usr/bin/perl -w
2 48 alirezamon
use constant::boolean;
3 43 alirezamon
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 48 alirezamon
# number; b:bit location;  W: number width log2(num); v: 1 assert the bit, 0 de-assert the bit; 
33 43 alirezamon
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 48 alirezamon
    else {$$num = $$num | $mask;} #de-assert bit      
41 43 alirezamon
}
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 48 alirezamon
     }
128
     if($traffic eq "custom"){
129
        my $num=$self->object_get_attribute($sample,"CUSTOM_SRC_NUM");
130
        for (my $i=0;$i<$num;$i++){
131
                                my $src = $self->object_get_attribute($sample,"SRC_$i");
132
                                my $dst = $self->object_get_attribute($sample,"DST_$i");
133
                                return endp_addr_encoder($self,$dst) if($src == $core_num);
134
        }
135
        return endp_addr_encoder($self,$core_num);#off     
136
     }
137 43 alirezamon
 
138 48 alirezamon
                 print ("ERROR: $traffic is an unsupported traffic pattern\n");
139 43 alirezamon
                 $dest_x = $current_x;
140
                 $dest_y = $current_y;
141
                 $dest_l = $current_l;
142
                 return mesh_tori_addr_join($dest_x,$dest_y,$dest_l,$T1, $T2,$T3);
143
}
144
 
145
 
146
 
147
 
148
sub pck_dst_gen_1D {
149
        my ($self,$sample,$traffic,$core_num,$line_num,$rnd)=@_;
150
        my ($topology, $T1, $T2, $T3, $V, $Fpay) = get_sample_emulation_param($self,$sample);
151
        my ($NE, $NR, $RAw, $EAw, $Fw) = get_topology_info_sub ($topology, $T1, $T2, $T3, $V, $Fpay);
152
        my $NEw=log2($NE);
153
 
154
        if( $traffic eq "random") {
155
                my @randoms=@{$rnd};
156
                my $tmp = @{$randoms[$core_num]}[$line_num-1];
157
                return endp_addr_encoder($self,$tmp);
158
        }
159
 
160
        if( $traffic eq "transposed 1"){
161
                  return endp_addr_encoder($self,$NE-$core_num-1);
162
        }
163
 
164
        if( $traffic eq "transposed 2"){
165
                  return endp_addr_encoder($self,$NE-$core_num-1);
166
        }
167
 
168
        if( $traffic eq "bit reverse"){
169
                my $tmp=0;
170
                for(my $i=0; $i< $NEw; $i++) {setBit(\$tmp, $i, $NEw, getBit($core_num, $NEw-$i-1, $NEw));}
171
                return endp_addr_encoder($self,$tmp);
172
         }
173
 
174
         if( $traffic  eq "bit complement") {
175
                my $tmp=0;
176
                for(my $i=0; $i< $NEw; $i++) {  setBit(\$tmp, $i, $NEw, getBit($core_num, $i, $NEw)==0)};
177
                return endp_addr_encoder($self,$tmp);
178
        }
179
 
180
        if( $traffic eq "tornado") {
181
                #[(x+(k/2-1)) mod k, (y+(k/2-1)) mod k],
182
                 return endp_addr_encoder($self, ($core_num + (int($NE/2)-1)) % $NE);
183
     }
184
 
185
      if($traffic eq "shuffle"){
186
                #di = si−1 mod b
187
                my $tmp=0;
188
                for(my $i=0; $i< $NEw; $i++) { setBit(\$tmp, $i, $NEw, getBit($core_num, $i-1, $NEw));}
189
                return endp_addr_encoder($self,$tmp);
190
     }
191
 
192
    if($traffic eq "bit rotation"){
193
                #di = si+1 mod b
194
                my $tmp=0;
195
                for(my $i=0; $i< $NEw; $i++) { setBit(\$tmp, $i, $NEw, getBit($core_num, $i+1, $NEw));}
196
                return endp_addr_encoder($self,$tmp);
197
     }
198
 
199
     if($traffic eq "neighbor"){
200
                #dx = sx + 1 mod k
201
                 return endp_addr_encoder($self,($core_num + 1) % $NE);
202 48 alirezamon
         }
203
 
204
         if($traffic eq "custom"){
205
        my $num=$self->object_get_attribute($sample,"CUSTOM_SRC_NUM");
206
        for (my $i=0;$i<$num;$i++){
207
                                my $src = $self->object_get_attribute($sample,"SRC_$i");
208
                                my $dst = $self->object_get_attribute($sample,"DST_$i");
209
                                return endp_addr_encoder($self,$dst) if($src == $core_num);
210
        }
211
        return endp_addr_encoder($self,$core_num);#off     
212
     }
213 43 alirezamon
 
214 48 alirezamon
         printf ("ERROR: $traffic is an unsupported traffic pattern\n");
215 43 alirezamon
         return  endp_addr_encoder($self,$core_num);
216
}
217
 
218
 
219
sub pck_dst_gen{
220
        my ($self,$sample,$traffic,$core_num,$line_num,$rnd)=@_;
221
        my ($topology, $T1, $T2, $T3, $V, $Fpay) = get_sample_emulation_param($self,$sample);
222
        return  pck_dst_gen_2D ($self,$sample,$traffic,$core_num,$line_num,$rnd) if(( $topology eq '"MESH"') ||( $topology eq '"TORUS"'));
223
        return  pck_dst_gen_1D ($self,$sample,$traffic,$core_num,$line_num,$rnd);
224
}
225
 
226
 1;
227 48 alirezamon
 

powered by: WebSVN 2.1.0

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