Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

floogen: Fix endpoint enum ordering and names #90

Merged
merged 5 commits into from
Dec 20, 2024
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- A FlooGen configuration file now requires a `network_type` field, to determine the type of network to generate. The options are `axi` for single-AXI networks and `narrow-wide` for the narrow-wide AXI configurations.
- The system address map `Sam` is now sorted correctly and can be indexed with `ep_id_e` values.
- `id_offset` was renamed to `xy_id_offset`, since this is now only applicable in `XYRouting` networks. An ID offset does not make sense for other types of routing algorithms. The use of `id_offset` is anyway not recommended anymore, since the direction of the connections can be specified in the `connections` schema.
- Endpoint names in the `ep_id_e` enum, which are created as 2D arrays now have clearer naming scheme by prefixing them with `X` and `Y`.

### Fixed

Expand Down
11 changes: 1 addition & 10 deletions floogen/model/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#
# Author: Tim Fischer <[email protected]>

import re
from typing import List, Tuple

import networkx as nx
Expand Down Expand Up @@ -287,15 +286,7 @@ def add_nodes_as_array(
def create_unique_ep_id(self, node) -> int:
"""Return the endpoint id."""
ep_nodes = [name for name, _ in self.get_ep_nodes(with_name=True)]

# Custom sorting function: extract numeric part after letters
def extract_number(name):
match = re.search(r"(\d+)$", name)
return int(match.group(1)) if match else -1

return sorted(
ep_nodes, key=lambda name: (re.sub(r"\d+$", "", name), extract_number(name))
).index(node)
return ep_nodes.index(node)

def get_node_id(self, node_name=None, node_obj=None):
"""Return the node id."""
Expand Down
8 changes: 5 additions & 3 deletions floogen/model/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ def compile_nis(self):
# 1D array case
case (_,):
node_idx = self.graph.get_node_arr_idx(ni_name)[0]
ni_dict["arr_idx"] = SimpleId(id=node_idx)
if ep_desc.is_sbr():
ni_dict["addr_range"] = [
rng.model_copy().set_idx(node_idx) for rng in ep_desc.addr_range
Expand Down Expand Up @@ -749,9 +750,10 @@ def render_nis(self):

def render_ep_enum(self):
"""Render the endpoint enum in the generated code."""
fields_dict = {
ep.name: self.graph.get_node_uid(node_obj=ep).id for ep in self.graph.get_ni_nodes()
}
fields_dict = {}
for ni in self.graph.get_ni_nodes():
name = ni.render_enum_name()
fields_dict[name] = self.graph.get_node_uid(node_obj=ni).id
fields_dict = dict(sorted(fields_dict.items(), key=lambda item: item[1]))
fields_dict["num_endpoints"] = len(fields_dict)
return sv_enum_typedef(name="ep_id_e", fields_dict=fields_dict)
Expand Down
11 changes: 10 additions & 1 deletion floogen/model/network_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from pydantic import BaseModel
from mako.lookup import Template

from floogen.model.routing import Id, SimpleId, AddrRange, Routing, RouteMap
from floogen.model.routing import Id, SimpleId, Coord, AddrRange, Routing, RouteMap
from floogen.model.protocol import AXI4
from floogen.model.link import NarrowWideLink, AxiLink
from floogen.model.endpoint import EndpointDesc
Expand Down Expand Up @@ -47,6 +47,15 @@ def is_only_mgr(self) -> bool:
"""Return true if the network interface is only a manager."""
return self.endpoint.is_mgr() and not self.endpoint.is_sbr()

def render_enum_name(self) -> str:
"""Render the enum name."""
name = f"{self.endpoint.name}"
if isinstance(self.arr_idx, Coord):
name += f"_x{self.arr_idx.x}_y{self.arr_idx.y}"
elif isinstance(self.arr_idx, SimpleId):
name += f"_{self.arr_idx.id}"
return name


class AxiNI(NetworkInterface):
""" Axi Network Interface class."""
Expand Down
2 changes: 1 addition & 1 deletion floogen/templates/floo_axi_chimney.sv.mako
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ floo_axi_chimney #(
.id_i ( id_t'(${ni.id.render()}) ),
% endif
% if ni.routing.route_algo.value == 'SourceRouting':
.route_table_i ( RoutingTables[${snake_to_camel(ni.name)}] ),
.route_table_i ( RoutingTables[${snake_to_camel(ni.render_enum_name())}] ),
% else:
.route_table_i ( '0 ),
% endif
Expand Down
2 changes: 1 addition & 1 deletion floogen/templates/floo_nw_chimney.sv.mako
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ floo_nw_chimney #(
.id_i ( id_t'(${ni.id.render()}) ),
% endif
% if ni.routing.route_algo.value == 'SourceRouting':
.route_table_i ( RoutingTables[${snake_to_camel(ni.name)}] ),
.route_table_i ( RoutingTables[${snake_to_camel(ni.render_enum_name())}] ),
% else:
.route_table_i ( '0 ),
% endif
Expand Down
2 changes: 1 addition & 1 deletion hw/tb/tb_floo_axi_mesh.sv
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ module tb_floo_axi_mesh;
localparam string DmaName = $sformatf("dma_%0d_%0d", x, y);

localparam int unsigned Index = x * NumY + y;
localparam addr_t MemBaseAddr = Sam[ClusterNi00+Index].start_addr;
localparam addr_t MemBaseAddr = Sam[ClusterX0Y0+Index].start_addr;

floo_dma_test_node #(
.TA ( ApplTime ),
Expand Down
2 changes: 1 addition & 1 deletion hw/tb/tb_floo_nw_mesh.sv
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ module tb_floo_nw_mesh;
localparam string WideDmaName = $sformatf("wide_dma_%0d_%0d", x, y);

localparam int unsigned Index = x * NumY + y;
localparam addr_t MemBaseAddr = Sam[ClusterNi00+Index].start_addr;
localparam addr_t MemBaseAddr = Sam[ClusterX0Y0+Index].start_addr;

floo_dma_test_node #(
.TA ( ApplTime ),
Expand Down
Loading