diff --git a/runtime/memory_manager/memory_manager.cpp b/runtime/memory_manager/memory_manager.cpp index e96953a26f..3ca3532d87 100644 --- a/runtime/memory_manager/memory_manager.cpp +++ b/runtime/memory_manager/memory_manager.cpp @@ -260,8 +260,6 @@ bool MemoryManager::getAllocationData(AllocationData &allocationData, const Allo case GraphicsAllocation::AllocationType::LINEAR_STREAM: case GraphicsAllocation::AllocationType::FILL_PATTERN: case GraphicsAllocation::AllocationType::TIMESTAMP_TAG_BUFFER: - case GraphicsAllocation::AllocationType::KERNEL_ISA: - case GraphicsAllocation::AllocationType::INTERNAL_HEAP: allocationData.flags.useSystemMemory = true; break; default: diff --git a/runtime/os_interface/windows/wddm/wddm.cpp b/runtime/os_interface/windows/wddm/wddm.cpp index 27b666ae0e..f5fc5c75e9 100644 --- a/runtime/os_interface/windows/wddm/wddm.cpp +++ b/runtime/os_interface/windows/wddm/wddm.cpp @@ -999,7 +999,7 @@ std::unique_lock Wddm::acquireLock(SpinLock &lock) { HeapIndex Wddm::selectHeap(const WddmAllocation *allocation, const void *ptr) const { if (allocation) { if (allocation->origin == AllocationOrigin::INTERNAL_ALLOCATION) { - return HeapIndex::HEAP_INTERNAL; + return HeapIndex::HEAP_INTERNAL_DEVICE_MEMORY; } else if (allocation->is32BitAllocation) { return HeapIndex::HEAP_EXTERNAL; } diff --git a/runtime/os_interface/windows/wddm_allocation.h b/runtime/os_interface/windows/wddm_allocation.h index 8f5729b0e4..90234bd4e5 100644 --- a/runtime/os_interface/windows/wddm_allocation.h +++ b/runtime/os_interface/windows/wddm_allocation.h @@ -80,6 +80,7 @@ class WddmAllocation : public GraphicsAllocation { this->reservedAddressSpace = reserveMem; } void setGpuAddress(uint64_t graphicsAddress) { this->gpuAddress = graphicsAddress; } + void setCpuAddress(void *cpuPtr) { this->cpuPtr = cpuPtr; } bool needsMakeResidentBeforeLock = false; AllocationOrigin origin = AllocationOrigin::EXTERNAL_ALLOCATION; diff --git a/runtime/os_interface/windows/wddm_memory_manager.cpp b/runtime/os_interface/windows/wddm_memory_manager.cpp index 0b8566e811..99153dc4fa 100644 --- a/runtime/os_interface/windows/wddm_memory_manager.cpp +++ b/runtime/os_interface/windows/wddm_memory_manager.cpp @@ -203,7 +203,7 @@ GraphicsAllocation *WddmMemoryManager::allocate32BitGraphicsMemoryImpl(const All } wddmAllocation->is32BitAllocation = true; - auto baseAddress = allocationData.allocationOrigin == AllocationOrigin::EXTERNAL_ALLOCATION ? allocator32Bit->getBase() : this->wddm->getGfxPartition().Heap32[1].Base; + auto baseAddress = allocationData.allocationOrigin == AllocationOrigin::EXTERNAL_ALLOCATION ? allocator32Bit->getBase() : getInternalHeapBaseAddress(); wddmAllocation->gpuBaseAddress = GmmHelper::canonize(baseAddress); DebugManager.logAllocation(wddmAllocation.get()); @@ -450,7 +450,7 @@ uint64_t WddmMemoryManager::getMaxApplicationAddress() { } uint64_t WddmMemoryManager::getInternalHeapBaseAddress() { - return this->wddm->getGfxPartition().Heap32[1].Base; + return this->wddm->getGfxPartition().Heap32[static_cast(HeapIndex::HEAP_INTERNAL_DEVICE_MEMORY)].Base; } bool WddmMemoryManager::mapAuxGpuVA(GraphicsAllocation *graphicsAllocation) { diff --git a/unit_tests/memory_manager/memory_manager_allocate_in_preferred_pool_tests.inl b/unit_tests/memory_manager/memory_manager_allocate_in_preferred_pool_tests.inl index f0d72016e9..b5d16604f2 100644 --- a/unit_tests/memory_manager/memory_manager_allocate_in_preferred_pool_tests.inl +++ b/unit_tests/memory_manager/memory_manager_allocate_in_preferred_pool_tests.inl @@ -412,3 +412,24 @@ TEST(MemoryManagerTest, givenAllocationPropertiesWithMultiOsContextCapableFlagDi EXPECT_FALSE(allocation->isMultiOsContextCapable()); memoryManager.freeGraphicsMemory(allocation); } + +TEST(MemoryManagerTest, givenInternalHeapTypeWhenGetAllocationDataIsCalledThenInternalAllocationIsRequested) { + AllocationData allocData; + MockMemoryManager::getAllocationData(allocData, {1, GraphicsAllocation::AllocationType::INTERNAL_HEAP}, 0, nullptr); + EXPECT_EQ(AllocationOrigin::INTERNAL_ALLOCATION, allocData.allocationOrigin); +} +TEST(MemoryManagerTest, givenInternalHeapTypeWhenGetAllocationDataIsCalledThenSystemMemoryIsNotRequested) { + AllocationData allocData; + MockMemoryManager::getAllocationData(allocData, {1, GraphicsAllocation::AllocationType::INTERNAL_HEAP}, 0, nullptr); + EXPECT_FALSE(allocData.flags.useSystemMemory); +} +TEST(MemoryManagerTest, givenKernelIsaTypeWhenGetAllocationDataIsCalledThenSystemMemoryIsNotRequested) { + AllocationData allocData; + MockMemoryManager::getAllocationData(allocData, {1, GraphicsAllocation::AllocationType::KERNEL_ISA}, 0, nullptr); + EXPECT_FALSE(allocData.flags.useSystemMemory); +} +TEST(MemoryManagerTest, givenKernelIsaTypeWhenGetAllocationDataIsCalledThenInternalAllocationIsRequested) { + AllocationData allocData; + MockMemoryManager::getAllocationData(allocData, {1, GraphicsAllocation::AllocationType::KERNEL_ISA}, 0, nullptr); + EXPECT_EQ(AllocationOrigin::INTERNAL_ALLOCATION, allocData.allocationOrigin); +} \ No newline at end of file diff --git a/unit_tests/os_interface/windows/wddm20_tests.cpp b/unit_tests/os_interface/windows/wddm20_tests.cpp index 532c442a69..858f91b1c2 100644 --- a/unit_tests/os_interface/windows/wddm20_tests.cpp +++ b/unit_tests/os_interface/windows/wddm20_tests.cpp @@ -267,7 +267,7 @@ TEST_F(Wddm20Tests, createAllocation32bit) { delete gmm; } -TEST_F(Wddm20Tests, givenGraphicsAllocationWhenItIsMappedInHeap1ThenItHasGpuAddressWithingHeap1Limits) { +TEST_F(Wddm20Tests, givenGraphicsAllocationWhenItIsMappedInHeap0ThenItHasGpuAddressWithingHeap0Limits) { void *alignedPtr = (void *)0x12000; size_t alignedSize = 0x2000; WddmAllocation allocation(alignedPtr, alignedSize, nullptr, MemoryPool::MemoryNull, 1u, false); @@ -275,12 +275,13 @@ TEST_F(Wddm20Tests, givenGraphicsAllocationWhenItIsMappedInHeap1ThenItHasGpuAddr allocation.handle = ALLOCATION_HANDLE; allocation.gmm = GmmHelperFunctions::getGmm(allocation.getUnderlyingBuffer(), allocation.getUnderlyingBufferSize()); allocation.origin = AllocationOrigin::INTERNAL_ALLOCATION; - EXPECT_EQ(HeapIndex::HEAP_INTERNAL, wddm->selectHeap(&allocation, allocation.getAlignedCpuPtr())); + EXPECT_EQ(HeapIndex::HEAP_INTERNAL_DEVICE_MEMORY, wddm->selectHeap(&allocation, allocation.getAlignedCpuPtr())); bool ret = wddm->mapGpuVirtualAddress(&allocation, allocation.getAlignedCpuPtr()); EXPECT_TRUE(ret); - auto cannonizedHeapBase = GmmHelper::canonize(this->wddm->getGfxPartition().Heap32[1].Base); - auto cannonizedHeapEnd = GmmHelper::canonize(this->wddm->getGfxPartition().Heap32[1].Limit); + uint32_t heapIndex = static_cast(HeapIndex::HEAP_INTERNAL_DEVICE_MEMORY); + auto cannonizedHeapBase = GmmHelper::canonize(this->wddm->getGfxPartition().Heap32[heapIndex].Base); + auto cannonizedHeapEnd = GmmHelper::canonize(this->wddm->getGfxPartition().Heap32[heapIndex].Limit); EXPECT_GE(allocation.gpuPtr, cannonizedHeapBase); EXPECT_LE(allocation.gpuPtr, cannonizedHeapEnd); @@ -1000,17 +1001,17 @@ TEST_F(Wddm20Tests, whenEvictingTemporaryResourceThenOtherResourcesRemainOnTheLi using WddmHeapSelectorTest = Wddm20Tests; -TEST_F(WddmHeapSelectorTest, given32bitInternalAllocationWhenSelectingHeapThenInternalHeapIsUsed) { +TEST_F(WddmHeapSelectorTest, given32bitInternalAllocationWhenSelectingHeapThenInternalDeviceMemoryHeapIsUsed) { WddmAllocation allocation{nullptr, 0, nullptr, MemoryPool::MemoryNull, 1u, false}; allocation.is32BitAllocation = true; allocation.origin = AllocationOrigin::INTERNAL_ALLOCATION; - EXPECT_EQ(HeapIndex::HEAP_INTERNAL, wddm->selectHeap(&allocation, nullptr)); + EXPECT_EQ(HeapIndex::HEAP_INTERNAL_DEVICE_MEMORY, wddm->selectHeap(&allocation, nullptr)); } -TEST_F(WddmHeapSelectorTest, givenNon32bitInternalAllocationWhenSelectingHeapThenInternalHeapIsUsed) { +TEST_F(WddmHeapSelectorTest, givenNon32bitInternalAllocationWhenSelectingHeapThenInternalDeviceMemoryHeapIsUsed) { WddmAllocation allocation{nullptr, 0, nullptr, MemoryPool::MemoryNull, 1u, false}; allocation.is32BitAllocation = false; allocation.origin = AllocationOrigin::INTERNAL_ALLOCATION; - EXPECT_EQ(HeapIndex::HEAP_INTERNAL, wddm->selectHeap(&allocation, nullptr)); + EXPECT_EQ(HeapIndex::HEAP_INTERNAL_DEVICE_MEMORY, wddm->selectHeap(&allocation, nullptr)); } TEST_F(WddmHeapSelectorTest, given32bitExternalAllocationWhenSelectingHeapThenExternalHeapIsUsed) { WddmAllocation allocation{nullptr, 0, nullptr, MemoryPool::MemoryNull, 1u, false}; 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 61245ed1db..3b3df429c5 100644 --- a/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp @@ -868,12 +868,12 @@ TEST_F(WddmMemoryManagerTest, givenManagerWithEnabledDeferredDeleterWhenFirstAnd TEST_F(WddmMemoryManagerTest, givenNullPtrAndSizePassedToCreateInternalAllocationWhenCallIsMadeThenAllocationIsCreatedIn32BitHeap1) { auto wddmAllocation = static_cast(memoryManager->allocate32BitGraphicsMemory(MemoryConstants::pageSize, nullptr, AllocationOrigin::INTERNAL_ALLOCATION)); ASSERT_NE(nullptr, wddmAllocation); - EXPECT_EQ(wddmAllocation->gpuBaseAddress, GmmHelper::canonize(this->wddm->getGfxPartition().Heap32[1].Base)); + EXPECT_EQ(wddmAllocation->gpuBaseAddress, GmmHelper::canonize(memoryManager->getInternalHeapBaseAddress())); EXPECT_NE(nullptr, wddmAllocation->getUnderlyingBuffer()); EXPECT_EQ(4096u, wddmAllocation->getUnderlyingBufferSize()); EXPECT_NE((uint64_t)wddmAllocation->getUnderlyingBuffer(), wddmAllocation->getGpuAddress()); - auto cannonizedHeapBase = GmmHelper::canonize(this->wddm->getGfxPartition().Heap32[1].Base); - auto cannonizedHeapEnd = GmmHelper::canonize(this->wddm->getGfxPartition().Heap32[1].Limit); + auto cannonizedHeapBase = GmmHelper::canonize(memoryManager->getInternalHeapBaseAddress()); + auto cannonizedHeapEnd = GmmHelper::canonize(this->wddm->getGfxPartition().Heap32[static_cast(HeapIndex::HEAP_INTERNAL_DEVICE_MEMORY)].Limit); EXPECT_GE(wddmAllocation->getGpuAddress(), cannonizedHeapBase); EXPECT_LE(wddmAllocation->getGpuAddress(), cannonizedHeapEnd); @@ -883,16 +883,16 @@ TEST_F(WddmMemoryManagerTest, givenNullPtrAndSizePassedToCreateInternalAllocatio memoryManager->freeGraphicsMemory(wddmAllocation); } -TEST_F(WddmMemoryManagerTest, givenPtrAndSizePassedToCreateInternalAllocationWhenCallIsMadeThenAllocationIsCreatedIn32BitHeap1) { +TEST_F(WddmMemoryManagerTest, givenPtrAndSizePassedToCreateInternalAllocationWhenCallIsMadeThenAllocationIsCreatedIn32BitHeapInternal) { auto ptr = reinterpret_cast(0x1000000); auto wddmAllocation = static_cast(memoryManager->allocate32BitGraphicsMemory(MemoryConstants::pageSize, ptr, AllocationOrigin::INTERNAL_ALLOCATION)); ASSERT_NE(nullptr, wddmAllocation); - EXPECT_EQ(wddmAllocation->gpuBaseAddress, GmmHelper::canonize(this->wddm->getGfxPartition().Heap32[1].Base)); + EXPECT_EQ(wddmAllocation->gpuBaseAddress, GmmHelper::canonize(memoryManager->getInternalHeapBaseAddress())); EXPECT_EQ(ptr, wddmAllocation->getUnderlyingBuffer()); EXPECT_EQ(4096u, wddmAllocation->getUnderlyingBufferSize()); EXPECT_NE((uint64_t)wddmAllocation->getUnderlyingBuffer(), wddmAllocation->getGpuAddress()); - auto cannonizedHeapBase = GmmHelper::canonize(this->wddm->getGfxPartition().Heap32[1].Base); - auto cannonizedHeapEnd = GmmHelper::canonize(this->wddm->getGfxPartition().Heap32[1].Limit); + auto cannonizedHeapBase = GmmHelper::canonize(memoryManager->getInternalHeapBaseAddress()); + auto cannonizedHeapEnd = GmmHelper::canonize(wddm->getGfxPartition().Heap32[static_cast(HeapIndex::HEAP_INTERNAL_DEVICE_MEMORY)].Limit); EXPECT_GE(wddmAllocation->getGpuAddress(), cannonizedHeapBase); EXPECT_LE(wddmAllocation->getGpuAddress(), cannonizedHeapEnd);