'cannot capture the struct value inside of the kernal function

It is so strange and I am struggling with this problem for the whole week. I just want to use the variable which is defined inside of the struct constructor, but fail to do that. The simple code is here:

#include <CL/sycl.hpp>
#include <fstream>
#include <cstdlib>
#include <stdio.h>
#include <stdlib.h>

#define ghost 3
using namespace cl::sycl;

struct test
{
    int ls[3];
    queue Q{};
    test()
    {
        ls[0] = ghost;
        ls[1] = ghost;
        ls[2] = ghost;
    }
    void calculate();
};

void test::calculate()
{
    size_t lx = 10;
    size_t ly = 10;

    auto abc = Q.submit([&](handler &h)
                        {
        sycl::stream out(1024, 256, h);
        h.parallel_for(range{lx, ly}, [=, lsq = this->ls](id<2> idx)
                       { out << "this is id1" << lsq[1] << "\n"; }); });
}

int main()
{
    test t1;
    t1.calculate();
    return 0;
}

Someone from the DPC++ community told me this method to capture this pointer, but I don't why it does not work well.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source