mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-21 01:04:57 +08:00
feature: Relaxed Virtual Memory reservation with pStart
Related-To: LOCI-3871 - Relaxed the Virtual Memory Reservation to allow pStart and not fail if the pStart value is not obtained. - Moves checks on pStart to the user to check and determine if they want to re-reserve or use the address allocated. - Changed reserveGpuAddress to use unit64_t type to allow internal address range structure assignment without cast. Signed-off-by: Spruit, Neil R <neil.r.spruit@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
c628ffe18a
commit
86e739e9dc
@@ -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<uint64_t>(pStart)) {
|
||||
delete virtualMemoryReservation;
|
||||
return ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY;
|
||||
}
|
||||
}
|
||||
virtualMemoryReservation->virtualAddressRange = this->driverHandle->getMemoryManager()->reserveGpuAddress(reinterpret_cast<uint64_t>(pStart), size, this->driverHandle->rootDeviceIndices, &virtualMemoryReservation->rootDeviceIndex);
|
||||
if (virtualMemoryReservation->virtualAddressRange.address == 0) {
|
||||
delete virtualMemoryReservation;
|
||||
return ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY;
|
||||
|
||||
@@ -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{};
|
||||
|
||||
@@ -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<void *>(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<uint64_t>(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; };
|
||||
|
||||
@@ -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{};
|
||||
|
||||
@@ -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{};
|
||||
|
||||
@@ -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<int>(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<void *>(0x1234);
|
||||
auto addressRange = memoryManager.reserveGpuAddress(requiredPtr, MemoryConstants::pageSize, rootDevices, &rootDeviceIndexReserved);
|
||||
EXPECT_EQ(0u, rootDeviceIndexReserved);
|
||||
EXPECT_EQ(static_cast<int>(addressRange.address), 0);
|
||||
EXPECT_EQ(static_cast<int>(addressRange.size), 0);
|
||||
}
|
||||
|
||||
TEST(OsAgnosticMemoryManager, givenOsAgnosticMemoryManagerWhenCheckedForIndirectAllocationsAsPackSupportThenFalseIsReturned) {
|
||||
MockExecutionEnvironment executionEnvironment;
|
||||
OsAgnosticMemoryManager memoryManager(executionEnvironment);
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<uint64_t>(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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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{};
|
||||
|
||||
@@ -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<int>(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<int>(addressRange.address), 0x1234);
|
||||
EXPECT_NE(static_cast<int>(addressRange.size), 0);
|
||||
}
|
||||
|
||||
@@ -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<TestedDrmMemoryManager>(false, true, false, *executionEnvironment);
|
||||
void *requiredPtr = reinterpret_cast<void *>(0x1234);
|
||||
RootDeviceIndicesContainer rootDevices;
|
||||
rootDevices.push_back(0);
|
||||
uint32_t rootDeviceIndexReserved = 1;
|
||||
auto addressRange = memoryManager->reserveGpuAddress(requiredPtr, MemoryConstants::pageSize, rootDevices, &rootDeviceIndexReserved);
|
||||
EXPECT_EQ(static_cast<int>(addressRange.address), 0);
|
||||
EXPECT_EQ(static_cast<int>(addressRange.size), 0);
|
||||
auto addressRange = memoryManager->reserveGpuAddress(0x1234, MemoryConstants::pageSize, rootDevices, &rootDeviceIndexReserved);
|
||||
EXPECT_NE(static_cast<int>(addressRange.address), 0x1234);
|
||||
EXPECT_NE(static_cast<int>(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<int>(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<TestedDrmMemoryManager>(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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user