gem5 v24.0.0.0
Loading...
Searching...
No Matches
register_file_cache.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023 The University of Wisconsin
3 *
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met: redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer;
10 * redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution;
13 * neither the name of the copyright holders nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
31
32#include <sstream>
33#include <string>
34
35#include "base/intmath.hh"
36#include "base/logging.hh"
37#include "debug/GPURFC.hh"
40#include "gpu-compute/shader.hh"
42#include "params/RegisterFileCache.hh"
43
44namespace gem5
45{
46
47RegisterFileCache::RegisterFileCache(const RegisterFileCacheParams &p)
48 : SimObject(p), simdId(p.simd_id), _capacity(p.cache_size)
49{
50 fatal_if(simdId < 0, "Illegal SIMD id for rfc");
51}
52
56
57void
59{
60 computeUnit = _computeUnit;
61}
62
63bool
65{
66 return (lruHash.find(regIdx) != lruHash.end());
67}
68
69std::string
71{
72 std::stringstream ss;
73 ss << "lru_order: ";
74 for (auto i=lruHead; i!=nullptr; i=i->next) {
75 if (i->prev == nullptr) {
76 ss << "reg: " << i->regIdx << " ";
77 } else {
78 ss << "reg: " << i->regIdx << " (prev: " << i->prev->regIdx<<") ";
79 }
80 if (i->next != nullptr) {
81 ss << " (next: " << i->next->regIdx<<") ";
82 }
83 }
84 ss << "\n";
85 return ss.str();
86}
87
88void
90{
91 if (_capacity == 0) {
92 return;
93 }
94 if (lruHash.find(regIdx) == lruHash.end()) {
95 if (lruHead == nullptr) {
96 DPRINTF(GPURFC, "RFC SIMD[%d] cache miss inserting physReg[%d]\n",
97 simdId, regIdx);
98 OrderedRegs *oreg = new OrderedRegs(regIdx);
99 lruHash[regIdx] = oreg;
100 lruHead = oreg;
101 lruTail = oreg;
102 return;
103 }
104
105 if (lruHash.size() >= _capacity) {
106 int val = lruTail->regIdx;
107 DPRINTF(GPURFC, "RFC SIMD[%d] cache miss inserting "
108 "physReg[%d] evicting physReg[%d]\n", simdId, regIdx, val);
109
111 lruTail->next = nullptr;
112 lruHash.erase(val);
113 } else {
114 DPRINTF(GPURFC, "RFC SIMD[%d] cache miss inserting physReg[%d]\n",
115 simdId, regIdx);
116 }
117 } else { // Exists in cache need to update
118 DPRINTF(GPURFC, "RFC SIMD[%d] cache hit physReg[%d]\n",
119 simdId, regIdx);
120
121 if (lruHead->regIdx == regIdx) {
122 return;
123 }
124 if (lruHash[regIdx]==lruTail) {
125 lruTail = lruHash[regIdx]->prev;
126 }
127 if (lruHash[regIdx]->next != nullptr) {
128 lruHash[regIdx]->next->prev = lruHash[regIdx]->prev;
129 }
130 lruHash[regIdx]->prev->next = lruHash[regIdx]->next;
131 lruHash.erase(regIdx);
132 }
133
134 OrderedRegs *oreg = new OrderedRegs(regIdx);
135 lruHash[regIdx] = oreg;
136 oreg->next = lruHead;
137 lruHead->prev = oreg;
138 lruHead = oreg;
139}
140
141void
143{
144 if (!ii->isLoad()
145 && !(ii->isAtomic() || ii->isMemSync())) {
146 Cycles delay(computeUnit->rfcLength());
147 Tick tickDelay = computeUnit->cyclesToTicks(delay);
148
149 for (const auto& dstVecOp : ii->dstVecRegOperands()) {
150 for (const auto& physIdx : dstVecOp.physIndices()) {
151 enqCacheInsertEvent(physIdx, tickDelay);
152 }
153 }
154 }
155}
156
157void
158RegisterFileCache::enqCacheInsertEvent(uint32_t regIdx, uint64_t delay)
159{
160 schedule(new MarkRegCachedEvent(this, regIdx),
161 curTick() + delay);
162}
163
164void
169
170}
#define DPRINTF(x,...)
Definition trace.hh:210
Tick cyclesToTicks(Cycles c) const
int rfcLength() const
Cycles is a wrapper class for representing cycle counts, i.e.
Definition types.hh:79
std::unordered_map< int, OrderedRegs * > lruHash
virtual void enqCacheInsertEvent(uint32_t regIdx, uint64_t delay)
RegisterFileCache(const RegisterFileCacheParams &p)
virtual std::string dumpLL() const
virtual void markRFC(int regIdx)
virtual void setParent(ComputeUnit *_computeUnit)
virtual bool inRFC(int regIdx)
virtual void waveExecuteInst(Wavefront *w, GPUDynInstPtr ii)
Abstract superclass for simulation objects.
void schedule(Event &event, Tick when)
Definition eventq.hh:1012
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
Definition logging.hh:236
Bitfield< 7 > i
Definition misc_types.hh:67
Bitfield< 21 > ss
Definition misc_types.hh:60
Bitfield< 0 > p
Bitfield< 0 > w
Bitfield< 63 > val
Definition misc.hh:804
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
std::shared_ptr< GPUDynInst > GPUDynInstPtr
Definition misc.hh:49
Tick curTick()
The universal simulation clock.
Definition cur_tick.hh:46
uint64_t Tick
Tick count type.
Definition types.hh:58

Generated on Tue Jun 18 2024 16:24:04 for gem5 by doxygen 1.11.0