Skip to content

Commit 30c57fd

Browse files
Simplify Device creation
Change-Id: Iac07194db73d7f0a6914bc3550c6cba67135c24c Signed-off-by: Dunajski, Bartosz <[email protected]>
1 parent 0ec6ef1 commit 30c57fd

File tree

2 files changed

+31
-33
lines changed

2 files changed

+31
-33
lines changed

runtime/device/device.cpp

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -103,29 +103,28 @@ Device::~Device() {
103103
executionEnvironment->decRefInternal();
104104
}
105105

106-
bool Device::createDeviceImpl(const HardwareInfo *pHwInfo, Device &outDevice) {
107-
auto executionEnvironment = outDevice.executionEnvironment;
106+
bool Device::createDeviceImpl(const HardwareInfo *pHwInfo) {
108107
executionEnvironment->initGmm(pHwInfo);
109108

110-
if (!createEngines(pHwInfo, outDevice)) {
109+
if (!createEngines(pHwInfo)) {
111110
return false;
112111
}
113112

114-
executionEnvironment->memoryManager->setDefaultEngineIndex(outDevice.defaultEngineIndex);
113+
executionEnvironment->memoryManager->setDefaultEngineIndex(defaultEngineIndex);
115114

116115
auto osInterface = executionEnvironment->osInterface.get();
117116

118-
if (!outDevice.osTime) {
119-
outDevice.osTime = OSTime::create(osInterface);
117+
if (!osTime) {
118+
osTime = OSTime::create(osInterface);
120119
}
121-
outDevice.driverInfo.reset(DriverInfo::create(osInterface));
120+
driverInfo.reset(DriverInfo::create(osInterface));
122121

123-
outDevice.initializeCaps();
122+
initializeCaps();
124123

125-
if (outDevice.osTime->getOSInterface()) {
124+
if (osTime->getOSInterface()) {
126125
if (pHwInfo->capabilityTable.instrumentationEnabled) {
127-
outDevice.performanceCounters = createPerformanceCountersFunc(outDevice.osTime.get());
128-
outDevice.performanceCounters->initialize(pHwInfo);
126+
performanceCounters = createPerformanceCountersFunc(osTime.get());
127+
performanceCounters->initialize(pHwInfo);
129128
}
130129
}
131130

@@ -134,57 +133,56 @@ bool Device::createDeviceImpl(const HardwareInfo *pHwInfo, Device &outDevice) {
134133
deviceHandle = osInterface->getDeviceHandle();
135134
}
136135

137-
if (outDevice.deviceInfo.sourceLevelDebuggerActive) {
138-
outDevice.executionEnvironment->sourceLevelDebugger->notifyNewDevice(deviceHandle);
136+
if (deviceInfo.sourceLevelDebuggerActive) {
137+
executionEnvironment->sourceLevelDebugger->notifyNewDevice(deviceHandle);
139138
}
140139

141-
outDevice.executionEnvironment->memoryManager->setForce32BitAllocations(outDevice.getDeviceInfo().force32BitAddressess);
140+
executionEnvironment->memoryManager->setForce32BitAllocations(getDeviceInfo().force32BitAddressess);
142141

143-
if (outDevice.preemptionMode == PreemptionMode::MidThread || outDevice.isSourceLevelDebuggerActive()) {
142+
if (preemptionMode == PreemptionMode::MidThread || isSourceLevelDebuggerActive()) {
144143
AllocationProperties properties(true, pHwInfo->capabilityTable.requiredPreemptionSurfaceSize, GraphicsAllocation::AllocationType::UNDECIDED);
145-
properties.flags.uncacheable = outDevice.getWaTable()->waCSRUncachable;
144+
properties.flags.uncacheable = getWaTable()->waCSRUncachable;
146145
properties.alignment = 256 * MemoryConstants::kiloByte;
147-
outDevice.preemptionAllocation = outDevice.executionEnvironment->memoryManager->allocateGraphicsMemoryWithProperties(properties);
148-
if (!outDevice.preemptionAllocation) {
146+
preemptionAllocation = executionEnvironment->memoryManager->allocateGraphicsMemoryWithProperties(properties);
147+
if (!preemptionAllocation) {
149148
return false;
150149
}
151150
}
152151

153-
for (auto engine : outDevice.engines) {
152+
for (auto engine : engines) {
154153
auto csr = engine.commandStreamReceiver;
155-
csr->setPreemptionCsrAllocation(outDevice.preemptionAllocation);
154+
csr->setPreemptionCsrAllocation(preemptionAllocation);
156155
if (DebugManager.flags.EnableExperimentalCommandBuffer.get() > 0) {
157-
csr->setExperimentalCmdBuffer(std::make_unique<ExperimentalCommandBuffer>(csr, outDevice.getDeviceInfo().profilingTimerResolution));
156+
csr->setExperimentalCmdBuffer(std::make_unique<ExperimentalCommandBuffer>(csr, getDeviceInfo().profilingTimerResolution));
158157
}
159158
}
160159

161160
return true;
162161
}
163162

164-
bool Device::createEngines(const HardwareInfo *pHwInfo, Device &outDevice) {
165-
auto executionEnvironment = outDevice.executionEnvironment;
163+
bool Device::createEngines(const HardwareInfo *pHwInfo) {
166164
auto defaultEngineType = getChosenEngineType(*pHwInfo);
167165
auto &gpgpuEngines = HwHelper::get(pHwInfo->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances();
168166

169167
for (uint32_t deviceCsrIndex = 0; deviceCsrIndex < gpgpuEngines.size(); deviceCsrIndex++) {
170-
if (!executionEnvironment->initializeCommandStreamReceiver(pHwInfo, outDevice.getDeviceIndex(), deviceCsrIndex)) {
168+
if (!executionEnvironment->initializeCommandStreamReceiver(pHwInfo, getDeviceIndex(), deviceCsrIndex)) {
171169
return false;
172170
}
173-
executionEnvironment->initializeMemoryManager(outDevice.getEnabled64kbPages(), outDevice.getEnableLocalMemory(),
174-
outDevice.getDeviceIndex(), deviceCsrIndex);
171+
executionEnvironment->initializeMemoryManager(getEnabled64kbPages(), getEnableLocalMemory(),
172+
getDeviceIndex(), deviceCsrIndex);
175173

176-
auto osContext = executionEnvironment->memoryManager->createAndRegisterOsContext(gpgpuEngines[deviceCsrIndex], outDevice.preemptionMode);
177-
auto commandStreamReceiver = executionEnvironment->commandStreamReceivers[outDevice.getDeviceIndex()][deviceCsrIndex].get();
174+
auto osContext = executionEnvironment->memoryManager->createAndRegisterOsContext(gpgpuEngines[deviceCsrIndex], preemptionMode);
175+
auto commandStreamReceiver = executionEnvironment->commandStreamReceivers[getDeviceIndex()][deviceCsrIndex].get();
178176
commandStreamReceiver->setupContext(*osContext);
179177
if (!commandStreamReceiver->initializeTagAllocation()) {
180178
return false;
181179
}
182180

183181
if (gpgpuEngines[deviceCsrIndex].type == defaultEngineType && gpgpuEngines[deviceCsrIndex].id == 0) {
184-
outDevice.defaultEngineIndex = deviceCsrIndex;
182+
defaultEngineIndex = deviceCsrIndex;
185183
}
186184

187-
outDevice.engines.push_back({commandStreamReceiver, osContext});
185+
engines.push_back({commandStreamReceiver, osContext});
188186
}
189187
return true;
190188
}

runtime/device/device.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,15 @@ class Device : public BaseObject<_cl_device_id> {
126126

127127
template <typename T>
128128
static T *createDeviceInternals(const HardwareInfo *pHwInfo, T *device) {
129-
if (false == createDeviceImpl(pHwInfo, *device)) {
129+
if (false == device->createDeviceImpl(pHwInfo)) {
130130
delete device;
131131
return nullptr;
132132
}
133133
return device;
134134
}
135135

136-
static bool createDeviceImpl(const HardwareInfo *pHwInfo, Device &outDevice);
137-
static bool createEngines(const HardwareInfo *pHwInfo, Device &outDevice);
136+
bool createDeviceImpl(const HardwareInfo *pHwInfo);
137+
bool createEngines(const HardwareInfo *pHwInfo);
138138
static const HardwareInfo *getDeviceInitHwInfo(const HardwareInfo *pHwInfoIn);
139139
MOCKABLE_VIRTUAL void initializeCaps();
140140
void setupFp64Flags();

0 commit comments

Comments
 (0)