|
Bugzilla – Full Text Bug Listing |
| Summary: | Feedback on OpenCL C++ bindings | ||
|---|---|---|---|
| Product: | OpenCL | Reporter: | thomas7755 |
| Component: | Man Pages, Reference Card & Other Documentation | Assignee: | Benedict Gaster <bgaster> |
| Status: | ASSIGNED --- | QA Contact: | OpenCL Working Group <opencl> |
| Severity: | normal | ||
| Priority: | P3 | CC: | devrel, stapostol |
| Version: | unspecified | ||
| Target Milestone: | --- | ||
| Hardware: | All | ||
| OS: | All | ||
Reassign to Benedict. I have updated the C++ bindings to provide copy constructor for KernelFunctor and the following program now compiles without error:
#include <CL/cl.hpp>
int main(void)
{
std::vector<cl::CommandQueue> commandQueues;
cl::Kernel kernel;
cl::NDRange globalNDRange;
cl::NDRange localNDRange;
std::vector<cl::KernelFunctor> kernelFunctors;
for (int d = 0 ; d < commandQueues.size() ; d++) {
kernelFunctors.push_back(
kernel.bind(
commandQueues[d],
globalNDRange,
localNDRange));
}
}
Please let me know if you have any problems using it and thanks for feedback.
This doesn't work as hoped unfortunately. The KernelFunctor has a reference to a Kernel and a CommandQueue, and so strange things start happening when you try reseat the reference in the assignment operator.
I can get the original code to execute by changing the copy constructor to:
inline KernelFunctor::KernelFunctor(const KernelFunctor& rhs) :
kernel_(rhs.kernel_),
queue_(rhs.queue_),
offset_(rhs.offset_),
global_(rhs.global_),
local_(rhs.local_),
err_(rhs.err_)
{
//*this = rhs;
}
(i.e. complete the initializer list and remove the call to the assignment operator)
In this case the assignment operator is never called, but it must still be present as stl::vectors mandate it. Perhaps the assignment operator should fail if rhs != lhs. KernelFunctor could maintain a pointer instead of a reference, but that's possibly not as elegant.
Indeed. Let me think about this some more and I will get back with a solution. Might be best to simply remove the reference. I do not what to have pointers. (In reply to comment #4) > Indeed. Let me think about this some more and I will get back with a solution. > Might be best to simply remove the reference. I do not what to have pointers. Have you had any thoughts on this? I agree it would be preferable to avoid pointers. My suggestion would be to provide the corrected copy constructor and make the assignment illegal. I'm working on fix for this, not using ponters, and will update the C++ bindings with some other fixes in the next few days. |
When handling multiple devices it would be handy to be able to maintain a vector of kernel functors, where each functor is associated with a command queue: std::vector<cl::KernelFunctor> kernelFunctors; for (int d = 0 ; d < commandQueues.size() ; d++) { kernelFunctors.push_back(kernel.bind(commandQueues[d], globalNDRange, localNDRange)); } Any ideas for how to implement something like this, given that this won't work without being able to copy KernelFunctors?