fix: fixing errors

This commit is contained in:
juanmanuel 2024-10-07 10:53:56 -05:00
parent 604ee46418
commit 3c6519fbe5
11 changed files with 108 additions and 260 deletions

View file

@ -23,6 +23,7 @@ ADD_EXECUTABLE(${PROJECT_NAME}
src/networkManager/NetworkManager.cpp
src/noc/noc.cpp
src/router/router.cpp
src/router/router_cs.cpp
src/utils/memory_manager.cpp
src/utils/utils.cpp
src/utils/noc_logger.cpp

View file

@ -26,8 +26,6 @@
#include "utils/configuration.h"
#include "utils/utils.h"
DECLARE_EXTENDED_PHASE(INTERNAL_PROC_PHASE);
using namespace std;
NetworkInterfaceTlm::NetworkInterfaceTlm(sc_module_name nm, Node& node,
@ -172,6 +170,13 @@ void NetworkInterfaceTlm::send_flit(Packet* p, Flit* f){
}
int NetworkInterfaceTlm::get_type_from_extension(tlm_gp& trans){
link_extension* extension;
trans.get_extension<link_extension>(extension);
return extension->data_type;
}
bool NetworkInterfaceTlm::check_cs_needed(tlm_gp& trans){
int type = get_type_from_extension(trans);
return type == TYPE_INIT_STREAM || type == TYPE_END_STREAM;
@ -191,7 +196,7 @@ void NetworkInterfaceTlm::send_cs_rout_conf_msg(tlm_gp& trans){
// add id to new_transaction
link_extension* ext = new link_extension();
ext->link = dest_link; // set direction of connected router
ext->link = Dir::local; // set direction of connected router
ext->data_type = get_type_from_extension(trans);
new_trans->set_extension(ext);
@ -360,7 +365,7 @@ void NetworkInterfaceTlm::receive_and_process_flit(tlm_gp& trans){
credit_counter++;
// send configuration message to cs_router
if(check_cs_needed(link, trans)){
if(check_cs_needed(trans)){
send_cs_rout_conf_msg(trans);
}
@ -425,7 +430,8 @@ tlm::tlm_sync_enum NetworkInterfaceTlm::send_end_req(tlm_gp& trans){
}
// Queue internal event to mark beginning of response
delay = p->dataType != TYPE_STREAM ?
int type = get_type_from_extension(trans);
delay = type != TYPE_STREAM ?
delay + sc_time(INTERN_PROC_DELAY, UNITS_DELAY) :
SC_ZERO_TIME; // no processing on stream
target_peq.notify(trans, INTERNAL_PROC_PHASE, delay);

View file

@ -125,6 +125,13 @@ public:
*/
tlm_gp* build_transaction(Packet* p, Flit* f);
/**
* Get type from extension
*
* @param trans TLM generic payload object
*/
int get_type_from_extension(tlm_gp& trans);
/**
* If message is init streaming, a router_cs needs to be
* configured
@ -138,7 +145,7 @@ public:
*
* @param trans TLM generic payload object
*/
bool send_cs_rout_conf_msg(tlm_gp& trans);
void send_cs_rout_conf_msg(tlm_gp& trans);
/**

View file

@ -1,151 +0,0 @@
/*******************************************************************************
* Copyright (C) 2024 Juan Neyra
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
******************************************************************************/
#include "NetworkInterfaceTlmCS.h"
DECLARE_EXTENDED_PHASE(INTERNAL_PROC_PHASE);
NetworkInterfaceTlmCS::NetworkInterfaceTlmCS(sc_module_name nm,
Node& node, uint8_t max_pos[3]) :
NetworkInterfaceTlm(nm, node, max_pos) {
initiator_cs.register_nb_transport_bw(this,
&NetworkInterfaceTlmCS::nb_transport_bw_cb, 0);
target_cs.register_nb_transport_fw(this,
&NetworkInterfaceTlmCS::nb_transport_fw_cb, 0);
}
NetworkInterfaceTlmCS::~NetworkInterfaceTlmCS() {
}
// Flits are now chunks of data, but in programming,
// they can still be treated the same way
void NetworkInterfaceTlmCS::send_flit(Packet* p, Flit* f){
tlm_gp* trans = build_transaction(p, f);
credit_counter--;
sc_time delay = sc_time(REQ_INIT_DELAY, UNITS_DELAY);
tlm::tlm_phase send_phase = tlm::BEGIN_REQ;
if(p->dataType == TYPE_STREAM){
initiator_cs->nb_transport_fw(*trans, send_phase, delay);
}
else{
initiator->nb_transport_fw(*trans, send_phase, delay);
}
}
bool NetworkInterfaceTlmCS::check_cs_needed(tlm_gp& trans){
int type = get_type_from_extension(trans);
return type == TYPE_INIT_STREAM || type == TYPE_END_STREAM;
};
void NetworkInterfaceTlmCS::send_cs_rout_conf_msg(tlm_gp& trans){
tlm::tlm_generic_payload* new_trans = m_mm.allocate();
new_trans->acquire();
new_trans->set_command(tlm::TLM_WRITE_COMMAND);
new_trans->set_address(trans.get_address());
new_trans->set_data_ptr(trans.get_data_ptr());
new_trans->set_data_length(trans.get_data_length());
new_trans->set_streaming_width(trans.get_streaming_width());
new_trans->set_byte_enable_ptr(trans.get_byte_enable_ptr());
new_trans->set_dmi_allowed(false);
new_trans->set_response_status(tlm::TLM_INCOMPLETE_RESPONSE);
// add id to new_transaction
link_extension* ext = new link_extension();
ext->link = dest_link; // set direction of connected router
ext->data_type = get_type_from_extension(trans);
new_trans->set_extension(ext);
// send transaction in socket
tlm_phase phase = BEGIN_REQ;
sc_time delay = sc_time(REQ_INIT_DELAY, UNITS_DELAY);
initiator_cs->nb_transport_fw(*new_trans, phase, delay);
}
void NetworkInterfaceTlmCS::receive_and_process_flit(tlm_gp& trans){
trans.set_response_status(tlm::TLM_OK_RESPONSE);
unsigned char* data_ptr = trans.get_data_ptr();
Flit* received_flit = reinterpret_cast<Flit*>(data_ptr);
Packet* p = received_flit->packet;
double time = sc_time_stamp().to_double();
auto position = find(p->inTransmit.begin(), p->inTransmit.end(), received_flit->id);
if (position!=p->inTransmit.end())
p->inTransmit.erase(position);
p->transmitted.push_back(received_flit->id);
// log arrived flit
if (received_flit->type==TAIL || received_flit->type==SINGLE){
stringstream ss;
string flit_type = received_flit->type==SINGLE ? "Single":"Tail";
ss << "Receive Flit " << flit_type << *received_flit;
log_info(ss.str());
}
if (!p->toTransmit.empty() || !p->inTransmit.empty()) {
stringstream ss;
ss << "Received Tail Flit, but still missing flits! "
<< *received_flit;
log_info(ss.str());
}
//globalReport.issueNoCOutputDataAmount(sc_time_stamp(),globalResources.bitWidth);
if (p->toTransmit.empty() && p->inTransmit.empty())
packet_recv_queue.push(p);
credit_counter++;
// send configuration message to cs_router
if(check_cs_needed(link, trans)){
send_cs_rout_conf_msg(trans);
}
// send response if not type stream
if(p->dataType != TYPE_STREAM){
if(resp_in_progress) {
if(nxt_resp_pend){
log_fatal("Attempt to have two pending responses in target");
nxt_resp_pend = &trans;
}
}
else{ send_response(trans); }
}
}
tlm::tlm_sync_enum NetworkInterfaceTlmCS::send_end_req(tlm_gp& trans){
// Queue the acceptance and the response with the appropriate latency
tlm::tlm_phase bw_phase = tlm::END_REQ;
sc_time delay = sc_time(REQ_END_DELAY, UNITS_DELAY); // Accept delay
tlm::tlm_sync_enum status = target->nb_transport_bw(trans,
bw_phase, delay);
if (status == tlm::TLM_COMPLETED) {
trans.release();
return status;
}
// Queue internal event to mark beginning of response
delay = p->dataType != TYPE_STREAM ?
delay + sc_time(INTERN_PROC_DELAY, UNITS_DELAY) :
SC_ZERO_TIME; // no processing on stream
target_peq.notify(trans, INTERNAL_PROC_PHASE, delay);
return status;
}

View file

@ -1,66 +0,0 @@
/*******************************************************************************
* Copyright (C) 2024 Juan Neyra
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
******************************************************************************/
#pragma once
#ifndef SC_INCLUDE_DYNAMIC_PROCESSES
#define SC_INCLUDE_DYNAMIC_PROCESSES
#endif
#include "NetworkInterfaceTlm.h"
#include "utils/memory_manager.h"
class NetworkInterfaceTlmCS : public NetworkInterfaceTlm {
public:
SC_HAS_PROCESS(NetworkInterfaceTlmCS);
NetworkInterfaceTlmCS(sc_module_name nm, Node& node, uint8_t max_pos[3]);
~NetworkInterfaceTlmCS() override;
// To Circuit Switching NoC
ni_init_socket initiator_cs;
ni_targ_socket target_cs;
private:
/**
* Sends flit to packet switching noc or circuit switching noc
*
* @param p parent packet of the flit to send
* @param f flit to send
*/
void send_flit(Packet* p, Flit* f) override;
/**
* Logs the arrival of a flit. After processing, sends a
* response if needed
*
* @param trans TLM transaction object
*/
void receive_and_process_flit(tlm_gp& trans) override;
/**
* Send end request
*
* @param trans TLM generic payload object
*/
tlm::tlm_sync_enum send_end_req(tlm_gp& trans) override;
};

View file

@ -67,19 +67,20 @@ void TlmNoc::initNoc() {
uint8_t rout_pos[3];
convert_pos_to_int(float_rout_pos, rout_pos);
string msg = name + " initialized in position " +
to_string(rout_pos[0]) + "," + to_string(rout_pos[1]) +
string msg = " initialized in position " +
to_string(rout_pos[0]) + "," + to_string(rout_pos[1])+
"," + to_string(rout_pos[2]);
log_info(msg);
TlmRouter *r;
string rout_name;
if (n.type->model == "Router") {
string name = "router_" + to_string(n.id);
r = new TlmRouter(name.c_str(), rout_pos, max_pos);
rout_name = "router_" + to_string(n.id);
r = new TlmRouter(rout_name.c_str(), rout_pos, max_pos);
}
else {
string name = "routercs_" + to_string(n.id);
r = new TlmRouterCS(name.c_str(), rout_pos, max_pos);
rout_name = "router_cs_" + to_string(n.id);
r = new TlmRouterCS(rout_name.c_str(), rout_pos, max_pos);
}
log_info(rout_name + msg);
routers.push_back(r);
int id = routers.size()-1;
mapNodeRouter.insert(

View file

@ -35,8 +35,10 @@
#include "ratatoskrUtils/utils/Structures.h"
#include "ratatoskrUtils/utils/GlobalResources.h"
#include "ratatoskrUtils/utils/GlobalReport.h"
#include "router/router.h"
#include "router/router_cs.h"
using namespace tlm;

View file

@ -115,7 +115,7 @@ bool TlmRouter::send_data(int link, int dest_link, tlm_gp& trans){
// check credits or that previous message is complete
if (credit_counter[dest_link] > 0 && !curr_req[dest_link]){
send_begin_req(link, trans, dest_link);
if(check_cs_needed(link, trans)){
if(check_cs_needed(link, dest_link, trans)){
send_cs_rout_conf_msg(link, dest_link, trans);
}
return true;
@ -169,8 +169,8 @@ bool TlmRouter::check_cs_needed(int link, int destination, tlm_gp& trans){
};
void TlmRouter::send_cs_rout_conf_msg(int link, int destination, tlm_gp& trans){
int dest_link = dir::local;
int* data = new int(link | destination<<2);
int dest_link = Dir::local;
unsigned char* data = new unsigned char(link | destination<<2);
tlm::tlm_generic_payload* conf_trans = m_mm.allocate();
conf_trans->acquire();
@ -178,7 +178,7 @@ void TlmRouter::send_cs_rout_conf_msg(int link, int destination, tlm_gp& trans){
conf_trans->set_address(rout_pos[0] + rout_pos[1]*max_pos[0] +
rout_pos[2]*max_pos[0]*max_pos[1]);
conf_trans->set_data_ptr(data);
conf_trans->set_data_length(sizeof(int));
conf_trans->set_data_length(1);
conf_trans->set_streaming_width(4);
conf_trans->set_byte_enable_ptr(0);
conf_trans->set_dmi_allowed(false);

View file

@ -44,7 +44,6 @@ using namespace tlm;
using namespace tlm_utils;
#define NUM_LINKS Direction::num_dirs
#define MAX_PRIORITY NUM_LINKS - 1
DECLARE_EXTENDED_PHASE(INTERNAL_PROC_PHASE);
@ -91,7 +90,7 @@ class TlmRouter : public sc_module{
uint8_t max_pos[3]);
~TlmRouter();
private:
protected:
/**
* Configure sockets and set initial values of variables
*/
@ -143,7 +142,7 @@ class TlmRouter : public sc_module{
* @param destination destination link to transmit transaction
* @param trans TLM generic payload object
*/
bool send_cs_rout_conf_msg(int link, int destination, tlm_gp& trans);
void send_cs_rout_conf_msg(int link, int destination, tlm_gp& trans);
/**
* Callback function for non blocking transport backward
@ -258,6 +257,13 @@ class TlmRouter : public sc_module{
*/
int get_link_from_extension(tlm_gp& trans);
/**
* Get type from extension
*
* @param trans TLM generic payload object
*/
int get_type_from_extension(tlm_gp& trans);
/** Log info
* @param link active link

View file

@ -20,6 +20,7 @@
* SOFTWARE.
******************************************************************************/
#include "router_cs.h"
#include "ratatoskrUtils/utils/Structures.h"
TlmRouterCS::TlmRouterCS(sc_module_name name, uint8_t rout_pos[3],
uint8_t max_pos[3]):
@ -44,7 +45,6 @@ void TlmRouterCS::initialize(){
valid_links[link] = false;
//resp_in_progress[link] = false;
//nxt_resp_pend[link] = 0;
end_req_pend[link] = 0;
nxt_send_data_pend[link] = 0;
curr_req[link] = 0;
//send_data_in_prog_dest[link] = Direction::invalid;
@ -66,7 +66,7 @@ Dir TlmRouterCS::get_auto_router_map(int link){
}
void TlmRouter::send_begin_req(int link, tlm_gp& trans, int dest_link){
void TlmRouterCS::send_begin_req(int link, tlm_gp& trans, int dest_link){
tlm_gp* new_trans = build_transaction(trans, dest_link);
// send transaction in socket
@ -89,17 +89,17 @@ void TlmRouter::send_begin_req(int link, tlm_gp& trans, int dest_link){
}
void configure_router(tlm_gp& trans){
void TlmRouterCS::configure_router(tlm_gp& trans){
// get link and destination
int* data = trans.get_data_ptr();
int link = data && 3;
int destination = data >> 2;
unsigned char* data = trans.get_data_ptr();
int link = *data && 3;
int destination = *data >> 2;
// set auto router map
set_auto_router_map(link, destination);
set_auto_router_map(link, Dir(destination));
}
/******************* INIT SOCKET FUNCTIONS ********************/
tlm_sync_enum TlmRouter::nb_transport_bw_cb(int id, tlm_gp& trans,
tlm_sync_enum TlmRouterCS::nb_transport_bw_cb(int id, tlm_gp& trans,
tlm_phase& phase, sc_time& delay) {
log_info(id, "Backward transport callback start");
return TLM_ACCEPTED;
@ -145,7 +145,7 @@ tlm_sync_enum TlmRouterCS::send_end_req(int link, tlm_gp& trans){
delay = SC_ZERO_TIME; // no processing in circuit switching routers
// Queue internal event to mark beginning of response
int type = get_type_from_extension(trans);
sc_phase phase = (type == TYPE_STREAM) ? INTERNAL_PROC_PHASE :
phase = (type == TYPE_STREAM) ? INTERNAL_PROC_PHASE :
CONF_ROUT_PHASE;
target_peq.notify(trans, phase, delay);

View file

@ -29,31 +29,53 @@
#include <string>
#include "tlm.h"
#include "router/router.h"
#include "utils/configuration.h"
#include "utils/utils.h"
using namespace sc_core;
using namespace sc_dt;
using namespace std;
using namespace tlm;
using namespace tlm_utils;
DECLARE_EXTENDED_PHASE(CONF_ROUT_PHASE);
class TlmRouterCS : public sc_module, TlmRouter{
class TlmRouterCS : public TlmRouter{
public:
SC_HAS_PROCESS(TlmRouterCS);
TlmRouterCS(sc_module_name name, uint8_t rout_pos[3],
uint8_t max_pos[3]);
~TlmRouterCS();
/** Setter for auto_rout_map variable
* @param link auto_router_map index
* @param dir direction to route to
*/
void set_auto_router_map(int link, Dir dir);
/** Getter for auto_rout_map variable
* @param link auto_router_map index
* @return direction to route to
*/
Dir get_auto_router_map(int link);
private:
Dir auto_rout_map[NUM_LINKS] = {0};
Dir auto_rout_map[NUM_LINKS];
/**
* Configure sockets and set initial values of variables
*/
void initialize() override;
void initialize();
/**
* Called during configure phase. Sets a new direction
* of routing for a given link
*
* @param trans TLM generic payload object
*/
void configure_router(tlm_gp& trans);
/**
* Routing
@ -61,7 +83,7 @@ class TlmRouterCS : public sc_module, TlmRouter{
* @param link active link
* @param trans TLM generic payload object
*/
Dir TlmRouterCS::routing(int link, tlm_gp& trans) override;
Dir routing(int link, tlm_gp& trans);
/**
@ -73,12 +95,24 @@ class TlmRouterCS : public sc_module, TlmRouter{
void switching(int link, tlm_gp& trans);
/**
* Send end request
* Begin request
*
* @param link active link
* @param trans TLM generic payload object
* @param dest_link destination link to transmit transaction
*/
tlm::tlm_sync_enum send_end_req(int link, tlm_gp& trans) override;
void send_begin_req(int link, tlm_gp& trans, int dest_link);
/**
* Callback function for non blocking transport backward
*
* @param id active link
* @param trans TLM generic payload object
* @param phase TLM current phase
* @param delay TLM expected delay
*/
tlm_sync_enum nb_transport_bw_cb(int id, tlm_gp& trans,
tlm_phase& phase, sc_time& delay);
/**
* Callback target Payload Event Queue (PEQ)
@ -86,6 +120,14 @@ class TlmRouterCS : public sc_module, TlmRouter{
* @param trans TLM generic payload object
* @param phase TLM current phase
*/
void target_peq_cb(tlm_gp& trans, const tlm_phase& phase) override;
void target_peq_cb(tlm_gp& trans, const tlm_phase& phase);
/**
* Send end request
*
* @param link active link
* @param trans TLM generic payload object
*/
tlm::tlm_sync_enum send_end_req(int link, tlm_gp& trans);
};