diff --git a/SYCL/Functor/kernel_functor.cpp b/SYCL/Functor/kernel_functor.cpp index ad9f4ea873..a43556d773 100644 --- a/SYCL/Functor/kernel_functor.cpp +++ b/SYCL/Functor/kernel_functor.cpp @@ -21,6 +21,27 @@ constexpr auto sycl_read_write = cl::sycl::access::mode::read_write; constexpr auto sycl_global_buffer = cl::sycl::access::target::global_buffer; // Case 1: +// - functor class is defined in an anonymous namespace +// - the '()' operator: +// * does not have parameters (to be used in 'single_task'). +// * has the 'const' qualifier +namespace { +class Functor1 { +public: + Functor1( + int X_, + cl::sycl::accessor &Acc_) + : X(X_), Acc(Acc_) {} + + void operator()() const { Acc[0] += X; } + +private: + int X; + cl::sycl::accessor Acc; +}; +} // namespace + +// Case 2: // - functor class is defined in a namespace // - the '()' operator: // * does not have parameters (to be used in 'single_task'). @@ -85,6 +106,13 @@ int foo(int X) { cl::sycl::queue Q; cl::sycl::buffer Buf(A, 1); + Q.submit([&](cl::sycl::handler &cgh) { + auto Acc = Buf.get_access(cgh); + Functor1 F(X, Acc); + + cgh.single_task(F); + }); + Q.submit([&](cl::sycl::handler &cgh) { auto Acc = Buf.get_access(cgh); ns::Functor2 F(X, Acc); @@ -143,7 +171,7 @@ template T bar(T X) { int main() { const int Res1 = foo(10); const int Res2 = bar(10); - const int Gold1 = 30; + const int Gold1 = 40; const int Gold2 = 80; assert(Res1 == Gold1);