英文:
How to release a cl::Context object [c++ API] - cannot convert ‘cl::Context’ to ‘cl_context’
问题
我正在使用OpenCL代码,并且想要释放几个OpenCL对象。更确切地说,我想要释放以下对象:
extern cl::Context context;
extern cl::CommandQueue q;
extern cl::Program program;
extern cl::Kernel kernel_k;
extern cl::Event kernel_e;
extern vector<cl::Event> r_events;
extern cl::Buffer *buffer_a;
然而,当我运行以下代码时:
clReleaseCommandQueue(q);
clReleaseContext(context);
我得到以下错误:
error: cannot convert ‘cl::CommandQueue’ to ‘cl_command_queue’ {aka ‘_cl_command_queue*’}
clReleaseCommandQueue(q);
error: cannot convert ‘cl::Context’ to ‘cl_context’ {aka ‘_cl_context*’}
clReleaseContext(context);
我假设我正在使用的函数是来自OpenCL C API,而我创建的对象来自C++ API。如何使用C++ API 成功释放OpenCL 对象?
英文:
I am using an OpenCL code, and I want to release several OpenCL objects. To be more exact I want to release the following objects:
extern cl::Context context;
extern cl::CommandQueue q;
extern cl::Program program;
extern cl::Kernel kernel_k;
extern cl::Event kernel_e;
extern vector<cl::Event> r_events;
extern cl::Buffer *buffer_a;
However, when I run:
clReleaseCommandQueue(q);
clReleaseContext(context);
I obtain:
error: cannot convert ‘cl::CommandQueue’ to ‘cl_command_queue’ {aka ‘_cl_command_queue*’}
clReleaseCommandQueue(q);
error: cannot convert ‘cl::Context’ to ‘cl_context’ {aka ‘_cl_context*’}
clReleaseContext(context);
I assume that the functions that I am using to realise the OpenCL objects are from OpenCL C API, and the objects that I have created are from C++ API. How can I realise the OpenCL object successfully with C++ API?
答案1
得分: 1
使用括号()运算符从C++绑定对象中获取C绑定指针:
clReleaseCommandQueue(q());
clReleaseContext(context());
请注意,一旦C++对象超出范围,它们将自动释放。
英文:
Use the brackets() operator to get the C-bindings pointers from the C++ bindings objects:
clReleaseCommandQueue(q());
clReleaseContext(context());
Note that the C++ objects are automatically released once they go out of scope.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论