Move initialization of AubCenter to RootDeviceEnvironment

make RootDeviceEnvironments vector of unique_ptr

Related-To: NEO-3857

Change-Id: I23998502198307c8535cdd5c9c4af5223a5d69a5
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2019-11-15 09:59:48 +01:00
committed by sys_ocldev
parent 8cc6a65e69
commit 3e1b15c31d
61 changed files with 355 additions and 178 deletions

View File

@@ -7,6 +7,7 @@
#include "api.h"
#include "core/execution_environment/root_device_environment.h"
#include "core/helpers/aligned_memory.h"
#include "core/helpers/kernel_helpers.h"
#include "core/memory_manager/unified_memory_manager.h"
@@ -5028,7 +5029,7 @@ cl_int CL_API_CALL clAddCommentINTEL(cl_platform_id platform, const char *commen
DBG_LOG_INPUTS("platform", platform, "comment", comment);
auto executionEnvironment = ::platform()->peekExecutionEnvironment();
auto aubCenter = executionEnvironment->rootDeviceEnvironments[0].aubCenter.get();
auto aubCenter = executionEnvironment->rootDeviceEnvironments[0]->aubCenter.get();
if (!comment || (aubCenter && !aubCenter->getAubManager())) {
retVal = CL_INVALID_VALUE;

View File

@@ -5,6 +5,7 @@
*
*/
#include "core/execution_environment/root_device_environment.h"
#include "core/helpers/aligned_memory.h"
#include "core/helpers/debug_helpers.h"
#include "core/helpers/hash.h"
@@ -43,8 +44,8 @@ AUBCommandStreamReceiverHw<GfxFamily>::AUBCommandStreamReceiverHw(const std::str
: BaseClass(executionEnvironment, rootDeviceIndex),
standalone(standalone) {
executionEnvironment.initAubCenter(this->isLocalMemoryEnabled(), fileName, this->getType());
auto aubCenter = executionEnvironment.rootDeviceEnvironments[0].aubCenter.get();
executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->initAubCenter(this->isLocalMemoryEnabled(), fileName, this->getType());
auto aubCenter = executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->aubCenter.get();
UNRECOVERABLE_IF(nullptr == aubCenter);
auto subCaptureCommon = aubCenter->getSubCaptureCommon();
@@ -276,13 +277,13 @@ void AUBCommandStreamReceiverHw<GfxFamily>::initializeEngine() {
template <typename GfxFamily>
CommandStreamReceiver *AUBCommandStreamReceiverHw<GfxFamily>::create(const std::string &fileName, bool standalone, ExecutionEnvironment &executionEnvironment, uint32_t rootDeviceIndex) {
auto csr = new AUBCommandStreamReceiverHw<GfxFamily>(fileName, standalone, executionEnvironment, rootDeviceIndex);
auto csr = std::make_unique<AUBCommandStreamReceiverHw<GfxFamily>>(fileName, standalone, executionEnvironment, rootDeviceIndex);
if (!csr->subCaptureManager->isSubCaptureMode()) {
csr->openFile(fileName);
}
return csr;
return csr.release();
}
template <typename GfxFamily>

View File

@@ -5,6 +5,7 @@
*
*/
#include "core/execution_environment/root_device_environment.h"
#include "runtime/aub/aub_center.h"
#include "runtime/command_stream/aub_command_stream_receiver.h"
#include "runtime/command_stream/command_stream_receiver_with_aub_dump.h"
@@ -17,7 +18,7 @@ extern CommandStreamReceiverCreateFunc commandStreamReceiverFactory[IGFX_MAX_COR
template <typename BaseCSR>
CommandStreamReceiverWithAUBDump<BaseCSR>::CommandStreamReceiverWithAUBDump(const std::string &baseName, ExecutionEnvironment &executionEnvironment, uint32_t rootDeviceIndex)
: BaseCSR(executionEnvironment, rootDeviceIndex) {
bool isAubManager = executionEnvironment.rootDeviceEnvironments[0].aubCenter && executionEnvironment.rootDeviceEnvironments[0].aubCenter->getAubManager();
bool isAubManager = executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->aubCenter && executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->aubCenter->getAubManager();
bool isTbxMode = CommandStreamReceiverType::CSR_TBX == BaseCSR::getType();
bool createAubCsr = (isAubManager && isTbxMode) ? false : true;
if (createAubCsr) {

View File

@@ -5,6 +5,7 @@
*
*/
#include "core/execution_environment/root_device_environment.h"
#include "core/helpers/aligned_memory.h"
#include "core/helpers/debug_helpers.h"
#include "core/helpers/hw_helper.h"
@@ -35,8 +36,8 @@ TbxCommandStreamReceiverHw<GfxFamily>::TbxCommandStreamReceiverHw(ExecutionEnvir
: BaseClass(executionEnvironment, rootDeviceIndex) {
physicalAddressAllocator.reset(this->createPhysicalAddressAllocator(&this->peekHwInfo()));
executionEnvironment.initAubCenter(this->localMemoryEnabled, "", this->getType());
auto aubCenter = executionEnvironment.rootDeviceEnvironments[0].aubCenter.get();
executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->initAubCenter(this->localMemoryEnabled, "", this->getType());
auto aubCenter = executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->aubCenter.get();
UNRECOVERABLE_IF(nullptr == aubCenter);
aubManager = aubCenter->getAubManager();
@@ -157,11 +158,11 @@ CommandStreamReceiver *TbxCommandStreamReceiverHw<GfxFamily>::create(const std::
if (DebugManager.flags.AUBDumpCaptureFileName.get() != "unk") {
fullName.assign(DebugManager.flags.AUBDumpCaptureFileName.get());
}
executionEnvironment.initAubCenter(localMemoryEnabled, fullName, CommandStreamReceiverType::CSR_TBX_WITH_AUB);
executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->initAubCenter(localMemoryEnabled, fullName, CommandStreamReceiverType::CSR_TBX_WITH_AUB);
csr = new CommandStreamReceiverWithAUBDump<TbxCommandStreamReceiverHw<GfxFamily>>(baseName, executionEnvironment, rootDeviceIndex);
auto aubCenter = executionEnvironment.rootDeviceEnvironments[0].aubCenter.get();
auto aubCenter = executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->aubCenter.get();
UNRECOVERABLE_IF(nullptr == aubCenter);
auto subCaptureCommon = aubCenter->getSubCaptureCommon();

View File

@@ -8,11 +8,10 @@
#include "runtime/execution_environment/execution_environment.h"
#include "core/compiler_interface/compiler_interface.h"
#include "core/execution_environment/root_device_environment.h"
#include "core/helpers/hw_helper.h"
#include "core/memory_manager/memory_operations_handler.h"
#include "runtime/aub/aub_center.h"
#include "runtime/built_ins/built_ins.h"
#include "runtime/command_stream/command_stream_receiver.h"
#include "runtime/command_stream/tbx_command_stream_receiver_hw.h"
#include "runtime/compiler_interface/default_cl_cache_config.h"
#include "runtime/gmm_helper/gmm_helper.h"
@@ -32,11 +31,6 @@ ExecutionEnvironment::~ExecutionEnvironment() {
rootDeviceEnvironments.clear();
}
void ExecutionEnvironment::initAubCenter(bool localMemoryEnabled, const std::string &aubFileName, CommandStreamReceiverType csrType) {
if (!rootDeviceEnvironments[0].aubCenter) {
rootDeviceEnvironments[0].aubCenter.reset(new AubCenter(hwInfo.get(), localMemoryEnabled, aubFileName, csrType));
}
}
void ExecutionEnvironment::initGmm() {
if (!gmmHelper) {
gmmHelper.reset(new GmmHelper(hwInfo.get()));
@@ -106,4 +100,15 @@ BuiltIns *ExecutionEnvironment::getBuiltIns() {
bool ExecutionEnvironment::isFullRangeSvm() const {
return hwInfo->capabilityTable.gpuAddressSpace >= maxNBitValue<47>;
}
void ExecutionEnvironment::prepareRootDeviceEnvironments(uint32_t numRootDevices) {
if (rootDeviceEnvironments.size() < numRootDevices) {
rootDeviceEnvironments.resize(numRootDevices);
}
for (auto rootDeviceIndex = 0u; rootDeviceIndex < numRootDevices; rootDeviceIndex++) {
if (!rootDeviceEnvironments[rootDeviceIndex]) {
rootDeviceEnvironments[rootDeviceIndex] = std::make_unique<RootDeviceEnvironment>(*this);
}
}
}
} // namespace NEO

View File

@@ -6,9 +6,7 @@
*/
#pragma once
#include "core/execution_environment/root_device_environment.h"
#include "core/utilities/reference_tracked_object.h"
#include "runtime/helpers/options.h"
#include "runtime/os_interface/device_factory.h"
#include <mutex>
@@ -21,8 +19,8 @@ class GmmHelper;
class MemoryManager;
class MemoryOperationsHandler;
class OSInterface;
class RootDevice;
class SourceLevelDebugger;
struct RootDeviceEnvironment;
struct HardwareInfo;
class ExecutionEnvironment : public ReferenceTrackedObject<ExecutionEnvironment> {
@@ -38,7 +36,6 @@ class ExecutionEnvironment : public ReferenceTrackedObject<ExecutionEnvironment>
ExecutionEnvironment();
~ExecutionEnvironment() override;
MOCKABLE_VIRTUAL void initAubCenter(bool localMemoryEnabled, const std::string &aubFileName, CommandStreamReceiverType csrType);
void initGmm();
void initializeMemoryManager();
void initSourceLevelDebugger();
@@ -46,6 +43,7 @@ class ExecutionEnvironment : public ReferenceTrackedObject<ExecutionEnvironment>
const HardwareInfo *getHardwareInfo() const { return hwInfo.get(); }
HardwareInfo *getMutableHardwareInfo() const { return hwInfo.get(); }
bool isFullRangeSvm() const;
void prepareRootDeviceEnvironments(uint32_t numRootDevices);
GmmHelper *getGmmHelper() const;
MOCKABLE_VIRTUAL CompilerInterface *getCompilerInterface();
@@ -54,7 +52,7 @@ class ExecutionEnvironment : public ReferenceTrackedObject<ExecutionEnvironment>
std::unique_ptr<OSInterface> osInterface;
std::unique_ptr<MemoryOperationsHandler> memoryOperationsInterface;
std::unique_ptr<MemoryManager> memoryManager;
std::vector<RootDeviceEnvironment> rootDeviceEnvironments{1};
std::vector<std::unique_ptr<RootDeviceEnvironment>> rootDeviceEnvironments;
std::unique_ptr<BuiltIns> builtins;
std::unique_ptr<CompilerInterface> compilerInterface;
std::unique_ptr<SourceLevelDebugger> sourceLevelDebugger;

View File

@@ -97,7 +97,7 @@ GraphicsAllocation *MemoryManager::allocateGraphicsMemoryWithHostPtr(const Alloc
deferredDeleter->drain(true);
}
GraphicsAllocation *graphicsAllocation = nullptr;
auto osStorage = hostPtrManager->prepareOsStorageForAllocation(*this, allocationData.size, allocationData.hostPtr);
auto osStorage = hostPtrManager->prepareOsStorageForAllocation(*this, allocationData.size, allocationData.hostPtr, allocationData.rootDeviceIndex);
if (osStorage.fragmentCount > 0) {
graphicsAllocation = createGraphicsAllocation(osStorage, allocationData);
}
@@ -115,7 +115,7 @@ GraphicsAllocation *MemoryManager::allocateGraphicsMemoryForImageFromHostPtr(con
void MemoryManager::cleanGraphicsMemoryCreatedFromHostPtr(GraphicsAllocation *graphicsAllocation) {
hostPtrManager->releaseHandleStorage(graphicsAllocation->fragmentsStorage);
cleanOsHandles(graphicsAllocation->fragmentsStorage);
cleanOsHandles(graphicsAllocation->fragmentsStorage, graphicsAllocation->getRootDeviceIndex());
}
GraphicsAllocation *MemoryManager::createGraphicsAllocationWithPadding(GraphicsAllocation *inputGraphicsAllocation, size_t sizeWithPadding) {

View File

@@ -89,7 +89,7 @@ class MemoryManager {
virtual GraphicsAllocation *createPaddedAllocation(GraphicsAllocation *inputGraphicsAllocation, size_t sizeWithPadding);
virtual AllocationStatus populateOsHandles(OsHandleStorage &handleStorage) = 0;
virtual void cleanOsHandles(OsHandleStorage &handleStorage) = 0;
virtual void cleanOsHandles(OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) = 0;
void freeSystemMemory(void *ptr);

View File

@@ -7,6 +7,7 @@
#include "runtime/memory_manager/os_agnostic_memory_manager.h"
#include "core/execution_environment/root_device_environment.h"
#include "core/helpers/aligned_memory.h"
#include "core/helpers/basic_math.h"
#include "core/helpers/ptr_math.h"
@@ -218,8 +219,10 @@ void OsAgnosticMemoryManager::freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllo
releaseReservedCpuAddressRange(gfxAllocation->getReservedAddressPtr(), gfxAllocation->getReservedAddressSize());
}
if (executionEnvironment.rootDeviceEnvironments.size() > 0) {
auto aubCenter = executionEnvironment.rootDeviceEnvironments[0].aubCenter.get();
auto rootDeviceIndex = gfxAllocation->getRootDeviceIndex();
if (executionEnvironment.rootDeviceEnvironments.size() > rootDeviceIndex) {
auto aubCenter = executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->aubCenter.get();
if (aubCenter && aubCenter->getAubManager() && DebugManager.flags.EnableFreeMemory.get()) {
aubCenter->getAubManager()->freeMemory(gfxAllocation->getGpuAddress(), gfxAllocation->getUnderlyingBufferSize());
}
@@ -260,10 +263,10 @@ MemoryManager::AllocationStatus OsAgnosticMemoryManager::populateOsHandles(OsHan
}
return AllocationStatus::Success;
}
void OsAgnosticMemoryManager::cleanOsHandles(OsHandleStorage &handleStorage) {
void OsAgnosticMemoryManager::cleanOsHandles(OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) {
for (unsigned int i = 0; i < maxFragmentsCount; i++) {
if (handleStorage.fragmentStorageData[i].freeTheFragment) {
auto aubCenter = executionEnvironment.rootDeviceEnvironments[0].aubCenter.get();
auto aubCenter = executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->aubCenter.get();
if (aubCenter && aubCenter->getAubManager() && DebugManager.flags.EnableFreeMemory.get()) {
aubCenter->getAubManager()->freeMemory((uint64_t)handleStorage.fragmentStorageData[i].cpuPtr, handleStorage.fragmentStorageData[i].fragmentSize);
}

View File

@@ -57,7 +57,7 @@ class OsAgnosticMemoryManager : public MemoryManager {
void freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation) override;
AllocationStatus populateOsHandles(OsHandleStorage &handleStorage) override;
void cleanOsHandles(OsHandleStorage &handleStorage) override;
void cleanOsHandles(OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override;
uint64_t getSystemSharedMemory() override;
uint64_t getLocalMemorySize() override;

View File

@@ -5,6 +5,7 @@
*
*/
#include "core/execution_environment/root_device_environment.h"
#include "core/helpers/hw_helper.h"
#include "core/os_interface/aub_memory_operations_handler.h"
#include "runtime/aub/aub_center.h"
@@ -20,7 +21,7 @@ bool DeviceFactory::getDevicesForProductFamilyOverride(size_t &numDevices, Execu
if (DebugManager.flags.CreateMultipleRootDevices.get()) {
numRootDevices = DebugManager.flags.CreateMultipleRootDevices.get();
}
executionEnvironment.rootDeviceEnvironments.resize(numRootDevices);
executionEnvironment.prepareRootDeviceEnvironments(numRootDevices);
auto productFamily = DebugManager.flags.ProductFamilyOverride.get();
auto hwInfoConst = *platformDevices;
@@ -39,12 +40,14 @@ bool DeviceFactory::getDevicesForProductFamilyOverride(size_t &numDevices, Execu
numDevices = numRootDevices;
DeviceFactory::numDevices = numDevices;
auto csr = DebugManager.flags.SetCommandStreamReceiver.get();
if (csr > 0) {
auto csrType = DebugManager.flags.SetCommandStreamReceiver.get();
if (csrType > 0) {
auto &hwHelper = HwHelper::get(hardwareInfo->platform.eRenderCoreFamily);
auto localMemoryEnabled = hwHelper.getEnableLocalMemory(*hardwareInfo);
executionEnvironment.initAubCenter(localMemoryEnabled, "", static_cast<CommandStreamReceiverType>(csr));
auto aubCenter = executionEnvironment.rootDeviceEnvironments[0].aubCenter.get();
for (auto rootDeviceIndex = 0u; rootDeviceIndex < numRootDevices; rootDeviceIndex++) {
executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->initAubCenter(localMemoryEnabled, "", static_cast<CommandStreamReceiverType>(csrType));
}
auto aubCenter = executionEnvironment.rootDeviceEnvironments[0]->aubCenter.get();
executionEnvironment.memoryOperationsInterface = std::make_unique<AubMemoryOperationsHandler>(aubCenter->getAubManager());
}
return true;

View File

@@ -26,7 +26,7 @@ bool DeviceFactory::getDevices(size_t &numDevices, ExecutionEnvironment &executi
numRootDevices = DebugManager.flags.CreateMultipleRootDevices.get();
}
executionEnvironment.rootDeviceEnvironments.resize(numRootDevices);
executionEnvironment.prepareRootDeviceEnvironments(static_cast<uint32_t>(numRootDevices));
Drm *drm = Drm::create(devNum);
if (!drm) {

View File

@@ -593,7 +593,7 @@ MemoryManager::AllocationStatus DrmMemoryManager::populateOsHandles(OsHandleStor
return AllocationStatus::Success;
}
void DrmMemoryManager::cleanOsHandles(OsHandleStorage &handleStorage) {
void DrmMemoryManager::cleanOsHandles(OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) {
for (unsigned int i = 0; i < maxFragmentsCount; i++) {
if (handleStorage.fragmentStorageData[i].freeTheFragment) {
if (handleStorage.fragmentStorageData[i].osHandleStorage->bo) {

View File

@@ -41,7 +41,7 @@ class DrmMemoryManager : public MemoryManager {
uint64_t getLocalMemorySize() override;
AllocationStatus populateOsHandles(OsHandleStorage &handleStorage) override;
void cleanOsHandles(OsHandleStorage &handleStorage) override;
void cleanOsHandles(OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override;
// drm/i915 ioctl wrappers
MOCKABLE_VIRTUAL uint32_t unreference(BufferObject *bo, bool synchronousDestroy);

View File

@@ -28,7 +28,7 @@ bool DeviceFactory::getDevices(size_t &numDevices, ExecutionEnvironment &executi
numRootDevices = DebugManager.flags.CreateMultipleRootDevices.get();
}
executionEnvironment.rootDeviceEnvironments.resize(numRootDevices);
executionEnvironment.prepareRootDeviceEnvironments(static_cast<uint32_t>(numRootDevices));
auto hardwareInfo = executionEnvironment.getMutableHardwareInfo();
std::unique_ptr<Wddm> wddm(Wddm::createWddm());

View File

@@ -428,7 +428,7 @@ MemoryManager::AllocationStatus WddmMemoryManager::populateOsHandles(OsHandleSto
return AllocationStatus::Success;
}
void WddmMemoryManager::cleanOsHandles(OsHandleStorage &handleStorage) {
void WddmMemoryManager::cleanOsHandles(OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) {
D3DKMT_HANDLE handles[maxFragmentsCount] = {0};
auto allocationCount = 0;

View File

@@ -43,7 +43,7 @@ class WddmMemoryManager : public MemoryManager {
void removeAllocationFromHostPtrManager(GraphicsAllocation *memory) override;
AllocationStatus populateOsHandles(OsHandleStorage &handleStorage) override;
void cleanOsHandles(OsHandleStorage &handleStorage) override;
void cleanOsHandles(OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override;
void obtainGpuAddressFromFragments(WddmAllocation *allocation, OsHandleStorage &handleStorage);

View File

@@ -8,6 +8,7 @@
#include "platform.h"
#include "core/compiler_interface/compiler_interface.h"
#include "core/execution_environment/root_device_environment.h"
#include "core/helpers/debug_helpers.h"
#include "core/helpers/hw_helper.h"
#include "core/helpers/string.h"
@@ -183,7 +184,7 @@ bool Platform::initialize() {
CommandStreamReceiverType csrType = this->devices[0]->getDefaultEngine().commandStreamReceiver->getType();
if (csrType != CommandStreamReceiverType::CSR_HW) {
auto enableLocalMemory = HwHelper::get(hwInfo->platform.eRenderCoreFamily).getEnableLocalMemory(*hwInfo);
executionEnvironment->initAubCenter(enableLocalMemory, "aubfile", csrType);
executionEnvironment->rootDeviceEnvironments[0]->initAubCenter(enableLocalMemory, "aubfile", csrType);
}
this->fillGlobalDispatchTable();