SWDEV-322620 - Virtual Memory Management
Implement hipMemAddressFree and hipMemAddressReserve Change-Id: I1b09e433db5c5c6d6b9fe2a7a15fe2c09f1e1874
This commit is contained in:
committato da
Christophe Paquot
parent
b4c5a01fbc
commit
fd17b53ea4
@@ -29,6 +29,10 @@ hipError_t hipMemAddressFree(void* devPtr, size_t size) {
|
||||
HIP_RETURN(hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
for (auto& dev: g_devices) {
|
||||
dev->devices()[0]->virtualFree(devPtr);
|
||||
}
|
||||
|
||||
HIP_RETURN(hipSuccess);
|
||||
}
|
||||
|
||||
@@ -40,6 +44,25 @@ hipError_t hipMemAddressReserve(void** ptr, size_t size, size_t alignment, void*
|
||||
HIP_RETURN(hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
*ptr = nullptr;
|
||||
|
||||
void* startAddress = addr;
|
||||
|
||||
for (auto& dev : g_devices) {
|
||||
*ptr = dev->devices()[0]->virtualAlloc(startAddress, size, alignment);
|
||||
|
||||
// if addr==0 we generate the va and use it for other devices
|
||||
if (startAddress == nullptr) {
|
||||
startAddress = *ptr;
|
||||
} else if (*ptr != startAddress) {
|
||||
// if we cannot reserve the same VA on other devices, just fail
|
||||
for (auto& d : g_devices) {
|
||||
if (d == dev) HIP_RETURN(hipErrorOutOfMemory);
|
||||
d->devices()[0]->virtualFree(startAddress);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HIP_RETURN(hipSuccess);
|
||||
}
|
||||
|
||||
|
||||
Fai riferimento in un nuovo problema
Block a user