Move memory manager ownership to execution environment.

Change-Id: Ib743b04139a6572da65eeffa6cd3e13db4bd9098
This commit is contained in:
Mrozek, Michal
2018-07-11 16:47:49 +02:00
committed by sys_ocldev
parent 0c094c05e5
commit 7735fb5767
7 changed files with 37 additions and 37 deletions

View File

@ -79,8 +79,7 @@ bool familyEnabled[IGFX_MAX_CORE] = {
};
Device::Device(const HardwareInfo &hwInfo, ExecutionEnvironment *executionEnvironment)
: memoryManager(nullptr), enabledClVersion(false), hwInfo(hwInfo),
tagAddress(nullptr), tagAllocation(nullptr), preemptionAllocation(nullptr),
: enabledClVersion(false), hwInfo(hwInfo), tagAddress(nullptr), tagAllocation(nullptr), preemptionAllocation(nullptr),
osTime(nullptr), slmWindowStartAddress(nullptr), executionEnvironment(executionEnvironment) {
memset(&deviceInfo, 0, sizeof(deviceInfo));
deviceExtensions.reserve(1000);
@ -102,7 +101,7 @@ Device::Device(const HardwareInfo &hwInfo, ExecutionEnvironment *executionEnviro
Device::~Device() {
BuiltIns::shutDown();
CompilerInterface::shutdown();
DEBUG_BREAK_IF(nullptr == memoryManager);
DEBUG_BREAK_IF(nullptr == executionEnvironment->memoryManager.get());
if (performanceCounters) {
performanceCounters->shutdown();
}
@ -115,19 +114,18 @@ Device::~Device() {
sourceLevelDebugger->notifyDeviceDestruction();
}
if (memoryManager) {
if (executionEnvironment->memoryManager) {
if (preemptionAllocation) {
memoryManager->freeGraphicsMemory(preemptionAllocation);
executionEnvironment->memoryManager->freeGraphicsMemory(preemptionAllocation);
preemptionAllocation = nullptr;
}
memoryManager->waitForDeletions();
executionEnvironment->memoryManager->waitForDeletions();
memoryManager->freeGraphicsMemory(tagAllocation);
executionEnvironment->memoryManager->freeGraphicsMemory(tagAllocation);
alignedFree(this->slmWindowStartAddress);
}
tagAllocation = nullptr;
delete memoryManager;
memoryManager = nullptr;
executionEnvironment->memoryManager.reset(nullptr);
executionEnvironment->decRefInternal();
}
@ -140,17 +138,17 @@ bool Device::createDeviceImpl(const HardwareInfo *pHwInfo, Device &outDevice) {
outDevice.executionEnvironment->commandStreamReceiver.reset(commandStreamReceiver);
if (!outDevice.memoryManager) {
outDevice.memoryManager = commandStreamReceiver->createMemoryManager(outDevice.deviceInfo.enabled64kbPages);
if (!outDevice.executionEnvironment->memoryManager) {
outDevice.executionEnvironment->memoryManager.reset(commandStreamReceiver->createMemoryManager(outDevice.deviceInfo.enabled64kbPages));
} else {
commandStreamReceiver->setMemoryManager(outDevice.memoryManager);
commandStreamReceiver->setMemoryManager(outDevice.executionEnvironment->memoryManager.get());
}
DEBUG_BREAK_IF(nullptr == outDevice.memoryManager);
DEBUG_BREAK_IF(nullptr == outDevice.executionEnvironment->memoryManager);
outDevice.memoryManager->csr = commandStreamReceiver;
outDevice.executionEnvironment->memoryManager->csr = commandStreamReceiver;
auto pTagAllocation = outDevice.memoryManager->allocateGraphicsMemory(sizeof(uint32_t));
auto pTagAllocation = outDevice.executionEnvironment->memoryManager->allocateGraphicsMemory(sizeof(uint32_t));
if (!pTagAllocation) {
return false;
}
@ -166,7 +164,6 @@ bool Device::createDeviceImpl(const HardwareInfo *pHwInfo, Device &outDevice) {
pDevice->osTime = OSTime::create(commandStreamReceiver->getOSInterface());
}
pDevice->driverInfo.reset(DriverInfo::create(commandStreamReceiver->getOSInterface()));
pDevice->memoryManager = outDevice.memoryManager;
pDevice->tagAddress = pTagMemory;
pDevice->initializeCaps();
@ -188,14 +185,14 @@ bool Device::createDeviceImpl(const HardwareInfo *pHwInfo, Device &outDevice) {
pDevice->sourceLevelDebugger->notifyNewDevice(deviceHandle);
}
outDevice.memoryManager->setForce32BitAllocations(pDevice->getDeviceInfo().force32BitAddressess);
outDevice.memoryManager->device = pDevice;
outDevice.executionEnvironment->memoryManager->setForce32BitAllocations(pDevice->getDeviceInfo().force32BitAddressess);
outDevice.executionEnvironment->memoryManager->device = pDevice;
if (pDevice->preemptionMode == PreemptionMode::MidThread || pDevice->isSourceLevelDebuggerActive()) {
size_t requiredSize = pHwInfo->capabilityTable.requiredPreemptionSurfaceSize;
size_t alignment = 256 * MemoryConstants::kiloByte;
bool uncacheable = pDevice->getWaTable()->waCSRUncachable;
pDevice->preemptionAllocation = outDevice.memoryManager->allocateGraphicsMemory(requiredSize, alignment, false, uncacheable);
pDevice->preemptionAllocation = outDevice.executionEnvironment->memoryManager->allocateGraphicsMemory(requiredSize, alignment, false, uncacheable);
if (!pDevice->preemptionAllocation) {
return false;
}
@ -230,7 +227,7 @@ void *Device::getSLMWindowStartAddress() {
void Device::prepareSLMWindow() {
if (this->slmWindowStartAddress == nullptr) {
this->slmWindowStartAddress = memoryManager->allocateSystemMemory(MemoryConstants::slmWindowSize, MemoryConstants::slmWindowAlignment);
this->slmWindowStartAddress = executionEnvironment->memoryManager->allocateSystemMemory(MemoryConstants::slmWindowSize, MemoryConstants::slmWindowAlignment);
}
}

View File

@ -46,9 +46,6 @@ struct OpenCLObjectMapper<_cl_device_id> {
};
class Device : public BaseObject<_cl_device_id> {
protected:
MemoryManager *memoryManager;
public:
static const cl_ulong objectMagic = 0x8055832341AC8D08LL;
@ -180,7 +177,7 @@ inline void Device::getCap(const void *&src,
}
inline CommandStreamReceiver &Device::getCommandStreamReceiver() {
return *(executionEnvironment->commandStreamReceiver.get());
return *executionEnvironment->commandStreamReceiver;
}
inline CommandStreamReceiver *Device::peekCommandStreamReceiver() {
@ -192,6 +189,6 @@ inline volatile uint32_t *Device::getTagAddress() const {
}
inline MemoryManager *Device::getMemoryManager() const {
return memoryManager;
return executionEnvironment->memoryManager.get();
}
} // namespace OCLRT

View File

@ -22,6 +22,7 @@
#include "runtime/command_stream/command_stream_receiver.h"
#include "runtime/execution_environment/execution_environment.h"
#include "runtime/memory_manager/memory_manager.h"
#include "runtime/gmm_helper/gmm_helper.h"
#include "runtime/os_interface/device_factory.h"

View File

@ -25,6 +25,7 @@
namespace OCLRT {
class GmmHelper;
class CommandStreamReceiver;
class MemoryManager;
struct HardwareInfo;
class ExecutionEnvironment : public ReferenceTrackedObject<ExecutionEnvironment> {
public:
@ -32,6 +33,7 @@ class ExecutionEnvironment : public ReferenceTrackedObject<ExecutionEnvironment>
~ExecutionEnvironment() override;
void initGmm(const HardwareInfo *hwInfo);
std::unique_ptr<CommandStreamReceiver> commandStreamReceiver;
std::unique_ptr<MemoryManager> memoryManager;
protected:
std::unique_ptr<GmmHelper> gmmHelper;