gem5  v20.0.0.2
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
vector_register_file.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-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 
35 
36 #include <string>
37 
38 #include "base/logging.hh"
41 #include "gpu-compute/shader.hh"
43 #include "gpu-compute/wavefront.hh"
44 #include "params/VectorRegisterFile.hh"
45 
46 VectorRegisterFile::VectorRegisterFile(const VectorRegisterFileParams *p)
47  : SimObject(p),
48  manager(new SimplePoolManager(p->min_alloc, p->num_regs_per_simd)),
49  simdId(p->simd_id), numRegsPerSimd(p->num_regs_per_simd),
50  vgprState(new VecRegisterState())
51 {
52  fatal_if(numRegsPerSimd % 2, "VRF size is illegal\n");
53  fatal_if(simdId < 0, "Illegal SIMD id for VRF");
54 
55  fatal_if(numRegsPerSimd % p->min_alloc, "Min VGPR region allocation is not "
56  "multiple of VRF size\n");
57 
58  busy.clear();
59  busy.resize(numRegsPerSimd, 0);
60  nxtBusy.clear();
61  nxtBusy.resize(numRegsPerSimd, 0);
62 
63  vgprState->init(numRegsPerSimd, p->wfSize);
64 }
65 
66 void
68 {
69  computeUnit = _computeUnit;
71 }
72 
73 uint8_t
74 VectorRegisterFile::regNxtBusy(int idx, uint32_t operandSize) const
75 {
76  uint8_t status = nxtBusy.at(idx);
77 
78  if (operandSize > 4) {
79  status = status | (nxtBusy.at((idx + 1) % numRegs()));
80  }
81 
82  return status;
83 }
84 
85 uint8_t
86 VectorRegisterFile::regBusy(int idx, uint32_t operandSize) const
87 {
88  uint8_t status = busy.at(idx);
89 
90  if (operandSize > 4) {
91  status = status | (busy.at((idx + 1) % numRegs()));
92  }
93 
94  return status;
95 }
96 
97 void
98 VectorRegisterFile::preMarkReg(int regIdx, uint32_t operandSize, uint8_t value)
99 {
100  nxtBusy.at(regIdx) = value;
101 
102  if (operandSize > 4) {
103  nxtBusy.at((regIdx + 1) % numRegs()) = value;
104  }
105 }
106 
107 void
108 VectorRegisterFile::markReg(int regIdx, uint32_t operandSize, uint8_t value)
109 {
110  busy.at(regIdx) = value;
111 
112  if (operandSize > 4) {
113  busy.at((regIdx + 1) % numRegs()) = value;
114  }
115 }
116 
117 bool
119 {
120  for (int i = 0; i < ii->getNumOperands(); ++i) {
121  if (ii->isVectorRegister(i)) {
122  uint32_t vgprIdx = ii->getRegisterIndex(i, ii);
123  uint32_t pVgpr = w->remap(vgprIdx, ii->getOperandSize(i), 1);
124 
125  if (regBusy(pVgpr, ii->getOperandSize(i)) == 1) {
126  if (ii->isDstOperand(i)) {
128  } else if (ii->isSrcOperand(i)) {
130  }
131 
132  return false;
133  }
134 
135  if (regNxtBusy(pVgpr, ii->getOperandSize(i)) == 1) {
136  if (ii->isDstOperand(i)) {
138  } else if (ii->isSrcOperand(i)) {
140  }
141 
142  return false;
143  }
144  }
145  }
146 
147  return true;
148 }
149 
150 void
152 {
153  bool loadInstr = ii->isLoad();
154  bool atomicInstr = ii->isAtomic() || ii->isMemFence();
155 
156  bool loadNoArgInstr = loadInstr && !ii->isArgLoad();
157 
158  // iterate over all register destination operands
159  for (int i = 0; i < ii->getNumOperands(); ++i) {
160  if (ii->isVectorRegister(i) && ii->isDstOperand(i)) {
161  uint32_t physReg = w->remap(ii->getRegisterIndex(i, ii),
162  ii->getOperandSize(i), 1);
163 
164  // mark the destination vector register as busy
165  markReg(physReg, ii->getOperandSize(i), 1);
166  // clear the in-flight status of the destination vector register
167  preMarkReg(physReg, ii->getOperandSize(i), 0);
168 
169  // FIXME: if we ever model correct timing behavior
170  // for load argument instructions then we should not
171  // set the destination register as busy now but when
172  // the data returns. Loads and Atomics should free
173  // their destination registers when the data returns,
174  // not now
175  if (!atomicInstr && !loadNoArgInstr) {
176  uint32_t pipeLen = ii->getOperandSize(i) <= 4 ?
179 
180  // schedule an event for marking the register as ready
181  computeUnit->registerEvent(w->simdId, physReg,
182  ii->getOperandSize(i),
184  computeUnit->shader->ticks(pipeLen),
185  0);
186  }
187  }
188  }
189 }
190 
191 int
192 VectorRegisterFile::exec(uint64_t dynamic_id, Wavefront *w,
193  std::vector<uint32_t> &regVec, uint32_t operandSize,
194  uint64_t timestamp)
195 {
196  int delay = 0;
197 
198  panic_if(regVec.size() <= 0, "Illegal VGPR vector size=%d\n",
199  regVec.size());
200 
201  for (int i = 0; i < regVec.size(); ++i) {
202  // mark the destination VGPR as free when the timestamp expires
203  computeUnit->registerEvent(w->simdId, regVec[i], operandSize,
204  computeUnit->shader->tick_cnt + timestamp +
205  computeUnit->shader->ticks(delay), 0);
206  }
207 
208  return delay;
209 }
210 
211 void
213 {
214  // iterate over all register destination operands
215  for (int i = 0; i < ii->getNumOperands(); ++i) {
216  if (ii->isVectorRegister(i) && ii->isDstOperand(i)) {
217  uint32_t physReg = w->remap(ii->getRegisterIndex(i, ii),
218  ii->getOperandSize(i), 1);
219  // set the in-flight status of the destination vector register
220  preMarkReg(physReg, ii->getOperandSize(i), 1);
221  }
222  }
223 }
224 
225 bool
227  GPUDynInstPtr ii,
228  VrfAccessType accessType)
229 {
230  bool ready = true;
231 
232  return ready;
233 }
234 
235 bool
237  VrfAccessType accessType)
238 {
239  bool ready = true;
240 
241  return ready;
242 }
243 
245 VectorRegisterFileParams::create()
246 {
247  return new VectorRegisterFile(this);
248 }
void init(uint32_t _size, uint32_t wf_size)
Stats::Scalar numTimesBlockedDueRAWDependencies
Definition: wavefront.hh:290
std::vector< uint8_t > nxtBusy
Bitfield< 7 > i
bool operandsReady(Wavefront *w, GPUDynInstPtr ii) const
int dpBypassLength()
virtual void updateResources(Wavefront *w, GPUDynInstPtr ii)
int simdId
Definition: wavefront.hh:163
virtual void exec(GPUDynInstPtr ii, Wavefront *w)
void setParent(ComputeUnit *_computeUnit)
Stats::Scalar numTimesBlockedDueWAXDependencies
Definition: wavefront.hh:287
int spBypassLength()
Bitfield< 5, 0 > status
std::shared_ptr< GPUDynInst > GPUDynInstPtr
Definition: misc.hh:46
VecRegisterState * vgprState
uint8_t regBusy(int idx, uint32_t operandSize) const
virtual bool vrfOperandAccessReady(uint64_t dynamic_id, Wavefront *w, GPUDynInstPtr ii, VrfAccessType accessType)
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
Definition: logging.hh:199
Bitfield< 0 > w
void setParent(ComputeUnit *_computeUnit)
uint8_t regNxtBusy(int idx, uint32_t operandSize) const
Shader * shader
Tick ticks(int numCycles) const
Definition: shader.hh:91
void markReg(int regIdx, uint32_t operandSize, uint8_t value)
void preMarkReg(int regIdx, uint32_t operandSize, uint8_t value)
void registerEvent(uint32_t simdId, uint32_t regIdx, uint32_t operandSize, uint64_t when, uint8_t newStatus)
uint32_t remap(uint32_t vgprIndex, uint32_t size, uint8_t mode=0)
Definition: wavefront.cc:280
uint64_t tick_cnt
Definition: shader.hh:151
std::vector< uint8_t > busy
Bitfield< 0 > p
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:181
VectorRegisterFile(const VectorRegisterFileParams *p)
Abstract superclass for simulation objects.
Definition: sim_object.hh:92

Generated on Mon Jun 8 2020 15:45:11 for gem5 by doxygen 1.8.13