gem5  v20.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  * For use for simulation and test purposes only
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright notice,
11  * this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright notice,
14  * this list of conditions and the following disclaimer in the documentation
15  * and/or other materials provided with the distribution.
16  *
17  * 3. Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived from this
19  * software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #ifndef __FETCH_UNIT_HH__
35 #define __FETCH_UNIT_HH__
36 
37 #include <string>
38 #include <utility>
39 
40 #include "arch/gpu_decoder.hh"
41 #include "base/statistics.hh"
42 #include "config/the_gpu_isa.hh"
43 #include "gpu-compute/scheduler.hh"
44 #include "mem/packet.hh"
45 
46 class ComputeUnit;
47 class Wavefront;
48 
49 class FetchUnit
50 {
51  public:
52  FetchUnit(const ComputeUnitParams* p, ComputeUnit &cu);
53  ~FetchUnit();
54  void init();
55  void exec();
57  void initiateFetch(Wavefront *wavefront);
58  void fetch(PacketPtr pkt, Wavefront *wavefront);
59  void processFetchReturn(PacketPtr pkt);
60  void flushBuf(int wfSlotId);
61  static uint32_t globalFetchUnitID;
62 
63  private:
69  {
70  public:
71  FetchBufDesc() : bufStart(nullptr), bufEnd(nullptr),
72  readPtr(nullptr), fetchDepth(0), maxIbSize(0), maxFbSize(0),
73  cacheLineSize(0), restartFromBranch(false), wavefront(nullptr),
74  _decoder(nullptr)
75  {
76  }
77 
79  {
80  delete[] bufStart;
81  }
82 
88  void allocateBuf(int fetch_depth, int cache_line_size, Wavefront *wf);
89 
90  int
92  {
93  return bufferedLines() + reservedLines();
94  }
95 
96  int bufferedLines() const { return bufferedPCs.size(); }
97  int bufferedBytes() const { return bufferedLines() * cacheLineSize; }
98  int reservedLines() const { return reservedPCs.size(); }
99  bool hasFreeSpace() const { return !freeList.empty(); }
100  void flushBuf();
102 
106  void reserveBuf(Addr vaddr);
107 
113  uint8_t*
115  {
116  auto reserved_pc = reservedPCs.find(vaddr);
117  assert(reserved_pc != reservedPCs.end());
118  assert(reserved_pc == reservedPCs.begin());
119 
120  return reserved_pc->second;
121  }
122 
127  bool
129  {
130  auto reserved_pc = reservedPCs.find(vaddr);
131  bool is_reserved = (reserved_pc != reservedPCs.end());
132  return is_reserved;
133  }
134 
135  void fetchDone(Addr vaddr);
136 
142  bool hasFetchDataToProcess() const;
143 
152  void decodeInsts();
153 
159  void checkWaveReleaseBuf();
160 
161  void
162  decoder(TheGpuISA::Decoder *dec)
163  {
164  _decoder = dec;
165  }
166 
167  bool
169  {
170  bool buffered = bufferedPCs.find(pc) != bufferedPCs.end()
171  && reservedPCs.find(pc) != reservedPCs.end();
172 
173  return buffered;
174  }
175 
180  int fetchBytesRemaining() const;
181 
182  private:
183  void decodeSplitInst();
184 
190  bool splitDecode() const;
191 
198  std::map<Addr, uint8_t*> bufferedPCs;
199  std::map<Addr, uint8_t*> reservedPCs;
200 
210 
215  uint8_t *bufStart;
216  uint8_t *bufEnd;
221  uint8_t *readPtr;
222  // how many lines the fetch unit may buffer
224  // maximum size (in number of insts) of the WF's IB
226  // maximum size (in bytes) of this fetch buffer
231  // wavefront whose IB is serviced by this fetch buffer
233  TheGpuISA::Decoder *_decoder;
234  };
235 
236  bool timingSim;
238  TheGpuISA::Decoder decoder;
239 
240  // Fetch scheduler; Selects one wave from
241  // the fetch queue for instruction fetching.
242  // The selection is made according to
243  // a scheduling policy
245 
246  // Stores the list of waves that are
247  // ready to be fetched this cycle
249 
250  // Stores the fetch status of all waves dispatched to this SIMD.
251  // TRUE implies the wave is ready to fetch and is already
252  // moved to fetchQueue
254 
255  // Pointer to list of waves dispatched on to this SIMD unit
257  // holds the fetch buffers. each wave has 1 entry.
266 };
267 
268 #endif // __FETCH_UNIT_HH__
FetchUnit::FetchBufDesc::reservedPCs
std::map< Addr, uint8_t * > reservedPCs
Definition: fetch_unit.hh:199
Scheduler
Definition: scheduler.hh:43
FetchUnit::computeUnit
ComputeUnit & computeUnit
Definition: fetch_unit.hh:237
FetchUnit::FetchBufDesc::bufferedAndReservedLines
int bufferedAndReservedLines() const
Definition: fetch_unit.hh:91
FetchUnit::FetchBufDesc::fetchBytesRemaining
int fetchBytesRemaining() const
calculates the number of fetched bytes that have yet to be decoded.
Definition: fetch_unit.cc:619
FetchUnit::FetchBufDesc::bufferedBytes
int bufferedBytes() const
Definition: fetch_unit.hh:97
FetchUnit::FetchBufDesc::bufferedPCs
std::map< Addr, uint8_t * > bufferedPCs
the set of PCs (fetch addresses) that are currently buffered.
Definition: fetch_unit.hh:198
FetchUnit::FetchBufDesc::isReserved
bool isReserved(Addr vaddr) const
returns true if there is an entry reserved for this address, and false otherwise
Definition: fetch_unit.hh:128
FetchUnit::FetchUnit
FetchUnit(const ComputeUnitParams *p, ComputeUnit &cu)
Definition: fetch_unit.cc:48
FetchUnit::initiateFetch
void initiateFetch(Wavefront *wavefront)
Definition: fetch_unit.cc:132
FetchUnit::FetchBufDesc::decoder
void decoder(TheGpuISA::Decoder *dec)
Definition: fetch_unit.hh:162
FetchUnit::fetchBuf
std::vector< FetchBufDesc > fetchBuf
Definition: fetch_unit.hh:258
FetchUnit::FetchBufDesc::~FetchBufDesc
~FetchBufDesc()
Definition: fetch_unit.hh:78
FetchUnit::fetchScheduler
Scheduler fetchScheduler
Definition: fetch_unit.hh:244
FetchUnit::bindWaveList
void bindWaveList(std::vector< Wavefront * > *list)
Definition: fetch_unit.cc:311
FetchUnit::FetchBufDesc::_decoder
TheGpuISA::Decoder * _decoder
Definition: fetch_unit.hh:233
sc_dt::list
static scfx_rep_node * list
Definition: scfx_rep.cc:368
FetchUnit::FetchBufDesc::bufferedLines
int bufferedLines() const
Definition: fetch_unit.hh:96
FetchUnit::fetchDepth
int fetchDepth
number of cache lines we can fetch and buffer.
Definition: fetch_unit.hh:265
std::vector< Wavefront * >
FetchUnit::FetchBufDesc::cacheLineBits
int cacheLineBits
Definition: fetch_unit.hh:229
FetchUnit::~FetchUnit
~FetchUnit()
Definition: fetch_unit.cc:54
packet.hh
FetchUnit::FetchBufDesc::readPtr
uint8_t * readPtr
pointer that points to the next chunk of inst data to be decoded.
Definition: fetch_unit.hh:221
FetchUnit::FetchBufDesc::maxFbSize
int maxFbSize
Definition: fetch_unit.hh:227
FetchUnit::FetchBufDesc::nextFetchAddr
Addr nextFetchAddr()
Definition: fetch_unit.cc:364
ComputeUnit
Definition: compute_unit.hh:198
FetchUnit::flushBuf
void flushBuf(int wfSlotId)
Definition: fetch_unit.cc:305
FetchUnit::FetchBufDesc::wavefront
Wavefront * wavefront
Definition: fetch_unit.hh:232
FetchUnit::FetchBufDesc::cacheLineSize
int cacheLineSize
Definition: fetch_unit.hh:228
FetchUnit::FetchBufDesc::bufEnd
uint8_t * bufEnd
Definition: fetch_unit.hh:216
MipsISA::vaddr
vaddr
Definition: pra_constants.hh:275
MipsISA::pc
Bitfield< 4 > pc
Definition: pra_constants.hh:240
statistics.hh
FetchUnit::FetchBufDesc::freeList
std::deque< uint8_t * > freeList
represents the fetch buffer free list.
Definition: fetch_unit.hh:209
FetchUnit
Definition: fetch_unit.hh:49
FetchUnit::FetchBufDesc::reserveBuf
void reserveBuf(Addr vaddr)
reserve an entry in the fetch buffer for PC = vaddr,
Definition: fetch_unit.cc:419
FetchUnit::FetchBufDesc::hasFreeSpace
bool hasFreeSpace() const
Definition: fetch_unit.hh:99
FetchUnit::FetchBufDesc::FetchBufDesc
FetchBufDesc()
Definition: fetch_unit.hh:71
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
FetchUnit::FetchBufDesc::maxIbSize
int maxIbSize
Definition: fetch_unit.hh:225
scheduler.hh
FetchUnit::init
void init()
Definition: fetch_unit.cc:61
FetchUnit::exec
void exec()
Definition: fetch_unit.cc:80
FetchUnit::FetchBufDesc::flushBuf
void flushBuf()
Definition: fetch_unit.cc:342
FetchUnit::fetch
void fetch(PacketPtr pkt, Wavefront *wavefront)
Definition: fetch_unit.cc:217
FetchUnit::FetchBufDesc::fetchDepth
int fetchDepth
Definition: fetch_unit.hh:223
FetchUnit::FetchBufDesc::decodeSplitInst
void decodeSplitInst()
Definition: fetch_unit.cc:570
FetchUnit::FetchBufDesc::pcBuffered
bool pcBuffered(Addr pc) const
Definition: fetch_unit.hh:168
FetchUnit::FetchBufDesc::reservedBuf
uint8_t * reservedBuf(Addr vaddr) const
return a pointer to the raw fetch buffer data.
Definition: fetch_unit.hh:114
Wavefront
Definition: wavefront.hh:57
FetchUnit::FetchBufDesc::decodeInsts
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:532
Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:257
std::deque< uint8_t * >
FetchUnit::FetchBufDesc::bufStart
uint8_t * bufStart
raw instruction buffer.
Definition: fetch_unit.hh:215
FetchUnit::FetchBufDesc::hasFetchDataToProcess
bool hasFetchDataToProcess() const
checks if the buffer contains valid data.
Definition: fetch_unit.cc:469
FetchUnit::fetchQueue
std::vector< Wavefront * > fetchQueue
Definition: fetch_unit.hh:248
FetchUnit::decoder
TheGpuISA::Decoder decoder
Definition: fetch_unit.hh:238
FetchUnit::FetchBufDesc::fetchDone
void fetchDone(Addr vaddr)
Definition: fetch_unit.cc:444
FetchUnit::FetchBufDesc::restartFromBranch
bool restartFromBranch
Definition: fetch_unit.hh:230
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
FetchUnit::processFetchReturn
void processFetchReturn(PacketPtr pkt)
Definition: fetch_unit.cc:279
FetchUnit::FetchBufDesc
fetch buffer descriptor.
Definition: fetch_unit.hh:68
FetchUnit::FetchBufDesc::splitDecode
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:607
FetchUnit::FetchBufDesc::allocateBuf
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:318
FetchUnit::fetchStatusQueue
std::vector< std::pair< Wavefront *, bool > > fetchStatusQueue
Definition: fetch_unit.hh:253
FetchUnit::waveList
std::vector< Wavefront * > * waveList
Definition: fetch_unit.hh:256
FetchUnit::timingSim
bool timingSim
Definition: fetch_unit.hh:236
FetchUnit::FetchBufDesc::reservedLines
int reservedLines() const
Definition: fetch_unit.hh:98
FetchUnit::globalFetchUnitID
static uint32_t globalFetchUnitID
Definition: fetch_unit.hh:61
FetchUnit::FetchBufDesc::checkWaveReleaseBuf
void checkWaveReleaseBuf()
checks if the wavefront can release any of its fetch buffer entries.
Definition: fetch_unit.cc:475

Generated on Wed Sep 30 2020 14:02:12 for gem5 by doxygen 1.8.17