From 66cad62196aa83d330e87025f7aca480b82eef0e Mon Sep 17 00:00:00 2001 From: MORITA Kazutaka Date: Thu, 7 Mar 2019 13:31:50 +0900 Subject: [PATCH] [RUNTIME][OPENCL] clFinish before releasing memory (#2737) --- src/runtime/opencl/opencl_device_api.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/runtime/opencl/opencl_device_api.cc b/src/runtime/opencl/opencl_device_api.cc index 6bb0948bca91..38edcd1967cc 100644 --- a/src/runtime/opencl/opencl_device_api.cc +++ b/src/runtime/opencl/opencl_device_api.cc @@ -110,6 +110,10 @@ void* OpenCLWorkspace::AllocDataSpace( } void OpenCLWorkspace::FreeDataSpace(TVMContext ctx, void* ptr) { + // We have to make sure that the memory object is not in the command queue + // for some OpenCL platforms. + OPENCL_CALL(clFinish(this->GetQueue(ctx))); + cl_mem mptr = static_cast(ptr); OPENCL_CALL(clReleaseMemObject(mptr)); }