10
10
#include " shared/source/command_container/implicit_scaling.h"
11
11
#include " shared/source/command_stream/command_stream_receiver.h"
12
12
#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"
14
14
#include " shared/source/helpers/gfx_core_helper.h"
15
15
#include " shared/source/helpers/ptr_math.h"
16
16
#include " shared/source/memory_manager/allocation_properties.h"
17
17
#include " shared/source/memory_manager/memory_operations_handler.h"
18
18
#include " shared/source/memory_manager/unified_memory_manager.h"
19
- #include " shared/source/utilities/cpu_info.h"
20
19
21
20
#include " level_zero/api/driver_experimental/public/zex_memory.h"
22
21
#include " level_zero/core/source/cmdlist/cmdlist.h"
@@ -1048,59 +1047,21 @@ NEO::VirtualMemoryReservation *ContextImp::findSupportedVirtualReservation(const
1048
1047
ze_result_t ContextImp::reserveVirtualMem (const void *pStart,
1049
1048
size_t size,
1050
1049
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;
1092
1054
}
1093
-
1094
1055
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
+ }
1098
1061
virtualMemoryReservation->flags .readWrite = false ;
1099
1062
virtualMemoryReservation->flags .readOnly = false ;
1100
1063
virtualMemoryReservation->flags .noAccess = true ;
1101
1064
virtualMemoryReservation->reservationSize = size;
1102
- virtualMemoryReservation->reservationBase = reservationBase;
1103
- virtualMemoryReservation->reservationTotalSize = reservationTotalSize;
1104
1065
auto lock = this ->driverHandle ->getMemoryManager ()->lockVirtualMemoryReservationMap ();
1105
1066
this ->driverHandle ->getMemoryManager ()->getVirtualMemoryReservationMap ().insert (std::pair<void *, NEO::VirtualMemoryReservation *>(reinterpret_cast <void *>(virtualMemoryReservation->virtualAddressRange .address ), virtualMemoryReservation));
1106
1067
*pptr = reinterpret_cast <void *>(virtualMemoryReservation->virtualAddressRange .address );
@@ -1121,12 +1082,7 @@ ze_result_t ContextImp::freeVirtualMem(const void *ptr,
1121
1082
if (virtualMemoryReservation->reservationSize != size) {
1122
1083
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
1123
1084
}
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 );
1130
1086
delete virtualMemoryReservation;
1131
1087
this ->driverHandle ->getMemoryManager ()->getVirtualMemoryReservationMap ().erase (it);
1132
1088
virtualMemoryReservation = nullptr ;
0 commit comments