aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/CL/CLMemoryRegion.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/runtime/CL/CLMemoryRegion.cpp')
-rw-r--r--src/runtime/CL/CLMemoryRegion.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/runtime/CL/CLMemoryRegion.cpp b/src/runtime/CL/CLMemoryRegion.cpp
index 380e4062ee..00f91a0ffb 100644
--- a/src/runtime/CL/CLMemoryRegion.cpp
+++ b/src/runtime/CL/CLMemoryRegion.cpp
@@ -72,6 +72,14 @@ CLBufferMemoryRegion::CLBufferMemoryRegion(const cl::Buffer &buffer)
_mem = buffer;
}
+CLBufferMemoryRegion::~CLBufferMemoryRegion()
+{
+ // Flush the command queue to ensure all commands that may use this memory buffer are scheduled to be finished before
+ // this buffer is freed
+ // Do not call finish as it is a blocking call which affects the performance
+ CLScheduler::get().queue().flush();
+}
+
void *CLBufferMemoryRegion::ptr()
{
return nullptr;
@@ -110,6 +118,9 @@ ICLSVMMemoryRegion::~ICLSVMMemoryRegion()
{
try
{
+ // Can only use the blocking finish instead of the non-blocking flush here, because clSVMFree requires all
+ // commands that may use the svm pointer to finish beforehand
+ // https://registry.khronos.org/OpenCL/sdk/3.0/docs/man/html/clSVMFree.html
clFinish(CLScheduler::get().queue().get());
_mem = cl::Buffer();
clSVMFree(_ctx.get(), _ptr);