SWDEV-357246 - Fixes to return with a error code instead of segfault in alloc failure case
Change-Id: Ie18d50f2f7ef3f4b2c0153152fca057232c1f8a2
Этот коммит содержится в:
коммит произвёл
Maneesh Gupta
родитель
47a29c748a
Коммит
aeeab1c975
@@ -226,6 +226,9 @@ hipError_t ihipMallocManaged(void** ptr, size_t size, unsigned int align) {
|
||||
}
|
||||
size_t offset = 0; //this is ignored
|
||||
amd::Memory* memObj = getMemoryObject(*ptr, offset);
|
||||
if (memObj == nullptr) {
|
||||
return hipErrorMemoryAllocation;
|
||||
}
|
||||
//saves the current device id so that it can be accessed later
|
||||
memObj->getUserData().deviceId = hip::getCurrentDevice()->deviceId();
|
||||
|
||||
|
||||
@@ -43,13 +43,19 @@ amd::Memory* getMemoryObject(const void* ptr, size_t& offset, size_t size) {
|
||||
}
|
||||
else {
|
||||
//SVM ptr or device ptr mapped from host
|
||||
const void *devPtr = reinterpret_cast<void*>
|
||||
(memObj->getDeviceMemory(*memObj->getContext().devices()[0])->virtualAddress());
|
||||
if (devPtr != nullptr) {
|
||||
offset = reinterpret_cast<size_t>(ptr) - reinterpret_cast<size_t>(devPtr);
|
||||
device::Memory* devMem =
|
||||
(memObj->getDeviceMemory(*memObj->getContext().devices()[0]));
|
||||
if (devMem == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
else {
|
||||
ShouldNotReachHere();
|
||||
const void* devPtr = reinterpret_cast<void*>((devMem)->virtualAddress());
|
||||
if (devPtr != nullptr) {
|
||||
offset = reinterpret_cast<size_t>(ptr) - reinterpret_cast<size_t>(devPtr);
|
||||
}
|
||||
else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
Ссылка в новой задаче
Block a user