gem5  v21.0.1.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
exec_stage.cc
Go to the documentation of this file.
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 
35 
36 #include <sstream>
37 
38 #include "base/trace.hh"
39 #include "debug/GPUSched.hh"
42 #include "gpu-compute/wavefront.hh"
43 
44 ExecStage::ExecStage(const ComputeUnitParams &p, ComputeUnit &cu,
45  ScheduleToExecute &from_schedule)
46  : computeUnit(cu), fromSchedule(from_schedule),
47  lastTimeInstExecuted(false),
48  thisTimeInstExecuted(false), instrExecuted (false),
49  executionResourcesUsed(0), _name(cu.name() + ".ExecStage"),
50  stats(&cu)
51 
52 {
54  idle_dur = 0;
55 }
56 
57 void
59 {
60  idle_dur = 0;
61 }
62 
63 void
64 ExecStage::collectStatistics(enum STAT_STATUS stage, int unitId) {
65  if (stage == IdleExec) {
66  // count cycles when no instruction to a specific execution resource
67  // is executed
69  } else if (stage == BusyExec) {
70  // count the number of cycles an instruction to a specific execution
71  // resource type was issued
73  thisTimeInstExecuted = true;
74  instrExecuted = true;
76  } else if (stage == PostExec) {
77  // count the number of transitions from active to idle
80  }
81 
84  idle_dur = 0;
85  } else if (!thisTimeInstExecuted) {
86  idle_dur++;
87  }
88 
90  // track the number of cycles we either issued at least
91  // instruction or issued no instructions at all
92  if (instrExecuted) {
94  } else {
96  }
98  }
99 }
100 
101 void
103 {
104  instrExecuted = false;
106  thisTimeInstExecuted = false;
107 }
108 
109 std::string
111 {
112  std::string s("INVALID");
113  switch (i) {
114  case EMPTY:
115  s = "EMPTY";
116  break;
117  case SKIP:
118  s = "SKIP";
119  break;
120  case EXREADY:
121  s = "EXREADY";
122  break;
123  }
124  return s;
125 }
126 
127 void
129 {
130  std::stringstream ss;
131  bool empty = true;
132  for (int i = 0; i < computeUnit.numExeUnits(); i++) {
134  ss << i << ": " << dispStatusToStr(s);
135  if (s != EMPTY) {
136  empty = false;
137  GPUDynInstPtr &gpu_dyn_inst = fromSchedule.readyInst(i);
138  Wavefront *wf = gpu_dyn_inst->wavefront();
139  ss << " SIMD[" << wf->simdId << "] WV[" << wf->wfDynId << "]: ";
140  ss << (wf->instructionBuffer.front())->seqNum() << ": ";
141  ss << (wf->instructionBuffer.front())->disassemble();
142  }
143  ss << "\n";
144  }
145  if (!empty) {
146  DPRINTF(GPUSched, "Dispatch List:\n%s", ss.str());
147  }
148 }
149 
150 void
152 {
153  initStatistics();
154  if (Debug::GPUSched) {
155  dumpDispList();
156  }
157  for (int unitId = 0; unitId < computeUnit.numExeUnits(); ++unitId) {
159  switch (s) {
160  case EMPTY:
161  // Do not execute if empty, waiting for VRF reads,
162  // or LM tied to GM waiting for VRF reads
163  collectStatistics(IdleExec, unitId);
164  break;
165  case EXREADY:
166  {
167  collectStatistics(BusyExec, unitId);
168  GPUDynInstPtr &gpu_dyn_inst = fromSchedule.readyInst(unitId);
169  assert(gpu_dyn_inst);
170  Wavefront *wf = gpu_dyn_inst->wavefront();
171  DPRINTF(GPUSched, "Exec[%d]: SIMD[%d] WV[%d]: %s\n",
172  unitId, wf->simdId, wf->wfDynId,
173  gpu_dyn_inst->disassemble());
174  DPRINTF(GPUSched, "dispatchList[%d] EXREADY->EMPTY\n", unitId);
175  wf->exec();
176  (computeUnit.scheduleStage).deleteFromSch(wf);
178  wf->freeResources();
179  break;
180  }
181  case SKIP:
182  {
183  collectStatistics(BusyExec, unitId);
184  GPUDynInstPtr &gpu_dyn_inst = fromSchedule.readyInst(unitId);
185  assert(gpu_dyn_inst);
186  Wavefront *wf = gpu_dyn_inst->wavefront();
187  DPRINTF(GPUSched, "dispatchList[%d] SKIP->EMPTY\n", unitId);
189  wf->freeResources();
190  break;
191  }
192  default:
193  panic("Unknown dispatch status in exec()\n");
194  }
195  }
196 
198 }
199 
201  : Stats::Group(parent, "ExecStage"),
202  ADD_STAT(numTransActiveIdle,
203  "number of CU transitions from active to idle"),
204  ADD_STAT(numCyclesWithNoIssue, "number of cycles the CU issues nothing"),
205  ADD_STAT(numCyclesWithInstrIssued,
206  "number of cycles the CU issued at least one instruction"),
207  ADD_STAT(spc,
208  "Execution units active per cycle (Exec unit=SIMD,MemPipe)"),
209  ADD_STAT(idleDur, "duration of idle periods in cycles"),
210  ADD_STAT(numCyclesWithInstrTypeIssued, "Number of cycles at least one "
211  "instruction issued to execution resource type"),
212  ADD_STAT(numCyclesWithNoInstrTypeIssued, "Number of clks no instructions"
213  " issued to execution resource type")
214 {
215  ComputeUnit *compute_unit = static_cast<ComputeUnit*>(parent);
216 
217  spc.init(0, compute_unit->numExeUnits(), 1);
218  idleDur.init(0, 75, 5);
221 
222  int c = 0;
223  for (int i = 0; i < compute_unit->numVectorALUs; i++,c++) {
224  std::string s = "VectorALU" + std::to_string(i);
227  }
228  for (int i = 0; i < compute_unit->numScalarALUs; i++,c++) {
229  std::string s = "ScalarALU" + std::to_string(i);
232  }
233  numCyclesWithNoInstrTypeIssued.subname(c, "VectorMemPipe");
234  numCyclesWithInstrTypeIssued.subname(c++, "VectorMemPipe");
235 
236  numCyclesWithNoInstrTypeIssued.subname(c, "SharedMemPipe");
237  numCyclesWithInstrTypeIssued.subname(c++, "SharedMemPipe");
238 }
STAT_STATUS
STAT_STATUS
Definition: exec_stage.hh:51
ExecStage::thisTimeInstExecuted
bool thisTimeInstExecuted
Definition: exec_stage.hh:93
ExecStage::collectStatistics
void collectStatistics(enum STAT_STATUS stage, int unitId)
Definition: exec_stage.cc:64
EMPTY
@ EMPTY
Definition: exec_stage.hh:60
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
ExecStage::idle_dur
uint64_t idle_dur
Definition: exec_stage.hh:96
ScheduleToExecute::readyInst
GPUDynInstPtr & readyInst(int func_unit_id)
Definition: comm.cc:126
compute_unit.hh
ExecStage::dispStatusToStr
std::string dispStatusToStr(int j)
Definition: exec_stage.cc:110
sc_dt::to_string
const std::string to_string(sc_enc enc)
Definition: sc_fxdefs.cc:91
ExecStage::init
void init()
Definition: exec_stage.cc:58
ExecStage::exec
void exec()
Definition: exec_stage.cc:151
ExecStage::initStatistics
void initStatistics()
Definition: exec_stage.cc:102
ComputeUnit::numExeUnits
int numExeUnits() const
Definition: compute_unit.cc:229
ScheduleToExecute::dispatchStatus
DISPATCH_STATUS dispatchStatus(int func_unit_id) const
Definition: comm.cc:149
ExecStage::ExecStageStats::spc
Stats::Distribution spc
Definition: exec_stage.hh:111
ComputeUnit::scheduleStage
ScheduleStage scheduleStage
Definition: compute_unit.hh:281
wavefront.hh
ExecStage::lastTimeInstExecuted
bool lastTimeInstExecuted
Definition: exec_stage.hh:92
SKIP
@ SKIP
Definition: exec_stage.hh:62
ComputeUnit
Definition: compute_unit.hh:200
vector_register_file.hh
ScheduleToExecute::dispatchTransition
void dispatchTransition(const GPUDynInstPtr &gpu_dyn_inst, int func_unit_id, DISPATCH_STATUS disp_status)
Once the scheduler has chosen a winning WF for execution, and after the WF's oldest instruction's ope...
Definition: comm.cc:132
ArmISA::ss
Bitfield< 21 > ss
Definition: miscregs_types.hh:56
Wavefront::exec
void exec()
Definition: wavefront.cc:861
ScheduleToExecute
Communication interface between Schedule and Execute stages.
Definition: comm.hh:97
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:237
Wavefront::freeResources
void freeResources()
Definition: wavefront.cc:740
ADD_STAT
#define ADD_STAT(n,...)
Convenience macro to add a stat to a statistics group.
Definition: group.hh:71
ExecStage::ExecStageStats::numCyclesWithNoIssue
Stats::Scalar numCyclesWithNoIssue
Definition: exec_stage.hh:107
ExecStage::ExecStageStats::ExecStageStats
ExecStageStats(Stats::Group *parent)
Definition: exec_stage.cc:200
ExecStage::ExecStageStats::numCyclesWithInstrIssued
Stats::Scalar numCyclesWithInstrIssued
Definition: exec_stage.hh:109
BusyExec
@ BusyExec
Definition: exec_stage.hh:54
Wavefront::simdId
const int simdId
Definition: wavefront.hh:97
ExecStage::fromSchedule
ScheduleToExecute & fromSchedule
Definition: exec_stage.hh:90
EXREADY
@ EXREADY
Definition: exec_stage.hh:61
name
const std::string & name()
Definition: trace.cc:48
Stats::VectorBase::init
Derived & init(size_type size)
Set this vector to have the given size.
Definition: statistics.hh:1028
ExecStage::executionResourcesUsed
int executionResourcesUsed
Definition: exec_stage.hh:95
IdleExec
@ IdleExec
Definition: exec_stage.hh:53
Stats::Distribution::init
Distribution & init(Counter min, Counter max, Counter bkt)
Set the parameters of this distribution.
Definition: statistics.hh:2113
Wavefront
Definition: wavefront.hh:59
Stats::Group
Statistics container.
Definition: group.hh:87
PostExec
@ PostExec
Definition: exec_stage.hh:55
ExecStage::ExecStageStats::numCyclesWithInstrTypeIssued
Stats::Vector numCyclesWithInstrTypeIssued
Definition: exec_stage.hh:116
GPUDynInstPtr
std::shared_ptr< GPUDynInst > GPUDynInstPtr
Definition: misc.hh:48
Stats::DistBase::sample
void sample(const U &v, int n=1)
Add a value to the distribtion n times.
Definition: statistics.hh:1323
ExecStage::ExecStageStats::numCyclesWithNoInstrTypeIssued
Stats::Vector numCyclesWithNoInstrTypeIssued
Definition: exec_stage.hh:120
ExecStage::ExecStageStats::numTransActiveIdle
Stats::Scalar numTransActiveIdle
Definition: exec_stage.hh:105
ExecStage::ExecStage
ExecStage(const ComputeUnitParams &p, ComputeUnit &cu, ScheduleToExecute &from_schedule)
Definition: exec_stage.cc:44
Wavefront::instructionBuffer
std::deque< GPUDynInstPtr > instructionBuffer
Definition: wavefront.hh:107
Stats::DataWrapVec::subname
Derived & subname(off_type index, const std::string &name)
Set the subfield name for the given index, and marks this stat to print at the end of simulation.
Definition: statistics.hh:383
ExecStage::instrExecuted
bool instrExecuted
Definition: exec_stage.hh:94
ArmISA::c
Bitfield< 29 > c
Definition: miscregs_types.hh:50
Stats
Definition: statistics.cc:53
trace.hh
ExecStage::dumpDispList
void dumpDispList()
Definition: exec_stage.cc:128
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
ArmISA::s
Bitfield< 4 > s
Definition: miscregs_types.hh:556
DISPATCH_STATUS
DISPATCH_STATUS
Definition: exec_stage.hh:58
ExecStage::stats
ExecStage::ExecStageStats stats
ExecStage::computeUnit
ComputeUnit & computeUnit
Definition: exec_stage.hh:89
exec_stage.hh
Wavefront::wfDynId
uint64_t wfDynId
Definition: wavefront.hh:224
ComputeUnit::numScalarALUs
int numScalarALUs
Definition: compute_unit.hh:247
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:171
ComputeUnit::numVectorALUs
int numVectorALUs
Definition: compute_unit.hh:243
ExecStage::ExecStageStats::idleDur
Stats::Distribution idleDur
Definition: exec_stage.hh:113

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