From 1b4bbfcb53089c4a591f394816da220d44aaafde Mon Sep 17 00:00:00 2001 From: Saleel Kudchadker Date: Fri, 20 Mar 2020 10:53:23 -0700 Subject: [PATCH] Sync streams when freeing or destroying mem Change-Id: I6932f225a8b932bb2adbd5e37880f7e604496809 [ROCm/hip commit: 8b39e0b74e1d8833cb2d0d0b6f04e369afed1d8a] --- projects/hip/vdi/hip_memory.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/projects/hip/vdi/hip_memory.cpp b/projects/hip/vdi/hip_memory.cpp index 6233c15a38..b38c2dbdbc 100644 --- a/projects/hip/vdi/hip_memory.cpp +++ b/projects/hip/vdi/hip_memory.cpp @@ -274,6 +274,13 @@ hipError_t hipHostFree(void* ptr) { HIP_INIT_API(hipHostFree, ptr); if (amd::SvmBuffer::malloced(ptr)) { + for (auto& dev : g_devices) { + amd::HostQueue* queue = hip::getNullStream(*dev->asContext()); + if (queue != nullptr) { + queue->finish(); + } + hip::syncStreams(dev->deviceId()); + } amd::SvmBuffer::free(*hip::getCurrentDevice()->asContext(), ptr); HIP_RETURN(hipSuccess); } @@ -289,7 +296,13 @@ hipError_t ihipArrayDestroy(hipArray* array) { if (is_valid(memObj) == false) { return hipErrorInvalidValue; } - + for (auto& dev : g_devices) { + amd::HostQueue* queue = hip::getNullStream(*dev->asContext()); + if (queue != nullptr) { + queue->finish(); + } + hip::syncStreams(dev->deviceId()); + } as_amd(memObj)->release(); delete array;