#include <vector>
#include <algorithm>
#include <boost/compute/system.hpp>
#include <boost/compute/algorithm/copy.hpp>
#include <boost/compute/algorithm/accumulate.hpp>
#include <boost/compute/container/vector.hpp>
#include <boost/compute/types/fundamental.hpp>
#include <boost/compute/algorithm/inclusive_scan.hpp>
//#include <boost/compute/interop/opencv/core.hpp>
//#include <boost/compute/interop/opencv/highgui.hpp>
#include <boost/compute/random/default_random_engine.hpp>
#include <boost/compute/random/uniform_real_distribution.hpp>
#include <boost/compute/utility/source.hpp>
//#define CL_USE_DEPRECATED_OPENCL_1_1_APIS
//#undef CL_VERSION_1_2
namespace compute = boost::compute;
int main()
{
// get the default compute device
compute::device gpu = compute::system::default_device();
// create a compute context and command queue
compute::context ctx(gpu);
compute::command_queue queue(ctx, gpu);
std::vector<float> host_vector(1000000);
size_t steps = 1000;
// create vector on device and populate with rng's
// calaculate random values for each step
compute::vector<float> random_vector(steps, ctx);
compute::default_random_engine random_engine(queue);
compute::uniform_real_distribution<float> random_distribution(0.f, 4.f);
random_distribution.generate(random_vector.begin(), random_vector.end(), random_engine, queue);
float result = compute::accumulate(random_vector.begin(), random_vector.end(), 0, queue);
std::cout << "before" << std::endl;
// copy data back to the host
compute::copy(
random_vector.begin(), random_vector.end(), host_vector.begin(), queue
);
std::cout << "vector: [ ";
boost::compute::copy(
host_vector.begin(), host_vector.end(),
std::ostream_iterator<float>(std::cout, ", "),
queue
);
std::cout << "]" << std::endl;
std::cout << result << std::endl;
return 0;
}
Where's the documentation for such things?