Refactor: Update Device::engineGroups to store only available engine groups

Simplify logic around engine groups.
Remove no longer needed code.

Related-To: NEO-6219

Signed-off-by: Filip Hazubski <filip.hazubski@intel.com>
This commit is contained in:
Filip Hazubski
2021-11-26 12:47:01 +00:00
committed by Compute-Runtime-Automation
parent 133e13b319
commit 4461b8ea3f
23 changed files with 196 additions and 302 deletions

View File

@@ -297,8 +297,11 @@ void Device::addEngineToEngineGroup(EngineControl &engine) {
return;
}
const uint32_t engineGroupIndex = static_cast<uint32_t>(engineGroupType);
this->engineGroups[engineGroupIndex].push_back(engine);
if (this->engineGroups.empty() || this->engineGroups.back().engineGroupType != engineGroupType) {
this->engineGroups.push_back(EngineGroupT{});
this->engineGroups.back().engineGroupType = engineGroupType;
}
this->engineGroups.back().engines.push_back(engine);
}
std::unique_ptr<CommandStreamReceiver> Device::createCommandStreamReceiver() const {
@@ -418,36 +421,14 @@ bool Device::areSharedSystemAllocationsAllowed() const {
return sharedSystemAllocationsSupport;
}
const std::vector<EngineControl> *Device::getNonEmptyEngineGroup(size_t index) const {
auto nonEmptyGroupIndex = 0u;
for (auto groupIndex = 0u; groupIndex < CommonConstants::engineGroupCount; groupIndex++) {
const std::vector<EngineControl> *currentGroup = &engineGroups[groupIndex];
if (currentGroup->empty()) {
continue;
}
if (index == nonEmptyGroupIndex) {
return currentGroup;
}
nonEmptyGroupIndex++;
}
return nullptr;
}
size_t Device::getIndexOfNonEmptyEngineGroup(EngineGroupType engineGroupType) const {
const auto groupIndex = static_cast<size_t>(engineGroupType);
UNRECOVERABLE_IF(groupIndex >= CommonConstants::engineGroupCount);
UNRECOVERABLE_IF(engineGroups[groupIndex].empty());
size_t result = 0u;
for (auto currentGroupIndex = 0u; currentGroupIndex < groupIndex; currentGroupIndex++) {
if (!engineGroups[currentGroupIndex].empty()) {
result++;
size_t Device::getEngineGroupIndexFromEngineGroupType(EngineGroupType engineGroupType) const {
for (size_t i = 0; i < engineGroups.size(); i++) {
if (engineGroups[i].engineGroupType == engineGroupType) {
return i;
}
}
return result;
UNRECOVERABLE_IF(true);
return 0;
}
EngineControl *Device::tryGetEngine(aub_stream::EngineType engineType, EngineUsage engineUsage) {
@@ -586,11 +567,11 @@ EngineControl &Device::getNextEngineForCommandQueue() {
const auto &hwHelper = NEO::HwHelper::get(hardwareInfo.platform.eRenderCoreFamily);
const auto engineGroupType = hwHelper.getEngineGroupType(defaultEngine.getEngineType(), defaultEngine.getEngineUsage(), hardwareInfo);
const auto defaultEngineGroupIndex = this->getIndexOfNonEmptyEngineGroup(engineGroupType);
const auto &engines = this->getEngineGroups()[defaultEngineGroupIndex];
const auto defaultEngineGroupIndex = this->getEngineGroupIndexFromEngineGroupType(engineGroupType);
auto &engineGroup = this->getEngineGroups()[defaultEngineGroupIndex];
const auto engineIndex = this->regularCommandQueuesCreatedWithinDeviceCount++ % engines.size();
return this->getEngineGroups()[defaultEngineGroupIndex][engineIndex];
const auto engineIndex = this->regularCommandQueuesCreatedWithinDeviceCount++ % engineGroup.engines.size();
return engineGroup.engines[engineIndex];
}
EngineControl *Device::getInternalCopyEngine() {

View File

@@ -32,8 +32,12 @@ struct SelectorCopyEngine : NonCopyableOrMovableClass {
class Device : public ReferenceTrackedObject<Device> {
public:
using EngineGroupT = std::vector<EngineControl>;
using EngineGroupsT = EngineGroupT[CommonConstants::engineGroupCount];
using EnginesT = std::vector<EngineControl>;
struct EngineGroupT {
EngineGroupType engineGroupType;
EnginesT engines;
};
using EngineGroupsT = std::vector<EngineGroupT>;
Device &operator=(const Device &) = delete;
Device(const Device &) = delete;
@@ -61,8 +65,7 @@ class Device : public ReferenceTrackedObject<Device> {
EngineGroupsT &getEngineGroups() {
return this->engineGroups;
}
const std::vector<EngineControl> *getNonEmptyEngineGroup(size_t index) const;
size_t getIndexOfNonEmptyEngineGroup(EngineGroupType engineGroupType) const;
size_t getEngineGroupIndexFromEngineGroupType(EngineGroupType engineGroupType) const;
EngineControl &getEngine(uint32_t index);
EngineControl &getDefaultEngine();
EngineControl &getNextEngineForCommandQueue();
@@ -83,7 +86,7 @@ class Device : public ReferenceTrackedObject<Device> {
MOCKABLE_VIRTUAL bool isDebuggerActive() const;
Debugger *getDebugger() const { return getRootDeviceEnvironment().debugger.get(); }
NEO::SourceLevelDebugger *getSourceLevelDebugger();
const std::vector<EngineControl> &getEngines() const;
const EnginesT &getEngines() const;
const std::string getDeviceName(const HardwareInfo &hwInfo) const;
ExecutionEnvironment *getExecutionEnvironment() const { return executionEnvironment; }
@@ -162,7 +165,7 @@ class Device : public ReferenceTrackedObject<Device> {
std::unique_ptr<PerformanceCounters> performanceCounters;
std::vector<std::unique_ptr<CommandStreamReceiver>> commandStreamReceivers;
std::vector<EngineControl> engines;
EnginesT engines;
EngineGroupsT engineGroups;
std::vector<SubDevice *> subdevices;