Tiago Mück has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/43123 )

Change subject: configs: changed CHI --noc-config format
......................................................................

configs: changed CHI --noc-config format

Changed format from yaml to plain python. The new py configuration
file must define a function to set the CustomMesh configuration
parameters for each of the CHI node types.

See configs/example/noc_config/2x4.py (replaces
configs/example/noc_config/2x4.yaml) for an example.

Change-Id: Ic0c5407dba3d2483d5c30634c115b5410a5228fd
Signed-off-by: Tiago Mück <tiago.m...@arm.com>
---
R configs/example/noc_config/2x4.py
M configs/ruby/CHI.py
M configs/topologies/CustomMesh.py
3 files changed, 121 insertions(+), 98 deletions(-)



diff --git a/configs/example/noc_config/2x4.yaml b/configs/example/noc_config/2x4.py
similarity index 72%
rename from configs/example/noc_config/2x4.yaml
rename to configs/example/noc_config/2x4.py
index 84ec476..b8e3700 100644
--- a/configs/example/noc_config/2x4.yaml
+++ b/configs/example/noc_config/2x4.py
@@ -33,38 +33,38 @@
 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

-# 2x4 mesh definition
+
+# CustomMesh parameters for a 2x4 mesh. Routers will have the following layout:
 #
 # 0 --- 1 --- 2 --- 3
 # |     |     |     |
 # 4 --- 5 --- 6 --- 7
 #
-mesh:
-    num_rows : 2
-    num_cols : 4
-    router_latency : 1
-    link_latency : 1
+# Default parameter are defined in create_system in configs/ruby/CHI.py
+#
+def setup_NoC_Params(params):
+    params.num_rows = 2
+    params.num_cols = 4
+    params.router_latency = 1
+    params.link_latency = 1

-# Bindings for each CHI node type.
+# Bindings for each CHI node type for CustomMesh
+# The default types are defined in CHI_Node in configs/ruby/CHI.py

-CHI_RNF:
-    # Uncomment to map num_nodes_per_router RNFs in each provided router,
- # assuming num. created CHI_RNFs == len(router_list)*num_nodes_per_router
-    # num_nodes_per_router: 1
-    router_list: [1, 2, 5, 6]
+def setup_CHI_RNF(params):
+    params.router_list = [1, 2, 5, 6]

-CHI_HNF:
-    # num_nodes_per_router: 1
-    router_list: [1, 2, 5, 6]
+def setup_CHI_HNF(params):
+    params.router_list = [1, 2, 5, 6]

-CHI_SNF_MainMem:
-    # num_nodes_per_router: 1
-    router_list: [0, 4]
+def setup_CHI_SNF_MainMem(params):
+    params.router_list = [0, 4]

-# Applies to CHI_SNF_BootMem and possibly other non-main memories
-CHI_SNF_IO:
-    router_list: [3]
+def setup_CHI_SNF_BootMem(params):
+    params.router_list = [3]

-# Applies to CHI_RNI_DMA and CHI_RNI_IO
-CHI_RNI_IO:
-    router_list: [7]
+def setup_CHI_RNI_DMA(params):
+    params.router_list = [7]
+
+def setup_CHI_RNI_IO(params):
+    params.router_list = [7]
diff --git a/configs/ruby/CHI.py b/configs/ruby/CHI.py
index 0a49371..44f9a7e 100644
--- a/configs/ruby/CHI.py
+++ b/configs/ruby/CHI.py
@@ -34,7 +34,6 @@
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

 import math
-import yaml
 import m5
 from m5.objects import *
 from m5.defines import buildEnv
@@ -43,8 +42,8 @@
 def define_options(parser):
     parser.add_option("--noc-config", action="store", type="string",
                       default=None,
-                      help="YAML NoC config. parameters and bindings. "
-                           "required for CustomMesh topology")
+                      help="NoC config. parameters and bindings. "
+                           "Required for CustomMesh topology")

 class Versions:
     '''
@@ -76,6 +75,25 @@
     in the derived classes.
     '''

+    class NoC_Params:
+        '''
+ NoC config. parameters and bindings required for CustomMesh topology
+        '''
+        def __init__(self):
+ # Maps 'num_nodes_per_router' CHI nodes to each router provided in + # 'router_list'. This assumes len(router_list)*num_nodes_per_router
+            # equals the number of nodes
+ # If 'num_nodes_per_router' is left undefined, we circulate around
+            # 'router_list' until all nodes are mapped.
+            # See 'distributeNodes' in configs/topologies/CustomMesh.py
+            self.num_nodes_per_router = None
+            self.router_list = None
+
+    @classmethod
+    def noc_params(cls):
+        # _noc_params defined for each specific node type
+        return cls._noc_params
+
     def __init__(self, ruby_system):
         super(CHI_Node, self).__init__()
         self._ruby_system = ruby_system
@@ -128,6 +146,7 @@
         cntrl.snpIn.in_port = self._network.out_port
         cntrl.datIn.in_port = self._network.out_port

+
 class TriggerMessageBuffer(MessageBuffer):
     '''
     MessageBuffer for triggering internal controller events.
@@ -343,6 +362,12 @@
this object acts more like a proxy for seting things up and has no topology
     significance unless the cpus are set as its children at the top level
     '''
+
+    class NoC_Params(CHI_Node.NoC_Params):
+        def __init__(self):
+            super().__init__()
+    _noc_params = NoC_Params()
+
     def __init__(self, cpus, ruby_system,
                  l1Icache_type, l1Dcache_type,
                  cache_line_size,
@@ -448,6 +473,13 @@
     to set-up the interleaved address ranges used by the HNFs
     '''

+    class NoC_Params(CHI_Node.NoC_Params):
+        def __init__(self):
+            super().__init__()
+            # HNFs may also define the 'pairing' parameter to allow pairing
+            self.pairing = None
+    _noc_params = NoC_Params()
+
     _addr_ranges = []
     @classmethod
     def createAddrRanges(cls, sys_mem_ranges, cache_line_size, num_hnfs):
@@ -542,6 +574,12 @@
     '''
     Create the SNF for the boot memory
     '''
+
+    class NoC_Params(CHI_Node.NoC_Params):
+        def __init__(self):
+            super().__init__()
+    _noc_params = NoC_Params()
+
     def __init__(self, ruby_system, parent, bootmem):
         super(CHI_SNF_BootMem, self).__init__(ruby_system, parent)
         self._cntrl.memory_out_port = bootmem.port
@@ -551,6 +589,12 @@
     '''
     Create the SNF for a list main memory controllers
     '''
+
+    class NoC_Params(CHI_Node.NoC_Params):
+        def __init__(self):
+            super().__init__()
+    _noc_params = NoC_Params()
+
     def __init__(self, ruby_system, parent, mem_ctrl = None):
         super(CHI_SNF_MainMem, self).__init__(ruby_system, parent)
         if mem_ctrl:
@@ -590,6 +634,12 @@
     '''
     DMA controller wiredup to a given dma port
     '''
+
+    class NoC_Params(CHI_Node.NoC_Params):
+        def __init__(self):
+            super().__init__()
+    _noc_params = NoC_Params()
+
     def __init__(self, ruby_system, dma_port, parent):
         super(CHI_RNI_DMA, self).__init__(ruby_system, parent)
         assert(dma_port != None)
@@ -599,50 +649,39 @@
     '''
     DMA controller wiredup to ruby_system IO port
     '''
+
+    class NoC_Params(CHI_Node.NoC_Params):
+        def __init__(self):
+            super().__init__()
+    _noc_params = NoC_Params()
+
     def __init__(self, ruby_system, parent):
         super(CHI_RNI_IO, self).__init__(ruby_system, parent)
         ruby_system._io_port = self._sequencer

+
 def noc_params_from_config(config, noc_params):
-    # mesh options
-    noc_params.num_rows = config['mesh']['num_rows']
-    noc_params.num_cols = config['mesh']['num_cols']
-    if 'router_latency' in config['mesh']:
-        noc_params.router_latency = config['mesh']['router_latency']
-    if 'link_latency' in config['mesh']:
-        noc_params.router_link_latency = config['mesh']['link_latency']
-        noc_params.node_link_latency = config['mesh']['link_latency']
-    if 'router_link_latency' in config['mesh']:
- noc_params.router_link_latency = config['mesh']['router_link_latency']
-    if 'node_link_latency' in config['mesh']:
-        noc_params.node_link_latency = config['mesh']['node_link_latency']
-    if 'cross_links' in config['mesh']:
-        noc_params.cross_link_latency = \
-                                config['mesh']['cross_link_latency']
-        noc_params.cross_links = []
-        for x, y in config['mesh']['cross_links']:
-            noc_params.cross_links.append((x, y))
-            noc_params.cross_links.append((y, x))
-    else:
-        noc_params.cross_links = []
-        noc_params.cross_link_latency = 0
+    config.setup_NoC_Params(noc_params)
+    config.setup_CHI_RNF(CHI_RNF.noc_params())
+    config.setup_CHI_HNF(CHI_HNF.noc_params())
+    config.setup_CHI_SNF_MainMem(CHI_SNF_MainMem.noc_params())
+    config.setup_CHI_SNF_BootMem(CHI_SNF_BootMem.noc_params())
+    config.setup_CHI_RNI_DMA(CHI_RNI_DMA.noc_params())
+    config.setup_CHI_RNI_IO(CHI_RNI_IO.noc_params())

-    # CHI_RNF options
-    noc_params.CHI_RNF = config['CHI_RNF']
-
-    # CHI_RNI_IO
-    noc_params.CHI_RNI_IO = config['CHI_RNI_IO']
-
-    # CHI_HNF options
-    noc_params.CHI_HNF = config['CHI_HNF']
-    if 'pairing' in config['CHI_HNF']:
-        noc_params.pairing = config['CHI_HNF']['pairing']
-
-    # CHI_SNF_MainMem
-    noc_params.CHI_SNF_MainMem = config['CHI_SNF_MainMem']
-
-    # CHI_SNF_IO (applies to CHI_SNF_Bootmem)
-    noc_params.CHI_SNF_IO = config['CHI_SNF_IO']
+def noc_params_from_config_file(noc_config_file, noc_params):
+    from importlib.machinery import SourceFileLoader
+    loader = SourceFileLoader('chi_noc_configs', noc_config_file)
+    config = loader.load_module()
+    # required configuration functions
+    required = ['setup_NoC_Params', 'setup_CHI_RNF', 'setup_CHI_HNF',
+                'setup_CHI_SNF_MainMem', 'setup_CHI_SNF_BootMem',
+                'setup_CHI_RNI_DMA', 'setup_CHI_RNI_IO']
+    for func in required:
+        if not hasattr(config, func):
+            m5.fatal('Configuration function %s undefined in %s' % \
+                     (func, noc_config_file))
+    noc_params_from_config(config, noc_params)


 def create_system(options, full_system, system, dma_ports, bootmem,
@@ -668,12 +707,13 @@
             self.router_buffer_size = 4
             self.cntrl_msg_size = 8
             self.data_width = 32
+            self.cross_links = []
+            self.cross_link_latency = 0
     params = NoC_Params()

-    # read additional configurations from yaml file if provided
+    # read additional configurations from noc config file if provided
     if options.noc_config:
-        with open(options.noc_config, 'r') as file:
-            noc_params_from_config(yaml.load(file), params)
+        noc_params_from_config_file(options.noc_config, params)
     elif params.topology == 'CustomMesh':
         m5.fatal('--noc-config must be provided if topology is CustomMesh')

diff --git a/configs/topologies/CustomMesh.py b/configs/topologies/CustomMesh.py
index 73793e4..43a55d8 100644
--- a/configs/topologies/CustomMesh.py
+++ b/configs/topologies/CustomMesh.py
@@ -163,8 +163,9 @@

         return node_router

-    def distributeNodes(self, num_nodes_per_router, router_idx_list,
-                        node_list):
+    def distributeNodes(self, node_placement_config, node_list):
+        num_nodes_per_router = node_placement_config.num_nodes_per_router
+        router_idx_list = node_placement_config.router_list

         if num_nodes_per_router:
             # evenly distribute nodes to all listed routers
@@ -237,7 +238,8 @@
         hnf_list = []
         mem_ctrls = []
         io_mem_ctrls = []
-        io_rni_ctrls = []
+        rni_dma_ctrls = []
+        rni_io_ctrls = []

         for n in self.nodes:
             if isinstance(n, CHI.CHI_RNF):
@@ -249,9 +251,9 @@
             elif isinstance(n, CHI.CHI_SNF_BootMem):
                 io_mem_ctrls.append(n)
             elif isinstance(n, CHI.CHI_RNI_DMA):
-                io_rni_ctrls.append(n)
+                rni_dma_ctrls.append(n)
             elif isinstance(n, CHI.CHI_RNI_IO):
-                io_rni_ctrls.append(n)
+                rni_io_ctrls.append(n)
             else:
                 fatal('topologies.CustomMesh: {} not supported'
                             .format(n.__class__.__name__))
@@ -269,39 +271,20 @@
                        options.cross_links, options.cross_link_latency)

         # Place CHI_RNF on the mesh
-        num_nodes_per_router = options.CHI_RNF['num_nodes_per_router'] \
-                if 'num_nodes_per_router' in options.CHI_RNF else None
-        self.distributeNodes(num_nodes_per_router,
-                             options.CHI_RNF['router_list'],
-                             rnf_list)
+        self.distributeNodes(CHI.CHI_RNF.noc_params(), rnf_list)

         # Place CHI_HNF on the mesh
-        num_nodes_per_router = options.CHI_HNF['num_nodes_per_router'] \
-                if 'num_nodes_per_router' in options.CHI_HNF else None
-        self.distributeNodes(num_nodes_per_router,
-                             options.CHI_HNF['router_list'],
-                             hnf_list)
+        self.distributeNodes(CHI.CHI_HNF.noc_params(), hnf_list)

         # Place CHI_SNF_MainMem on the mesh
- num_nodes_per_router = options.CHI_SNF_MainMem['num_nodes_per_router']\ - if 'num_nodes_per_router' in options.CHI_SNF_MainMem else None
-        self.distributeNodes(num_nodes_per_router,
-                             options.CHI_SNF_MainMem['router_list'],
-                             mem_ctrls)
+        self.distributeNodes(CHI.CHI_SNF_MainMem.noc_params(), mem_ctrls)

         # Place all IO mem nodes on the mesh
-        num_nodes_per_router = options.CHI_SNF_IO['num_nodes_per_router'] \
-                if 'num_nodes_per_router' in options.CHI_SNF_IO else None
-        self.distributeNodes(num_nodes_per_router,
-                             options.CHI_SNF_IO['router_list'],
-                             io_mem_ctrls)
+ self.distributeNodes(CHI.CHI_SNF_BootMem.noc_params(), io_mem_ctrls)

         # Place all IO request nodes on the mesh
-        num_nodes_per_router = options.CHI_RNI_IO['num_nodes_per_router'] \
-                if 'num_nodes_per_router' in options.CHI_RNI_IO else None
-        self.distributeNodes(num_nodes_per_router,
-                             options.CHI_RNI_IO['router_list'],
-                             io_rni_ctrls)
+        self.distributeNodes(CHI.CHI_RNI_DMA.noc_params(), rni_dma_ctrls)
+        self.distributeNodes(CHI.CHI_RNI_IO.noc_params(), rni_io_ctrls)

         # Set up
         network.int_links = self._int_links

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/43123
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: release-staging-v21-0
Gerrit-Change-Id: Ic0c5407dba3d2483d5c30634c115b5410a5228fd
Gerrit-Change-Number: 43123
Gerrit-PatchSet: 1
Gerrit-Owner: Tiago Mück <tiago.m...@arm.com>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to