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

(1) fix bug on gem5 full-system simulation / (2) add support on standard library #62

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
Binary file added .README.md.swp
Binary file not shown.
22 changes: 17 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,24 +116,36 @@ env.Append(
ramulator2_path+'/ext/yaml-cpp/include'
])
```
4. Put the Ramulator2 wrapper code to `gem5/src/mem/`
5. Add the code to `gem5/src/mem/SConscript` to register the Ramulator2 SimObjects to gem5
4. Put the Ramulator2 wrapper code to `gem5/src/mem/`. And `wrapper/component` code to `gem5/src/python/gem5/components/memory`
5. Add the code to register the Ramulator2 SimObjects to gem5
```python
# add to gem5/src/mem/SConscript
if env['HAVE_RAMULATOR2']:
SimObject('Ramulator2.py', sim_objects=['Ramulator2'])
Source('ramulator2.cc')
DebugFlag("Ramulator2")

# add to gem5/src/python/SConscript
PySource('gem5.components.memory', 'gem5/components/memory/ramulator_2.py')

```
6. Create the Ramulator2 SimObject as the memory controller and specify the path to the Ramulator 2.0 configuration file in your gem5 configuration script, e.g.,
6. Create the Ramulator2 SimObject as the memory controller and specify the path to the Ramulator 2.0 configuration file in your gem5 configuration script. e.g.,
```python
# version1 - using se.py
import m5
from m5.objects import *

system = System()
system.mem_ctrl = Ramulator2()
system.mem_ctrl.config_path = "<path-to-config>.yaml" # Don't forget to specify GEM5 as the implementation of the frontend interface!

# Continue your configuration of gem5 ...
...

# version2 - using standard library
memory = Ramulator2System("<path-to-config>.yaml", "<fill-size>GB")
board = SimpleBoard (
memory = memory
...
)
```

### General Instructions for Writing Your Own Wrapper of Ramulator 2.0 for Another (including Your Own) Simulator
Expand Down
82 changes: 82 additions & 0 deletions resources/gem5_wrappers/component/ramulator_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import m5
import os
import configparser

from m5.objects import Ramulator2, AddrRange, Port, MemCtrl
from m5.util.convert import toMemorySize

from ...utils.override import overrides
from ..boards.abstract_board import AbstractBoard
from .abstract_memory_system import AbstractMemorySystem


from typing import Optional, Tuple, Sequence, List

class Ramulator2MemCtrl(Ramulator2):
"""
A Ramulator2 Memory Controller.

The class serves as a SimObject object wrapper, utiliszing the Ramulator2
configuratons.
"""

def __init__(self, config_path: str) -> None:
"""
:param mem_name: The name of the type of memory to be configured.
:param num_chnls: The number of channels.
"""
super().__init__()
self.config_path = config_path


class Ramulator2System (AbstractMemorySystem):

def __init__(self, config_path: str, size: Optional[str]):
"""
:param mem_name: The name of the type of memory to be configured.
:param num_chnls: The number of channels.
"""
super().__init__()
self.mem_ctrl = Ramulator2MemCtrl(config_path)
self._size = toMemorySize(size)

if not size:
raise NotImplementedError(
"Ramulator2 memory controller requires a size parameter."
)

@overrides(AbstractMemorySystem)
def incorporate_memory(self, board: AbstractBoard) -> None:
pass

@overrides(AbstractMemorySystem)
def get_mem_ports(self) -> Tuple[Sequence[AddrRange], Port]:
return [(self.mem_ctrl.range, self.mem_ctrl.port)]

@overrides(AbstractMemorySystem)
def get_memory_controllers(self) -> List[MemCtrl]:
return [self.mem_ctrl]

@overrides(AbstractMemorySystem)
def get_size(self) -> int:
return self._size

@overrides(AbstractMemorySystem)
def set_memory_range(self, ranges: List[AddrRange]) -> None:
if len(ranges)!=1 or ranges[0].size() != self._size:
raise Exception(
"Single channel Ramulator2 memory controller requires a single "
"range which matches the memory's size."
)
#self._mem_range = ranges[0]
#self.mem_ctrl.range = AddrRange(
# start=self._mem_range.start,
# size=self._mem_range.size(),
# intlvHighBit=6+0-1,
# xorHighBit=0,
# intlvBits=0,
# intlvMatch=0,
#)
self.mem_ctrl.range = ranges[0]


2 changes: 1 addition & 1 deletion resources/gem5_wrappers/ramulator2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Ramulator2::startup()
startTick = curTick();

// kick off the clock ticks
schedule(tickEvent, clockEdge());
schedule(tickEvent, 10000000000000);
}

void
Expand Down