diff --git a/runtime/memory_manager/memory_manager.h b/runtime/memory_manager/memory_manager.h index c1eb0f7326..bc0a6a61fa 100644 --- a/runtime/memory_manager/memory_manager.h +++ b/runtime/memory_manager/memory_manager.h @@ -23,6 +23,7 @@ class DeferredDeleter; class ExecutionEnvironment; class GraphicsAllocation; class CommandStreamReceiver; +class OsContext; class TimestampPacket; struct HwPerfCounter; diff --git a/runtime/memory_manager/residency.cpp b/runtime/memory_manager/residency.cpp index b79caa4ce2..5cd29dd938 100644 --- a/runtime/memory_manager/residency.cpp +++ b/runtime/memory_manager/residency.cpp @@ -10,19 +10,13 @@ using namespace OCLRT; -void ResidencyData::updateCompletionData(uint64_t newFenceValue, OsContext *context) { - auto contextId = context->getContextId(); - if (contextId + 1 > completionData.size()) { - completionData.resize(contextId + 1); +void ResidencyData::updateCompletionData(uint64_t newFenceValue, uint32_t contextId) { + if (contextId + 1 > lastFenceValues.size()) { + lastFenceValues.resize(contextId + 1); } - completionData[contextId].lastFence = newFenceValue; - completionData[contextId].osContext = context; + lastFenceValues[contextId] = newFenceValue; } uint64_t ResidencyData::getFenceValueForContextId(uint32_t contextId) { - return completionData[contextId].lastFence; -} - -OsContext *ResidencyData::getOsContextFromId(uint32_t contextId) { - return completionData[contextId].osContext; + return lastFenceValues[contextId]; } diff --git a/runtime/memory_manager/residency.h b/runtime/memory_manager/residency.h index ec1f52f9d8..77fae13340 100644 --- a/runtime/memory_manager/residency.h +++ b/runtime/memory_manager/residency.h @@ -9,23 +9,16 @@ #include #include namespace OCLRT { -class OsContext; - -struct FenceData { - uint64_t lastFence = 0; - OsContext *osContext = nullptr; -}; struct ResidencyData { ResidencyData() = default; ~ResidencyData() = default; bool resident = false; - void updateCompletionData(uint64_t newFenceValue, OsContext *context); + void updateCompletionData(uint64_t newFenceValue, uint32_t contextId); uint64_t getFenceValueForContextId(uint32_t contextId); - OsContext *getOsContextFromId(uint32_t contextId); protected: - std::vector completionData; + std::vector lastFenceValues; }; } // namespace OCLRT diff --git a/runtime/os_interface/windows/wddm_memory_manager.cpp b/runtime/os_interface/windows/wddm_memory_manager.cpp index b13818ae5e..d95cf01be5 100644 --- a/runtime/os_interface/windows/wddm_memory_manager.cpp +++ b/runtime/os_interface/windows/wddm_memory_manager.cpp @@ -539,13 +539,13 @@ bool WddmMemoryManager::makeResidentResidencyAllocations(ResidencyContainer &all WddmAllocation *allocation = reinterpret_cast(allocationsForResidency[i]); // Update fence value not to early destroy / evict allocation auto currentFence = osContext.get()->getMonitoredFence().currentFenceValue; - allocation->getResidencyData().updateCompletionData(currentFence, &osContext); + allocation->getResidencyData().updateCompletionData(currentFence, osContext.getContextId()); allocation->getResidencyData().resident = true; for (uint32_t allocationId = 0; allocationId < allocation->fragmentsStorage.fragmentCount; allocationId++) { auto residencyData = allocation->fragmentsStorage.fragmentStorageData[allocationId].residency; // Update fence value not to remove the fragment referenced by different GA in trimming callback - residencyData->updateCompletionData(currentFence, &osContext); + residencyData->updateCompletionData(currentFence, osContext.getContextId()); residencyData->resident = true; } } diff --git a/runtime/sharings/gl/gl_arb_sync_event.h b/runtime/sharings/gl/gl_arb_sync_event.h index 7ace73bf14..dbaf33c58d 100644 --- a/runtime/sharings/gl/gl_arb_sync_event.h +++ b/runtime/sharings/gl/gl_arb_sync_event.h @@ -15,6 +15,7 @@ namespace OCLRT { class Context; class GLSharingFunctions; class OsInterface; +class OsContext; char *createArbSyncEventName(); void destroyArbSyncEventName(char *name); diff --git a/runtime/sharings/gl/gl_sharing.h b/runtime/sharings/gl/gl_sharing.h index 7ce9ebb2d0..1662bb9f7b 100644 --- a/runtime/sharings/gl/gl_sharing.h +++ b/runtime/sharings/gl/gl_sharing.h @@ -26,6 +26,7 @@ class Event; class GlArbSyncEvent; class GLSharingFunctions; class OSInterface; +class OsContext; typedef unsigned int OS_HANDLE; diff --git a/unit_tests/memory_manager/memory_manager_tests.cpp b/unit_tests/memory_manager/memory_manager_tests.cpp index cdaf47f4b7..0545be6c51 100644 --- a/unit_tests/memory_manager/memory_manager_tests.cpp +++ b/unit_tests/memory_manager/memory_manager_tests.cpp @@ -1864,11 +1864,11 @@ TEST(ResidencyDataTest, givenTwoOsContextsWhenTheyAreRegistredFromHigherToLowerT } TEST(ResidencyDataTest, givenResidencyDataWhenUpdateCompletionDataIsCalledThenItIsProperlyUpdated) { - struct mockResidencyData : public ResidencyData { - using ResidencyData::completionData; + struct MockResidencyData : public ResidencyData { + using ResidencyData::lastFenceValues; }; - mockResidencyData residency; + MockResidencyData residency; OsContext osContext(nullptr, 0u); OsContext osContext2(nullptr, 1u); @@ -1877,25 +1877,20 @@ TEST(ResidencyDataTest, givenResidencyDataWhenUpdateCompletionDataIsCalledThenIt auto lastFenceValue2 = 23llu; auto lastFenceValue3 = 373llu; - EXPECT_EQ(0u, residency.completionData.size()); + EXPECT_EQ(0u, residency.lastFenceValues.size()); - residency.updateCompletionData(lastFenceValue, &osContext); - EXPECT_EQ(1u, residency.completionData.size()); - EXPECT_EQ(&osContext, residency.completionData[0].osContext); - EXPECT_EQ(lastFenceValue, residency.completionData[0].lastFence); + residency.updateCompletionData(lastFenceValue, osContext.getContextId()); + EXPECT_EQ(1u, residency.lastFenceValues.size()); + EXPECT_EQ(lastFenceValue, residency.lastFenceValues[0]); EXPECT_EQ(lastFenceValue, residency.getFenceValueForContextId(osContext.getContextId())); - EXPECT_EQ(&osContext, residency.getOsContextFromId(0u)); - residency.updateCompletionData(lastFenceValue2, &osContext2); + residency.updateCompletionData(lastFenceValue2, osContext2.getContextId()); - EXPECT_EQ(2u, residency.completionData.size()); - EXPECT_EQ(&osContext2, residency.completionData[1].osContext); - EXPECT_EQ(lastFenceValue2, residency.completionData[1].lastFence); + EXPECT_EQ(2u, residency.lastFenceValues.size()); + EXPECT_EQ(lastFenceValue2, residency.lastFenceValues[1]); EXPECT_EQ(lastFenceValue2, residency.getFenceValueForContextId(osContext2.getContextId())); - EXPECT_EQ(&osContext2, residency.getOsContextFromId(1u)); - residency.updateCompletionData(lastFenceValue3, &osContext2); - EXPECT_EQ(lastFenceValue3, residency.completionData[1].lastFence); + residency.updateCompletionData(lastFenceValue3, osContext2.getContextId()); + EXPECT_EQ(lastFenceValue3, residency.lastFenceValues[1]); EXPECT_EQ(lastFenceValue3, residency.getFenceValueForContextId(osContext2.getContextId())); - EXPECT_EQ(&osContext2, residency.getOsContextFromId(1u)); } diff --git a/unit_tests/os_interface/windows/wddm20_tests.cpp b/unit_tests/os_interface/windows/wddm20_tests.cpp index 65feaaa418..49a17a51b8 100644 --- a/unit_tests/os_interface/windows/wddm20_tests.cpp +++ b/unit_tests/os_interface/windows/wddm20_tests.cpp @@ -631,7 +631,7 @@ TEST_F(Wddm20Tests, makeNonResidentCallsEvict) { TEST_F(Wddm20Tests, givenDestroyAllocationWhenItIsCalledThenAllocationIsPassedToDestroyAllocation) { WddmAllocation allocation((void *)0x23000, 0x1000, nullptr, MemoryPool::MemoryNull, 1u); - allocation.getResidencyData().updateCompletionData(10, osContext.get()); + allocation.getResidencyData().updateCompletionData(10, osContext.get()->getContextId()); allocation.handle = ALLOCATION_HANDLE; *osContextWin->getMonitoredFence().cpuAddress = 10; @@ -659,7 +659,7 @@ TEST_F(Wddm20Tests, givenDestroyAllocationWhenItIsCalledThenAllocationIsPassedTo TEST_F(Wddm20Tests, WhenLastFenceLessEqualThanMonitoredThenWaitFromCpuIsNotCalled) { WddmAllocation allocation((void *)0x23000, 0x1000, nullptr, MemoryPool::MemoryNull, 1u); - allocation.getResidencyData().updateCompletionData(10, osContext.get()); + allocation.getResidencyData().updateCompletionData(10, osContext.get()->getContextId()); allocation.handle = ALLOCATION_HANDLE; *osContextWin->getMonitoredFence().cpuAddress = 10; @@ -682,7 +682,7 @@ TEST_F(Wddm20Tests, WhenLastFenceLessEqualThanMonitoredThenWaitFromCpuIsNotCalle TEST_F(Wddm20Tests, WhenLastFenceGreaterThanMonitoredThenWaitFromCpuIsCalled) { WddmAllocation allocation((void *)0x23000, 0x1000, nullptr, MemoryPool::MemoryNull, 1u); - allocation.getResidencyData().updateCompletionData(10, osContext.get()); + allocation.getResidencyData().updateCompletionData(10, osContext.get()->getContextId()); allocation.handle = ALLOCATION_HANDLE; *osContextWin->getMonitoredFence().cpuAddress = 10; 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 728af52beb..30f4db5e8e 100644 --- a/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp @@ -971,8 +971,8 @@ TEST_F(WddmMemoryManagerResidencyTest, givenNotUsedAllocationsFromPreviousPeriod // allocations have fence value == 0 by default MockWddmAllocation allocation1, allocation2; - allocation1.getResidencyData().updateCompletionData(0, osContext); - allocation2.getResidencyData().updateCompletionData(0, osContext); + allocation1.getResidencyData().updateCompletionData(0, osContext->getContextId()); + allocation2.getResidencyData().updateCompletionData(0, osContext->getContextId()); allocation1.getResidencyData().resident = true; allocation2.getResidencyData().resident = true; @@ -1008,8 +1008,8 @@ TEST_F(WddmMemoryManagerResidencyTest, givenOneUsedAllocationFromPreviousPeriodi MockWddmAllocation allocation1, allocation2; allocation1.getResidencyData().resident = true; // mark allocation used from last periodic trim - allocation1.getResidencyData().updateCompletionData(0, osContext); - allocation2.getResidencyData().updateCompletionData(11, osContext); + allocation1.getResidencyData().updateCompletionData(0, osContext->getContextId()); + allocation2.getResidencyData().updateCompletionData(11, osContext->getContextId()); allocation2.getResidencyData().resident = true; // Set last periodic fence value @@ -1043,17 +1043,17 @@ TEST_F(WddmMemoryManagerResidencyTest, givenTripleAllocationWithUsedAndUnusedFra // 3-fragment Allocation WddmAllocation *allocationTriple = (WddmAllocation *)memoryManager->allocateGraphicsMemory(8196, ptr); // whole allocation unused since previous trim - allocationTriple->getResidencyData().updateCompletionData(0, osContext); + allocationTriple->getResidencyData().updateCompletionData(0, osContext->getContextId()); EXPECT_EQ(3u, allocationTriple->fragmentsStorage.fragmentCount); - allocationTriple->fragmentsStorage.fragmentStorageData[0].residency->updateCompletionData(0, osContext); + allocationTriple->fragmentsStorage.fragmentStorageData[0].residency->updateCompletionData(0, osContext->getContextId()); allocationTriple->fragmentsStorage.fragmentStorageData[0].residency->resident = true; // this fragment was used - allocationTriple->fragmentsStorage.fragmentStorageData[1].residency->updateCompletionData(11, osContext); + allocationTriple->fragmentsStorage.fragmentStorageData[1].residency->updateCompletionData(11, osContext->getContextId()); allocationTriple->fragmentsStorage.fragmentStorageData[0].residency->resident = true; - allocationTriple->fragmentsStorage.fragmentStorageData[2].residency->updateCompletionData(0, osContext); + allocationTriple->fragmentsStorage.fragmentStorageData[2].residency->updateCompletionData(0, osContext->getContextId()); allocationTriple->fragmentsStorage.fragmentStorageData[2].residency->resident = true; // Set last periodic fence value @@ -1122,12 +1122,12 @@ TEST_F(WddmMemoryManagerResidencyTest, trimToBudgetAllDoneAllocations) { MockWddmAllocation allocation1, allocation2, allocation3; allocation1.getResidencyData().resident = true; - allocation1.getResidencyData().updateCompletionData(0, osContext); + allocation1.getResidencyData().updateCompletionData(0, osContext->getContextId()); - allocation2.getResidencyData().updateCompletionData(1, osContext); + allocation2.getResidencyData().updateCompletionData(1, osContext->getContextId()); allocation2.getResidencyData().resident = true; - allocation3.getResidencyData().updateCompletionData(2, osContext); + allocation3.getResidencyData().updateCompletionData(2, osContext->getContextId()); allocation3.getResidencyData().resident = true; *osContext->get()->getMonitoredFence().cpuAddress = 1; @@ -1159,7 +1159,7 @@ TEST_F(WddmMemoryManagerResidencyTest, trimToBudgetReturnsFalseWhenNumBytesToTri MockWddmAllocation allocation1; allocation1.getResidencyData().resident = true; - allocation1.getResidencyData().updateCompletionData(0, osContext); + allocation1.getResidencyData().updateCompletionData(0, osContext->getContextId()); *osContext->get()->getMonitoredFence().cpuAddress = 1; osContext->get()->getMonitoredFence().lastSubmittedFence = 1; @@ -1182,12 +1182,12 @@ TEST_F(WddmMemoryManagerResidencyTest, trimToBudgetStopsEvictingWhenNumBytesToTr allocation3(reinterpret_cast(0x1000), 0x1000, reinterpret_cast(0x1000), 0x1000, nullptr, MemoryPool::MemoryNull, memoryManager->getOsContextCount()); allocation1.getResidencyData().resident = true; - allocation1.getResidencyData().updateCompletionData(0, osContext); + allocation1.getResidencyData().updateCompletionData(0, osContext->getContextId()); - allocation2.getResidencyData().updateCompletionData(1, osContext); + allocation2.getResidencyData().updateCompletionData(1, osContext->getContextId()); allocation2.getResidencyData().resident = true; - allocation3.getResidencyData().updateCompletionData(2, osContext); + allocation3.getResidencyData().updateCompletionData(2, osContext->getContextId()); allocation3.getResidencyData().resident = true; *osContext->get()->getMonitoredFence().cpuAddress = 1; @@ -1217,12 +1217,12 @@ TEST_F(WddmMemoryManagerResidencyTest, trimToBudgetMarksEvictedAllocationNonResi MockWddmAllocation allocation1, allocation2, allocation3; allocation1.getResidencyData().resident = true; - allocation1.getResidencyData().updateCompletionData(0, osContext); + allocation1.getResidencyData().updateCompletionData(0, osContext->getContextId()); - allocation2.getResidencyData().updateCompletionData(1, osContext); + allocation2.getResidencyData().updateCompletionData(1, osContext->getContextId()); allocation2.getResidencyData().resident = true; - allocation3.getResidencyData().updateCompletionData(2, osContext); + allocation3.getResidencyData().updateCompletionData(2, osContext->getContextId()); allocation3.getResidencyData().resident = true; *osContext->get()->getMonitoredFence().cpuAddress = 1; @@ -1248,7 +1248,7 @@ TEST_F(WddmMemoryManagerResidencyTest, trimToBudgetWaitsFromCpuWhenLastFenceIsGr MockWddmAllocation allocation1; allocation1.getResidencyData().resident = true; - allocation1.getResidencyData().updateCompletionData(2, osContext); + allocation1.getResidencyData().updateCompletionData(2, osContext->getContextId()); *osContext->get()->getMonitoredFence().cpuAddress = 1; osContext->get()->getMonitoredFence().lastSubmittedFence = 2; @@ -1276,26 +1276,26 @@ TEST_F(WddmMemoryManagerResidencyTest, trimToBudgetEvictsDoneFragmentsOnly) { WddmAllocation allocation2(ptr, 0x1000, ptr, 0x1000, nullptr, MemoryPool::MemoryNull, memoryManager->getOsContextCount()); allocation1.getResidencyData().resident = true; - allocation1.getResidencyData().updateCompletionData(0, osContext); + allocation1.getResidencyData().updateCompletionData(0, osContext->getContextId()); - allocation2.getResidencyData().updateCompletionData(1, osContext); + allocation2.getResidencyData().updateCompletionData(1, osContext->getContextId()); allocation2.getResidencyData().resident = true; void *ptrTriple = reinterpret_cast(reinterpret_cast(ptr) + 0x500); WddmAllocation *allocationTriple = static_cast(memoryManager->allocateGraphicsMemory(8196, ptrTriple)); - allocationTriple->getResidencyData().updateCompletionData(1, osContext); + allocationTriple->getResidencyData().updateCompletionData(1, osContext->getContextId()); allocationTriple->getResidencyData().resident = true; EXPECT_EQ(3u, allocationTriple->fragmentsStorage.fragmentCount); for (uint32_t i = 0; i < 3; i++) { - allocationTriple->fragmentsStorage.fragmentStorageData[i].residency->updateCompletionData(1, osContext); + allocationTriple->fragmentsStorage.fragmentStorageData[i].residency->updateCompletionData(1, osContext->getContextId()); allocationTriple->fragmentsStorage.fragmentStorageData[i].residency->resident = true; } // This should not be evicted - allocationTriple->fragmentsStorage.fragmentStorageData[1].residency->updateCompletionData(2, osContext); + allocationTriple->fragmentsStorage.fragmentStorageData[1].residency->updateCompletionData(2, osContext->getContextId()); osContext->get()->getResidencyController().addToTrimCandidateList(&allocation1); osContext->get()->getResidencyController().addToTrimCandidateList(allocationTriple); @@ -1336,12 +1336,12 @@ TEST_F(WddmMemoryManagerResidencyTest, givenThreeAllocationsAlignedSizeBiggerTha WddmAllocation allocation3(ptr3, underlyingSize, ptr3, alignedSize, nullptr, MemoryPool::MemoryNull, memoryManager->getOsContextCount()); allocation1.getResidencyData().resident = true; - allocation1.getResidencyData().updateCompletionData(0, osContext); + allocation1.getResidencyData().updateCompletionData(0, osContext->getContextId()); - allocation2.getResidencyData().updateCompletionData(1, osContext); + allocation2.getResidencyData().updateCompletionData(1, osContext->getContextId()); allocation2.getResidencyData().resident = true; - allocation3.getResidencyData().updateCompletionData(1, osContext); + allocation3.getResidencyData().updateCompletionData(1, osContext->getContextId()); allocation3.getResidencyData().resident = true; *osContext->get()->getMonitoredFence().cpuAddress = 1; @@ -1624,7 +1624,7 @@ TEST_F(WddmMemoryManagerTest2, makeResidentResidencyAllocationsSucceedsWhenMakeR size_t allocationSize = 0x1000; WddmAllocation allocationToTrim(cpuPtr, allocationSize, cpuPtr, allocationSize, nullptr, MemoryPool::MemoryNull, memoryManager->getOsContextCount()); - allocationToTrim.getResidencyData().updateCompletionData(osContext->get()->getMonitoredFence().lastSubmittedFence, osContext); + allocationToTrim.getResidencyData().updateCompletionData(osContext->get()->getMonitoredFence().lastSubmittedFence, osContext->getContextId()); auto makeResidentWithOutBytesToTrim = [allocationSize](D3DKMT_HANDLE *handles, uint32_t count, bool cantTrimFurther, uint64_t *numberOfBytesToTrim) -> bool { *numberOfBytesToTrim = allocationSize; return false; };