Permalink
Browse files

Safer work with boost.compute

  • Loading branch information...
1 parent 34c8fb8 commit 219acb31b9674e8f88c0d7797da29188db767775 @ddemidov committed Mar 20, 2013
Showing with 15 additions and 15 deletions.
  1. +5 −7 examples/boost.compute/vecsum.cpp
  2. +10 −8 vexcl/external/boost_compute.hpp
@@ -1,5 +1,3 @@
-#define BOOST_COMPUTE_DEBUG_KERNEL_COMPILATION
-
#include <vexcl/vexcl.hpp>
#include <vexcl/external/boost_compute.hpp>
@@ -28,12 +26,12 @@ int main() {
boost::compute::command_queue q( ctx.queue(0)() );
- cl::Buffer xbuf = x(0);
- cl::Buffer ybuf = y(0);
+ boost::compute::buffer xbuf( x(0)() );
+ boost::compute::buffer ybuf( y(0)() );
- auto x_begin = boost::compute::make_buffer_iterator<float>(xbuf(), 0);
- auto x_end = boost::compute::make_buffer_iterator<float>(xbuf(), n);
- auto y_begin = boost::compute::make_buffer_iterator<float>(ybuf(), 0);
+ auto x_begin = boost::compute::make_buffer_iterator<float>(xbuf, 0);
+ auto x_end = boost::compute::make_buffer_iterator<float>(xbuf, n);
+ auto y_begin = boost::compute::make_buffer_iterator<float>(ybuf, 0);
prof.tic_cl("compute");
for(size_t i = 0; i < m; ++i) {
@@ -37,6 +37,7 @@ THE SOFTWARE.
namespace vex {
+/// \cond INTERNAL
template <typename T>
void scan(const vex::vector<T> &src, vex::vector<T> &dst, bool exclusive = false) {
auto queue = src.queue_list();
@@ -46,13 +47,13 @@ void scan(const vex::vector<T> &src, vex::vector<T> &dst, bool exclusive = false
if (src.part_size(d)) {
boost::compute::command_queue q( queue[d]() );
- cl::Buffer sbuf = src(d);
- cl::Buffer dbuf = dst(d);
+ boost::compute::buffer sbuf( src(d)() );
+ boost::compute::buffer dbuf( dst(d)() );
boost::compute::detail::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),
+ 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),
exclusive && (d == 0), q
);
}
@@ -79,6 +80,7 @@ void scan(const vex::vector<T> &src, vex::vector<T> &dst, bool exclusive = false
}
}
}
+/// \endcond
/// Inclusive scan.
template <typename T>
@@ -104,11 +106,11 @@ void sort(vex::vector<T> &x) {
for(unsigned d = 0; d < queue.size(); ++d) {
if (x.part_size(d)) {
boost::compute::command_queue q( queue[d]() );
- cl::Buffer buf = x(d);
+ boost::compute::buffer buf( x(d)() );
boost::compute::sort(
- boost::compute::make_buffer_iterator<T>(buf(), 0),
- boost::compute::make_buffer_iterator<T>(buf(), x.part_size(d)),
+ boost::compute::make_buffer_iterator<T>(buf, 0),
+ boost::compute::make_buffer_iterator<T>(buf, x.part_size(d)),
q
);
}

0 comments on commit 219acb3

Please sign in to comment.