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.
33 * Authors: John Kalamatianos,
37 #include "gpu-compute/global_memory_pipeline.hh"
39 #include "debug/GPUMem.hh"
40 #include "debug/GPUReg.hh"
41 #include "gpu-compute/compute_unit.hh"
42 #include "gpu-compute/gpu_dyn_inst.hh"
43 #include "gpu-compute/shader.hh"
44 #include "gpu-compute/vector_register_file.hh"
45 #include "gpu-compute/wavefront.hh"
47 GlobalMemPipeline::GlobalMemPipeline(const ComputeUnitParams
* p
) :
48 computeUnit(nullptr), gmQueueSize(p
->global_mem_queue_size
),
49 outOfOrderDataDelivery(p
->out_of_order_data_delivery
), inflightStores(0),
55 GlobalMemPipeline::init(ComputeUnit
*cu
)
58 globalMemSize
= computeUnit
->shader
->globalMemSize
;
59 _name
= computeUnit
->name() + ".GlobalMemPipeline";
63 GlobalMemPipeline::exec()
65 // apply any returned global memory operations
66 GPUDynInstPtr m
= getNextReadyResp();
68 bool accessVrf
= true;
69 Wavefront
*w
= nullptr;
71 // check the VRF to see if the operands of a load (or load component
72 // of an atomic) are accessible
73 if ((m
) && (m
->isLoad() || m
->isAtomicRet())) {
77 w
->computeUnit
->vrf
[w
->simdId
]->
78 vrfOperandAccessReady(m
->seqNum(), w
, m
, VrfAccessType::WRITE
);
81 if (m
&& m
->latency
.rdy() && computeUnit
->glbMemToVrfBus
.rdy() &&
82 accessVrf
&& m
->statusBitVector
== VectorMask(0) &&
83 (computeUnit
->shader
->coissue_return
||
84 computeUnit
->wfWait
.at(m
->pipeId
).rdy())) {
92 // Decrement outstanding register count
93 computeUnit
->shader
->ScheduleAdd(&w
->outstandingReqs
, m
->time
, -1);
95 if (m
->isStore() || m
->isAtomic()) {
96 computeUnit
->shader
->ScheduleAdd(&w
->outstandingReqsWrGm
,
100 if (m
->isLoad() || m
->isAtomic()) {
101 computeUnit
->shader
->ScheduleAdd(&w
->outstandingReqsRdGm
,
105 // Mark write bus busy for appropriate amount of time
106 computeUnit
->glbMemToVrfBus
.set(m
->time
);
107 if (!computeUnit
->shader
->coissue_return
)
108 w
->computeUnit
->wfWait
.at(m
->pipeId
).set(m
->time
);
111 // If pipeline has executed a global memory instruction
112 // execute global memory packets and issue global
113 // memory packets to DTLB
114 if (!gmIssuedRequests
.empty()) {
115 GPUDynInstPtr mp
= gmIssuedRequests
.front();
116 if (mp
->isLoad() || mp
->isAtomic()) {
117 if (inflightLoads
>= gmQueueSize
) {
122 } else if (mp
->isStore()) {
123 if (inflightStores
>= gmQueueSize
) {
132 if (!outOfOrderDataDelivery
&& !mp
->isMemFence()) {
134 * if we are not in out-of-order data delivery mode
135 * then we keep the responses sorted in program order.
136 * in order to do so we must reserve an entry in the
137 * resp buffer before we issue the request to the mem
138 * system. mem fence requests will not be stored here
139 * because once they are issued from the GM pipeline,
140 * they do not send any response back to it.
142 gmOrderedRespBuffer
.insert(std::make_pair(mp
->seqNum(),
143 std::make_pair(mp
, false)));
146 gmIssuedRequests
.pop();
148 DPRINTF(GPUMem
, "CU%d: WF[%d][%d] Popping 0 mem_op = \n",
149 computeUnit
->cu_id
, mp
->simdId
, mp
->wfSlotId
);
154 GlobalMemPipeline::getNextReadyResp()
156 if (outOfOrderDataDelivery
) {
157 if (!gmReturnedLoads
.empty()) {
158 return gmReturnedLoads
.front();
159 } else if (!gmReturnedStores
.empty()) {
160 return gmReturnedStores
.front();
163 if (!gmOrderedRespBuffer
.empty()) {
164 auto mem_req
= gmOrderedRespBuffer
.begin();
166 if (mem_req
->second
.second
) {
167 return mem_req
->second
.first
;
176 GlobalMemPipeline::completeRequest(GPUDynInstPtr gpuDynInst
)
178 if (gpuDynInst
->isLoad() || gpuDynInst
->isAtomic()) {
179 assert(inflightLoads
> 0);
181 } else if (gpuDynInst
->isStore()) {
182 assert(inflightStores
> 0);
186 if (outOfOrderDataDelivery
) {
187 if (gpuDynInst
->isLoad() || gpuDynInst
->isAtomic()) {
188 assert(!gmReturnedLoads
.empty());
189 gmReturnedLoads
.pop();
190 } else if (gpuDynInst
->isStore()) {
191 assert(!gmReturnedStores
.empty());
192 gmReturnedStores
.pop();
195 // we should only pop the oldest requst, and it
196 // should be marked as done if we are here
197 assert(gmOrderedRespBuffer
.begin()->first
== gpuDynInst
->seqNum());
198 assert(gmOrderedRespBuffer
.begin()->second
.first
== gpuDynInst
);
199 assert(gmOrderedRespBuffer
.begin()->second
.second
);
200 // remove this instruction from the buffer by its
202 gmOrderedRespBuffer
.erase(gpuDynInst
->seqNum());
207 GlobalMemPipeline::issueRequest(GPUDynInstPtr gpuDynInst
)
209 gmIssuedRequests
.push(gpuDynInst
);
213 GlobalMemPipeline::handleResponse(GPUDynInstPtr gpuDynInst
)
215 if (outOfOrderDataDelivery
) {
216 if (gpuDynInst
->isLoad() || gpuDynInst
->isAtomic()) {
217 assert(isGMLdRespFIFOWrRdy());
218 gmReturnedLoads
.push(gpuDynInst
);
220 assert(isGMStRespFIFOWrRdy());
221 gmReturnedStores
.push(gpuDynInst
);
224 auto mem_req
= gmOrderedRespBuffer
.find(gpuDynInst
->seqNum());
225 // if we are getting a response for this mem request,
226 // then it ought to already be in the ordered response
228 assert(mem_req
!= gmOrderedRespBuffer
.end());
229 mem_req
->second
.second
= true;
234 GlobalMemPipeline::regStats()
236 loadVrfBankConflictCycles
237 .name(name() + ".load_vrf_bank_conflict_cycles")
238 .desc("total number of cycles GM data are delayed before updating "