arch,cpu,mem: Replace the mmmapped IPR mechanism with local accesses.
[gem5.git] / src / gpu-compute / scoreboard_check_stage.cc
1 /*
2 * Copyright (c) 2014-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
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
34 #include "gpu-compute/scoreboard_check_stage.hh"
35
36 #include "gpu-compute/compute_unit.hh"
37 #include "gpu-compute/gpu_static_inst.hh"
38 #include "gpu-compute/shader.hh"
39 #include "gpu-compute/wavefront.hh"
40 #include "params/ComputeUnit.hh"
41
42 ScoreboardCheckStage::ScoreboardCheckStage(const ComputeUnitParams *p)
43 : numSIMDs(p->num_SIMDs),
44 numMemUnits(p->num_global_mem_pipes + p->num_shared_mem_pipes),
45 numShrMemPipes(p->num_shared_mem_pipes),
46 vectorAluInstAvail(nullptr),
47 lastGlbMemSimd(-1),
48 lastShrMemSimd(-1), glbMemInstAvail(nullptr),
49 shrMemInstAvail(nullptr)
50 {
51 }
52
53 ScoreboardCheckStage::~ScoreboardCheckStage()
54 {
55 readyList.clear();
56 waveStatusList.clear();
57 shrMemInstAvail = nullptr;
58 glbMemInstAvail = nullptr;
59 }
60
61 void
62 ScoreboardCheckStage::init(ComputeUnit *cu)
63 {
64 computeUnit = cu;
65 _name = computeUnit->name() + ".ScoreboardCheckStage";
66
67 for (int unitId = 0; unitId < numSIMDs + numMemUnits; ++unitId) {
68 readyList.push_back(&computeUnit->readyList[unitId]);
69 }
70
71 for (int unitId = 0; unitId < numSIMDs; ++unitId) {
72 waveStatusList.push_back(&computeUnit->waveStatusList[unitId]);
73 }
74
75 vectorAluInstAvail = &computeUnit->vectorAluInstAvail;
76 glbMemInstAvail= &computeUnit->glbMemInstAvail;
77 shrMemInstAvail= &computeUnit->shrMemInstAvail;
78 }
79
80 void
81 ScoreboardCheckStage::initStatistics()
82 {
83 lastGlbMemSimd = -1;
84 lastShrMemSimd = -1;
85 *glbMemInstAvail = 0;
86 *shrMemInstAvail = 0;
87
88 for (int unitId = 0; unitId < numSIMDs; ++unitId)
89 vectorAluInstAvail->at(unitId) = false;
90 }
91
92 void
93 ScoreboardCheckStage::collectStatistics(Wavefront *curWave, int unitId)
94 {
95 if (curWave->instructionBuffer.empty())
96 return;
97
98 // track which vector SIMD unit has at least one WV with a vector
99 // ALU as the oldest instruction in its Instruction buffer
100 vectorAluInstAvail->at(unitId) = vectorAluInstAvail->at(unitId) ||
101 curWave->isOldestInstALU();
102
103 // track how many vector SIMD units have at least one WV with a
104 // vector Global memory instruction as the oldest instruction
105 // in its Instruction buffer
106 if ((curWave->isOldestInstGMem() || curWave->isOldestInstPrivMem() ||
107 curWave->isOldestInstFlatMem()) && lastGlbMemSimd != unitId &&
108 *glbMemInstAvail <= 1) {
109 (*glbMemInstAvail)++;
110 lastGlbMemSimd = unitId;
111 }
112
113 // track how many vector SIMD units have at least one WV with a
114 // vector shared memory (LDS) instruction as the oldest instruction
115 // in its Instruction buffer
116 // TODO: parametrize the limit of the LDS units
117 if (curWave->isOldestInstLMem() && (*shrMemInstAvail <= numShrMemPipes) &&
118 lastShrMemSimd != unitId) {
119 (*shrMemInstAvail)++;
120 lastShrMemSimd = unitId;
121 }
122 }
123
124 void
125 ScoreboardCheckStage::exec()
126 {
127 initStatistics();
128
129 // reset the ready list for all execution units; it will be
130 // constructed every cycle since resource availability may change
131 for (int unitId = 0; unitId < numSIMDs + numMemUnits; ++unitId) {
132 readyList[unitId]->clear();
133 }
134
135 // iterate over the Wavefronts of all SIMD units
136 for (int unitId = 0; unitId < numSIMDs; ++unitId) {
137 for (int wvId = 0; wvId < computeUnit->shader->n_wf; ++wvId) {
138 // reset the ready status of each wavefront
139 waveStatusList[unitId]->at(wvId).second = BLOCKED;
140 Wavefront *curWave = waveStatusList[unitId]->at(wvId).first;
141 collectStatistics(curWave, unitId);
142
143 if (curWave->ready(Wavefront::I_ALU)) {
144 readyList[unitId]->push_back(curWave);
145 waveStatusList[unitId]->at(wvId).second = READY;
146 } else if (curWave->ready(Wavefront::I_GLOBAL)) {
147 if (computeUnit->cedeSIMD(unitId, wvId)) {
148 continue;
149 }
150
151 readyList[computeUnit->GlbMemUnitId()]->push_back(curWave);
152 waveStatusList[unitId]->at(wvId).second = READY;
153 } else if (curWave->ready(Wavefront::I_SHARED)) {
154 readyList[computeUnit->ShrMemUnitId()]->push_back(curWave);
155 waveStatusList[unitId]->at(wvId).second = READY;
156 } else if (curWave->ready(Wavefront::I_FLAT)) {
157 readyList[computeUnit->GlbMemUnitId()]->push_back(curWave);
158 waveStatusList[unitId]->at(wvId).second = READY;
159 } else if (curWave->ready(Wavefront::I_PRIVATE)) {
160 readyList[computeUnit->GlbMemUnitId()]->push_back(curWave);
161 waveStatusList[unitId]->at(wvId).second = READY;
162 }
163 }
164 }
165 }
166
167 void
168 ScoreboardCheckStage::regStats()
169 {
170 }