diff --git a/level_zero/core/source/context/context_imp.cpp b/level_zero/core/source/context/context_imp.cpp index 7b5ecdf96e..5acd8231f7 100644 --- a/level_zero/core/source/context/context_imp.cpp +++ b/level_zero/core/source/context/context_imp.cpp @@ -798,13 +798,7 @@ ze_result_t ContextImp::reserveVirtualMem(const void *pStart, return ZE_RESULT_ERROR_UNSUPPORTED_SIZE; } NEO::VirtualMemoryReservation *virtualMemoryReservation = new NEO::VirtualMemoryReservation; - virtualMemoryReservation->virtualAddressRange = this->driverHandle->getMemoryManager()->reserveGpuAddress(pStart, size, this->driverHandle->rootDeviceIndices, &virtualMemoryReservation->rootDeviceIndex); - if (pStart != 0x0) { - if (virtualMemoryReservation->virtualAddressRange.address != reinterpret_cast(pStart)) { - delete virtualMemoryReservation; - return ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY; - } - } + virtualMemoryReservation->virtualAddressRange = this->driverHandle->getMemoryManager()->reserveGpuAddress(reinterpret_cast(pStart), size, this->driverHandle->rootDeviceIndices, &virtualMemoryReservation->rootDeviceIndex); if (virtualMemoryReservation->virtualAddressRange.address == 0) { delete virtualMemoryReservation; return ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY; diff --git a/level_zero/core/test/unit_tests/fixtures/memory_ipc_fixture.h b/level_zero/core/test/unit_tests/fixtures/memory_ipc_fixture.h index cbf2715fff..57605a479f 100644 --- a/level_zero/core/test/unit_tests/fixtures/memory_ipc_fixture.h +++ b/level_zero/core/test/unit_tests/fixtures/memory_ipc_fixture.h @@ -408,7 +408,7 @@ class MemoryManagerIpcMock : public NEO::MemoryManager { uint64_t getSystemSharedMemory(uint32_t rootDeviceIndex) override { return 0; }; uint64_t getLocalMemorySize(uint32_t rootDeviceIndex, uint32_t deviceBitfield) override { return 0; }; double getPercentOfGlobalMemoryAvailable(uint32_t rootDeviceIndex) override { return 0; } - AddressRange reserveGpuAddress(const void *requiredStartAddress, size_t size, RootDeviceIndicesContainer rootDeviceIndices, uint32_t *reservedOnRootDeviceIndex) override { + AddressRange reserveGpuAddress(const uint64_t requiredStartAddress, size_t size, RootDeviceIndicesContainer rootDeviceIndices, uint32_t *reservedOnRootDeviceIndex) override { return {}; } void freeGpuAddress(AddressRange addressRange, uint32_t rootDeviceIndex) override{}; @@ -628,7 +628,7 @@ class MemoryManagerIpcImplicitScalingMock : public NEO::MemoryManager { uint64_t getSystemSharedMemory(uint32_t rootDeviceIndex) override { return 0; }; uint64_t getLocalMemorySize(uint32_t rootDeviceIndex, uint32_t deviceBitfield) override { return 0; }; double getPercentOfGlobalMemoryAvailable(uint32_t rootDeviceIndex) override { return 0; } - AddressRange reserveGpuAddress(const void *requiredStartAddress, size_t size, RootDeviceIndicesContainer rootDeviceIndices, uint32_t *reservedOnRootDeviceIndex) override { + AddressRange reserveGpuAddress(const uint64_t requiredStartAddress, size_t size, RootDeviceIndicesContainer rootDeviceIndices, uint32_t *reservedOnRootDeviceIndex) override { return {}; } void freeGpuAddress(AddressRange addressRange, uint32_t rootDeviceIndex) override{}; diff --git a/level_zero/core/test/unit_tests/sources/context/test_context.cpp b/level_zero/core/test/unit_tests/sources/context/test_context.cpp index b95197fcc7..6520793697 100644 --- a/level_zero/core/test/unit_tests/sources/context/test_context.cpp +++ b/level_zero/core/test/unit_tests/sources/context/test_context.cpp @@ -1241,9 +1241,6 @@ TEST_F(ContextTest, whenCallingVirtualMemoryReservationWithInvalidArgumentsThenF size_t pagesize = 0u; res = contextImp->queryVirtualMemPageSize(device, size, &pagesize); EXPECT_EQ(ZE_RESULT_SUCCESS, res); - pStart = reinterpret_cast(0x1234); - res = contextImp->reserveVirtualMem(pStart, pagesize, &ptr); - EXPECT_EQ(ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY, res); res = contextImp->destroy(); EXPECT_EQ(ZE_RESULT_SUCCESS, res); @@ -1264,11 +1261,11 @@ class ReserveMemoryManagerMock : public NEO::MemoryManager { uint64_t getSystemSharedMemory(uint32_t rootDeviceIndex) override { return 0; }; uint64_t getLocalMemorySize(uint32_t rootDeviceIndex, uint32_t deviceBitfield) override { return 0; }; double getPercentOfGlobalMemoryAvailable(uint32_t rootDeviceIndex) override { return 0; } - AddressRange reserveGpuAddress(const void *requiredStartAddress, size_t size, RootDeviceIndicesContainer rootDeviceIndices, uint32_t *reservedOnRootDeviceIndex) override { + AddressRange reserveGpuAddress(const uint64_t requiredStartAddress, size_t size, RootDeviceIndicesContainer rootDeviceIndices, uint32_t *reservedOnRootDeviceIndex) override { if (failReserveGpuAddress) { return {}; } - return AddressRange{reinterpret_cast(requiredStartAddress), size}; + return AddressRange{requiredStartAddress, size}; } void freeGpuAddress(AddressRange addressRange, uint32_t rootDeviceIndex) override{}; NEO::GraphicsAllocation *createGraphicsAllocation(OsHandleStorage &handleStorage, const NEO::AllocationData &allocationData) override { return nullptr; }; diff --git a/level_zero/core/test/unit_tests/sources/event/test_event.cpp b/level_zero/core/test/unit_tests/sources/event/test_event.cpp index e85b9a8835..f4b1c8b194 100644 --- a/level_zero/core/test/unit_tests/sources/event/test_event.cpp +++ b/level_zero/core/test/unit_tests/sources/event/test_event.cpp @@ -71,7 +71,7 @@ class MemoryManagerEventPoolFailMock : public NEO::MemoryManager { uint64_t getSystemSharedMemory(uint32_t rootDeviceIndex) override { return 0; }; uint64_t getLocalMemorySize(uint32_t rootDeviceIndex, uint32_t deviceBitfield) override { return 0; }; double getPercentOfGlobalMemoryAvailable(uint32_t rootDeviceIndex) override { return 0; } - AddressRange reserveGpuAddress(const void *requiredStartAddress, size_t size, RootDeviceIndicesContainer rootDeviceIndices, uint32_t *reservedOnRootDeviceIndex) override { + AddressRange reserveGpuAddress(const uint64_t requiredStartAddress, size_t size, RootDeviceIndicesContainer rootDeviceIndices, uint32_t *reservedOnRootDeviceIndex) override { return {}; } void freeGpuAddress(AddressRange addressRange, uint32_t rootDeviceIndex) override{}; diff --git a/level_zero/core/test/unit_tests/sources/memory/linux/test_memory_linux.cpp b/level_zero/core/test/unit_tests/sources/memory/linux/test_memory_linux.cpp index 2769bd54b9..9046ab6f89 100644 --- a/level_zero/core/test/unit_tests/sources/memory/linux/test_memory_linux.cpp +++ b/level_zero/core/test/unit_tests/sources/memory/linux/test_memory_linux.cpp @@ -71,7 +71,7 @@ class MemoryManagerIpcImplicitScalingObtainFdMock : public NEO::DrmMemoryManager uint64_t getSystemSharedMemory(uint32_t rootDeviceIndex) override { return 0; }; uint64_t getLocalMemorySize(uint32_t rootDeviceIndex, uint32_t deviceBitfield) override { return 0; }; double getPercentOfGlobalMemoryAvailable(uint32_t rootDeviceIndex) override { return 0; } - AddressRange reserveGpuAddress(const void *requiredStartAddress, size_t size, RootDeviceIndicesContainer rootDeviceIndices, uint32_t *reservedOnRootDeviceIndex) override { + AddressRange reserveGpuAddress(const uint64_t requiredStartAddress, size_t size, RootDeviceIndicesContainer rootDeviceIndices, uint32_t *reservedOnRootDeviceIndex) override { return {}; } void freeGpuAddress(AddressRange addressRange, uint32_t rootDeviceIndex) override{}; @@ -499,7 +499,7 @@ class MemoryManagerIpcObtainFdMock : public NEO::DrmMemoryManager { uint64_t getSystemSharedMemory(uint32_t rootDeviceIndex) override { return 0; }; uint64_t getLocalMemorySize(uint32_t rootDeviceIndex, uint32_t deviceBitfield) override { return 0; }; double getPercentOfGlobalMemoryAvailable(uint32_t rootDeviceIndex) override { return 0; } - AddressRange reserveGpuAddress(const void *requiredStartAddress, size_t size, RootDeviceIndicesContainer rootDeviceIndices, uint32_t *reservedOnRootDeviceIndex) override { + AddressRange reserveGpuAddress(const uint64_t requiredStartAddress, size_t size, RootDeviceIndicesContainer rootDeviceIndices, uint32_t *reservedOnRootDeviceIndex) override { return {}; } void freeGpuAddress(AddressRange addressRange, uint32_t rootDeviceIndex) override{}; diff --git a/opencl/test/unit_test/memory_manager/memory_manager_tests.cpp b/opencl/test/unit_test/memory_manager/memory_manager_tests.cpp index 28d18c14bd..d60818c7dd 100644 --- a/opencl/test/unit_test/memory_manager/memory_manager_tests.cpp +++ b/opencl/test/unit_test/memory_manager/memory_manager_tests.cpp @@ -1592,61 +1592,6 @@ TEST(OsAgnosticMemoryManager, givenOsAgnosticMemoryManagerAndFreeMemoryDisabledW EXPECT_FALSE(mockManager->freeMemoryCalled); } -TEST(OsAgnosticMemoryManager, givenOsAgnosticMemoryManagerWhenGpuAddressIsReservedAndFreedThenAddressFromGfxPartitionIsUsed) { - MockExecutionEnvironment executionEnvironment; - OsAgnosticMemoryManager memoryManager(executionEnvironment); - RootDeviceIndicesContainer rootDevices; - rootDevices.push_back(0); - uint32_t rootDeviceIndexReserved = 10; - auto addressRange = memoryManager.reserveGpuAddress(nullptr, MemoryConstants::pageSize, rootDevices, &rootDeviceIndexReserved); - auto gmmHelper = memoryManager.getGmmHelper(0); - EXPECT_EQ(0u, rootDeviceIndexReserved); - EXPECT_LE(memoryManager.getGfxPartition(0)->getHeapBase(HeapIndex::HEAP_STANDARD), gmmHelper->decanonize(addressRange.address)); - EXPECT_GT(memoryManager.getGfxPartition(0)->getHeapLimit(HeapIndex::HEAP_STANDARD), gmmHelper->decanonize(addressRange.address)); - - memoryManager.freeGpuAddress(addressRange, 0); -} - -TEST(OsAgnosticMemoryManager, givenOsAgnosticMemoryManagerWhenGpuAddressIsReservedOnIndex1AndFreedThenAddressFromGfxPartitionIsUsed) { - MockExecutionEnvironment executionEnvironment(defaultHwInfo.get(), true, 2u); - OsAgnosticMemoryManager memoryManager(executionEnvironment); - RootDeviceIndicesContainer rootDevices; - rootDevices.push_back(1); - uint32_t rootDeviceIndexReserved = 10; - auto addressRange = memoryManager.reserveGpuAddress(nullptr, MemoryConstants::pageSize, rootDevices, &rootDeviceIndexReserved); - auto gmmHelper = memoryManager.getGmmHelper(1); - EXPECT_EQ(1u, rootDeviceIndexReserved); - EXPECT_LE(memoryManager.getGfxPartition(1)->getHeapBase(HeapIndex::HEAP_STANDARD), gmmHelper->decanonize(addressRange.address)); - EXPECT_GT(memoryManager.getGfxPartition(1)->getHeapLimit(HeapIndex::HEAP_STANDARD), gmmHelper->decanonize(addressRange.address)); - - memoryManager.freeGpuAddress(addressRange, 1); -} - -TEST(OsAgnosticMemoryManager, givenOsAgnosticMemoryManagerWhenGpuAddressReservationIsAttemptedWihtInvalidSizeThenFailureReturnsNullAddressRange) { - MockExecutionEnvironment executionEnvironment; - OsAgnosticMemoryManager memoryManager(executionEnvironment); - RootDeviceIndicesContainer rootDevices; - rootDevices.push_back(0); - uint32_t rootDeviceIndexReserved = 10; - // emulate GPU address space exhaust - memoryManager.getGfxPartition(0)->heapInit(HeapIndex::HEAP_STANDARD, 0x0, 0x10000); - auto addressRange = memoryManager.reserveGpuAddress(nullptr, (size_t)(memoryManager.getGfxPartition(0)->getHeapLimit(HeapIndex::HEAP_STANDARD) * 2), rootDevices, &rootDeviceIndexReserved); - EXPECT_EQ(static_cast(addressRange.address), 0); -} - -TEST(OsAgnosticMemoryManager, givenOsAgnosticMemoryManagerWhenGpuAddressReservationIsAttemptedWithARequiredPtrThenNullRangeReturned) { - MockExecutionEnvironment executionEnvironment; - OsAgnosticMemoryManager memoryManager(executionEnvironment); - RootDeviceIndicesContainer rootDevices; - rootDevices.push_back(0); - uint32_t rootDeviceIndexReserved = 10; - void *requiredPtr = reinterpret_cast(0x1234); - auto addressRange = memoryManager.reserveGpuAddress(requiredPtr, MemoryConstants::pageSize, rootDevices, &rootDeviceIndexReserved); - EXPECT_EQ(0u, rootDeviceIndexReserved); - EXPECT_EQ(static_cast(addressRange.address), 0); - EXPECT_EQ(static_cast(addressRange.size), 0); -} - TEST(OsAgnosticMemoryManager, givenOsAgnosticMemoryManagerWhenCheckedForIndirectAllocationsAsPackSupportThenFalseIsReturned) { MockExecutionEnvironment executionEnvironment; OsAgnosticMemoryManager memoryManager(executionEnvironment); diff --git a/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp b/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp index d0b532537a..aeab6fff78 100644 --- a/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp +++ b/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp @@ -632,7 +632,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenWddmMemoryManagerWhenGpuAddressIsReserv RootDeviceIndicesContainer rootDevices; rootDevices.push_back(0); uint32_t rootDeviceIndexReserved = 1; - auto addressRange = memoryManager->reserveGpuAddress(nullptr, MemoryConstants::pageSize64k, rootDevices, &rootDeviceIndexReserved); + auto addressRange = memoryManager->reserveGpuAddress(0ull, MemoryConstants::pageSize64k, rootDevices, &rootDeviceIndexReserved); auto gmmHelper = memoryManager->getGmmHelper(0); EXPECT_EQ(0u, rootDeviceIndexReserved); EXPECT_NE(0u, gmmHelper->decanonize(addressRange.address)); diff --git a/shared/source/debugger/debugger_l0.cpp b/shared/source/debugger/debugger_l0.cpp index 5637fa3b28..46c1897ac6 100644 --- a/shared/source/debugger/debugger_l0.cpp +++ b/shared/source/debugger/debugger_l0.cpp @@ -56,7 +56,7 @@ void DebuggerL0::initialize() { RootDeviceIndicesContainer rootDevices; rootDevices.push_back(device->getRootDeviceIndex()); uint32_t rootDeviceIndexReserved = 0; - sbaTrackingGpuVa = device->getMemoryManager()->reserveGpuAddress(nullptr, MemoryConstants::pageSize, rootDevices, &rootDeviceIndexReserved); + sbaTrackingGpuVa = device->getMemoryManager()->reserveGpuAddress(0ull, MemoryConstants::pageSize, rootDevices, &rootDeviceIndexReserved); properties.gpuAddress = sbaTrackingGpuVa.address; } diff --git a/shared/source/memory_manager/memory_manager.h b/shared/source/memory_manager/memory_manager.h index 1fd6f80751..1f2e35c732 100644 --- a/shared/source/memory_manager/memory_manager.h +++ b/shared/source/memory_manager/memory_manager.h @@ -229,7 +229,7 @@ class MemoryManager { void *getReservedMemory(size_t size, size_t alignment); GfxPartition *getGfxPartition(uint32_t rootDeviceIndex) { return gfxPartitions.at(rootDeviceIndex).get(); } GmmHelper *getGmmHelper(uint32_t rootDeviceIndex); - virtual AddressRange reserveGpuAddress(const void *requiredStartAddress, size_t size, RootDeviceIndicesContainer rootDeviceIndices, uint32_t *reservedOnRootDeviceIndex) = 0; + virtual AddressRange reserveGpuAddress(const uint64_t requiredStartAddress, size_t size, RootDeviceIndicesContainer rootDeviceIndices, uint32_t *reservedOnRootDeviceIndex) = 0; virtual void freeGpuAddress(AddressRange addressRange, uint32_t rootDeviceIndex) = 0; static HeapIndex selectInternalHeap(bool useLocalMemory); static HeapIndex selectExternalHeap(bool useLocalMemory); diff --git a/shared/source/memory_manager/os_agnostic_memory_manager.cpp b/shared/source/memory_manager/os_agnostic_memory_manager.cpp index 5d2fdcab76..f82b609574 100644 --- a/shared/source/memory_manager/os_agnostic_memory_manager.cpp +++ b/shared/source/memory_manager/os_agnostic_memory_manager.cpp @@ -530,12 +530,9 @@ MemoryAllocation *OsAgnosticMemoryManager::createMemoryAllocation(AllocationType return memoryAllocation; } -AddressRange OsAgnosticMemoryManager::reserveGpuAddress(const void *requiredStartAddress, size_t size, RootDeviceIndicesContainer rootDeviceIndices, uint32_t *reservedOnRootDeviceIndex) { +AddressRange OsAgnosticMemoryManager::reserveGpuAddress(const uint64_t requiredStartAddress, size_t size, RootDeviceIndicesContainer rootDeviceIndices, uint32_t *reservedOnRootDeviceIndex) { uint64_t gpuVa = 0u; *reservedOnRootDeviceIndex = 0; - if (requiredStartAddress) { - return AddressRange{0, 0}; - } for (auto rootDeviceIndex : rootDeviceIndices) { auto gfxPartition = getGfxPartition(rootDeviceIndex); auto gmmHelper = getGmmHelper(rootDeviceIndex); diff --git a/shared/source/memory_manager/os_agnostic_memory_manager.h b/shared/source/memory_manager/os_agnostic_memory_manager.h index 09db98df77..0ac1c1c88d 100644 --- a/shared/source/memory_manager/os_agnostic_memory_manager.h +++ b/shared/source/memory_manager/os_agnostic_memory_manager.h @@ -44,7 +44,7 @@ class OsAgnosticMemoryManager : public MemoryManager { void *reserveCpuAddressRange(size_t size, uint32_t rootDeviceIndex) override; void releaseReservedCpuAddressRange(void *reserved, size_t size, uint32_t rootDeviceIndex) override; - AddressRange reserveGpuAddress(const void *requiredStartAddress, size_t size, RootDeviceIndicesContainer rootDeviceIndices, uint32_t *reservedOnRootDeviceIndex) override; + AddressRange reserveGpuAddress(const uint64_t requiredStartAddress, size_t size, RootDeviceIndicesContainer rootDeviceIndices, uint32_t *reservedOnRootDeviceIndex) override; void freeGpuAddress(AddressRange addressRange, uint32_t rootDeviceIndex) override; bool is64kbPagesEnabled(const HardwareInfo *hwInfo); diff --git a/shared/source/os_interface/linux/drm_memory_manager.cpp b/shared/source/os_interface/linux/drm_memory_manager.cpp index 0b4065815d..5c22e4ff52 100644 --- a/shared/source/os_interface/linux/drm_memory_manager.cpp +++ b/shared/source/os_interface/linux/drm_memory_manager.cpp @@ -1326,12 +1326,9 @@ uint32_t DrmMemoryManager::getRootDeviceIndex(const Drm *drm) { return CommonConstants::unspecifiedDeviceIndex; } -AddressRange DrmMemoryManager::reserveGpuAddress(const void *requiredStartAddress, size_t size, RootDeviceIndicesContainer rootDeviceIndices, uint32_t *reservedOnRootDeviceIndex) { +AddressRange DrmMemoryManager::reserveGpuAddress(const uint64_t requiredStartAddress, size_t size, RootDeviceIndicesContainer rootDeviceIndices, uint32_t *reservedOnRootDeviceIndex) { uint64_t gpuVa = 0u; *reservedOnRootDeviceIndex = 0; - if (requiredStartAddress) { - return AddressRange{0, 0}; - } for (auto rootDeviceIndex : rootDeviceIndices) { gpuVa = acquireGpuRange(size, rootDeviceIndex, HeapIndex::HEAP_STANDARD); if (gpuVa != 0u) { diff --git a/shared/source/os_interface/linux/drm_memory_manager.h b/shared/source/os_interface/linux/drm_memory_manager.h index 9fbbd59b60..714e90b338 100644 --- a/shared/source/os_interface/linux/drm_memory_manager.h +++ b/shared/source/os_interface/linux/drm_memory_manager.h @@ -65,7 +65,7 @@ class DrmMemoryManager : public MemoryManager { bool copyMemoryToAllocationBanks(GraphicsAllocation *graphicsAllocation, size_t destinationOffset, const void *memoryToCopy, size_t sizeToCopy, DeviceBitfield handleMask) override; MOCKABLE_VIRTUAL int obtainFdFromHandle(int boHandle, uint32_t rootDeviceindex); - AddressRange reserveGpuAddress(const void *requiredStartAddress, size_t size, RootDeviceIndicesContainer rootDeviceIndices, uint32_t *reservedOnRootDeviceIndex) override; + AddressRange reserveGpuAddress(const uint64_t requiredStartAddress, size_t size, RootDeviceIndicesContainer rootDeviceIndices, uint32_t *reservedOnRootDeviceIndex) override; void freeGpuAddress(AddressRange addressRange, uint32_t rootDeviceIndex) override; MOCKABLE_VIRTUAL BufferObject *createBufferObjectInMemoryRegion(Drm *drm, Gmm *gmm, AllocationType allocationType, uint64_t gpuAddress, size_t size, uint32_t memoryBanks, size_t maxOsContextCount, int32_t pairHandle); diff --git a/shared/source/os_interface/windows/wddm_memory_manager.cpp b/shared/source/os_interface/windows/wddm_memory_manager.cpp index 5e412150aa..2b8ce65a66 100644 --- a/shared/source/os_interface/windows/wddm_memory_manager.cpp +++ b/shared/source/os_interface/windows/wddm_memory_manager.cpp @@ -816,13 +816,13 @@ bool WddmMemoryManager::createWddmAllocation(WddmAllocation *allocation, void *r return mapGpuVirtualAddress(allocation, requiredGpuPtr); } -AddressRange WddmMemoryManager::reserveGpuAddress(const void *requiredStartAddress, size_t size, RootDeviceIndicesContainer rootDeviceIndices, uint32_t *reservedOnRootDeviceIndex) { +AddressRange WddmMemoryManager::reserveGpuAddress(const uint64_t requiredStartAddress, size_t size, RootDeviceIndicesContainer rootDeviceIndices, uint32_t *reservedOnRootDeviceIndex) { uint64_t gpuVa = 0u; *reservedOnRootDeviceIndex = 0; size_t reservedSize = 0; for (auto rootDeviceIndex : rootDeviceIndices) { auto gfxPartition = getGfxPartition(rootDeviceIndex); - gpuVa = getWddm(rootDeviceIndex).reserveGpuVirtualAddress(reinterpret_cast(requiredStartAddress), gfxPartition->getHeapMinimalAddress(HeapIndex::HEAP_STANDARD64KB), gfxPartition->getHeapLimit(HeapIndex::HEAP_STANDARD64KB), size); + gpuVa = getWddm(rootDeviceIndex).reserveGpuVirtualAddress(requiredStartAddress, gfxPartition->getHeapMinimalAddress(HeapIndex::HEAP_STANDARD64KB), gfxPartition->getHeapLimit(HeapIndex::HEAP_STANDARD64KB), size); if (gpuVa != 0u) { *reservedOnRootDeviceIndex = rootDeviceIndex; reservedSize = size; diff --git a/shared/source/os_interface/windows/wddm_memory_manager.h b/shared/source/os_interface/windows/wddm_memory_manager.h index a2b2c23376..23f5676699 100644 --- a/shared/source/os_interface/windows/wddm_memory_manager.h +++ b/shared/source/os_interface/windows/wddm_memory_manager.h @@ -69,7 +69,7 @@ class WddmMemoryManager : public MemoryManager { bool isCpuCopyRequired(const void *ptr) override; bool isWCMemory(const void *ptr) override; - AddressRange reserveGpuAddress(const void *requiredStartAddress, size_t size, RootDeviceIndicesContainer rootDeviceIndices, uint32_t *reservedOnRootDeviceIndex) override; + AddressRange reserveGpuAddress(const uint64_t requiredStartAddress, size_t size, RootDeviceIndicesContainer rootDeviceIndices, uint32_t *reservedOnRootDeviceIndex) override; void freeGpuAddress(AddressRange addressRange, uint32_t rootDeviceIndex) override; bool verifyHandle(osHandle handle, uint32_t rootDeviceIndex, bool ntHandle) override; bool isNTHandle(osHandle handle, uint32_t rootDeviceIndex) override; diff --git a/shared/test/unit_test/device/neo_device_tests.cpp b/shared/test/unit_test/device/neo_device_tests.cpp index 8470c7b280..05502ede36 100644 --- a/shared/test/unit_test/device/neo_device_tests.cpp +++ b/shared/test/unit_test/device/neo_device_tests.cpp @@ -422,7 +422,7 @@ TEST_F(DeviceGetCapsTest, givenFlagEnabled64kbPagesWhenCallConstructorMemoryMana }; uint64_t getLocalMemorySize(uint32_t rootDeviceIndex, uint32_t deviceBitfield) override { return 0; }; double getPercentOfGlobalMemoryAvailable(uint32_t rootDeviceIndex) override { return 0; } - AddressRange reserveGpuAddress(const void *requiredStartAddress, size_t size, RootDeviceIndicesContainer rootDeviceIndices, uint32_t *reservedOnRootDeviceIndex) override { + AddressRange reserveGpuAddress(const uint64_t requiredStartAddress, size_t size, RootDeviceIndicesContainer rootDeviceIndices, uint32_t *reservedOnRootDeviceIndex) override { return {}; } void freeGpuAddress(AddressRange addressRange, uint32_t rootDeviceIndex) override{}; diff --git a/shared/test/unit_test/memory_manager/memory_manager_tests.cpp b/shared/test/unit_test/memory_manager/memory_manager_tests.cpp index 23d5f2f1fb..31eac078fb 100644 --- a/shared/test/unit_test/memory_manager/memory_manager_tests.cpp +++ b/shared/test/unit_test/memory_manager/memory_manager_tests.cpp @@ -5,11 +5,13 @@ * */ +#include "shared/source/gmm_helper/gmm_helper.h" #include "shared/test/common/helpers/engine_descriptor_helper.h" #include "shared/test/common/mocks/mock_allocation_properties.h" #include "shared/test/common/mocks/mock_csr.h" #include "shared/test/common/mocks/mock_deferred_deleter.h" #include "shared/test/common/mocks/mock_device.h" +#include "shared/test/common/mocks/mock_gfx_partition.h" #include "shared/test/common/mocks/mock_graphics_allocation.h" #include "shared/test/common/mocks/mock_internal_allocation_storage.h" #include "shared/test/common/mocks/mock_memory_manager.h" @@ -175,3 +177,57 @@ HWTEST_F(MemoryhManagerMultiContextResourceTests, givenAllocationUsedByManyOsCon EXPECT_TRUE(nonDefaultCsr->getInternalAllocationStorage()->getTemporaryAllocations().peekIsEmpty()); EXPECT_TRUE(defaultCsr->getInternalAllocationStorage()->getTemporaryAllocations().peekIsEmpty()); } + +TEST(OsAgnosticMemoryManager, givenOsAgnosticMemoryManagerWhenGpuAddressIsReservedAndFreedThenAddressFromGfxPartitionIsUsed) { + MockExecutionEnvironment executionEnvironment; + OsAgnosticMemoryManager memoryManager(executionEnvironment); + RootDeviceIndicesContainer rootDevices; + rootDevices.push_back(0); + uint32_t rootDeviceIndexReserved = 10; + auto addressRange = memoryManager.reserveGpuAddress(0ull, MemoryConstants::pageSize, rootDevices, &rootDeviceIndexReserved); + auto gmmHelper = memoryManager.getGmmHelper(0); + EXPECT_EQ(0u, rootDeviceIndexReserved); + EXPECT_LE(memoryManager.getGfxPartition(0)->getHeapBase(HeapIndex::HEAP_STANDARD), gmmHelper->decanonize(addressRange.address)); + EXPECT_GT(memoryManager.getGfxPartition(0)->getHeapLimit(HeapIndex::HEAP_STANDARD), gmmHelper->decanonize(addressRange.address)); + + memoryManager.freeGpuAddress(addressRange, 0); +} + +TEST(OsAgnosticMemoryManager, givenOsAgnosticMemoryManagerWhenGpuAddressIsReservedOnIndex1AndFreedThenAddressFromGfxPartitionIsUsed) { + MockExecutionEnvironment executionEnvironment(defaultHwInfo.get(), true, 2u); + OsAgnosticMemoryManager memoryManager(executionEnvironment); + RootDeviceIndicesContainer rootDevices; + rootDevices.push_back(1); + uint32_t rootDeviceIndexReserved = 10; + auto addressRange = memoryManager.reserveGpuAddress(0ull, MemoryConstants::pageSize, rootDevices, &rootDeviceIndexReserved); + auto gmmHelper = memoryManager.getGmmHelper(1); + EXPECT_EQ(1u, rootDeviceIndexReserved); + EXPECT_LE(memoryManager.getGfxPartition(1)->getHeapBase(HeapIndex::HEAP_STANDARD), gmmHelper->decanonize(addressRange.address)); + EXPECT_GT(memoryManager.getGfxPartition(1)->getHeapLimit(HeapIndex::HEAP_STANDARD), gmmHelper->decanonize(addressRange.address)); + + memoryManager.freeGpuAddress(addressRange, 1); +} + +TEST(OsAgnosticMemoryManager, givenOsAgnosticMemoryManagerWhenGpuAddressReservationIsAttemptedWihtInvalidSizeThenFailureReturnsNullAddressRange) { + MockExecutionEnvironment executionEnvironment; + OsAgnosticMemoryManager memoryManager(executionEnvironment); + RootDeviceIndicesContainer rootDevices; + rootDevices.push_back(0); + uint32_t rootDeviceIndexReserved = 10; + // emulate GPU address space exhaust + memoryManager.getGfxPartition(0)->heapInit(HeapIndex::HEAP_STANDARD, 0x0, 0x10000); + auto addressRange = memoryManager.reserveGpuAddress(0ull, (size_t)(memoryManager.getGfxPartition(0)->getHeapLimit(HeapIndex::HEAP_STANDARD) * 2), rootDevices, &rootDeviceIndexReserved); + EXPECT_EQ(static_cast(addressRange.address), 0); +} + +TEST(OsAgnosticMemoryManager, givenOsAgnosticMemoryManagerWhenGpuAddressReservationIsAttemptedWithAnInvalidRequiredPtrThenADifferentRangeIsReturned) { + MockExecutionEnvironment executionEnvironment; + OsAgnosticMemoryManager memoryManager(executionEnvironment); + RootDeviceIndicesContainer rootDevices; + rootDevices.push_back(0); + uint32_t rootDeviceIndexReserved = 10; + auto addressRange = memoryManager.reserveGpuAddress(0x1234, MemoryConstants::pageSize, rootDevices, &rootDeviceIndexReserved); + EXPECT_EQ(0u, rootDeviceIndexReserved); + EXPECT_NE(static_cast(addressRange.address), 0x1234); + EXPECT_NE(static_cast(addressRange.size), 0); +} diff --git a/shared/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp b/shared/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp index 12fc7bb8dd..d039fc1402 100644 --- a/shared/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp @@ -271,7 +271,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenDrmMemoryManagerWhenGp RootDeviceIndicesContainer rootDevices; rootDevices.push_back(1); uint32_t rootDeviceIndexReserved = 0; - auto addressRange = memoryManager->reserveGpuAddress(nullptr, MemoryConstants::pageSize, rootDevices, &rootDeviceIndexReserved); + auto addressRange = memoryManager->reserveGpuAddress(0ull, MemoryConstants::pageSize, rootDevices, &rootDeviceIndexReserved); auto gmmHelper = memoryManager->getGmmHelper(1); EXPECT_EQ(rootDeviceIndexReserved, 1u); @@ -285,7 +285,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenDrmMemoryManagerWhenGp RootDeviceIndicesContainer rootDevices; rootDevices.push_back(0); uint32_t rootDeviceIndexReserved = 1; - auto addressRange = memoryManager->reserveGpuAddress(nullptr, MemoryConstants::pageSize, rootDevices, &rootDeviceIndexReserved); + auto addressRange = memoryManager->reserveGpuAddress(0ull, MemoryConstants::pageSize, rootDevices, &rootDeviceIndexReserved); auto gmmHelper = memoryManager->getGmmHelper(0); EXPECT_LE(memoryManager->getGfxPartition(0)->getHeapBase(HeapIndex::HEAP_STANDARD), gmmHelper->decanonize(addressRange.address)); @@ -293,15 +293,14 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenDrmMemoryManagerWhenGp memoryManager->freeGpuAddress(addressRange, 0); } -TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenDrmMemoryManagerWhenGpuAddressReservationIsAttemptedWithARequiredPtrThenNullRangeReturned) { +TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenDrmMemoryManagerWhenGpuAddressReservationIsAttemptedWithAnInvalidRequiredPtrThenDifferentRangeReturned) { auto memoryManager = std::make_unique(false, true, false, *executionEnvironment); - void *requiredPtr = reinterpret_cast(0x1234); RootDeviceIndicesContainer rootDevices; rootDevices.push_back(0); uint32_t rootDeviceIndexReserved = 1; - auto addressRange = memoryManager->reserveGpuAddress(requiredPtr, MemoryConstants::pageSize, rootDevices, &rootDeviceIndexReserved); - EXPECT_EQ(static_cast(addressRange.address), 0); - EXPECT_EQ(static_cast(addressRange.size), 0); + auto addressRange = memoryManager->reserveGpuAddress(0x1234, MemoryConstants::pageSize, rootDevices, &rootDeviceIndexReserved); + EXPECT_NE(static_cast(addressRange.address), 0x1234); + EXPECT_NE(static_cast(addressRange.size), 0); } TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenDrmMemoryManagerWhenGpuAddressReservationIsAttemptedWhichFailsThenNullRangeReturned) { @@ -313,7 +312,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenDrmMemoryManagerWhenGp memoryManager->forceLimitedRangeAllocator(0xFFFFFFFFF); memoryManager->getGfxPartition(0)->heapInit(HeapIndex::HEAP_STANDARD, 0x0, 0x10000); size_t invalidSize = (size_t)memoryManager->getGfxPartition(0)->getHeapLimit(HeapIndex::HEAP_STANDARD) + MemoryConstants::pageSize; - auto addressRange = memoryManager->reserveGpuAddress(nullptr, invalidSize, rootDevices, &rootDeviceIndexReserved); + auto addressRange = memoryManager->reserveGpuAddress(0ull, invalidSize, rootDevices, &rootDeviceIndexReserved); EXPECT_EQ(static_cast(addressRange.address), 0); } @@ -6130,3 +6129,25 @@ TEST_F(DrmMemoryManagerTest, givenMakeBosResidentSuccessWhenRegisteringMemoryAll EXPECT_EQ(MemoryManager::AllocationStatus::Success, memoryManager->registerLocalMemAlloc(&allocation, 0)); } + +TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenDrmMemoryManagerWhenGpuAddressReservationIsAttemptedWithKnownAddressAtIndex1ThenAddressFromGfxPartitionIsUsed) { + auto memoryManager = std::make_unique(false, true, false, *executionEnvironment); + RootDeviceIndicesContainer rootDevices; + rootDevices.push_back(1); + uint32_t rootDeviceIndexReserved = 0; + auto addressRange = memoryManager->reserveGpuAddress(0ull, MemoryConstants::pageSize, rootDevices, &rootDeviceIndexReserved); + auto gmmHelper = memoryManager->getGmmHelper(1); + + EXPECT_EQ(rootDeviceIndexReserved, 1u); + EXPECT_LE(memoryManager->getGfxPartition(1)->getHeapBase(HeapIndex::HEAP_STANDARD), gmmHelper->decanonize(addressRange.address)); + EXPECT_GT(memoryManager->getGfxPartition(1)->getHeapLimit(HeapIndex::HEAP_STANDARD), gmmHelper->decanonize(addressRange.address)); + uint64_t requiredAddr = addressRange.address; + memoryManager->freeGpuAddress(addressRange, 1); + addressRange = memoryManager->reserveGpuAddress(requiredAddr, MemoryConstants::pageSize, rootDevices, &rootDeviceIndexReserved); + + EXPECT_EQ(rootDeviceIndexReserved, 1u); + EXPECT_EQ(addressRange.address, requiredAddr); + EXPECT_LE(memoryManager->getGfxPartition(1)->getHeapBase(HeapIndex::HEAP_STANDARD), gmmHelper->decanonize(addressRange.address)); + EXPECT_GT(memoryManager->getGfxPartition(1)->getHeapLimit(HeapIndex::HEAP_STANDARD), gmmHelper->decanonize(addressRange.address)); + memoryManager->freeGpuAddress(addressRange, 1); +} diff --git a/shared/test/unit_test/os_interface/windows/wddm_memory_reservation_tests.cpp b/shared/test/unit_test/os_interface/windows/wddm_memory_reservation_tests.cpp index 5c4e65717f..90c596ad95 100644 --- a/shared/test/unit_test/os_interface/windows/wddm_memory_reservation_tests.cpp +++ b/shared/test/unit_test/os_interface/windows/wddm_memory_reservation_tests.cpp @@ -50,7 +50,7 @@ TEST_F(WddmMemoryReservationTests, givenWddmMemoryManagerWhenGpuAddressIsReserve RootDeviceIndicesContainer rootDevices; rootDevices.push_back(0); uint32_t rootDeviceIndexReserved = 1; - auto addressRange = memManager->reserveGpuAddress(nullptr, MemoryConstants::pageSize64k, rootDevices, &rootDeviceIndexReserved); + auto addressRange = memManager->reserveGpuAddress(0ull, MemoryConstants::pageSize64k, rootDevices, &rootDeviceIndexReserved); auto gmmHelper = memManager->getGmmHelper(0); EXPECT_EQ(rootDeviceIndexReserved, 0u); @@ -77,7 +77,7 @@ TEST(WddmMemoryReservationFailTest, givenWddmMemoryManagerWhenGpuAddressReservat RootDeviceIndicesContainer rootDevices; rootDevices.push_back(0); uint32_t rootDeviceIndexReserved = 1; - auto addressRange = memManager->reserveGpuAddress(nullptr, MemoryConstants::pageSize64k, rootDevices, &rootDeviceIndexReserved); + auto addressRange = memManager->reserveGpuAddress(0ull, MemoryConstants::pageSize64k, rootDevices, &rootDeviceIndexReserved); EXPECT_EQ(addressRange.address, 0ull); EXPECT_EQ(addressRange.size, 0u); }