gem5  v21.0.1.0
static_register_manager_policy.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 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 "config/the_gpu_isa.hh"
37 #include "debug/GPURename.hh"
41 #include "gpu-compute/shader.hh"
43 #include "gpu-compute/wavefront.hh"
44 
46 {
47 }
48 
49 void
51 {
52 }
53 
54 int
56 {
57  panic_if((vgprIndex >= w->reservedVectorRegs)
58  || (w->reservedVectorRegs < 0),
59  "VGPR index %d is out of range: VGPR range=[0,%d]",
60  vgprIndex, w->reservedVectorRegs);
61 
62  // add the offset from where the VGPRs of the wavefront have been assigned
63  int physicalVgprIndex = w->startVgprIndex + vgprIndex;
64 
65  panic_if(!((w->startVgprIndex <= physicalVgprIndex) &&
66  (w->startVgprIndex + w->reservedVectorRegs - 1)
67  >= physicalVgprIndex),
68  "Invalid VGPR index %d\n", physicalVgprIndex);
69 
70  // calculate physical VGPR index
71  return physicalVgprIndex % w->computeUnit->vrf[w->simdId]->numRegs();
72 }
73 
74 int
76 {
77  panic_if(!((sgprIndex < w->reservedScalarRegs)
78  && (w->reservedScalarRegs > 0)),
79  "SGPR index %d is out of range: SGPR range=[0,%d]\n",
80  sgprIndex, w->reservedScalarRegs);
81 
82  // add the offset from where the SGPRs of the wavefront have been assigned
83  int physicalSgprIndex = w->startSgprIndex + sgprIndex;
84 
85  panic_if(!((w->startSgprIndex <= physicalSgprIndex) &&
86  (w->startSgprIndex + w->reservedScalarRegs - 1)
87  >= physicalSgprIndex),
88  "Invalid SGPR index %d\n", physicalSgprIndex);
89 
90  // calculate physical SGPR index
91  return physicalSgprIndex % w->computeUnit->srf[w->simdId]->numRegs();
92 }
93 
94 bool
96  int demandPerWf)
97 {
98  return cu->registerManager->vrfPoolMgrs[simdId]->
99  canAllocate(nWfs, demandPerWf);
100 }
101 
102 bool
104  int demandPerWf)
105 {
106  return cu->registerManager->srfPoolMgrs[simdId]->
107  canAllocate(nWfs, demandPerWf);
108 }
109 
110 void
112  int scalarDemand)
113 {
114  uint32_t allocatedSize = 0;
115  w->startVgprIndex = cu->registerManager->vrfPoolMgrs[w->simdId]->
116  allocateRegion(vectorDemand, &allocatedSize);
117  w->reservedVectorRegs = allocatedSize;
118  cu->vectorRegsReserved[w->simdId] += w->reservedVectorRegs;
120  "VRF[%d] has been overallocated %d > %d\n",
121  w->simdId, cu->vectorRegsReserved[w->simdId],
123 
124  if (scalarDemand) {
125  w->startSgprIndex = cu->registerManager->srfPoolMgrs[w->simdId]->
126  allocateRegion(scalarDemand, &allocatedSize);
127  w->reservedScalarRegs = allocatedSize;
128  cu->scalarRegsReserved[w->simdId] += w->reservedScalarRegs;
130  "SRF[%d] has been overallocated %d > %d\n",
131  w->simdId, cu->scalarRegsReserved[w->simdId],
133  }
134 }
135 
136 void
138 {
139  // free the vector registers of the completed wavefront
140  w->computeUnit->vectorRegsReserved[w->simdId] -= w->reservedVectorRegs;
141  // free the scalar registers of the completed wavefront
142  w->computeUnit->scalarRegsReserved[w->simdId] -= w->reservedScalarRegs;
143 
144  panic_if(w->computeUnit->vectorRegsReserved[w->simdId] < 0,
145  "Freeing VRF[%d] registers left %d registers reserved\n",
146  w->simdId,
147  w->computeUnit->vectorRegsReserved[w->simdId]);
148  panic_if(w->computeUnit->scalarRegsReserved[w->simdId] < 0,
149  "Freeing SRF[%d] registers left %d registers reserved\n",
150  w->simdId,
151  w->computeUnit->scalarRegsReserved[w->simdId]);
152 
153  // Current dynamic register allocation does not handle wraparound
154  int endIndex = w->startVgprIndex + w->reservedVectorRegs;
155 
156  w->computeUnit->registerManager->vrfPoolMgrs[w->simdId]->
157  freeRegion(w->startVgprIndex, endIndex);
158 
159  // mark/pre-mark all registers are not busy
160  for (int i = 0; i < w->reservedVectorRegs; i++) {
161  uint32_t physVgprIdx = mapVgpr(w, i);
162  w->computeUnit->vrf[w->simdId]->markReg(physVgprIdx, false);
163  }
164 
165  w->reservedVectorRegs = 0;
166  w->startVgprIndex = 0;
167 
168  endIndex = w->startSgprIndex + w->reservedScalarRegs;
169  w->computeUnit->registerManager->srfPoolMgrs[w->simdId]->
170  freeRegion(w->startSgprIndex, endIndex);
171 
172  // mark/pre-mark all registers are not busy
173  for (int i = 0; i < w->reservedScalarRegs; i++) {
174  uint32_t physSgprIdx = mapSgpr(w, i);
175  w->computeUnit->srf[w->simdId]->markReg(physSgprIdx, false);
176  }
177 
178  w->reservedScalarRegs = 0;
179  w->startSgprIndex = 0;
180 }
ComputeUnit::numScalarRegsPerSimd
int numScalarRegsPerSimd
Definition: compute_unit.hh:372
StaticRegisterManagerPolicy::freeRegisters
void freeRegisters(Wavefront *w) override
Definition: static_register_manager_policy.cc:137
static_register_manager_policy.hh
shader.hh
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
compute_unit.hh
StaticRegisterManagerPolicy::mapSgpr
int mapSgpr(Wavefront *w, int sgprIndex) override
Definition: static_register_manager_policy.cc:75
ComputeUnit::registerManager
RegisterManager * registerManager
Definition: compute_unit.hh:277
wavefront.hh
StaticRegisterManagerPolicy::canAllocateSgprs
bool canAllocateSgprs(int simdId, int nWfs, int demandPerWf) override
Definition: static_register_manager_policy.cc:103
StaticRegisterManagerPolicy::StaticRegisterManagerPolicy
StaticRegisterManagerPolicy()
Definition: static_register_manager_policy.cc:45
StaticRegisterManagerPolicy::mapVgpr
int mapVgpr(Wavefront *w, int vgprIndex) override
Definition: static_register_manager_policy.cc:55
vector_register_file.hh
MipsISA::w
Bitfield< 0 > w
Definition: pra_constants.hh:278
RegisterManager::vrfPoolMgrs
std::vector< PoolManager * > vrfPoolMgrs
Definition: register_manager.hh:79
scalar_register_file.hh
StaticRegisterManagerPolicy::exec
void exec() override
Definition: static_register_manager_policy.cc:50
ComputeUnit::scalarRegsReserved
std::vector< int > scalarRegsReserved
Definition: compute_unit.hh:368
RegisterManager::srfPoolMgrs
std::vector< PoolManager * > srfPoolMgrs
Definition: register_manager.hh:78
StaticRegisterManagerPolicy::canAllocateVgprs
bool canAllocateVgprs(int simdId, int nWfs, int demandPerWf) override
Definition: static_register_manager_policy.cc:95
ComputeUnit::numVecRegsPerSimd
int numVecRegsPerSimd
Definition: compute_unit.hh:370
panic_if
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:197
Wavefront
Definition: wavefront.hh:59
RegisterManagerPolicy::cu
ComputeUnit * cu
Definition: register_manager_policy.hh:78
pool_manager.hh
ComputeUnit::vectorRegsReserved
std::vector< int > vectorRegsReserved
Definition: compute_unit.hh:366
StaticRegisterManagerPolicy::allocateRegisters
void allocateRegisters(Wavefront *w, int vectorDemand, int scalarDemand) override
Definition: static_register_manager_policy.cc:111

Generated on Tue Jun 22 2021 15:28:29 for gem5 by doxygen 1.8.17