-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMeshCacheWithPickleDevice.py
More file actions
312 lines (291 loc) · 12.5 KB
/
MeshCacheWithPickleDevice.py
File metadata and controls
312 lines (291 loc) · 12.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
# Copyright (c) 2024 Advanced Micro Devices, Inc.
# Copyright (c) 2025-2026 The Regents of the University of California
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met: redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer;
# redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution;
# neither the name of the copyright holders nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from typing import List
from gem5.utils.override import overrides
from gem5.components.boards.abstract_board import AbstractBoard
from m5.objects import (
RubySequencer,
AddrRange,
TrafficMux,
PickleDevice,
LLCPrefetchAgent,
NULL,
)
from .components.CoreTile import CoreTile
from .components.PickleDeviceTile import PickleDeviceTile
from .components.MeshDescriptor import MeshTracker, NodeType
from .components.custom_components.DummyCacheController import DummyCacheController
from .utils.SizeArithmetic import SizeArithmetic
from .MeshCache import MeshCache
class MeshCacheWithPickleDevice(MeshCache):
def __init__(
self,
l1i_size: str,
l1i_assoc: int,
l1d_size: str,
l1d_assoc: int,
l2_size: str,
l2_assoc: int,
l3_size: str,
l3_assoc: int,
num_core_complexes: int,
is_fullsystem: bool,
data_prefetcher_class: str,
mesh_descriptor: MeshTracker,
device_cache_size: str,
device_cache_assoc: int,
pdev_num_tbes: int,
):
MeshCache.__init__(
self=self,
l1i_size=l1i_size,
l1i_assoc=l1i_assoc,
l1d_size=l1d_size,
l1d_assoc=l1d_assoc,
l2_size=l2_size,
l2_assoc=l2_assoc,
l3_size=l3_size,
l3_assoc=l3_assoc,
num_core_complexes=num_core_complexes,
is_fullsystem=is_fullsystem,
data_prefetcher_class=data_prefetcher_class,
mesh_descriptor=mesh_descriptor,
)
self._pickle_devices = []
self._device_cache_size = device_cache_size
self._device_cache_assoc = device_cache_assoc
self._pdev_num_tbes = pdev_num_tbes
self._addr_range_assigned = False
def set_pickle_devices(self, pickle_devices):
self._pickle_devices = pickle_devices
def set_traffic_uncacheable_forwarders(self, uncacheable_forwarders):
self._uncacheable_forwarders = uncacheable_forwarders
@overrides(MeshCache)
def _create_core_tiles(
self,
board: AbstractBoard,
pickle_devices: PickleDevice,
uncacheable_forwarders: TrafficMux,
data_prefetcher_class: str,
) -> None:
core_tile_coordinates = self._mesh_descriptor.get_tiles_coordinates(
NodeType.CoreTile
)
cores = board.get_processor().get_cores()
num_l3_slices = self._mesh_descriptor.get_num_l3_slices()
l3_slice_size = (SizeArithmetic(self._l3_size) // num_l3_slices).get()
self.core_tiles = [
CoreTile(
board=board,
ruby_system=self.ruby_system,
coordinate=core_tile_coordinate,
mesh_descriptor=self._mesh_descriptor,
core=core,
core_id=core_id,
l1i_size=self._l1i_size,
l1i_associativity=self._l1i_assoc,
l1d_size=self._l1d_size,
l1d_associativity=self._l1d_assoc,
l2_size=self._l2_size,
l2_associativity=self._l2_assoc,
l3_slice_size=l3_slice_size,
l3_associativity=self._l3_assoc,
pickle_device=pickle_devices[0],
uncacheable_forwarder=uncacheable_forwarders[core_id],
data_prefetcher_class=data_prefetcher_class,
)
for core_id, (core, core_tile_coordinate) in enumerate(
zip(cores, core_tile_coordinates)
)
]
for tile in self.core_tiles:
self.ruby_system.network.incorporate_ruby_subsystem(tile)
@overrides(MeshCache)
def incorporate_cache(self, board: AbstractBoard) -> None:
self._setup_ruby_system()
self._get_board_info(board)
self._create_core_tiles(
board,
self._pickle_devices,
self._uncacheable_forwarders,
self._data_prefetcher_class,
)
self._create_l3_only_tiles(board)
self._create_memory_tiles(board)
self._create_dma_tiles(board)
self._create_pickle_device_component_tiles(
board,
self._pickle_devices,
self._device_cache_size,
self._device_cache_assoc,
self._pdev_num_tbes,
)
self._assign_addr_range(board)
self._create_llc_prefetch_agents(board)
self._set_downstream_destinations()
self.ruby_system.network.create_mesh()
self._incorperate_system_ports(board)
self._setup_cache_block_tracker(board)
self._setup_cache_block_tracker_for_pickle_devices(board, self._pickle_devices)
self._finalize_ruby_system()
@overrides(MeshCache)
def support_pickle_device_tile(self) -> bool:
return True
def _create_llc_prefetch_agents(self, board: AbstractBoard) -> None:
assert hasattr(
self, "_pickle_devices"
), "Pickle devices must be set before creating LLC prefetch agents"
assert hasattr(
self, "core_tiles"
), "LLC prefetch agents must be created after core tiles"
assert hasattr(
self, "pickle_device_component_tiles"
), "LLC prefetch agents must be created after pickle device tiles"
assert (
hasattr(self, "_addr_range_assigned") and self._addr_range_assigned
), "LLC prefetch agents must be created after the addr range was assigned to each LLC"
# Create one LLC prefetch agent per LLC slice
l3_slices, l3_routers = self._get_all_l3_slices_and_l3_routers()
self.llc_prefetch_agents = [
LLCPrefetchAgent(
llc_controller=l3_slice,
addr_ranges=l3_slice.addr_ranges,
)
for l3_slice in l3_slices
]
# Assign the LLC prefetch agent to the Pickle prefetcher
for pickle_device in self._pickle_devices:
pickle_device.prefetcher.llc_prefetch_agents = self.llc_prefetch_agents
# Create one dummy cache and one sequencer per LLC prefetch agent
self.llc_prefetch_agent_dummy_caches = [
DummyCacheController(
ruby_system=self.ruby_system,
cache_line_size=board.get_cache_line_size(),
clk_domain=board.get_clock_domain(),
)
for _ in self.llc_prefetch_agents
]
self.llc_prefetch_agent_sequencers = [
RubySequencer(
version=self.ruby_system.network.get_next_sequencer_id(),
coreid=100 + i,
dcache=dummy_cache.cache,
clk_domain=dummy_cache.clk_domain,
ruby_system=self.ruby_system,
)
for i, dummy_cache in enumerate(self.llc_prefetch_agent_dummy_caches)
]
for dummy_cache, sequencer in zip(
self.llc_prefetch_agent_dummy_caches, self.llc_prefetch_agent_sequencers
):
dummy_cache.sequencer = sequencer
# Connect and set the downstream destination of dummy cache to the LLC slice
# The dummy cache does not store any data so entries will be evicted to
# the LLC slice immediately
for dummy_cache, l3_slice in zip(
self.llc_prefetch_agent_dummy_caches, l3_slices
):
dummy_cache.downstream_destinations = [l3_slice]
self.dummy_cache_and_l3_router_links = [
self.ruby_system.network.create_ext_link(dummy_cache, l3_router)
for dummy_cache, l3_router in zip(
self.llc_prefetch_agent_dummy_caches, l3_routers
)
]
# Connect sequencer to the agent
for agent, sequencer in zip(
self.llc_prefetch_agents, self.llc_prefetch_agent_sequencers
):
agent.mem_side_port = sequencer.in_ports
def _create_pickle_device_component_tiles(
self,
board: AbstractBoard,
pickle_devices: PickleDevice,
device_cache_size: str,
device_cache_assoc: int,
pdev_num_tbes: int,
) -> None:
pickle_device_tile_coordinates = self._mesh_descriptor.get_tiles_coordinates(
NodeType.PickleDeviceTile
)
self.pickle_device_component_tiles = [
PickleDeviceTile(
board=board,
ruby_system=self.ruby_system,
coordinate=pickle_device_tile_coordinate,
mesh_descriptor=self._mesh_descriptor,
device_cache_size=device_cache_size,
device_cache_assoc=device_cache_assoc,
num_tbes=pdev_num_tbes,
)
for pickle_device_tile_coordinate in pickle_device_tile_coordinates
]
assert len(pickle_devices) == len(self.pickle_device_component_tiles)
for pd, tile in zip(pickle_devices, self.pickle_device_component_tiles):
self.traffic_mux = TrafficMux()
self.traffic_mux.rsp_ports = pd.request_port
if pd.mmu != NULL:
pd.mmu.connectWalkerPorts(
self.traffic_mux.rsp_ports, self.traffic_mux.rsp_ports
)
pd.functional_mmu.connectWalkerPorts(
self.traffic_mux.rsp_ports, self.traffic_mux.rsp_ports
)
self.traffic_mux.req_port = tile.controller.sequencer.in_ports
for tile in self.pickle_device_component_tiles:
self.ruby_system.network.incorporate_ruby_subsystem(tile)
def post_instantiate(self) -> None:
pass
@overrides(MeshCache)
def _assign_addr_range(self, board: AbstractBoard) -> None:
MeshCache._assign_addr_range(self, board)
pickle_device_tile = self.pickle_device_component_tiles[0]
pickle_device_tile.controller.addr_ranges = [AddrRange((1 << 64) - 2, size=1)]
self._addr_range_assigned = True
@overrides(MeshCache)
def _set_downstream_destinations(self) -> None:
all_l3_slices = self._get_all_l3_slices()
all_mem_ctrls = [mem_tile.memory_controller for mem_tile in self.memory_tiles]
pickle_device_tile = self.pickle_device_component_tiles[0]
all_l3_slices_and_pickle_device_tile = all_l3_slices + [
pickle_device_tile.controller
]
for tile in self.core_tiles:
tile.set_l2_downstream_destinations(all_l3_slices_and_pickle_device_tile)
pickle_device_tile.controller.downstream_destinations = all_l3_slices
for l3_slice in all_l3_slices:
l3_slice.downstream_destinations = all_mem_ctrls
if self._has_dma:
for tile in self.dma_tiles:
tile.dma_controller.downstream_destinations = all_l3_slices
def _setup_cache_block_tracker_for_pickle_devices(
self, board: AbstractBoard, pickle_devices: List[PickleDevice]
) -> None:
for pickle_device in pickle_devices:
self.cache_block_tracker.addPrefetcherRequestor(pickle_device)
for llc_prefetch_agent in self.llc_prefetch_agents:
self.cache_block_tracker.addPrefetcherRequestor(llc_prefetch_agent)