OpenCL with c ++ wrapper - 如何将cl :: CommandQueue转换为cl_command_queue?

时间:2014-05-19 16:24:32

标签: c++ opencl

我正在使用OpenCL和CL / cl.hpp c ++包装器。 所以我有c ++对象,例如cl::CommandQueue代替cl_command_queue

我也想使用AMD的BLAS库clAmdBlas。那里的函数需要cl_command_queue作为其参数之一。

如何从cl_command_queue获取cl::CommandQueue

2 个答案:

答案 0 :(得分:5)

要获取cl_command_queue对象,您只需使用()运算符:

cl::CommandQueue cppQueue;
...
cl_command_queue queue = cppQueue();

此头文件中包含OpenCL运行时对象的所有其他C ++对象也是如此。

答案 1 :(得分:4)

cl.hpp中,cl::CommandQueue定义如下:

class CommandQueue : public detail::Wrapper<cl_command_queue>

detail::Wrapper<T>定义如下:

template <typename T>
class Wrapper
{
public:
    typedef T cl_type;

protected:
    cl_type object_;

public:
    cl_type operator ()() const { return object_; }
    cl_type& operator ()() { return object_; }

    ...
};

所以你可以这样做:

cl::CommandQueue commandQueue = cl::CommandQueue(...);
cl_command_queue queue = commandQueue();