Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I return a custom struct from a BOOST_COMPUTE_FUNCTION #863

Open
phillvancejr opened this issue May 18, 2021 · 0 comments
Open

How can I return a custom struct from a BOOST_COMPUTE_FUNCTION #863

phillvancejr opened this issue May 18, 2021 · 0 comments

Comments

@phillvancejr
Copy link

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?

struct pixel {
  int r, g, b, a;
};

BOOST_COMPUTE_ADAPT_STRUCT(pixel, pixel, (r,g,b,a))

//main


vector<pixel> image1( size, pixel{0,0,0,1});
vector<pixel> image2( size, pixel{1,0,0,1});
vector<pixel> 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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant