gem5 v24.0.0.0
Loading...
Searching...
No Matches
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] = random_mt.random<uint8_t>();
152 }
153 pkt->dataDynamic(pkt_data);
154 return pkt;
155 }
156};
157
159{
160 private:
161 typedef enums::SpatterKernelType SpatterKernelType;
163
165 uint32_t _id;
166 uint32_t delta;
167 uint32_t count;
168
170
171 size_t indexSize;
173
174 size_t valueSize;
176
177 // needed to iterate over indices multiple times.
178 uint32_t index;
179 // current iteration over indices
180 uint32_t iteration;
181
182 // number of times we have left to roll indices to finish one iteration.
183 uint32_t remRolls;
185
186 public:
187
189 RequestorID requestor_id,
190 uint32_t id, uint32_t delta, uint32_t count,
192 size_t index_size, Addr base_index_addr,
193 size_t value_size, Addr base_value_addr
194 ):
195 requestorId(requestor_id),
197 _type(type),
198 indexSize(index_size), baseIndexAddr(base_index_addr),
199 valueSize(value_size), baseValueAddr(base_value_addr),
200 index(0), iteration(0), remRolls(0)
201 {}
202
203 uint32_t id() const { return _id; }
204
206 {
207 indices.assign(pattern.begin(), pattern.end());
208 remRolls = indices.size();
209 }
210
211 SpatterKernelType type() const { return _type; }
212
213 bool done() const { return iteration == count; }
214
216 {
217 std::queue<AccessPair> access_pairs;
218 Addr index_addr = baseIndexAddr + (index * indexSize);
219 access_pairs.emplace(index_addr, indexSize);
220 // update index in the index array
221 index++;
222
223 uint32_t front = indices.front();
224 uint32_t value_index = (delta * iteration) + front;
225 Addr value_addr = baseValueAddr + (value_index * valueSize);
226 access_pairs.emplace(value_addr, valueSize);
227 // roll indices
228 indices.pop_front();
229 indices.push_back(front);
230 remRolls--;
231 if (remRolls == 0) {
232 remRolls = indices.size();
233 iteration++;
234 }
235
236 return new SpatterAccess(requestorId, _type, access_pairs);
237 }
238};
239
240} // namespace gem5
241
242#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
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, 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
Random random_mt
Definition random.cc:99
std::enable_if_t< std::is_integral_v< T >, T > random()
Use the SFINAE idiom to choose an implementation based on whether the type is integral or floating po...
Definition random.hh:90
Bitfield< 7 > i
Definition misc_types.hh:67
Bitfield< 3 > addr
Definition types.hh:84
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria 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
void recordTripTime(Tick trip_time)

Generated on Tue Jun 18 2024 16:24:02 for gem5 by doxygen 1.11.0