SWDEV-258754 Fix seg fault hipMemset with device pointer mapped from hipHostRegister
Change-Id: Ifab66b67df172812ebb6eb25c2bac71821f4d614
Этот коммит содержится в:
@@ -30,14 +30,23 @@
|
||||
amd::Memory* getMemoryObject(const void* ptr, size_t& offset) {
|
||||
amd::Memory *memObj = amd::MemObjMap::FindMemObj(ptr);
|
||||
if (memObj != nullptr) {
|
||||
if (memObj->getSvmPtr() != nullptr) {
|
||||
// SVM pointer
|
||||
offset = reinterpret_cast<size_t>(ptr) - reinterpret_cast<size_t>(memObj->getSvmPtr());
|
||||
} else if (memObj->getHostMem() != nullptr) {
|
||||
// Prepinned memory
|
||||
offset = reinterpret_cast<size_t>(ptr) - reinterpret_cast<size_t>(memObj->getHostMem());
|
||||
} else {
|
||||
ShouldNotReachHere();
|
||||
const char* hostPtr = reinterpret_cast<const char*>(ptr);
|
||||
const char* hostMem = reinterpret_cast<const char*>(memObj->getHostMem());
|
||||
//Prepinned memory
|
||||
if ((hostMem != nullptr) &&
|
||||
(hostPtr >= hostMem && hostPtr <= (hostMem + memObj->getSize()))) {
|
||||
offset = reinterpret_cast<size_t>(hostPtr) - reinterpret_cast<size_t>(hostMem);
|
||||
}
|
||||
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);
|
||||
}
|
||||
else {
|
||||
ShouldNotReachHere();
|
||||
}
|
||||
}
|
||||
}
|
||||
return memObj;
|
||||
|
||||
@@ -111,6 +111,35 @@ int main(int argc, char* argv[]) {
|
||||
delete [] Ad;
|
||||
}
|
||||
|
||||
if (p_tests & 0x3) {
|
||||
float *A, **Ad;
|
||||
int num_devices;
|
||||
HIPCHECK(hipGetDeviceCount(&num_devices));
|
||||
Ad = new float*[num_devices];
|
||||
A = (float*)malloc(size);
|
||||
HIPCHECK(hipHostRegister(A, size, 0));
|
||||
|
||||
for (int i = 0; i < N; i++) {
|
||||
A[i] = float(1);
|
||||
}
|
||||
|
||||
for (int i = 0; i < num_devices; i++) {
|
||||
HIPCHECK(hipSetDevice(i));
|
||||
HIPCHECK(hipHostGetDevicePointer((void**)&Ad[i], A, 0));
|
||||
}
|
||||
|
||||
// Reference the registered device pointer Ad in hipMemset:
|
||||
for (int i = 0; i < num_devices; i++) {
|
||||
HIPCHECK(hipSetDevice(i));
|
||||
HIPCHECK(hipMemset(Ad[i], 0, size));
|
||||
}
|
||||
HIPASSERT(A[10] == 0.0f);
|
||||
|
||||
HIPCHECK(hipHostUnregister(A));
|
||||
|
||||
free(A);
|
||||
delete [] Ad;
|
||||
}
|
||||
|
||||
if (p_tests & 0x6) {
|
||||
// Sensitize HIP bug if device does not match where the memory was registered.
|
||||
|
||||
Ссылка в новой задаче
Block a user