Compile error: reference to non-static member function must be called

Hello, I’m trying to build a SYCL application but I’m having some problems with the buffers, depending on how I specify the buffer’s data type either the program runs or it fails to compile at the line of the ‘get_access’ call. I’ll provide a simplified source code bellow.

Source code
template <typename C1_T>
void test(C1_T &input) {
    auto size = input.size();
    using container_t = typename C1_T::value_type;
    sycl::queue queue{sycl::host_selector()};
    sycl::buffer<container_t> buffer (input.data(), sycl::range<1>{size});
    queue.submit([&] (sycl::handler &cgh) {
        auto acc = buffer.get_access<sycl::access::mode::read_write>(cgh);
        cgh.parallel_for<class map_func>(sycl::range<1>{size}, [=] (sycl::id<1> index) {
           acc[index] += 1;
        });
    });
    queue.wait();
}

int main() {
    std::vector<int> vec = {1,2,3,4};
    test(vec);
}

I’m trying to infer the type of the data from containers like std vector or std array. However while trying to compile the code I get the following error:

Error
error: reference to non-static member function must be called
        auto acc = buffer.get_access<sycl::access::mode::read_write>(cgh);

Now if I replace ‘container_t’ by ‘int’ at the line:

sycl::buffer<container_t> buffer (input.data(), sycl::range<1>{size});

Now the code compiles and runs successfully.

I’d like to avoid adding extra parameters to the template function ‘test’. Any help is appreciated, and thank you for your time.

Hi Yago,

I believe the error you are seeing here is due to the compiler mis-parsing the call to get_access due to a C++ context ambiguity.

If you replace the line where you call get_access to the following, that should resolve the issue.

auto acc = buffer.template get_access<sycl::access::mode::read_write>(cgh);

The reason this happens is that the type of buffer is inferred from the template parameter C1_T, which means the type of buffer is type-dependant and therefore during the first lookup phase (before the template is instantiated), the compiler doesn’t yet know the type and assumes that get_access is a non-template member rather than a template member unless you specify the template keyword.

If you’re interested I wrote a blog post a while back that goes into this in more detail - http://www.aerialmantis.co.uk/blog/2017/03/17/template-keywords/

I hope this helps.

Gordon

2 Likes

Hello Gordon,

Thank you very much for your solution, it completely resolved the issue. I’ll make sure to read your blog post. Once again, thank you for your time.

Best regards.