diff --git a/opencl/test/unit_test/device/device_tests.cpp b/opencl/test/unit_test/device/device_tests.cpp index a667c4ca3d..532e48c502 100644 --- a/opencl/test/unit_test/device/device_tests.cpp +++ b/opencl/test/unit_test/device/device_tests.cpp @@ -192,9 +192,10 @@ HWTEST_F(DeviceTest, givenNoHwCsrTypeAndModifiedDefaultEngineIndexWhenIsSimulati HWTEST_F(DeviceTest, givenDeviceWithoutSubDevicesWhenCreatingContextsThenMemoryManagerDefaultContextIsSetCorrectly) { UltDeviceFactory factory(1, 1); MockDevice &device = *factory.rootDevices[0]; + auto rootDeviceIndex = device.getRootDeviceIndex(); MockMemoryManager *memoryManager = static_cast(device.getMemoryManager()); - OsContext *defaultOsContextMemoryManager = memoryManager->registeredEngines[memoryManager->defaultEngineIndex].osContext; + OsContext *defaultOsContextMemoryManager = memoryManager->registeredEngines[memoryManager->defaultEngineIndex[rootDeviceIndex]].osContext; OsContext *defaultOsContextRootDevice = device.getDefaultEngine().osContext; EXPECT_EQ(defaultOsContextRootDevice, defaultOsContextMemoryManager); } @@ -202,9 +203,10 @@ HWTEST_F(DeviceTest, givenDeviceWithoutSubDevicesWhenCreatingContextsThenMemoryM HWTEST_F(DeviceTest, givenDeviceWithSubDevicesWhenCreatingContextsThenMemoryManagerDefaultContextIsSetCorrectly) { UltDeviceFactory factory(1, 2); MockDevice &device = *factory.rootDevices[0]; + auto rootDeviceIndex = device.getRootDeviceIndex(); MockMemoryManager *memoryManager = static_cast(device.getMemoryManager()); - OsContext *defaultOsContextMemoryManager = memoryManager->registeredEngines[memoryManager->defaultEngineIndex].osContext; + OsContext *defaultOsContextMemoryManager = memoryManager->registeredEngines[memoryManager->defaultEngineIndex[rootDeviceIndex]].osContext; OsContext *defaultOsContextRootDevice = device.getDefaultEngine().osContext; EXPECT_EQ(defaultOsContextRootDevice, defaultOsContextMemoryManager); } @@ -214,9 +216,11 @@ HWTEST_F(DeviceTest, givenMultiDeviceWhenCreatingContextsThenMemoryManagerDefaul MockDevice &device = *factory.rootDevices[2]; MockMemoryManager *memoryManager = static_cast(device.getMemoryManager()); - OsContext *defaultOsContextMemoryManager = memoryManager->registeredEngines[memoryManager->defaultEngineIndex].osContext; - OsContext *defaultOsContextRootDevice = device.getDefaultEngine().osContext; - EXPECT_EQ(defaultOsContextRootDevice, defaultOsContextMemoryManager); + for (auto &pRootDevice : factory.rootDevices) { + OsContext *defaultOsContextMemoryManager = memoryManager->registeredEngines[memoryManager->defaultEngineIndex[pRootDevice->getRootDeviceIndex()]].osContext; + OsContext *defaultOsContextRootDevice = pRootDevice->getDefaultEngine().osContext; + EXPECT_EQ(defaultOsContextRootDevice, defaultOsContextMemoryManager); + } } TEST(DeviceCleanup, givenDeviceWhenItIsDestroyedThenFlushBatchedSubmissionsIsCalled) { diff --git a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp index 99564782b3..37e974946b 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp +++ b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp @@ -380,7 +380,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmContextIdWhenAllocationIsCreatedThenPinWith for (auto engine : memoryManager->registeredEngines) { engine.osContext->incRefInternal(); } - auto drmContextId = memoryManager->getDefaultDrmContextId(); + auto drmContextId = memoryManager->getDefaultDrmContextId(rootDeviceIndex); ASSERT_NE(nullptr, memoryManager->pinBBs[rootDeviceIndex]); EXPECT_NE(0u, drmContextId); diff --git a/shared/source/device/device.cpp b/shared/source/device/device.cpp index 37da64b1a7..5489219585 100644 --- a/shared/source/device/device.cpp +++ b/shared/source/device/device.cpp @@ -91,7 +91,7 @@ bool Device::createDeviceImpl() { break; } } - executionEnvironment->memoryManager->setDefaultEngineIndex(defaultEngineIndexWithinMemoryManager); + executionEnvironment->memoryManager->setDefaultEngineIndex(getRootDeviceIndex(), defaultEngineIndexWithinMemoryManager); auto osInterface = getRootDeviceEnvironment().osInterface.get(); diff --git a/shared/source/memory_manager/memory_manager.cpp b/shared/source/memory_manager/memory_manager.cpp index f2cd32ff5f..86cf8e9759 100644 --- a/shared/source/memory_manager/memory_manager.cpp +++ b/shared/source/memory_manager/memory_manager.cpp @@ -42,6 +42,7 @@ MemoryManager::MemoryManager(ExecutionEnvironment &executionEnvironment) : execu bool anyLocalMemorySupported = false; + defaultEngineIndex.resize(executionEnvironment.rootDeviceEnvironments.size()); for (uint32_t rootDeviceIndex = 0; rootDeviceIndex < executionEnvironment.rootDeviceEnvironments.size(); ++rootDeviceIndex) { auto hwInfo = executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->getHardwareInfo(); localMemoryUsageBankSelector.emplace_back(new LocalMemoryUsageBankSelector(HwHelper::getSubDevicesCount(hwInfo))); diff --git a/shared/source/memory_manager/memory_manager.h b/shared/source/memory_manager/memory_manager.h index d9771b1dfe..027e61c640 100644 --- a/shared/source/memory_manager/memory_manager.h +++ b/shared/source/memory_manager/memory_manager.h @@ -177,7 +177,7 @@ class MemoryManager { EngineControl *getRegisteredEngineForCsr(CommandStreamReceiver *commandStreamReceiver); void unregisterEngineForCsr(CommandStreamReceiver *commandStreamReceiver); HostPtrManager *getHostPtrManager() const { return hostPtrManager.get(); } - void setDefaultEngineIndex(uint32_t index) { defaultEngineIndex = index; } + void setDefaultEngineIndex(uint32_t rootDeviceIndex, uint32_t engineIndex) { defaultEngineIndex[rootDeviceIndex] = engineIndex; } virtual bool copyMemoryToAllocation(GraphicsAllocation *graphicsAllocation, size_t destinationOffset, const void *memoryToCopy, size_t sizeToCopy); HeapIndex selectHeap(const GraphicsAllocation *allocation, bool hasPointer, bool isFullRangeSVM, bool useFrontWindow); static std::unique_ptr createMemoryManager(ExecutionEnvironment &executionEnvironment); @@ -235,12 +235,12 @@ class MemoryManager { bool asyncDeleterEnabled = false; std::vector enable64kbpages; std::vector localMemorySupported; + std::vector defaultEngineIndex; bool supportsMultiStorageResources = true; ExecutionEnvironment &executionEnvironment; EngineControlContainer registeredEngines; std::unique_ptr hostPtrManager; uint32_t latestContextId = std::numeric_limits::max(); - uint32_t defaultEngineIndex = 0; std::unique_ptr multiContextResourceDestructor; std::vector> gfxPartitions; std::vector> localMemoryUsageBankSelector; diff --git a/shared/source/os_interface/linux/drm_memory_manager.cpp b/shared/source/os_interface/linux/drm_memory_manager.cpp index eff65dee9f..d588ed54f1 100644 --- a/shared/source/os_interface/linux/drm_memory_manager.cpp +++ b/shared/source/os_interface/linux/drm_memory_manager.cpp @@ -210,8 +210,9 @@ NEO::BufferObject *DrmMemoryManager::allocUserptr(uintptr_t address, size_t size } void DrmMemoryManager::emitPinningRequest(BufferObject *bo, const AllocationData &allocationData) const { - if (forcePinEnabled && pinBBs.at(allocationData.rootDeviceIndex) != nullptr && allocationData.flags.forcePin && allocationData.size >= this->pinThreshold) { - pinBBs.at(allocationData.rootDeviceIndex)->pin(&bo, 1, registeredEngines[defaultEngineIndex].osContext, 0, getDefaultDrmContextId()); + auto rootDeviceIndex = allocationData.rootDeviceIndex; + if (forcePinEnabled && pinBBs.at(rootDeviceIndex) != nullptr && allocationData.flags.forcePin && allocationData.size >= this->pinThreshold) { + pinBBs.at(rootDeviceIndex)->pin(&bo, 1, registeredEngines[defaultEngineIndex[rootDeviceIndex]].osContext, 0, getDefaultDrmContextId(rootDeviceIndex)); } } @@ -382,15 +383,16 @@ DrmAllocation *DrmMemoryManager::allocateGraphicsMemoryForNonSvmHostPtr(const Al auto alignedSize = alignSizeWholePage(allocationData.hostPtr, allocationData.size); auto realAllocationSize = alignedSize; auto offsetInPage = ptrDiff(allocationData.hostPtr, alignedPtr); + auto rootDeviceIndex = allocationData.rootDeviceIndex; - auto gpuVirtualAddress = acquireGpuRange(alignedSize, allocationData.rootDeviceIndex, HeapIndex::HEAP_STANDARD); + auto gpuVirtualAddress = acquireGpuRange(alignedSize, rootDeviceIndex, HeapIndex::HEAP_STANDARD); if (!gpuVirtualAddress) { return nullptr; } - std::unique_ptr bo(allocUserptr(reinterpret_cast(alignedPtr), realAllocationSize, 0, allocationData.rootDeviceIndex)); + std::unique_ptr bo(allocUserptr(reinterpret_cast(alignedPtr), realAllocationSize, 0, rootDeviceIndex)); if (!bo) { - releaseGpuRange(reinterpret_cast(gpuVirtualAddress), alignedSize, allocationData.rootDeviceIndex); + releaseGpuRange(reinterpret_cast(gpuVirtualAddress), alignedSize, rootDeviceIndex); return nullptr; } @@ -398,10 +400,10 @@ DrmAllocation *DrmMemoryManager::allocateGraphicsMemoryForNonSvmHostPtr(const Al if (validateHostPtrMemory) { auto boPtr = bo.get(); - int result = pinBBs.at(allocationData.rootDeviceIndex)->validateHostPtr(&boPtr, 1, registeredEngines[defaultEngineIndex].osContext, 0, getDefaultDrmContextId()); + int result = pinBBs.at(rootDeviceIndex)->validateHostPtr(&boPtr, 1, registeredEngines[defaultEngineIndex[rootDeviceIndex]].osContext, 0, getDefaultDrmContextId(rootDeviceIndex)); if (result != 0) { unreference(bo.release(), true); - releaseGpuRange(reinterpret_cast(gpuVirtualAddress), alignedSize, allocationData.rootDeviceIndex); + releaseGpuRange(reinterpret_cast(gpuVirtualAddress), alignedSize, rootDeviceIndex); return nullptr; } } @@ -806,7 +808,7 @@ MemoryManager::AllocationStatus DrmMemoryManager::populateOsHandles(OsHandleStor } if (validateHostPtrMemory) { - int result = pinBBs.at(rootDeviceIndex)->validateHostPtr(allocatedBos, numberOfBosAllocated, registeredEngines[defaultEngineIndex].osContext, 0, getDefaultDrmContextId()); + int result = pinBBs.at(rootDeviceIndex)->validateHostPtr(allocatedBos, numberOfBosAllocated, registeredEngines[defaultEngineIndex[rootDeviceIndex]].osContext, 0, getDefaultDrmContextId(rootDeviceIndex)); if (result == EFAULT) { for (uint32_t i = 0; i < numberOfBosAllocated; i++) { @@ -922,8 +924,8 @@ int DrmMemoryManager::obtainFdFromHandle(int boHandle, uint32_t rootDeviceindex) return openFd.fd; } -uint32_t DrmMemoryManager::getDefaultDrmContextId() const { - auto osContextLinux = static_cast(registeredEngines[defaultEngineIndex].osContext); +uint32_t DrmMemoryManager::getDefaultDrmContextId(uint32_t rootDeviceIndex) const { + auto osContextLinux = static_cast(registeredEngines[defaultEngineIndex[rootDeviceIndex]].osContext); return osContextLinux->getDrmContextIds()[0]; } diff --git a/shared/source/os_interface/linux/drm_memory_manager.h b/shared/source/os_interface/linux/drm_memory_manager.h index 0f8495a9b0..6acaa1c9fc 100644 --- a/shared/source/os_interface/linux/drm_memory_manager.h +++ b/shared/source/os_interface/linux/drm_memory_manager.h @@ -80,7 +80,7 @@ class DrmMemoryManager : public MemoryManager { uint64_t acquireGpuRange(size_t &size, uint32_t rootDeviceIndex, HeapIndex heapIndex); MOCKABLE_VIRTUAL void releaseGpuRange(void *address, size_t size, uint32_t rootDeviceIndex); void emitPinningRequest(BufferObject *bo, const AllocationData &allocationData) const; - uint32_t getDefaultDrmContextId() const; + uint32_t getDefaultDrmContextId(uint32_t rootDeviceIndex) const; size_t getUserptrAlignment(); DrmAllocation *createGraphicsAllocation(OsHandleStorage &handleStorage, const AllocationData &allocationData) override;