I'm following this tutorial: http://simpleopencl.blogspot.com.br/2013/06/tutorial-simple-start-with-opencl-and-c.html
and I got 3 errors:
ERROR 1) - solved
cl::Context context({default_device}); //original code
I just took off the braces and It's ok.
ERROR 2) - solved
if(program.build(default_device)!=CL_SUCCESS){
I just replace "default_device" for "all_devices" and It's ok.
ERROR 3) - not solved
sources.push_back({kernel_code.c_str(),kernel_code.length()});
I don't know what to do. Visual Studio is pointing this error message: "IntelliSense: expected an expression"
Here is the piece of the code I'm talking about:
cl::Device default_device = all_devices[0];
std::cout<< "Using device: "<<default_device.getInfo<CL_DEVICE_NAME>()<<"\n";
cl::Context context(default_device);
cl::Program::Sources sources;
// kernel calculates for each element C=A+B
std::string kernel_code=
"void kernel simple_add(global const int* A, global const int* B, global int* C)"
"{"
"C[get_global_id(0)]=A[get_global_id(0)]+B[get_global_id(0)];"
"}";
sources.push_back({kernel_code.c_str(),kernel_code.length()});
cl::Program program(context,sources);
if(program.build(all_devices)!=CL_SUCCESS){
std::cout<<" Error building: "<<program.getBuildInfo<CL_PROGRAM_BUILD_LOG>(default_device)<<"\n";
exit(1);
}
sources.push_back({kernel_code.c_str(),kernel_code.length()});
Could be written as
sources.push_back(
{
kernel_code.c_str(),kernel_code.length()
}
);
In between the curly brackets its expecting an expression, something that ends with ;. Thats what your error is telling you.
Now i dont know how Sources is defined but here in these brackets
sources.push_back(...);
you have to specify a variable of whatever type sources consists of, so it can be added (pushed back)
This is an example of a std::vector<int> that consists of ints
std::vector<int> myvector;
myvector.push_back(42);
Sources probably works in a similar way
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With