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

Is it possible to create an Boost Compute vector and wrap a vexcl vector with Compute vector? #288

Open
kafi350 opened this issue Aug 12, 2021 · 3 comments

Comments

@kafi350
Copy link

kafi350 commented Aug 12, 2021

As given in the documentation we can do it for the vexcl but not for the compute vecotrs.

@ddemidov
Copy link
Owner

Both boost.compute and vexcl vectors are just wrappers around raw opencl buffers, so the conversion is possible both ways.

@kafi350
Copy link
Author

kafi350 commented Aug 12, 2021

// Wrap boost.compute vectors into vexcl vectors (no data is copied):
compute::vector bcv(n, bcq.get_context());
vex::vector y({bcq}, bcv.get_buffer());
y = x * 2;

this is the way to wrap a compute vector but is it possible to wrap a vex vector?

@ddemidov
Copy link
Owner

See examples in <vexcl/external/boost_compute.hpp>, which uses Boost.compute algorithms with vexcl vectors:

/// Inclusive scan.
template <typename T>
void inclusive_scan(const vex::vector<T> &src, vex::vector<T> &dst) {
auto queue = src.queue_list();
// Scan partitions separately.
for(unsigned d = 0; d < queue.size(); ++d) {
if (src.part_size(d)) {
boost::compute::command_queue q( queue[d]() );
boost::compute::buffer sbuf( src(d).raw() );
boost::compute::buffer dbuf( dst(d).raw() );
boost::compute::inclusive_scan(
boost::compute::make_buffer_iterator<T>(sbuf, 0),
boost::compute::make_buffer_iterator<T>(sbuf, src.part_size(d)),
boost::compute::make_buffer_iterator<T>(dbuf, 0),
q
);
}
}
// If there are more than one partition,
// update all of them except for the first.
if (queue.size() > 1) {
std::vector<T> tail(queue.size() - 1, T());
for(unsigned d = 0; d < tail.size(); ++d) {
if (src.part_size(d))
tail[d] = dst[src.part_start(d + 1) - 1];
}
std::partial_sum(tail.begin(), tail.end(), tail.begin());
for(unsigned d = 1; d < queue.size(); ++d) {
if (src.part_size(d)) {
// Wrap partition into vector for ease of use:
vex::vector<T> part(queue[d], dst(d));
part += tail[d - 1];
}
}
}
}

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

2 participants