- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I am trying to compile a simple SYCL program which runs parallel for using "Named function objects" instead of lambdas. I get a compile error which ultimately is resolved if I add "const" to the end of the overloaded () operator and I am not sure why that is the case. Could someone please point out why the "const" qualifier is needed and if there are any ways around it ?
#include <iostream>
#include <sycl/sycl.hpp>
#define SIZE 10
#define DIV 12.3
using namespace sycl;
class test_kernel
{
public:
test_kernel(int* xx, const double yy):x(xx), y(yy)
{}
void operator() (nd_item<3> itm)
{
int idx = itm.get_global_id(0);
if(idx < SIZE)
x[idx] = y/12.3;
}
private:
int* x;
double y;
};
int main()
{
queue m_que{default_selector_v};
range<3> global_range(SIZE,1,1);
range<3> local_range(SIZE,1,1);
std::cout << "Device Name: " << m_que.get_device().get_info<info::device::name>() << std::endl;
double val = DIV * 1000;
int* x = malloc_shared<int>(SIZE, m_que);
for(int i =0; i<SIZE; i++)
{
x[i] = 10;
}
m_que.parallel_for(sycl::nd_range<3>{global_range,local_range}, test_kernel{x, val}).wait();
for(int i = 0; i < SIZE; i++)
{
if(x[i] != 1000)
{
std::cout << "x[ " << i << "] = " << x[i] << " instead of " << int(val/DIV) << std::endl;
}
}
free(x, m_que);
}
Here is the compile command and error:
snarayanan@crane:builds$ icpx -fsycl -o submit_to_gpu_complex ../src/submit_to_gpu_complex.cpp
In file included from ../src/submit_to_gpu_complex.cpp:2:
In file included from /usr/people/shared/tools/rocky/9/intel_oneapi/2024.1.0/compiler/2024.1/bin/compiler/../../include/sycl/sycl.hpp:16:
In file included from /usr/people/shared/tools/rocky/9/intel_oneapi/2024.1.0/compiler/2024.1/bin/compiler/../../include/sycl/backend.hpp:27:
/usr/people/shared/tools/rocky/9/intel_oneapi/2024.1.0/compiler/2024.1/bin/compiler/../../include/sycl/handler.hpp:1540:5: error: no matching function for call to object of type 'const test_kernel'
1540 | KernelFunc(detail::Builder::getElement(detail::declptr<ElementType>()));
| ^~~~~~~~~~
/usr/people/shared/tools/rocky/9/intel_oneapi/2024.1.0/compiler/2024.1/bin/compiler/../../include/sycl/handler.hpp:1617:10: note: in instantiation of function template specialization 'sycl::handler::kernel_parallel_for<test_kernel, sycl::nd_item<3>, test_kernel>' requested here
1617 | h->kernel_parallel_for<TypesToForward..., Props...>(Args...);
| ^
/usr/people/shared/tools/rocky/9/intel_oneapi/2024.1.0/compiler/2024.1/bin/compiler/../../include/sycl/handler.hpp:1703:29: note: in instantiation of function template specialization 'sycl::handler::KernelPropertiesUnpackerImpl<>::kernel_parallel_for_unpack<test_kernel, sycl::nd_item<3>, test_kernel, test_kernel>' requested here
1703 | Unpacker.template kernel_parallel_for_unpack<KernelName, ElementType,
| ^
/usr/people/shared/tools/rocky/9/intel_oneapi/2024.1.0/compiler/2024.1/bin/compiler/../../include/sycl/handler.hpp:1699:5: note: in instantiation of function template specialization 'sycl::handler::unpack<test_kernel, test_kernel, sycl::ext::oneapi::experimental::properties<std::tuple<>>, false, (lambda at /usr/people/shared/tools/rocky/9/intel_oneapi/2024.1.0/compiler/2024.1/bin/compiler/../../include/sycl/handler.hpp:1702:21)>' requested here
1699 | unpack<KernelName, KernelType, PropertiesT,
| ^
/usr/people/shared/tools/rocky/9/intel_oneapi/2024.1.0/compiler/2024.1/bin/compiler/../../include/sycl/handler.hpp:1373:5: note: in instantiation of function template specialization 'sycl::handler::kernel_parallel_for_wrapper<test_kernel, sycl::nd_item<3>, test_kernel, sycl::ext::oneapi::experimental::properties<std::tuple<>>>' requested here
1373 | kernel_parallel_for_wrapper<NameT, TransformedArgType, KernelType,
| ^
/usr/people/shared/tools/rocky/9/intel_oneapi/2024.1.0/compiler/2024.1/bin/compiler/../../include/sycl/handler.hpp:2370:5: note: in instantiation of function template specialization 'sycl::handler::parallel_for_impl<sycl::detail::auto_name, test_kernel, 3, sycl::ext::oneapi::experimental::properties<std::tuple<>>>' requested here
2370 | parallel_for_impl<KernelName>(Range, Properties, std::move(KernelFunc));
| ^
/usr/people/shared/tools/rocky/9/intel_oneapi/2024.1.0/compiler/2024.1/bin/compiler/../../include/sycl/queue.hpp:2504:24: note: in instantiation of function template specialization 'sycl::handler::parallel_for<sycl::detail::auto_name, test_kernel, sycl::ext::oneapi::experimental::properties<std::tuple<>>, 3>' requested here
2504 | CGH.template parallel_for<KernelName>(Range, Properties, Rest...);
| ^
/usr/people/shared/tools/rocky/9/intel_oneapi/2024.1.0/compiler/2024.1/bin/compiler/../../include/sycl/queue.hpp:2519:12: note: in instantiation of function template specialization 'sycl::queue::parallel_for<sycl::detail::auto_name, 3, sycl::ext::oneapi::experimental::properties<std::tuple<>>, test_kernel &>' requested here
2519 | return parallel_for<KernelName>(
| ^
../src/submit_to_gpu_complex.cpp:43:11: note: in instantiation of function template specialization 'sycl::queue::parallel_for<sycl::detail::auto_name, 3, test_kernel>' requested here
43 | m_que.parallel_for(sycl::nd_range<3>{global_range,local_range}, test_kernel{x, val}).wait();
| ^
../src/submit_to_gpu_complex.cpp:15:9: note: candidate function not viable: 'this' argument has type 'const test_kernel', but method is not marked const
15 | void operator() (nd_item<3> itm)
| ^
1 error generated.
DPC++ compiler version:
snarayanan@crane:builds$ icpx --version
Intel(R) oneAPI DPC++/C++ Compiler 2024.1.0 (2024.1.0.20240308)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/people/shared/tools/rocky/9/intel_oneapi/2024.1.0/compiler/2024.1/bin/compiler
Configuration file: /usr/people/shared/tools/rocky/9/intel_oneapi/2024.1.0/compiler/2024.1/bin/compiler/../icpx.cfg
- Tags:
- Compile Error
- SYCL
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm escalating your question to our internal team for further investigation.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page