diff --git a/core/execution_environment/root_device_environment.cpp b/core/execution_environment/root_device_environment.cpp index d818e48170..81b2f4f53f 100644 --- a/core/execution_environment/root_device_environment.cpp +++ b/core/execution_environment/root_device_environment.cpp @@ -8,10 +8,16 @@ #include "core/execution_environment/root_device_environment.h" #include "runtime/aub/aub_center.h" +#include "runtime/execution_environment/execution_environment.h" namespace NEO { -RootDeviceEnvironment::RootDeviceEnvironment() = default; -RootDeviceEnvironment::RootDeviceEnvironment(RootDeviceEnvironment &&) = default; +RootDeviceEnvironment::RootDeviceEnvironment(ExecutionEnvironment &executionEnvironment) : executionEnvironment(executionEnvironment) {} RootDeviceEnvironment::~RootDeviceEnvironment() = default; + +void RootDeviceEnvironment::initAubCenter(bool localMemoryEnabled, const std::string &aubFileName, CommandStreamReceiverType csrType) { + if (!aubCenter) { + aubCenter.reset(new AubCenter(executionEnvironment.getHardwareInfo(), localMemoryEnabled, aubFileName, csrType)); + } +} } // namespace NEO diff --git a/core/execution_environment/root_device_environment.h b/core/execution_environment/root_device_environment.h index 8ccc9dbeb9..768dca9571 100644 --- a/core/execution_environment/root_device_environment.h +++ b/core/execution_environment/root_device_environment.h @@ -6,17 +6,25 @@ */ #pragma once +#include "runtime/helpers/options.h" + +#include #include +#include namespace NEO { class AubCenter; +class ExecutionEnvironment; struct RootDeviceEnvironment { - RootDeviceEnvironment(); + RootDeviceEnvironment(ExecutionEnvironment &executionEnvironment); RootDeviceEnvironment(RootDeviceEnvironment &) = delete; - RootDeviceEnvironment(RootDeviceEnvironment &&); - ~RootDeviceEnvironment(); + MOCKABLE_VIRTUAL ~RootDeviceEnvironment(); + + MOCKABLE_VIRTUAL void initAubCenter(bool localMemoryEnabled, const std::string &aubFileName, CommandStreamReceiverType csrType); + std::unique_ptr aubCenter; + ExecutionEnvironment &executionEnvironment; }; } // namespace NEO diff --git a/core/memory_manager/graphics_allocation.h b/core/memory_manager/graphics_allocation.h index 00952b2537..9d147b7178 100644 --- a/core/memory_manager/graphics_allocation.h +++ b/core/memory_manager/graphics_allocation.h @@ -84,7 +84,7 @@ class GraphicsAllocation : public IDNode { GraphicsAllocation(uint32_t rootDeviceIndex, AllocationType allocationType, void *cpuPtrIn, size_t sizeIn, osHandle sharedHandleIn, MemoryPool::Type pool); - uint32_t getRootDeviceIndex() { return rootDeviceIndex; } + uint32_t getRootDeviceIndex() const { return rootDeviceIndex; } void *getUnderlyingBuffer() const { return cpuPtr; } void *getDriverAllocatedCpuPtr() const { return driverAllocatedCpuPointer; } void setDriverAllocatedCpuPtr(void *allocatedCpuPtr) { driverAllocatedCpuPointer = allocatedCpuPtr; } diff --git a/core/memory_manager/host_ptr_manager.cpp b/core/memory_manager/host_ptr_manager.cpp index e2ecf1f142..7f72c629ff 100644 --- a/core/memory_manager/host_ptr_manager.cpp +++ b/core/memory_manager/host_ptr_manager.cpp @@ -240,14 +240,14 @@ FragmentStorage *HostPtrManager::getFragmentAndCheckForOverlaps(const void *inPt return nullptr; } -OsHandleStorage HostPtrManager::prepareOsStorageForAllocation(MemoryManager &memoryManager, size_t size, const void *ptr) { +OsHandleStorage HostPtrManager::prepareOsStorageForAllocation(MemoryManager &memoryManager, size_t size, const void *ptr, uint32_t rootDeviceIndex) { std::lock_guard lock(allocationsMutex); auto requirements = HostPtrManager::getAllocationRequirements(ptr, size); UNRECOVERABLE_IF(checkAllocationsForOverlapping(memoryManager, &requirements) == RequirementsStatus::FATAL); auto osStorage = populateAlreadyAllocatedFragments(requirements); if (osStorage.fragmentCount > 0) { if (memoryManager.populateOsHandles(osStorage) != MemoryManager::AllocationStatus::Success) { - memoryManager.cleanOsHandles(osStorage); + memoryManager.cleanOsHandles(osStorage, rootDeviceIndex); osStorage.fragmentCount = 0; } } diff --git a/core/memory_manager/host_ptr_manager.h b/core/memory_manager/host_ptr_manager.h index 204a7af759..0fa244f0a9 100644 --- a/core/memory_manager/host_ptr_manager.h +++ b/core/memory_manager/host_ptr_manager.h @@ -18,7 +18,7 @@ class MemoryManager; class HostPtrManager { public: FragmentStorage *getFragment(const void *inputPtr); - OsHandleStorage prepareOsStorageForAllocation(MemoryManager &memoryManager, size_t size, const void *ptr); + OsHandleStorage prepareOsStorageForAllocation(MemoryManager &memoryManager, size_t size, const void *ptr, uint32_t rootDeviceIndex); void releaseHandleStorage(OsHandleStorage &fragments); bool releaseHostPtr(const void *ptr); void storeFragment(AllocationStorageData &storageData); diff --git a/runtime/api/api.cpp b/runtime/api/api.cpp index ea3effd3a0..3a09ac5b1a 100644 --- a/runtime/api/api.cpp +++ b/runtime/api/api.cpp @@ -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; diff --git a/runtime/command_stream/aub_command_stream_receiver_hw_base.inl b/runtime/command_stream/aub_command_stream_receiver_hw_base.inl index eef41ab5d1..031ff6f01c 100644 --- a/runtime/command_stream/aub_command_stream_receiver_hw_base.inl +++ b/runtime/command_stream/aub_command_stream_receiver_hw_base.inl @@ -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::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::initializeEngine() { template CommandStreamReceiver *AUBCommandStreamReceiverHw::create(const std::string &fileName, bool standalone, ExecutionEnvironment &executionEnvironment, uint32_t rootDeviceIndex) { - auto csr = new AUBCommandStreamReceiverHw(fileName, standalone, executionEnvironment, rootDeviceIndex); + auto csr = std::make_unique>(fileName, standalone, executionEnvironment, rootDeviceIndex); if (!csr->subCaptureManager->isSubCaptureMode()) { csr->openFile(fileName); } - return csr; + return csr.release(); } template diff --git a/runtime/command_stream/command_stream_receiver_with_aub_dump.inl b/runtime/command_stream/command_stream_receiver_with_aub_dump.inl index 14ab480444..0942af9d12 100644 --- a/runtime/command_stream/command_stream_receiver_with_aub_dump.inl +++ b/runtime/command_stream/command_stream_receiver_with_aub_dump.inl @@ -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 CommandStreamReceiverWithAUBDump::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) { diff --git a/runtime/command_stream/tbx_command_stream_receiver_hw.inl b/runtime/command_stream/tbx_command_stream_receiver_hw.inl index eed13f50ec..c98258854c 100644 --- a/runtime/command_stream/tbx_command_stream_receiver_hw.inl +++ b/runtime/command_stream/tbx_command_stream_receiver_hw.inl @@ -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::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::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>(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(); diff --git a/runtime/execution_environment/execution_environment.cpp b/runtime/execution_environment/execution_environment.cpp index 21a509dc2c..e7ea650da1 100644 --- a/runtime/execution_environment/execution_environment.cpp +++ b/runtime/execution_environment/execution_environment.cpp @@ -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(*this); + } + } +} } // namespace NEO diff --git a/runtime/execution_environment/execution_environment.h b/runtime/execution_environment/execution_environment.h index a92e4cf5be..d2bb9caca2 100644 --- a/runtime/execution_environment/execution_environment.h +++ b/runtime/execution_environment/execution_environment.h @@ -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 @@ -21,8 +19,8 @@ class GmmHelper; class MemoryManager; class MemoryOperationsHandler; class OSInterface; -class RootDevice; class SourceLevelDebugger; +struct RootDeviceEnvironment; struct HardwareInfo; class ExecutionEnvironment : public ReferenceTrackedObject { @@ -38,7 +36,6 @@ class ExecutionEnvironment : public ReferenceTrackedObject 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 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 std::unique_ptr osInterface; std::unique_ptr memoryOperationsInterface; std::unique_ptr memoryManager; - std::vector rootDeviceEnvironments{1}; + std::vector> rootDeviceEnvironments; std::unique_ptr builtins; std::unique_ptr compilerInterface; std::unique_ptr sourceLevelDebugger; diff --git a/runtime/memory_manager/memory_manager.cpp b/runtime/memory_manager/memory_manager.cpp index 9bfda1fe6e..90401cdac7 100644 --- a/runtime/memory_manager/memory_manager.cpp +++ b/runtime/memory_manager/memory_manager.cpp @@ -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) { diff --git a/runtime/memory_manager/memory_manager.h b/runtime/memory_manager/memory_manager.h index adb7170ffe..2b497d2bfb 100644 --- a/runtime/memory_manager/memory_manager.h +++ b/runtime/memory_manager/memory_manager.h @@ -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); diff --git a/runtime/memory_manager/os_agnostic_memory_manager.cpp b/runtime/memory_manager/os_agnostic_memory_manager.cpp index 71d1664fd3..139fe8a3e4 100644 --- a/runtime/memory_manager/os_agnostic_memory_manager.cpp +++ b/runtime/memory_manager/os_agnostic_memory_manager.cpp @@ -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); } diff --git a/runtime/memory_manager/os_agnostic_memory_manager.h b/runtime/memory_manager/os_agnostic_memory_manager.h index 970532db05..9e7740e9d2 100644 --- a/runtime/memory_manager/os_agnostic_memory_manager.h +++ b/runtime/memory_manager/os_agnostic_memory_manager.h @@ -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; diff --git a/runtime/os_interface/device_factory.cpp b/runtime/os_interface/device_factory.cpp index 4997a08ebe..20752d689a 100644 --- a/runtime/os_interface/device_factory.cpp +++ b/runtime/os_interface/device_factory.cpp @@ -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(csr)); - auto aubCenter = executionEnvironment.rootDeviceEnvironments[0].aubCenter.get(); + for (auto rootDeviceIndex = 0u; rootDeviceIndex < numRootDevices; rootDeviceIndex++) { + executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->initAubCenter(localMemoryEnabled, "", static_cast(csrType)); + } + auto aubCenter = executionEnvironment.rootDeviceEnvironments[0]->aubCenter.get(); executionEnvironment.memoryOperationsInterface = std::make_unique(aubCenter->getAubManager()); } return true; diff --git a/runtime/os_interface/linux/device_factory_linux.cpp b/runtime/os_interface/linux/device_factory_linux.cpp index 83d5daa69a..4e6a442d53 100644 --- a/runtime/os_interface/linux/device_factory_linux.cpp +++ b/runtime/os_interface/linux/device_factory_linux.cpp @@ -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(numRootDevices)); Drm *drm = Drm::create(devNum); if (!drm) { diff --git a/runtime/os_interface/linux/drm_memory_manager.cpp b/runtime/os_interface/linux/drm_memory_manager.cpp index 210c3821b5..df45199a61 100644 --- a/runtime/os_interface/linux/drm_memory_manager.cpp +++ b/runtime/os_interface/linux/drm_memory_manager.cpp @@ -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) { diff --git a/runtime/os_interface/linux/drm_memory_manager.h b/runtime/os_interface/linux/drm_memory_manager.h index b53bb7ef02..11fec7e9bb 100644 --- a/runtime/os_interface/linux/drm_memory_manager.h +++ b/runtime/os_interface/linux/drm_memory_manager.h @@ -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); diff --git a/runtime/os_interface/windows/device_factory_win.cpp b/runtime/os_interface/windows/device_factory_win.cpp index e3039f8c97..69fac6b53a 100644 --- a/runtime/os_interface/windows/device_factory_win.cpp +++ b/runtime/os_interface/windows/device_factory_win.cpp @@ -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(numRootDevices)); auto hardwareInfo = executionEnvironment.getMutableHardwareInfo(); std::unique_ptr wddm(Wddm::createWddm()); diff --git a/runtime/os_interface/windows/wddm_memory_manager.cpp b/runtime/os_interface/windows/wddm_memory_manager.cpp index 7f8f8f3bc4..6ded8bfa9c 100644 --- a/runtime/os_interface/windows/wddm_memory_manager.cpp +++ b/runtime/os_interface/windows/wddm_memory_manager.cpp @@ -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; diff --git a/runtime/os_interface/windows/wddm_memory_manager.h b/runtime/os_interface/windows/wddm_memory_manager.h index a03f25b0c3..921d8c5c1c 100644 --- a/runtime/os_interface/windows/wddm_memory_manager.h +++ b/runtime/os_interface/windows/wddm_memory_manager.h @@ -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); diff --git a/runtime/platform/platform.cpp b/runtime/platform/platform.cpp index 750ec270d7..ffc39f248c 100644 --- a/runtime/platform/platform.cpp +++ b/runtime/platform/platform.cpp @@ -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(); diff --git a/unit_tests/api/cl_add_comment_to_aub_tests.inl b/unit_tests/api/cl_add_comment_to_aub_tests.inl index c511291eee..1503a553b6 100644 --- a/unit_tests/api/cl_add_comment_to_aub_tests.inl +++ b/unit_tests/api/cl_add_comment_to_aub_tests.inl @@ -5,6 +5,7 @@ * */ +#include "core/execution_environment/root_device_environment.h" #include "runtime/execution_environment/execution_environment.h" #include "runtime/platform/platform.h" #include "unit_tests/api/cl_api_tests.h" @@ -28,7 +29,7 @@ TEST_F(clAddCommentToAubTest, givenNullptrCommentWhenAddCommentToAubThenErrorIsR } TEST_F(clAddCommentToAubTest, givenAubCenterAndProperCommentButNullptrAubManagerWhenAddCommentToAubThenErrorIsReturned) { - pPlatform->peekExecutionEnvironment()->rootDeviceEnvironments[0].aubCenter.reset(new MockAubCenter()); + pPlatform->peekExecutionEnvironment()->rootDeviceEnvironments[0]->aubCenter.reset(new MockAubCenter()); auto retVal = clAddCommentINTEL(pPlatform, "comment"); EXPECT_EQ(CL_INVALID_VALUE, retVal); @@ -46,7 +47,7 @@ TEST_F(clAddCommentToAubTest, givenProperCommentAubCenterAndAubManagerWhenAddCom auto mockAubCenter = new MockAubCenter(); auto mockAubManager = new AubManagerCommentMock; mockAubCenter->aubManager.reset(mockAubManager); - pPlatform->peekExecutionEnvironment()->rootDeviceEnvironments[0].aubCenter.reset(mockAubCenter); + pPlatform->peekExecutionEnvironment()->rootDeviceEnvironments[0]->aubCenter.reset(mockAubCenter); EXPECT_FALSE(mockAubManager->addCommentCalled); diff --git a/unit_tests/command_stream/aub_command_stream_receiver_1_tests.cpp b/unit_tests/command_stream/aub_command_stream_receiver_1_tests.cpp index b225f8795b..2eba3cc102 100644 --- a/unit_tests/command_stream/aub_command_stream_receiver_1_tests.cpp +++ b/unit_tests/command_stream/aub_command_stream_receiver_1_tests.cpp @@ -80,7 +80,7 @@ TEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenTypeIsChe HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenItIsCreatedThenAubManagerAndHardwareContextAreNull) { DebugManagerStateRestore restorer; DebugManager.flags.UseAubStream.set(false); - MockExecutionEnvironment executionEnvironment(platformDevices[0], false); + MockExecutionEnvironment executionEnvironment(platformDevices[0], false, 1); executionEnvironment.initializeMemoryManager(); auto aubCsr = std::make_unique>("", true, executionEnvironment, 0); @@ -118,40 +118,40 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenMultipl HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenMultipleInstancesAreCreatedThenTheyUseTheSameFileStream) { auto aubCsr1 = std::make_unique>("", true, *pDevice->executionEnvironment, pDevice->getRootDeviceIndex()); - auto streamProvider1 = pDevice->executionEnvironment->rootDeviceEnvironments[0].aubCenter->getStreamProvider(); + auto streamProvider1 = pDevice->executionEnvironment->rootDeviceEnvironments[0]->aubCenter->getStreamProvider(); EXPECT_NE(nullptr, streamProvider1); auto aubCsr2 = std::make_unique>("", true, *pDevice->executionEnvironment, pDevice->getRootDeviceIndex()); - auto streamProvider2 = pDevice->executionEnvironment->rootDeviceEnvironments[0].aubCenter->getStreamProvider(); + auto streamProvider2 = pDevice->executionEnvironment->rootDeviceEnvironments[0]->aubCenter->getStreamProvider(); EXPECT_NE(nullptr, streamProvider2); EXPECT_EQ(streamProvider1, streamProvider2); } HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenMultipleInstancesAreCreatedThenTheyUseTheSamePhysicalAddressAllocator) { auto aubCsr1 = std::make_unique>("", true, *pDevice->executionEnvironment, pDevice->getRootDeviceIndex()); - auto physicalAddressAlocator1 = pDevice->executionEnvironment->rootDeviceEnvironments[0].aubCenter->getPhysicalAddressAllocator(); + auto physicalAddressAlocator1 = pDevice->executionEnvironment->rootDeviceEnvironments[0]->aubCenter->getPhysicalAddressAllocator(); EXPECT_NE(nullptr, physicalAddressAlocator1); auto aubCsr2 = std::make_unique>("", true, *pDevice->executionEnvironment, pDevice->getRootDeviceIndex()); - auto physicalAddressAlocator2 = pDevice->executionEnvironment->rootDeviceEnvironments[0].aubCenter->getPhysicalAddressAllocator(); + auto physicalAddressAlocator2 = pDevice->executionEnvironment->rootDeviceEnvironments[0]->aubCenter->getPhysicalAddressAllocator(); EXPECT_NE(nullptr, physicalAddressAlocator2); EXPECT_EQ(physicalAddressAlocator1, physicalAddressAlocator2); } HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenMultipleInstancesAreCreatedThenTheyUseTheSameAddressMapper) { auto aubCsr1 = std::make_unique>("", true, *pDevice->executionEnvironment, pDevice->getRootDeviceIndex()); - auto addressMapper1 = pDevice->executionEnvironment->rootDeviceEnvironments[0].aubCenter->getAddressMapper(); + auto addressMapper1 = pDevice->executionEnvironment->rootDeviceEnvironments[0]->aubCenter->getAddressMapper(); EXPECT_NE(nullptr, addressMapper1); auto aubCsr2 = std::make_unique>("", true, *pDevice->executionEnvironment, pDevice->getRootDeviceIndex()); - auto addressMapper2 = pDevice->executionEnvironment->rootDeviceEnvironments[0].aubCenter->getAddressMapper(); + auto addressMapper2 = pDevice->executionEnvironment->rootDeviceEnvironments[0]->aubCenter->getAddressMapper(); EXPECT_NE(nullptr, addressMapper2); EXPECT_EQ(addressMapper1, addressMapper2); } HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenMultipleInstancesAreCreatedThenTheyUseTheSameSubCaptureCommon) { auto aubCsr1 = std::make_unique>("", true, *pDevice->executionEnvironment, pDevice->getRootDeviceIndex()); - auto subCaptureCommon1 = pDevice->executionEnvironment->rootDeviceEnvironments[0].aubCenter->getSubCaptureCommon(); + auto subCaptureCommon1 = pDevice->executionEnvironment->rootDeviceEnvironments[0]->aubCenter->getSubCaptureCommon(); EXPECT_NE(nullptr, subCaptureCommon1); auto aubCsr2 = std::make_unique>("", true, *pDevice->executionEnvironment, pDevice->getRootDeviceIndex()); - auto subCaptureCommon2 = pDevice->executionEnvironment->rootDeviceEnvironments[0].aubCenter->getSubCaptureCommon(); + auto subCaptureCommon2 = pDevice->executionEnvironment->rootDeviceEnvironments[0]->aubCenter->getSubCaptureCommon(); EXPECT_NE(nullptr, subCaptureCommon2); EXPECT_EQ(subCaptureCommon1, subCaptureCommon2); } @@ -161,7 +161,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWithAubMana MockAubManager *mockManager = new MockAubManager(); MockAubCenter *mockAubCenter = new MockAubCenter(platformDevices[0], false, fileName, CommandStreamReceiverType::CSR_AUB); mockAubCenter->aubManager = std::unique_ptr(mockManager); - pDevice->executionEnvironment->rootDeviceEnvironments[0].aubCenter = std::unique_ptr(mockAubCenter); + pDevice->executionEnvironment->rootDeviceEnvironments[0]->aubCenter = std::unique_ptr(mockAubCenter); std::unique_ptr> aubCsr(static_cast *>(AUBCommandStreamReceiver::create(fileName, true, *pDevice->executionEnvironment, pDevice->getRootDeviceIndex()))); ASSERT_NE(nullptr, aubCsr); @@ -177,7 +177,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCsrWhenOsContextIsSetThenCreateH MockAubManager *mockManager = new MockAubManager(); MockAubCenter *mockAubCenter = new MockAubCenter(platformDevices[0], false, fileName, CommandStreamReceiverType::CSR_AUB); mockAubCenter->aubManager = std::unique_ptr(mockManager); - pDevice->executionEnvironment->rootDeviceEnvironments[0].aubCenter = std::unique_ptr(mockAubCenter); + pDevice->executionEnvironment->rootDeviceEnvironments[0]->aubCenter = std::unique_ptr(mockAubCenter); std::unique_ptr> aubCsr(static_cast *>(AUBCommandStreamReceiver::create(fileName, true, *pDevice->executionEnvironment, pDevice->getRootDeviceIndex()))); EXPECT_EQ(nullptr, aubCsr->hardwareContextController.get()); @@ -194,7 +194,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCsrWhenLowPriorityOsContextIsSet MockAubManager *mockManager = new MockAubManager(); MockAubCenter *mockAubCenter = new MockAubCenter(platformDevices[0], false, fileName, CommandStreamReceiverType::CSR_AUB); mockAubCenter->aubManager = std::unique_ptr(mockManager); - pDevice->executionEnvironment->rootDeviceEnvironments[0].aubCenter = std::unique_ptr(mockAubCenter); + pDevice->executionEnvironment->rootDeviceEnvironments[0]->aubCenter = std::unique_ptr(mockAubCenter); std::unique_ptr> aubCsr(static_cast *>(AUBCommandStreamReceiver::create(fileName, true, *pDevice->executionEnvironment, pDevice->getRootDeviceIndex()))); EXPECT_EQ(nullptr, aubCsr->hardwareContextController.get()); @@ -251,7 +251,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenGraphicsAllocationWhenMakeResidentC } HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenMultipleInstancesInitializeTheirEnginesThenUniqueGlobalGttAdressesAreGenerated) { - pDevice->executionEnvironment->rootDeviceEnvironments[0].aubCenter.reset(new AubCenter()); + pDevice->executionEnvironment->rootDeviceEnvironments[0]->aubCenter.reset(new AubCenter()); auto engineInstance = HwHelper::get(platformDevices[0]->platform.eRenderCoreFamily).getGpgpuEngineInstances()[0]; MockOsContext osContext(0, 1, engineInstance, PreemptionMode::Disabled, false); diff --git a/unit_tests/command_stream/aub_command_stream_receiver_2_tests.cpp b/unit_tests/command_stream/aub_command_stream_receiver_2_tests.cpp index 43f984d566..4ad4a78f69 100644 --- a/unit_tests/command_stream/aub_command_stream_receiver_2_tests.cpp +++ b/unit_tests/command_stream/aub_command_stream_receiver_2_tests.cpp @@ -648,7 +648,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenProcess } HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenWriteMemoryIsCalledThenGraphicsAllocationSizeIsReadCorrectly) { - pDevice->executionEnvironment->rootDeviceEnvironments[0].aubCenter.reset(new AubCenter()); + pDevice->executionEnvironment->rootDeviceEnvironments[0]->aubCenter.reset(new AubCenter()); auto aubCsr = std::make_unique>("", false, *pDevice->executionEnvironment, pDevice->getRootDeviceIndex()); aubCsr->setupContext(*pDevice->getDefaultEngine().osContext); @@ -896,7 +896,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenCompressedGraphicsAllocationWritabl MockAubCenter *mockAubCenter = new MockAubCenter(platformDevices[0], false, "aubfile", CommandStreamReceiverType::CSR_AUB); mockAubCenter->aubManager = std::make_unique(); - pDevice->executionEnvironment->rootDeviceEnvironments[0].aubCenter.reset(mockAubCenter); + pDevice->executionEnvironment->rootDeviceEnvironments[0]->aubCenter.reset(mockAubCenter); MockAubCsr aubCsr("", true, *pDevice->executionEnvironment, pDevice->getRootDeviceIndex()); MockOsContext osContext(0, 1, aub_stream::ENGINE_RCS, PreemptionMode::Disabled, false); aubCsr.setupContext(osContext); @@ -1032,3 +1032,21 @@ HWTEST_F(AubCommandStreamReceiverTests, givenGraphicsAllocationWritableWhenDumpA memoryManager->freeGraphicsMemory(gfxAllocation); } + +using SimulatedCsrTest = ::testing::Test; +HWTEST_F(SimulatedCsrTest, givenAubCsrTypeWhenCreateCommandStreamReceiverThenProperAubCenterIsInitalized) { + uint32_t expectedRootDeviceIndex = 10; + ExecutionEnvironment executionEnvironment; + executionEnvironment.initializeMemoryManager(); + executionEnvironment.prepareRootDeviceEnvironments(expectedRootDeviceIndex + 2); + + auto rootDeviceEnvironment = new MockRootDeviceEnvironment(executionEnvironment); + executionEnvironment.rootDeviceEnvironments[expectedRootDeviceIndex].reset(rootDeviceEnvironment); + + EXPECT_EQ(nullptr, executionEnvironment.rootDeviceEnvironments[expectedRootDeviceIndex]->aubCenter.get()); + EXPECT_FALSE(rootDeviceEnvironment->initAubCenterCalled); + + auto csr = std::make_unique>("", true, executionEnvironment, expectedRootDeviceIndex); + EXPECT_TRUE(rootDeviceEnvironment->initAubCenterCalled); + EXPECT_NE(nullptr, executionEnvironment.rootDeviceEnvironments[expectedRootDeviceIndex]->aubCenter.get()); +} diff --git a/unit_tests/command_stream/command_stream_receiver_tests.cpp b/unit_tests/command_stream/command_stream_receiver_tests.cpp index d56c3f9f87..6084b0b509 100644 --- a/unit_tests/command_stream/command_stream_receiver_tests.cpp +++ b/unit_tests/command_stream/command_stream_receiver_tests.cpp @@ -227,6 +227,7 @@ HWTEST_F(CommandStreamReceiverTest, givenCsrWhenAllocateHeapMemoryIsCalledThenHe TEST(CommandStreamReceiverSimpleTest, givenCSRWithoutTagAllocationWhenGetTagAllocationIsCalledThenNullptrIsReturned) { ExecutionEnvironment executionEnvironment; + executionEnvironment.prepareRootDeviceEnvironments(1); executionEnvironment.initializeMemoryManager(); MockCommandStreamReceiver csr(executionEnvironment, 0); EXPECT_EQ(nullptr, csr.getTagAllocation()); @@ -337,6 +338,7 @@ TEST(CommandStreamReceiverSimpleTest, givenNullHardwareDebugModeWhenInitializeTa TEST(CommandStreamReceiverSimpleTest, givenVariousDataSetsWhenVerifyingMemoryThenCorrectValueIsReturned) { ExecutionEnvironment executionEnvironment; + executionEnvironment.prepareRootDeviceEnvironments(1); executionEnvironment.initializeMemoryManager(); MockCommandStreamReceiver csr(executionEnvironment, 0); @@ -593,6 +595,7 @@ HWTEST_P(CommandStreamReceiverWithAubSubCaptureTest, givenCommandStreamReceiverW bool isActive = status.second; ExecutionEnvironment executionEnvironment; + executionEnvironment.prepareRootDeviceEnvironments(1); executionEnvironment.initializeMemoryManager(); MyMockCsr mockCsr(executionEnvironment, 0); @@ -615,20 +618,22 @@ INSTANTIATE_TEST_CASE_P( testing::ValuesIn(aubSubCaptureStatus)); TEST(CommandStreamReceiverDeviceIndexTest, givenCsrWithOsContextWhenGetDeviceIndexThenGetHighestEnabledBitInDeviceBitfield) { - ExecutionEnvironment executioneEnvironment; - executioneEnvironment.initializeMemoryManager(); - MockCommandStreamReceiver csr(executioneEnvironment, 0); - auto osContext = executioneEnvironment.memoryManager->createAndRegisterOsContext(&csr, aub_stream::EngineType::ENGINE_RCS, 0b10, PreemptionMode::Disabled, false); + ExecutionEnvironment executionEnvironment; + executionEnvironment.prepareRootDeviceEnvironments(1); + executionEnvironment.initializeMemoryManager(); + MockCommandStreamReceiver csr(executionEnvironment, 0); + auto osContext = executionEnvironment.memoryManager->createAndRegisterOsContext(&csr, aub_stream::EngineType::ENGINE_RCS, 0b10, PreemptionMode::Disabled, false); csr.setupContext(*osContext); EXPECT_EQ(1u, csr.getDeviceIndex()); } TEST(CommandStreamReceiverDeviceIndexTest, givenOsContextWithNoDeviceBitfieldWhenGettingDeviceIndexThenZeroIsReturned) { - ExecutionEnvironment executioneEnvironment; - executioneEnvironment.initializeMemoryManager(); - MockCommandStreamReceiver csr(executioneEnvironment, 0); - auto osContext = executioneEnvironment.memoryManager->createAndRegisterOsContext(&csr, aub_stream::EngineType::ENGINE_RCS, 0b00, PreemptionMode::Disabled, false); + ExecutionEnvironment executionEnvironment; + executionEnvironment.prepareRootDeviceEnvironments(1); + executionEnvironment.initializeMemoryManager(); + MockCommandStreamReceiver csr(executionEnvironment, 0); + auto osContext = executionEnvironment.memoryManager->createAndRegisterOsContext(&csr, aub_stream::EngineType::ENGINE_RCS, 0b00, PreemptionMode::Disabled, false); csr.setupContext(*osContext); EXPECT_EQ(0u, csr.getDeviceIndex()); @@ -639,7 +644,7 @@ TEST(CommandStreamReceiverRootDeviceIndexTest, commandStreamGraphicsAllocationsH // Setup auto executionEnvironment = platformImpl->peekExecutionEnvironment(); - executionEnvironment->rootDeviceEnvironments.resize(2 * expectedRootDeviceIndex); + executionEnvironment->prepareRootDeviceEnvironments(2 * expectedRootDeviceIndex); auto memoryManager = new MockMemoryManager(false, false, *executionEnvironment); executionEnvironment->memoryManager.reset(memoryManager); std::unique_ptr device(Device::create(executionEnvironment, expectedRootDeviceIndex)); diff --git a/unit_tests/command_stream/command_stream_receiver_with_aub_dump_tests.cpp b/unit_tests/command_stream/command_stream_receiver_with_aub_dump_tests.cpp index 2205b9fa5c..7237951884 100644 --- a/unit_tests/command_stream/command_stream_receiver_with_aub_dump_tests.cpp +++ b/unit_tests/command_stream/command_stream_receiver_with_aub_dump_tests.cpp @@ -153,7 +153,7 @@ HWTEST_F(CommandStreamReceiverWithAubDumpSimpleTest, givenAubManagerAvailableWhe MockAubManager *mockManager = new MockAubManager(); MockAubCenter *mockAubCenter = new MockAubCenter(*platformDevices, false, fileName, CommandStreamReceiverType::CSR_TBX_WITH_AUB); mockAubCenter->aubManager = std::unique_ptr(mockManager); - executionEnvironment->rootDeviceEnvironments[0].aubCenter = std::unique_ptr(mockAubCenter); + executionEnvironment->rootDeviceEnvironments[0]->aubCenter = std::unique_ptr(mockAubCenter); CommandStreamReceiverWithAUBDump> csrWithAubDump("aubfile", *executionEnvironment, 0); ASSERT_EQ(nullptr, csrWithAubDump.aubCSR); @@ -167,17 +167,51 @@ HWTEST_F(CommandStreamReceiverWithAubDumpSimpleTest, givenAubManagerAvailableWhe ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); executionEnvironment->initializeMemoryManager(); - executionEnvironment->rootDeviceEnvironments[0].aubCenter = std::unique_ptr(mockAubCenter); + executionEnvironment->rootDeviceEnvironments[0]->aubCenter = std::unique_ptr(mockAubCenter); CommandStreamReceiverWithAUBDump> csrWithAubDump("aubfile", *executionEnvironment, 0); ASSERT_NE(nullptr, csrWithAubDump.aubCSR); } +using SimulatedCsrTest = ::testing::Test; +HWTEST_F(SimulatedCsrTest, givenHwWithAubDumpCsrTypeWhenCreateCommandStreamReceiverThenProperAubCenterIsInitialized) { + uint32_t expectedRootDeviceIndex = 10; + ExecutionEnvironment executionEnvironment; + executionEnvironment.initializeMemoryManager(); + executionEnvironment.prepareRootDeviceEnvironments(expectedRootDeviceIndex + 2); + + auto rootDeviceEnvironment = new MockRootDeviceEnvironment(executionEnvironment); + executionEnvironment.rootDeviceEnvironments[expectedRootDeviceIndex].reset(rootDeviceEnvironment); + + EXPECT_EQ(nullptr, executionEnvironment.rootDeviceEnvironments[expectedRootDeviceIndex]->aubCenter.get()); + EXPECT_FALSE(rootDeviceEnvironment->initAubCenterCalled); + + auto csr = std::make_unique>>("", executionEnvironment, expectedRootDeviceIndex); + EXPECT_TRUE(rootDeviceEnvironment->initAubCenterCalled); + EXPECT_NE(nullptr, rootDeviceEnvironment->aubCenter.get()); +} +HWTEST_F(SimulatedCsrTest, givenTbxWithAubDumpCsrTypeWhenCreateCommandStreamReceiverThenProperAubCenterIsInitialized) { + uint32_t expectedRootDeviceIndex = 10; + ExecutionEnvironment executionEnvironment; + executionEnvironment.initializeMemoryManager(); + executionEnvironment.prepareRootDeviceEnvironments(expectedRootDeviceIndex + 2); + + auto rootDeviceEnvironment = new MockRootDeviceEnvironment(executionEnvironment); + executionEnvironment.rootDeviceEnvironments[expectedRootDeviceIndex].reset(rootDeviceEnvironment); + + EXPECT_EQ(nullptr, executionEnvironment.rootDeviceEnvironments[expectedRootDeviceIndex]->aubCenter.get()); + EXPECT_FALSE(rootDeviceEnvironment->initAubCenterCalled); + + auto csr = std::make_unique>>("", executionEnvironment, expectedRootDeviceIndex); + EXPECT_TRUE(rootDeviceEnvironment->initAubCenterCalled); + EXPECT_NE(nullptr, rootDeviceEnvironment->aubCenter.get()); +} + HWTEST_F(CommandStreamReceiverWithAubDumpSimpleTest, givenNullAubManagerAvailableWhenTbxCsrWithAubDumpIsCreatedThenAubCsrIsCreated) { MockAubCenter *mockAubCenter = new MockAubCenter(); ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); executionEnvironment->initializeMemoryManager(); - executionEnvironment->rootDeviceEnvironments[0].aubCenter = std::unique_ptr(mockAubCenter); + executionEnvironment->rootDeviceEnvironments[0]->aubCenter = std::unique_ptr(mockAubCenter); CommandStreamReceiverWithAUBDump> csrWithAubDump("aubfile", *executionEnvironment, 0); EXPECT_NE(nullptr, csrWithAubDump.aubCSR); diff --git a/unit_tests/command_stream/create_command_stream_receiver_tests.cpp b/unit_tests/command_stream/create_command_stream_receiver_tests.cpp index b5d590fb5b..87ddf2ef02 100644 --- a/unit_tests/command_stream/create_command_stream_receiver_tests.cpp +++ b/unit_tests/command_stream/create_command_stream_receiver_tests.cpp @@ -25,7 +25,7 @@ HWTEST_P(CreateCommandStreamReceiverTest, givenCreateCommandStreamWhenCsrIsSetTo DebugManagerStateRestore stateRestorer; HardwareInfo *hwInfo = nullptr; ExecutionEnvironment *executionEnvironment = getExecutionEnvironmentImpl(hwInfo); - MockAubCenterFixture::setMockAubCenter(executionEnvironment); + MockAubCenterFixture::setMockAubCenter(*executionEnvironment->rootDeviceEnvironments[0]); CommandStreamReceiverType csrType = GetParam(); diff --git a/unit_tests/command_stream/experimental_command_buffer_tests.cpp b/unit_tests/command_stream/experimental_command_buffer_tests.cpp index 1383dba852..40a7145443 100644 --- a/unit_tests/command_stream/experimental_command_buffer_tests.cpp +++ b/unit_tests/command_stream/experimental_command_buffer_tests.cpp @@ -359,7 +359,7 @@ TEST(ExperimentalCommandBufferRootDeviceIndexTest, experimentalCommandBufferGrap // Setup auto executionEnvironment = platformImpl->peekExecutionEnvironment(); - executionEnvironment->rootDeviceEnvironments.resize(2 * expectedRootDeviceIndex); + executionEnvironment->prepareRootDeviceEnvironments(2 * expectedRootDeviceIndex); auto memoryManager = new MockMemoryManager(false, false, *executionEnvironment); executionEnvironment->memoryManager.reset(memoryManager); std::unique_ptr device(Device::create(executionEnvironment, expectedRootDeviceIndex)); diff --git a/unit_tests/command_stream/tbx_command_stream_tests.cpp b/unit_tests/command_stream/tbx_command_stream_tests.cpp index fb144d0872..b56a737fc3 100644 --- a/unit_tests/command_stream/tbx_command_stream_tests.cpp +++ b/unit_tests/command_stream/tbx_command_stream_tests.cpp @@ -59,7 +59,7 @@ struct TbxFixture : public TbxCommandStreamFixture, void SetUp() { DeviceFixture::SetUp(); - setMockAubCenter(pDevice->getExecutionEnvironment()); + setMockAubCenter(*pDevice->getExecutionEnvironment()->rootDeviceEnvironments[0]); TbxCommandStreamFixture::SetUp(pDevice); MockAubCenterFixture::SetUp(); } @@ -460,11 +460,11 @@ HWTEST_F(TbxCommandSteamSimpleTest, givenTbxCommandStreamReceiverWhenPhysicalAdd HWTEST_F(TbxCommandStreamTests, givenTbxCommandStreamReceiverWhenItIsCreatedWithUseAubStreamFalseThenDontInitializeAubManager) { DebugManagerStateRestore dbgRestore; DebugManager.flags.UseAubStream.set(false); - MockExecutionEnvironment executionEnvironment(platformDevices[0], false); + MockExecutionEnvironment executionEnvironment(platformDevices[0], false, 1); executionEnvironment.initializeMemoryManager(); auto tbxCsr = std::make_unique>(executionEnvironment, 0); - EXPECT_EQ(nullptr, executionEnvironment.rootDeviceEnvironments[0].aubCenter->getAubManager()); + EXPECT_EQ(nullptr, executionEnvironment.rootDeviceEnvironments[0]->aubCenter->getAubManager()); } HWTEST_F(TbxCommandStreamTests, givenTbxCommandStreamReceiverWhenFlushIsCalledThenItShouldCallTheExpectedHwContextFunctions) { @@ -559,7 +559,7 @@ HWTEST_F(TbxCommandStreamTests, givenTbxCsrWhenHardwareContextIsCreatedThenTbxSt MockAubCenter *mockAubCenter = new MockAubCenter(pDevice->executionEnvironment->getHardwareInfo(), false, "", CommandStreamReceiverType::CSR_TBX); mockAubCenter->aubManager = std::unique_ptr(mockManager); - pDevice->executionEnvironment->rootDeviceEnvironments[0].aubCenter = std::unique_ptr(mockAubCenter); + pDevice->executionEnvironment->rootDeviceEnvironments[0]->aubCenter = std::unique_ptr(mockAubCenter); auto tbxCsr = std::unique_ptr>(reinterpret_cast *>( TbxCommandStreamReceiverHw::create("", false, *pDevice->executionEnvironment, pDevice->getRootDeviceIndex()))); @@ -575,7 +575,7 @@ HWTEST_F(TbxCommandStreamTests, givenTbxCsrWhenOsContextIsSetThenCreateHardwareC MockAubCenter *mockAubCenter = new MockAubCenter(hwInfo, false, fileName, CommandStreamReceiverType::CSR_TBX); mockAubCenter->aubManager = std::unique_ptr(mockManager); - pDevice->executionEnvironment->rootDeviceEnvironments[0].aubCenter = std::unique_ptr(mockAubCenter); + pDevice->executionEnvironment->rootDeviceEnvironments[0]->aubCenter = std::unique_ptr(mockAubCenter); std::unique_ptr> tbxCsr(reinterpret_cast *>(TbxCommandStreamReceiver::create(fileName, false, *pDevice->executionEnvironment, pDevice->getRootDeviceIndex()))); EXPECT_EQ(nullptr, tbxCsr->hardwareContextController.get()); @@ -598,12 +598,13 @@ HWTEST_F(TbxCommandStreamTests, givenTbxCsrWhenCreatedWithAubDumpThenFileNameIsE executionEnvironment.setHwInfo(*platformDevices); executionEnvironment.initializeMemoryManager(); - setMockAubCenter(&executionEnvironment, CommandStreamReceiverType::CSR_TBX); + auto rootDeviceEnvironment = static_cast(executionEnvironment.rootDeviceEnvironments[0].get()); + setMockAubCenter(*rootDeviceEnvironment, CommandStreamReceiverType::CSR_TBX); auto fullName = AUBCommandStreamReceiver::createFullFilePath(*platformDevices[0], "aubfile"); std::unique_ptr> tbxCsr(reinterpret_cast *>(TbxCommandStreamReceiver::create("aubfile", true, executionEnvironment, 0))); - EXPECT_STREQ(fullName.c_str(), executionEnvironment.aubFileNameReceived.c_str()); + EXPECT_STREQ(fullName.c_str(), rootDeviceEnvironment->aubFileNameReceived.c_str()); } HWTEST_F(TbxCommandStreamTests, givenTbxCsrWhenCreatedWithAubDumpThenOpenIsCalledOnAubManagerToOpenFileStream) { @@ -616,6 +617,24 @@ HWTEST_F(TbxCommandStreamTests, givenTbxCsrWhenCreatedWithAubDumpThenOpenIsCalle EXPECT_TRUE(tbxCsrWithAubDump->aubManager->isOpen()); } +using SimulatedCsrTest = ::testing::Test; +HWTEST_F(SimulatedCsrTest, givenTbxCsrTypeWhenCreateCommandStreamReceiverThenProperAubCenterIsInitalized) { + uint32_t expectedRootDeviceIndex = 10; + ExecutionEnvironment executionEnvironment; + executionEnvironment.initializeMemoryManager(); + executionEnvironment.prepareRootDeviceEnvironments(expectedRootDeviceIndex + 2); + + auto rootDeviceEnvironment = new MockRootDeviceEnvironment(executionEnvironment); + executionEnvironment.rootDeviceEnvironments[expectedRootDeviceIndex].reset(rootDeviceEnvironment); + + EXPECT_EQ(nullptr, executionEnvironment.rootDeviceEnvironments[expectedRootDeviceIndex]->aubCenter.get()); + EXPECT_FALSE(rootDeviceEnvironment->initAubCenterCalled); + + auto csr = std::make_unique>(executionEnvironment, expectedRootDeviceIndex); + EXPECT_NE(nullptr, executionEnvironment.rootDeviceEnvironments[expectedRootDeviceIndex]->aubCenter.get()); + EXPECT_TRUE(rootDeviceEnvironment->initAubCenterCalled); +} + HWTEST_F(TbxCommandStreamTests, givenTbxCsrWhenCreatedWithAubDumpInSubCaptureModeThenCreateSubCaptureManagerAndGenerateSubCaptureFileName) { DebugManagerStateRestore dbgRestore; DebugManager.flags.AUBDumpSubCaptureMode.set(static_cast(AubSubCaptureManager::SubCaptureMode::Filter)); @@ -636,7 +655,7 @@ HWTEST_F(TbxCommandStreamTests, givenTbxCsrWhenCreatedWithAubDumpInSubCaptureMod } HWTEST_F(TbxCommandStreamTests, givenTbxCsrWhenCreatedWithAubDumpSeveralTimesThenOpenIsCalledOnAubManagerOnceOnly) { - MockExecutionEnvironment executionEnvironment(*platformDevices, true); + MockExecutionEnvironment executionEnvironment(*platformDevices, true, 1); executionEnvironment.setHwInfo(*platformDevices); executionEnvironment.initializeMemoryManager(); @@ -646,7 +665,7 @@ HWTEST_F(TbxCommandStreamTests, givenTbxCsrWhenCreatedWithAubDumpSeveralTimesThe auto tbxCsrWithAubDump2 = std::unique_ptr>(reinterpret_cast *>( TbxCommandStreamReceiverHw::create("aubfile", true, executionEnvironment, 0))); - auto mockManager = reinterpret_cast(executionEnvironment.rootDeviceEnvironments[0].aubCenter->getAubManager()); + auto mockManager = reinterpret_cast(executionEnvironment.rootDeviceEnvironments[0]->aubCenter->getAubManager()); EXPECT_EQ(1u, mockManager->openCalledCnt); } @@ -667,7 +686,7 @@ HWTEST_F(TbxCommandStreamTests, givenTbxCsrInSubCaptureModeWhenFlushIsCalledAndS tbxCsr.flush(batchBuffer, allocationsForResidency); - auto mockAubManager = reinterpret_cast(pDevice->executionEnvironment->rootDeviceEnvironments[0].aubCenter->getAubManager()); + auto mockAubManager = reinterpret_cast(pDevice->executionEnvironment->rootDeviceEnvironments[0]->aubCenter->getAubManager()); EXPECT_TRUE(mockAubManager->isPaused); pDevice->executionEnvironment->memoryManager->freeGraphicsMemory(commandBuffer); @@ -691,7 +710,7 @@ HWTEST_F(TbxCommandStreamTests, givenTbxCsrInSubCaptureModeWhenFlushIsCalledAndS tbxCsr.flush(batchBuffer, allocationsForResidency); - auto mockAubManager = reinterpret_cast(pDevice->executionEnvironment->rootDeviceEnvironments[0].aubCenter->getAubManager()); + auto mockAubManager = reinterpret_cast(pDevice->executionEnvironment->rootDeviceEnvironments[0]->aubCenter->getAubManager()); EXPECT_FALSE(mockAubManager->isPaused); pDevice->executionEnvironment->memoryManager->freeGraphicsMemory(commandBuffer); diff --git a/unit_tests/device/device_caps_tests.cpp b/unit_tests/device/device_caps_tests.cpp index 8280dfc829..0c41085d3f 100644 --- a/unit_tests/device/device_caps_tests.cpp +++ b/unit_tests/device/device_caps_tests.cpp @@ -197,6 +197,7 @@ TEST(DeviceGetCapsTest, givenDeviceWithMidThreadPreemptionWhenDeviceIsCreatedThe DebugManager.flags.ForcePreemptionMode.set((int32_t)PreemptionMode::MidThread); auto executionEnvironment = new ExecutionEnvironment(); + executionEnvironment->prepareRootDeviceEnvironments(1); executionEnvironment->builtins.reset(builtIns); auto device = std::unique_ptr(MockDevice::createWithExecutionEnvironment(platformDevices[0], executionEnvironment, 0u)); ASSERT_EQ(builtIns, device->getExecutionEnvironment()->getBuiltIns()); @@ -817,6 +818,7 @@ TEST(DeviceGetCapsTest, GivenFlagEnabled64kbPagesWhenSetThenReturnCorrectValue) VariableBackup OsEnabled64kbPagesBackup(&OSInterface::osEnabled64kbPages); ExecutionEnvironment executionEnvironment; + executionEnvironment.prepareRootDeviceEnvironments(1); auto &capabilityTable = executionEnvironment.getMutableHardwareInfo()->capabilityTable; std::unique_ptr memoryManager; diff --git a/unit_tests/device/device_tests.cpp b/unit_tests/device/device_tests.cpp index 2d0034cec9..abda216bf2 100644 --- a/unit_tests/device/device_tests.cpp +++ b/unit_tests/device/device_tests.cpp @@ -185,7 +185,7 @@ TEST(DeviceCreation, givenDeviceWhenItIsCreatedThenOsContextIsRegistredInMemoryM TEST(DeviceCreation, givenMultiRootDeviceWhenTheyAreCreatedThenEachOsContextHasUniqueId) { ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); const size_t numDevices = 2; - executionEnvironment->rootDeviceEnvironments.resize(numDevices); + executionEnvironment->prepareRootDeviceEnvironments(numDevices); const auto &numGpgpuEngines = static_cast(HwHelper::get(platformDevices[0]->platform.eRenderCoreFamily).getGpgpuEngineInstances().size()); auto device1 = std::unique_ptr(Device::create(executionEnvironment, 0u)); @@ -211,7 +211,7 @@ TEST(DeviceCreation, givenMultiRootDeviceWhenTheyAreCreatedThenEachOsContextHasU TEST(DeviceCreation, givenMultiRootDeviceWhenTheyAreCreatedThenEachDeviceHasSeperateDeviceIndex) { ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); const size_t numDevices = 2; - executionEnvironment->rootDeviceEnvironments.resize(numDevices); + executionEnvironment->prepareRootDeviceEnvironments(numDevices); auto device = std::unique_ptr(Device::create(executionEnvironment, 0u)); auto device2 = std::unique_ptr(Device::create(executionEnvironment, 1u)); @@ -222,7 +222,7 @@ TEST(DeviceCreation, givenMultiRootDeviceWhenTheyAreCreatedThenEachDeviceHasSepe TEST(DeviceCreation, givenMultiRootDeviceWhenTheyAreCreatedThenEachDeviceHasSeperateCommandStreamReceiver) { ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); const size_t numDevices = 2; - executionEnvironment->rootDeviceEnvironments.resize(numDevices); + executionEnvironment->prepareRootDeviceEnvironments(numDevices); const auto &numGpgpuEngines = HwHelper::get(platformDevices[0]->platform.eRenderCoreFamily).getGpgpuEngineInstances().size(); auto device1 = std::unique_ptr(Device::create(executionEnvironment, 0u)); auto device2 = std::unique_ptr(Device::create(executionEnvironment, 1u)); @@ -268,6 +268,7 @@ HWTEST_F(DeviceHwTest, givenHwHelperInputWhenInitializingCsrThenCreatePageTableM localHwInfo.capabilityTable.ftrRenderCompressedImages = false; ExecutionEnvironment executionEnvironment; + executionEnvironment.prepareRootDeviceEnvironments(1); executionEnvironment.incRefInternal(); executionEnvironment.initializeMemoryManager(); executionEnvironment.setHwInfo(&localHwInfo); diff --git a/unit_tests/device/sub_device_tests.cpp b/unit_tests/device/sub_device_tests.cpp index 635f6c1d66..e4ce427ec2 100644 --- a/unit_tests/device/sub_device_tests.cpp +++ b/unit_tests/device/sub_device_tests.cpp @@ -83,6 +83,7 @@ TEST(SubDevicesTest, givenDeviceWithSubDevicesWhenSubDeviceCreationFailThenWhole DebugManagerStateRestore restorer; DebugManager.flags.CreateMultipleSubDevices.set(10); ExecutionEnvironment executionEnvironment; + executionEnvironment.prepareRootDeviceEnvironments(1); executionEnvironment.incRefInternal(); executionEnvironment.memoryManager.reset(new FailMemoryManager(10, executionEnvironment)); auto device = Device::create(&executionEnvironment, 0u); diff --git a/unit_tests/execution_environment/execution_environment_tests.cpp b/unit_tests/execution_environment/execution_environment_tests.cpp index 0574839856..c797d194bb 100644 --- a/unit_tests/execution_environment/execution_environment_tests.cpp +++ b/unit_tests/execution_environment/execution_environment_tests.cpp @@ -94,38 +94,41 @@ TEST(ExecutionEnvironment, givenDeviceWhenItIsDestroyedThenMemoryManagerIsStillA EXPECT_NE(nullptr, executionEnvironment->memoryManager); } -TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenInitializeAubCenterIsCalledThenItIsReceivesCorrectInputParams) { +TEST(RootDeviceEnvironment, givenExecutionEnvironmentWhenInitializeAubCenterIsCalledThenItIsReceivesCorrectInputParams) { MockExecutionEnvironment executionEnvironment; executionEnvironment.setHwInfo(*platformDevices); - executionEnvironment.initAubCenter(true, "test.aub", CommandStreamReceiverType::CSR_AUB); - EXPECT_TRUE(executionEnvironment.initAubCenterCalled); - EXPECT_TRUE(executionEnvironment.localMemoryEnabledReceived); - EXPECT_STREQ(executionEnvironment.aubFileNameReceived.c_str(), "test.aub"); + auto rootDeviceEnvironment = static_cast(executionEnvironment.rootDeviceEnvironments[0].get()); + rootDeviceEnvironment->initAubCenter(true, "test.aub", CommandStreamReceiverType::CSR_AUB); + EXPECT_TRUE(rootDeviceEnvironment->initAubCenterCalled); + EXPECT_TRUE(rootDeviceEnvironment->localMemoryEnabledReceived); + EXPECT_STREQ(rootDeviceEnvironment->aubFileNameReceived.c_str(), "test.aub"); } -TEST(ExecutionEnvironment, givenUseAubStreamFalseWhenGetAubManagerIsCalledThenReturnNull) { +TEST(RootDeviceEnvironment, givenUseAubStreamFalseWhenGetAubManagerIsCalledThenReturnNull) { DebugManagerStateRestore dbgRestore; DebugManager.flags.UseAubStream.set(false); ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); - executionEnvironment->initAubCenter(false, "", CommandStreamReceiverType::CSR_AUB); - auto aubManager = executionEnvironment->rootDeviceEnvironments[0].aubCenter->getAubManager(); + auto rootDeviceEnvironment = executionEnvironment->rootDeviceEnvironments[0].get(); + rootDeviceEnvironment->initAubCenter(false, "", CommandStreamReceiverType::CSR_AUB); + auto aubManager = rootDeviceEnvironment->aubCenter->getAubManager(); EXPECT_EQ(nullptr, aubManager); } -TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenInitializeAubCenterIsCalledThenItIsInitalizedOnce) { +TEST(RootDeviceEnvironment, givenExecutionEnvironmentWhenInitializeAubCenterIsCalledThenItIsInitalizedOnce) { ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); - executionEnvironment->initAubCenter(false, "", CommandStreamReceiverType::CSR_AUB); - auto currentAubCenter = executionEnvironment->rootDeviceEnvironments[0].aubCenter.get(); + auto rootDeviceEnvironment = executionEnvironment->rootDeviceEnvironments[0].get(); + rootDeviceEnvironment->initAubCenter(false, "", CommandStreamReceiverType::CSR_AUB); + auto currentAubCenter = rootDeviceEnvironment->aubCenter.get(); EXPECT_NE(nullptr, currentAubCenter); auto currentAubStreamProvider = currentAubCenter->getStreamProvider(); EXPECT_NE(nullptr, currentAubStreamProvider); auto currentAubFileStream = currentAubStreamProvider->getStream(); EXPECT_NE(nullptr, currentAubFileStream); - executionEnvironment->initAubCenter(false, "", CommandStreamReceiverType::CSR_AUB); - EXPECT_EQ(currentAubCenter, executionEnvironment->rootDeviceEnvironments[0].aubCenter.get()); - EXPECT_EQ(currentAubStreamProvider, executionEnvironment->rootDeviceEnvironments[0].aubCenter->getStreamProvider()); - EXPECT_EQ(currentAubFileStream, executionEnvironment->rootDeviceEnvironments[0].aubCenter->getStreamProvider()->getStream()); + rootDeviceEnvironment->initAubCenter(false, "", CommandStreamReceiverType::CSR_AUB); + EXPECT_EQ(currentAubCenter, rootDeviceEnvironment->aubCenter.get()); + EXPECT_EQ(currentAubStreamProvider, rootDeviceEnvironment->aubCenter->getStreamProvider()); + EXPECT_EQ(currentAubFileStream, rootDeviceEnvironment->aubCenter->getStreamProvider()->getStream()); } TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenInitializeMemoryManagerIsCalledThenLocalMemorySupportedInMemoryManagerHasCorrectValue) { @@ -181,11 +184,12 @@ TEST(ExecutionEnvironment, givenExecutionEnvironmentWithVariousMembersWhenItIsDe auto executionEnvironment = std::make_unique(); executionEnvironment->setHwInfo(*platformDevices); + executionEnvironment->prepareRootDeviceEnvironments(1); executionEnvironment->gmmHelper = std::make_unique(destructorId, platformDevices[0]); executionEnvironment->osInterface = std::make_unique(destructorId); executionEnvironment->memoryOperationsInterface = std::make_unique(destructorId); executionEnvironment->memoryManager = std::make_unique(destructorId, *executionEnvironment); - executionEnvironment->rootDeviceEnvironments[0].aubCenter = std::make_unique(destructorId); + executionEnvironment->rootDeviceEnvironments[0]->aubCenter = std::make_unique(destructorId); executionEnvironment->builtins = std::make_unique(destructorId); executionEnvironment->compilerInterface = std::make_unique(destructorId); executionEnvironment->sourceLevelDebugger = std::make_unique(destructorId); @@ -196,7 +200,7 @@ TEST(ExecutionEnvironment, givenExecutionEnvironmentWithVariousMembersWhenItIsDe TEST(ExecutionEnvironment, givenMultipleRootDevicesWhenTheyAreCreatedTheyAllReuseTheSameMemoryManager) { ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); - executionEnvironment->rootDeviceEnvironments.resize(2); + executionEnvironment->prepareRootDeviceEnvironments(2); std::unique_ptr device(Device::create(executionEnvironment, 0u)); auto &commandStreamReceiver = device->getGpgpuCommandStreamReceiver(); auto memoryManager = device->getMemoryManager(); diff --git a/unit_tests/fixtures/aub_command_stream_receiver_fixture.h b/unit_tests/fixtures/aub_command_stream_receiver_fixture.h index cc26c73647..0596ebec77 100644 --- a/unit_tests/fixtures/aub_command_stream_receiver_fixture.h +++ b/unit_tests/fixtures/aub_command_stream_receiver_fixture.h @@ -15,7 +15,7 @@ struct AubCommandStreamReceiverFixture : public DeviceFixture, MockAubCenterFixt void SetUp() { DeviceFixture::SetUp(); MockAubCenterFixture::SetUp(); - setMockAubCenter(pDevice->getExecutionEnvironment()); + setMockAubCenter(*pDevice->getExecutionEnvironment()->rootDeviceEnvironments[0]); } void TearDown() { MockAubCenterFixture::TearDown(); diff --git a/unit_tests/fixtures/memory_allocator_fixture.h b/unit_tests/fixtures/memory_allocator_fixture.h index b2fd735189..991fb7c1be 100644 --- a/unit_tests/fixtures/memory_allocator_fixture.h +++ b/unit_tests/fixtures/memory_allocator_fixture.h @@ -24,6 +24,7 @@ class MemoryAllocatorFixture : public MemoryManagementFixture { MemoryManagementFixture::SetUp(); executionEnvironment = new ExecutionEnvironment(); executionEnvironment->setHwInfo(*platformDevices); + executionEnvironment->prepareRootDeviceEnvironments(1); device.reset(MockDevice::createWithExecutionEnvironment(*platformDevices, executionEnvironment, 0u)); memoryManager = new MockMemoryManager(false, false, *executionEnvironment); executionEnvironment->memoryManager.reset(memoryManager); diff --git a/unit_tests/fixtures/memory_allocator_multi_device_fixture.h b/unit_tests/fixtures/memory_allocator_multi_device_fixture.h index bd8a3da5e3..7be323859d 100644 --- a/unit_tests/fixtures/memory_allocator_multi_device_fixture.h +++ b/unit_tests/fixtures/memory_allocator_multi_device_fixture.h @@ -21,7 +21,7 @@ class MemoryAllocatorMultiDeviceFixture : public MemoryManagementFixture { MemoryManagementFixture::SetUp(); executionEnvironment = std::make_unique(); executionEnvironment->setHwInfo(*platformDevices); - executionEnvironment->rootDeviceEnvironments.resize(numRootDevices); + executionEnvironment->prepareRootDeviceEnvironments(numRootDevices); memoryManager = new MockMemoryManager(false, false, *executionEnvironment); executionEnvironment->memoryManager.reset(memoryManager); } diff --git a/unit_tests/fixtures/memory_manager_fixture.cpp b/unit_tests/fixtures/memory_manager_fixture.cpp index 6362da663f..7271bba98d 100644 --- a/unit_tests/fixtures/memory_manager_fixture.cpp +++ b/unit_tests/fixtures/memory_manager_fixture.cpp @@ -17,6 +17,7 @@ using namespace NEO; void MemoryManagerWithCsrFixture::SetUp() { executionEnvironment.setHwInfo(*platformDevices); + executionEnvironment.prepareRootDeviceEnvironments(1); csr = std::make_unique(this->executionEnvironment, 0); memoryManager = new MockMemoryManager(executionEnvironment); executionEnvironment.memoryManager.reset(memoryManager); diff --git a/unit_tests/fixtures/mock_aub_center_fixture.h b/unit_tests/fixtures/mock_aub_center_fixture.h index 0b62b77ef4..31fea9f02b 100644 --- a/unit_tests/fixtures/mock_aub_center_fixture.h +++ b/unit_tests/fixtures/mock_aub_center_fixture.h @@ -7,7 +7,7 @@ #pragma once -#include "runtime/execution_environment/execution_environment.h" +#include "core/execution_environment/root_device_environment.h" #include "runtime/platform/platform.h" #include "unit_tests/mocks/mock_aub_center.h" #include "unit_tests/mocks/mock_aub_manager.h" @@ -20,19 +20,19 @@ struct MockAubCenterFixture { MockAubCenterFixture(CommandStreamReceiverType commandStreamReceiverType) : commandStreamReceiverType(commandStreamReceiverType){}; void SetUp() { - setMockAubCenter(platformImpl->peekExecutionEnvironment(), commandStreamReceiverType); + setMockAubCenter(*platformImpl->peekExecutionEnvironment()->rootDeviceEnvironments[0], commandStreamReceiverType); } void TearDown() { } - static void setMockAubCenter(ExecutionEnvironment *executionEnvironment) { - setMockAubCenter(executionEnvironment, CommandStreamReceiverType::CSR_AUB); + static void setMockAubCenter(RootDeviceEnvironment &rootDeviceEnvironment) { + setMockAubCenter(rootDeviceEnvironment, CommandStreamReceiverType::CSR_AUB); } - static void setMockAubCenter(ExecutionEnvironment *executionEnvironment, CommandStreamReceiverType commandStreamReceiverType) { + static void setMockAubCenter(RootDeviceEnvironment &rootDeviceEnvironment, CommandStreamReceiverType commandStreamReceiverType) { if (testMode != TestMode::AubTests && testMode != TestMode::AubTestsWithTbx) { auto mockAubCenter = std::make_unique(platformDevices[0], false, "", commandStreamReceiverType); mockAubCenter->aubManager = std::make_unique(); - executionEnvironment->rootDeviceEnvironments[0].aubCenter.reset(mockAubCenter.release()); + rootDeviceEnvironment.aubCenter.reset(mockAubCenter.release()); } } diff --git a/unit_tests/fixtures/templated_fixture_tests.cpp b/unit_tests/fixtures/templated_fixture_tests.cpp index 99ee5faae7..6915cd8fce 100644 --- a/unit_tests/fixtures/templated_fixture_tests.cpp +++ b/unit_tests/fixtures/templated_fixture_tests.cpp @@ -6,6 +6,7 @@ */ #include "runtime/helpers/hardware_commands_helper.h" +#include "runtime/helpers/options.h" #include "test.h" namespace NEO { diff --git a/unit_tests/gtpin/gtpin_tests.cpp b/unit_tests/gtpin/gtpin_tests.cpp index bf0e3b3279..14e12321a9 100644 --- a/unit_tests/gtpin/gtpin_tests.cpp +++ b/unit_tests/gtpin/gtpin_tests.cpp @@ -144,6 +144,7 @@ class GTPinFixture : public ContextFixture, public MemoryManagementFixture { pPlatform = platform(); auto executionEnvironment = pPlatform->peekExecutionEnvironment(); executionEnvironment->setHwInfo(*platformDevices); + executionEnvironment->prepareRootDeviceEnvironments(1); memoryManager = new MockMemoryManagerWithFailures(*executionEnvironment); executionEnvironment->memoryManager.reset(memoryManager); pPlatform->initialize(); diff --git a/unit_tests/helpers/timestamp_packet_tests.cpp b/unit_tests/helpers/timestamp_packet_tests.cpp index 83255b1cf6..f4499917e0 100644 --- a/unit_tests/helpers/timestamp_packet_tests.cpp +++ b/unit_tests/helpers/timestamp_packet_tests.cpp @@ -49,7 +49,7 @@ struct TimestampPacketSimpleTests : public ::testing::Test { struct TimestampPacketTests : public TimestampPacketSimpleTests { void SetUp() override { executionEnvironment = platformImpl->peekExecutionEnvironment(); - executionEnvironment->rootDeviceEnvironments.resize(2); + executionEnvironment->prepareRootDeviceEnvironments(2); device = std::unique_ptr(Device::create(executionEnvironment, 0u)); context = new MockContext(device.get()); kernel = std::make_unique(*device, context); diff --git a/unit_tests/kernel/kernel_tests.cpp b/unit_tests/kernel/kernel_tests.cpp index b5f0cfd851..c19d085e61 100644 --- a/unit_tests/kernel/kernel_tests.cpp +++ b/unit_tests/kernel/kernel_tests.cpp @@ -467,6 +467,7 @@ class CommandStreamReceiverMock : public CommandStreamReceiver { CommandStreamReceiverMock() : BaseClass(*(new ExecutionEnvironment), 0) { this->mockExecutionEnvironment.reset(&this->executionEnvironment); + executionEnvironment.prepareRootDeviceEnvironments(1); executionEnvironment.initializeMemoryManager(); } diff --git a/unit_tests/libult/create_command_stream.cpp b/unit_tests/libult/create_command_stream.cpp index e27b74307e..a49814a0dc 100644 --- a/unit_tests/libult/create_command_stream.cpp +++ b/unit_tests/libult/create_command_stream.cpp @@ -39,7 +39,7 @@ CommandStreamReceiver *createCommandStream(ExecutionEnvironment &executionEnviro bool getDevices(size_t &numDevicesReturned, ExecutionEnvironment &executionEnvironment) { if (overrideDeviceWithDefaultHardwareInfo) { numDevicesReturned = numPlatformDevices; - executionEnvironment.rootDeviceEnvironments.resize(numDevicesReturned); + executionEnvironment.prepareRootDeviceEnvironments(static_cast(numDevicesReturned)); return getDevicesResult; } diff --git a/unit_tests/memory_manager/host_ptr_manager_tests.cpp b/unit_tests/memory_manager/host_ptr_manager_tests.cpp index cb9b1ecaa4..72ae1f5298 100644 --- a/unit_tests/memory_manager/host_ptr_manager_tests.cpp +++ b/unit_tests/memory_manager/host_ptr_manager_tests.cpp @@ -805,11 +805,11 @@ TEST_F(HostPtrAllocationTest, whenPrepareOsHandlesForAllocationThenPopulateAsMan for (uint32_t expectedFragmentCount = 1; expectedFragmentCount <= 3; expectedFragmentCount++, allocationSize += MemoryConstants::pageSize) { auto requirements = hostPtrManager->getAllocationRequirements(cpuPtr, allocationSize); EXPECT_EQ(expectedFragmentCount, requirements.requiredFragmentsCount); - auto osStorage = hostPtrManager->prepareOsStorageForAllocation(*memoryManager, allocationSize, cpuPtr); + auto osStorage = hostPtrManager->prepareOsStorageForAllocation(*memoryManager, allocationSize, cpuPtr, 0); EXPECT_EQ(expectedFragmentCount, osStorage.fragmentCount); EXPECT_EQ(expectedFragmentCount, hostPtrManager->getFragmentCount()); hostPtrManager->releaseHandleStorage(osStorage); - memoryManager->cleanOsHandles(osStorage); + memoryManager->cleanOsHandles(osStorage, 0); EXPECT_EQ(0u, hostPtrManager->getFragmentCount()); } } diff --git a/unit_tests/memory_manager/memory_manager_tests.cpp b/unit_tests/memory_manager/memory_manager_tests.cpp index b7c09b39ba..dfd416e28b 100644 --- a/unit_tests/memory_manager/memory_manager_tests.cpp +++ b/unit_tests/memory_manager/memory_manager_tests.cpp @@ -288,7 +288,7 @@ TEST_F(MemoryAllocatorTest, NullOsHandleStorageAskedForPopulationReturnsFilledPo EXPECT_EQ(nullptr, storage.fragmentStorageData[1].osHandleStorage); EXPECT_EQ(nullptr, storage.fragmentStorageData[2].osHandleStorage); memoryManager->getHostPtrManager()->releaseHandleStorage(storage); - memoryManager->cleanOsHandles(storage); + memoryManager->cleanOsHandles(storage, 0); } TEST_F(MemoryAllocatorTest, givenOsHandleStorageWhenOsHandlesAreCleanedAndAubManagerIsNotAvailableThenFreeMemoryIsNotCalledOnAubManager) { @@ -296,13 +296,13 @@ TEST_F(MemoryAllocatorTest, givenOsHandleStorageWhenOsHandlesAreCleanedAndAubMan MockMemoryManager mockMemoryManager(mockExecutionEnvironment); auto mockAubCenter = new MockAubCenter(platformDevices[0], false, "aubfile", CommandStreamReceiverType::CSR_AUB); mockAubCenter->aubManager.reset(nullptr); - mockExecutionEnvironment.rootDeviceEnvironments[0].aubCenter.reset(mockAubCenter); + mockExecutionEnvironment.rootDeviceEnvironments[0]->aubCenter.reset(mockAubCenter); OsHandleStorage storage; storage.fragmentStorageData[0].cpuPtr = (void *)0x1000; mockMemoryManager.populateOsHandles(storage); mockMemoryManager.getHostPtrManager()->releaseHandleStorage(storage); - mockMemoryManager.cleanOsHandles(storage); + mockMemoryManager.cleanOsHandles(storage, 0); EXPECT_EQ(nullptr, mockAubCenter->aubManager); } @@ -310,20 +310,27 @@ TEST_F(MemoryAllocatorTest, givenOsHandleStorageWhenOsHandlesAreCleanedAndAubMan TEST_F(MemoryAllocatorTest, givenOsHandleStorageAndFreeMemoryEnabledWhenOsHandlesAreCleanedAndAubManagerIsAvailableThenFreeMemoryIsCalledOnAubManager) { DebugManagerStateRestore dbgRestore; DebugManager.flags.EnableFreeMemory.set(true); - MockExecutionEnvironment mockExecutionEnvironment(*platformDevices); + const uint32_t rootDeviceIndex = 1u; + MockExecutionEnvironment mockExecutionEnvironment(*platformDevices, true, 3); MockMemoryManager mockMemoryManager(mockExecutionEnvironment); - auto mockManager = new MockAubManager(); - auto mockAubCenter = new MockAubCenter(platformDevices[0], false, "aubfile", CommandStreamReceiverType::CSR_AUB); - mockAubCenter->aubManager.reset(mockManager); - mockExecutionEnvironment.rootDeviceEnvironments[0].aubCenter.reset(mockAubCenter); + auto mockManager0 = new MockAubManager(); + auto mockAubCenter0 = new MockAubCenter(platformDevices[0], false, "aubfile", CommandStreamReceiverType::CSR_AUB); + mockAubCenter0->aubManager.reset(mockManager0); + mockExecutionEnvironment.rootDeviceEnvironments[0]->aubCenter.reset(mockAubCenter0); + + auto mockManager1 = new MockAubManager(); + auto mockAubCenter1 = new MockAubCenter(platformDevices[0], false, "aubfile", CommandStreamReceiverType::CSR_AUB); + mockAubCenter1->aubManager.reset(mockManager1); + mockExecutionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->aubCenter.reset(mockAubCenter1); OsHandleStorage storage; - storage.fragmentStorageData[0].cpuPtr = (void *)0x1000; + storage.fragmentStorageData[0].cpuPtr = reinterpret_cast(0x1000); mockMemoryManager.populateOsHandles(storage); mockMemoryManager.getHostPtrManager()->releaseHandleStorage(storage); - mockMemoryManager.cleanOsHandles(storage); + mockMemoryManager.cleanOsHandles(storage, rootDeviceIndex); - EXPECT_TRUE(mockManager->freeMemoryCalled); + EXPECT_FALSE(mockManager0->freeMemoryCalled); + EXPECT_TRUE(mockManager1->freeMemoryCalled); } TEST_F(MemoryAllocatorTest, GivenEmptyMemoryManagerAndMisalingedHostPtrWithHugeSizeWhenAskedForHostPtrAllocationThenGraphicsAllocationIsBeignCreatedWithAllFragmentsPresent) { @@ -1227,7 +1234,7 @@ TEST(OsAgnosticMemoryManager, givenOsAgnosticMemoryManagerAndFreeMemoryEnabledWh MockAubManager *mockManager = new MockAubManager(); MockAubCenter *mockAubCenter = new MockAubCenter(platformDevices[0], false, "file_name.aub", CommandStreamReceiverType::CSR_AUB); mockAubCenter->aubManager = std::unique_ptr(mockManager); - executionEnvironment.rootDeviceEnvironments[0].aubCenter.reset(mockAubCenter); + executionEnvironment.rootDeviceEnvironments[0]->aubCenter.reset(mockAubCenter); auto gfxAllocation = memoryManager.allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); EXPECT_FALSE(mockManager->freeMemoryCalled); @@ -1243,7 +1250,7 @@ TEST(OsAgnosticMemoryManager, givenOsAgnosticMemoryManagerAndFreeMemoryDisabledW MockAubManager *mockManager = new MockAubManager(); MockAubCenter *mockAubCenter = new MockAubCenter(platformDevices[0], false, "file_name.aub", CommandStreamReceiverType::CSR_AUB); mockAubCenter->aubManager = std::unique_ptr(mockManager); - executionEnvironment.rootDeviceEnvironments[0].aubCenter.reset(mockAubCenter); + executionEnvironment.rootDeviceEnvironments[0]->aubCenter.reset(mockAubCenter); auto gfxAllocation = memoryManager.allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); EXPECT_FALSE(mockManager->freeMemoryCalled); diff --git a/unit_tests/mocks/mock_aub_csr.h b/unit_tests/mocks/mock_aub_csr.h index d60c092108..b472dffce2 100644 --- a/unit_tests/mocks/mock_aub_csr.h +++ b/unit_tests/mocks/mock_aub_csr.h @@ -8,6 +8,7 @@ #pragma once #include "core/command_stream/preemption.h" +#include "core/execution_environment/root_device_environment.h" #include "runtime/command_stream/aub_command_stream_receiver_hw.h" #include "runtime/execution_environment/execution_environment.h" #include "runtime/helpers/hw_info.h" @@ -177,8 +178,9 @@ struct AubExecutionEnvironment { template std::unique_ptr getEnvironment(bool createTagAllocation, bool allocateCommandBuffer, bool standalone) { std::unique_ptr executionEnvironment(new ExecutionEnvironment); + executionEnvironment->prepareRootDeviceEnvironments(1); executionEnvironment->setHwInfo(*platformDevices); - executionEnvironment->rootDeviceEnvironments[0].aubCenter.reset(new AubCenter()); + executionEnvironment->rootDeviceEnvironments[0]->aubCenter.reset(new AubCenter()); executionEnvironment->initializeMemoryManager(); auto commandStreamReceiver = std::make_unique("", standalone, *executionEnvironment, 0); diff --git a/unit_tests/mocks/mock_device.h b/unit_tests/mocks/mock_device.h index 022cccc800..0a55c63568 100644 --- a/unit_tests/mocks/mock_device.h +++ b/unit_tests/mocks/mock_device.h @@ -97,7 +97,7 @@ class MockDevice : public RootDevice { static T *createWithNewExecutionEnvironment(const HardwareInfo *pHwInfo) { ExecutionEnvironment *executionEnvironment = new ExecutionEnvironment(); auto numRootDevices = DebugManager.flags.CreateMultipleRootDevices.get() ? DebugManager.flags.CreateMultipleRootDevices.get() : 1u; - executionEnvironment->rootDeviceEnvironments.resize(numRootDevices); + executionEnvironment->prepareRootDeviceEnvironments(numRootDevices); pHwInfo = pHwInfo ? pHwInfo : platformDevices[0]; executionEnvironment->setHwInfo(pHwInfo); return createWithExecutionEnvironment(pHwInfo, executionEnvironment, 0u); @@ -127,7 +127,8 @@ class MockDevice : public RootDevice { template <> inline Device *MockDevice::createWithNewExecutionEnvironment(const HardwareInfo *pHwInfo) { auto executionEnvironment = new ExecutionEnvironment(); - MockAubCenterFixture::setMockAubCenter(executionEnvironment); + executionEnvironment->prepareRootDeviceEnvironments(1); + MockAubCenterFixture::setMockAubCenter(*executionEnvironment->rootDeviceEnvironments[0]); auto hwInfo = pHwInfo ? pHwInfo : *platformDevices; executionEnvironment->setHwInfo(hwInfo); executionEnvironment->initializeMemoryManager(); diff --git a/unit_tests/mocks/mock_execution_environment.h b/unit_tests/mocks/mock_execution_environment.h index 68a74e01fc..a910676fb8 100644 --- a/unit_tests/mocks/mock_execution_environment.h +++ b/unit_tests/mocks/mock_execution_environment.h @@ -13,14 +13,12 @@ #include "unit_tests/fixtures/mock_aub_center_fixture.h" namespace NEO { -struct MockExecutionEnvironment : ExecutionEnvironment { - MockExecutionEnvironment() = default; - MockExecutionEnvironment(const HardwareInfo *hwInfo) : MockExecutionEnvironment(hwInfo, true) {} - MockExecutionEnvironment(const HardwareInfo *hwInfo, bool useMockAubCenter) : useMockAubCenter(useMockAubCenter) { - if (hwInfo) { - setHwInfo(hwInfo); - } - } + +struct MockRootDeviceEnvironment : public RootDeviceEnvironment { + using RootDeviceEnvironment::RootDeviceEnvironment; + + ~MockRootDeviceEnvironment() override = default; + void initAubCenter(bool localMemoryEnabled, const std::string &aubFileName, CommandStreamReceiverType csrType) override { if (!initAubCenterCalled) { initAubCenterCalled = true; @@ -28,13 +26,33 @@ struct MockExecutionEnvironment : ExecutionEnvironment { aubFileNameReceived = aubFileName; } if (useMockAubCenter) { - MockAubCenterFixture::setMockAubCenter(this); + MockAubCenterFixture::setMockAubCenter(*this); } - ExecutionEnvironment::initAubCenter(localMemoryEnabled, aubFileName, csrType); + RootDeviceEnvironment::initAubCenter(localMemoryEnabled, aubFileName, csrType); } bool initAubCenterCalled = false; bool localMemoryEnabledReceived = false; std::string aubFileNameReceived = ""; bool useMockAubCenter = true; }; + +struct MockExecutionEnvironment : ExecutionEnvironment { + ~MockExecutionEnvironment() override = default; + MockExecutionEnvironment() : MockExecutionEnvironment(nullptr) {} + MockExecutionEnvironment(const HardwareInfo *hwInfo) : MockExecutionEnvironment(hwInfo, true, 1u) { + } + MockExecutionEnvironment(const HardwareInfo *hwInfo, bool useMockAubCenter, uint32_t numRootDevices) { + prepareRootDeviceEnvironments(numRootDevices); + for (auto rootDeviceIndex = 0u; rootDeviceIndex < numRootDevices; rootDeviceIndex++) { + auto rootDeviceEnvironment = new MockRootDeviceEnvironment(*this); + rootDeviceEnvironment->useMockAubCenter = useMockAubCenter; + rootDeviceEnvironments[rootDeviceIndex].reset(rootDeviceEnvironment); + } + + if (hwInfo) { + setHwInfo(hwInfo); + } + } +}; + } // namespace NEO diff --git a/unit_tests/mocks/mock_memory_manager.h b/unit_tests/mocks/mock_memory_manager.h index e368c32674..1a533cff1e 100644 --- a/unit_tests/mocks/mock_memory_manager.h +++ b/unit_tests/mocks/mock_memory_manager.h @@ -194,7 +194,7 @@ class FailMemoryManager : public MockMemoryManager { MemoryManager::AllocationStatus populateOsHandles(OsHandleStorage &handleStorage) override { return AllocationStatus::Error; }; - void cleanOsHandles(OsHandleStorage &handleStorage) override{}; + void cleanOsHandles(OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override{}; uint64_t getSystemSharedMemory() override { return 0; diff --git a/unit_tests/os_interface/device_factory_tests.cpp b/unit_tests/os_interface/device_factory_tests.cpp index 8076181aec..7d8bbb1c5b 100644 --- a/unit_tests/os_interface/device_factory_tests.cpp +++ b/unit_tests/os_interface/device_factory_tests.cpp @@ -177,8 +177,32 @@ TEST_F(DeviceFactoryTest, givenSetCommandStreamReceiverInAubModeForTgllpProductF bool success = DeviceFactory::getDevicesForProductFamilyOverride(numDevices, executionEnvironment); ASSERT_TRUE(success); - EXPECT_TRUE(executionEnvironment.initAubCenterCalled); - EXPECT_FALSE(executionEnvironment.localMemoryEnabledReceived); + auto rootDeviceEnvironment = static_cast(executionEnvironment.rootDeviceEnvironments[0].get()); + + EXPECT_TRUE(rootDeviceEnvironment->initAubCenterCalled); + EXPECT_FALSE(rootDeviceEnvironment->localMemoryEnabledReceived); +} + +TEST_F(DeviceFactoryTest, givenSetCommandStreamReceiverInAubModeWhenGetDevicesForProductFamilyOverrideIsCalledThenAllAubCentersAreInitializedCorrectly) { + DeviceFactoryCleaner cleaner; + DebugManagerStateRestore stateRestore; + auto requiredDeviceCount = 2u; + DebugManager.flags.CreateMultipleRootDevices.set(requiredDeviceCount); + DebugManager.flags.SetCommandStreamReceiver.set(1); + DebugManager.flags.ProductFamilyOverride.set("tgllp"); + + MockExecutionEnvironment executionEnvironment(*platformDevices, true, requiredDeviceCount); + + size_t numDevices = 0; + bool success = DeviceFactory::getDevicesForProductFamilyOverride(numDevices, executionEnvironment); + ASSERT_TRUE(success); + EXPECT_EQ(requiredDeviceCount, numDevices); + + for (auto rootDeviceIndex = 0u; rootDeviceIndex < requiredDeviceCount; rootDeviceIndex++) { + auto rootDeviceEnvironment = static_cast(executionEnvironment.rootDeviceEnvironments[rootDeviceIndex].get()); + EXPECT_TRUE(rootDeviceEnvironment->initAubCenterCalled); + EXPECT_FALSE(rootDeviceEnvironment->localMemoryEnabledReceived); + } } TEST_F(DeviceFactoryTest, givenGetDevicesCallWhenItIsDoneThenOsInterfaceIsAllocated) { diff --git a/unit_tests/os_interface/linux/device_command_stream_tests.cpp b/unit_tests/os_interface/linux/device_command_stream_tests.cpp index 68aeb17108..b3ec040321 100644 --- a/unit_tests/os_interface/linux/device_command_stream_tests.cpp +++ b/unit_tests/os_interface/linux/device_command_stream_tests.cpp @@ -29,7 +29,7 @@ struct DeviceCommandStreamLeaksTest : ::testing::Test { void SetUp() override { HardwareInfo *hwInfo = nullptr; executionEnvironment = getExecutionEnvironmentImpl(hwInfo); - MockAubCenterFixture::setMockAubCenter(executionEnvironment); + MockAubCenterFixture::setMockAubCenter(*executionEnvironment->rootDeviceEnvironments[0]); } ExecutionEnvironment *executionEnvironment; diff --git a/unit_tests/os_interface/linux/drm_command_stream_fixture.h b/unit_tests/os_interface/linux/drm_command_stream_fixture.h index 4bf6ab152b..aa2b709d0a 100644 --- a/unit_tests/os_interface/linux/drm_command_stream_fixture.h +++ b/unit_tests/os_interface/linux/drm_command_stream_fixture.h @@ -31,6 +31,7 @@ class DrmCommandStreamTest : public ::testing::Test { mock = std::make_unique<::testing::NiceMock>(mockFd); executionEnvironment.setHwInfo(*platformDevices); + executionEnvironment.prepareRootDeviceEnvironments(1); executionEnvironment.osInterface = std::make_unique(); executionEnvironment.osInterface->get()->setDrm(mock.get()); @@ -91,6 +92,7 @@ class DrmCommandStreamEnhancedTest : public ::testing::Test { executionEnvironment = new ExecutionEnvironment; executionEnvironment->incRefInternal(); executionEnvironment->setHwInfo(*platformDevices); + executionEnvironment->prepareRootDeviceEnvironments(1); executionEnvironment->initGmm(); this->dbgState = std::make_unique(); //make sure this is disabled, we don't want to test this now diff --git a/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp b/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp index d273d4fc84..4b96f33f37 100644 --- a/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp +++ b/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp @@ -572,7 +572,7 @@ TEST_F(DrmMemoryManagerTest, NullOsHandleStorageAskedForPopulationReturnsFilledP EXPECT_EQ(nullptr, storage.fragmentStorageData[1].osHandleStorage); EXPECT_EQ(nullptr, storage.fragmentStorageData[2].osHandleStorage); storage.fragmentStorageData[0].freeTheFragment = true; - memoryManager->cleanOsHandles(storage); + memoryManager->cleanOsHandles(storage, 0); } TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenEnabledHostMemoryValidationWhenReadOnlyPointerCausesPinningFailWithEfaultThenPopulateOsHandlesReturnsInvalidHostPointerError) { @@ -607,7 +607,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenEnabledHostMemoryValid EXPECT_EQ(nullptr, storage.fragmentStorageData[2].osHandleStorage); storage.fragmentStorageData[0].freeTheFragment = true; - memoryManager->cleanOsHandles(storage); + memoryManager->cleanOsHandles(storage, 0); mock->ioctl_res_ext = &mock->NONE; } @@ -642,7 +642,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenEnabledHostMemoryValid EXPECT_EQ(nullptr, storage.fragmentStorageData[2].osHandleStorage); storage.fragmentStorageData[0].freeTheFragment = true; - memoryManager->cleanOsHandles(storage); + memoryManager->cleanOsHandles(storage, 0); mock->ioctl_res_ext = &mock->NONE; } @@ -2538,7 +2538,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenDisabledForcePinAndEna EXPECT_NE(nullptr, handleStorage.fragmentStorageData[0].osHandleStorage); handleStorage.fragmentStorageData[0].freeTheFragment = true; - memoryManager->cleanOsHandles(handleStorage); + memoryManager->cleanOsHandles(handleStorage, 0); } TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenDisabledForcePinAndEnabledValidateHostMemoryWhenPopulateOsHandlesIsCalledWithFirstFragmentAlreadyAllocatedThenNewBosAreValidated) { @@ -2604,7 +2604,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenDisabledForcePinAndEna handleStorage.fragmentStorageData[1].freeTheFragment = true; handleStorage.fragmentStorageData[2].freeTheFragment = true; - memoryManager->cleanOsHandles(handleStorage); + memoryManager->cleanOsHandles(handleStorage, 0); } TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenValidateHostPtrMemoryEnabledWhenHostPtrAllocationIsCreatedWithoutForcingPinThenBufferObjectIsPinned) { @@ -2647,7 +2647,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenEnabledHostMemoryValid EXPECT_NE(nullptr, storage.fragmentStorageData[0].osHandleStorage); storage.fragmentStorageData[0].freeTheFragment = true; - memoryManager->cleanOsHandles(storage); + memoryManager->cleanOsHandles(storage, 0); } TEST_F(DrmMemoryManagerTest, givenForcePinAndHostMemoryValidationEnabledWhenSmallAllocationIsCreatedThenBufferObjectIsPinned) { @@ -2873,7 +2873,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenEnabledValidateHostMem handleStorage.fragmentStorageData[1].freeTheFragment = true; handleStorage.fragmentStorageData[2].freeTheFragment = true; - memoryManager->cleanOsHandles(handleStorage); + memoryManager->cleanOsHandles(handleStorage, 0); mock->ioctl_res_ext = &mock->NONE; } @@ -2922,7 +2922,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenEnabledValidateHostMem handleStorage.fragmentStorageData[1].freeTheFragment = true; handleStorage.fragmentStorageData[2].freeTheFragment = true; - memoryManager->cleanOsHandles(handleStorage); + memoryManager->cleanOsHandles(handleStorage, 0); mock->ioctl_res_ext = &mock->NONE; } @@ -2953,7 +2953,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenEnabledValidateHostMem EXPECT_NE(nullptr, hostPtrManager->getFragment(handleStorage.fragmentStorageData[0].cpuPtr)); handleStorage.fragmentStorageData[0].freeTheFragment = true; - memoryManager->cleanOsHandles(handleStorage); + memoryManager->cleanOsHandles(handleStorage, 0); } TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenDrmMemoryManagerWhenCleanOsHandlesDeletesHandleDataThenOsHandleStorageAndResidencyIsSetToNullptr) { @@ -2974,7 +2974,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenDrmMemoryManagerWhenCl handleStorage.fragmentStorageData[0].freeTheFragment = true; handleStorage.fragmentStorageData[1].freeTheFragment = true; - memoryManager->cleanOsHandles(handleStorage); + memoryManager->cleanOsHandles(handleStorage, 0); for (uint32_t i = 0; i < 2; i++) { EXPECT_EQ(nullptr, handleStorage.fragmentStorageData[i].osHandleStorage); diff --git a/unit_tests/os_interface/linux/drm_memory_manager_tests.h b/unit_tests/os_interface/linux/drm_memory_manager_tests.h index 0f9896e8c3..ce6cd1664d 100644 --- a/unit_tests/os_interface/linux/drm_memory_manager_tests.h +++ b/unit_tests/os_interface/linux/drm_memory_manager_tests.h @@ -92,6 +92,7 @@ class DrmMemoryManagerFixtureWithoutQuietIoctlExpectation { void SetUp() { executionEnvironment = new ExecutionEnvironment; executionEnvironment->setHwInfo(*platformDevices); + executionEnvironment->prepareRootDeviceEnvironments(1); mock = std::make_unique(); executionEnvironment->osInterface = std::make_unique(); executionEnvironment->osInterface->get()->setDrm(mock.get()); diff --git a/unit_tests/os_interface/linux/linux_create_command_queue_with_properties_tests.cpp b/unit_tests/os_interface/linux/linux_create_command_queue_with_properties_tests.cpp index 5bbd6e529c..620f4dae41 100644 --- a/unit_tests/os_interface/linux/linux_create_command_queue_with_properties_tests.cpp +++ b/unit_tests/os_interface/linux/linux_create_command_queue_with_properties_tests.cpp @@ -20,6 +20,7 @@ struct clCreateCommandQueueWithPropertiesLinux : public UltCommandStreamReceiver void SetUp() override { UltCommandStreamReceiverTest::SetUp(); ExecutionEnvironment *executionEnvironment = new ExecutionEnvironment(); + executionEnvironment->prepareRootDeviceEnvironments(1); auto osInterface = new OSInterface(); osInterface->get()->setDrm(drm.get()); executionEnvironment->osInterface.reset(osInterface); diff --git a/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp b/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp index e2889cc3d4..4628380d8d 100644 --- a/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp @@ -914,7 +914,7 @@ TEST_F(WddmMemoryManagerTest, GivenThreeOsHandlesWhenAskedForDestroyAllocationsT storage.fragmentStorageData[2].osHandleStorage->gmm = new Gmm(pSysMem, 4096u, false); storage.fragmentStorageData[2].residency = new ResidencyData; - memoryManager->cleanOsHandles(storage); + memoryManager->cleanOsHandles(storage, 0); auto destroyWithResourceHandleCalled = 0u; D3DKMT_DESTROYALLOCATION2 *ptrToDestroyAlloc2 = nullptr; @@ -1076,7 +1076,7 @@ TEST_F(BufferWithWddmMemory, NullOsHandleStorageAskedForPopulationReturnsFilledP EXPECT_EQ(nullptr, storage.fragmentStorageData[1].osHandleStorage); EXPECT_EQ(nullptr, storage.fragmentStorageData[2].osHandleStorage); storage.fragmentStorageData[0].freeTheFragment = true; - memoryManager->cleanOsHandles(storage); + memoryManager->cleanOsHandles(storage, 0); } TEST_F(BufferWithWddmMemory, GivenMisalignedHostPtrAndMultiplePagesSizeWhenAskedForGraphicsAllcoationThenItContainsAllFragmentsWithProperGpuAdrresses) { @@ -1585,7 +1585,7 @@ TEST_F(WddmMemoryManagerTest2, givenReadOnlyMemoryWhenCreateAllocationFailsThenP EXPECT_EQ(MemoryManager::AllocationStatus::InvalidHostPointer, result); handleStorage.fragmentStorageData[0].freeTheFragment = true; - memoryManager->cleanOsHandles(handleStorage); + memoryManager->cleanOsHandles(handleStorage, 0); } TEST_F(WddmMemoryManagerTest2, givenReadOnlyMemoryPassedToPopulateOsHandlesWhenCreateAllocationFailsThenAllocatedFragmentsAreNotStored) { @@ -1610,7 +1610,7 @@ TEST_F(WddmMemoryManagerTest2, givenReadOnlyMemoryPassedToPopulateOsHandlesWhenC EXPECT_EQ(nullptr, hostPtrManager->getFragment(handleStorage.fragmentStorageData[1].cpuPtr)); handleStorage.fragmentStorageData[1].freeTheFragment = true; - memoryManager->cleanOsHandles(handleStorage); + memoryManager->cleanOsHandles(handleStorage, 0); } TEST(WddmMemoryManagerCleanupTest, givenUsedTagAllocationInWddmMemoryManagerWhenCleanupMemoryManagerThenDontAccessCsr) { diff --git a/unit_tests/platform/platform_tests.cpp b/unit_tests/platform/platform_tests.cpp index b9f8367267..7ca06f1f4f 100644 --- a/unit_tests/platform/platform_tests.cpp +++ b/unit_tests/platform/platform_tests.cpp @@ -37,9 +37,9 @@ struct MockPlatformWithMockExecutionEnvironment : public Platform { MockPlatformWithMockExecutionEnvironment() { this->executionEnvironment->decRefInternal(); - mockExecutionEnvironment = new MockExecutionEnvironment(nullptr, false); + mockExecutionEnvironment = new MockExecutionEnvironment(nullptr, false, 1); executionEnvironment = mockExecutionEnvironment; - MockAubCenterFixture::setMockAubCenter(executionEnvironment); + MockAubCenterFixture::setMockAubCenter(*executionEnvironment->rootDeviceEnvironments[0]); executionEnvironment->incRefInternal(); } }; @@ -149,7 +149,8 @@ TEST(PlatformTestSimple, givenCsrHwTypeWhenPlatformIsInitializedThenInitAubCente MockPlatformWithMockExecutionEnvironment platform; bool ret = platform.initialize(); EXPECT_TRUE(ret); - EXPECT_FALSE(platform.mockExecutionEnvironment->initAubCenterCalled); + auto rootDeviceEnvironment = static_cast(platform.mockExecutionEnvironment->rootDeviceEnvironments[0].get()); + EXPECT_FALSE(rootDeviceEnvironment->initAubCenterCalled); } TEST(PlatformTestSimple, givenNotCsrHwTypeWhenPlatformIsInitializedThenInitAubCenterIsCalled) { @@ -159,7 +160,8 @@ TEST(PlatformTestSimple, givenNotCsrHwTypeWhenPlatformIsInitializedThenInitAubCe MockPlatformWithMockExecutionEnvironment platform; bool ret = platform.initialize(); EXPECT_TRUE(ret); - EXPECT_TRUE(platform.mockExecutionEnvironment->initAubCenterCalled); + auto rootDeviceEnvironment = static_cast(platform.mockExecutionEnvironment->rootDeviceEnvironments[0].get()); + EXPECT_TRUE(rootDeviceEnvironment->initAubCenterCalled); } TEST(PlatformTestSimple, shutdownClosesAsyncEventHandlerThread) { diff --git a/unit_tests/source_level_debugger/source_level_debugger_tests.cpp b/unit_tests/source_level_debugger/source_level_debugger_tests.cpp index 2f85ce2445..4bc12dcf2f 100644 --- a/unit_tests/source_level_debugger/source_level_debugger_tests.cpp +++ b/unit_tests/source_level_debugger/source_level_debugger_tests.cpp @@ -529,7 +529,7 @@ TEST(SourceLevelDebugger, givenTwoRootDevicesWhenSecondIsCreatedThenNotCreatingN DebuggerLibrary::injectDebuggerLibraryInterceptor(&interceptor); ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); - executionEnvironment->rootDeviceEnvironments.resize(2); + executionEnvironment->prepareRootDeviceEnvironments(2); std::unique_ptr device1(Device::create(executionEnvironment, 0u)); EXPECT_NE(nullptr, executionEnvironment->memoryManager); @@ -550,7 +550,7 @@ TEST(SourceLevelDebugger, givenMultipleRootDevicesWhenTheyAreCreatedTheyAllReuse DebuggerLibrary::setDebuggerActive(true); ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); - executionEnvironment->rootDeviceEnvironments.resize(2); + executionEnvironment->prepareRootDeviceEnvironments(2); std::unique_ptr device1(Device::create(executionEnvironment, 0u)); auto sourceLevelDebugger = device1->getSourceLevelDebugger(); std::unique_ptr device2(Device::create(executionEnvironment, 1u)); diff --git a/unit_tests/ult_config_listener.cpp b/unit_tests/ult_config_listener.cpp index cf54499d95..55d409b080 100644 --- a/unit_tests/ult_config_listener.cpp +++ b/unit_tests/ult_config_listener.cpp @@ -12,9 +12,10 @@ #include "runtime/platform/platform.h" void NEO::UltConfigListener::OnTestStart(const ::testing::TestInfo &testInfo) { - constructPlatform()->peekExecutionEnvironment()->setHwInfo(*platformDevices); - // Create platform and initialize gmm that dont want to create Platform and test gmm initialization path - platform()->peekExecutionEnvironment()->initGmm(); + auto executionEnvironment = constructPlatform()->peekExecutionEnvironment(); + executionEnvironment->prepareRootDeviceEnvironments(1); + executionEnvironment->setHwInfo(*platformDevices); + executionEnvironment->initGmm(); } void NEO::UltConfigListener::OnTestEnd(const ::testing::TestInfo &testInfo) { // Clear global platform that it shouldn't be reused between tests