orca-sim
Public Member Functions | Private Attributes | List of all members
orcasim::models::hermes::HermesRouter Class Reference

#include <HermesRouter.hpp>

Inheritance diagram for orcasim::models::hermes::HermesRouter:
orcasim::base::TimedModel orcasim::base::Model

Public Member Functions

uint32_t GetRR ()
 
Buffer< FlitType > * GetOutputBuffer (uint32_t p)
 Get a pointer to one of the output buffers. More...
 
Buffer< FlitType > * GetInputBuffer (uint32_t p)
 
void SetOutputBuffer (Buffer< FlitType > *b, uint32_t port)
 
SimulationTime Run ()
 Implementation of the Process' interface. More...
 
uint32_t GetRouteXY (FlitType flit)
 return this More...
 
 HermesRouter (std::string name, uint32_t x_pos, uint32_t y_pos)
 Ctor. More...
 
 ~HermesRouter ()
 Dtor. More...
 
std::string GetPortName (int port)
 Get the name of the port of id equals to <port> More...
 
void Reset ()
 Resets the instance to its starting state. More...
 
std::string ToString ()
 
a name that identifies the model, advisably not empty.

Default ctor.

std::string GetName ()
 Getter method for the <_name> field. More...
 
void SetName (std::string s)
 Setter method for the <_name> field. More...
 

Private Attributes

int16_t _switch_control [5]
 
int16_t _flits_to_send [5]
 
uint32_t _round_robin
 
uint32_t _x
 
uint32_t _y
 
Buffer< FlitType > * _ob [5]
 
Buffer< FlitType > * _ib [5]
 

Detailed Description

Definition at line 61 of file HermesRouter.hpp.

Constructor & Destructor Documentation

§ HermesRouter()

HermesRouter::HermesRouter ( std::string  name,
uint32_t  x_pos,
uint32_t  y_pos 
)

Ctor.

Parameters
nameName of the instance (proccess impl)
x_posX coordinate (first part of router addr)
y_posY coordinate (second part of router addr)

Definition at line 57 of file HermesRouter.cpp.

57  :
58  TimedModel(name) {
59  _x = x_pos;
60  _y = y_pos;
61 
62  // for all ports, create a new input buffer; Note that data is bufferred by
63  // input buffers, since output buffers come from somewhere else;
64  for (int i = 0; i < 5; i++) {
65  std::string bname = GetName() + ".IN-" + this->GetPortName(i);
66  _ob[i] = nullptr;
67  _ib[i] = new Buffer<FlitType>(bname, BUFFER_CAPACITY);
68  }
69 
70  #ifdef ROUTER_ENABLE_COUNTERS
71  // if counters are enabled, initiate the respective signals
72  // please note that these signals are not mapped to anywhere yet
73  _counter_active = new Signal<uint32_t>(GetName() + ".counters.active");
74  #endif
75 
76  this->Reset();
77 }
std::string GetPortName(int port)
Get the name of the port of id equals to <port>
void Reset()
Resets the instance to its starting state.
TimedModel(std::string name)
Default Ctor.
Definition: TimedModel.cpp:31
std::string GetName()
Getter method for the <_name> field.
Definition: Model.cpp:34
#define BUFFER_CAPACITY

§ ~HermesRouter()

HermesRouter::~HermesRouter ( )

Dtor.

Free allocated memory if any.

Definition at line 82 of file HermesRouter.cpp.

82  {
83  #ifdef ROUTER_ENABLE_COUNTERS
84  delete _counter_active;
85  #endif
86 
87  for (int i = 0; i < 5; i++)
88  delete(_ib[i]);
89 }

Member Function Documentation

§ GetInputBuffer()

Buffer< FlitType > * HermesRouter::GetInputBuffer ( uint32_t  p)

Definition at line 241 of file HermesRouter.cpp.

241  {
242  return _ib[r];
243 }

§ GetName()

std::string Model::GetName ( )
inherited

Getter method for the <_name> field.

Definition at line 34 of file Model.cpp.

34  {
35  return _name;
36 }
std::string _name
A name for the model.
Definition: Model.hpp:47

§ GetOutputBuffer()

Buffer< FlitType > * HermesRouter::GetOutputBuffer ( uint32_t  r)

Get a pointer to one of the output buffers.

Parameters
rThe port from which get the pointer.
Returns
A pointer to the buffer.

Definition at line 237 of file HermesRouter.cpp.

237  {
238  return _ob[r];
239 }

§ GetPortName()

std::string HermesRouter::GetPortName ( int  port)

Get the name of the port of id equals to <port>

Parameters
portthe id of the port
Returns
and instance of std::string containing port's name

Definition at line 41 of file HermesRouter.cpp.

41  {
42  switch (port) {
43  case SOUTH: return "SOUTH";
44  case NORTH: return "NORTH";
45  case WEST: return "WEST";
46  case EAST: return "EAST";
47  default: return "LOCAL";
48  }
49  return "???";
50 }
#define EAST
#define WEST
#define SOUTH
#define NORTH

§ GetRouteXY()

uint32_t HermesRouter::GetRouteXY ( FlitType  flit)

return this

Calculate the port to route a given flit.

Parameters
flitto be routed
Returns
the port to where te packet must go

Definition at line 214 of file HermesRouter.cpp.

214  {
215  FlitType tx = (flit & 0x00F0) >> 4;
216  FlitType ty = flit & 0x000F;
217 
218  // if X=0, then route "vertically" (Y)
219  if (_x == tx) {
220  return (_y == ty)
221  ? LOCAL
222  : (_y > ty)
223  ? SOUTH
224  : NORTH;
225  // route X
226  } else {
227  return (_x > tx)
228  ? WEST
229  : EAST;
230  }
231 }
#define EAST
#define WEST
#define SOUTH
#define LOCAL
#define NORTH

§ GetRR()

uint32_t HermesRouter::GetRR ( )

Definition at line 102 of file HermesRouter.cpp.

102  {
103  return _round_robin;
104 }

§ Reset()

void HermesRouter::Reset ( )
virtual

Resets the instance to its starting state.

Must be implemented by subclasses

Implements orcasim::base::TimedModel.

Definition at line 91 of file HermesRouter.cpp.

91  {
92  _round_robin = LOCAL; // starts checking on local port
93 
94  for (int i = 0; i < 5; i++) {
95  _flits_to_send[i] = 0;
96  _switch_control[i] = -1;
97  }
98 
99  // TODO(ad): reset buffers
100 }
#define LOCAL

§ Run()

SimulationTime HermesRouter::Run ( )
virtual

Implementation of the Process' interface.

Implementation of the Run method from the Proccess abstract class.

Returns
time taken for perming next cycle
The next time to schedule the event.

Implements orcasim::base::TimedModel.

Definition at line 110 of file HermesRouter.cpp.

110  {
111  // CROSSBAR CONTROL: connect priority port to destination if it has any
112  // packet to send but is waiting for the destination to free
113  if (_ib[_round_robin]->size() > 0 && _switch_control[_round_robin] == -1) {
114  // find the destination using the address in the first flit
115  uint8_t target_port = this->GetRouteXY(_ib[_round_robin]->top());
116 
117  // check whether the destination port is bound to some other source port
118  bool bound = false;
119 
120  for (int i = 0; i < 5; i++) {
121  if (_switch_control[i] == target_port) {
122  bound = true;
123  break;
124  }
125  }
126 
127  // if the port is not bind, binds it to the source
128  if (!bound) {
129  // set crossbar connection
130  _switch_control[_round_robin] = target_port;
131  // -2 means "the size flit has not arrived yet"
133  }
134  }
135 
136  // drive flits into destination ports
137  for (int i = 0; i < 5; i++) {
138  // check whether the switch control is closed for some port
139  if (_switch_control[i] != -1) {
140  // prevent routing to a non-existing router
141  #ifdef ROUTER_PORT_CONNECTED_CHECKING
142  if (_ob[_switch_control[i]] == nullptr) {
143  stringstream ss;
144  ss << this->GetName() << ": unable to route to unknown port"
145  << std::endl;
146  std::runtime_error(ss.str());
147  }
148 
149  if (_ib[i] == nullptr) {
150  stringstream ss;
151  ss << this->GetName() << ": unable to route from unknown port"
152  << std::endl;
153  std::runtime_error(ss.str());
154  }
155  #endif
156  // check whether the output is able to receive new flits.
157  // buffer must have some room
158  if (!_ob[_switch_control[i]]->full() && _ib[i]->size() > 0) {
159  // if -2, we send the address flit
160  if (_flits_to_send[i] == -2) {
161  // push one flit to destination port
162  _ob[_switch_control[i]]->push(_ib[i]->top());
163  _flits_to_send[i] = -1;
164  _ib[i]->pop(); // remove flit from source port
165 
166  // if -1, we set the size flit and send it
167  } else if (_flits_to_send[i] == -1) {
168  _flits_to_send[i] = _ib[i]->top();
169  // push one flit to destination port
170  _ob[_switch_control[i]]->push(_ib[i]->top());
171  _ib[i]->pop(); // remove flit from source port
172 
173  } else {
174  _flits_to_send[i] -= 1;
175  // push one flit to destination port
176  _ob[_switch_control[i]]->push(_ib[i]->top());
177  _ib[i]->pop(); // remove flit from source port
178  }
179 
180  #ifdef ROUTER_ENABLE_COUNTERS
181  _is_active = true;
182  #endif
183 
184  // free port
185  if (_flits_to_send[i] == 0)
186  _switch_control[i] = -1;
187  }
188  }
189  }
190 
191  // round robin update
192  _round_robin = (_round_robin + 1) % 5;
193 
194  #ifdef ROUTER_ENABLE_COUNTERS
195  if (is_active) {
196  _counter_active->Inc(1);
197  _is_active = false;
198  }
199  #endif
200  return 1;
201 }
void push(T)
Pushes an object to the back of the buffer.
Definition: Buffer.cpp:74
T top()
Peeks at the top of the buffer.
Definition: Buffer.cpp:100
std::string GetName()
Getter method for the <_name> field.
Definition: Model.cpp:34
uint32_t size()
Counts elements from the buffer.
Definition: Buffer.cpp:109
void pop()
Removes the object at the front of the buffer.
Definition: Buffer.cpp:56
uint32_t GetRouteXY(FlitType flit)
return this

§ SetName()

void Model::SetName ( std::string  s)
inherited

Setter method for the <_name> field.

Parameters
sValue to be set

Definition at line 38 of file Model.cpp.

38  {
39  _name = name;
40 }
std::string _name
A name for the model.
Definition: Model.hpp:47

§ SetOutputBuffer()

void HermesRouter::SetOutputBuffer ( Buffer< FlitType > *  b,
uint32_t  port 
)

Definition at line 245 of file HermesRouter.cpp.

245  {
246  _ob[port] = b;
247 }

§ ToString()

std::string HermesRouter::ToString ( )

Definition at line 249 of file HermesRouter.cpp.

249  {
250  std::stringstream ss;
251  ss << this->GetName() + ": ";
252 
253  for (int i = 0; i < 5; i++) {
254  if (_ob[i] != nullptr)
255  ss << "{" << _ob[i]->GetName() << "} ";
256  }
257 
258  return ss.str();
259 }
std::string GetName()
Getter method for the <_name> field.
Definition: Model.cpp:34

Member Data Documentation

§ _flits_to_send

int16_t orcasim::models::hermes::HermesRouter::_flits_to_send[5]
private

Definition at line 78 of file HermesRouter.hpp.

§ _ib

Buffer<FlitType>* orcasim::models::hermes::HermesRouter::_ib[5]
private

Definition at line 90 of file HermesRouter.hpp.

§ _ob

Buffer<FlitType>* orcasim::models::hermes::HermesRouter::_ob[5]
private

Definition at line 87 of file HermesRouter.hpp.

§ _round_robin

uint32_t orcasim::models::hermes::HermesRouter::_round_robin
private

Definition at line 81 of file HermesRouter.hpp.

§ _switch_control

int16_t orcasim::models::hermes::HermesRouter::_switch_control[5]
private

Definition at line 75 of file HermesRouter.hpp.

§ _x

uint32_t orcasim::models::hermes::HermesRouter::_x
private

Definition at line 84 of file HermesRouter.hpp.

§ _y

uint32_t orcasim::models::hermes::HermesRouter::_y
private

Definition at line 84 of file HermesRouter.hpp.


The documentation for this class was generated from the following files: