boost::compute copy custom structures

402 Views Asked by At

Is it possible to copy arrays of custom structures using boost::compute? E.g.

struct A { float a; };
struct AB { float a; float b; };

BOOST_COMPUTE_ADAPT_STRUCT(A, A, (a))
BOOST_COMPUTE_ADAPT_STRUCT(AB, AB, (a, b))

boost::compute::vector<A> va(100);
boost::compute::vector<AB> vab(100);
boost::compute::copy(va.begin(), va.end(), vab.begin());
1

There are 1 best solutions below

4
On

Yes, look at this example from Boost.Compute tests. Remember that:

Due to differences in struct padding between the host compiler and the device compiler, the BOOST_COMPUTE_ADAPT_STRUCT() macro requires that the adapted struct is packed (i.e. no padding bytes between members).

Source: boost/compute/types/struct.hpp