gem5  v21.0.1.0
gpu_mem_helpers.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 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 #ifndef __ARCH_GCN3_GPU_MEM_HELPERS_HH__
35 #define __ARCH_GCN3_GPU_MEM_HELPERS_HH__
36 
39 #include "debug/GPUMem.hh"
41 
48 template<typename T, int N>
49 inline void
50 initMemReqHelper(GPUDynInstPtr gpuDynInst, MemCmd mem_req_type,
51  bool is_atomic=false)
52 {
53  // local variables
54  int req_size = N * sizeof(T);
55  int block_size = gpuDynInst->computeUnit()->cacheLineSize();
56  Addr vaddr = 0, split_addr = 0;
57  bool misaligned_acc = false;
58  RequestPtr req = nullptr, req1 = nullptr, req2 = nullptr;
59  PacketPtr pkt = nullptr, pkt1 = nullptr, pkt2 = nullptr;
60 
61  gpuDynInst->resetEntireStatusVector();
62  for (int lane = 0; lane < Gcn3ISA::NumVecElemPerVecReg; ++lane) {
63  if (gpuDynInst->exec_mask[lane]) {
64  vaddr = gpuDynInst->addr[lane];
65 
70  split_addr = roundDown(vaddr + req_size - 1, block_size);
71 
72  assert(split_addr <= vaddr || split_addr - vaddr < block_size);
78  misaligned_acc = split_addr > vaddr;
79 
80  if (is_atomic) {
81  // make sure request is word aligned
82  assert((vaddr & 0x3) == 0);
83 
84  // a given lane's atomic can't cross cache lines
85  assert(!misaligned_acc);
86 
87  req = std::make_shared<Request>(vaddr, sizeof(T), 0,
88  gpuDynInst->computeUnit()->requestorId(), 0,
89  gpuDynInst->wfDynId,
90  gpuDynInst->makeAtomicOpFunctor<T>(
91  &(reinterpret_cast<T*>(gpuDynInst->a_data))[lane],
92  &(reinterpret_cast<T*>(gpuDynInst->x_data))[lane]));
93  } else {
94  req = std::make_shared<Request>(vaddr, req_size, 0,
95  gpuDynInst->computeUnit()->requestorId(), 0,
96  gpuDynInst->wfDynId);
97  }
98 
99  if (misaligned_acc) {
100  gpuDynInst->setStatusVector(lane, 2);
101  req->splitOnVaddr(split_addr, req1, req2);
102  gpuDynInst->setRequestFlags(req1);
103  gpuDynInst->setRequestFlags(req2);
104  pkt1 = new Packet(req1, mem_req_type);
105  pkt2 = new Packet(req2, mem_req_type);
106  pkt1->dataStatic(&(reinterpret_cast<T*>(
107  gpuDynInst->d_data))[lane * N]);
108  pkt2->dataStatic(&(reinterpret_cast<T*>(
109  gpuDynInst->d_data))[lane * N + req1->getSize()]);
110  DPRINTF(GPUMem, "CU%d: WF[%d][%d]: index: %d unaligned memory "
111  "request for %#x\n", gpuDynInst->cu_id,
112  gpuDynInst->simdId, gpuDynInst->wfSlotId, lane,
113  split_addr);
114  gpuDynInst->computeUnit()->sendRequest(gpuDynInst, lane, pkt1);
115  gpuDynInst->computeUnit()->sendRequest(gpuDynInst, lane, pkt2);
116  } else {
117  gpuDynInst->setStatusVector(lane, 1);
118  gpuDynInst->setRequestFlags(req);
119  pkt = new Packet(req, mem_req_type);
120  pkt->dataStatic(&(reinterpret_cast<T*>(
121  gpuDynInst->d_data))[lane * N]);
122  gpuDynInst->computeUnit()->sendRequest(gpuDynInst, lane, pkt);
123  }
124  } else { // if lane is not active, then no pending requests
125  gpuDynInst->setStatusVector(lane, 0);
126  }
127  }
128 }
129 
136 template<typename T, int N>
137 inline void
138 initMemReqScalarHelper(GPUDynInstPtr gpuDynInst, MemCmd mem_req_type)
139 {
140  int req_size = N * sizeof(T);
141  int block_size = gpuDynInst->computeUnit()->cacheLineSize();
142  Addr vaddr = gpuDynInst->scalarAddr;
143 
148  Addr split_addr = roundDown(vaddr + req_size - 1, block_size);
149 
150  assert(split_addr <= vaddr || split_addr - vaddr < block_size);
156  bool misaligned_acc = split_addr > vaddr;
157 
158  RequestPtr req = std::make_shared<Request>(vaddr, req_size, 0,
159  gpuDynInst->computeUnit()->requestorId(), 0,
160  gpuDynInst->wfDynId);
161 
162  if (misaligned_acc) {
163  RequestPtr req1, req2;
164  req->splitOnVaddr(split_addr, req1, req2);
165  gpuDynInst->numScalarReqs = 2;
166  gpuDynInst->setRequestFlags(req1);
167  gpuDynInst->setRequestFlags(req2);
168  PacketPtr pkt1 = new Packet(req1, mem_req_type);
169  PacketPtr pkt2 = new Packet(req2, mem_req_type);
170  pkt1->dataStatic(gpuDynInst->scalar_data);
171  pkt2->dataStatic(gpuDynInst->scalar_data + req1->getSize());
172  DPRINTF(GPUMem, "CU%d: WF[%d][%d]: unaligned scalar memory request for"
173  " %#x\n", gpuDynInst->cu_id, gpuDynInst->simdId,
174  gpuDynInst->wfSlotId, split_addr);
175  gpuDynInst->computeUnit()->sendScalarRequest(gpuDynInst, pkt1);
176  gpuDynInst->computeUnit()->sendScalarRequest(gpuDynInst, pkt2);
177  } else {
178  gpuDynInst->numScalarReqs = 1;
179  gpuDynInst->setRequestFlags(req);
180  PacketPtr pkt = new Packet(req, mem_req_type);
181  pkt->dataStatic(gpuDynInst->scalar_data);
182  gpuDynInst->computeUnit()->sendScalarRequest(gpuDynInst, pkt);
183  }
184 }
185 
186 #endif // __ARCH_GCN3_GPU_MEM_HELPERS_HH__
Gcn3ISA::NumVecElemPerVecReg
const int NumVecElemPerVecReg(64)
roundDown
T roundDown(const T &val, const U &align)
This function is used to align addresses in memory.
Definition: intmath.hh:150
op_encodings.hh
initMemReqHelper
void initMemReqHelper(GPUDynInstPtr gpuDynInst, MemCmd mem_req_type, bool is_atomic=false)
Helper function for instructions declared in op_encodings.
Definition: gpu_mem_helpers.hh:50
RequestPtr
std::shared_ptr< Request > RequestPtr
Definition: request.hh:86
gpu_static_inst.hh
initMemReqScalarHelper
void initMemReqScalarHelper(GPUDynInstPtr gpuDynInst, MemCmd mem_req_type)
Helper function for scalar instructions declared in op_encodings.
Definition: gpu_mem_helpers.hh:138
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:237
MemCmd
Definition: packet.hh:72
MipsISA::vaddr
vaddr
Definition: pra_constants.hh:275
gpu_dyn_inst.hh
ProbePoints::Packet
ProbePointArg< PacketInfo > Packet
Packet probe point.
Definition: mem.hh:103
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:148
Packet::dataStatic
void dataStatic(T *p)
Set the data pointer to the following value that should not be freed.
Definition: packet.hh:1108
Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:258
GPUDynInstPtr
std::shared_ptr< GPUDynInst > GPUDynInstPtr
Definition: misc.hh:48

Generated on Tue Jun 22 2021 15:28:21 for gem5 by doxygen 1.8.17