From 04803387f4010fd32d5f0c2c0ff812e39369fa69 Mon Sep 17 00:00:00 2001 From: Chris Sullivan Date: Mon, 14 Jun 2021 14:57:48 -0700 Subject: [PATCH] Add check to only cast opaque handles to cl::BufferDescriptor at runtime. --- src/runtime/opencl/opencl_module.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/runtime/opencl/opencl_module.cc b/src/runtime/opencl/opencl_module.cc index 397f57b36dad..7944178f6bee 100644 --- a/src/runtime/opencl/opencl_module.cc +++ b/src/runtime/opencl/opencl_module.cc @@ -64,8 +64,13 @@ class OpenCLWrappedFunc { } // setup arguments. for (cl_uint i = 0; i < arg_size_.size(); ++i) { - auto* arg = static_cast(void_args[i]); - OPENCL_CALL(clSetKernelArg(kernel, i, arg_size_[i], arg->buffer)); + void* arg = nullptr; + if (args.type_codes[i] == DLDataTypeCode::kDLOpaqueHandle) { + arg = static_cast(void_args[i])->buffer; + } else { + arg = void_args[i]; + } + OPENCL_CALL(clSetKernelArg(kernel, i, arg_size_[i], arg)); } cl_command_queue queue = w_->GetQueue(t->device); ThreadWorkLoad wl = thread_axis_cfg_.Extract(args);