gem5 v24.1.0.1
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
utility_structs.hh
Go to the documentation of this file.
1/*
2* Copyright (c) 2024 The Regents of The University of California
3* All rights reserved.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are
7* met: redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer;
9* redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution;
12* neither the name of the copyright holders nor the names of its
13* contributors may be used to endorse or promote products derived from
14* this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27*/
28
29#ifndef __CPU_TESTERS_SPATTER_GEN_UTILITY_STRUCTS_HH__
30#define __CPU_TESTERS_SPATTER_GEN_UTILITY_STRUCTS_HH__
31
32#include <deque>
33#include <queue>
34
35#include "base/random.hh"
36#include "base/types.hh"
37#include "enums/SpatterKernelType.hh"
38#include "mem/packet.hh"
39
40namespace gem5
41{
42
43template<typename T>
45{
46 private:
48
49 std::queue<T> items;
50 std::queue<Tick> insertionTimes;
51
52 public:
54
55 void push(T item, Tick insertion_time)
56 {
57 items.push(item);
58 insertionTimes.push(insertion_time);
59 }
60
61 void pop()
62 {
63 items.pop();
64 insertionTimes.pop();
65 }
66
67 T front() const { return items.front(); }
68
69 bool empty() const { return items.empty(); }
70
71 size_t size() const { return items.size(); }
72
73 bool hasReady(Tick current_time) const
74 {
75 if (empty()) {
76 return false;
77 }
78 return (current_time - insertionTimes.front()) >= latency;
79 }
80};
81
82
83
84// Represents a single access to a SpatterKernel.
85// It supports multiple levels of indirection.
86// However, the SpatterKernel class only works with one level of
87// indirection (i.e. accessing value[index[i]]).
89{
90 typedef std::tuple<Addr, size_t> AccessPair;
91 typedef enums::SpatterKernelType SpatterKernelType;
92
96 std::queue<AccessPair> accessPairs;
97
99 RequestorID requestor_id,
100 SpatterKernelType kernel_type,
101 const std::queue<AccessPair>& access_pairs
102 ):
103 requestorId(requestor_id), _kernelType(kernel_type),
104 accTripTime(0), accessPairs(access_pairs)
105 {}
106
108
109 int tripsLeft() const { return accessPairs.size(); }
110
111 void recordTripTime(Tick trip_time) { accTripTime += trip_time; }
112
113 Tick tripTimeSoFar() const { return accTripTime; }
114
116 {
117 assert(tripsLeft() > 0);
118 AccessPair access_pair = accessPairs.front();
119 accessPairs.pop();
120 return access_pair;
121 }
122
124 {
125 Addr addr;
126 size_t size;
127 std::tie(addr, size) = nextAccessPair();
128 MemCmd cmd;
129 if (tripsLeft() >= 1){
130 cmd = MemCmd::ReadReq;
131 } else {
132 cmd = _kernelType == \
133 SpatterKernelType::gather ? MemCmd::ReadReq : MemCmd::WriteReq;
134 }
135 return createPacket(addr, size, cmd);
136 }
137
138 PacketPtr createPacket(Addr addr, size_t size, MemCmd cmd) const
139 {
140 RequestPtr req = std::make_shared<Request>(addr, size, 0, requestorId);
141
142 // Dummy PC to have PC-based prefetchers latch on;
143 // get entropy into higher bits
144 // This piece of code is directly copied from
145 // gem5::TrafficGen::
146 req->setPC(((Addr) requestorId) << 2);
147 PacketPtr pkt = new Packet(req, cmd);
148 uint8_t* pkt_data = new uint8_t[req->getSize()];
149 // Randomly intialize pkt_data, for testing cache coherence.
150 for (int i = 0; i < req->getSize(); i++) {
151 pkt_data[i] = rng->random<uint8_t>();
152 }
153 pkt->dataDynamic(pkt_data);
154 return pkt;
155 }
156
157 private:
159};
160
162{
163 private:
164 typedef enums::SpatterKernelType SpatterKernelType;
166
168 {
169 private:
171 uint32_t stride;
172
173 uint32_t next;
174 public:
176 {}
177
178 IndexGen(uint32_t base_index,
179 uint32_t indices_per_stride,
180 uint32_t stride_size):
181 indicesPerStride(indices_per_stride),
182 stride(stride_size), next(base_index)
183 {}
184
185 uint32_t nextIndex() {
186 uint32_t ret = next;
187 // update next index
188 next++;
189 if (next % indicesPerStride == 0) {
191 }
192 return ret;
193 }
194 };
195
198
199 uint32_t _id;
200 uint32_t delta;
201 uint32_t count;
202
204
205 size_t indexSize;
207
208 size_t valueSize;
210
211 // current iteration over indices
212 uint32_t iteration;
213
214 // number of times we have left to roll indices to finish one iteration.
215 uint32_t remRolls;
217
218 public:
219
221 RequestorID requestor_id,
222 uint32_t id, uint32_t delta, uint32_t count,
224 uint32_t base_index, uint32_t indices_per_stride, uint32_t stride,
225 size_t index_size, Addr base_index_addr,
226 size_t value_size, Addr base_value_addr
227 ):
228 requestorId(requestor_id),
229 indexGen(base_index, indices_per_stride, stride),
231 _type(type),
232 indexSize(index_size), baseIndexAddr(base_index_addr),
233 valueSize(value_size), baseValueAddr(base_value_addr),
234 iteration(0), remRolls(0)
235 {}
236
237 uint32_t id() const { return _id; }
238
240 {
241 indices.assign(pattern.begin(), pattern.end());
242 remRolls = indices.size();
243 }
244
245 SpatterKernelType type() const { return _type; }
246
247 bool done() const { return iteration == count; }
248
250 {
251 std::queue<AccessPair> access_pairs;
252 // get the next index for the index array
253 uint32_t index = indexGen.nextIndex();
254 Addr index_addr = baseIndexAddr + (index * indexSize);
255 access_pairs.emplace(index_addr, indexSize);
256
257 uint32_t front = indices.front();
258 uint32_t value_index = (delta * iteration) + front;
259 Addr value_addr = baseValueAddr + (value_index * valueSize);
260 access_pairs.emplace(value_addr, valueSize);
261 // roll indices
262 indices.pop_front();
263 indices.push_back(front);
264 remRolls--;
265 if (remRolls == 0) {
266 remRolls = indices.size();
267 iteration++;
268 }
269
270 return new SpatterAccess(requestorId, _type, access_pairs);
271 }
272};
273
274} // namespace gem5
275
276#endif // __CPU_TESTERS_SPATTER_GEN_UTILITY_STRUCTS_HH__
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition packet.hh:295
void dataDynamic(T *p)
Set the data pointer to a value that should have delete [] called on it.
Definition packet.hh:1213
std::shared_ptr< Random > RandomPtr
Definition random.hh:65
static RandomPtr genRandom()
Definition random.hh:68
IndexGen(uint32_t base_index, uint32_t indices_per_stride, uint32_t stride_size)
SpatterAccess::AccessPair AccessPair
SpatterKernelType _type
void setIndices(const std::vector< uint32_t > &pattern)
uint32_t id() const
enums::SpatterKernelType SpatterKernelType
SpatterAccess * nextSpatterAccess()
SpatterKernel(RequestorID requestor_id, uint32_t id, uint32_t delta, uint32_t count, SpatterKernelType type, uint32_t base_index, uint32_t indices_per_stride, uint32_t stride, size_t index_size, Addr base_index_addr, size_t value_size, Addr base_value_addr)
SpatterKernelType type() const
std::deque< uint32_t > indices
std::queue< T > items
TimedQueue(Tick latency)
std::queue< Tick > insertionTimes
bool hasReady(Tick current_time) const
size_t size() const
void push(T item, Tick insertion_time)
STL deque class.
Definition stl.hh:44
STL vector class.
Definition stl.hh:37
Bitfield< 7 > i
Definition misc_types.hh:67
Bitfield< 21, 20 > stride
Bitfield< 30, 0 > index
Bitfield< 3 > addr
Definition types.hh:84
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36
std::shared_ptr< Request > RequestPtr
Definition request.hh:94
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
uint64_t Tick
Tick count type.
Definition types.hh:58
uint16_t RequestorID
Definition request.hh:95
Declaration of the Packet class.
A virtual base opaque structure used to hold state associated with the packet (e.g....
Definition packet.hh:469
PacketPtr createPacket(Addr addr, size_t size, MemCmd cmd) const
SpatterKernelType type() const
enums::SpatterKernelType SpatterKernelType
std::tuple< Addr, size_t > AccessPair
SpatterAccess(RequestorID requestor_id, SpatterKernelType kernel_type, const std::queue< AccessPair > &access_pairs)
SpatterKernelType _kernelType
AccessPair nextAccessPair()
std::queue< AccessPair > accessPairs
Random::RandomPtr rng
void recordTripTime(Tick trip_time)

Generated on Mon Jan 13 2025 04:28:32 for gem5 by doxygen 1.9.8