Skip to content

Commit 9bda117

Browse files
Revert "feature: support SVM heap in reserveVirtualMem"
This reverts commit bfaeeb0. Signed-off-by: Compute-Runtime-Validation <compute-runtime-validation@intel.com> Source: 41df1a6
1 parent 2ffde8e commit 9bda117

18 files changed

+29
-517
lines changed

level_zero/core/source/context/context_imp.cpp

Lines changed: 11 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@
1010
#include "shared/source/command_container/implicit_scaling.h"
1111
#include "shared/source/command_stream/command_stream_receiver.h"
1212
#include "shared/source/execution_environment/root_device_environment.h"
13-
#include "shared/source/helpers/aligned_memory.h"
13+
#include "shared/source/helpers/basic_math.h"
1414
#include "shared/source/helpers/gfx_core_helper.h"
1515
#include "shared/source/helpers/ptr_math.h"
1616
#include "shared/source/memory_manager/allocation_properties.h"
1717
#include "shared/source/memory_manager/memory_operations_handler.h"
1818
#include "shared/source/memory_manager/unified_memory_manager.h"
19-
#include "shared/source/utilities/cpu_info.h"
2019

2120
#include "level_zero/api/driver_experimental/public/zex_memory.h"
2221
#include "level_zero/core/source/cmdlist/cmdlist.h"
@@ -1048,59 +1047,21 @@ NEO::VirtualMemoryReservation *ContextImp::findSupportedVirtualReservation(const
10481047
ze_result_t ContextImp::reserveVirtualMem(const void *pStart,
10491048
size_t size,
10501049
void **pptr) {
1051-
uint64_t maxCpuVa = 0;
1052-
if (this->driverHandle->getMemoryManager()->peek32bit()) {
1053-
maxCpuVa = maxNBitValue(32);
1054-
} else {
1055-
maxCpuVa = NEO::CpuInfo::getInstance().getVirtualAddressSize() == 57u ? maxNBitValue(56) : maxNBitValue(47);
1056-
}
1057-
bool reserveOnSvmHeap = pStart == nullptr;
1058-
if (castToUint64(pStart) <= maxCpuVa) {
1059-
reserveOnSvmHeap = true;
1060-
}
1061-
1062-
NEO::AddressRange addressRange{};
1063-
uint32_t reservedOnRootDeviceIndex = 0;
1064-
uint64_t reservationBase = 0;
1065-
size_t reservationTotalSize = 0;
1066-
1067-
if (reserveOnSvmHeap) {
1068-
if (alignUp(size, MemoryConstants::pageSize) != size) {
1069-
return ZE_RESULT_ERROR_UNSUPPORTED_SIZE;
1070-
}
1071-
reservationTotalSize = size + MemoryConstants::pageSize2M;
1072-
addressRange = this->driverHandle->getMemoryManager()->reserveCpuAddressWithZeroBaseRetry(castToUint64(pStart), reservationTotalSize);
1073-
if (addressRange.address == 0) {
1074-
return ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY;
1075-
}
1076-
DEBUG_BREAK_IF(addressRange.address + reservationTotalSize > maxCpuVa);
1077-
reservationBase = addressRange.address;
1078-
addressRange.address = alignUp(addressRange.address, MemoryConstants::pageSize2M);
1079-
addressRange.size = size;
1080-
} else {
1081-
NEO::HeapIndex heap;
1082-
size_t pageSize;
1083-
if ((getPageAlignedSizeRequired(size, &heap, &pageSize) != size)) {
1084-
return ZE_RESULT_ERROR_UNSUPPORTED_SIZE;
1085-
}
1086-
addressRange = this->driverHandle->getMemoryManager()->reserveGpuAddressOnHeap(castToUint64(pStart), size, this->driverHandle->rootDeviceIndices, &reservedOnRootDeviceIndex, heap, pageSize);
1087-
if (addressRange.address == 0) {
1088-
return ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY;
1089-
}
1090-
reservationBase = addressRange.address;
1091-
reservationTotalSize = addressRange.size;
1050+
NEO::HeapIndex heap;
1051+
size_t pageSize;
1052+
if ((getPageAlignedSizeRequired(size, &heap, &pageSize) != size)) {
1053+
return ZE_RESULT_ERROR_UNSUPPORTED_SIZE;
10921054
}
1093-
10941055
NEO::VirtualMemoryReservation *virtualMemoryReservation = new NEO::VirtualMemoryReservation;
1095-
virtualMemoryReservation->virtualAddressRange = addressRange;
1096-
virtualMemoryReservation->isSvmReservation = reserveOnSvmHeap;
1097-
virtualMemoryReservation->rootDeviceIndex = reservedOnRootDeviceIndex;
1056+
virtualMemoryReservation->virtualAddressRange = this->driverHandle->getMemoryManager()->reserveGpuAddressOnHeap(reinterpret_cast<uint64_t>(pStart), size, this->driverHandle->rootDeviceIndices, &virtualMemoryReservation->rootDeviceIndex, heap, pageSize);
1057+
if (virtualMemoryReservation->virtualAddressRange.address == 0) {
1058+
delete virtualMemoryReservation;
1059+
return ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY;
1060+
}
10981061
virtualMemoryReservation->flags.readWrite = false;
10991062
virtualMemoryReservation->flags.readOnly = false;
11001063
virtualMemoryReservation->flags.noAccess = true;
11011064
virtualMemoryReservation->reservationSize = size;
1102-
virtualMemoryReservation->reservationBase = reservationBase;
1103-
virtualMemoryReservation->reservationTotalSize = reservationTotalSize;
11041065
auto lock = this->driverHandle->getMemoryManager()->lockVirtualMemoryReservationMap();
11051066
this->driverHandle->getMemoryManager()->getVirtualMemoryReservationMap().insert(std::pair<void *, NEO::VirtualMemoryReservation *>(reinterpret_cast<void *>(virtualMemoryReservation->virtualAddressRange.address), virtualMemoryReservation));
11061067
*pptr = reinterpret_cast<void *>(virtualMemoryReservation->virtualAddressRange.address);
@@ -1121,12 +1082,7 @@ ze_result_t ContextImp::freeVirtualMem(const void *ptr,
11211082
if (virtualMemoryReservation->reservationSize != size) {
11221083
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
11231084
}
1124-
NEO::AddressRange addressRange{virtualMemoryReservation->reservationBase, virtualMemoryReservation->reservationTotalSize};
1125-
if (virtualMemoryReservation->isSvmReservation) {
1126-
this->driverHandle->getMemoryManager()->freeCpuAddress(addressRange);
1127-
} else {
1128-
this->driverHandle->getMemoryManager()->freeGpuAddress(addressRange, virtualMemoryReservation->rootDeviceIndex);
1129-
}
1085+
this->driverHandle->getMemoryManager()->freeGpuAddress(virtualMemoryReservation->virtualAddressRange, virtualMemoryReservation->rootDeviceIndex);
11301086
delete virtualMemoryReservation;
11311087
this->driverHandle->getMemoryManager()->getVirtualMemoryReservationMap().erase(it);
11321088
virtualMemoryReservation = nullptr;

level_zero/core/test/unit_tests/fixtures/memory_ipc_fixture.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,6 @@ class MemoryManagerIpcMock : public NEO::MemoryManager {
212212
return MemoryConstants::pageSize64k;
213213
}
214214
void freeGpuAddress(AddressRange addressRange, uint32_t rootDeviceIndex) override{};
215-
AddressRange reserveCpuAddress(const uint64_t requiredStartAddress, size_t size) override { return {}; }
216-
void freeCpuAddress(AddressRange addressRange) override{};
217215
NEO::GraphicsAllocation *createGraphicsAllocation(OsHandleStorage &handleStorage, const NEO::AllocationData &allocationData) override { return nullptr; };
218216
NEO::GraphicsAllocation *allocateGraphicsMemoryForNonSvmHostPtr(const NEO::AllocationData &allocationData) override { return nullptr; };
219217
NEO::GraphicsAllocation *allocateGraphicsMemoryWithAlignment(const NEO::AllocationData &allocationData) override { return nullptr; };
@@ -340,8 +338,6 @@ class MemoryManagerIpcImplicitScalingMock : public NEO::MemoryManager {
340338
return MemoryConstants::pageSize64k;
341339
}
342340
void freeGpuAddress(AddressRange addressRange, uint32_t rootDeviceIndex) override{};
343-
AddressRange reserveCpuAddress(const uint64_t requiredStartAddress, size_t size) override { return {}; }
344-
void freeCpuAddress(AddressRange addressRange) override{};
345341
NEO::GraphicsAllocation *createGraphicsAllocation(OsHandleStorage &handleStorage, const NEO::AllocationData &allocationData) override { return nullptr; };
346342
NEO::GraphicsAllocation *allocateGraphicsMemoryForNonSvmHostPtr(const NEO::AllocationData &allocationData) override { return nullptr; };
347343
NEO::GraphicsAllocation *allocateGraphicsMemoryWithAlignment(const NEO::AllocationData &allocationData) override { return nullptr; };
@@ -396,4 +392,4 @@ struct MemoryExportImportImplicitScalingTest : public ::testing::Test {
396392
};
397393

398394
} // namespace ult
399-
} // namespace L0
395+
} // namespace L0

0 commit comments

Comments
 (0)