From 0c5d671ea12b94f78975d881f72a715dca6516cb Mon Sep 17 00:00:00 2001 From: Tony Gutierrez Date: Fri, 29 Jun 2018 16:06:36 -0400 Subject: [PATCH] gpu-compute: Init CU object for pipe stages in their ctors This change updates the constructors of the CU's pipe stages/memory pipelines to accept a pointer to their parent CU. Because the CU creates these objects, and can pass a pointer to itself to these object via their constructors, this is the safer way to initalize these classes. Change-Id: I0b3732ce7c03781ee15332dac7a21c097ad387a4 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/29945 Reviewed-by: Anthony Gutierrez Maintainer: Anthony Gutierrez Tested-by: kokoro --- src/gpu-compute/compute_unit.cc | 23 +++++++++++++---------- src/gpu-compute/exec_stage.cc | 12 ++++++------ src/gpu-compute/exec_stage.hh | 4 ++-- src/gpu-compute/fetch_stage.cc | 14 ++++++-------- src/gpu-compute/fetch_stage.hh | 4 ++-- src/gpu-compute/fetch_unit.cc | 9 ++++----- src/gpu-compute/fetch_unit.hh | 4 ++-- src/gpu-compute/global_memory_pipeline.cc | 14 +++++++------- src/gpu-compute/global_memory_pipeline.hh | 4 ++-- src/gpu-compute/local_memory_pipeline.cc | 12 +++--------- src/gpu-compute/local_memory_pipeline.hh | 3 +-- src/gpu-compute/scalar_memory_pipeline.cc | 15 +++++---------- src/gpu-compute/scalar_memory_pipeline.hh | 3 +-- src/gpu-compute/schedule_stage.cc | 7 +++---- src/gpu-compute/schedule_stage.hh | 4 ++-- src/gpu-compute/scoreboard_check_stage.cc | 9 ++++----- src/gpu-compute/scoreboard_check_stage.hh | 4 ++-- 17 files changed, 65 insertions(+), 80 deletions(-) diff --git a/src/gpu-compute/compute_unit.cc b/src/gpu-compute/compute_unit.cc index 0fcbb1ac6..f3387a7b7 100644 --- a/src/gpu-compute/compute_unit.cc +++ b/src/gpu-compute/compute_unit.cc @@ -66,9 +66,14 @@ ComputeUnit::ComputeUnit(const Params *p) : ClockedObject(p), numScalarALUs(p->num_scalar_cores), vrfToCoalescerBusWidth(p->vrf_to_coalescer_bus_width), coalescerToVrfBusWidth(p->coalescer_to_vrf_bus_width), - registerManager(p->register_manager), fetchStage(p), - scoreboardCheckStage(p), scheduleStage(p, this), execStage(p), - globalMemoryPipe(p), localMemoryPipe(p), scalarMemoryPipe(p), + registerManager(p->register_manager), + fetchStage(p, this), + scoreboardCheckStage(p, this), + scheduleStage(p, this), + execStage(p, this), + globalMemoryPipe(p, this), + localMemoryPipe(p, this), + scalarMemoryPipe(p, this), tickEvent([this]{ exec(); }, "Compute unit tick event", false, Event::CPU_Tick_Pri), cu_id(p->cu_id), @@ -788,13 +793,11 @@ ComputeUnit::init() dispatchList.push_back(std::make_pair(nullptr, EMPTY)); } - fetchStage.init(this); - scoreboardCheckStage.init(this); - scheduleStage.init(this); - execStage.init(this); - globalMemoryPipe.init(this); - localMemoryPipe.init(this); - scalarMemoryPipe.init(this); + fetchStage.init(); + scoreboardCheckStage.init(); + scheduleStage.init(); + execStage.init(); + globalMemoryPipe.init(); gmTokenPort.setTokenManager(memPortTokens); } diff --git a/src/gpu-compute/exec_stage.cc b/src/gpu-compute/exec_stage.cc index 2dece180b..e420579c9 100644 --- a/src/gpu-compute/exec_stage.cc +++ b/src/gpu-compute/exec_stage.cc @@ -41,19 +41,19 @@ #include "gpu-compute/vector_register_file.hh" #include "gpu-compute/wavefront.hh" -ExecStage::ExecStage(const ComputeUnitParams *p) : lastTimeInstExecuted(false), - thisTimeInstExecuted(false), instrExecuted (false), - executionResourcesUsed(0) +ExecStage::ExecStage(const ComputeUnitParams *p, ComputeUnit *cu) + : computeUnit(cu), lastTimeInstExecuted(false), + thisTimeInstExecuted(false), instrExecuted (false), + executionResourcesUsed(0), _name(cu->name() + ".ExecStage") + { numTransActiveIdle = 0; idle_dur = 0; } void -ExecStage::init(ComputeUnit *cu) +ExecStage::init() { - computeUnit = cu; - _name = computeUnit->name() + ".ExecStage"; dispatchList = &computeUnit->dispatchList; idle_dur = 0; } diff --git a/src/gpu-compute/exec_stage.hh b/src/gpu-compute/exec_stage.hh index 670252cde..f984d729c 100644 --- a/src/gpu-compute/exec_stage.hh +++ b/src/gpu-compute/exec_stage.hh @@ -69,9 +69,9 @@ enum DISPATCH_STATUS class ExecStage { public: - ExecStage(const ComputeUnitParams* params); + ExecStage(const ComputeUnitParams* p, ComputeUnit *cu); ~ExecStage() { } - void init(ComputeUnit *cu); + void init(); void exec(); std::string dispStatusToStr(int j); diff --git a/src/gpu-compute/fetch_stage.cc b/src/gpu-compute/fetch_stage.cc index cf0b39e70..b9df6ce4f 100644 --- a/src/gpu-compute/fetch_stage.cc +++ b/src/gpu-compute/fetch_stage.cc @@ -36,11 +36,12 @@ #include "gpu-compute/compute_unit.hh" #include "gpu-compute/wavefront.hh" -FetchStage::FetchStage(const ComputeUnitParams* p) : - numVectorALUs(p->num_SIMDs), computeUnit(nullptr) +FetchStage::FetchStage(const ComputeUnitParams* p, ComputeUnit *cu) + : numVectorALUs(p->num_SIMDs), computeUnit(cu), + _name(cu->name() + ".FetchStage") { for (int j = 0; j < numVectorALUs; ++j) { - FetchUnit newFetchUnit(p); + FetchUnit newFetchUnit(p, cu); _fetchUnit.push_back(newFetchUnit); } } @@ -51,14 +52,11 @@ FetchStage::~FetchStage() } void -FetchStage::init(ComputeUnit *cu) +FetchStage::init() { - computeUnit = cu; - _name = computeUnit->name() + ".FetchStage"; - for (int j = 0; j < numVectorALUs; ++j) { _fetchUnit[j].bindWaveList(&computeUnit->wfList[j]); - _fetchUnit[j].init(computeUnit); + _fetchUnit[j].init(); } } diff --git a/src/gpu-compute/fetch_stage.hh b/src/gpu-compute/fetch_stage.hh index afaf81b5a..afecce7cb 100644 --- a/src/gpu-compute/fetch_stage.hh +++ b/src/gpu-compute/fetch_stage.hh @@ -51,9 +51,9 @@ class Wavefront; class FetchStage { public: - FetchStage(const ComputeUnitParams* params); + FetchStage(const ComputeUnitParams* p, ComputeUnit *cu); ~FetchStage(); - void init(ComputeUnit *cu); + void init(); void exec(); void processFetchReturn(PacketPtr pkt); void fetch(PacketPtr pkt, Wavefront *wave); diff --git a/src/gpu-compute/fetch_unit.cc b/src/gpu-compute/fetch_unit.cc index 447ff12fa..e0127e868 100644 --- a/src/gpu-compute/fetch_unit.cc +++ b/src/gpu-compute/fetch_unit.cc @@ -45,9 +45,9 @@ uint32_t FetchUnit::globalFetchUnitID; -FetchUnit::FetchUnit(const ComputeUnitParams* params) - : timingSim(true), computeUnit(nullptr), fetchScheduler(params), - waveList(nullptr), fetchDepth(params->fetch_depth) +FetchUnit::FetchUnit(const ComputeUnitParams *p, ComputeUnit *cu) + : timingSim(true), computeUnit(cu), fetchScheduler(p), + waveList(nullptr), fetchDepth(p->fetch_depth) { } @@ -58,9 +58,8 @@ FetchUnit::~FetchUnit() } void -FetchUnit::init(ComputeUnit *cu) +FetchUnit::init() { - computeUnit = cu; timingSim = computeUnit->shader->timingSim; fetchQueue.clear(); fetchStatusQueue.resize(computeUnit->shader->n_wf); diff --git a/src/gpu-compute/fetch_unit.hh b/src/gpu-compute/fetch_unit.hh index 798c26465..1615d81bb 100644 --- a/src/gpu-compute/fetch_unit.hh +++ b/src/gpu-compute/fetch_unit.hh @@ -49,9 +49,9 @@ class Wavefront; class FetchUnit { public: - FetchUnit(const ComputeUnitParams* params); + FetchUnit(const ComputeUnitParams* p, ComputeUnit *cu); ~FetchUnit(); - void init(ComputeUnit *cu); + void init(); void exec(); void bindWaveList(std::vector *list); void initiateFetch(Wavefront *wavefront); diff --git a/src/gpu-compute/global_memory_pipeline.cc b/src/gpu-compute/global_memory_pipeline.cc index cfd7c3db1..2619360a4 100644 --- a/src/gpu-compute/global_memory_pipeline.cc +++ b/src/gpu-compute/global_memory_pipeline.cc @@ -43,19 +43,19 @@ #include "gpu-compute/vector_register_file.hh" #include "gpu-compute/wavefront.hh" -GlobalMemPipeline::GlobalMemPipeline(const ComputeUnitParams* p) : - computeUnit(nullptr), gmQueueSize(p->global_mem_queue_size), - maxWaveRequests(p->max_wave_requests), inflightStores(0), - inflightLoads(0) +GlobalMemPipeline::GlobalMemPipeline(const ComputeUnitParams* p, + ComputeUnit *cu) + : computeUnit(cu), _name(cu->name() + ".GlobalMemPipeline"), + gmQueueSize(p->global_mem_queue_size), + maxWaveRequests(p->max_wave_requests), inflightStores(0), + inflightLoads(0) { } void -GlobalMemPipeline::init(ComputeUnit *cu) +GlobalMemPipeline::init() { - computeUnit = cu; globalMemSize = computeUnit->shader->globalMemSize; - _name = computeUnit->name() + ".GlobalMemPipeline"; } bool diff --git a/src/gpu-compute/global_memory_pipeline.hh b/src/gpu-compute/global_memory_pipeline.hh index 6fb1db7b4..97c0e8d59 100644 --- a/src/gpu-compute/global_memory_pipeline.hh +++ b/src/gpu-compute/global_memory_pipeline.hh @@ -56,8 +56,8 @@ class ComputeUnit; class GlobalMemPipeline { public: - GlobalMemPipeline(const ComputeUnitParams *params); - void init(ComputeUnit *cu); + GlobalMemPipeline(const ComputeUnitParams *p, ComputeUnit *cu); + void init(); void exec(); /** diff --git a/src/gpu-compute/local_memory_pipeline.cc b/src/gpu-compute/local_memory_pipeline.cc index b31ed6f4a..6644a0bf4 100644 --- a/src/gpu-compute/local_memory_pipeline.cc +++ b/src/gpu-compute/local_memory_pipeline.cc @@ -41,18 +41,12 @@ #include "gpu-compute/vector_register_file.hh" #include "gpu-compute/wavefront.hh" -LocalMemPipeline::LocalMemPipeline(const ComputeUnitParams* p) : - computeUnit(nullptr), lmQueueSize(p->local_mem_queue_size) +LocalMemPipeline::LocalMemPipeline(const ComputeUnitParams* p, ComputeUnit *cu) + : computeUnit(cu), _name(cu->name() + ".LocalMemPipeline"), + lmQueueSize(p->local_mem_queue_size) { } -void -LocalMemPipeline::init(ComputeUnit *cu) -{ - computeUnit = cu; - _name = computeUnit->name() + ".LocalMemPipeline"; -} - void LocalMemPipeline::exec() { diff --git a/src/gpu-compute/local_memory_pipeline.hh b/src/gpu-compute/local_memory_pipeline.hh index d9ab485b2..7821785c2 100644 --- a/src/gpu-compute/local_memory_pipeline.hh +++ b/src/gpu-compute/local_memory_pipeline.hh @@ -55,8 +55,7 @@ class Wavefront; class LocalMemPipeline { public: - LocalMemPipeline(const ComputeUnitParams *params); - void init(ComputeUnit *cu); + LocalMemPipeline(const ComputeUnitParams *p, ComputeUnit *cu); void exec(); std::queue &getLMRespFIFO() { return lmReturnedRequests; } diff --git a/src/gpu-compute/scalar_memory_pipeline.cc b/src/gpu-compute/scalar_memory_pipeline.cc index c8823b8a6..9ec354c1b 100644 --- a/src/gpu-compute/scalar_memory_pipeline.cc +++ b/src/gpu-compute/scalar_memory_pipeline.cc @@ -43,19 +43,14 @@ #include "gpu-compute/shader.hh" #include "gpu-compute/wavefront.hh" -ScalarMemPipeline::ScalarMemPipeline(const ComputeUnitParams* p) : - computeUnit(nullptr), queueSize(p->scalar_mem_queue_size), - inflightStores(0), inflightLoads(0) +ScalarMemPipeline::ScalarMemPipeline(const ComputeUnitParams* p, + ComputeUnit *cu) + : computeUnit(cu), _name(cu->name() + ".ScalarMemPipeline"), + queueSize(p->scalar_mem_queue_size), + inflightStores(0), inflightLoads(0) { } -void -ScalarMemPipeline::init(ComputeUnit *cu) -{ - computeUnit = cu; - _name = computeUnit->name() + ".ScalarMemPipeline"; -} - void ScalarMemPipeline::exec() { diff --git a/src/gpu-compute/scalar_memory_pipeline.hh b/src/gpu-compute/scalar_memory_pipeline.hh index 1944477cf..03211a291 100644 --- a/src/gpu-compute/scalar_memory_pipeline.hh +++ b/src/gpu-compute/scalar_memory_pipeline.hh @@ -59,8 +59,7 @@ class ComputeUnit; class ScalarMemPipeline { public: - ScalarMemPipeline(const ComputeUnitParams *params); - void init(ComputeUnit *cu); + ScalarMemPipeline(const ComputeUnitParams *p, ComputeUnit *cu); void exec(); std::queue &getGMReqFIFO() { return issuedRequests; } diff --git a/src/gpu-compute/schedule_stage.cc b/src/gpu-compute/schedule_stage.cc index 949eed155..510d3f347 100644 --- a/src/gpu-compute/schedule_stage.cc +++ b/src/gpu-compute/schedule_stage.cc @@ -44,7 +44,8 @@ #include "gpu-compute/wavefront.hh" ScheduleStage::ScheduleStage(const ComputeUnitParams *p, ComputeUnit *cu) - : vectorAluRdy(false), scalarAluRdy(false), scalarMemBusRdy(false), + : computeUnit(cu), _name(cu->name() + ".ScheduleStage"), + vectorAluRdy(false), scalarAluRdy(false), scalarMemBusRdy(false), scalarMemIssueRdy(false), glbMemBusRdy(false), glbMemIssueRdy(false), locMemBusRdy(false), locMemIssueRdy(false) { @@ -66,10 +67,8 @@ ScheduleStage::~ScheduleStage() } void -ScheduleStage::init(ComputeUnit *cu) +ScheduleStage::init() { - computeUnit = cu; - _name = computeUnit->name() + ".ScheduleStage"; fatal_if(scheduler.size() != computeUnit->readyList.size(), "Scheduler should have same number of entries as CU's readyList"); diff --git a/src/gpu-compute/schedule_stage.hh b/src/gpu-compute/schedule_stage.hh index 98519701a..be2691b28 100644 --- a/src/gpu-compute/schedule_stage.hh +++ b/src/gpu-compute/schedule_stage.hh @@ -57,9 +57,9 @@ struct ComputeUnitParams; class ScheduleStage { public: - ScheduleStage(const ComputeUnitParams *params, ComputeUnit *cu); + ScheduleStage(const ComputeUnitParams *p, ComputeUnit *cu); ~ScheduleStage(); - void init(ComputeUnit *cu); + void init(); void exec(); // Stats related variables and methods diff --git a/src/gpu-compute/scoreboard_check_stage.cc b/src/gpu-compute/scoreboard_check_stage.cc index 7b715cebf..e14a2f2b2 100644 --- a/src/gpu-compute/scoreboard_check_stage.cc +++ b/src/gpu-compute/scoreboard_check_stage.cc @@ -44,7 +44,9 @@ #include "gpu-compute/wavefront.hh" #include "params/ComputeUnit.hh" -ScoreboardCheckStage::ScoreboardCheckStage(const ComputeUnitParams *p) +ScoreboardCheckStage::ScoreboardCheckStage(const ComputeUnitParams *p, + ComputeUnit *cu) + : computeUnit(cu), _name(cu->name() + ".ScoreboardCheckStage") { } @@ -54,11 +56,8 @@ ScoreboardCheckStage::~ScoreboardCheckStage() } void -ScoreboardCheckStage::init(ComputeUnit *cu) +ScoreboardCheckStage::init() { - computeUnit = cu; - _name = computeUnit->name() + ".ScoreboardCheckStage"; - for (int unitId = 0; unitId < computeUnit->numExeUnits(); ++unitId) { readyList.push_back(&computeUnit->readyList[unitId]); } diff --git a/src/gpu-compute/scoreboard_check_stage.hh b/src/gpu-compute/scoreboard_check_stage.hh index 1e5695139..3cdae278c 100644 --- a/src/gpu-compute/scoreboard_check_stage.hh +++ b/src/gpu-compute/scoreboard_check_stage.hh @@ -70,9 +70,9 @@ class ScoreboardCheckStage NRDY_CONDITIONS }; - ScoreboardCheckStage(const ComputeUnitParams* params); + ScoreboardCheckStage(const ComputeUnitParams* p, ComputeUnit *cu); ~ScoreboardCheckStage(); - void init(ComputeUnit *cu); + void init(); void exec(); // Stats related variables and methods -- 2.30.2