Problems with 'parallel_for'. ComputeCpp does not recognize "parallel_for"

Hello everyone.

I’m Juan and I’m currently learning SYCL through ComputeCpp. I did this code:

#include<CL/sycl.hpp>
#include<iostream>


// SYCL code
// Juan J. Garcia
class mat_add;

int main (){
    cl::sycl::gpu_selector device;
    cl::sycl::queue Q{device};
    std::cout << "Running on "
    << Q.get_device().get_info<sycl::info::device::name>()
    << "\n";
    //Create a buffer of 4 doubles and initialize it from a host pointer
    double mat1[4] = {1.2,2.2,3.3,4.4};
    double mat2[4] = {1.2,2.2,3.3,4.4};
    double mat3[4] = {0.0,0.0,0.0,0.0};
    constexpr int N = 4;
    {
        cl::sycl::buffer<double, 1> buff1{mat1, cl::sycl::range<1>{4}};
        cl::sycl::buffer<double, 1> buff2{mat2, cl::sycl::range<1>{4}};
       cl::sycl::buffer<double, 1> buff3{mat3, cl::sycl::range<1>{4}};


    //
        Q.submit([&](cl::sycl::handler &cgh){

            auto acc_mat1 = buff1.get_access<cl::sycl::access::mode::read>(cgh);// Accessor for Mat1
            auto acc_mat2 = buff2.get_access<cl::sycl::access::mode::read>(cgh); //Accessor for mat2
            auto acc_mat3 = buff3.get_access<cl::sycl::access::mode::write>(cgh); //Accessor for mat3


            cgh.parallel_for<class mat_add>(N, [=](cl::sycl::id<1> index){

                    acc_mat3[index] = acc_mat1[index] + acc_mat2[index];
               });


       });

    }

    for(int i=0; i<4; i++)
            std::cout<<"mat3 = "<<mat3[i]<<std::endl;
    return 0;
}

I compiled this using:

compute++ accessors.cpp -o accessors -I /usr/local/computecpp/include/ -lOpenCL -L /usr/local/computecpp/lib/ -lComputeCpp -IOpenCL-Headers/ -sycl-driver -sycl-target ptx64

but i returns this error:

accessors.cpp:37:7: error: no matching member function for call to 'parallel_for'
            cgh.parallel_for(N,[=](cl::sycl::id<1> index){
            ~~~~^~~~~~~~~~~~
 /usr/local/computecpp/include/SYCL/apis.h:1425:8: note: candidate template ignored: could not      match 'nd_range<dimensions>' against 'const int'
 void parallel_for(const nd_range<dimensions>& ndRange,
   ^
/usr/local/computecpp/include/SYCL/apis.h:1428:8: note: candidate template ignored: could not match 'range<dimensions>' against 'const int'
void parallel_for(const range<dimensions>& range,
   ^
 /usr/local/computecpp/include/SYCL/apis.h:1442:8: note: candidate template ignored: could not     match 'nd_range<dimensions>' against 'const int'
  void parallel_for(const nd_range<dimensions>& ndRange, kernel syclKernel) {}
   ^
/usr/local/computecpp/include/SYCL/apis.h:1446:8: note: candidate template ignored: could not match 'range<dimensions>' against 'const int'
void parallel_for(const range<dimensions>& range, kernel syclKernel) {}
   ^
  /usr/local/computecpp/include/SYCL/apis.h:1482:8: note: candidate template ignored: could not  match 'nd_range<dimensions>' against 'const int'
   void parallel_for(const nd_range<dimensions>& ndRange,
   ^
  /usr/local/computecpp/include/SYCL/apis.h:1511:8: note: candidate template ignored: could not match 'range<dimensions>' against 'const int'
void parallel_for(const range<dimensions>& range, const functorT& functor) {
   ^
/usr/local/computecpp/include/SYCL/apis.h:1431:8: note: candidate function template not viable: requires 3 arguments, but 2 were provided
void parallel_for(const range<dimensions>& range,
  ^
 /usr/local/computecpp/include/SYCL/apis.h:1450:8: note: candidate function template not viable: requires 3 arguments, but 2 were provided
 void parallel_for(const range<dimensions>& range,
   ^
/usr/local/computecpp/include/SYCL/apis.h:1473:8: note: candidate function template not viable: requires 3 arguments, but 2 were provided
 void parallel_for(kernel syclKernel, const nd_range<dimensions>& ndRange,
   ^
   /usr/local/computecpp/include/SYCL/apis.h:1492:8: note: candidate function template not viable: requires 3 arguments, but 2 were provided
 void parallel_for(kernel syclKernel, const range<dimensions>& range,
   ^
  /usr/local/computecpp/include/SYCL/apis.h:1501:8: note: candidate function template not viable: requires 4 arguments, but 2 were provided
  void parallel_for(kernel syclKernel, const range<dimensions>& globalRange,
   ^
 /usr/local/computecpp/include/SYCL/apis.h:1520:8: note: candidate function template not viable: requires 3 arguments, but 2 were provided
void parallel_for(const range<dimensions>& globalRange,

Sorry for the bunch of error messages, but i think it’s important to be explicit.

Any idea of why is this happening?

this is my ComputeCpp version:

Codeplay ComputeCpp - CE 2.0.0 Device Compiler - clang version 8.0.0  (based on LLVM 8.0.0svn)

It looks like a header issue, I’m just trying to figure it out. I would also suggest you could use the CMake file we use with the samples on GitHub. You can find this here. This will look in all the right places for the correct headers and library files.

@nullpointer Your code is not compiling because the signature of parallel_for requires a cl::sycl::range as the first parameter and you are passing an int. To fix it just change

cgh.parallel_for<class mat_add>(N, [=](cl::sycl::id<1> index){

to

cgh.parallel_for<class mat_add>(cl::sycl::range<1>(N), [=](cl::sycl::id<1> index){

Also, since you are declaring the kernel name mat_add at the top of the file, you can remove the class keyword from the parallel for invocation

cgh.parallel_for<mat_add>(cl::sycl::range<1>(N), [=](cl::sycl::id<1> index){
2 Likes

Hey! it worked!! thank you so much! I’ll never forget your advice!