如何释放一个cl::Context对象 [C++ API] – 无法将’cl::Context’转换为’cl_context’

huangapple go评论45阅读模式
英文:

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&lt;cl::Event&gt; 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.

huangapple
  • 本文由 发表于 2023年6月22日 19:29:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/76531429.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定