gem5  v21.2.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
dyn_pool_manager.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 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 
33 #include "base/logging.hh"
34 #include "base/trace.hh"
35 #include "debug/GPUVRF.hh"
37 
38 namespace gem5
39 {
40 
41 // return the min number of elements that the manager can reserve given
42 // a request for "size" elements
43 uint32_t
45 {
46  fatal_if(size <= 0 || size > poolSize(), "Illegal VGPR region size=%d\n",
47  size);
48 
49  return size % minAllocation() > 0 ?
50  (minAllocation() - (size % minAllocation())) + size : size;
51 }
52 
53 std::string
55 {
56  std::string _cout;
57  uint32_t reservedEntries = 0;
58 
59  /*
60  Iterate over all elements in freeSpaceRecord, checking first element
61  of each pair to see how much space in it has been allocated already.
62  This only counts the partially allocated regions. Thus, in addition,
63  count the elements in reservedSpaceRecord.
64  */
65  auto it_free = freeSpaceRecord.begin();
66  while (it_free != freeSpaceRecord.end()) {
67  reservedEntries += it_free->first;
68  ++it_free;
69  }
70  reservedEntries += (reservedSpaceRecord * totalRegSpace);
71 
72  if (reservedEntries == 0)
73  _cout = "VRF is empty\n";
74  else {
75  _cout = "VRF reserves " + std::to_string(reservedEntries) + " VGPRs\n";
76  }
77  return _cout;
78 }
79 
80 // reset freeSpace and reservedSpace
81 void
82 DynPoolManager::resetRegion(const int & regsPerSimd){
83  totalRegSpace = regsPerSimd;
85  freeSpaceRecord.clear();
86 
87  // reset available free space
88  _totRegSpaceAvailable = regsPerSimd;
89  freeSpaceRecord.push_back(std::make_pair(0,regsPerSimd));
90 }
91 
92 bool
93 DynPoolManager::canAllocate(uint32_t numRegions, uint32_t size)
94 {
95  uint32_t actualSize = minAllocatedElements(size);
96  DPRINTF(GPUVRF,"Can Allocate %d\n",actualSize);
97  return (_totRegSpaceAvailable >= actualSize);
98 }
99 
100 uint32_t
101 DynPoolManager::allocateRegion(const uint32_t size,
102  uint32_t *reservedPoolSize)
103 {
104  uint32_t startIdx = (unsigned)-1;
105  uint32_t actualSize = minAllocatedElements(size);
106  auto it = freeSpaceRecord.begin();
107  while (it != freeSpaceRecord.end()) {
108  if (it->second >= actualSize) {
109  // assign the next block starting from here
110  startIdx = it->first;
111  _regionSize = actualSize;
112  *reservedPoolSize = actualSize;
113  _totRegSpaceAvailable -= actualSize;
114 
115  // This case sees if this chunk size is exactly equal to
116  // the size of the requested chunk. If yes, then this can't
117  // contribute to future requests and hence, should be removed
118  if (it->second == actualSize) {
119  it = freeSpaceRecord.erase(it);
120  // once entire freeSpaceRecord allocated, increment
121  // reservedSpaceRecord count
123  } else {
124  it->first += actualSize;
125  it->second -= actualSize;
126  }
127  break;
128  }
129  it++;
130  }
131  DPRINTF(GPUVRF,"totRegSpace %d allocating Register at %d and"
132  " size %d\n",_totRegSpaceAvailable,startIdx,actualSize);
133  return startIdx;
134 }
135 
136 void
137 DynPoolManager::freeRegion(uint32_t firstIdx,
138  uint32_t lastIdx)
139 {
140  // lastIdx-firstIdx should give the size of free space
141  DPRINTF(GPUVRF,"freeing Region at %d %d, size %d\n",
142  firstIdx,lastIdx,lastIdx-firstIdx);
143 
144  // Current dynamic register allocation does not handle wraparound
145  assert(firstIdx < lastIdx);
146  _totRegSpaceAvailable += lastIdx-firstIdx;
147  freeSpaceRecord.push_back(std::make_pair(firstIdx,lastIdx-firstIdx));
148  // remove corresponding entry from reservedSpaceRecord too
150 }
151 
152 uint32_t
154 {
155  bool wrapAround = (region.first > region.second);
156  if (!wrapAround) {
157  return region.second - region.first + 1;
158  } else {
159  return region.second + poolSize() - region.first + 1;
160  }
161 }
162 
163 } // namespace gem5
gem5::DynPoolManager::regionSize
uint32_t regionSize(std::pair< uint32_t, uint32_t > &region) override
Definition: dyn_pool_manager.cc:153
gem5::DynPoolManager::freeSpaceRecord
std::list< std::pair< int, int > > freeSpaceRecord
Definition: dyn_pool_manager.hh:70
gem5::DynPoolManager::totalRegSpace
int totalRegSpace
Definition: dyn_pool_manager.hh:73
sc_dt::to_string
const std::string to_string(sc_enc enc)
Definition: sc_fxdefs.cc:91
gem5::DynPoolManager::canAllocate
bool canAllocate(uint32_t numRegions, uint32_t size) override
Definition: dyn_pool_manager.cc:93
dyn_pool_manager.hh
gem5::DynPoolManager::minAllocatedElements
uint32_t minAllocatedElements(uint32_t size)
Definition: dyn_pool_manager.cc:44
gem5::DynPoolManager::resetRegion
void resetRegion(const int &regsPerSimd) override
Definition: dyn_pool_manager.cc:82
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:186
gem5::PoolManager::minAllocation
uint32_t minAllocation()
Definition: pool_manager.hh:51
gem5::DynPoolManager::_regionSize
uint32_t _regionSize
Definition: dyn_pool_manager.hh:66
gem5::DynPoolManager::allocateRegion
uint32_t allocateRegion(const uint32_t size, uint32_t *reservedPoolSize) override
Definition: dyn_pool_manager.cc:101
gem5::DynPoolManager::_totRegSpaceAvailable
uint32_t _totRegSpaceAvailable
Definition: dyn_pool_manager.hh:68
std::pair
STL pair class.
Definition: stl.hh:58
gem5::DynPoolManager::printRegion
std::string printRegion() override
Definition: dyn_pool_manager.cc:54
logging.hh
gem5::DynPoolManager::reservedSpaceRecord
int reservedSpaceRecord
Definition: dyn_pool_manager.hh:71
trace.hh
gem5::DynPoolManager::freeRegion
void freeRegion(uint32_t firstIdx, uint32_t lastIdx) override
Definition: dyn_pool_manager.cc:137
gem5::PoolManager::poolSize
uint32_t poolSize()
Definition: pool_manager.hh:60
fatal_if
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
Definition: logging.hh:226
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: tlb.cc:60

Generated on Tue Dec 21 2021 11:34:30 for gem5 by doxygen 1.8.17