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; }