2 * Copyright (c) 2014-2015 Advanced Micro Devices, Inc.
5 * For use for simulation and test purposes only
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
10 * 1. Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
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.
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.
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.
34 #include "gpu-compute/scoreboard_check_stage.hh"
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"
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),
48 lastShrMemSimd(-1), glbMemInstAvail(nullptr),
49 shrMemInstAvail(nullptr)
53 ScoreboardCheckStage::~ScoreboardCheckStage()
56 waveStatusList
.clear();
57 shrMemInstAvail
= nullptr;
58 glbMemInstAvail
= nullptr;
62 ScoreboardCheckStage::init(ComputeUnit
*cu
)
65 _name
= computeUnit
->name() + ".ScoreboardCheckStage";
67 for (int unitId
= 0; unitId
< numSIMDs
+ numMemUnits
; ++unitId
) {
68 readyList
.push_back(&computeUnit
->readyList
[unitId
]);
71 for (int unitId
= 0; unitId
< numSIMDs
; ++unitId
) {
72 waveStatusList
.push_back(&computeUnit
->waveStatusList
[unitId
]);
75 vectorAluInstAvail
= &computeUnit
->vectorAluInstAvail
;
76 glbMemInstAvail
= &computeUnit
->glbMemInstAvail
;
77 shrMemInstAvail
= &computeUnit
->shrMemInstAvail
;
81 ScoreboardCheckStage::initStatistics()
88 for (int unitId
= 0; unitId
< numSIMDs
; ++unitId
)
89 vectorAluInstAvail
->at(unitId
) = false;
93 ScoreboardCheckStage::collectStatistics(Wavefront
*curWave
, int unitId
)
95 if (curWave
->instructionBuffer
.empty())
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();
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
;
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
;
125 ScoreboardCheckStage::exec()
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();
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
);
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
)) {
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
;
168 ScoreboardCheckStage::regStats()