I'm currently exploring boost_compute. Unfortunately there are less documentation pages and examples, than I need to understand what to do.
Given the following minified code:
BOOST_COMPUTE_FUNCTION(bool, add, (int* values, int* results, int constant),
{
// Whats the indexing variable?
// In opencl it would be get_global_id(0)
int index = // ?
results[index] = values[index] + values[index + 1] + values[index + 2] + constant;
});
void compute(float* results, compute::context* ctx, compute::command_queue* queue)
{
compute::vector<float> device_values(100, *ctx);
compute::vector<float> device_results(98, *ctx);
compute::copy(
parameters->values.begin(), parameters->values.end(), device_values.begin(), *queue
);
// Actual computation
// HOW TO CALL 'add' for every device_results element?
compute::copy(
device_results.begin(), device_results.end(), results, *queue
);
}
How to call the 'add' function and what's the iterating variable inside of this function? Furthermore I need this structure of code to make more complex calculation.
Kind Regards, Toni
In short
boost:compute
functions are notOpenCL
kernel functions. They are more likeOpenGL
kernel functions.I believe that your function takes too many parameters to be used with the
boost:compute
algorithms.However, a slightly simpler function, just adding adjacent values without the constant, would be:
And could be called using
boost::compute::transform
as @ddemidov suggested:It may be possible to implement your function using
boost::compute::lambda
functions. e.g.:But it's still short of a set of values...
Your function could be written as an
OpenCL
kernel inboost:compute
using theBOOST_COMPUTE_STRINGIZE_SOURCE
macro:After you've built your kernel program and created your kernel (using
boost::compute::program
), you can set the kernel arguments individually and call theboost::compute::command_queue
enqueue_1d_range_kernel
function: