// Delete the Message Buffers
for (auto& it : m_toNetQueues[node]) {
- delete it.second;
+ delete it;
}
for (auto& it : m_fromNetQueues[node]) {
- delete it.second;
+ delete it;
}
}
static uint32_t m_data_msg_size;
// vector of queues from the components
- std::vector<std::map<int, MessageBuffer*> > m_toNetQueues;
- std::vector<std::map<int, MessageBuffer*> > m_fromNetQueues;
+ std::vector<std::vector<MessageBuffer*> > m_toNetQueues;
+ std::vector<std::vector<MessageBuffer*> > m_fromNetQueues;
std::vector<bool> m_in_use;
std::vector<bool> m_ordered;
string vnet_type, MessageBuffer *b)
{
checkNetworkAllocation(id, ordered, network_num, vnet_type);
+ while (m_toNetQueues[id].size() <= network_num) {
+ m_toNetQueues[id].push_back(nullptr);
+ }
m_toNetQueues[id][network_num] = b;
}
string vnet_type, MessageBuffer *b)
{
checkNetworkAllocation(id, ordered, network_num, vnet_type);
+ while (m_fromNetQueues[id].size() <= network_num) {
+ m_fromNetQueues[id].push_back(nullptr);
+ }
m_fromNetQueues[id][network_num] = b;
}
}
void
-NetworkInterface_d::addNode(map<int, MessageBuffer *>& in,
- map<int, MessageBuffer *>& out)
+NetworkInterface_d::addNode(vector<MessageBuffer *>& in,
+ vector<MessageBuffer *>& out)
{
inNode_ptr = in;
outNode_ptr = out;
for (auto& it : in) {
- // the protocol injects messages into the NI
- it.second->setConsumer(this);
- it.second->setReceiver(this);
+ if (it != nullptr) {
+ it->setConsumer(this);
+ it->setReceiver(this);
+ }
}
for (auto& it : out) {
- it.second->setSender(this);
+ if (it != nullptr) {
+ it->setSender(this);
+ }
}
}
// Checking for messages coming from the protocol
// can pick up a message/cycle for each virtual net
- for (auto it = inNode_ptr.begin(); it != inNode_ptr.end(); ++it) {
- int vnet = (*it).first;
- MessageBuffer *b = (*it).second;
+ for (int vnet = 0; vnet < inNode_ptr.size(); ++vnet) {
+ MessageBuffer *b = inNode_ptr[vnet];
+ if (b == nullptr) {
+ continue;
+ }
while (b->isReady()) { // Is there a message waiting
msg_ptr = b->peekMsgPtr();
NetworkInterface_d::checkReschedule()
{
for (const auto& it : inNode_ptr) {
- MessageBuffer *b = it.second;
+ if (it == nullptr) {
+ continue;
+ }
- while (b->isReady()) { // Is there a message waiting
+ while (it->isReady()) { // Is there a message waiting
scheduleEvent(Cycles(1));
return;
}
void addOutPort(NetworkLink_d *out_link, CreditLink_d *credit_link);
void wakeup();
- void addNode(std::map<int, MessageBuffer *> &inNode,
- std::map<int, MessageBuffer *> &outNode);
+ void addNode(std::vector<MessageBuffer *> &inNode,
+ std::vector<MessageBuffer *> &outNode);
void print(std::ostream& out) const;
int get_vnet(int vc);
std::vector<Cycles> m_ni_enqueue_time;
// The Message buffers that takes messages from the protocol
- std::map<int, MessageBuffer *> inNode_ptr;
+ std::vector<MessageBuffer *> inNode_ptr;
// The Message buffers that provides messages to the protocol
- std::map<int, MessageBuffer *> outNode_ptr;
+ std::vector<MessageBuffer *> outNode_ptr;
bool flitisizeMessage(MsgPtr msg_ptr, int vnet);
int calculateVC(int vnet);
}
void
-NetworkInterface::addNode(map<int, MessageBuffer*>& in,
- map<int, MessageBuffer*>& out)
+NetworkInterface::addNode(vector<MessageBuffer*>& in,
+ vector<MessageBuffer*>& out)
{
inNode_ptr = in;
outNode_ptr = out;
for (auto& it: in) {
- // the protocol injects messages into the NI
- it.second->setConsumer(this);
- it.second->setReceiver(this);
+ if (it != nullptr) {
+ it->setConsumer(this);
+ it->setReceiver(this);
+ }
}
for (auto& it : out) {
- it.second->setSender(this);
+ if (it != nullptr) {
+ it->setSender(this);
+ }
}
}
//Checking for messages coming from the protocol
// can pick up a message/cycle for each virtual net
- for (auto it = inNode_ptr.begin(); it != inNode_ptr.end(); ++it) {
- int vnet = (*it).first;
- MessageBuffer *b = (*it).second;
+ for (int vnet = 0; vnet < inNode_ptr.size(); ++vnet) {
+ MessageBuffer *b = inNode_ptr[vnet];
+ if (b == nullptr) {
+ continue;
+ }
while (b->isReady()) { // Is there a message waiting
msg_ptr = b->peekMsgPtr();
NetworkInterface::checkReschedule()
{
for (const auto& it : inNode_ptr) {
- MessageBuffer *b = it.second;
+ if (it == nullptr) {
+ continue;
+ }
- while (b->isReady()) { // Is there a message waiting
+ while (it->isReady()) { // Is there a message waiting
scheduleEvent(Cycles(1));
return;
}
void addInPort(NetworkLink *in_link);
void addOutPort(NetworkLink *out_link);
- void addNode(std::map<int, MessageBuffer *> &inNode,
- std::map<int, MessageBuffer *> &outNode);
+ void addNode(std::vector<MessageBuffer *> &inNode,
+ std::vector<MessageBuffer *> &outNode);
void wakeup();
void grant_vc(int out_port, int vc, Cycles grant_time);
std::vector<flitBuffer *> m_ni_buffers;
// The Message buffers that takes messages from the protocol
- std::map<int, MessageBuffer *> inNode_ptr;
+ std::vector<MessageBuffer *> inNode_ptr;
// The Message buffers that provides messages to the protocol
- std::map<int, MessageBuffer *> outNode_ptr;
+ std::vector<MessageBuffer *> outNode_ptr;
bool flitisizeMessage(MsgPtr msg_ptr, int vnet);
int calculateVC(int vnet);
}
void
-PerfectSwitch::addInPort(const map<int, MessageBuffer*>& in)
+PerfectSwitch::addInPort(const vector<MessageBuffer*>& in)
{
NodeID port = m_in.size();
m_in.push_back(in);
- for (auto& it : in) {
- it.second->setConsumer(this);
+ for (int i = 0; i < in.size(); ++i) {
+ if (in[i] != nullptr) {
+ in[i]->setConsumer(this);
- string desc = csprintf("[Queue from port %s %s %s to PerfectSwitch]",
- to_string(m_switch_id), to_string(port), to_string(it.first));
+ string desc =
+ csprintf("[Queue from port %s %s %s to PerfectSwitch]",
+ to_string(m_switch_id), to_string(port),
+ to_string(i));
- it.second->setDescription(desc);
- it.second->setIncomingLink(port);
- it.second->setVnet(it.first);
+ in[i]->setDescription(desc);
+ in[i]->setIncomingLink(port);
+ in[i]->setVnet(i);
+ }
}
}
void
-PerfectSwitch::addOutPort(const map<int, MessageBuffer*>& out,
- const NetDest& routing_table_entry)
+PerfectSwitch::addOutPort(const vector<MessageBuffer*>& out,
+ const NetDest& routing_table_entry)
{
// Setup link order
LinkOrder l;
vector<NetDest> output_link_destinations;
// Is there a message waiting?
- auto it = m_in[incoming].find(vnet);
- if (it == m_in[incoming].end())
+ if (m_in[incoming].size() <= vnet) {
continue;
- MessageBuffer *buffer = (*it).second;
+ }
+
+ MessageBuffer *buffer = m_in[incoming][vnet];
+ if (buffer == nullptr) {
+ continue;
+ }
while (buffer->isReady()) {
DPRINTF(RubyNetwork, "incoming: %d\n", incoming);
{ return csprintf("PerfectSwitch-%i", m_switch_id); }
void init(SimpleNetwork *);
- void addInPort(const std::map<int, MessageBuffer*>& in);
- void addOutPort(const std::map<int, MessageBuffer*>& out,
+ void addInPort(const std::vector<MessageBuffer*>& in);
+ void addOutPort(const std::vector<MessageBuffer*>& out,
const NetDest& routing_table_entry);
int getInLinks() const { return m_in.size(); }
SwitchID m_switch_id;
// vector of queues from the components
- std::vector<std::map<int, MessageBuffer*> > m_in;
- std::vector<std::map<int, MessageBuffer*> > m_out;
+ std::vector<std::vector<MessageBuffer*> > m_in;
+ std::vector<std::vector<MessageBuffer*> > m_out;
std::vector<NetDest> m_routing_table;
std::vector<LinkOrder> m_link_order;
const NetDest& routing_table_entry)
{
// Create a set of new MessageBuffers
- std::map<int, MessageBuffer*> queues;
+ std::vector<MessageBuffer*> queues(m_virtual_networks);
+
for (int i = 0; i < m_virtual_networks; i++) {
// allocate a buffer
MessageBuffer* buffer_ptr = new MessageBuffer;
std::string vnet_type, MessageBuffer *b)
{
checkNetworkAllocation(id, ordered, network_num);
+ while (m_toNetQueues[id].size() <= network_num) {
+ m_toNetQueues[id].push_back(nullptr);
+ }
m_toNetQueues[id][network_num] = b;
}
std::string vnet_type, MessageBuffer *b)
{
checkNetworkAllocation(id, ordered, network_num);
+ while (m_fromNetQueues[id].size() <= network_num) {
+ m_fromNetQueues[id].push_back(nullptr);
+ }
m_fromNetQueues[id][network_num] = b;
}
}
void
-Switch::addInPort(const map<int, MessageBuffer*>& in)
+Switch::addInPort(const vector<MessageBuffer*>& in)
{
m_perfect_switch->addInPort(in);
for (auto& it : in) {
- it.second->setReceiver(this);
+ if (it != nullptr) {
+ it->setReceiver(this);
+ }
}
}
void
-Switch::addOutPort(const map<int, MessageBuffer*>& out,
+Switch::addOutPort(const vector<MessageBuffer*>& out,
const NetDest& routing_table_entry,
Cycles link_latency, int bw_multiplier)
{
m_throttles.push_back(throttle_ptr);
// Create one buffer per vnet (these are intermediaryQueues)
- map<int, MessageBuffer*> intermediateBuffers;
+ vector<MessageBuffer*> intermediateBuffers;
- for (auto& it : out) {
- it.second->setSender(this);
+ for (int i = 0; i < out.size(); ++i) {
+ if (out[i] != nullptr) {
+ out[i]->setSender(this);
+ }
MessageBuffer* buffer_ptr = new MessageBuffer;
// Make these queues ordered
buffer_ptr->resize(m_network_ptr->getBufferSize());
}
- intermediateBuffers[it.first] = buffer_ptr;
+ intermediateBuffers.push_back(buffer_ptr);
m_buffers_to_free.push_back(buffer_ptr);
buffer_ptr->setSender(this);
~Switch();
void init();
- void addInPort(const std::map<int, MessageBuffer*>& in);
- void addOutPort(const std::map<int, MessageBuffer*>& out,
+ void addInPort(const std::vector<MessageBuffer*>& in);
+ void addOutPort(const std::vector<MessageBuffer*>& out,
const NetDest& routing_table_entry,
Cycles link_latency, int bw_multiplier);
int link_bandwidth_multiplier, int endpoint_bandwidth)
{
m_node = node;
+ m_vnets = 0;
+
assert(link_bandwidth_multiplier > 0);
m_link_bandwidth_multiplier = link_bandwidth_multiplier;
}
void
-Throttle::addLinks(const map<int, MessageBuffer*>& in_vec,
- const map<int, MessageBuffer*>& out_vec)
+Throttle::addLinks(const vector<MessageBuffer*>& in_vec,
+ const vector<MessageBuffer*>& out_vec)
{
assert(in_vec.size() == out_vec.size());
- for (auto& it : in_vec) {
- int vnet = it.first;
-
- auto jt = out_vec.find(vnet);
- assert(jt != out_vec.end());
+ for (int vnet = 0; vnet < in_vec.size(); ++vnet) {
+ MessageBuffer *in_ptr = in_vec[vnet];
+ MessageBuffer *out_ptr = out_vec[vnet];
- MessageBuffer *in_ptr = it.second;
- MessageBuffer *out_ptr = (*jt).second;
-
- m_in[vnet] = in_ptr;
- m_out[vnet] = out_ptr;
- m_units_remaining[vnet] = 0;
+ m_vnets++;
+ m_units_remaining.push_back(0);
+ m_in.push_back(in_ptr);
+ m_out.push_back(out_ptr);
// Set consumer and description
in_ptr->setConsumer(this);
Throttle::operateVnet(int vnet, int &bw_remaining, bool &schedule_wakeup,
MessageBuffer *in, MessageBuffer *out)
{
- assert(out != NULL);
- assert(in != NULL);
+ if (out == nullptr || in == nullptr) {
+ return;
+ }
assert(m_units_remaining[vnet] >= 0);
while (bw_remaining > 0 && (in->isReady() || m_units_remaining[vnet] > 0) &&
}
if (iteration_direction) {
- for (auto& it : m_in) {
- int vnet = it.first;
+ for (int vnet = 0; vnet < m_vnets; ++vnet) {
operateVnet(vnet, bw_remaining, schedule_wakeup,
- it.second, m_out[vnet]);
+ m_in[vnet], m_out[vnet]);
}
} else {
- for (auto it = m_in.rbegin(); it != m_in.rend(); ++it) {
- int vnet = (*it).first;
+ for (int vnet = m_vnets-1; vnet >= 0; --vnet) {
operateVnet(vnet, bw_remaining, schedule_wakeup,
- (*it).second, m_out[vnet]);
+ m_in[vnet], m_out[vnet]);
}
}
std::string name()
{ return csprintf("Throttle-%i", m_sID); }
- void addLinks(const std::map<int, MessageBuffer*>& in_vec,
- const std::map<int, MessageBuffer*>& out_vec);
+ void addLinks(const std::vector<MessageBuffer*>& in_vec,
+ const std::vector<MessageBuffer*>& out_vec);
void wakeup();
// The average utilization (a fraction) since last clearStats()
Throttle(const Throttle& obj);
Throttle& operator=(const Throttle& obj);
- std::map<int, MessageBuffer*> m_in;
- std::map<int, MessageBuffer*> m_out;
- std::map<int, int> m_units_remaining;
+ std::vector<MessageBuffer*> m_in;
+ std::vector<MessageBuffer*> m_out;
+ unsigned int m_vnets;
+ std::vector<int> m_units_remaining;
int m_sID;
NodeID m_node;