mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-09 22:43:00 +08:00
Revert "feature: support SVM heap in reserveVirtualMem"
This reverts commit 93cde3ee12.
Signed-off-by: Compute-Runtime-Validation <compute-runtime-validation@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
37b7caa137
commit
99f62ac866
@@ -10,15 +10,12 @@
|
||||
#include "shared/source/command_container/implicit_scaling.h"
|
||||
#include "shared/source/command_stream/command_stream_receiver.h"
|
||||
#include "shared/source/execution_environment/root_device_environment.h"
|
||||
#include "shared/source/helpers/aligned_memory.h"
|
||||
#include "shared/source/helpers/basic_math.h"
|
||||
#include "shared/source/helpers/constants.h"
|
||||
#include "shared/source/helpers/gfx_core_helper.h"
|
||||
#include "shared/source/helpers/ptr_math.h"
|
||||
#include "shared/source/memory_manager/allocation_properties.h"
|
||||
#include "shared/source/memory_manager/memory_operations_handler.h"
|
||||
#include "shared/source/memory_manager/unified_memory_manager.h"
|
||||
#include "shared/source/utilities/cpu_info.h"
|
||||
|
||||
#include "level_zero/api/driver_experimental/public/zex_memory.h"
|
||||
#include "level_zero/core/source/cmdlist/cmdlist.h"
|
||||
@@ -1015,60 +1012,21 @@ NEO::VirtualMemoryReservation *ContextImp::findSupportedVirtualReservation(const
|
||||
ze_result_t ContextImp::reserveVirtualMem(const void *pStart,
|
||||
size_t size,
|
||||
void **pptr) {
|
||||
NEO::AddressRange addressRange{};
|
||||
uint32_t reservedOnRootDeviceIndex = 0;
|
||||
|
||||
uint64_t maxCpuVa = 0;
|
||||
if (this->driverHandle->getMemoryManager()->peek32bit()) {
|
||||
maxCpuVa = maxNBitValue(32);
|
||||
} else {
|
||||
maxCpuVa = NEO::CpuInfo::getInstance().getVirtualAddressSize() == 57u ? maxNBitValue(56) : maxNBitValue(47);
|
||||
NEO::HeapIndex heap;
|
||||
size_t pageSize;
|
||||
if ((getPageAlignedSizeRequired(size, &heap, &pageSize) != size)) {
|
||||
return ZE_RESULT_ERROR_UNSUPPORTED_SIZE;
|
||||
}
|
||||
bool reserveOnSvmHeap = pStart == nullptr;
|
||||
if (castToUint64(pStart) <= maxCpuVa) {
|
||||
reserveOnSvmHeap = true;
|
||||
}
|
||||
|
||||
size_t reservationTotalSize = 0;
|
||||
uint64_t reservationBase = 0;
|
||||
|
||||
if (reserveOnSvmHeap) {
|
||||
if (alignUp(size, MemoryConstants::pageSize) != size) {
|
||||
return ZE_RESULT_ERROR_UNSUPPORTED_SIZE;
|
||||
}
|
||||
reservationTotalSize = size + MemoryConstants::pageSize2M;
|
||||
addressRange = this->driverHandle->getMemoryManager()->reserveCpuAddress(castToUint64(pStart), reservationTotalSize);
|
||||
DEBUG_BREAK_IF(addressRange.address + reservationTotalSize > MemoryConstants::maxSvmAddress);
|
||||
if (addressRange.address == 0) {
|
||||
return ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY;
|
||||
}
|
||||
reservationBase = addressRange.address;
|
||||
addressRange.address = alignUp(addressRange.address, MemoryConstants::pageSize2M);
|
||||
addressRange.size = size;
|
||||
} else {
|
||||
NEO::HeapIndex heap;
|
||||
size_t pageSize;
|
||||
if ((getPageAlignedSizeRequired(size, &heap, &pageSize) != size)) {
|
||||
return ZE_RESULT_ERROR_UNSUPPORTED_SIZE;
|
||||
}
|
||||
addressRange = this->driverHandle->getMemoryManager()->reserveGpuAddressOnHeap(castToUint64(pStart), size, this->driverHandle->rootDeviceIndices, &reservedOnRootDeviceIndex, heap, pageSize);
|
||||
if (addressRange.address == 0) {
|
||||
return ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY;
|
||||
}
|
||||
reservationBase = addressRange.address;
|
||||
reservationTotalSize = addressRange.size;
|
||||
}
|
||||
|
||||
NEO::VirtualMemoryReservation *virtualMemoryReservation = new NEO::VirtualMemoryReservation;
|
||||
virtualMemoryReservation->virtualAddressRange = addressRange;
|
||||
virtualMemoryReservation->isSvmReservation = reserveOnSvmHeap;
|
||||
virtualMemoryReservation->rootDeviceIndex = reservedOnRootDeviceIndex;
|
||||
virtualMemoryReservation->virtualAddressRange = this->driverHandle->getMemoryManager()->reserveGpuAddressOnHeap(reinterpret_cast<uint64_t>(pStart), size, this->driverHandle->rootDeviceIndices, &virtualMemoryReservation->rootDeviceIndex, heap, pageSize);
|
||||
if (virtualMemoryReservation->virtualAddressRange.address == 0) {
|
||||
delete virtualMemoryReservation;
|
||||
return ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY;
|
||||
}
|
||||
virtualMemoryReservation->flags.readWrite = false;
|
||||
virtualMemoryReservation->flags.readOnly = false;
|
||||
virtualMemoryReservation->flags.noAccess = true;
|
||||
virtualMemoryReservation->reservationSize = size;
|
||||
virtualMemoryReservation->reservationBase = reservationBase;
|
||||
virtualMemoryReservation->reservationTotalSize = reservationTotalSize;
|
||||
auto lock = this->driverHandle->getMemoryManager()->lockVirtualMemoryReservationMap();
|
||||
this->driverHandle->getMemoryManager()->getVirtualMemoryReservationMap().insert(std::pair<void *, NEO::VirtualMemoryReservation *>(reinterpret_cast<void *>(virtualMemoryReservation->virtualAddressRange.address), virtualMemoryReservation));
|
||||
*pptr = reinterpret_cast<void *>(virtualMemoryReservation->virtualAddressRange.address);
|
||||
@@ -1089,12 +1047,7 @@ ze_result_t ContextImp::freeVirtualMem(const void *ptr,
|
||||
if (virtualMemoryReservation->reservationSize != size) {
|
||||
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
NEO::AddressRange addressRange{virtualMemoryReservation->reservationBase, virtualMemoryReservation->reservationTotalSize};
|
||||
if (virtualMemoryReservation->isSvmReservation) {
|
||||
this->driverHandle->getMemoryManager()->freeCpuAddress(addressRange);
|
||||
} else {
|
||||
this->driverHandle->getMemoryManager()->freeGpuAddress(addressRange, virtualMemoryReservation->rootDeviceIndex);
|
||||
}
|
||||
this->driverHandle->getMemoryManager()->freeGpuAddress(virtualMemoryReservation->virtualAddressRange, virtualMemoryReservation->rootDeviceIndex);
|
||||
delete virtualMemoryReservation;
|
||||
this->driverHandle->getMemoryManager()->getVirtualMemoryReservationMap().erase(it);
|
||||
virtualMemoryReservation = nullptr;
|
||||
|
||||
@@ -212,8 +212,6 @@ class MemoryManagerIpcMock : public NEO::MemoryManager {
|
||||
return MemoryConstants::pageSize64k;
|
||||
}
|
||||
void freeGpuAddress(AddressRange addressRange, uint32_t rootDeviceIndex) override{};
|
||||
AddressRange reserveCpuAddress(const uint64_t requiredStartAddress, size_t size) override { return {}; }
|
||||
void freeCpuAddress(AddressRange addressRange) override{};
|
||||
NEO::GraphicsAllocation *createGraphicsAllocation(OsHandleStorage &handleStorage, const NEO::AllocationData &allocationData) override { return nullptr; };
|
||||
NEO::GraphicsAllocation *allocateGraphicsMemoryForNonSvmHostPtr(const NEO::AllocationData &allocationData) override { return nullptr; };
|
||||
NEO::GraphicsAllocation *allocateGraphicsMemoryWithAlignment(const NEO::AllocationData &allocationData) override { return nullptr; };
|
||||
@@ -340,8 +338,6 @@ class MemoryManagerIpcImplicitScalingMock : public NEO::MemoryManager {
|
||||
return MemoryConstants::pageSize64k;
|
||||
}
|
||||
void freeGpuAddress(AddressRange addressRange, uint32_t rootDeviceIndex) override{};
|
||||
AddressRange reserveCpuAddress(const uint64_t requiredStartAddress, size_t size) override { return {}; }
|
||||
void freeCpuAddress(AddressRange addressRange) override{};
|
||||
NEO::GraphicsAllocation *createGraphicsAllocation(OsHandleStorage &handleStorage, const NEO::AllocationData &allocationData) override { return nullptr; };
|
||||
NEO::GraphicsAllocation *allocateGraphicsMemoryForNonSvmHostPtr(const NEO::AllocationData &allocationData) override { return nullptr; };
|
||||
NEO::GraphicsAllocation *allocateGraphicsMemoryWithAlignment(const NEO::AllocationData &allocationData) override { return nullptr; };
|
||||
@@ -396,4 +392,4 @@ struct MemoryExportImportImplicitScalingTest : public ::testing::Test {
|
||||
};
|
||||
|
||||
} // namespace ult
|
||||
} // namespace L0
|
||||
} // namespace L0
|
||||
@@ -10,9 +10,9 @@
|
||||
#include "shared/source/helpers/blit_properties.h"
|
||||
#include "shared/source/memory_manager/gfx_partition.h"
|
||||
#include "shared/source/os_interface/device_factory.h"
|
||||
#include "shared/source/utilities/cpu_info.h"
|
||||
#include "shared/test/common/mocks/mock_bindless_heaps_helper.h"
|
||||
#include "shared/test/common/mocks/mock_command_stream_receiver.h"
|
||||
#include "shared/test/common/mocks/mock_compilers.h"
|
||||
#include "shared/test/common/mocks/mock_cpu_page_fault_manager.h"
|
||||
#include "shared/test/common/mocks/mock_device.h"
|
||||
#include "shared/test/common/mocks/mock_graphics_allocation.h"
|
||||
@@ -28,6 +28,7 @@
|
||||
#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h"
|
||||
#include "level_zero/core/test/unit_tests/fixtures/host_pointer_manager_fixture.h"
|
||||
#include "level_zero/core/test/unit_tests/mocks/mock_cmdlist.h"
|
||||
#include "level_zero/core/test/unit_tests/mocks/mock_driver_handle.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
@@ -1380,17 +1381,6 @@ TEST_F(ContextTest, whenCallingVirtualMemoryFreeWithInvalidValuesThenFailuresRet
|
||||
res = contextImp->freeVirtualMem(ptr, pagesize);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
|
||||
|
||||
pStart = reinterpret_cast<void *>(MemoryConstants::maxSvmAddress * 2 + 1);
|
||||
res = contextImp->reserveVirtualMem(pStart, pagesize, &ptr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
|
||||
EXPECT_GT(static_cast<int>(driverHandle->getMemoryManager()->getVirtualMemoryReservationMap().size()), 0);
|
||||
|
||||
res = contextImp->freeVirtualMem(ptr, invalidSize);
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, res);
|
||||
|
||||
res = contextImp->freeVirtualMem(ptr, pagesize);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
|
||||
|
||||
res = contextImp->destroy();
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
|
||||
}
|
||||
@@ -1426,13 +1416,6 @@ class ReserveMemoryManagerMock : public NEO::MemoryManager {
|
||||
return MemoryConstants::pageSize64k;
|
||||
}
|
||||
void freeGpuAddress(AddressRange addressRange, uint32_t rootDeviceIndex) override{};
|
||||
AddressRange reserveCpuAddress(const uint64_t requiredStartAddress, size_t size) override {
|
||||
if (failReserveCpuAddress) {
|
||||
return {};
|
||||
}
|
||||
return AddressRange{requiredStartAddress, size};
|
||||
}
|
||||
void freeCpuAddress(AddressRange addressRange) override{};
|
||||
NEO::GraphicsAllocation *createGraphicsAllocation(OsHandleStorage &handleStorage, const NEO::AllocationData &allocationData) override { return nullptr; };
|
||||
NEO::GraphicsAllocation *allocateGraphicsMemoryForNonSvmHostPtr(const NEO::AllocationData &allocationData) override { return nullptr; };
|
||||
NEO::GraphicsAllocation *allocateGraphicsMemoryWithAlignment(const NEO::AllocationData &allocationData) override { return nullptr; };
|
||||
@@ -1465,21 +1448,16 @@ class ReserveMemoryManagerMock : public NEO::MemoryManager {
|
||||
NEO::GraphicsAllocation *allocateMemoryByKMD(const NEO::AllocationData &allocationData) override { return nullptr; };
|
||||
void *lockResourceImpl(NEO::GraphicsAllocation &graphicsAllocation) override { return nullptr; };
|
||||
void unlockResourceImpl(NEO::GraphicsAllocation &graphicsAllocation) override{};
|
||||
bool peek32bit() override {
|
||||
return this->is32bit;
|
||||
}
|
||||
|
||||
bool failReserveGpuAddress = true;
|
||||
bool failReserveCpuAddress = true;
|
||||
bool failMapVirtualMemory = true;
|
||||
bool failAllocatePhysicalGraphicsMemory = true;
|
||||
bool is32bit = false;
|
||||
void *buffer = nullptr;
|
||||
size_t size = 0;
|
||||
std::unique_ptr<NEO::GraphicsAllocation> mockAllocation;
|
||||
};
|
||||
|
||||
TEST_F(ContextTest, whenCallingVirtualMemReserveWithPStartInSvmRangeWithSuccessfulAllocationThenSuccessReturned) {
|
||||
TEST_F(ContextTest, whenCallingVirtualMemReserveWithPStartWithSuccessfulAllocationThenSuccessReturned) {
|
||||
ze_context_handle_t hContext{};
|
||||
ze_context_desc_t desc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr, 0};
|
||||
|
||||
@@ -1493,37 +1471,6 @@ TEST_F(ContextTest, whenCallingVirtualMemReserveWithPStartInSvmRangeWithSuccessf
|
||||
void *ptr = nullptr;
|
||||
size_t pagesize = 0u;
|
||||
|
||||
res = contextImp->queryVirtualMemPageSize(device, size, &pagesize);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
|
||||
auto reserveMemoryManager = std::make_unique<ReserveMemoryManagerMock>(*neoDevice->executionEnvironment);
|
||||
auto memoryManager = driverHandle->getMemoryManager();
|
||||
reserveMemoryManager->failReserveCpuAddress = false;
|
||||
driverHandle->setMemoryManager(reserveMemoryManager.get());
|
||||
res = contextImp->reserveVirtualMem(pStart, pagesize, &ptr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
|
||||
EXPECT_GT(reserveMemoryManager->getVirtualMemoryReservationMap().size(), 0u);
|
||||
res = contextImp->freeVirtualMem(ptr, pagesize);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
|
||||
driverHandle->setMemoryManager(memoryManager);
|
||||
|
||||
res = contextImp->destroy();
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
|
||||
}
|
||||
|
||||
TEST_F(ContextTest, whenCallingVirtualMemReserveWithPStartAboveSvmRangeWithSuccessfulAllocationThenSuccessReturned) {
|
||||
ze_context_handle_t hContext{};
|
||||
ze_context_desc_t desc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr, 0};
|
||||
|
||||
ze_result_t res = driverHandle->createContext(&desc, 0u, nullptr, &hContext);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
|
||||
|
||||
ContextImp *contextImp = static_cast<ContextImp *>(L0::Context::fromHandle(hContext));
|
||||
|
||||
void *pStart = reinterpret_cast<void *>(MemoryConstants::maxSvmAddress * 2 + 1);
|
||||
size_t size = 4096u;
|
||||
void *ptr = nullptr;
|
||||
size_t pagesize = 0u;
|
||||
|
||||
res = contextImp->queryVirtualMemPageSize(device, size, &pagesize);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
|
||||
auto reserveMemoryManager = std::make_unique<ReserveMemoryManagerMock>(*neoDevice->executionEnvironment);
|
||||
@@ -1702,12 +1649,9 @@ TEST_F(ContextTest, whenCallingVirtualMemoryReservationWhenOutOfMemoryThenOutOfM
|
||||
auto memoryManager = driverHandle->getMemoryManager();
|
||||
driverHandle->setMemoryManager(failingReserveMemoryManager);
|
||||
res = contextImp->reserveVirtualMem(pStart, pagesize, &ptr);
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY, res);
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY, res);
|
||||
pStart = reinterpret_cast<void *>(0x1234);
|
||||
res = contextImp->reserveVirtualMem(pStart, pagesize, &ptr);
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY, res);
|
||||
pStart = reinterpret_cast<void *>(MemoryConstants::maxSvmAddress * 2 + 1);
|
||||
res = contextImp->reserveVirtualMem(pStart, pagesize, &ptr);
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY, res);
|
||||
driverHandle->setMemoryManager(memoryManager);
|
||||
delete failingReserveMemoryManager;
|
||||
@@ -1738,9 +1682,6 @@ TEST_F(ContextTest, whenCallingVirtualMemoryReservationWithInvalidArgumentsThenU
|
||||
driverHandle->setMemoryManager(failingReserveMemoryManager);
|
||||
res = contextImp->reserveVirtualMem(pStart, size, &ptr);
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_SIZE, res);
|
||||
pStart = reinterpret_cast<void *>(MemoryConstants::maxSvmAddress * 2 + 1);
|
||||
res = contextImp->reserveVirtualMem(pStart, size, &ptr);
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_SIZE, res);
|
||||
driverHandle->setMemoryManager(memoryManager);
|
||||
delete failingReserveMemoryManager;
|
||||
|
||||
@@ -1807,159 +1748,6 @@ TEST_F(ContextTest, whenCallingVirtualMemoryReservationWithValidMultiPageSizeInA
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
|
||||
}
|
||||
|
||||
class MockCpuInfoOverrideVirtualAddressSize {
|
||||
public:
|
||||
class MockCpuInfo : public CpuInfo {
|
||||
public:
|
||||
using CpuInfo::cpuFlags;
|
||||
using CpuInfo::virtualAddressSize;
|
||||
} *mockCpuInfo = reinterpret_cast<MockCpuInfo *>(const_cast<CpuInfo *>(&CpuInfo::getInstance()));
|
||||
|
||||
MockCpuInfoOverrideVirtualAddressSize(uint32_t newCpuVirtualAddressSize) {
|
||||
virtualAddressSizeSave = mockCpuInfo->getVirtualAddressSize();
|
||||
mockCpuInfo->virtualAddressSize = newCpuVirtualAddressSize;
|
||||
}
|
||||
|
||||
~MockCpuInfoOverrideVirtualAddressSize() {
|
||||
mockCpuInfo->virtualAddressSize = virtualAddressSizeSave;
|
||||
}
|
||||
|
||||
uint32_t virtualAddressSizeSave = 0;
|
||||
};
|
||||
|
||||
TEST_F(ContextTest, Given32BitCpuAddressWidthWhenCallingVirtualMemoryReservationCorrectAllocationMethodIsSelected) {
|
||||
MockCpuInfoOverrideVirtualAddressSize overrideCpuInfo(32);
|
||||
|
||||
ze_context_handle_t hContext;
|
||||
ze_context_desc_t desc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr, 0};
|
||||
|
||||
ze_result_t res = driverHandle->createContext(&desc, 0u, nullptr, &hContext);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
|
||||
|
||||
ContextImp *contextImp = static_cast<ContextImp *>(L0::Context::fromHandle(hContext));
|
||||
|
||||
void *pStart = reinterpret_cast<void *>(0x1234);
|
||||
size_t size = MemoryConstants::pageSize2M;
|
||||
void *ptr = nullptr;
|
||||
|
||||
auto reserveMemoryManager = new ReserveMemoryManagerMock(*neoDevice->executionEnvironment);
|
||||
reserveMemoryManager->is32bit = true;
|
||||
auto memoryManager = driverHandle->getMemoryManager();
|
||||
driverHandle->setMemoryManager(reserveMemoryManager);
|
||||
|
||||
res = contextImp->reserveVirtualMem(pStart, size, &ptr);
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY, res);
|
||||
reserveMemoryManager->failReserveCpuAddress = false;
|
||||
res = contextImp->reserveVirtualMem(pStart, size, &ptr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
|
||||
res = contextImp->freeVirtualMem(ptr, size);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
|
||||
|
||||
pStart = reinterpret_cast<void *>(maxNBitValue(32) + 0x1234);
|
||||
|
||||
res = contextImp->reserveVirtualMem(pStart, size, &ptr);
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY, res);
|
||||
reserveMemoryManager->failReserveGpuAddress = false;
|
||||
res = contextImp->reserveVirtualMem(pStart, size, &ptr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
|
||||
res = contextImp->freeVirtualMem(ptr, size);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
|
||||
|
||||
driverHandle->setMemoryManager(memoryManager);
|
||||
delete reserveMemoryManager;
|
||||
|
||||
res = contextImp->destroy();
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
|
||||
}
|
||||
|
||||
TEST_F(ContextTest, Given48BitCpuAddressWidthWhenCallingVirtualMemoryReservationCorrectAllocationMethodIsSelected) {
|
||||
MockCpuInfoOverrideVirtualAddressSize overrideCpuInfo(48);
|
||||
|
||||
ze_context_handle_t hContext;
|
||||
ze_context_desc_t desc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr, 0};
|
||||
|
||||
ze_result_t res = driverHandle->createContext(&desc, 0u, nullptr, &hContext);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
|
||||
|
||||
ContextImp *contextImp = static_cast<ContextImp *>(L0::Context::fromHandle(hContext));
|
||||
|
||||
void *pStart = reinterpret_cast<void *>(0x1234);
|
||||
size_t size = MemoryConstants::pageSize2M;
|
||||
void *ptr = nullptr;
|
||||
|
||||
auto reserveMemoryManager = new ReserveMemoryManagerMock(*neoDevice->executionEnvironment);
|
||||
auto memoryManager = driverHandle->getMemoryManager();
|
||||
driverHandle->setMemoryManager(reserveMemoryManager);
|
||||
|
||||
res = contextImp->reserveVirtualMem(pStart, size, &ptr);
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY, res);
|
||||
reserveMemoryManager->failReserveCpuAddress = false;
|
||||
res = contextImp->reserveVirtualMem(pStart, size, &ptr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
|
||||
res = contextImp->freeVirtualMem(ptr, size);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
|
||||
|
||||
pStart = reinterpret_cast<void *>(maxNBitValue(47) + 0x1234);
|
||||
|
||||
res = contextImp->reserveVirtualMem(pStart, size, &ptr);
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY, res);
|
||||
reserveMemoryManager->failReserveGpuAddress = false;
|
||||
res = contextImp->reserveVirtualMem(pStart, size, &ptr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
|
||||
res = contextImp->freeVirtualMem(ptr, size);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
|
||||
|
||||
driverHandle->setMemoryManager(memoryManager);
|
||||
delete reserveMemoryManager;
|
||||
|
||||
res = contextImp->destroy();
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
|
||||
}
|
||||
|
||||
TEST_F(ContextTest, Given57BitCpuAddressWidthWhenCallingVirtualMemoryReservationCorrectAllocationMethodIsSelected) {
|
||||
MockCpuInfoOverrideVirtualAddressSize overrideCpuInfo(57);
|
||||
|
||||
ze_context_handle_t hContext;
|
||||
ze_context_desc_t desc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr, 0};
|
||||
|
||||
ze_result_t res = driverHandle->createContext(&desc, 0u, nullptr, &hContext);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
|
||||
|
||||
ContextImp *contextImp = static_cast<ContextImp *>(L0::Context::fromHandle(hContext));
|
||||
|
||||
void *pStart = reinterpret_cast<void *>(0x1234);
|
||||
size_t size = MemoryConstants::pageSize2M;
|
||||
void *ptr = nullptr;
|
||||
|
||||
auto reserveMemoryManager = new ReserveMemoryManagerMock(*neoDevice->executionEnvironment);
|
||||
auto memoryManager = driverHandle->getMemoryManager();
|
||||
driverHandle->setMemoryManager(reserveMemoryManager);
|
||||
|
||||
res = contextImp->reserveVirtualMem(pStart, size, &ptr);
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY, res);
|
||||
reserveMemoryManager->failReserveCpuAddress = false;
|
||||
res = contextImp->reserveVirtualMem(pStart, size, &ptr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
|
||||
res = contextImp->freeVirtualMem(ptr, size);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
|
||||
|
||||
pStart = reinterpret_cast<void *>(maxNBitValue(56) + 0x1234);
|
||||
|
||||
res = contextImp->reserveVirtualMem(pStart, size, &ptr);
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY, res);
|
||||
reserveMemoryManager->failReserveGpuAddress = false;
|
||||
res = contextImp->reserveVirtualMem(pStart, size, &ptr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
|
||||
res = contextImp->freeVirtualMem(ptr, size);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
|
||||
|
||||
driverHandle->setMemoryManager(memoryManager);
|
||||
delete reserveMemoryManager;
|
||||
|
||||
res = contextImp->destroy();
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
|
||||
}
|
||||
|
||||
TEST_F(ContextTest, whenCallingPhysicalMemoryAllocateWhenOutOfMemoryThenOutofMemoryReturned) {
|
||||
ze_context_handle_t hContext;
|
||||
ze_context_desc_t desc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr, 0};
|
||||
|
||||
@@ -89,8 +89,6 @@ class MemoryManagerEventPoolFailMock : public NEO::MemoryManager {
|
||||
return MemoryConstants::pageSize64k;
|
||||
}
|
||||
void freeGpuAddress(AddressRange addressRange, uint32_t rootDeviceIndex) override{};
|
||||
AddressRange reserveCpuAddress(const uint64_t requiredStartAddress, size_t size) override { return {}; }
|
||||
void freeCpuAddress(AddressRange addressRange) override{};
|
||||
NEO::GraphicsAllocation *createGraphicsAllocation(OsHandleStorage &handleStorage, const NEO::AllocationData &allocationData) override { return nullptr; };
|
||||
NEO::GraphicsAllocation *allocateGraphicsMemoryForNonSvmHostPtr(const NEO::AllocationData &allocationData) override { return nullptr; };
|
||||
NEO::GraphicsAllocation *allocateGraphicsMemoryWithAlignment(const NEO::AllocationData &allocationData) override { return nullptr; };
|
||||
|
||||
Reference in New Issue
Block a user