Skip to content

Commit

Permalink
Merge pull request #5 from hariharan-n/master
Browse files Browse the repository at this point in the history
Added EjectFlits and Permute
  • Loading branch information
ameyagodbole authored Jan 13, 2017
2 parents 06f1681 + 37940b2 commit 788fcea
Showing 1 changed file with 200 additions and 35 deletions.
235 changes: 200 additions & 35 deletions src/routers/chipper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
#include "chipper.hpp"
#include "stats.hpp"
#include "globals.hpp"
#include "routefunc.hpp"

int retire_index = 4; // HH : For mesh, ejection is through _output_channels[4];

Chipper::Chipper( const Configuration& config,
Module *parent, const string & name, int id,
Expand All @@ -30,11 +33,11 @@ Chipper::Chipper( const Configuration& config,

assert(_inputs == _outputs);

_input_buffer.resize(_inputs);
_output_buffer.resize(_outputs);
_input_buffer.resize(_inputs-1);
_output_buffer.resize(_outputs-1);

_stage_1.resize(_inputs);
_stage_2.resize(_inputs);
_stage_1.resize(_inputs-1);
_stage_2.resize(_inputs-1);
}

Chipper::~Chipper()
Expand Down Expand Up @@ -155,59 +158,221 @@ void Chipper::_InternalStep( )

// Added by HH
void _EjectFlits(){
Flit *f;

for ( int input = 0; input < _inputs; ++input ) {
array Flit *f received_flits[_inputs]; // To keep track of all the flits that need to be ejected
int flit_to_eject = -1;
int golden_cnt = 0;
for ( int input = 0; input < _inputs-1; ++input ) {
// One input channel is for the router
// f = _input_buffer[input].pop;

if ( f->dest == GetID() ) {
;
received_flits[input] = f;
// Check for golden status and golden tie
if(f->golden == 1 && !golden_cnt)
{
flit_to_eject = input;
golden_cnt++;
}
else if(f->golden == 1)
{
if(received_flits[flit_to_eject]->pri > f->pri) // Resolve golden tie based on older flit
{
flit_to_eject = input;
break;
}
}
}
else if {

else{
received_flits[input] = NULL; // Flit not at destination
}
else
}
if(flit_to_eject == -1){
for( int input = 0; input < _inputs-1; ++input ){
// Iterating through the array of stored flits that need to be ejected
// to find the oldest flit and consequently retiring that flit
int oldest_flit_index;
int high_pri = -1;
if(received_flits[input] != NULL && received_flits[input]->pri > high_pri)
{
high_pri = received_flits[input]->pri;
oldest_flit_index = input;
}
if(high_pri > -1)
{
flit_to_eject = oldest_flit_index;
_output_channels[retire_index] = received_flits[flit_to_eject];
// HH : Receive flit with oldest_flit_index -> Need to apply the function that handles retire flit
}
}
}
}


void Chipper::_Buffer_to_stage1()
{
map<int, Flit *> intermediate_1;
// map<int, Flit *> intermediate_1;
int input = 0;
map<int, Flit*>::iterator it;
for ( int input = 0; input < _inputs; ++input ){
intermediate = _input_buffer[input];
for( map<int, Flit*>::iterator it = intermediate_1.begin() ; it = intermediate_1.end() ; ++it ){ //Nandan: Adding the delay associated with the pipe
if(pair_time == it->first){
it->first = it->first + delay_pipe_1;
}
}
stage_1[input] = _input_buffer[input];
// intermediate = _input_buffer[input];
// for( map<int, Flit*>::iterator it = intermediate_1.begin() ; it = intermediate_1.end() ; ++it ){ //Nandan: Adding the delay associated with the pipe
// if(pair_time == it->first){
// it->first = it->first + 1;
// }
// }
it =_input_buffer[input].find(GetSimTime());
if(it == _input_buffer[input].end())
continue;
_stage_1[input].insert(make_pair(it->first+1, it->second));
_input_buffer[input].erase(it);
}
}

void Chipper::_stage1_to_stage2()
{
msp<int, Flit *> intermediate_2;
// msp<int, Flit *> intermediate_2;
int input = 0;
for ( int input = 0; input < _inputs; ++input ){ // Nandan: Adding the delay associated with the pipe
intermediate = _stage_1[input];
for( map<int, Flit*>::iterator it = intermediate_2.begin() ; it = intermediate_2.end() ; ++it ){
if(pair_time == it->first){
it->first = it->first + delay_pipe_2;
}
}
stage_2[input] = _stage_1[input];
// intermediate = _stage_1[input];
// for( map<int, Flit*>::iterator it = intermediate_2.begin() ; it = intermediate_2.end() ; ++it ){
// if(pair_time == it->first){
// it->first = it->first + 1;
// }
// }
it = _stage_1[input].find(GetSimTime());
if(it == _stage_1[input].end())
continue;
_stage_2[input].insert(make_pair(it->first+1, it->second));
_stage_1[input].erase(it);
}
}

void Chipper::Permute()
{
// int router_number = GetID();
// int west = _LeftNode(router_number, 0);
// int east = _RightNode(router_number, 0);
// int north = _LeftNode(router_number, 1);
// int south = _RightNode(router_number, 1);
// vector<int> direction;
// vector<int> priority;
// vector<bool> golden;
// direction.resize(_inputs-1);
// priority.resize(_inputs-1);
// for(input = 0; input < _inputs; ++input)
// {

// if(golden[input] == true)
Partial_Permute(2,0,1);
Partial_Permute(3,1,1);
Partial_Permute(3,2,2);
Partial_Permute(1,0,0);
// }
}

void Chipper::Partial_Permute(int dir1, int dir2, int perm_num)
{
Flit *f1;
Flit *f2;
map<int, Flit*> iterator it1,it2;
it1 = _stage_2[dir1].find(GetSimTime());
it2 = _stage_2[dir2].find(GetSimTime());
*f1 = it1->second;
*f2 = it2->second;
if((f1->golden == 1)&&(f2->golden == 1))
{
if(f1->pri >= f2->pri)
{
if(_rf(GetID(), f1->dest, true) > perm_num)
{

}
else
{
_stage_2[dir2].make_pair(it1->first, it1->second);
_stage_2[dir1].make_pair(it2->first, it2->second);
_stage_2[dir1].erase(it1);
_stage_2[dir2].erase(it2);
}
}
else
{
if(_rf(GetID(), f2->dest, true) > perm_num)
{
_stage_2[dir2].make_pair(it1->first, it1->second);
_stage_2[dir1].make_pair(it2->first, it2->second);
_stage_2[dir1].erase(it1);
_stage_2[dir2].erase(it2);
}
else
{

}
}
}
else if((f1->golden == 1))
{
if(_rf(GetID(), f1->dest, true) > perm_num)
{

}
else
{
_stage_2[dir2].make_pair(it1->first, it1->second);
_stage_2[dir1].make_pair(it2->first, it2->second);
_stage_2[dir1].erase(it1);
_stage_2[dir2].erase(it2);
}
}
else if((f2->golden == 1))
{
if(_rf(GetID(), f2->dest, true) > perm_num)
{
_stage_2[dir2].make_pair(it1->first, it1->second);
_stage_2[dir1].make_pair(it2->first, it2->second);
_stage_2[dir1].erase(it1);
_stage_2[dir2].erase(it2);
}
else
{

}
}
else
{
if(f1->pri >= f2->pri)
{
if(_rf(GetID(), f1->dest, true) > perm_num)
{

}
else
{
_stage_2[dir2].make_pair(it1->first, it1->second);
_stage_2[dir1].make_pair(it2->first, it2->second);
_stage_2[dir1].erase(it1);
_stage_2[dir2].erase(it2);
}
}
else
{
if(_rf(GetID(), f2->dest, true) > perm_num)
{
_stage_2[dir2].make_pair(it1->first, it1->second);
_stage_2[dir1].make_pair(it2->first, it2->second);
_stage_2[dir1].erase(it1);
_stage_2[dir2].erase(it2);
}
else
{

}
}

}
}
// Added by HH : scheme for determining Golden_packet as in chipper paper(not exactly)
// Returning the packet id that is to be made golden by just dividing time_elapsed by L instead of
// keeping track of all the packets in the network. (I don't know if a maximum number of packets is available)
// Instead of iterating over all possible packet ids called "transaction ids" from all nodes, just iterate over
// packet ids which uniquely identifies each packet
int Chipper::Golden_Packet(int L) // Parameter L is obtained from before from another function
{
int time_elapsed = GetSimTime();
int epoch_no = time_elapsed/L; // L is the golden epoch, needs to be defined as the upper
//bound of the maximum time taken by a golden packet to reach its destination
return epoch_no;
}

0 comments on commit 788fcea

Please sign in to comment.