gem5  v22.1.0.0
fetch_unit.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2017 Advanced Micro Devices, Inc.
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 met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its
16  * contributors may be used to endorse or promote products derived from this
17  * software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef __FETCH_UNIT_HH__
33 #define __FETCH_UNIT_HH__
34 
35 #include <cassert>
36 #include <cstdint>
37 #include <deque>
38 #include <map>
39 #include <utility>
40 #include <vector>
41 
42 #include "arch/gpu_decoder.hh"
43 #include "base/types.hh"
44 #include "config/the_gpu_isa.hh"
45 #include "gpu-compute/scheduler.hh"
46 #include "mem/packet.hh"
47 #include "sim/eventq.hh"
48 
49 namespace gem5
50 {
51 
52 class ComputeUnit;
53 class Wavefront;
54 
55 class FetchUnit
56 {
57  public:
58  FetchUnit(const ComputeUnitParams &p, ComputeUnit &cu);
59  ~FetchUnit();
60  void init();
61  void exec();
63  void initiateFetch(Wavefront *wavefront);
64  void fetch(PacketPtr pkt, Wavefront *wavefront);
65  void processFetchReturn(PacketPtr pkt);
66  void flushBuf(int wfSlotId);
67  static uint32_t globalFetchUnitID;
68 
69  private:
75  {
76  public:
77  FetchBufDesc() : bufStart(nullptr), bufEnd(nullptr),
78  readPtr(nullptr), fetchDepth(0), maxIbSize(0), maxFbSize(0),
79  cacheLineSize(0), restartFromBranch(false), wavefront(nullptr),
80  _decoder(nullptr)
81  {
82  }
83 
85  {
86  delete[] bufStart;
87  }
88 
94  void allocateBuf(int fetch_depth, int cache_line_size, Wavefront *wf);
95 
96  int
98  {
99  return bufferedLines() + reservedLines();
100  }
101 
102  int bufferedLines() const { return bufferedPCs.size(); }
103  int bufferedBytes() const { return bufferedLines() * cacheLineSize; }
104  int reservedLines() const { return reservedPCs.size(); }
105  bool hasFreeSpace() const { return !freeList.empty(); }
106  void flushBuf();
108 
112  void reserveBuf(Addr vaddr);
113 
119  uint8_t*
121  {
122  auto reserved_pc = reservedPCs.find(vaddr);
123  assert(reserved_pc != reservedPCs.end());
124  assert(reserved_pc == reservedPCs.begin());
125 
126  return reserved_pc->second;
127  }
128 
133  bool
135  {
136  auto reserved_pc = reservedPCs.find(vaddr);
137  bool is_reserved = (reserved_pc != reservedPCs.end());
138  return is_reserved;
139  }
140 
141  void fetchDone(Addr vaddr);
142 
148  bool hasFetchDataToProcess() const;
149 
158  void decodeInsts();
159 
165  void checkWaveReleaseBuf();
166 
167  void
168  decoder(TheGpuISA::Decoder *dec)
169  {
170  _decoder = dec;
171  }
172 
173  bool
175  {
176  bool buffered = bufferedPCs.find(pc) != bufferedPCs.end()
177  && reservedPCs.find(pc) != reservedPCs.end();
178 
179  return buffered;
180  }
181 
186  int fetchBytesRemaining() const;
187 
188  private:
189  void decodeSplitInst();
190 
196  bool splitDecode() const;
197 
204  std::map<Addr, uint8_t*> bufferedPCs;
205  std::map<Addr, uint8_t*> reservedPCs;
206 
216 
221  uint8_t *bufStart;
222  uint8_t *bufEnd;
227  uint8_t *readPtr;
228  // how many lines the fetch unit may buffer
230  // maximum size (in number of insts) of the WF's IB
232  // maximum size (in bytes) of this fetch buffer
237  // wavefront whose IB is serviced by this fetch buffer
239  TheGpuISA::Decoder *_decoder;
240  };
241 
242  class SystemHubEvent : public Event
243  {
246 
247  public:
249  : fetchUnit(fetch_unit), reqPkt(pkt)
250  {
252  }
253 
254  void process();
255  };
256 
257  bool timingSim;
259  TheGpuISA::Decoder decoder;
260 
261  // Fetch scheduler; Selects one wave from
262  // the fetch queue for instruction fetching.
263  // The selection is made according to
264  // a scheduling policy
266 
267  // Stores the list of waves that are
268  // ready to be fetched this cycle
270 
271  // Stores the fetch status of all waves dispatched to this SIMD.
272  // TRUE implies the wave is ready to fetch and is already
273  // moved to fetchQueue
275 
276  // Pointer to list of waves dispatched on to this SIMD unit
278  // holds the fetch buffers. each wave has 1 entry.
287 };
288 
289 } // namespace gem5
290 
291 #endif // __FETCH_UNIT_HH__
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
static const FlagsType AutoDelete
Definition: eventq.hh:107
void setFlags(Flags _flags)
Definition: eventq.hh:328
fetch buffer descriptor.
Definition: fetch_unit.hh:75
void fetchDone(Addr vaddr)
Definition: fetch_unit.cc:472
std::map< Addr, uint8_t * > reservedPCs
Definition: fetch_unit.hh:205
uint8_t * reservedBuf(Addr vaddr) const
return a pointer to the raw fetch buffer data.
Definition: fetch_unit.hh:120
void reserveBuf(Addr vaddr)
reserve an entry in the fetch buffer for PC = vaddr,
Definition: fetch_unit.cc:447
void decoder(TheGpuISA::Decoder *dec)
Definition: fetch_unit.hh:168
uint8_t * readPtr
pointer that points to the next chunk of inst data to be decoded.
Definition: fetch_unit.hh:227
int fetchBytesRemaining() const
calculates the number of fetched bytes that have yet to be decoded.
Definition: fetch_unit.cc:648
void checkWaveReleaseBuf()
checks if the wavefront can release any of its fetch buffer entries.
Definition: fetch_unit.cc:503
bool hasFetchDataToProcess() const
checks if the buffer contains valid data.
Definition: fetch_unit.cc:497
std::map< Addr, uint8_t * > bufferedPCs
the set of PCs (fetch addresses) that are currently buffered.
Definition: fetch_unit.hh:204
int bufferedAndReservedLines() const
Definition: fetch_unit.hh:97
bool isReserved(Addr vaddr) const
returns true if there is an entry reserved for this address, and false otherwise
Definition: fetch_unit.hh:134
void allocateBuf(int fetch_depth, int cache_line_size, Wavefront *wf)
allocate the fetch buffer space, and set the fetch depth (number of lines that may be buffered),...
Definition: fetch_unit.cc:346
bool pcBuffered(Addr pc) const
Definition: fetch_unit.hh:174
bool splitDecode() const
check if the next instruction to be processed out of the fetch buffer is split across the end/beginni...
Definition: fetch_unit.cc:636
void decodeInsts()
each time the fetch stage is ticked, we check if there are any data in the fetch buffer that may be d...
Definition: fetch_unit.cc:560
uint8_t * bufStart
raw instruction buffer.
Definition: fetch_unit.hh:221
TheGpuISA::Decoder * _decoder
Definition: fetch_unit.hh:239
std::deque< uint8_t * > freeList
represents the fetch buffer free list.
Definition: fetch_unit.hh:215
SystemHubEvent(PacketPtr pkt, FetchUnit *fetch_unit)
Definition: fetch_unit.hh:248
static uint32_t globalFetchUnitID
Definition: fetch_unit.hh:67
Scheduler fetchScheduler
Definition: fetch_unit.hh:265
std::vector< Wavefront * > * waveList
Definition: fetch_unit.hh:277
void bindWaveList(std::vector< Wavefront * > *list)
Definition: fetch_unit.cc:339
FetchUnit(const ComputeUnitParams &p, ComputeUnit &cu)
Definition: fetch_unit.cc:52
void fetch(PacketPtr pkt, Wavefront *wavefront)
Definition: fetch_unit.cc:230
std::vector< Wavefront * > fetchQueue
Definition: fetch_unit.hh:269
void initiateFetch(Wavefront *wavefront)
Definition: fetch_unit.cc:136
int fetchDepth
number of cache lines we can fetch and buffer.
Definition: fetch_unit.hh:286
TheGpuISA::Decoder decoder
Definition: fetch_unit.hh:259
ComputeUnit & computeUnit
Definition: fetch_unit.hh:258
void processFetchReturn(PacketPtr pkt)
Definition: fetch_unit.cc:307
std::vector< FetchBufDesc > fetchBuf
Definition: fetch_unit.hh:279
void flushBuf(int wfSlotId)
Definition: fetch_unit.cc:333
std::vector< std::pair< Wavefront *, bool > > fetchStatusQueue
Definition: fetch_unit.hh:274
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:294
STL vector class.
Definition: stl.hh:37
Bitfield< 4 > pc
Bitfield< 54 > p
Definition: pagetable.hh:70
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
static scfx_rep_node * list
Definition: scfx_rep.cc:336
Declaration of the Packet class.

Generated on Wed Dec 21 2022 10:22:35 for gem5 by doxygen 1.9.1