Skip to content

Commit c5ced8c

Browse files
authored
SWDEV-512344 - Unmap all subbuffers (#214)
1 parent a7492c5 commit c5ced8c

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

hipamd/src/hip_vm.cpp

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -354,26 +354,32 @@ hipError_t hipMemUnmap(void* ptr, size_t size) {
354354
HIP_RETURN(hipErrorInvalidValue);
355355
}
356356

357-
amd::Memory* phys_mem_obj = vaddr_sub_obj->getUserData().phys_mem_obj;
358-
if (phys_mem_obj == nullptr) {
359-
HIP_RETURN(hipErrorInvalidValue);
360-
}
357+
address end_address = reinterpret_cast<address>(vaddr_sub_obj->getSvmPtr()) + size;
358+
while (vaddr_sub_obj &&
359+
reinterpret_cast<address>(vaddr_sub_obj->getSvmPtr()) + vaddr_sub_obj->getSize() <=
360+
end_address) {
361+
amd::Memory* phys_mem_obj = vaddr_sub_obj->getUserData().phys_mem_obj;
362+
if (phys_mem_obj == nullptr) {
363+
HIP_RETURN(hipErrorInvalidValue);
364+
}
361365

362-
auto& queue = *g_devices[phys_mem_obj->getUserData().deviceId]->NullStream();
366+
amd::Command* cmd = new amd::VirtualMapCommand(
367+
*hip::getCurrentDevice()->NullStream(), amd::Command::EventWaitList{},
368+
vaddr_sub_obj->getSvmPtr(), vaddr_sub_obj->getSize(), nullptr);
363369

364-
amd::Command* cmd = new amd::VirtualMapCommand(queue, amd::Command::EventWaitList{}, ptr, size,
365-
nullptr);
366-
cmd->enqueue();
367-
cmd->awaitCompletion();
368-
cmd->release();
369-
vaddr_sub_obj->release();
370-
371-
// restore the original pa of the generic allocation
372-
hip::GenericAllocation* ga
373-
= reinterpret_cast<hip::GenericAllocation*>(phys_mem_obj->getUserData().data);
374-
ga->release();
370+
cmd->enqueue();
371+
cmd->awaitCompletion();
372+
cmd->release();
373+
// restore the original pa of the generic allocation
374+
hip::GenericAllocation* ga =
375+
reinterpret_cast<hip::GenericAllocation*>(phys_mem_obj->getUserData().data);
376+
ga->release();
377+
address next_subbuffer_ptr =
378+
reinterpret_cast<address>(vaddr_sub_obj->getSvmPtr()) + vaddr_sub_obj->getSize();
379+
vaddr_sub_obj->release();
380+
vaddr_sub_obj = amd::MemObjMap::FindMemObj(next_subbuffer_ptr);
381+
}
375382

376383
HIP_RETURN(hipSuccess);
377384
}
378385
} //namespace hip
379-

0 commit comments

Comments
 (0)