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

Generated on Fri Jun 9 2017 13:03:48 for gem5 by doxygen 1.8.6