Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pulp/floonoc/floonoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def o_MAP_DIR(self, base: int, size: int, dir: FlooNocDirection, name: str,
self.__add_mapping(f"ni_{name}", base=base, size=size, x=dir, y=0, remove_offset=remove_offset)

def o_MAP(self, base: int, size: int,
x: int, y: int,
x: int, y: int, name: str | None=None,
rm_base: bool=False, remove_offset:int =0):
"""Binds the output of a node to a target, associated to a memory-mapped region.

Expand All @@ -173,7 +173,7 @@ def o_MAP(self, base: int, size: int,
"""
if rm_base and remove_offset == 0:
remove_offset =base
self.__add_mapping(f"ni_{x}_{y}", base=base, size=size, x=x, y=y, remove_offset=remove_offset)
self.__add_mapping(f"ni_{x}_{y}" if name is None else name, base=base, size=size, x=x, y=y, remove_offset=remove_offset)

def o_WIDE_MAP(self, itf: gvsoc.systree.SlaveItf | None, base: int, size: int,
x: int | FlooNocDirection, y: int | FlooNocDirection, name: str | None=None,
Expand Down
26 changes: 13 additions & 13 deletions pulp/floonoc/floonoc_network_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,16 @@ void NetworkQueue::handle_req(vp::IoReq *req)
this->trace.msg(vp::Trace::LEVEL_DEBUG, "Received %s burst from initiator (burst: %p, offset: 0x%x, size: 0x%x, is_write: %d, op: %d)\n",
req->get_int(FlooNoc::REQ_WIDE) ? "wide" : "narrow", req, req->get_addr(), req->get_size(), req->get_is_write(), req->get_opcode());

this->enqueue_router_req(req, true);
this->enqueue_router_req(req, true, true);
if (req->get_is_write())
{
this->enqueue_router_req(req, false);
this->enqueue_router_req(req, false, true);
}
}

void NetworkQueue::handle_rsp(vp::IoReq *req, bool is_address)
{
this->enqueue_router_req(req, is_address);
this->enqueue_router_req(req, is_address, false);
}

bool NetworkQueue::handle_request(FloonocNode *node, vp::IoReq *req, int from_x, int from_y)
Expand All @@ -89,12 +89,11 @@ bool NetworkQueue::handle_request(FloonocNode *node, vp::IoReq *req, int from_x,
}


void NetworkQueue::enqueue_router_req(vp::IoReq *req, bool is_address)
void NetworkQueue::enqueue_router_req(vp::IoReq *req, bool is_address, bool is_req)
{
uint64_t burst_base = req->get_addr();
uint64_t burst_size = req->get_size();
uint8_t *burst_data = req->get_data();
bool wide = *(bool *)req->arg_get(FlooNoc::REQ_WIDE);

while(burst_size > 0)
{
Expand All @@ -107,16 +106,17 @@ void NetworkQueue::enqueue_router_req(vp::IoReq *req, bool is_address)
*router_req->arg_get(FlooNoc::REQ_SRC_NI) = (void *)&this->ni;
*router_req->arg_get(FlooNoc::REQ_BURST) = (void *)req;
*router_req->arg_get(FlooNoc::REQ_IS_ADDRESS) = (void *)is_address;
*router_req->arg_get(FlooNoc::REQ_WIDE) = (void *)wide;
router_req->set_size(size);
router_req->set_data(burst_data);
router_req->set_addr(burst_base);
router_req->set_is_write(req->get_is_write());
router_req->set_opcode(req->get_opcode());
router_req->set_second_data(req->get_second_data());

if (*(NetworkInterface **)req->arg_get(FlooNoc::REQ_SRC_NI))
if (is_req)
{
bool wide = *(bool *)req->arg_get(IO_REQ_NB_ARGS-1);
Copy link

Copilot AI Nov 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The magic number IO_REQ_NB_ARGS-1 is used multiple times throughout the file for accessing the wide flag. Consider defining a named constant like FlooNoc::REQ_WIDE_FLAG to improve code clarity and maintainability.

Copilot uses AI. Check for mistakes.
*router_req->arg_get(FlooNoc::REQ_WIDE) = (void *)wide;
if (wide)
{
req->get_is_write() ? this->ni.wide_write_pending_burst_nb_req++ :
Expand Down Expand Up @@ -164,6 +164,7 @@ void NetworkQueue::enqueue_router_req(vp::IoReq *req, bool is_address)
else
{
*router_req->arg_get(FlooNoc::REQ_SRC_NI) = NULL;
*router_req->arg_get(FlooNoc::REQ_WIDE) = *req->arg_get(FlooNoc::REQ_WIDE);
*router_req->arg_get(FlooNoc::REQ_DEST_X) = *req->arg_get(FlooNoc::REQ_DEST_X);
*router_req->arg_get(FlooNoc::REQ_DEST_Y) = *req->arg_get(FlooNoc::REQ_DEST_Y);
*router_req->arg_get(FlooNoc::REQ_BURST) = *req->arg_get(FlooNoc::REQ_BURST);
Expand Down Expand Up @@ -360,15 +361,15 @@ vp::IoReqStatus NetworkInterface::narrow_req(vp::Block *__this, vp::IoReq *req)
{
NetworkInterface *_this = (NetworkInterface *)__this;
_this->signal_narrow_req = req->get_addr();
*req->arg_get(FlooNoc::REQ_WIDE) = (void *)0;
*(bool *)req->arg_get(IO_REQ_NB_ARGS-1) = false;
return _this->handle_req(req);
}

vp::IoReqStatus NetworkInterface::wide_req(vp::Block *__this, vp::IoReq *req)
{
NetworkInterface *_this = (NetworkInterface *)__this;
_this->signal_wide_req = req->get_addr();
*req->arg_get(FlooNoc::REQ_WIDE) = (void *)1;
*(bool *)req->arg_get(IO_REQ_NB_ARGS-1) = true;
return _this->handle_req(req);
}

Expand All @@ -383,7 +384,7 @@ vp::IoReqStatus NetworkInterface::handle_req(vp::IoReq *req)

vp::IoReq **queue;
std::queue<vp::IoReq *> *denied_queue;
bool is_wide = *(bool *)req->arg_get(FlooNoc::REQ_WIDE);
bool is_wide = *(bool *)req->arg_get(IO_REQ_NB_ARGS-1);
if (is_wide)
{
queue = req->get_is_write() ? &this->wide_write_pending_burst :
Expand All @@ -408,7 +409,7 @@ vp::IoReqStatus NetworkInterface::handle_req(vp::IoReq *req)
{
this->nb_pending_bursts[is_wide]++;
*queue = req;
if (!req->get_is_write() || !*(vp::IoReq **)req->arg_get(FlooNoc::REQ_WIDE))
if (!req->get_is_write() || !is_wide)
{
this->req_queue.handle_req(req);
}
Expand Down Expand Up @@ -488,14 +489,13 @@ bool NetworkInterface::handle_request(FloonocNode *node, vp::IoReq *req, int fro

if (result == vp::IO_REQ_OK)
{
NetworkInterface *ni = *(NetworkInterface **)req->arg_get(FlooNoc::REQ_SRC_NI);
if (req->get_latency() > 0)
{
this->response_queue.push_delayed(req, req->get_latency());
}
else
{
ni->handle_response(req);
this->handle_response(req);
Copy link

Copilot AI Nov 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The response is now being sent to this->handle_response(req) instead of the source NI. This appears correct given the removed line that retrieved the source NI, but verify that responses should be handled by the destination NI rather than being routed back to the source NI that initiated the request.

Suggested change
this->handle_response(req);
// Retrieve the source NI from the request and send the response back to it
NetworkInterface *source_ni = (NetworkInterface *)req->arg_get(FlooNoc::REQ_SOURCE_NI);
if (source_ni != nullptr)
{
source_ni->handle_response(req);
}
else
{
// Fallback: handle locally if source NI is not set
this->handle_response(req);
}

Copilot uses AI. Check for mistakes.
}
}
else if (result == vp::IO_REQ_DENIED)
Expand Down
2 changes: 1 addition & 1 deletion pulp/floonoc/floonoc_network_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class NetworkQueue : public FloonocNode
void handle_rsp(vp::IoReq *req, bool is_address);

private:
void enqueue_router_req(vp::IoReq *req, bool is_address);
void enqueue_router_req(vp::IoReq *req, bool is_address, bool is_req);
void send_router_req();
void unstall_queue(int from_x, int from_y) override;
bool handle_request(FloonocNode *node, vp::IoReq *req, int from_x, int from_y) override;
Expand Down