diff --git a/core/execution_environment/root_device_environment.cpp b/core/execution_environment/root_device_environment.cpp index 6f60c5fde8..459af59e15 100644 --- a/core/execution_environment/root_device_environment.cpp +++ b/core/execution_environment/root_device_environment.cpp @@ -11,6 +11,7 @@ #include "core/memory_manager/memory_operations_handler.h" #include "runtime/aub/aub_center.h" #include "runtime/execution_environment/execution_environment.h" +#include "runtime/os_interface/os_interface.h" namespace NEO { diff --git a/core/execution_environment/root_device_environment.h b/core/execution_environment/root_device_environment.h index 336f0a1bd2..a7d1a72aaf 100644 --- a/core/execution_environment/root_device_environment.h +++ b/core/execution_environment/root_device_environment.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 Intel Corporation + * Copyright (C) 2019-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -18,6 +18,7 @@ class AubCenter; class ExecutionEnvironment; class GmmPageTableMngr; class MemoryOperationsHandler; +class OSInterface; struct RootDeviceEnvironment { RootDeviceEnvironment(ExecutionEnvironment &executionEnvironment); @@ -26,6 +27,7 @@ struct RootDeviceEnvironment { MOCKABLE_VIRTUAL void initAubCenter(bool localMemoryEnabled, const std::string &aubFileName, CommandStreamReceiverType csrType); + std::unique_ptr osInterface; std::unique_ptr pageTableManager; std::unique_ptr memoryOperationsInterface; std::unique_ptr aubCenter; diff --git a/core/memory_manager/host_ptr_manager.cpp b/core/memory_manager/host_ptr_manager.cpp index 7f72c629ff..3bda231c34 100644 --- a/core/memory_manager/host_ptr_manager.cpp +++ b/core/memory_manager/host_ptr_manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2019 Intel Corporation + * Copyright (C) 2017-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -246,7 +246,7 @@ OsHandleStorage HostPtrManager::prepareOsStorageForAllocation(MemoryManager &mem UNRECOVERABLE_IF(checkAllocationsForOverlapping(memoryManager, &requirements) == RequirementsStatus::FATAL); auto osStorage = populateAlreadyAllocatedFragments(requirements); if (osStorage.fragmentCount > 0) { - if (memoryManager.populateOsHandles(osStorage) != MemoryManager::AllocationStatus::Success) { + if (memoryManager.populateOsHandles(osStorage, rootDeviceIndex) != MemoryManager::AllocationStatus::Success) { memoryManager.cleanOsHandles(osStorage, rootDeviceIndex); osStorage.fragmentCount = 0; } diff --git a/core/unit_tests/os_interface/windows/wddm_preemption_tests.cpp b/core/unit_tests/os_interface/windows/wddm_preemption_tests.cpp index 4e95fe6e4e..3201bc85dd 100644 --- a/core/unit_tests/os_interface/windows/wddm_preemption_tests.cpp +++ b/core/unit_tests/os_interface/windows/wddm_preemption_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2019 Intel Corporation + * Copyright (C) 2018-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -31,10 +31,10 @@ class WddmPreemptionTests : public Test { void createAndInitWddm(unsigned int forceReturnPreemptionRegKeyValue) { wddm = static_cast(Wddm::createWddm(*executionEnvironment->rootDeviceEnvironments[0].get())); - executionEnvironment->osInterface = std::make_unique(); - executionEnvironment->osInterface->get()->setWddm(wddm); + executionEnvironment->rootDeviceEnvironments[0]->osInterface = std::make_unique(); + executionEnvironment->rootDeviceEnvironments[0]->osInterface->get()->setWddm(wddm); executionEnvironment->rootDeviceEnvironments[0]->memoryOperationsInterface = std::make_unique(wddm); - osInterface = executionEnvironment->osInterface.get(); + osInterface = executionEnvironment->rootDeviceEnvironments[0]->osInterface.get(); auto regReader = new RegistryReaderMock(); wddm->registryReader.reset(regReader); regReader->forceRetValue = forceReturnPreemptionRegKeyValue; diff --git a/runtime/command_stream/tbx_command_stream_receiver_hw.h b/runtime/command_stream/tbx_command_stream_receiver_hw.h index 20cb7f641e..01b99c79ca 100644 --- a/runtime/command_stream/tbx_command_stream_receiver_hw.h +++ b/runtime/command_stream/tbx_command_stream_receiver_hw.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2019 Intel Corporation + * Copyright (C) 2017-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -24,7 +24,7 @@ class TbxStream; class TbxMemoryManager : public OsAgnosticMemoryManager { public: TbxMemoryManager(ExecutionEnvironment &executionEnvironment) : OsAgnosticMemoryManager(executionEnvironment) {} - uint64_t getSystemSharedMemory() override { + uint64_t getSystemSharedMemory(uint32_t rootDeviceIndex) override { return 1 * GB; } }; diff --git a/runtime/device/device.cpp b/runtime/device/device.cpp index d529426b4d..640a64d493 100644 --- a/runtime/device/device.cpp +++ b/runtime/device/device.cpp @@ -8,6 +8,7 @@ #include "runtime/device/device.h" #include "core/command_stream/preemption.h" +#include "core/execution_environment/root_device_environment.h" #include "core/helpers/hw_helper.h" #include "core/os_interface/os_context.h" #include "core/program/sync_buffer_handler.h" @@ -15,7 +16,6 @@ #include "runtime/command_stream/experimental_command_buffer.h" #include "runtime/device/device_vector.h" #include "runtime/device/driver_info.h" -#include "runtime/execution_environment/execution_environment.h" #include "runtime/memory_manager/memory_manager.h" #include "runtime/os_interface/os_interface.h" #include "runtime/os_interface/os_time.h" @@ -86,7 +86,7 @@ bool Device::createDeviceImpl() { } executionEnvironment->memoryManager->setDefaultEngineIndex(defaultEngineIndex); - auto osInterface = executionEnvironment->osInterface.get(); + auto osInterface = getRootDeviceEnvironment().osInterface.get(); if (!osTime) { osTime = OSTime::create(osInterface); diff --git a/runtime/device/device_caps.cpp b/runtime/device/device_caps.cpp index f4de341a5c..7a4d193fa8 100644 --- a/runtime/device/device_caps.cpp +++ b/runtime/device/device_caps.cpp @@ -238,8 +238,8 @@ void Device::initializeCaps() { deviceInfo.grfSize = hwInfo.capabilityTable.grfSize; deviceInfo.globalMemSize = getMemoryManager()->isLocalMemorySupported() - ? getMemoryManager()->getLocalMemorySize() - : getMemoryManager()->getSystemSharedMemory(); + ? getMemoryManager()->getLocalMemorySize(this->getRootDeviceIndex()) + : getMemoryManager()->getSystemSharedMemory(this->getRootDeviceIndex()); deviceInfo.globalMemSize = std::min(deviceInfo.globalMemSize, (cl_ulong)(getMemoryManager()->getMaxApplicationAddress() + 1)); deviceInfo.globalMemSize = (cl_ulong)((double)deviceInfo.globalMemSize * 0.8); diff --git a/runtime/execution_environment/execution_environment.cpp b/runtime/execution_environment/execution_environment.cpp index 835ba9e413..f239443ad5 100644 --- a/runtime/execution_environment/execution_environment.cpp +++ b/runtime/execution_environment/execution_environment.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2019 Intel Corporation + * Copyright (C) 2018-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -16,7 +16,6 @@ #include "runtime/compiler_interface/default_cl_cache_config.h" #include "runtime/helpers/device_helpers.h" #include "runtime/memory_manager/memory_manager.h" -#include "runtime/os_interface/os_interface.h" #include "runtime/source_level_debugger/source_level_debugger.h" namespace NEO { @@ -33,7 +32,7 @@ ExecutionEnvironment::~ExecutionEnvironment() { void ExecutionEnvironment::initGmm() { if (!gmmHelper) { - gmmHelper.reset(new GmmHelper(osInterface.get(), hwInfo.get())); + gmmHelper.reset(new GmmHelper(rootDeviceEnvironments[0]->osInterface.get(), hwInfo.get())); } } diff --git a/runtime/execution_environment/execution_environment.h b/runtime/execution_environment/execution_environment.h index 3e36af934f..9591cca811 100644 --- a/runtime/execution_environment/execution_environment.h +++ b/runtime/execution_environment/execution_environment.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2019 Intel Corporation + * Copyright (C) 2018-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -18,7 +18,6 @@ class CompilerInterface; class GmmClientContext; class GmmHelper; class MemoryManager; -class OSInterface; class SourceLevelDebugger; struct RootDeviceEnvironment; struct HardwareInfo; @@ -51,7 +50,6 @@ class ExecutionEnvironment : public ReferenceTrackedObject MOCKABLE_VIRTUAL CompilerInterface *getCompilerInterface(); BuiltIns *getBuiltIns(); - std::unique_ptr osInterface; std::unique_ptr memoryManager; std::vector> rootDeviceEnvironments; std::unique_ptr builtins; diff --git a/runtime/memory_manager/memory_manager.cpp b/runtime/memory_manager/memory_manager.cpp index 84b12220d1..d6a09f4f52 100644 --- a/runtime/memory_manager/memory_manager.cpp +++ b/runtime/memory_manager/memory_manager.cpp @@ -193,7 +193,8 @@ bool MemoryManager::isMemoryBudgetExhausted() const { OsContext *MemoryManager::createAndRegisterOsContext(CommandStreamReceiver *commandStreamReceiver, aub_stream::EngineType engineType, DeviceBitfield deviceBitfield, PreemptionMode preemptionMode, bool lowPriority) { auto contextId = ++latestContextId; - auto osContext = OsContext::create(peekExecutionEnvironment().osInterface.get(), contextId, deviceBitfield, engineType, preemptionMode, lowPriority); + auto rootDeviceIndex = commandStreamReceiver ? commandStreamReceiver->getRootDeviceIndex() : 0u; + auto osContext = OsContext::create(peekExecutionEnvironment().rootDeviceEnvironments[rootDeviceIndex]->osInterface.get(), contextId, deviceBitfield, engineType, preemptionMode, lowPriority); UNRECOVERABLE_IF(!osContext->isInitialized()); osContext->incRefInternal(); diff --git a/runtime/memory_manager/memory_manager.h b/runtime/memory_manager/memory_manager.h index c192dc1d61..e929f1850c 100644 --- a/runtime/memory_manager/memory_manager.h +++ b/runtime/memory_manager/memory_manager.h @@ -83,7 +83,7 @@ class MemoryManager { GraphicsAllocation *createGraphicsAllocationWithPadding(GraphicsAllocation *inputGraphicsAllocation, size_t sizeWithPadding); virtual GraphicsAllocation *createPaddedAllocation(GraphicsAllocation *inputGraphicsAllocation, size_t sizeWithPadding); - virtual AllocationStatus populateOsHandles(OsHandleStorage &handleStorage) = 0; + virtual AllocationStatus populateOsHandles(OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) = 0; virtual void cleanOsHandles(OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) = 0; void freeSystemMemory(void *ptr); @@ -94,8 +94,8 @@ class MemoryManager { void checkGpuUsageAndDestroyGraphicsAllocations(GraphicsAllocation *gfxAllocation); - virtual uint64_t getSystemSharedMemory() = 0; - virtual uint64_t getLocalMemorySize() = 0; + virtual uint64_t getSystemSharedMemory(uint32_t rootDeviceIndex) = 0; + virtual uint64_t getLocalMemorySize(uint32_t rootDeviceIndex) = 0; uint64_t getMaxApplicationAddress() { return is64bit ? MemoryConstants::max64BitAppAddress : MemoryConstants::max32BitAppAddress; }; uint64_t getInternalHeapBaseAddress(uint32_t rootDeviceIndex) { return getGfxPartition(rootDeviceIndex)->getHeapBase(HeapIndex::HEAP_INTERNAL_DEVICE_MEMORY); } @@ -153,8 +153,8 @@ class MemoryManager { virtual bool copyMemoryToAllocation(GraphicsAllocation *graphicsAllocation, const void *memoryToCopy, size_t sizeToCopy); static HeapIndex selectHeap(const GraphicsAllocation *allocation, bool hasPointer, bool isFullRangeSVM); static std::unique_ptr createMemoryManager(ExecutionEnvironment &executionEnvironment); - virtual void *reserveCpuAddressRange(size_t size) { return nullptr; }; - virtual void releaseReservedCpuAddressRange(void *reserved, size_t size){}; + virtual void *reserveCpuAddressRange(size_t size, uint32_t rootDeviceIndex) { return nullptr; }; + virtual void releaseReservedCpuAddressRange(void *reserved, size_t size, uint32_t rootDeviceIndex){}; void *getReservedMemory(size_t size, size_t alignment); GfxPartition *getGfxPartition(uint32_t rootDeviceIndex) { return gfxPartitions.at(rootDeviceIndex).get(); } diff --git a/runtime/memory_manager/os_agnostic_memory_manager.cpp b/runtime/memory_manager/os_agnostic_memory_manager.cpp index 6b6ed48023..38a0a78fd4 100644 --- a/runtime/memory_manager/os_agnostic_memory_manager.cpp +++ b/runtime/memory_manager/os_agnostic_memory_manager.cpp @@ -62,7 +62,7 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemoryWithAlignment if (allocationData.type == GraphicsAllocation::AllocationType::SVM_CPU) { //add 2MB padding in case mapPtr is not 2MB aligned size_t reserveSize = sizeAligned + allocationData.alignment; - void *gpuPtr = reserveCpuAddressRange(reserveSize); + void *gpuPtr = reserveCpuAddressRange(reserveSize, allocationData.rootDeviceIndex); if (!gpuPtr) { delete memoryAllocation; alignedFreeWrapper(ptr); @@ -215,7 +215,7 @@ void OsAgnosticMemoryManager::freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllo alignedFreeWrapper(gfxAllocation->getDriverAllocatedCpuPtr()); if (gfxAllocation->getReservedAddressPtr()) { - releaseReservedCpuAddressRange(gfxAllocation->getReservedAddressPtr(), gfxAllocation->getReservedAddressSize()); + releaseReservedCpuAddressRange(gfxAllocation->getReservedAddressPtr(), gfxAllocation->getReservedAddressSize(), gfxAllocation->getRootDeviceIndex()); } auto rootDeviceIndex = gfxAllocation->getRootDeviceIndex(); @@ -229,7 +229,7 @@ void OsAgnosticMemoryManager::freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllo delete gfxAllocation; } -uint64_t OsAgnosticMemoryManager::getSystemSharedMemory() { +uint64_t OsAgnosticMemoryManager::getSystemSharedMemory(uint32_t rootDeviceIndex) { return 16 * GB; } @@ -246,7 +246,7 @@ void OsAgnosticMemoryManager::turnOnFakingBigAllocations() { this->fakeBigAllocations = true; } -MemoryManager::AllocationStatus OsAgnosticMemoryManager::populateOsHandles(OsHandleStorage &handleStorage) { +MemoryManager::AllocationStatus OsAgnosticMemoryManager::populateOsHandles(OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) { for (unsigned int i = 0; i < maxFragmentsCount; i++) { if (!handleStorage.fragmentStorageData[i].osHandleStorage && handleStorage.fragmentStorageData[i].cpuPtr) { handleStorage.fragmentStorageData[i].osHandleStorage = new OsHandle(); @@ -318,12 +318,12 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemoryForImageImpl( return alloc; } -void *OsAgnosticMemoryManager::reserveCpuAddressRange(size_t size) { +void *OsAgnosticMemoryManager::reserveCpuAddressRange(size_t size, uint32_t rootDeviceIndex) { void *reservePtr = allocateSystemMemory(size, MemoryConstants::preferredAlignment); return reservePtr; } -void OsAgnosticMemoryManager::releaseReservedCpuAddressRange(void *reserved, size_t size) { +void OsAgnosticMemoryManager::releaseReservedCpuAddressRange(void *reserved, size_t size, uint32_t rootDeviceIndex) { alignedFreeWrapper(reserved); } diff --git a/runtime/memory_manager/os_agnostic_memory_manager.h b/runtime/memory_manager/os_agnostic_memory_manager.h index e8b521556b..76fc5d495b 100644 --- a/runtime/memory_manager/os_agnostic_memory_manager.h +++ b/runtime/memory_manager/os_agnostic_memory_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2019 Intel Corporation + * Copyright (C) 2017-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -56,16 +56,16 @@ class OsAgnosticMemoryManager : public MemoryManager { void removeAllocationFromHostPtrManager(GraphicsAllocation *gfxAllocation) override; void freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation) override; - AllocationStatus populateOsHandles(OsHandleStorage &handleStorage) override; + AllocationStatus populateOsHandles(OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override; void cleanOsHandles(OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override; - uint64_t getSystemSharedMemory() override; - uint64_t getLocalMemorySize() override; + uint64_t getSystemSharedMemory(uint32_t rootDeviceIndex) override; + uint64_t getLocalMemorySize(uint32_t rootDeviceIndex) override; void turnOnFakingBigAllocations(); - void *reserveCpuAddressRange(size_t size) override; - void releaseReservedCpuAddressRange(void *reserved, size_t size) override; + void *reserveCpuAddressRange(size_t size, uint32_t rootDeviceIndex) override; + void releaseReservedCpuAddressRange(void *reserved, size_t size, uint32_t rootDeviceIndex) override; protected: GraphicsAllocation *createGraphicsAllocation(OsHandleStorage &handleStorage, const AllocationData &allocationData) override; diff --git a/runtime/memory_manager/os_agnostic_memory_manager_allocate_in_device_pool.cpp b/runtime/memory_manager/os_agnostic_memory_manager_allocate_in_device_pool.cpp index 0826be9d69..b74cb8dc77 100644 --- a/runtime/memory_manager/os_agnostic_memory_manager_allocate_in_device_pool.cpp +++ b/runtime/memory_manager/os_agnostic_memory_manager_allocate_in_device_pool.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2019 Intel Corporation + * Copyright (C) 2018-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -40,7 +40,7 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemoryInDevicePool( return nullptr; } -uint64_t OsAgnosticMemoryManager::getLocalMemorySize() { +uint64_t OsAgnosticMemoryManager::getLocalMemorySize(uint32_t rootDeviceIndex) { return 0 * GB; } diff --git a/runtime/os_interface/linux/device_factory_linux.cpp b/runtime/os_interface/linux/device_factory_linux.cpp index 800c9478ae..88fbb04044 100644 --- a/runtime/os_interface/linux/device_factory_linux.cpp +++ b/runtime/os_interface/linux/device_factory_linux.cpp @@ -30,21 +30,21 @@ bool DeviceFactory::getDevices(size_t &numDevices, ExecutionEnvironment &executi executionEnvironment.prepareRootDeviceEnvironments(static_cast(numRootDevices)); - Drm *drm = Drm::create(devNum); - if (!drm) { - return false; - } - for (auto rootDeviceIndex = 0u; rootDeviceIndex < numRootDevices; rootDeviceIndex++) { + Drm *drm = Drm::create(rootDeviceIndex); + if (!drm) { + return false; + } + executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->memoryOperationsInterface = std::make_unique(); + executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->osInterface.reset(new OSInterface()); + executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->osInterface->get()->setDrm(drm); } - executionEnvironment.osInterface.reset(new OSInterface()); - executionEnvironment.osInterface->get()->setDrm(drm); auto hardwareInfo = executionEnvironment.getMutableHardwareInfo(); const HardwareInfo *pCurrDevice = platformDevices[devNum]; HwInfoConfig *hwConfig = HwInfoConfig::get(pCurrDevice->platform.eProductFamily); - if (hwConfig->configureHwInfo(pCurrDevice, hardwareInfo, executionEnvironment.osInterface.get())) { + if (hwConfig->configureHwInfo(pCurrDevice, hardwareInfo, executionEnvironment.rootDeviceEnvironments[0]->osInterface.get())) { return false; } executionEnvironment.calculateMaxOsContextCount(); diff --git a/runtime/os_interface/linux/drm_allocation.cpp b/runtime/os_interface/linux/drm_allocation.cpp index 1c608aac82..03274e49ab 100644 --- a/runtime/os_interface/linux/drm_allocation.cpp +++ b/runtime/os_interface/linux/drm_allocation.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 Intel Corporation + * Copyright (C) 2019-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -24,6 +24,6 @@ std::string DrmAllocation::getAllocationInfoString() const { } uint64_t DrmAllocation::peekInternalHandle(MemoryManager *memoryManager) { - return static_cast((static_cast(memoryManager))->obtainFdFromHandle(getBO()->peekHandle())); + return static_cast((static_cast(memoryManager))->obtainFdFromHandle(getBO()->peekHandle(), this->rootDeviceIndex)); } } // namespace NEO diff --git a/runtime/os_interface/linux/drm_command_stream.inl b/runtime/os_interface/linux/drm_command_stream.inl index 193b1f156e..ea027d469f 100644 --- a/runtime/os_interface/linux/drm_command_stream.inl +++ b/runtime/os_interface/linux/drm_command_stream.inl @@ -33,13 +33,13 @@ template DrmCommandStreamReceiver::DrmCommandStreamReceiver(ExecutionEnvironment &executionEnvironment, uint32_t rootDeviceIndex, gemCloseWorkerMode mode) : BaseClass(executionEnvironment, rootDeviceIndex), gemCloseWorkerOperationMode(mode) { - this->drm = executionEnvironment.osInterface->get()->getDrm(); + this->drm = executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->osInterface->get()->getDrm(); residency.reserve(512); execObjectsStorage.reserve(512); - executionEnvironment.osInterface->get()->setDrm(this->drm); - CommandStreamReceiver::osInterface = executionEnvironment.osInterface.get(); + executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->osInterface->get()->setDrm(this->drm); + CommandStreamReceiver::osInterface = executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->osInterface.get(); } template diff --git a/runtime/os_interface/linux/drm_memory_manager.cpp b/runtime/os_interface/linux/drm_memory_manager.cpp index 7ca9e13eca..643f200306 100644 --- a/runtime/os_interface/linux/drm_memory_manager.cpp +++ b/runtime/os_interface/linux/drm_memory_manager.cpp @@ -7,6 +7,7 @@ #include "runtime/os_interface/linux/drm_memory_manager.h" +#include "core/execution_environment/root_device_environment.h" #include "core/gmm_helper/gmm.h" #include "core/gmm_helper/gmm_helper.h" #include "core/gmm_helper/resource_info.h" @@ -34,7 +35,6 @@ DrmMemoryManager::DrmMemoryManager(gemCloseWorkerMode mode, bool forcePinAllowed, bool validateHostPtrMemory, ExecutionEnvironment &executionEnvironment) : MemoryManager(executionEnvironment), - drm(executionEnvironment.osInterface->get()->getDrm()), forcePinEnabled(forcePinAllowed), validateHostPtrMemory(validateHostPtrMemory) { auto gpuAddressSpace = executionEnvironment.getHardwareInfo()->capabilityTable.gpuAddressSpace; @@ -140,11 +140,11 @@ NEO::BufferObject *DrmMemoryManager::allocUserptr(uintptr_t address, size_t size userptr.user_size = size; userptr.flags = static_cast(flags); - if (this->drm->ioctl(DRM_IOCTL_I915_GEM_USERPTR, &userptr) != 0) { + if (this->getDrm(rootDeviceIndex).ioctl(DRM_IOCTL_I915_GEM_USERPTR, &userptr) != 0) { return nullptr; } - auto res = new (std::nothrow) BufferObject(this->drm, userptr.handle, rootDeviceIndex); + auto res = new (std::nothrow) BufferObject(&getDrm(rootDeviceIndex), userptr.handle, rootDeviceIndex); if (!res) { DEBUG_BREAK_IF(true); return nullptr; @@ -283,11 +283,11 @@ GraphicsAllocation *DrmMemoryManager::allocateShareableMemory(const AllocationDa drm_i915_gem_create create = {0, 0, 0}; create.size = bufferSize; - auto ret = this->drm->ioctl(DRM_IOCTL_I915_GEM_CREATE, &create); + auto ret = this->getDrm(allocationData.rootDeviceIndex).ioctl(DRM_IOCTL_I915_GEM_CREATE, &create); DEBUG_BREAK_IF(ret != 0); ((void)(ret)); - auto bo = new BufferObject(this->drm, create.handle, allocationData.rootDeviceIndex); + auto bo = new BufferObject(&getDrm(allocationData.rootDeviceIndex), create.handle, allocationData.rootDeviceIndex); bo->size = bufferSize; bo->gpuAddress = gpuRange; @@ -313,11 +313,11 @@ GraphicsAllocation *DrmMemoryManager::allocateGraphicsMemoryForImageImpl(const A drm_i915_gem_create create = {0, 0, 0}; create.size = allocationData.imgInfo->size; - auto ret = this->drm->ioctl(DRM_IOCTL_I915_GEM_CREATE, &create); + auto ret = this->getDrm(allocationData.rootDeviceIndex).ioctl(DRM_IOCTL_I915_GEM_CREATE, &create); DEBUG_BREAK_IF(ret != 0); UNUSED_VARIABLE(ret); - auto bo = new (std::nothrow) BufferObject(this->drm, create.handle, allocationData.rootDeviceIndex); + auto bo = new (std::nothrow) BufferObject(&getDrm(allocationData.rootDeviceIndex), create.handle, allocationData.rootDeviceIndex); if (!bo) { return nullptr; } @@ -422,7 +422,7 @@ BufferObject *DrmMemoryManager::createSharedBufferObject(int boHandle, size_t si gpuRange = acquireGpuRange(size, requireSpecificBitness, rootDeviceIndex); - auto bo = new (std::nothrow) BufferObject(this->drm, boHandle, rootDeviceIndex); + auto bo = new (std::nothrow) BufferObject(&getDrm(rootDeviceIndex), boHandle, rootDeviceIndex); if (!bo) { return nullptr; } @@ -439,7 +439,7 @@ GraphicsAllocation *DrmMemoryManager::createGraphicsAllocationFromSharedHandle(o drm_prime_handle openFd = {0, 0, 0}; openFd.fd = handle; - auto ret = this->drm->ioctl(DRM_IOCTL_PRIME_FD_TO_HANDLE, &openFd); + auto ret = this->getDrm(properties.rootDeviceIndex).ioctl(DRM_IOCTL_PRIME_FD_TO_HANDLE, &openFd); if (ret != 0) { int err = errno; @@ -476,7 +476,7 @@ GraphicsAllocation *DrmMemoryManager::createGraphicsAllocationFromSharedHandle(o if (properties.imgInfo) { drm_i915_gem_get_tiling getTiling = {0}; getTiling.handle = boHandle; - ret = this->drm->ioctl(DRM_IOCTL_I915_GEM_GET_TILING, &getTiling); + ret = this->getDrm(properties.rootDeviceIndex).ioctl(DRM_IOCTL_I915_GEM_GET_TILING, &getTiling); DEBUG_BREAK_IF(ret != 0); UNUSED_VARIABLE(ret); @@ -569,12 +569,12 @@ void DrmMemoryManager::handleFenceCompletion(GraphicsAllocation *allocation) { static_cast(allocation)->getBO()->wait(-1); } -uint64_t DrmMemoryManager::getSystemSharedMemory() { +uint64_t DrmMemoryManager::getSystemSharedMemory(uint32_t rootDeviceIndex) { uint64_t hostMemorySize = MemoryConstants::pageSize * (uint64_t)(sysconf(_SC_PHYS_PAGES)); drm_i915_gem_context_param getContextParam = {}; getContextParam.param = I915_CONTEXT_PARAM_GTT_SIZE; - auto ret = drm->ioctl(DRM_IOCTL_I915_GEM_CONTEXT_GETPARAM, &getContextParam); + auto ret = getDrm(rootDeviceIndex).ioctl(DRM_IOCTL_I915_GEM_CONTEXT_GETPARAM, &getContextParam); DEBUG_BREAK_IF(ret != 0); UNUSED_VARIABLE(ret); uint64_t gpuMemorySize = getContextParam.value; @@ -582,7 +582,7 @@ uint64_t DrmMemoryManager::getSystemSharedMemory() { return std::min(hostMemorySize, gpuMemorySize); } -MemoryManager::AllocationStatus DrmMemoryManager::populateOsHandles(OsHandleStorage &handleStorage) { +MemoryManager::AllocationStatus DrmMemoryManager::populateOsHandles(OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) { BufferObject *allocatedBos[maxFragmentsCount]; uint32_t numberOfBosAllocated = 0; uint32_t indexesOfAllocatedBos[maxFragmentsCount]; @@ -661,7 +661,7 @@ bool DrmMemoryManager::setDomainCpu(GraphicsAllocation &graphicsAllocation, bool set_domain.read_domains = I915_GEM_DOMAIN_CPU; set_domain.write_domain = writeEnable ? I915_GEM_DOMAIN_CPU : 0; - return drm->ioctl(DRM_IOCTL_I915_GEM_SET_DOMAIN, &set_domain) == 0; + return getDrm(graphicsAllocation.getRootDeviceIndex()).ioctl(DRM_IOCTL_I915_GEM_SET_DOMAIN, &set_domain) == 0; } void *DrmMemoryManager::lockResourceImpl(GraphicsAllocation &graphicsAllocation) { @@ -684,7 +684,7 @@ void *DrmMemoryManager::lockResourceImpl(GraphicsAllocation &graphicsAllocation) drm_i915_gem_mmap mmap_arg = {}; mmap_arg.handle = bo->peekHandle(); mmap_arg.size = bo->peekSize(); - if (drm->ioctl(DRM_IOCTL_I915_GEM_MMAP, &mmap_arg) != 0) { + if (getDrm(graphicsAllocation.getRootDeviceIndex()).ioctl(DRM_IOCTL_I915_GEM_MMAP, &mmap_arg) != 0) { return nullptr; } @@ -707,18 +707,18 @@ void DrmMemoryManager::unlockResourceImpl(GraphicsAllocation &graphicsAllocation if (bo == nullptr) return; - releaseReservedCpuAddressRange(bo->peekLockedAddress(), bo->peekSize()); + releaseReservedCpuAddressRange(bo->peekLockedAddress(), bo->peekSize(), graphicsAllocation.getRootDeviceIndex()); bo->setLockedAddress(nullptr); } -int DrmMemoryManager::obtainFdFromHandle(int boHandle) { +int DrmMemoryManager::obtainFdFromHandle(int boHandle, uint32_t rootDeviceindex) { drm_prime_handle openFd = {0, 0, 0}; openFd.flags = DRM_CLOEXEC | DRM_RDWR; openFd.handle = boHandle; - drm->ioctl(DRM_IOCTL_PRIME_HANDLE_TO_FD, &openFd); + getDrm(rootDeviceindex).ioctl(DRM_IOCTL_PRIME_HANDLE_TO_FD, &openFd); return openFd.fd; } @@ -728,4 +728,8 @@ uint32_t DrmMemoryManager::getDefaultDrmContextId() const { return osContextLinux->getDrmContextIds()[0]; } +Drm &DrmMemoryManager::getDrm(uint32_t rootDeviceIndex) const { + return *this->executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->osInterface->get()->getDrm(); +} + } // namespace NEO diff --git a/runtime/os_interface/linux/drm_memory_manager.h b/runtime/os_interface/linux/drm_memory_manager.h index fdc596ba83..0d9005f6c3 100644 --- a/runtime/os_interface/linux/drm_memory_manager.h +++ b/runtime/os_interface/linux/drm_memory_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2019 Intel Corporation + * Copyright (C) 2017-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -37,10 +37,10 @@ class DrmMemoryManager : public MemoryManager { GraphicsAllocation *createPaddedAllocation(GraphicsAllocation *inputGraphicsAllocation, size_t sizeWithPadding) override; GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex) override { return nullptr; } - uint64_t getSystemSharedMemory() override; - uint64_t getLocalMemorySize() override; + uint64_t getSystemSharedMemory(uint32_t rootDeviceIndex) override; + uint64_t getLocalMemorySize(uint32_t rootDeviceIndex) override; - AllocationStatus populateOsHandles(OsHandleStorage &handleStorage) override; + AllocationStatus populateOsHandles(OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override; void cleanOsHandles(OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override; // drm/i915 ioctl wrappers @@ -53,7 +53,7 @@ class DrmMemoryManager : public MemoryManager { DrmGemCloseWorker *peekGemCloseWorker() const { return this->gemCloseWorker.get(); } bool copyMemoryToAllocation(GraphicsAllocation *graphicsAllocation, const void *memoryToCopy, size_t sizeToCopy) override; - int obtainFdFromHandle(int boHandle); + int obtainFdFromHandle(int boHandle, uint32_t rootDeviceindex); protected: BufferObject *findAndReferenceSharedBufferObject(int boHandle); @@ -83,7 +83,8 @@ class DrmMemoryManager : public MemoryManager { DrmAllocation *allocate32BitGraphicsMemoryImpl(const AllocationData &allocationData) override; GraphicsAllocation *allocateGraphicsMemoryInDevicePool(const AllocationData &allocationData, AllocationStatus &status) override; - Drm *drm; + Drm &getDrm(uint32_t rootDeviceIndex) const; + BufferObject *pinBB = nullptr; void *memoryForPinBB = nullptr; size_t pinThreshold = 8 * 1024 * 1024; diff --git a/runtime/os_interface/linux/drm_memory_manager_allocate_in_device_pool.cpp b/runtime/os_interface/linux/drm_memory_manager_allocate_in_device_pool.cpp index d864ffe2ce..e7733ffd93 100644 --- a/runtime/os_interface/linux/drm_memory_manager_allocate_in_device_pool.cpp +++ b/runtime/os_interface/linux/drm_memory_manager_allocate_in_device_pool.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 Intel Corporation + * Copyright (C) 2019-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -29,7 +29,7 @@ bool DrmMemoryManager::copyMemoryToAllocation(GraphicsAllocation *graphicsAlloca return MemoryManager::copyMemoryToAllocation(graphicsAllocation, memoryToCopy, sizeToCopy); } -uint64_t DrmMemoryManager::getLocalMemorySize() { +uint64_t DrmMemoryManager::getLocalMemorySize(uint32_t rootDeviceIndex) { return 0 * GB; } } // namespace NEO diff --git a/runtime/os_interface/windows/device_factory_win.cpp b/runtime/os_interface/windows/device_factory_win.cpp index 8409cab025..672c543b82 100644 --- a/runtime/os_interface/windows/device_factory_win.cpp +++ b/runtime/os_interface/windows/device_factory_win.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2019 Intel Corporation + * Copyright (C) 2017-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -32,18 +32,17 @@ bool DeviceFactory::getDevices(size_t &numDevices, ExecutionEnvironment &executi executionEnvironment.prepareRootDeviceEnvironments(static_cast(numRootDevices)); auto hardwareInfo = executionEnvironment.getMutableHardwareInfo(); - std::unique_ptr wddm(Wddm::createWddm(*executionEnvironment.rootDeviceEnvironments[0].get())); - if (!wddm->init(*hardwareInfo)) { - return false; + for (auto rootDeviceIndex = 0u; rootDeviceIndex < numRootDevices; rootDeviceIndex++) { + std::unique_ptr wddm(Wddm::createWddm(*executionEnvironment.rootDeviceEnvironments[rootDeviceIndex].get())); + if (!wddm->init(*hardwareInfo)) { + return false; + } + executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->memoryOperationsInterface = std::make_unique(wddm.get()); + executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->osInterface = std::make_unique(); + executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->osInterface->get()->setWddm(wddm.release()); } executionEnvironment.calculateMaxOsContextCount(); - for (auto rootDeviceIndex = 0u; rootDeviceIndex < numRootDevices; rootDeviceIndex++) { - executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->memoryOperationsInterface = std::make_unique(wddm.get()); - } - executionEnvironment.osInterface = std::make_unique(); - executionEnvironment.osInterface->get()->setWddm(wddm.release()); - numDevices = numRootDevices; DeviceFactory::numDevices = numDevices; diff --git a/runtime/os_interface/windows/wddm_device_command_stream.inl b/runtime/os_interface/windows/wddm_device_command_stream.inl index e6f241a375..2ce95eec5b 100644 --- a/runtime/os_interface/windows/wddm_device_command_stream.inl +++ b/runtime/os_interface/windows/wddm_device_command_stream.inl @@ -37,8 +37,8 @@ WddmCommandStreamReceiver::WddmCommandStreamReceiver(ExecutionEnviron : BaseClass(executionEnvironment, rootDeviceIndex) { notifyAubCaptureImpl = DeviceCallbacks::notifyAubCapture; - this->wddm = executionEnvironment.osInterface->get()->getWddm(); - this->osInterface = executionEnvironment.osInterface.get(); + this->osInterface = executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->osInterface.get(); + this->wddm = this->osInterface->get()->getWddm(); PreemptionMode preemptionMode = PreemptionHelper::getDefaultPreemptionMode(peekHwInfo()); diff --git a/runtime/os_interface/windows/wddm_memory_manager.cpp b/runtime/os_interface/windows/wddm_memory_manager.cpp index 851d83919c..1c3ce71378 100644 --- a/runtime/os_interface/windows/wddm_memory_manager.cpp +++ b/runtime/os_interface/windows/wddm_memory_manager.cpp @@ -37,17 +37,15 @@ namespace NEO { WddmMemoryManager::~WddmMemoryManager() = default; -WddmMemoryManager::WddmMemoryManager(ExecutionEnvironment &executionEnvironment) : MemoryManager(executionEnvironment), - wddm(executionEnvironment.osInterface->get()->getWddm()) { - DEBUG_BREAK_IF(wddm == nullptr); - +WddmMemoryManager::WddmMemoryManager(ExecutionEnvironment &executionEnvironment) : MemoryManager(executionEnvironment) { asyncDeleterEnabled = isDeferredDeleterEnabled(); if (asyncDeleterEnabled) deferredDeleter = createDeferredDeleter(); - mallocRestrictions.minAddress = wddm->getWddmMinAddress(); + mallocRestrictions.minAddress = 0u; for (uint32_t rootDeviceIndex = 0; rootDeviceIndex < gfxPartitions.size(); ++rootDeviceIndex) { - wddm->initGfxPartition(*getGfxPartition(rootDeviceIndex)); + getWddm(rootDeviceIndex).initGfxPartition(*getGfxPartition(rootDeviceIndex)); + mallocRestrictions.minAddress = std::max(mallocRestrictions.minAddress, getWddm(rootDeviceIndex).getWddmMinAddress()); } } @@ -88,7 +86,7 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemory64kb(const Allocati auto gmm = new Gmm(executionEnvironment.getGmmClientContext(), nullptr, sizeAligned, false, allocationData.flags.preferRenderCompressed, true, {}); wddmAllocation->setDefaultGmm(gmm); - if (!wddm->createAllocation64k(gmm, wddmAllocation->getHandleToModify(0u))) { + if (!getWddm(allocationData.rootDeviceIndex).createAllocation64k(gmm, wddmAllocation->getHandleToModify(0u))) { delete gmm; return nullptr; } @@ -123,7 +121,7 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemoryWithAlignment(const if (allocationData.type == GraphicsAllocation::AllocationType::SVM_CPU) { //add 2MB padding in case mapPtr is not 2MB aligned size_t reserveSizeAligned = sizeAligned + allocationData.alignment; - bool ret = wddm->reserveValidAddressRange(reserveSizeAligned, mapPtr); + bool ret = getWddm(wddmAllocation->getRootDeviceIndex()).reserveValidAddressRange(reserveSizeAligned, mapPtr); if (!ret) { delete gmm; freeSystemMemory(pSysMem); @@ -171,7 +169,7 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemoryWithHostPtr(const A size_t sizeAligned = alignSizeWholePage(inputPtr, allocationData.size); size_t offset = ptrDiff(inputPtr, ptrAligned); - if (!wddm->reserveValidAddressRange(sizeAligned, reserve)) { + if (!getWddm(allocationData.rootDeviceIndex).reserveValidAddressRange(sizeAligned, reserve)) { return nullptr; } @@ -233,8 +231,8 @@ GraphicsAllocation *WddmMemoryManager::allocate32BitGraphicsMemoryImpl(const All GraphicsAllocation *WddmMemoryManager::createAllocationFromHandle(osHandle handle, bool requireSpecificBitness, bool ntHandle, GraphicsAllocation::AllocationType allocationType, uint32_t rootDeviceIndex) { auto allocation = std::make_unique(rootDeviceIndex, allocationType, nullptr, 0, handle, MemoryPool::SystemCpuInaccessible); - bool status = ntHandle ? wddm->openNTHandle(reinterpret_cast(static_cast(handle)), allocation.get()) - : wddm->openSharedHandle(handle, allocation.get()); + bool status = ntHandle ? getWddm(rootDeviceIndex).openNTHandle(reinterpret_cast(static_cast(handle)), allocation.get()) + : getWddm(rootDeviceIndex).openSharedHandle(handle, allocation.get()); if (!status) { return nullptr; @@ -246,7 +244,7 @@ GraphicsAllocation *WddmMemoryManager::createAllocationFromHandle(osHandle handl if (is32bit) { void *ptr = nullptr; - if (!wddm->reserveValidAddressRange(size, ptr)) { + if (!getWddm(rootDeviceIndex).reserveValidAddressRange(size, ptr)) { return nullptr; } allocation->setReservedAddressRange(ptr, size); @@ -301,13 +299,13 @@ void WddmMemoryManager::removeAllocationFromHostPtrManager(GraphicsAllocation *g void *WddmMemoryManager::lockResourceImpl(GraphicsAllocation &graphicsAllocation) { auto &wddmAllocation = static_cast(graphicsAllocation); - return wddm->lockResource(wddmAllocation.getDefaultHandle(), wddmAllocation.needsMakeResidentBeforeLock); + return getWddm(graphicsAllocation.getRootDeviceIndex()).lockResource(wddmAllocation.getDefaultHandle(), wddmAllocation.needsMakeResidentBeforeLock); } void WddmMemoryManager::unlockResourceImpl(GraphicsAllocation &graphicsAllocation) { auto &wddmAllocation = static_cast(graphicsAllocation); - wddm->unlockResource(wddmAllocation.getDefaultHandle()); + getWddm(graphicsAllocation.getRootDeviceIndex()).unlockResource(wddmAllocation.getDefaultHandle()); if (wddmAllocation.needsMakeResidentBeforeLock) { - auto evictionStatus = wddm->getTemporaryResourcesContainer()->evictResource(wddmAllocation.getDefaultHandle()); + auto evictionStatus = getWddm(graphicsAllocation.getRootDeviceIndex()).getTemporaryResourcesContainer()->evictResource(wddmAllocation.getDefaultHandle()); DEBUG_BREAK_IF(evictionStatus == MemoryOperationsStatus::FAILED); } } @@ -315,7 +313,7 @@ void WddmMemoryManager::freeAssociatedResourceImpl(GraphicsAllocation &graphicsA auto &wddmAllocation = static_cast(graphicsAllocation); if (wddmAllocation.needsMakeResidentBeforeLock) { for (auto i = 0u; i < wddmAllocation.getNumHandles(); i++) { - wddm->getTemporaryResourcesContainer()->removeResource(wddmAllocation.getHandles()[i]); + getWddm(graphicsAllocation.getRootDeviceIndex()).getTemporaryResourcesContainer()->removeResource(wddmAllocation.getHandles()[i]); } } } @@ -358,15 +356,15 @@ void WddmMemoryManager::freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation allocationHandles = input->getHandles().data(); allocationCount = input->getNumHandles(); } - auto status = tryDeferDeletions(allocationHandles, allocationCount, resourceHandle); + auto status = tryDeferDeletions(allocationHandles, allocationCount, resourceHandle, gfxAllocation->getRootDeviceIndex()); DEBUG_BREAK_IF(!status); alignedFreeWrapper(input->getDriverAllocatedCpuPtr()); } if (input->getReservedAddressPtr()) { - releaseReservedCpuAddressRange(input->getReservedAddressPtr(), input->getReservedAddressSize()); + releaseReservedCpuAddressRange(input->getReservedAddressPtr(), input->getReservedAddressSize(), gfxAllocation->getRootDeviceIndex()); } if (input->reservedGpuVirtualAddress) { - wddm->freeGpuVirtualAddress(input->reservedGpuVirtualAddress, input->reservedSizeForGpuVirtualAddress); + getWddm(gfxAllocation->getRootDeviceIndex()).freeGpuVirtualAddress(input->reservedGpuVirtualAddress, input->reservedSizeForGpuVirtualAddress); } delete gfxAllocation; } @@ -383,12 +381,12 @@ void WddmMemoryManager::handleFenceCompletion(GraphicsAllocation *allocation) { } } -bool WddmMemoryManager::tryDeferDeletions(const D3DKMT_HANDLE *handles, uint32_t allocationCount, D3DKMT_HANDLE resourceHandle) { +bool WddmMemoryManager::tryDeferDeletions(const D3DKMT_HANDLE *handles, uint32_t allocationCount, D3DKMT_HANDLE resourceHandle, uint32_t rootDeviceIndex) { bool status = true; if (deferredDeleter) { - deferredDeleter->deferDeletion(DeferrableDeletion::create(wddm, handles, allocationCount, resourceHandle)); + deferredDeleter->deferDeletion(DeferrableDeletion::create(&getWddm(rootDeviceIndex), handles, allocationCount, resourceHandle)); } else { - status = wddm->destroyAllocations(handles, allocationCount, resourceHandle); + status = getWddm(rootDeviceIndex).destroyAllocations(handles, allocationCount, resourceHandle); } return status; } @@ -411,7 +409,7 @@ bool WddmMemoryManager::validateAllocation(WddmAllocation *alloc) { return true; } -MemoryManager::AllocationStatus WddmMemoryManager::populateOsHandles(OsHandleStorage &handleStorage) { +MemoryManager::AllocationStatus WddmMemoryManager::populateOsHandles(OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) { uint32_t allocatedFragmentIndexes[maxFragmentsCount]; uint32_t allocatedFragmentsCounter = 0; @@ -427,7 +425,7 @@ MemoryManager::AllocationStatus WddmMemoryManager::populateOsHandles(OsHandleSto allocatedFragmentsCounter++; } } - auto result = wddm->createAllocationsAndMapGpuVa(handleStorage); + auto result = getWddm(rootDeviceIndex).createAllocationsAndMapGpuVa(handleStorage); if (result == STATUS_GRAPHICS_NO_VIDEO_MEMORY) { return AllocationStatus::InvalidHostPointer; @@ -454,7 +452,7 @@ void WddmMemoryManager::cleanOsHandles(OsHandleStorage &handleStorage, uint32_t } } - bool success = tryDeferDeletions(handles, allocationCount, 0); + bool success = tryDeferDeletions(handles, allocationCount, 0, rootDeviceIndex); for (unsigned int i = 0; i < maxFragmentsCount; i++) { if (handleStorage.fragmentStorageData[i].freeTheFragment) { @@ -492,8 +490,8 @@ GraphicsAllocation *WddmMemoryManager::createGraphicsAllocation(OsHandleStorage return allocation; } -uint64_t WddmMemoryManager::getSystemSharedMemory() { - return wddm->getSystemSharedMemory(); +uint64_t WddmMemoryManager::getSystemSharedMemory(uint32_t rootDeviceIndex) { + return getWddm(rootDeviceIndex).getSystemSharedMemory(); } AlignedMallocRestrictions *WddmMemoryManager::getAlignedMallocRestrictions() { @@ -518,21 +516,17 @@ bool WddmMemoryManager::mapGpuVaForOneHandleAllocation(WddmAllocation *allocatio addressToMap = allocation->reservedGpuVirtualAddress; } auto gfxPartition = getGfxPartition(allocation->getRootDeviceIndex()); - auto status = wddm->mapGpuVirtualAddress(allocation->getDefaultGmm(), allocation->getDefaultHandle(), - gfxPartition->getHeapMinimalAddress(heapIndex), gfxPartition->getHeapLimit(heapIndex), - addressToMap, allocation->getGpuAddressToModify()); + auto status = getWddm(allocation->getRootDeviceIndex()).mapGpuVirtualAddress(allocation->getDefaultGmm(), allocation->getDefaultHandle(), gfxPartition->getHeapMinimalAddress(heapIndex), gfxPartition->getHeapLimit(heapIndex), addressToMap, allocation->getGpuAddressToModify()); if (!status && deferredDeleter) { deferredDeleter->drain(true); - status = wddm->mapGpuVirtualAddress(allocation->getDefaultGmm(), allocation->getDefaultHandle(), - gfxPartition->getHeapMinimalAddress(heapIndex), gfxPartition->getHeapLimit(heapIndex), - addressToMap, allocation->getGpuAddressToModify()); + status = getWddm(allocation->getRootDeviceIndex()).mapGpuVirtualAddress(allocation->getDefaultGmm(), allocation->getDefaultHandle(), gfxPartition->getHeapMinimalAddress(heapIndex), gfxPartition->getHeapLimit(heapIndex), addressToMap, allocation->getGpuAddressToModify()); } if (!status) { if (allocation->reservedGpuVirtualAddress) { - wddm->freeGpuVirtualAddress(allocation->reservedGpuVirtualAddress, allocation->reservedSizeForGpuVirtualAddress); + getWddm(allocation->getRootDeviceIndex()).freeGpuVirtualAddress(allocation->reservedGpuVirtualAddress, allocation->reservedSizeForGpuVirtualAddress); } - wddm->destroyAllocations(allocation->getHandles().data(), allocation->getNumHandles(), allocation->resourceHandle); + getWddm(allocation->getRootDeviceIndex()).destroyAllocations(allocation->getHandles().data(), allocation->getNumHandles(), allocation->resourceHandle); return false; } return true; @@ -540,27 +534,31 @@ bool WddmMemoryManager::mapGpuVaForOneHandleAllocation(WddmAllocation *allocatio bool WddmMemoryManager::createGpuAllocationsWithRetry(WddmAllocation *allocation) { for (auto handleId = 0u; handleId < allocation->getNumHandles(); handleId++) { - auto status = wddm->createAllocation(allocation->getAlignedCpuPtr(), allocation->getGmm(handleId), allocation->getHandleToModify(handleId), allocation->shareable); + auto status = getWddm(allocation->getRootDeviceIndex()).createAllocation(allocation->getAlignedCpuPtr(), allocation->getGmm(handleId), allocation->getHandleToModify(handleId), allocation->shareable); if (status == STATUS_GRAPHICS_NO_VIDEO_MEMORY && deferredDeleter) { deferredDeleter->drain(true); - status = wddm->createAllocation(allocation->getAlignedCpuPtr(), allocation->getGmm(handleId), allocation->getHandleToModify(handleId), allocation->shareable); + status = getWddm(allocation->getRootDeviceIndex()).createAllocation(allocation->getAlignedCpuPtr(), allocation->getGmm(handleId), allocation->getHandleToModify(handleId), allocation->shareable); } if (status != STATUS_SUCCESS) { - wddm->destroyAllocations(allocation->getHandles().data(), handleId, allocation->resourceHandle); + getWddm(allocation->getRootDeviceIndex()).destroyAllocations(allocation->getHandles().data(), handleId, allocation->resourceHandle); return false; } } return true; } -void *WddmMemoryManager::reserveCpuAddressRange(size_t size) { +Wddm &WddmMemoryManager::getWddm(uint32_t rootDeviceIndex) const { + return *this->executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->osInterface->get()->getWddm(); +} + +void *WddmMemoryManager::reserveCpuAddressRange(size_t size, uint32_t rootDeviceIndex) { void *reservePtr = nullptr; - wddm->reserveValidAddressRange(size, reservePtr); + getWddm(rootDeviceIndex).reserveValidAddressRange(size, reservePtr); return reservePtr; } -void WddmMemoryManager::releaseReservedCpuAddressRange(void *reserved, size_t size) { - wddm->releaseReservedAddress(reserved); +void WddmMemoryManager::releaseReservedCpuAddressRange(void *reserved, size_t size, uint32_t rootDeviceIndex) { + getWddm(rootDeviceIndex).releaseReservedAddress(reserved); } } // namespace NEO diff --git a/runtime/os_interface/windows/wddm_memory_manager.h b/runtime/os_interface/windows/wddm_memory_manager.h index c97cf4394d..20ff2ab4df 100644 --- a/runtime/os_interface/windows/wddm_memory_manager.h +++ b/runtime/os_interface/windows/wddm_memory_manager.h @@ -42,23 +42,23 @@ class WddmMemoryManager : public MemoryManager { void addAllocationToHostPtrManager(GraphicsAllocation *memory) override; void removeAllocationFromHostPtrManager(GraphicsAllocation *memory) override; - AllocationStatus populateOsHandles(OsHandleStorage &handleStorage) override; + AllocationStatus populateOsHandles(OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override; void cleanOsHandles(OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override; void obtainGpuAddressFromFragments(WddmAllocation *allocation, OsHandleStorage &handleStorage); - uint64_t getSystemSharedMemory() override; - uint64_t getLocalMemorySize() override; + uint64_t getSystemSharedMemory(uint32_t rootDeviceIndex) override; + uint64_t getLocalMemorySize(uint32_t rootDeviceIndex) override; - bool tryDeferDeletions(const D3DKMT_HANDLE *handles, uint32_t allocationCount, D3DKMT_HANDLE resourceHandle); + bool tryDeferDeletions(const D3DKMT_HANDLE *handles, uint32_t allocationCount, D3DKMT_HANDLE resourceHandle, uint32_t rootDeviceIndex); bool isMemoryBudgetExhausted() const override; AlignedMallocRestrictions *getAlignedMallocRestrictions() override; bool copyMemoryToAllocation(GraphicsAllocation *graphicsAllocation, const void *memoryToCopy, size_t sizeToCopy) override; - void *reserveCpuAddressRange(size_t size) override; - void releaseReservedCpuAddressRange(void *reserved, size_t size) override; + void *reserveCpuAddressRange(size_t size, uint32_t rootDeviceIndex) override; + void releaseReservedCpuAddressRange(void *reserved, size_t size, uint32_t rootDeviceIndex) override; protected: GraphicsAllocation *createGraphicsAllocation(OsHandleStorage &handleStorage, const AllocationData &allocationData) override; @@ -83,7 +83,6 @@ class WddmMemoryManager : public MemoryManager { bool createGpuAllocationsWithRetry(WddmAllocation *graphicsAllocation); AlignedMallocRestrictions mallocRestrictions; - private: - Wddm *wddm; + Wddm &getWddm(uint32_t rootDeviceIndex) const; }; } // namespace NEO diff --git a/runtime/os_interface/windows/wddm_memory_manager_allocate_in_device_pool.cpp b/runtime/os_interface/windows/wddm_memory_manager_allocate_in_device_pool.cpp index 4f0de8465d..7b3d0e09a8 100644 --- a/runtime/os_interface/windows/wddm_memory_manager_allocate_in_device_pool.cpp +++ b/runtime/os_interface/windows/wddm_memory_manager_allocate_in_device_pool.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2019 Intel Corporation + * Copyright (C) 2018-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -19,7 +19,7 @@ bool WddmMemoryManager::copyMemoryToAllocation(GraphicsAllocation *graphicsAlloc bool WddmMemoryManager::mapGpuVirtualAddress(WddmAllocation *allocation, const void *requiredPtr) { return mapGpuVaForOneHandleAllocation(allocation, requiredPtr); } -uint64_t WddmMemoryManager::getLocalMemorySize() { +uint64_t WddmMemoryManager::getLocalMemorySize(uint32_t rootDeviceIndex) { return 0 * GB; } } // namespace NEO diff --git a/unit_tests/command_stream/command_stream_receiver_tests.cpp b/unit_tests/command_stream/command_stream_receiver_tests.cpp index 38d45041ad..9b52890f7d 100644 --- a/unit_tests/command_stream/command_stream_receiver_tests.cpp +++ b/unit_tests/command_stream/command_stream_receiver_tests.cpp @@ -461,7 +461,7 @@ TEST_F(CreateAllocationForHostSurfaceTest, givenReadOnlyHostPointerWhenAllocatio HostPtrSurface surface(const_cast(memory), size, true); if (!gmockMemoryManager->useNonSvmHostPtrAlloc(GraphicsAllocation::AllocationType::EXTERNAL_HOST_PTR)) { - EXPECT_CALL(*gmockMemoryManager, populateOsHandles(::testing::_)) + EXPECT_CALL(*gmockMemoryManager, populateOsHandles(::testing::_, device->getRootDeviceIndex())) .Times(1) .WillOnce(::testing::Return(MemoryManager::AllocationStatus::InvalidHostPointer)); } else { @@ -488,7 +488,7 @@ TEST_F(CreateAllocationForHostSurfaceTest, givenReadOnlyHostPointerWhenAllocatio HostPtrSurface surface(const_cast(memory), size, false); if (!gmockMemoryManager->useNonSvmHostPtrAlloc(GraphicsAllocation::AllocationType::EXTERNAL_HOST_PTR)) { - EXPECT_CALL(*gmockMemoryManager, populateOsHandles(::testing::_)) + EXPECT_CALL(*gmockMemoryManager, populateOsHandles(::testing::_, device->getRootDeviceIndex())) .Times(1) .WillOnce(::testing::Return(MemoryManager::AllocationStatus::InvalidHostPointer)); } else { @@ -788,4 +788,4 @@ TEST_F(CommandStreamReceiverPageTableManagerTest, givenDefaultEngineTypeAndNonEx EXPECT_EQ(nullptr, executionEnvironment.rootDeviceEnvironments[0]->pageTableManager.get()); EXPECT_EQ(supportsPageTableManager, commandStreamReceiver.needsPageTableManager(defaultEngineType)); -} \ No newline at end of file +} diff --git a/unit_tests/command_stream/tbx_command_stream_tests.cpp b/unit_tests/command_stream/tbx_command_stream_tests.cpp index 68f3ae9122..91cadbd2db 100644 --- a/unit_tests/command_stream/tbx_command_stream_tests.cpp +++ b/unit_tests/command_stream/tbx_command_stream_tests.cpp @@ -91,7 +91,7 @@ HWTEST_F(TbxCommandStreamTests, DISABLED_testTbxMemoryManager) { TbxCommandStreamReceiverHw *tbxCsr = (TbxCommandStreamReceiverHw *)pCommandStreamReceiver; TbxMemoryManager *getMM = tbxCsr->getMemoryManager(); EXPECT_NE(nullptr, getMM); - EXPECT_EQ(1 * GB, getMM->getSystemSharedMemory()); + EXPECT_EQ(1 * GB, getMM->getSystemSharedMemory(0u)); } TEST_F(TbxCommandStreamTests, DISABLED_makeResident) { @@ -369,7 +369,7 @@ HWTEST_F(TbxCommandStreamTests, givenTbxCommandStreamReceiverWhenFlushIsCalledTh TEST(TbxMemoryManagerTest, givenTbxMemoryManagerWhenItIsQueriedForSystemSharedMemoryThen1GBIsReturned) { MockExecutionEnvironment executionEnvironment(*platformDevices); TbxMemoryManager memoryManager(executionEnvironment); - EXPECT_EQ(1 * GB, memoryManager.getSystemSharedMemory()); + EXPECT_EQ(1 * GB, memoryManager.getSystemSharedMemory(0u)); } HWTEST_F(TbxCommandStreamTests, givenNoDbgDeviceIdFlagWhenTbxCsrIsCreatedThenUseDefaultDeviceId) { diff --git a/unit_tests/device/device_caps_tests.cpp b/unit_tests/device/device_caps_tests.cpp index e1bb7c5417..ee80e670be 100644 --- a/unit_tests/device/device_caps_tests.cpp +++ b/unit_tests/device/device_caps_tests.cpp @@ -303,7 +303,7 @@ TEST_F(DeviceGetCapsTest, checkGlobalMemSize) { unsigned int enabledCLVer = device->getEnabledClVersion(); bool addressing32Bit = is32bit || (is64bit && (enabledCLVer < 20)) || DebugManager.flags.Force32bitAddressing.get(); - cl_ulong sharedMem = (cl_ulong)pMemManager->getSystemSharedMemory(); + cl_ulong sharedMem = (cl_ulong)pMemManager->getSystemSharedMemory(0u); cl_ulong maxAppAddrSpace = (cl_ulong)pMemManager->getMaxApplicationAddress() + 1ULL; cl_ulong memSize = std::min(sharedMem, maxAppAddrSpace); memSize = (cl_ulong)((double)memSize * 0.8); @@ -325,7 +325,7 @@ TEST_F(DeviceGetCapsTest, givenDeviceCapsWhenLocalMemoryIsEnabledThenCalculateGl auto enabledCLVer = device->getEnabledClVersion(); bool addressing32Bit = is32bit || (is64bit && (enabledCLVer < 20)) || DebugManager.flags.Force32bitAddressing.get(); - auto localMem = pMemManager->getLocalMemorySize(); + auto localMem = pMemManager->getLocalMemorySize(0u); auto maxAppAddrSpace = pMemManager->getMaxApplicationAddress() + 1; auto memSize = std::min(localMem, maxAppAddrSpace); memSize = static_cast(memSize * 0.8); diff --git a/unit_tests/execution_environment/execution_environment_tests.cpp b/unit_tests/execution_environment/execution_environment_tests.cpp index 68aff4baf3..3cd2b52ac7 100644 --- a/unit_tests/execution_environment/execution_environment_tests.cpp +++ b/unit_tests/execution_environment/execution_environment_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2019 Intel Corporation + * Copyright (C) 2018-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -149,7 +149,7 @@ TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenInitializeMemoryManagerI static_assert(sizeof(ExecutionEnvironment) == sizeof(std::mutex) + sizeof(std::unique_ptr) + sizeof(std::vector) + - (is64bit ? 72 : 40), + (is64bit ? 64 : 36), "New members detected in ExecutionEnvironment, please ensure that destruction sequence of objects is correct"); TEST(ExecutionEnvironment, givenExecutionEnvironmentWithVariousMembersWhenItIsDestroyedThenDeleteSequenceIsSpecified) { @@ -161,12 +161,12 @@ TEST(ExecutionEnvironment, givenExecutionEnvironmentWithVariousMembersWhenItIsDe struct GmmHelperMock : public DestructorCounted { GmmHelperMock(uint32_t &destructorId, const HardwareInfo *hwInfo) : DestructorCounted(destructorId, nullptr, hwInfo) {} }; - struct OsInterfaceMock : public DestructorCounted { - OsInterfaceMock(uint32_t &destructorId) : DestructorCounted(destructorId) {} - }; - struct MemoryMangerMock : public DestructorCounted { + struct MemoryMangerMock : public DestructorCounted { MemoryMangerMock(uint32_t &destructorId, ExecutionEnvironment &executionEnvironment) : DestructorCounted(destructorId, executionEnvironment) {} }; + struct OsInterfaceMock : public DestructorCounted { + OsInterfaceMock(uint32_t &destructorId) : DestructorCounted(destructorId) {} + }; struct MemoryOperationsHandlerMock : public DestructorCounted { MemoryOperationsHandlerMock(uint32_t &destructorId) : DestructorCounted(destructorId) {} }; @@ -187,7 +187,7 @@ TEST(ExecutionEnvironment, givenExecutionEnvironmentWithVariousMembersWhenItIsDe executionEnvironment->setHwInfo(*platformDevices); executionEnvironment->prepareRootDeviceEnvironments(1); executionEnvironment->gmmHelper = std::make_unique(destructorId, platformDevices[0]); - executionEnvironment->osInterface = std::make_unique(destructorId); + executionEnvironment->rootDeviceEnvironments[0]->osInterface = std::make_unique(destructorId); executionEnvironment->rootDeviceEnvironments[0]->memoryOperationsInterface = std::make_unique(destructorId); executionEnvironment->memoryManager = std::make_unique(destructorId, *executionEnvironment); executionEnvironment->rootDeviceEnvironments[0]->aubCenter = std::make_unique(destructorId); diff --git a/unit_tests/fixtures/image_fixture.h b/unit_tests/fixtures/image_fixture.h index 1b93966bf0..9d5150e168 100644 --- a/unit_tests/fixtures/image_fixture.h +++ b/unit_tests/fixtures/image_fixture.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2019 Intel Corporation + * Copyright (C) 2017-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -118,6 +118,7 @@ struct ImageClearColorFixture : ::testing::Test { NEO::platformImpl.reset(); NEO::constructPlatform()->peekExecutionEnvironment()->setHwInfo(&hardwareInfo); + NEO::platform()->peekExecutionEnvironment()->prepareRootDeviceEnvironments(1u); NEO::platform()->peekExecutionEnvironment()->initGmm(); } diff --git a/unit_tests/gmm_helper/gmm_helper_tests.cpp b/unit_tests/gmm_helper/gmm_helper_tests.cpp index 6e274a617c..3496217d4f 100644 --- a/unit_tests/gmm_helper/gmm_helper_tests.cpp +++ b/unit_tests/gmm_helper/gmm_helper_tests.cpp @@ -801,7 +801,7 @@ TEST(GmmHelperTest, givenValidGmmFunctionsWhenCreateGmmHelperWithInitializedOsIn SkuInfoTransfer::transferFtrTableForGmm(&expectedFtrTable, &hwInfo->featureTable); SkuInfoTransfer::transferWaTableForGmm(&expectedWaTable, &hwInfo->workaroundTable); - gmmHelper.reset(new GmmHelper(executionEnvironment->osInterface.get(), hwInfo)); + gmmHelper.reset(new GmmHelper(executionEnvironment->rootDeviceEnvironments[0]->osInterface.get(), hwInfo)); EXPECT_EQ(0, memcmp(&hwInfo->platform, &passedInputArgs.Platform, sizeof(PLATFORM))); EXPECT_EQ(&hwInfo->gtSystemInfo, passedInputArgs.pGtSysInfo); EXPECT_EQ(0, memcmp(&expectedFtrTable, &passedFtrTable, sizeof(SKU_FEATURE_TABLE))); diff --git a/unit_tests/linux/main_linux_dll.cpp b/unit_tests/linux/main_linux_dll.cpp index 812e56cbdc..33e541d922 100644 --- a/unit_tests/linux/main_linux_dll.cpp +++ b/unit_tests/linux/main_linux_dll.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2019 Intel Corporation + * Copyright (C) 2017-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -360,8 +360,8 @@ TEST(DrmMemoryManagerCreate, whenCallCreateMemoryManagerThenDrmMemoryManagerIsCr DrmMockSuccess mock; MockExecutionEnvironment executionEnvironment(*platformDevices); - executionEnvironment.osInterface = std::make_unique(); - executionEnvironment.osInterface->get()->setDrm(&mock); + executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique(); + executionEnvironment.rootDeviceEnvironments[0]->osInterface->get()->setDrm(&mock); auto drmMemoryManager = MemoryManager::createMemoryManager(executionEnvironment); EXPECT_NE(nullptr, drmMemoryManager.get()); executionEnvironment.memoryManager = std::move(drmMemoryManager); diff --git a/unit_tests/memory_manager/memory_manager_allocate_in_device_pool_tests.cpp b/unit_tests/memory_manager/memory_manager_allocate_in_device_pool_tests.cpp index 7f4d9fae47..c9bbdb8996 100644 --- a/unit_tests/memory_manager/memory_manager_allocate_in_device_pool_tests.cpp +++ b/unit_tests/memory_manager/memory_manager_allocate_in_device_pool_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2019 Intel Corporation + * Copyright (C) 2018-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -89,5 +89,5 @@ TEST(MemoryManagerTest, givenOsAgnosticMemoryManagerWhenGetLocalMemoryIsCalledTh MockExecutionEnvironment executionEnvironment(*platformDevices); MockMemoryManager memoryManager(false, false, executionEnvironment); - EXPECT_EQ(0 * GB, memoryManager.getLocalMemorySize()); + EXPECT_EQ(0 * GB, memoryManager.getLocalMemorySize(0u)); } diff --git a/unit_tests/memory_manager/memory_manager_tests.cpp b/unit_tests/memory_manager/memory_manager_tests.cpp index 1457cdaded..07bf6e8d07 100644 --- a/unit_tests/memory_manager/memory_manager_tests.cpp +++ b/unit_tests/memory_manager/memory_manager_tests.cpp @@ -287,7 +287,7 @@ TEST_F(MemoryAllocatorTest, GivenHostPtrAlignedToCacheLineWhenAskedForL3Allowanc TEST_F(MemoryAllocatorTest, NullOsHandleStorageAskedForPopulationReturnsFilledPointer) { OsHandleStorage storage; storage.fragmentStorageData[0].cpuPtr = (void *)0x1000; - memoryManager->populateOsHandles(storage); + memoryManager->populateOsHandles(storage, 0); EXPECT_NE(nullptr, storage.fragmentStorageData[0].osHandleStorage); EXPECT_EQ(nullptr, storage.fragmentStorageData[1].osHandleStorage); EXPECT_EQ(nullptr, storage.fragmentStorageData[2].osHandleStorage); @@ -304,7 +304,7 @@ TEST_F(MemoryAllocatorTest, givenOsHandleStorageWhenOsHandlesAreCleanedAndAubMan OsHandleStorage storage; storage.fragmentStorageData[0].cpuPtr = (void *)0x1000; - mockMemoryManager.populateOsHandles(storage); + mockMemoryManager.populateOsHandles(storage, 0); mockMemoryManager.getHostPtrManager()->releaseHandleStorage(storage); mockMemoryManager.cleanOsHandles(storage, 0); @@ -329,7 +329,7 @@ TEST_F(MemoryAllocatorTest, givenOsHandleStorageAndFreeMemoryEnabledWhenOsHandle OsHandleStorage storage; storage.fragmentStorageData[0].cpuPtr = reinterpret_cast(0x1000); - mockMemoryManager.populateOsHandles(storage); + mockMemoryManager.populateOsHandles(storage, 0); mockMemoryManager.getHostPtrManager()->releaseHandleStorage(storage); mockMemoryManager.cleanOsHandles(storage, rootDeviceIndex); @@ -2082,7 +2082,7 @@ TEST_F(MemoryAllocatorTest, whenReservingAddressRangeThenExpectProperAddressAndR size_t size = 0x1000; auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{size}); ASSERT_NE(nullptr, allocation); - void *reserve = memoryManager->reserveCpuAddressRange(size); + void *reserve = memoryManager->reserveCpuAddressRange(size, 0); EXPECT_NE(nullptr, reserve); allocation->setReservedAddressRange(reserve, size); EXPECT_EQ(reserve, allocation->getReservedAddressPtr()); diff --git a/unit_tests/mocks/linux/mock_drm_memory_manager.h b/unit_tests/mocks/linux/mock_drm_memory_manager.h index a9a2f159d0..b445ce6d42 100644 --- a/unit_tests/mocks/linux/mock_drm_memory_manager.h +++ b/unit_tests/mocks/linux/mock_drm_memory_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2019 Intel Corporation + * Copyright (C) 2018-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -38,8 +38,8 @@ class TestedDrmMemoryManager : public MemoryManagerCreate { using DrmMemoryManager::AllocationData; using DrmMemoryManager::allocUserptr; using DrmMemoryManager::createGraphicsAllocation; - using DrmMemoryManager::drm; using DrmMemoryManager::getDefaultDrmContextId; + using DrmMemoryManager::getDrm; using DrmMemoryManager::gfxPartitions; using DrmMemoryManager::lockResourceInLocalMemoryImpl; using DrmMemoryManager::pinThreshold; diff --git a/unit_tests/mocks/mock_memory_manager.h b/unit_tests/mocks/mock_memory_manager.h index 5d52326bcf..c96f51d218 100644 --- a/unit_tests/mocks/mock_memory_manager.h +++ b/unit_tests/mocks/mock_memory_manager.h @@ -96,11 +96,11 @@ class MockMemoryManager : public MemoryManagerCreate { OsAgnosticMemoryManager::handleFenceCompletion(graphicsAllocation); } - void *reserveCpuAddressRange(size_t size) override { + void *reserveCpuAddressRange(size_t size, uint32_t rootDeviceIndex) override { if (failReserveAddress) { return nullptr; } - return OsAgnosticMemoryManager::reserveCpuAddressRange(size); + return OsAgnosticMemoryManager::reserveCpuAddressRange(size, rootDeviceIndex); } GraphicsAllocation *allocate32BitGraphicsMemory(size_t size, const void *ptr, GraphicsAllocation::AllocationType allocationType); @@ -132,10 +132,10 @@ using AllocationData = MockMemoryManager::AllocationData; class GMockMemoryManager : public MockMemoryManager { public: GMockMemoryManager(const ExecutionEnvironment &executionEnvironment) : MockMemoryManager(const_cast(executionEnvironment)){}; - MOCK_METHOD1(populateOsHandles, MemoryManager::AllocationStatus(OsHandleStorage &handleStorage)); + MOCK_METHOD2(populateOsHandles, MemoryManager::AllocationStatus(OsHandleStorage &handleStorage, uint32_t rootDeviceIndex)); MOCK_METHOD1(allocateGraphicsMemoryForNonSvmHostPtr, GraphicsAllocation *(const AllocationData &)); - MemoryManager::AllocationStatus MemoryManagerPopulateOsHandles(OsHandleStorage &handleStorage) { return OsAgnosticMemoryManager::populateOsHandles(handleStorage); } + MemoryManager::AllocationStatus MemoryManagerPopulateOsHandles(OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) { return OsAgnosticMemoryManager::populateOsHandles(handleStorage, rootDeviceIndex); } }; class MockAllocSysMemAgnosticMemoryManager : public OsAgnosticMemoryManager { @@ -195,12 +195,12 @@ class FailMemoryManager : public MockMemoryManager { void *lockResourceImpl(GraphicsAllocation &gfxAllocation) override { return nullptr; }; void unlockResourceImpl(GraphicsAllocation &gfxAllocation) override{}; - MemoryManager::AllocationStatus populateOsHandles(OsHandleStorage &handleStorage) override { + MemoryManager::AllocationStatus populateOsHandles(OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override { return AllocationStatus::Error; }; void cleanOsHandles(OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override{}; - uint64_t getSystemSharedMemory() override { + uint64_t getSystemSharedMemory(uint32_t rootDeviceIndex) override { return 0; }; diff --git a/unit_tests/mocks/mock_wddm.h b/unit_tests/mocks/mock_wddm.h index 8c941f388d..cdd0a38804 100644 --- a/unit_tests/mocks/mock_wddm.h +++ b/unit_tests/mocks/mock_wddm.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2019 Intel Corporation + * Copyright (C) 2018-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -36,6 +36,7 @@ class WddmMock : public Wddm { using Wddm::getSystemInfo; using Wddm::gmmMemory; using Wddm::mapGpuVirtualAddress; + using Wddm::minAddress; using Wddm::pagingFenceAddress; using Wddm::pagingQueue; using Wddm::temporaryResources; diff --git a/unit_tests/mt_tests/os_interface/linux/drm_memory_manager_mt_tests.cpp b/unit_tests/mt_tests/os_interface/linux/drm_memory_manager_mt_tests.cpp index 4ed6398934..c346801355 100644 --- a/unit_tests/mt_tests/os_interface/linux/drm_memory_manager_mt_tests.cpp +++ b/unit_tests/mt_tests/os_interface/linux/drm_memory_manager_mt_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2019 Intel Corporation + * Copyright (C) 2018-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -35,9 +35,9 @@ TEST(DrmMemoryManagerTest, givenDrmMemoryManagerWhenSharedAllocationIsCreatedFro } }; MockExecutionEnvironment executionEnvironment(*platformDevices); - executionEnvironment.osInterface = std::make_unique(); + executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique(); auto mock = make_unique(0); - executionEnvironment.osInterface->get()->setDrm(mock.get()); + executionEnvironment.rootDeviceEnvironments[0]->osInterface->get()->setDrm(mock.get()); auto memoryManager = make_unique(executionEnvironment); osHandle handle = 3; @@ -100,9 +100,9 @@ TEST(DrmMemoryManagerTest, givenMultipleThreadsWhenSharedAllocationIsCreatedThen }; MockExecutionEnvironment executionEnvironment(*platformDevices); - executionEnvironment.osInterface = std::make_unique(); + executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique(); auto mock = make_unique(0); - executionEnvironment.osInterface->get()->setDrm(mock.get()); + executionEnvironment.rootDeviceEnvironments[0]->osInterface->get()->setDrm(mock.get()); auto memoryManager = make_unique(executionEnvironment); osHandle handle = 3; diff --git a/unit_tests/os_interface/device_factory_tests.cpp b/unit_tests/os_interface/device_factory_tests.cpp index 7c3cb7ce5b..1f037efc8a 100644 --- a/unit_tests/os_interface/device_factory_tests.cpp +++ b/unit_tests/os_interface/device_factory_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2019 Intel Corporation + * Copyright (C) 2017-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -227,6 +227,7 @@ TEST_F(DeviceFactoryTest, whenGetDevicesIsCalledThenAllRootDeviceEnvironmentMemb EXPECT_EQ(requiredDeviceCount, numDevices); std::set memoryOperationHandlers; + std::set osInterfaces; for (auto rootDeviceIndex = 0u; rootDeviceIndex < requiredDeviceCount; rootDeviceIndex++) { auto rootDeviceEnvironment = static_cast(executionEnvironment.rootDeviceEnvironments[rootDeviceIndex].get()); @@ -234,6 +235,11 @@ TEST_F(DeviceFactoryTest, whenGetDevicesIsCalledThenAllRootDeviceEnvironmentMemb EXPECT_NE(nullptr, memoryOperationInterface); EXPECT_EQ(memoryOperationHandlers.end(), memoryOperationHandlers.find(memoryOperationInterface)); memoryOperationHandlers.insert(memoryOperationInterface); + + auto osInterface = rootDeviceEnvironment->osInterface.get(); + EXPECT_NE(nullptr, osInterface); + EXPECT_EQ(osInterfaces.end(), osInterfaces.find(osInterface)); + osInterfaces.insert(osInterface); } } @@ -255,5 +261,5 @@ TEST_F(DeviceFactoryTest, givenGetDevicesCallWhenItIsDoneThenOsInterfaceIsAlloca size_t numDevices = 0; bool success = DeviceFactory::getDevices(numDevices, *executionEnvironment); EXPECT_TRUE(success); - EXPECT_NE(nullptr, executionEnvironment->osInterface); + EXPECT_NE(nullptr, executionEnvironment->rootDeviceEnvironments[0]->osInterface); } 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 1127785287..8e1cd24f6c 100644 --- a/unit_tests/os_interface/linux/device_command_stream_tests.cpp +++ b/unit_tests/os_interface/linux/device_command_stream_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2019 Intel Corporation + * Copyright (C) 2018-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -57,6 +57,6 @@ HWTEST_F(DeviceCommandStreamLeaksTest, givenDefaultDrmCsrWithAubDumWhenItIsCreat HWTEST_F(DeviceCommandStreamLeaksTest, givenDefaultDrmCsrWhenOsInterfaceIsNullptrThenValidateDrm) { std::unique_ptr ptr(DeviceCommandStreamReceiver::create(false, *executionEnvironment, 0)); auto drmCsr = (DrmCommandStreamReceiver *)ptr.get(); - EXPECT_NE(nullptr, executionEnvironment->osInterface); - EXPECT_EQ(drmCsr->getOSInterface()->get()->getDrm(), executionEnvironment->osInterface->get()->getDrm()); + EXPECT_NE(nullptr, executionEnvironment->rootDeviceEnvironments[0]->osInterface); + EXPECT_EQ(drmCsr->getOSInterface()->get()->getDrm(), executionEnvironment->rootDeviceEnvironments[0]->osInterface->get()->getDrm()); } diff --git a/unit_tests/os_interface/linux/device_factory_tests.cpp b/unit_tests/os_interface/linux/device_factory_tests.cpp index 12fc38420f..01518aa39e 100644 --- a/unit_tests/os_interface/linux/device_factory_tests.cpp +++ b/unit_tests/os_interface/linux/device_factory_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2019 Intel Corporation + * Copyright (C) 2017-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -7,6 +7,7 @@ #include "unit_tests/os_interface/linux/device_factory_tests.h" +#include "core/execution_environment/root_device_environment.h" #include "runtime/os_interface/linux/os_interface.h" #include "runtime/os_interface/os_interface.h" @@ -79,6 +80,6 @@ TEST_F(DeviceFactoryLinuxTest, givenGetDeviceCallWhenItIsDoneThenOsInterfaceIsAl size_t numDevices = 0; bool success = mockDeviceFactory.getDevices(numDevices, executionEnvironment); EXPECT_TRUE(success); - EXPECT_NE(nullptr, executionEnvironment.osInterface); - EXPECT_EQ(pDrm, executionEnvironment.osInterface->get()->getDrm()); + EXPECT_NE(nullptr, executionEnvironment.rootDeviceEnvironments[0]->osInterface); + EXPECT_EQ(pDrm, executionEnvironment.rootDeviceEnvironments[0]->osInterface->get()->getDrm()); } 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 aa2b709d0a..0bf746969c 100644 --- a/unit_tests/os_interface/linux/drm_command_stream_fixture.h +++ b/unit_tests/os_interface/linux/drm_command_stream_fixture.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2019 Intel Corporation + * Copyright (C) 2017-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -32,8 +32,8 @@ class DrmCommandStreamTest : public ::testing::Test { executionEnvironment.setHwInfo(*platformDevices); executionEnvironment.prepareRootDeviceEnvironments(1); - executionEnvironment.osInterface = std::make_unique(); - executionEnvironment.osInterface->get()->setDrm(mock.get()); + executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique(); + executionEnvironment.rootDeviceEnvironments[0]->osInterface->get()->setDrm(mock.get()); osContext = std::make_unique(*mock, 0u, 1, HwHelper::get(platformDevices[0]->platform.eRenderCoreFamily).getGpgpuEngineInstances()[0], PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]), false); @@ -99,8 +99,8 @@ class DrmCommandStreamEnhancedTest : public ::testing::Test { DebugManager.flags.EnableForcePin.set(false); mock = std::make_unique(); - executionEnvironment->osInterface = std::make_unique(); - executionEnvironment->osInterface->get()->setDrm(mock.get()); + executionEnvironment->rootDeviceEnvironments[0]->osInterface = std::make_unique(); + executionEnvironment->rootDeviceEnvironments[0]->osInterface->get()->setDrm(mock.get()); csr = new TestedDrmCommandStreamReceiver(*executionEnvironment); ASSERT_NE(nullptr, csr); diff --git a/unit_tests/os_interface/linux/drm_command_stream_mm_tests.cpp b/unit_tests/os_interface/linux/drm_command_stream_mm_tests.cpp index 95077e7fa7..2739a15164 100644 --- a/unit_tests/os_interface/linux/drm_command_stream_mm_tests.cpp +++ b/unit_tests/os_interface/linux/drm_command_stream_mm_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2019 Intel Corporation + * Copyright (C) 2017-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -13,6 +13,7 @@ #include "runtime/os_interface/linux/os_interface.h" #include "runtime/platform/platform.h" #include "test.h" +#include "unit_tests/mocks/mock_execution_environment.h" #include "unit_tests/os_interface/linux/device_command_stream_fixture.h" using namespace NEO; @@ -25,11 +26,11 @@ HWTEST_F(DrmCommandStreamMMTest, MMwithPinBB) { DebugManager.flags.EnableForcePin.set(true); DrmMockCustom mock; - ExecutionEnvironment executionEnvironment; + MockExecutionEnvironment executionEnvironment; executionEnvironment.setHwInfo(*platformDevices); - executionEnvironment.osInterface = std::make_unique(); - executionEnvironment.osInterface->get()->setDrm(&mock); + executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique(); + executionEnvironment.rootDeviceEnvironments[0]->osInterface->get()->setDrm(&mock); executionEnvironment.prepareRootDeviceEnvironments(1u); executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = std::make_unique(); @@ -49,11 +50,11 @@ HWTEST_F(DrmCommandStreamMMTest, givenForcePinDisabledWhenMemoryManagerIsCreated DebugManager.flags.EnableForcePin.set(false); DrmMockCustom mock; - ExecutionEnvironment executionEnvironment; + MockExecutionEnvironment executionEnvironment; executionEnvironment.setHwInfo(*platformDevices); - executionEnvironment.osInterface = std::make_unique(); - executionEnvironment.osInterface->get()->setDrm(&mock); + executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique(); + executionEnvironment.rootDeviceEnvironments[0]->osInterface->get()->setDrm(&mock); DrmCommandStreamReceiver csr(executionEnvironment, 0, gemCloseWorkerMode::gemCloseWorkerInactive); diff --git a/unit_tests/os_interface/linux/drm_command_stream_tests.cpp b/unit_tests/os_interface/linux/drm_command_stream_tests.cpp index 59b1720456..3dc3c62989 100644 --- a/unit_tests/os_interface/linux/drm_command_stream_tests.cpp +++ b/unit_tests/os_interface/linux/drm_command_stream_tests.cpp @@ -627,8 +627,8 @@ HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, givenCommandStreamWithDuplicate } HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, givenDrmCsrCreatedWithInactiveGemCloseWorkerPolicyThenThreadIsNotCreated) { - this->executionEnvironment->osInterface = std::make_unique(); - this->executionEnvironment->osInterface->get()->setDrm(mock.get()); + this->executionEnvironment->rootDeviceEnvironments[0]->osInterface = std::make_unique(); + this->executionEnvironment->rootDeviceEnvironments[0]->osInterface->get()->setDrm(mock.get()); TestedDrmCommandStreamReceiver testedCsr(gemCloseWorkerMode::gemCloseWorkerInactive, *this->executionEnvironment); EXPECT_EQ(gemCloseWorkerMode::gemCloseWorkerInactive, testedCsr.peekGemCloseWorkerOperationMode()); @@ -1385,6 +1385,8 @@ struct MockDrmCsr : public DrmCommandStreamReceiver { HWTEST_TEMPLATED_F(DrmCommandStreamTest, givenDrmCommandStreamReceiverWhenCreatePageTableMngrIsCalledThenCreatePageTableManager) { executionEnvironment.prepareRootDeviceEnvironments(2); + executionEnvironment.rootDeviceEnvironments[1]->osInterface = std::make_unique(); + executionEnvironment.rootDeviceEnvironments[1]->osInterface->get()->setDrm(mock.get()); auto csr = std::make_unique>(executionEnvironment, 1, gemCloseWorkerMode::gemCloseWorkerActive); auto pageTableManager = csr->createPageTableManager(); EXPECT_EQ(executionEnvironment.rootDeviceEnvironments[1]->pageTableManager.get(), pageTableManager); diff --git a/unit_tests/os_interface/linux/drm_gem_close_worker_tests.cpp b/unit_tests/os_interface/linux/drm_gem_close_worker_tests.cpp index 488c193017..68736cb5bb 100644 --- a/unit_tests/os_interface/linux/drm_gem_close_worker_tests.cpp +++ b/unit_tests/os_interface/linux/drm_gem_close_worker_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2019 Intel Corporation + * Copyright (C) 2017-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -69,8 +69,8 @@ class DrmGemCloseWorkerFixture { this->drmMock->gem_close_cnt = 0; this->drmMock->gem_close_expected = 0; - executionEnvironment.osInterface = std::make_unique(); - executionEnvironment.osInterface->get()->setDrm(drmMock); + executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique(); + executionEnvironment.rootDeviceEnvironments[0]->osInterface->get()->setDrm(drmMock); executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = std::make_unique(); this->mm = new DrmMemoryManager(gemCloseWorkerMode::gemCloseWorkerInactive, diff --git a/unit_tests/os_interface/linux/drm_memory_manager_allocate_in_device_pool_tests.cpp b/unit_tests/os_interface/linux/drm_memory_manager_allocate_in_device_pool_tests.cpp index da9039c4f2..2c874124ab 100644 --- a/unit_tests/os_interface/linux/drm_memory_manager_allocate_in_device_pool_tests.cpp +++ b/unit_tests/os_interface/linux/drm_memory_manager_allocate_in_device_pool_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 Intel Corporation + * Copyright (C) 2019-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -21,8 +21,8 @@ using AllocationData = TestedDrmMemoryManager::AllocationData; TEST(DrmMemoryManagerSimpleTest, givenDrmMemoryManagerWhenAllocateInDevicePoolIsCalledThenNullptrAndStatusRetryIsReturned) { MockExecutionEnvironment executionEnvironment(*platformDevices); - executionEnvironment.osInterface = std::make_unique(); - executionEnvironment.osInterface->get()->setDrm(Drm::get(0)); + executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique(); + executionEnvironment.rootDeviceEnvironments[0]->osInterface->get()->setDrm(Drm::get(0)); TestedDrmMemoryManager memoryManager(executionEnvironment); MemoryManager::AllocationStatus status = MemoryManager::AllocationStatus::Success; AllocationData allocData; @@ -37,7 +37,7 @@ TEST(DrmMemoryManagerSimpleTest, givenDrmMemoryManagerWhenAllocateInDevicePoolIs TEST(DrmMemoryManagerSimpleTest, givenDrmMemoryManagerWhenLockResourceIsCalledOnNullBufferObjectThenReturnNullPtr) { MockExecutionEnvironment executionEnvironment(*platformDevices); - executionEnvironment.osInterface = std::make_unique(); + executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique(); TestedDrmMemoryManager memoryManager(executionEnvironment); DrmAllocation drmAllocation(0, GraphicsAllocation::AllocationType::UNKNOWN, nullptr, nullptr, 0u, 0u, MemoryPool::LocalMemory); @@ -49,7 +49,7 @@ TEST(DrmMemoryManagerSimpleTest, givenDrmMemoryManagerWhenLockResourceIsCalledOn TEST(DrmMemoryManagerSimpleTest, givenDrmMemoryManagerWhenFreeGraphicsMemoryIsCalledOnAllocationWithNullBufferObjectThenEarlyReturn) { MockExecutionEnvironment executionEnvironment(*platformDevices); - executionEnvironment.osInterface = std::make_unique(); + executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique(); TestedDrmMemoryManager memoryManager(executionEnvironment); auto drmAllocation = new DrmAllocation(0, GraphicsAllocation::AllocationType::UNKNOWN, nullptr, nullptr, 0u, 0u, MemoryPool::LocalMemory); @@ -90,5 +90,5 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenCopyMemoryToAllocationThen } TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenGetLocalMemoryIsCalledThenSizeOfLocalMemoryIsReturned) { - EXPECT_EQ(0 * GB, memoryManager->getLocalMemorySize()); + EXPECT_EQ(0 * GB, memoryManager->getLocalMemorySize(0u)); } 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 b7bf671b95..dfa6629664 100644 --- a/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp +++ b/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp @@ -44,7 +44,8 @@ #include #include -using namespace NEO; +namespace NEO { +extern bool overrideDeviceWithDefaultHardwareInfo; AllocationProperties createAllocationProperties(size_t size, bool forcePin) { MockAllocationProperties properties(size); @@ -506,11 +507,20 @@ TEST_F(DrmMemoryManagerTest, givenDrmAllocationWhenHandleFenceCompletionThenCall } TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhengetSystemSharedMemoryIsCalledThenContextGetParamIsCalled) { - mock->getContextParamRetValue = 16 * MemoryConstants::gigaByte; - uint64_t mem = memoryManager->getSystemSharedMemory(); - mock->ioctl_expected.contextGetParam = 1; - EXPECT_EQ(mock->recordedGetContextParam.param, static_cast<__u64>(I915_CONTEXT_PARAM_GTT_SIZE)); - EXPECT_GT(mem, 0u); + executionEnvironment->prepareRootDeviceEnvironments(4u); + for (auto i = 0u; i < 4u; i++) { + auto mock = std::make_unique(); + executionEnvironment->rootDeviceEnvironments[i]->osInterface = std::make_unique(); + executionEnvironment->rootDeviceEnvironments[i]->osInterface->get()->setDrm(mock.get()); + + mock->getContextParamRetValue = 16 * MemoryConstants::gigaByte; + uint64_t mem = memoryManager->getSystemSharedMemory(i); + mock->ioctl_expected.contextGetParam = 1; + EXPECT_EQ(mock->recordedGetContextParam.param, static_cast<__u64>(I915_CONTEXT_PARAM_GTT_SIZE)); + EXPECT_GT(mem, 0u); + + executionEnvironment->rootDeviceEnvironments[i]->osInterface.reset(); + } } TEST_F(DrmMemoryManagerTest, getMaxApplicationAddress) { @@ -523,26 +533,36 @@ TEST_F(DrmMemoryManagerTest, getMaxApplicationAddress) { } TEST_F(DrmMemoryManagerTest, getMinimumSystemSharedMemory) { - auto hostMemorySize = MemoryConstants::pageSize * (uint64_t)(sysconf(_SC_PHYS_PAGES)); - // gpuMemSize < hostMemSize - auto gpuMemorySize = hostMemorySize - 1u; - mock->getContextParamRetValue = gpuMemorySize; + executionEnvironment->prepareRootDeviceEnvironments(4u); + for (auto i = 0u; i < 4u; i++) { + auto mock = std::make_unique(); + executionEnvironment->rootDeviceEnvironments[i]->osInterface = std::make_unique(); + executionEnvironment->rootDeviceEnvironments[i]->osInterface->get()->setDrm(mock.get()); - uint64_t systemSharedMemorySize = memoryManager->getSystemSharedMemory(); - mock->ioctl_expected.contextGetParam = 1; + auto hostMemorySize = MemoryConstants::pageSize * (uint64_t)(sysconf(_SC_PHYS_PAGES)); + // gpuMemSize < hostMemSize + auto gpuMemorySize = hostMemorySize - 1u; + mock->getContextParamRetValue = gpuMemorySize; - EXPECT_EQ(gpuMemorySize, systemSharedMemorySize); - mock->ioctl_expected.contextDestroy = 0; - mock->testIoctls(); + uint64_t systemSharedMemorySize = memoryManager->getSystemSharedMemory(i); + mock->ioctl_expected.contextGetParam = 1; - // gpuMemSize > hostMemSize - gpuMemorySize = hostMemorySize + 1u; - mock->getContextParamRetValue = gpuMemorySize; - systemSharedMemorySize = memoryManager->getSystemSharedMemory(); - mock->ioctl_expected.contextGetParam = 2; - EXPECT_EQ(hostMemorySize, systemSharedMemorySize); - mock->testIoctls(); - mock->ioctl_expected.contextDestroy = static_cast(device->engines.size()); + EXPECT_EQ(gpuMemorySize, systemSharedMemorySize); + mock->ioctl_expected.contextDestroy = 0; + mock->ioctl_expected.contextCreate = 0; + mock->testIoctls(); + + // gpuMemSize > hostMemSize + gpuMemorySize = hostMemorySize + 1u; + mock->getContextParamRetValue = gpuMemorySize; + systemSharedMemorySize = memoryManager->getSystemSharedMemory(i); + mock->ioctl_expected.contextGetParam = 2; + EXPECT_EQ(hostMemorySize, systemSharedMemorySize); + mock->testIoctls(); + mock->ioctl_expected.contextDestroy = static_cast(device->engines.size()); + + executionEnvironment->rootDeviceEnvironments[i]->osInterface.reset(); + } } TEST_F(DrmMemoryManagerTest, BoWaitFailure) { @@ -568,7 +588,7 @@ TEST_F(DrmMemoryManagerTest, NullOsHandleStorageAskedForPopulationReturnsFilledP OsHandleStorage storage; storage.fragmentStorageData[0].cpuPtr = reinterpret_cast(0x1000); storage.fragmentStorageData[0].fragmentSize = 1; - memoryManager->populateOsHandles(storage); + memoryManager->populateOsHandles(storage, 0u); EXPECT_NE(nullptr, storage.fragmentStorageData[0].osHandleStorage); EXPECT_EQ(nullptr, storage.fragmentStorageData[1].osHandleStorage); EXPECT_EQ(nullptr, storage.fragmentStorageData[2].osHandleStorage); @@ -598,7 +618,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenEnabledHostMemoryValid mock->ioctl_expected.gemUserptr = 1; mock->ioctl_expected.execbuffer2 = 1; - MemoryManager::AllocationStatus result = memoryManager->populateOsHandles(storage); + MemoryManager::AllocationStatus result = memoryManager->populateOsHandles(storage, 0u); EXPECT_EQ(MemoryManager::AllocationStatus::InvalidHostPointer, result); mock->testIoctls(); @@ -709,7 +729,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenEnabledHostMemoryValid mock->ioctl_expected.gemUserptr = 1; mock->ioctl_expected.execbuffer2 = 1; - MemoryManager::AllocationStatus result = memoryManager->populateOsHandles(storage); + MemoryManager::AllocationStatus result = memoryManager->populateOsHandles(storage, 0u); EXPECT_EQ(MemoryManager::AllocationStatus::Error, result); mock->testIoctls(); @@ -1919,8 +1939,8 @@ TEST_F(DrmMemoryManagerTest, givenTwoGraphicsAllocationsThatShareTheSameBufferOb auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(sharedHandle, properties, false); auto graphicsAllocation2 = memoryManager->createGraphicsAllocationFromSharedHandle(sharedHandle, properties, false); - executionEnvironment->osInterface = std::make_unique(); - executionEnvironment->osInterface->get()->setDrm(mock.get()); + executionEnvironment->rootDeviceEnvironments[0]->osInterface = std::make_unique(); + executionEnvironment->rootDeviceEnvironments[0]->osInterface->get()->setDrm(mock.get()); auto testedCsr = new TestedDrmCommandStreamReceiver(*executionEnvironment); device->resetCommandStreamReceiver(testedCsr); @@ -1947,8 +1967,8 @@ TEST_F(DrmMemoryManagerTest, givenTwoGraphicsAllocationsThatDoesnShareTheSameBuf mock->outputHandle++; auto graphicsAllocation2 = memoryManager->createGraphicsAllocationFromSharedHandle(sharedHandle, properties, false); - executionEnvironment->osInterface = std::make_unique(); - executionEnvironment->osInterface->get()->setDrm(mock.get()); + executionEnvironment->rootDeviceEnvironments[0]->osInterface = std::make_unique(); + executionEnvironment->rootDeviceEnvironments[0]->osInterface->get()->setDrm(mock.get()); auto testedCsr = new TestedDrmCommandStreamReceiver(*executionEnvironment); device->resetCommandStreamReceiver(testedCsr); @@ -2522,7 +2542,7 @@ TEST_F(DrmMemoryManagerBasic, givenMemoryManagerWhenAllocateGraphicsMemoryIsCall } TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenMemoryManagerWhenAllocateGraphicsMemoryWithPtrIsCalledThenMemoryPoolIsSystem4KBPages) { - executionEnvironment->osInterface->get()->setDrm(Drm::get(0)); + executionEnvironment->rootDeviceEnvironments[0]->osInterface->get()->setDrm(Drm::get(0)); std::unique_ptr memoryManager(new (std::nothrow) TestedDrmMemoryManager(false, false, true, @@ -2618,7 +2638,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenDisabledForcePinAndEna OsHandleStorage handleStorage; handleStorage.fragmentStorageData[0].cpuPtr = reinterpret_cast(0x1000); handleStorage.fragmentStorageData[0].fragmentSize = 4096; - auto result = memoryManager->populateOsHandles(handleStorage); + auto result = memoryManager->populateOsHandles(handleStorage, 0u); EXPECT_EQ(MemoryManager::AllocationStatus::Success, result); mock->testIoctls(); @@ -2676,7 +2696,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenDisabledForcePinAndEna handleStorage.fragmentStorageData[2].cpuPtr = reinterpret_cast(0x4000); handleStorage.fragmentStorageData[2].fragmentSize = 4096; - auto result = memoryManager->populateOsHandles(handleStorage); + auto result = memoryManager->populateOsHandles(handleStorage, 0u); EXPECT_EQ(MemoryManager::AllocationStatus::Success, result); mock->testIoctls(); @@ -2730,7 +2750,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenEnabledHostMemoryValid OsHandleStorage storage; storage.fragmentStorageData[0].cpuPtr = reinterpret_cast(0x1000); storage.fragmentStorageData[0].fragmentSize = 1; - auto result = memoryManager->populateOsHandles(storage); + auto result = memoryManager->populateOsHandles(storage, 0u); EXPECT_EQ(MemoryManager::AllocationStatus::Success, result); EXPECT_NE(nullptr, storage.fragmentStorageData[0].osHandleStorage); @@ -2945,7 +2965,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenEnabledValidateHostMem handleStorage.fragmentStorageData[2].cpuPtr = reinterpret_cast(0x4000); handleStorage.fragmentStorageData[2].fragmentSize = 4096; - auto result = memoryManager->populateOsHandles(handleStorage); + auto result = memoryManager->populateOsHandles(handleStorage, 0u); EXPECT_EQ(MemoryManager::AllocationStatus::InvalidHostPointer, result); mock->testIoctls(); @@ -2961,7 +2981,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenEnabledValidateHostMem handleStorage.fragmentStorageData[1].freeTheFragment = true; handleStorage.fragmentStorageData[2].freeTheFragment = true; - memoryManager->cleanOsHandles(handleStorage, 0); + memoryManager->cleanOsHandles(handleStorage, 0u); mock->ioctl_res_ext = &mock->NONE; } @@ -2995,7 +3015,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenEnabledValidateHostMem handleStorage.fragmentStorageData[2].cpuPtr = reinterpret_cast(0x4000); handleStorage.fragmentStorageData[2].fragmentSize = 4096; - auto result = memoryManager->populateOsHandles(handleStorage); + auto result = memoryManager->populateOsHandles(handleStorage, 0u); EXPECT_EQ(MemoryManager::AllocationStatus::InvalidHostPointer, result); mock->testIoctls(); @@ -3031,7 +3051,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenEnabledValidateHostMem handleStorage.fragmentStorageData[0].cpuPtr = reinterpret_cast(0x1000); handleStorage.fragmentStorageData[0].fragmentSize = 4096; - auto result = memoryManager->populateOsHandles(handleStorage); + auto result = memoryManager->populateOsHandles(handleStorage, 0u); EXPECT_EQ(MemoryManager::AllocationStatus::Success, result); mock->testIoctls(); @@ -3170,7 +3190,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, whenReservingAddressRangeTh constexpr size_t size = 0x1000; auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{size}); ASSERT_NE(nullptr, allocation); - void *reserve = memoryManager->reserveCpuAddressRange(size); + void *reserve = memoryManager->reserveCpuAddressRange(size, 0u); EXPECT_EQ(nullptr, reserve); allocation->setReservedAddressRange(reserve, size); EXPECT_EQ(reserve, allocation->getReservedAddressPtr()); @@ -3179,13 +3199,22 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, whenReservingAddressRangeTh } TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, whenObtainFdFromHandleIsCalledThenProperFdHandleIsReturned) { - int boHandle = 3; - this->mock->outputFd = 1337; - this->mock->ioctl_expected.handleToPrimeFd = 1; - auto fdHandle = memoryManager->obtainFdFromHandle(boHandle); - EXPECT_EQ(this->mock->inputHandle, static_cast(boHandle)); - EXPECT_EQ(this->mock->inputFlags, DRM_CLOEXEC | DRM_RDWR); - EXPECT_EQ(1337, fdHandle); + executionEnvironment->prepareRootDeviceEnvironments(4u); + for (auto i = 0u; i < 4u; i++) { + auto mock = std::make_unique(); + executionEnvironment->rootDeviceEnvironments[i]->osInterface = std::make_unique(); + executionEnvironment->rootDeviceEnvironments[i]->osInterface->get()->setDrm(mock.get()); + + int boHandle = 3; + mock->outputFd = 1337; + mock->ioctl_expected.handleToPrimeFd = 1; + auto fdHandle = memoryManager->obtainFdFromHandle(boHandle, i); + EXPECT_EQ(mock->inputHandle, static_cast(boHandle)); + EXPECT_EQ(mock->inputFlags, DRM_CLOEXEC | DRM_RDWR); + EXPECT_EQ(1337, fdHandle); + + executionEnvironment->rootDeviceEnvironments[i]->osInterface.reset(); + } } TEST_F(DrmMemoryManagerTest, givenSvmCpuAllocationWhenSizeAndAlignmentProvidedThenAllocateMemoryAndReserveGpuVa) { @@ -3282,8 +3311,8 @@ class GMockDrmMemoryManager : public TestedDrmMemoryManager { TEST(DrmMemoryManagerFreeGraphicsMemoryCallSequenceTest, givenDrmMemoryManagerAndFreeGraphicsMemoryIsCalledThenUnreferenceBufferObjectIsCalledFirstWithSynchronousDestroySetToTrue) { MockExecutionEnvironment executionEnvironment(*platformDevices); - executionEnvironment.osInterface = std::make_unique(); - executionEnvironment.osInterface->get()->setDrm(Drm::get(0)); + executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique(); + executionEnvironment.rootDeviceEnvironments[0]->osInterface->get()->setDrm(Drm::get(0)); GMockDrmMemoryManager gmockDrmMemoryManager(executionEnvironment); AllocationProperties properties{0, MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER}; @@ -3302,8 +3331,8 @@ TEST(DrmMemoryManagerFreeGraphicsMemoryCallSequenceTest, givenDrmMemoryManagerAn TEST(DrmMemoryManagerFreeGraphicsMemoryUnreferenceTest, givenDrmMemoryManagerAndFreeGraphicsMemoryIsCalledForSharedAllocationThenUnreferenceBufferObjectIsCalledWithSynchronousDestroySetToFalse) { MockExecutionEnvironment executionEnvironment(*platformDevices); - executionEnvironment.osInterface = std::make_unique(); - executionEnvironment.osInterface->get()->setDrm(Drm::get(0)); + executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique(); + executionEnvironment.rootDeviceEnvironments[0]->osInterface->get()->setDrm(Drm::get(0)); ::testing::NiceMock gmockDrmMemoryManager(executionEnvironment); osHandle handle = 1u; @@ -3316,3 +3345,17 @@ TEST(DrmMemoryManagerFreeGraphicsMemoryUnreferenceTest, givenDrmMemoryManagerAnd gmockDrmMemoryManager.freeGraphicsMemory(allocation); } + +TEST(DrmMemoryMangerTest, givenMultipleRootDeviceWhenMemoryManagerGetsDrmThenDrmIsFromCorrectRootDevice) { + DebugManagerStateRestore restorer; + DebugManager.flags.CreateMultipleRootDevices.set(4); + VariableBackup backup(&overrideDeviceWithDefaultHardwareInfo, false); + platform()->initialize(); + + TestedDrmMemoryManager drmMemoryManager(*platformImpl->peekExecutionEnvironment()); + for (auto i = 0u; i < platformImpl->peekExecutionEnvironment()->rootDeviceEnvironments.size(); i++) { + auto drmFromRootDevice = platformImpl->peekExecutionEnvironment()->rootDeviceEnvironments[i]->osInterface->get()->getDrm(); + EXPECT_EQ(drmFromRootDevice, &drmMemoryManager.getDrm(i)); + } +} +} // namespace NEO 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 8f2fa86d28..6f967feea1 100644 --- a/unit_tests/os_interface/linux/drm_memory_manager_tests.h +++ b/unit_tests/os_interface/linux/drm_memory_manager_tests.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 Intel Corporation + * Copyright (C) 2019-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -24,8 +24,8 @@ class DrmMemoryManagerBasic : public ::testing::Test { public: DrmMemoryManagerBasic() : executionEnvironment(*platformDevices){}; void SetUp() override { - executionEnvironment.osInterface = std::make_unique(); - executionEnvironment.osInterface->get()->setDrm(Drm::get(0)); + executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique(); + executionEnvironment.rootDeviceEnvironments[0]->osInterface->get()->setDrm(Drm::get(0)); executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = std::make_unique(); } @@ -47,8 +47,8 @@ class DrmMemoryManagerFixture : public MemoryManagementFixture { this->mock = std::unique_ptr(mock); executionEnvironment = new MockExecutionEnvironment(*platformDevices); executionEnvironment->incRefInternal(); - executionEnvironment->osInterface = std::make_unique(); - executionEnvironment->osInterface->get()->setDrm(mock); + executionEnvironment->rootDeviceEnvironments[0]->osInterface = std::make_unique(); + executionEnvironment->rootDeviceEnvironments[0]->osInterface->get()->setDrm(mock); memoryManager = new (std::nothrow) TestedDrmMemoryManager(localMemoryEnabled, false, false, *executionEnvironment); //assert we have memory manager @@ -95,8 +95,8 @@ class DrmMemoryManagerFixtureWithoutQuietIoctlExpectation { executionEnvironment->setHwInfo(*platformDevices); executionEnvironment->prepareRootDeviceEnvironments(1); mock = std::make_unique(); - executionEnvironment->osInterface = std::make_unique(); - executionEnvironment->osInterface->get()->setDrm(mock.get()); + executionEnvironment->rootDeviceEnvironments[0]->osInterface = std::make_unique(); + executionEnvironment->rootDeviceEnvironments[0]->osInterface->get()->setDrm(mock.get()); memoryManager.reset(new TestedDrmMemoryManager(*executionEnvironment)); ASSERT_NE(nullptr, memoryManager); diff --git a/unit_tests/os_interface/linux/drm_neo_create.cpp b/unit_tests/os_interface/linux/drm_neo_create.cpp index 4f14f37023..b0b331ef9a 100644 --- a/unit_tests/os_interface/linux/drm_neo_create.cpp +++ b/unit_tests/os_interface/linux/drm_neo_create.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2019 Intel Corporation + * Copyright (C) 2017-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -45,15 +45,10 @@ void popDrmMock() { drmMockStack.pop_back(); } Drm::~Drm() { fd = -1; } Drm *Drm::get(int32_t deviceOrdinal) { - // We silently skip deviceOrdinal - EXPECT_EQ(deviceOrdinal, 0); return drmMockStack[drmMockStack.size() - 1]; } Drm *Drm::create(int32_t deviceOrdinal) { - // We silently skip deviceOrdinal - EXPECT_EQ(deviceOrdinal, 0); - return drmMockStack[drmMockStack.size() - 1]; } 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 620f4dae41..a0ff1322b2 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 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2019 Intel Corporation + * Copyright (C) 2017-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -23,7 +23,7 @@ struct clCreateCommandQueueWithPropertiesLinux : public UltCommandStreamReceiver executionEnvironment->prepareRootDeviceEnvironments(1); auto osInterface = new OSInterface(); osInterface->get()->setDrm(drm.get()); - executionEnvironment->osInterface.reset(osInterface); + executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(osInterface); executionEnvironment->memoryManager.reset(new TestedDrmMemoryManager(*executionEnvironment)); mdevice.reset(MockDevice::create(executionEnvironment, 0u)); @@ -53,7 +53,7 @@ TEST_F(clCreateCommandQueueWithPropertiesLinux, givenUnPossiblePropertiesWithClQ cl_queue_properties properties[] = {CL_QUEUE_SLICE_COUNT_INTEL, newSliceCount, 0}; std::unique_ptr drm = std::make_unique(); - mdevice.get()->getExecutionEnvironment()->osInterface->get()->setDrm(drm.get()); + mdevice.get()->getExecutionEnvironment()->rootDeviceEnvironments[0]->osInterface->get()->setDrm(drm.get()); cl_command_queue cmdQ = clCreateCommandQueueWithProperties(context.get(), clDevice, properties, &retVal); @@ -68,7 +68,7 @@ TEST_F(clCreateCommandQueueWithPropertiesLinux, givenZeroWithClQueueSliceCountWh cl_queue_properties properties[] = {CL_QUEUE_SLICE_COUNT_INTEL, newSliceCount, 0}; std::unique_ptr drm = std::make_unique(); - mdevice.get()->getExecutionEnvironment()->osInterface->get()->setDrm(drm.get()); + mdevice.get()->getExecutionEnvironment()->rootDeviceEnvironments[0]->osInterface->get()->setDrm(drm.get()); cl_command_queue cmdQ = clCreateCommandQueueWithProperties(context.get(), clDevice, properties, &retVal); @@ -94,7 +94,7 @@ TEST_F(clCreateCommandQueueWithPropertiesLinux, givenPossiblePropertiesWithClQue cl_queue_properties properties[] = {CL_QUEUE_SLICE_COUNT_INTEL, newSliceCount, 0}; std::unique_ptr drm = std::make_unique(); - mdevice.get()->getExecutionEnvironment()->osInterface->get()->setDrm(drm.get()); + mdevice.get()->getExecutionEnvironment()->rootDeviceEnvironments[0]->osInterface->get()->setDrm(drm.get()); cl_command_queue cmdQ = clCreateCommandQueueWithProperties(context.get(), clDevice, properties, &retVal); diff --git a/unit_tests/os_interface/windows/device_command_stream_tests.cpp b/unit_tests/os_interface/windows/device_command_stream_tests.cpp index 38b2e7c96b..8e3562144f 100644 --- a/unit_tests/os_interface/windows/device_command_stream_tests.cpp +++ b/unit_tests/os_interface/windows/device_command_stream_tests.cpp @@ -64,7 +64,7 @@ class WddmCommandStreamFixture { memoryManager = new MockWddmMemoryManager(*executionEnvironment); executionEnvironment->memoryManager.reset(memoryManager); - wddm = static_cast(executionEnvironment->osInterface->get()->getWddm()); + wddm = static_cast(executionEnvironment->rootDeviceEnvironments[0]->osInterface->get()->getWddm()); csr = new WddmCommandStreamReceiver(*executionEnvironment, 0); device.reset(MockDevice::create(executionEnvironment, 0u)); @@ -117,7 +117,7 @@ class WddmCommandStreamWithMockGdiFixture { virtual void SetUp() { HardwareInfo *hwInfo = nullptr; ExecutionEnvironment *executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 1); - wddm = static_cast(executionEnvironment->osInterface->get()->getWddm()); + wddm = static_cast(executionEnvironment->rootDeviceEnvironments[0]->osInterface->get()->getWddm()); gdi = new MockGdi(); wddm->gdi.reset(gdi); ASSERT_NE(wddm, nullptr); @@ -145,8 +145,8 @@ using DeviceCommandStreamTest = ::Test; TEST_F(DeviceCommandStreamTest, CreateWddmCSR) { ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); auto wddm = Wddm::createWddm(*executionEnvironment->rootDeviceEnvironments[0].get()); - executionEnvironment->osInterface = std::make_unique(); - executionEnvironment->osInterface->get()->setWddm(static_cast(wddm)); + executionEnvironment->rootDeviceEnvironments[0]->osInterface = std::make_unique(); + executionEnvironment->rootDeviceEnvironments[0]->osInterface->get()->setWddm(static_cast(wddm)); executionEnvironment->initializeMemoryManager(); std::unique_ptr> csr(static_cast *>(WddmCommandStreamReceiver::create(false, *executionEnvironment, 0))); EXPECT_NE(nullptr, csr); @@ -157,8 +157,8 @@ TEST_F(DeviceCommandStreamTest, CreateWddmCSR) { TEST_F(DeviceCommandStreamTest, CreateWddmCSRWithAubDump) { ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); auto wddm = Wddm::createWddm(*executionEnvironment->rootDeviceEnvironments[0].get()); - executionEnvironment->osInterface = std::make_unique(); - executionEnvironment->osInterface->get()->setWddm(static_cast(wddm)); + executionEnvironment->rootDeviceEnvironments[0]->osInterface = std::make_unique(); + executionEnvironment->rootDeviceEnvironments[0]->osInterface->get()->setWddm(static_cast(wddm)); executionEnvironment->initializeMemoryManager(); std::unique_ptr> csr(static_cast *>(WddmCommandStreamReceiver::create(true, *executionEnvironment, 0))); EXPECT_NE(nullptr, csr); @@ -240,7 +240,7 @@ TEST(WddmPreemptionHeaderTests, givenWddmCommandStreamReceiverWhenPreemptionIsOf ExecutionEnvironment *executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 1); hwInfo->capabilityTable.defaultPreemptionMode = PreemptionMode::Disabled; executionEnvironment->setHwInfo(hwInfo); - auto wddm = static_cast(executionEnvironment->osInterface->get()->getWddm()); + auto wddm = static_cast(executionEnvironment->rootDeviceEnvironments[0]->osInterface->get()->getWddm()); auto csr = std::make_unique>(*executionEnvironment, 0); executionEnvironment->memoryManager.reset(new MemoryManagerCreate(false, false, *executionEnvironment)); csr->overrideDispatchPolicy(DispatchMode::ImmediateDispatch); @@ -265,7 +265,7 @@ TEST(WddmPreemptionHeaderTests, givenWddmCommandStreamReceiverWhenPreemptionIsOn ExecutionEnvironment *executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 1); hwInfo->capabilityTable.defaultPreemptionMode = PreemptionMode::MidThread; executionEnvironment->setHwInfo(hwInfo); - auto wddm = static_cast(executionEnvironment->osInterface->get()->getWddm()); + auto wddm = static_cast(executionEnvironment->rootDeviceEnvironments[0]->osInterface->get()->getWddm()); auto csr = std::make_unique>(*executionEnvironment, 0); executionEnvironment->memoryManager.reset(new MemoryManagerCreate(false, false, *executionEnvironment)); csr->overrideDispatchPolicy(DispatchMode::ImmediateDispatch); @@ -820,8 +820,8 @@ HWTEST_F(WddmSimpleTest, givenDefaultWddmCsrWhenItIsCreatedThenBatchingIsTurnedO ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); std::unique_ptr device(Device::create(executionEnvironment, 0u)); auto wddm = Wddm::createWddm(*executionEnvironment->rootDeviceEnvironments[0].get()); - executionEnvironment->osInterface = std::make_unique(); - executionEnvironment->osInterface->get()->setWddm(wddm); + executionEnvironment->rootDeviceEnvironments[0]->osInterface = std::make_unique(); + executionEnvironment->rootDeviceEnvironments[0]->osInterface->get()->setWddm(wddm); executionEnvironment->rootDeviceEnvironments[0]->memoryOperationsInterface = std::make_unique(wddm); std::unique_ptr> mockCsr(new MockWddmCsr(*executionEnvironment, 0)); EXPECT_EQ(DispatchMode::BatchedDispatch, mockCsr->dispatchMode); @@ -829,8 +829,8 @@ HWTEST_F(WddmSimpleTest, givenDefaultWddmCsrWhenItIsCreatedThenBatchingIsTurnedO HWTEST_F(WddmDefaultTest, givenFtrWddmHwQueuesFlagWhenCreatingCsrThenPickWddmVersionBasingOnFtrFlag) { auto wddm = Wddm::createWddm(*pDevice->executionEnvironment->rootDeviceEnvironments[0].get()); - pDevice->executionEnvironment->osInterface = std::make_unique(); - pDevice->executionEnvironment->osInterface->get()->setWddm(wddm); + pDevice->executionEnvironment->rootDeviceEnvironments[0]->osInterface = std::make_unique(); + pDevice->executionEnvironment->rootDeviceEnvironments[0]->osInterface->get()->setWddm(wddm); pDevice->executionEnvironment->rootDeviceEnvironments[0]->memoryOperationsInterface = std::make_unique(wddm); WddmCommandStreamReceiver wddmCsr(*pDevice->executionEnvironment, 0); @@ -863,7 +863,7 @@ HWTEST_P(WddmCsrCompressionParameterizedTest, givenEnabledCompressionWhenInitial ExecutionEnvironment *executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 2); std::unique_ptr device(Device::create(executionEnvironment, 1u)); setCompressionEnabled(compressionEnabled, !compressionEnabled); - myMockWddm = static_cast(executionEnvironment->osInterface->get()->getWddm()); + myMockWddm = static_cast(executionEnvironment->rootDeviceEnvironments[0]->osInterface->get()->getWddm()); EXPECT_EQ(nullptr, executionEnvironment->rootDeviceEnvironments[index]->pageTableManager.get()); MockWddmCsr mockWddmCsr(*executionEnvironment, index); @@ -887,7 +887,7 @@ HWTEST_F(WddmCsrCompressionTests, givenDisabledCompressionWhenInitializedThenDon ExecutionEnvironment *executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 2); std::unique_ptr device(Device::create(executionEnvironment, 1u)); setCompressionEnabled(false, false); - myMockWddm = static_cast(executionEnvironment->osInterface->get()->getWddm()); + myMockWddm = static_cast(executionEnvironment->rootDeviceEnvironments[0]->osInterface->get()->getWddm()); MockWddmCsr mockWddmCsr(*executionEnvironment, 1); EXPECT_EQ(nullptr, executionEnvironment->rootDeviceEnvironments[1]->pageTableManager.get()); } @@ -900,7 +900,7 @@ INSTANTIATE_TEST_CASE_P( HWTEST_F(WddmCsrCompressionTests, givenDisabledCompressionWhenFlushingThenDontInitTranslationTable) { ExecutionEnvironment *executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 2); setCompressionEnabled(false, false); - myMockWddm = static_cast(executionEnvironment->osInterface->get()->getWddm()); + myMockWddm = static_cast(executionEnvironment->rootDeviceEnvironments[0]->osInterface->get()->getWddm()); auto mockWddmCsr = new MockWddmCsr(*executionEnvironment, 1); mockWddmCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); diff --git a/unit_tests/os_interface/windows/driver_info_tests.cpp b/unit_tests/os_interface/windows/driver_info_tests.cpp index b2dc8dc76a..1e82819bd4 100644 --- a/unit_tests/os_interface/windows/driver_info_tests.cpp +++ b/unit_tests/os_interface/windows/driver_info_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2019 Intel Corporation + * Copyright (C) 2017-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -49,16 +49,16 @@ class DriverInfoDeviceTest : public ::testing::Test { CommandStreamReceiver *createMockCommandStreamReceiver(bool withAubDump, ExecutionEnvironment &executionEnvironment, uint32_t rootDeviceIndex) { auto csr = new MockCommandStreamReceiver(executionEnvironment, rootDeviceIndex); - if (!executionEnvironment.osInterface) { - executionEnvironment.osInterface = std::make_unique(); + if (!executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->osInterface) { + executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->osInterface = std::make_unique(); auto wddm = new WddmMock(*executionEnvironment.rootDeviceEnvironments[0]); auto hwInfo = *executionEnvironment.getHardwareInfo(); wddm->init(hwInfo); - executionEnvironment.osInterface->get()->setWddm(wddm); + executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->osInterface->get()->setWddm(wddm); } - EXPECT_NE(nullptr, executionEnvironment.osInterface.get()); - csr->setOSInterface(executionEnvironment.osInterface.get()); + EXPECT_NE(nullptr, executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->osInterface.get()); + csr->setOSInterface(executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->osInterface.get()); return csr; } diff --git a/unit_tests/os_interface/windows/mock_wddm_memory_manager.h b/unit_tests/os_interface/windows/mock_wddm_memory_manager.h index e58f6270f6..d5495d7894 100644 --- a/unit_tests/os_interface/windows/mock_wddm_memory_manager.h +++ b/unit_tests/os_interface/windows/mock_wddm_memory_manager.h @@ -23,6 +23,7 @@ class MockWddmMemoryManager : public MemoryManagerCreate { using BaseClass::allocateShareableMemory; using BaseClass::createGraphicsAllocation; using BaseClass::createWddmAllocation; + using BaseClass::getWddm; using BaseClass::gfxPartitions; using BaseClass::localMemorySupported; using BaseClass::supportsMultiStorageResources; diff --git a/unit_tests/os_interface/windows/wddm_fixture.h b/unit_tests/os_interface/windows/wddm_fixture.h index f241102911..ed8264b6c1 100644 --- a/unit_tests/os_interface/windows/wddm_fixture.h +++ b/unit_tests/os_interface/windows/wddm_fixture.h @@ -30,10 +30,10 @@ struct WddmFixture : ::testing::Test { void SetUp() override { executionEnvironment = platformImpl->peekExecutionEnvironment(); wddm = static_cast(Wddm::createWddm(*executionEnvironment->rootDeviceEnvironments[0].get())); - executionEnvironment->osInterface = std::make_unique(); - executionEnvironment->osInterface->get()->setWddm(wddm); + executionEnvironment->rootDeviceEnvironments[0]->osInterface = std::make_unique(); + executionEnvironment->rootDeviceEnvironments[0]->osInterface->get()->setWddm(wddm); executionEnvironment->rootDeviceEnvironments[0]->memoryOperationsInterface = std::make_unique(wddm); - osInterface = executionEnvironment->osInterface.get(); + osInterface = executionEnvironment->rootDeviceEnvironments[0]->osInterface.get(); gdi = new MockGdi(); wddm->gdi.reset(gdi); auto preemptionMode = PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]); @@ -59,10 +59,10 @@ struct WddmFixtureWithMockGdiDll : public GdiDllFixture { wddm = static_cast(Wddm::createWddm(*executionEnvironment->rootDeviceEnvironments[0].get())); wddmMockInterface = new WddmMockInterface20(*wddm); wddm->wddmInterface.reset(wddmMockInterface); - executionEnvironment->osInterface = std::make_unique(); - executionEnvironment->osInterface->get()->setWddm(wddm); + executionEnvironment->rootDeviceEnvironments[0]->osInterface = std::make_unique(); + executionEnvironment->rootDeviceEnvironments[0]->osInterface->get()->setWddm(wddm); executionEnvironment->rootDeviceEnvironments[0]->memoryOperationsInterface = std::make_unique(wddm); - osInterface = executionEnvironment->osInterface.get(); + osInterface = executionEnvironment->rootDeviceEnvironments[0]->osInterface.get(); } void init() { diff --git a/unit_tests/os_interface/windows/wddm_memory_manager_allocate_in_device_pool_tests.cpp b/unit_tests/os_interface/windows/wddm_memory_manager_allocate_in_device_pool_tests.cpp index f0882e2d08..eb7ec0bfc7 100644 --- a/unit_tests/os_interface/windows/wddm_memory_manager_allocate_in_device_pool_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_memory_manager_allocate_in_device_pool_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2019 Intel Corporation + * Copyright (C) 2018-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -8,5 +8,5 @@ #include "unit_tests/os_interface/windows/wddm_memory_manager_allocate_in_device_pool_tests.inl" TEST_F(WddmMemoryManagerSimpleTest, givenWddmMemoryManagerWhenGetLocalMemoryIsCalledThenSizeOfLocalMemoryIsReturned) { - EXPECT_EQ(0 * GB, memoryManager->getLocalMemorySize()); + EXPECT_EQ(0 * GB, memoryManager->getLocalMemorySize(0u)); } 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 727d60009c..ad0f02fda5 100644 --- a/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp @@ -33,6 +33,10 @@ using namespace NEO; using namespace ::testing; +namespace NEO { +extern bool overrideDeviceWithDefaultHardwareInfo; +} + void WddmMemoryManagerFixture::SetUp() { GdiDllFixture::SetUp(); @@ -47,8 +51,8 @@ void WddmMemoryManagerFixture::SetUp() { constexpr uint64_t heap32Base = (is32bit) ? 0x1000 : 0x800000000000; wddm->setHeap32(heap32Base, 1000 * MemoryConstants::pageSize - 1); - executionEnvironment->osInterface = std::make_unique(); - executionEnvironment->osInterface->get()->setWddm(wddm); + executionEnvironment->rootDeviceEnvironments[0]->osInterface = std::make_unique(); + executionEnvironment->rootDeviceEnvironments[0]->osInterface->get()->setWddm(wddm); executionEnvironment->rootDeviceEnvironments[0]->memoryOperationsInterface = std::make_unique(wddm); memoryManager = std::make_unique(*executionEnvironment); @@ -112,7 +116,7 @@ TEST(WddmMemoryManagerExternalHeapTest, externalHeapIsCreatedWithCorrectBase) { uint64_t base = 0x56000; uint64_t size = 0x9000; wddm->setHeap32(base, size); - executionEnvironment->osInterface->get()->setWddm(wddm.release()); + executionEnvironment->rootDeviceEnvironments[0]->osInterface->get()->setWddm(wddm.release()); std::unique_ptr memoryManager = std::unique_ptr(new WddmMemoryManager(*executionEnvironment)); @@ -123,7 +127,7 @@ TEST(WddmMemoryManagerWithDeferredDeleterTest, givenWMMWhenAsyncDeleterIsEnabled HardwareInfo *hwInfo; auto executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 1); auto wddm = std::make_unique(*executionEnvironment->rootDeviceEnvironments[0].get()); - executionEnvironment->osInterface->get()->setWddm(wddm.release()); + executionEnvironment->rootDeviceEnvironments[0]->osInterface->get()->setWddm(wddm.release()); bool actualDeleterFlag = DebugManager.flags.EnableDeferredDeleter.get(); DebugManager.flags.EnableDeferredDeleter.set(true); MockWddmMemoryManager memoryManager(*executionEnvironment); @@ -834,8 +838,19 @@ TEST_F(WddmMemoryManagerTest, GivenUnAlignedPointerAndSizeWhenAllocate32BitMemor } TEST_F(WddmMemoryManagerTest, getSystemSharedMemory) { - int64_t mem = memoryManager->getSystemSharedMemory(); - EXPECT_EQ(mem, 4249540608); + executionEnvironment->prepareRootDeviceEnvironments(4u); + for (auto i = 0u; i < 4u; i++) { + auto mockWddm = Wddm::createWddm(*executionEnvironment->rootDeviceEnvironments[i].get()); + auto hwInfo = *platformDevices[0]; + mockWddm->init(hwInfo); + executionEnvironment->rootDeviceEnvironments[i]->osInterface = std::make_unique(); + executionEnvironment->rootDeviceEnvironments[i]->osInterface->get()->setWddm(mockWddm); + + int64_t mem = memoryManager->getSystemSharedMemory(i); + EXPECT_EQ(mem, 4249540608); + + executionEnvironment->rootDeviceEnvironments[i]->osInterface.reset(); + } } TEST_F(WddmMemoryManagerTest, getMaxApplicationAddress) { @@ -1080,7 +1095,7 @@ TEST_F(BufferWithWddmMemory, NullOsHandleStorageAskedForPopulationReturnsFilledP OsHandleStorage storage; storage.fragmentStorageData[0].cpuPtr = reinterpret_cast(0x1000); storage.fragmentStorageData[0].fragmentSize = MemoryConstants::pageSize; - memoryManager->populateOsHandles(storage); + memoryManager->populateOsHandles(storage, 0); EXPECT_NE(nullptr, storage.fragmentStorageData[0].osHandleStorage); EXPECT_NE(nullptr, storage.fragmentStorageData[0].osHandleStorage->gmm); EXPECT_EQ(nullptr, storage.fragmentStorageData[1].osHandleStorage); @@ -1236,14 +1251,14 @@ struct WddmMemoryManagerWithAsyncDeleterTest : public MockWddmMemoryManagerTest TEST_F(WddmMemoryManagerWithAsyncDeleterTest, givenWddmWhenAsyncDeleterIsEnabledThenCanDeferDeletions) { EXPECT_EQ(0, deleter->deferDeletionCalled); - memoryManager->tryDeferDeletions(nullptr, 0, 0); + memoryManager->tryDeferDeletions(nullptr, 0, 0, 0); EXPECT_EQ(1, deleter->deferDeletionCalled); EXPECT_EQ(1u, wddm->destroyAllocationResult.called); } TEST_F(WddmMemoryManagerWithAsyncDeleterTest, givenWddmWhenAsyncDeleterIsDisabledThenCannotDeferDeletions) { memoryManager->setDeferredDeleter(nullptr); - memoryManager->tryDeferDeletions(nullptr, 0, 0); + memoryManager->tryDeferDeletions(nullptr, 0, 0, 0); EXPECT_EQ(1u, wddm->destroyAllocationResult.called); } @@ -1304,7 +1319,7 @@ TEST(WddmMemoryManagerDefaults, givenDefaultWddmMemoryManagerWhenItIsQueriedForI HardwareInfo *hwInfo; auto executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 1); auto wddm = new WddmMock(*executionEnvironment->rootDeviceEnvironments[0].get()); - executionEnvironment->osInterface->get()->setWddm(wddm); + executionEnvironment->rootDeviceEnvironments[0]->osInterface->get()->setWddm(wddm); executionEnvironment->rootDeviceEnvironments[0]->memoryOperationsInterface = std::make_unique(wddm); auto hwInfoMock = *platformDevices[0]; wddm->init(hwInfoMock); @@ -1615,7 +1630,7 @@ TEST_F(WddmMemoryManagerTest2, givenReadOnlyMemoryWhenCreateAllocationFailsThenP EXPECT_CALL(*wddm, createAllocationsAndMapGpuVa(::testing::_)).WillOnce(::testing::Return(STATUS_GRAPHICS_NO_VIDEO_MEMORY)); - auto result = memoryManager->populateOsHandles(handleStorage); + auto result = memoryManager->populateOsHandles(handleStorage, 0); EXPECT_EQ(MemoryManager::AllocationStatus::InvalidHostPointer, result); handleStorage.fragmentStorageData[0].freeTheFragment = true; @@ -1635,7 +1650,7 @@ TEST_F(WddmMemoryManagerTest2, givenReadOnlyMemoryPassedToPopulateOsHandlesWhenC EXPECT_CALL(*wddm, createAllocationsAndMapGpuVa(::testing::_)).WillOnce(::testing::Return(STATUS_GRAPHICS_NO_VIDEO_MEMORY)); - auto result = memoryManager->populateOsHandles(handleStorage); + auto result = memoryManager->populateOsHandles(handleStorage, 0); auto hostPtrManager = static_cast(memoryManager->getHostPtrManager()); EXPECT_EQ(MemoryManager::AllocationStatus::InvalidHostPointer, result); @@ -1655,8 +1670,8 @@ TEST(WddmMemoryManagerCleanupTest, givenUsedTagAllocationInWddmMemoryManagerWhen auto hwInfo = *platformDevices[0]; wddm->init(hwInfo); - executionEnvironment.osInterface = std::make_unique(); - executionEnvironment.osInterface->get()->setWddm(wddm); + executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique(); + executionEnvironment.rootDeviceEnvironments[0]->osInterface->get()->setWddm(wddm); executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = std::make_unique(wddm); executionEnvironment.memoryManager = std::make_unique(executionEnvironment); auto osContext = executionEnvironment.memoryManager->createAndRegisterOsContext(csr.get(), aub_stream::ENGINE_RCS, 1, preemptionMode, false); @@ -1787,3 +1802,32 @@ TEST_F(WddmMemoryManagerSimpleTest, givenBufferHostMemoryAllocationAndLimitedRan memoryManager->freeGraphicsMemory(allocation); } + +TEST(WddmMemoryManager, givenMultipleRootDeviceWhenMemoryManagerGetsWddmThenWddmIsFromCorrectRootDevice) { + DebugManagerStateRestore restorer; + DebugManager.flags.CreateMultipleRootDevices.set(4); + VariableBackup backup(&overrideDeviceWithDefaultHardwareInfo, false); + platform()->initialize(); + + MockWddmMemoryManager wddmMemoryManager(*platformImpl->peekExecutionEnvironment()); + for (auto i = 0u; i < platformImpl->peekExecutionEnvironment()->rootDeviceEnvironments.size(); i++) { + auto wddmFromRootDevice = platformImpl->peekExecutionEnvironment()->rootDeviceEnvironments[i]->osInterface->get()->getWddm(); + EXPECT_EQ(wddmFromRootDevice, &wddmMemoryManager.getWddm(i)); + } +} + +TEST(WddmMemoryManager, givenMultipleRootDeviceWhenCreateMemoryManagerThenTakeMaxMallocRestrictionAvailable) { + uint32_t numRootDevices = 4u; + DebugManagerStateRestore restorer; + DebugManager.flags.CreateMultipleRootDevices.set(numRootDevices); + VariableBackup backup(&overrideDeviceWithDefaultHardwareInfo, false); + platform()->initialize(); + for (auto i = 0u; i < numRootDevices; i++) { + auto wddm = static_cast(platformImpl->peekExecutionEnvironment()->rootDeviceEnvironments[i]->osInterface->get()->getWddm()); + wddm->minAddress = i * (numRootDevices - i); + } + + MockWddmMemoryManager wddmMemoryManager(*platformImpl->peekExecutionEnvironment()); + + EXPECT_EQ(4u, wddmMemoryManager.getAlignedMallocRestrictions()->minAddress); +} diff --git a/unit_tests/os_interface/windows/wddm_memory_manager_tests.h b/unit_tests/os_interface/windows/wddm_memory_manager_tests.h index 7524ad66c4..3273713bc5 100644 --- a/unit_tests/os_interface/windows/wddm_memory_manager_tests.h +++ b/unit_tests/os_interface/windows/wddm_memory_manager_tests.h @@ -55,8 +55,8 @@ class MockWddmMemoryManagerFixture { auto hwInfo = *platformDevices[0]; wddm->init(hwInfo); - executionEnvironment->osInterface.reset(new OSInterface()); - executionEnvironment->osInterface->get()->setWddm(wddm); + executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(new OSInterface()); + executionEnvironment->rootDeviceEnvironments[0]->osInterface->get()->setWddm(wddm); executionEnvironment->rootDeviceEnvironments[0]->memoryOperationsInterface = std::make_unique(wddm); memoryManager = std::make_unique(*executionEnvironment); @@ -98,14 +98,14 @@ class WddmMemoryManagerFixtureWithGmockWddm : public ExecutionEnvironmentFixture // wddm is deleted by memory manager wddm = new NiceMock(*executionEnvironment->rootDeviceEnvironments[0].get()); - executionEnvironment->osInterface = std::make_unique(); + executionEnvironment->rootDeviceEnvironments[0]->osInterface = std::make_unique(); ASSERT_NE(nullptr, wddm); auto preemptionMode = PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]); auto hwInfo = *platformDevices[0]; wddm->init(hwInfo); - executionEnvironment->osInterface->get()->setWddm(wddm); + executionEnvironment->rootDeviceEnvironments[0]->osInterface->get()->setWddm(wddm); executionEnvironment->rootDeviceEnvironments[0]->memoryOperationsInterface = std::make_unique(wddm); - osInterface = executionEnvironment->osInterface.get(); + osInterface = executionEnvironment->rootDeviceEnvironments[0]->osInterface.get(); memoryManager = new (std::nothrow) MockWddmMemoryManager(*executionEnvironment); //assert we have memory manager ASSERT_NE(nullptr, memoryManager); @@ -165,7 +165,7 @@ class MockWddmMemoryManagerTest : public ::testing::Test { void SetUp() override { executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 2); wddm = new WddmMock(*executionEnvironment->rootDeviceEnvironments[1].get()); - executionEnvironment->osInterface->get()->setWddm(wddm); + executionEnvironment->rootDeviceEnvironments[0]->osInterface->get()->setWddm(wddm); executionEnvironment->rootDeviceEnvironments[0]->memoryOperationsInterface = std::make_unique(wddm); } diff --git a/unit_tests/os_interface/windows/wddm_residency_controller_tests.cpp b/unit_tests/os_interface/windows/wddm_residency_controller_tests.cpp index c061398aa3..a08c589be7 100644 --- a/unit_tests/os_interface/windows/wddm_residency_controller_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_residency_controller_tests.cpp @@ -119,8 +119,8 @@ struct WddmResidencyControllerWithMockWddmTest : public WddmResidencyControllerT auto hwInfo = *platformDevices[0]; wddm->init(hwInfo); - executionEnvironment->osInterface = std::make_unique(); - executionEnvironment->osInterface->get()->setWddm(wddm); + executionEnvironment->rootDeviceEnvironments[0]->osInterface = std::make_unique(); + executionEnvironment->rootDeviceEnvironments[0]->osInterface->get()->setWddm(wddm); executionEnvironment->rootDeviceEnvironments[0]->memoryOperationsInterface = std::make_unique(wddm); memoryManager = std::make_unique(*executionEnvironment); @@ -152,8 +152,8 @@ struct WddmResidencyControllerWithGdiAndMemoryManagerTest : ::testing::Test { gdi = new MockGdi(); wddm->gdi.reset(gdi); - executionEnvironment->osInterface = std::make_unique(); - executionEnvironment->osInterface->get()->setWddm(wddm); + executionEnvironment->rootDeviceEnvironments[0]->osInterface = std::make_unique(); + executionEnvironment->rootDeviceEnvironments[0]->osInterface->get()->setWddm(wddm); executionEnvironment->rootDeviceEnvironments[0]->memoryOperationsInterface = std::make_unique(wddm); memoryManager = std::make_unique(*executionEnvironment); diff --git a/unit_tests/sharings/gl/gl_arb_sync_event_tests.cpp b/unit_tests/sharings/gl/gl_arb_sync_event_tests.cpp index f84d886372..74202c8b9a 100644 --- a/unit_tests/sharings/gl/gl_arb_sync_event_tests.cpp +++ b/unit_tests/sharings/gl/gl_arb_sync_event_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2019 Intel Corporation + * Copyright (C) 2018-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -79,7 +79,7 @@ struct GlArbSyncEventTest : public ::testing::Test { sharing->pfnGlArbSyncObjectWaitServer = glArbSyncObjectWaitServerMock; osInterface = new OSInterface; mockCsr->setOSInterface(osInterface); - executionEnvironment->osInterface.reset(osInterface); + executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(osInterface); } void TearDown() override {