Use std::bitset for deviceBitfield.

Change-Id: I9078ffbb38967b753980cb1c5ebcab00f5292598
Signed-off-by: Piotr Fusik <piotr.fusik@intel.com>
This commit is contained in:
Piotr Fusik
2019-03-13 15:00:07 +01:00
parent 4997dffcf8
commit 25e6494443
13 changed files with 47 additions and 40 deletions

View File

@@ -173,8 +173,10 @@ bool Device::createEngines(const HardwareInfo *pHwInfo) {
auto commandStreamReceiver = executionEnvironment->commandStreamReceivers[getDeviceIndex()][deviceCsrIndex].get();
DeviceBitfield deviceBitfield;
deviceBitfield.set(getDeviceIndex());
auto osContext = executionEnvironment->memoryManager->createAndRegisterOsContext(commandStreamReceiver, gpgpuEngines[deviceCsrIndex],
(1 << getDeviceIndex()), preemptionMode);
deviceBitfield, preemptionMode);
commandStreamReceiver->setupContext(*osContext);
if (!commandStreamReceiver->initializeTagAllocation()) {

View File

@@ -7,18 +7,15 @@
#include "runtime/helpers/hardware_context_controller.h"
#include "common/helpers/bit_helpers.h"
#include "runtime/memory_manager/memory_constants.h"
#include "runtime/os_interface/os_context.h"
#include <limits>
using namespace OCLRT;
HardwareContextController::HardwareContextController(aub_stream::AubManager &aubManager, OsContext &osContext, uint32_t engineIndex, uint32_t flags) {
constexpr uint32_t maxIndex = std::numeric_limits<decltype(osContext.getDeviceBitfield())>::digits;
for (uint32_t deviceIndex = 0; deviceIndex < maxIndex; deviceIndex++) {
if (isBitSet(osContext.getDeviceBitfield(), deviceIndex)) {
auto deviceBitfield = osContext.getDeviceBitfield();
for (uint32_t deviceIndex = 0; deviceIndex < deviceBitfield.size(); deviceIndex++) {
if (deviceBitfield.test(deviceIndex)) {
hardwareContexts.emplace_back(aubManager.createHardwareContext(deviceIndex, engineIndex, flags));
}
}

View File

@@ -188,7 +188,7 @@ bool MemoryManager::isMemoryBudgetExhausted() const {
}
OsContext *MemoryManager::createAndRegisterOsContext(CommandStreamReceiver *commandStreamReceiver, EngineInstanceT engineType,
uint32_t deviceBitfield, PreemptionMode preemptionMode) {
DeviceBitfield deviceBitfield, PreemptionMode preemptionMode) {
auto contextId = ++latestContextId;
auto osContext = OsContext::create(executionEnvironment.osInterface.get(), contextId, deviceBitfield, engineType, preemptionMode);
osContext->incRefInternal();

View File

@@ -17,6 +17,7 @@
#include "engine_node.h"
#include <bitset>
#include <cstdint>
#include <mutex>
#include <vector>
@@ -34,6 +35,7 @@ struct ImageInfo;
using CsrContainer = std::vector<std::vector<std::unique_ptr<CommandStreamReceiver>>>;
using EngineControlContainer = std::vector<EngineControl>;
using DeviceBitfield = std::bitset<32>;
enum AllocationUsage {
TEMPORARY_ALLOCATION,
@@ -173,7 +175,7 @@ class MemoryManager {
}
OsContext *createAndRegisterOsContext(CommandStreamReceiver *commandStreamReceiver, EngineInstanceT engineType,
uint32_t deviceBitfield, PreemptionMode preemptionMode);
DeviceBitfield deviceBitfield, PreemptionMode preemptionMode);
uint32_t getRegisteredEnginesCount() const { return static_cast<uint32_t>(registeredEngines.size()); }
CommandStreamReceiver *getDefaultCommandStreamReceiver(uint32_t deviceId) const;
EngineControlContainer &getRegisteredEngines();

View File

@@ -14,7 +14,7 @@
namespace OCLRT {
OsContext *OsContext::create(OSInterface *osInterface, uint32_t contextId, uint32_t deviceBitfield,
OsContext *OsContext::create(OSInterface *osInterface, uint32_t contextId, DeviceBitfield deviceBitfield,
EngineInstanceT engineType, PreemptionMode preemptionMode) {
if (osInterface) {
return new OsContextLinux(*osInterface->get()->getDrm(), contextId, deviceBitfield, engineType, preemptionMode);
@@ -22,7 +22,7 @@ OsContext *OsContext::create(OSInterface *osInterface, uint32_t contextId, uint3
return new OsContext(contextId, deviceBitfield, engineType, preemptionMode);
}
OsContextLinux::OsContextLinux(Drm &drm, uint32_t contextId, uint32_t deviceBitfield,
OsContextLinux::OsContextLinux(Drm &drm, uint32_t contextId, DeviceBitfield deviceBitfield,
EngineInstanceT engineType, PreemptionMode preemptionMode)
: OsContext(contextId, deviceBitfield, engineType, preemptionMode), drm(drm) {

View File

@@ -14,7 +14,7 @@ class OsContextLinux : public OsContext {
public:
OsContextLinux() = delete;
~OsContextLinux() override;
OsContextLinux(Drm &drm, uint32_t contextId, uint32_t deviceBitfield,
OsContextLinux(Drm &drm, uint32_t contextId, DeviceBitfield deviceBitfield,
EngineInstanceT engineType, PreemptionMode preemptionMode);
unsigned int getEngineFlag() const { return engineFlag; }

View File

@@ -6,13 +6,12 @@
*/
#pragma once
#include "common/helpers/bit_helpers.h"
#include "runtime/command_stream/preemption_mode.h"
#include "runtime/memory_manager/memory_manager.h"
#include "runtime/utilities/reference_tracked_object.h"
#include "engine_node.h"
#include <limits>
#include <memory>
namespace OCLRT {
@@ -22,28 +21,25 @@ class OsContext : public ReferenceTrackedObject<OsContext> {
public:
OsContext() = delete;
static OsContext *create(OSInterface *osInterface, uint32_t contextId, uint32_t deviceBitfield, EngineInstanceT engineType, PreemptionMode preemptionMode);
static OsContext *create(OSInterface *osInterface, uint32_t contextId, DeviceBitfield deviceBitfield, EngineInstanceT engineType, PreemptionMode preemptionMode);
uint32_t getContextId() const { return contextId; }
uint32_t getNumSupportedDevices() const { return numSupportedDevices; }
uint8_t getDeviceBitfield() const { return deviceBitfield; }
DeviceBitfield getDeviceBitfield() const { return deviceBitfield; }
PreemptionMode getPreemptionMode() const { return preemptionMode; }
EngineInstanceT &getEngineType() { return engineType; }
protected:
OsContext(uint32_t contextId, uint32_t deviceBitfield, EngineInstanceT engineType, PreemptionMode preemptionMode)
: contextId(contextId), deviceBitfield(deviceBitfield), preemptionMode(preemptionMode), engineType(engineType) {
constexpr uint32_t maxIndex = std::numeric_limits<decltype(deviceBitfield)>::digits;
for (uint32_t deviceIndex = 0; deviceIndex < maxIndex; deviceIndex++) {
if (isBitSet(deviceBitfield, deviceIndex)) {
numSupportedDevices++;
}
}
};
OsContext(uint32_t contextId, DeviceBitfield deviceBitfield, EngineInstanceT engineType, PreemptionMode preemptionMode)
: contextId(contextId),
deviceBitfield(deviceBitfield),
preemptionMode(preemptionMode),
numSupportedDevices(static_cast<uint32_t>(deviceBitfield.count())),
engineType(engineType) {}
const uint32_t contextId;
const uint32_t deviceBitfield;
const DeviceBitfield deviceBitfield;
const PreemptionMode preemptionMode;
uint32_t numSupportedDevices = 0;
const uint32_t numSupportedDevices;
EngineInstanceT engineType = {EngineType::ENGINE_RCS, 0};
};
} // namespace OCLRT

View File

@@ -13,7 +13,7 @@
namespace OCLRT {
OsContext *OsContext::create(OSInterface *osInterface, uint32_t contextId, uint32_t deviceBitfield,
OsContext *OsContext::create(OSInterface *osInterface, uint32_t contextId, DeviceBitfield deviceBitfield,
EngineInstanceT engineType, PreemptionMode preemptionMode) {
if (osInterface) {
return new OsContextWin(*osInterface->get()->getWddm(), contextId, deviceBitfield, engineType, preemptionMode);
@@ -21,7 +21,7 @@ OsContext *OsContext::create(OSInterface *osInterface, uint32_t contextId, uint3
return new OsContext(contextId, deviceBitfield, engineType, preemptionMode);
}
OsContextWin::OsContextWin(Wddm &wddm, uint32_t contextId, uint32_t deviceBitfield,
OsContextWin::OsContextWin(Wddm &wddm, uint32_t contextId, DeviceBitfield deviceBitfield,
EngineInstanceT engineType, PreemptionMode preemptionMode)
: OsContext(contextId, deviceBitfield, engineType, preemptionMode), wddm(wddm), residencyController(wddm, contextId) {

View File

@@ -17,7 +17,7 @@ class OsContextWin : public OsContext {
OsContextWin() = delete;
~OsContextWin() override;
OsContextWin(Wddm &wddm, uint32_t contextId, uint32_t deviceBitfield,
OsContextWin(Wddm &wddm, uint32_t contextId, DeviceBitfield deviceBitfield,
EngineInstanceT engineType, PreemptionMode preemptionMode);
D3DKMT_HANDLE getWddmContextHandle() const { return wddmContextHandle; }

View File

@@ -784,7 +784,9 @@ HWTEST_F(AubCommandStreamReceiverTests, givenOsContextWithMultipleDevicesSupport
mockAubCenter->aubManager = std::make_unique<MockAubManager>();
pDevice->executionEnvironment->aubCenter.reset(mockAubCenter);
uint32_t deviceBitfield = 3;
DeviceBitfield deviceBitfield;
deviceBitfield.set(0);
deviceBitfield.set(1);
MockOsContext osContext(nullptr, 1, deviceBitfield, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled);
auto aubCsr = std::make_unique<AUBCommandStreamReceiverHw<FamilyType>>(*platformDevices[0], "", true, *pDevice->executionEnvironment);
aubCsr->setupContext(osContext);
@@ -1095,7 +1097,9 @@ using HardwareContextContainerTests = ::testing::Test;
TEST_F(HardwareContextContainerTests, givenOsContextWithMultipleDevicesSupportedThenInitialzeHwContextsWithValidIndexes) {
MockAubManager aubManager;
uint32_t deviceBitfield = 3;
DeviceBitfield deviceBitfield;
deviceBitfield.set(0);
deviceBitfield.set(1);
MockOsContext osContext(nullptr, 1, deviceBitfield, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled);
HardwareContextController hwContextControler(aubManager, osContext, 0, 0);
@@ -1109,9 +1113,11 @@ TEST_F(HardwareContextContainerTests, givenOsContextWithMultipleDevicesSupported
TEST_F(HardwareContextContainerTests, givenMultipleHwContextWhenSingleMethodIsCalledThenUseAllContexts) {
MockAubManager aubManager;
uint32_t deviceBitfield = 3;
DeviceBitfield deviceBitfield;
deviceBitfield.set(0);
deviceBitfield.set(1);
MockOsContext osContext(nullptr, 1, deviceBitfield, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled);
HardwareContextController hwContextContainer(aubManager, osContext, deviceBitfield, 0);
HardwareContextController hwContextContainer(aubManager, osContext, 3, 0);
EXPECT_EQ(2u, hwContextContainer.hardwareContexts.size());
auto mockHwContext0 = static_cast<MockHardwareContext *>(hwContextContainer.hardwareContexts[0].get());
@@ -1148,7 +1154,9 @@ TEST_F(HardwareContextContainerTests, givenMultipleHwContextWhenSingleMethodIsCa
TEST_F(HardwareContextContainerTests, givenMultipleHwContextWhenSingleMethodIsCalledThenUseFirstContext) {
MockAubManager aubManager;
uint32_t deviceBitfield = 3;
DeviceBitfield deviceBitfield;
deviceBitfield.set(0);
deviceBitfield.set(1);
MockOsContext osContext(nullptr, 1, deviceBitfield, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled);
HardwareContextController hwContextContainer(aubManager, osContext, 2, 0);
EXPECT_EQ(2u, hwContextContainer.hardwareContexts.size());

View File

@@ -167,9 +167,9 @@ TEST(DeviceCreation, givenMultiDeviceWhenTheyAreCreatedThenEachOsContextHasUniqu
for (uint32_t i = 0; i < numGpgpuEngines; i++) {
EXPECT_EQ(i, device1->getEngine(i).osContext->getContextId());
EXPECT_EQ(1u, device1->getEngine(i).osContext->getDeviceBitfield());
EXPECT_EQ(1u, device1->getEngine(i).osContext->getDeviceBitfield().to_ulong());
EXPECT_EQ(i + numGpgpuEngines, device2->getEngine(i).osContext->getContextId());
EXPECT_EQ(2u, device2->getEngine(i).osContext->getDeviceBitfield());
EXPECT_EQ(2u, device2->getEngine(i).osContext->getDeviceBitfield().to_ulong());
EXPECT_EQ(registeredEngines[i].commandStreamReceiver,
device1->getEngine(i).commandStreamReceiver);

View File

@@ -1560,7 +1560,9 @@ TEST(ResidencyDataTest, givenOsContextWhenItIsRegisteredToMemoryManagerThenRefCo
TEST(ResidencyDataTest, givenDeviceBitfieldWhenCreatingOsContextThenSetValidValue) {
ExecutionEnvironment executionEnvironment;
MockMemoryManager memoryManager(false, false, executionEnvironment);
uint32_t deviceBitfield = 3;
DeviceBitfield deviceBitfield;
deviceBitfield.set(0);
deviceBitfield.set(1);
PreemptionMode preemptionMode = PreemptionMode::MidThread;
memoryManager.createAndRegisterOsContext(nullptr, HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[0],
deviceBitfield, preemptionMode);

View File

@@ -11,8 +11,8 @@
namespace OCLRT {
class MockOsContext : public OsContext {
public:
MockOsContext(OSInterface *osInterface, uint32_t contextId, uint32_t numDevicesSupported,
MockOsContext(OSInterface *osInterface, uint32_t contextId, DeviceBitfield deviceBitfield,
EngineInstanceT engineType, PreemptionMode preemptionMode)
: OsContext(contextId, numDevicesSupported, engineType, preemptionMode) {}
: OsContext(contextId, deviceBitfield, engineType, preemptionMode) {}
};
} // namespace OCLRT