Skip to content

Commit f24b428

Browse files
Improve HardwareContextController creation
Change-Id: Iba929a2b4fcd993b38dd674be578aad0a481e8de Signed-off-by: Dunajski, Bartosz <[email protected]>
1 parent e721f7c commit f24b428

File tree

14 files changed

+66
-71
lines changed

14 files changed

+66
-71
lines changed

runtime/command_stream/command_stream_receiver_simulated_common_hw.inl

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,7 @@ void CommandStreamReceiverSimulatedCommonHw<GfxFamily>::setupContext(OsContext &
9696

9797
auto &engineType = osContext.getEngineType();
9898
if (aubManager && !(engineType.type == lowPriorityGpgpuEngine.type && engineType.id == lowPriorityGpgpuEngine.id)) {
99-
if (osContext.getNumDevicesSupported() == 1) {
100-
hardwareContextController = std::make_unique<HardwareContextController>(*aubManager, osContext,
101-
deviceIndex, engineIndex, flags);
102-
} else {
103-
hardwareContextController = std::make_unique<HardwareContextController>(*aubManager, osContext, engineIndex, flags);
104-
}
99+
hardwareContextController = std::make_unique<HardwareContextController>(*aubManager, osContext, engineIndex, flags);
105100
}
106101
}
107102

runtime/device/device.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ bool Device::createEngines(const HardwareInfo *pHwInfo) {
179179
auto commandStreamReceiver = executionEnvironment->commandStreamReceivers[getDeviceIndex()][deviceCsrIndex].get();
180180

181181
auto osContext = executionEnvironment->memoryManager->createAndRegisterOsContext(commandStreamReceiver, gpgpuEngines[deviceCsrIndex],
182-
1, preemptionMode);
182+
(1 << getDeviceIndex()), preemptionMode);
183183
commandStreamReceiver->setupContext(*osContext);
184184

185185
if (!commandStreamReceiver->initializeTagAllocation()) {

runtime/helpers/hardware_context_controller.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,20 @@
77

88
#include "runtime/helpers/hardware_context_controller.h"
99

10+
#include "common/helpers/bit_helpers.h"
1011
#include "runtime/memory_manager/memory_constants.h"
1112
#include "runtime/os_interface/os_context.h"
1213

13-
using namespace OCLRT;
14+
#include <limits>
1415

15-
HardwareContextController::HardwareContextController(aub_stream::AubManager &aubManager, OsContext &osContext,
16-
uint32_t deviceIndex, uint32_t engineIndex, uint32_t flags) {
17-
UNRECOVERABLE_IF(osContext.getNumDevicesSupported() > 1);
18-
hardwareContexts.emplace_back(aubManager.createHardwareContext(deviceIndex, engineIndex, flags));
19-
}
16+
using namespace OCLRT;
2017

21-
HardwareContextController::HardwareContextController(aub_stream::AubManager &aubManager, OsContext &osContext,
22-
uint32_t engineIndex, uint32_t flags) {
23-
DEBUG_BREAK_IF(osContext.getNumDevicesSupported() < 2);
24-
for (uint32_t deviceIndex = 0; deviceIndex < osContext.getNumDevicesSupported(); deviceIndex++) {
25-
hardwareContexts.emplace_back(aubManager.createHardwareContext(deviceIndex, engineIndex, flags));
18+
HardwareContextController::HardwareContextController(aub_stream::AubManager &aubManager, OsContext &osContext, uint32_t engineIndex, uint32_t flags) {
19+
constexpr uint32_t maxIndex = std::numeric_limits<decltype(osContext.getDeviceBitfiled())>::digits;
20+
for (uint32_t deviceIndex = 0; deviceIndex < maxIndex; deviceIndex++) {
21+
if (isBitSet(osContext.getDeviceBitfiled(), deviceIndex)) {
22+
hardwareContexts.emplace_back(aubManager.createHardwareContext(deviceIndex, engineIndex, flags));
23+
}
2624
}
2725
}
2826

runtime/helpers/hardware_context_controller.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ class OsContext;
1818
class HardwareContextController {
1919
public:
2020
HardwareContextController() = delete;
21-
HardwareContextController(aub_stream::AubManager &aubManager, OsContext &osContext, uint32_t deviceIndex, uint32_t engineIndex, uint32_t flags);
2221
HardwareContextController(aub_stream::AubManager &aubManager, OsContext &osContext, uint32_t engineIndex, uint32_t flags);
2322

2423
void initialize();

runtime/memory_manager/memory_manager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,9 @@ bool MemoryManager::isMemoryBudgetExhausted() const {
180180
}
181181

182182
OsContext *MemoryManager::createAndRegisterOsContext(CommandStreamReceiver *commandStreamReceiver, EngineInstanceT engineType,
183-
uint32_t numSupportedDevices, PreemptionMode preemptionMode) {
183+
uint32_t deviceBitfiled, PreemptionMode preemptionMode) {
184184
auto contextId = ++latestContextId;
185-
auto osContext = OsContext::create(executionEnvironment.osInterface.get(), contextId, numSupportedDevices, engineType, preemptionMode);
185+
auto osContext = OsContext::create(executionEnvironment.osInterface.get(), contextId, deviceBitfiled, engineType, preemptionMode);
186186
osContext->incRefInternal();
187187

188188
registeredEngines.emplace_back(commandStreamReceiver, osContext);

runtime/memory_manager/memory_manager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ class MemoryManager {
184184
}
185185

186186
OsContext *createAndRegisterOsContext(CommandStreamReceiver *commandStreamReceiver, EngineInstanceT engineType,
187-
uint32_t numSupportedDevices, PreemptionMode preemptionMode);
187+
uint32_t deviceBitfiled, PreemptionMode preemptionMode);
188188
uint32_t getRegisteredEnginesCount() const { return static_cast<uint32_t>(registeredEngines.size()); }
189189
CommandStreamReceiver *getDefaultCommandStreamReceiver(uint32_t deviceId) const;
190190
EngineControlContainer &getRegisteredEngines();

runtime/os_interface/linux/os_context_linux.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@
1414

1515
namespace OCLRT {
1616

17-
OsContext *OsContext::create(OSInterface *osInterface, uint32_t contextId, uint32_t numDevicesSupported,
17+
OsContext *OsContext::create(OSInterface *osInterface, uint32_t contextId, uint32_t deviceBitfiled,
1818
EngineInstanceT engineType, PreemptionMode preemptionMode) {
1919
if (osInterface) {
20-
return new OsContextLinux(*osInterface->get()->getDrm(), contextId, numDevicesSupported, engineType, preemptionMode);
20+
return new OsContextLinux(*osInterface->get()->getDrm(), contextId, deviceBitfiled, engineType, preemptionMode);
2121
}
22-
return new OsContext(contextId, numDevicesSupported, engineType, preemptionMode);
22+
return new OsContext(contextId, deviceBitfiled, engineType, preemptionMode);
2323
}
2424

25-
OsContextLinux::OsContextLinux(Drm &drm, uint32_t contextId, uint32_t numDevicesSupported,
25+
OsContextLinux::OsContextLinux(Drm &drm, uint32_t contextId, uint32_t deviceBitfiled,
2626
EngineInstanceT engineType, PreemptionMode preemptionMode)
27-
: OsContext(contextId, numDevicesSupported, engineType, preemptionMode), drm(drm) {
27+
: OsContext(contextId, deviceBitfiled, engineType, preemptionMode), drm(drm) {
2828

2929
engineFlag = DrmEngineMapper::engineNodeMap(engineType.type);
3030
this->drmContextId = drm.createDrmContext();

runtime/os_interface/linux/os_context_linux.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class OsContextLinux : public OsContext {
1414
public:
1515
OsContextLinux() = delete;
1616
~OsContextLinux() override;
17-
OsContextLinux(Drm &drm, uint32_t contextId, uint32_t numDevicesSupported,
17+
OsContextLinux(Drm &drm, uint32_t contextId, uint32_t deviceBitfiled,
1818
EngineInstanceT engineType, PreemptionMode preemptionMode);
1919

2020
unsigned int getEngineFlag() const { return engineFlag; }

runtime/os_interface/os_context.h

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
*/
77

88
#pragma once
9+
#include "common/helpers/bit_helpers.h"
910
#include "runtime/command_stream/preemption_mode.h"
1011
#include "runtime/utilities/reference_tracked_object.h"
1112

1213
#include "engine_node.h"
1314

15+
#include <limits>
1416
#include <memory>
1517

1618
namespace OCLRT {
@@ -20,19 +22,28 @@ class OsContext : public ReferenceTrackedObject<OsContext> {
2022
public:
2123
OsContext() = delete;
2224

23-
static OsContext *create(OSInterface *osInterface, uint32_t contextId, uint32_t numDevicesSupported, EngineInstanceT engineType, PreemptionMode preemptionMode);
25+
static OsContext *create(OSInterface *osInterface, uint32_t contextId, uint32_t deviceBitfiled, EngineInstanceT engineType, PreemptionMode preemptionMode);
2426
uint32_t getContextId() const { return contextId; }
25-
uint32_t getNumDevicesSupported() const { return numDevicesSupported; }
27+
uint32_t getNumSupportedDevices() const { return numSupportedDevices; }
28+
uint8_t getDeviceBitfiled() const { return deviceBitfiled; }
2629
PreemptionMode getPreemptionMode() const { return preemptionMode; }
2730
EngineInstanceT &getEngineType() { return engineType; }
2831

2932
protected:
30-
OsContext(uint32_t contextId, uint32_t numDevicesSupported, EngineInstanceT engineType, PreemptionMode preemptionMode)
31-
: contextId(contextId), numDevicesSupported(numDevicesSupported), preemptionMode(preemptionMode), engineType(engineType){};
33+
OsContext(uint32_t contextId, uint32_t deviceBitfiled, EngineInstanceT engineType, PreemptionMode preemptionMode)
34+
: contextId(contextId), deviceBitfiled(deviceBitfiled), preemptionMode(preemptionMode), engineType(engineType) {
35+
constexpr uint32_t maxIndex = std::numeric_limits<decltype(deviceBitfiled)>::digits;
36+
for (uint32_t deviceIndex = 0; deviceIndex < maxIndex; deviceIndex++) {
37+
if (isBitSet(deviceBitfiled, deviceIndex)) {
38+
numSupportedDevices++;
39+
}
40+
}
41+
};
3242

3343
const uint32_t contextId;
34-
const uint32_t numDevicesSupported;
44+
const uint32_t deviceBitfiled;
3545
const PreemptionMode preemptionMode;
46+
uint32_t numSupportedDevices = 0;
3647
EngineInstanceT engineType = {EngineType::ENGINE_RCS, 0};
3748
};
3849
} // namespace OCLRT

runtime/os_interface/windows/os_context_win.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@
1313

1414
namespace OCLRT {
1515

16-
OsContext *OsContext::create(OSInterface *osInterface, uint32_t contextId, uint32_t numDevicesSupported,
16+
OsContext *OsContext::create(OSInterface *osInterface, uint32_t contextId, uint32_t deviceBitfiled,
1717
EngineInstanceT engineType, PreemptionMode preemptionMode) {
1818
if (osInterface) {
19-
return new OsContextWin(*osInterface->get()->getWddm(), contextId, numDevicesSupported, engineType, preemptionMode);
19+
return new OsContextWin(*osInterface->get()->getWddm(), contextId, deviceBitfiled, engineType, preemptionMode);
2020
}
21-
return new OsContext(contextId, numDevicesSupported, engineType, preemptionMode);
21+
return new OsContext(contextId, deviceBitfiled, engineType, preemptionMode);
2222
}
2323

24-
OsContextWin::OsContextWin(Wddm &wddm, uint32_t contextId, uint32_t numDevicesSupported,
24+
OsContextWin::OsContextWin(Wddm &wddm, uint32_t contextId, uint32_t deviceBitfiled,
2525
EngineInstanceT engineType, PreemptionMode preemptionMode)
26-
: OsContext(contextId, numDevicesSupported, engineType, preemptionMode), wddm(wddm), residencyController(wddm, contextId) {
26+
: OsContext(contextId, deviceBitfiled, engineType, preemptionMode), wddm(wddm), residencyController(wddm, contextId) {
2727

2828
UNRECOVERABLE_IF(!wddm.isInitialized());
2929

0 commit comments

Comments
 (0)