How can I return a custom struct from a BOOST_COMPUTE_FUNCTION
- Dominant language
- C++
- Stars
- 1.7k
- Forks
- 340
- PR merge metrics
- No merged PRs in 30d
Description
Lets say I have a pixel struct and want to loop through two vectors of pixels add the components of the two pixels together and then put them in another vector, how can I return a new struct from transform?
```c++
struct pixel {
int r, g, b, a;
};
BOOST_COMPUTE_ADAPT_STRUCT(pixel, pixel, (r,g,b,a))
//main
vector image1( size, pixel{0,0,0,1});
vector image2( size, pixel{1,0,0,1});
vector result( size, pixel{0,0,0,1});
// setup up device, context, queue and device vectors ...
BOOST_COMPUTE_FUNCTION(pixel, add_images, (pixel a, pixel b),
{
pixel out;
out.r = a.r + b.r;
// etc....
return out;
});
compute::transform(
device_image1.begin(),
device_image1.end(),
device_image2.begin(),
device_result.begin(),
add_images,
queue
);
// get results...
```
How do I allocate memory for the result pixel inside the Compute Function?
Contributor guide
Assessment
This issue has not been assessed yet.