Opencl:从c样式指针创建UserEvent

[英]Opencl: creating UserEvent from c style pointer


I'm trying to recreate a UserEvent object from a C pointer that is returned from another part of the code:

我正在尝试从代码的另一部分返回的C指针重新创建一个UserEvent对象:

uintptr_t get_event_ptr(); // returns cl_event pointer to user event, comes from pyopencl


uintptr_t evt_ptr = get_event_ptr();

Events in C++ have the following constructor:

C ++中的事件具有以下构造函数:

Event (const cl_event &event, bool retainObject=false)

But UserEvents have no such constructor. All they have is:

但是UserEvents没有这样的构造函数。他们只有:

UserEvent (const Context &context, cl_int *err=NULL)
UserEvent ()

I've tried doing a static cast, a reinterpret cast and a dynamic cast, to no avail:

我试过做静态演员,重新演绎演员和动态演员,但无济于事:

dynamic_cast

cl::UserEvent* ue = dynamic_cast<cl::UserEvent*> (new cl::Event(*((const cl_event*) evt_ptr)));

error: 'cl::Event' is not polymorphic

static_cast

cl::UserEvent* ue = static_cast<cl::UserEvent*> (new cl::Event(*((const cl_event*) evt_ptr)));

ue->setStatus(CL_COMPLETE);

Segmentation fault: 11

reinterpret_cast

cl::UserEvent* ue = reinterpret_cast<cl::UserEvent*> (new cl::Event(*((const cl_event*) evt_ptr)));

ue->setStatus(CL_COMPLETE);

Segmentation fault: 11

using parent constructor

使用父构造函数

cl::UserEvent* ue = new cl::UserEvent((const cl_event&)(*((const cl_event*) evt_ptr)));

error: no matching constructor for initialization of 'cl::UserEvent'

How can I recreate the UserEvent from a C pointer?

如何从C指针重新创建UserEvent?

1 个解决方案

#1


0  

cl_event is typedef'd as a pointer, not an opencl abstract type. Therefore, it should be set AS evt_ptr, and not as *evt_ptr.

cl_event是typedef'd作为指针,而不是opencl抽象类型。因此,它应该设置为AS evt_ptr,而不是* evt_ptr。

cl::UserEvent* ue = static_cast<cl::UserEvent*> (new cl::Event((cl_event) evt_ptr));

ue->setStatus(CL_COMPLETE);

works just fine

工作得很好

智能推荐

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.itdaan.com/blog/2017/06/22/33bfc8c810a2a68e56f2015ddf1df15a.html



 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告