boostorg / compute

A C++ GPU Computing Library for OpenCL
http://boostorg.github.io/compute/
Boost Software License 1.0
1.56k stars 332 forks source link

Why I cannot get result from boost::compute::function make_function_from_source #846

Open Baiyun-u-smartAI opened 4 years ago

Baiyun-u-smartAI commented 4 years ago

`using namespace boost;

using compute::int_;
// get default device and setup context
compute::device device = compute::system::default_device();
compute::context context(device);
compute::command_queue queue(context, device);

// point coordinates
int a[]={2};

// create vector for five points
compute::vector<int_> vector(1, context);

// copy point data to the device
compute::copy(
        reinterpret_cast<int *>(a),
        reinterpret_cast<int *>(a) + 1,
        vector.begin(),
        queue
);

compute::vector<int_> out(1, context);
boost::compute::function<int (int)> add_four =
        boost::compute::make_function_from_source<int (int)>(
                "add_four",
                "int add_four(int x) { return x + 4; }"
        );

boost::compute::transform(vector.begin(), vector.end(), out.begin(), add_four, queue);
cout<<out[0];`