diff --git a/sycl/include/CL/sycl/queue.hpp b/sycl/include/CL/sycl/queue.hpp index 77ce1fab86474..20ff09eee99c7 100644 --- a/sycl/include/CL/sycl/queue.hpp +++ b/sycl/include/CL/sycl/queue.hpp @@ -432,10 +432,9 @@ class __SYCL_EXPORT queue { /// \param NumWorkItems is a range that specifies the work space of the kernel /// \param KernelFunc is the Kernel functor or lambda /// \param CodeLoc contains the code location of user code - template + template event parallel_for( - range NumWorkItems, KernelType KernelFunc + range<1> NumWorkItems, KernelType KernelFunc #ifndef DISABLE_SYCL_INSTRUMENTATION_METADATA , const detail::code_location &CodeLoc = detail::code_location::current() @@ -444,12 +443,47 @@ class __SYCL_EXPORT queue { #ifdef DISABLE_SYCL_INSTRUMENTATION_METADATA const detail::code_location &CodeLoc = {}; #endif - return submit( - [&](handler &CGH) { - CGH.template parallel_for(NumWorkItems, - KernelFunc); - }, - CodeLoc); + return parallel_for_impl(NumWorkItems, KernelFunc, CodeLoc); + } + + /// parallel_for version with a kernel represented as a lambda + range that + /// specifies global size only. + /// + /// \param NumWorkItems is a range that specifies the work space of the kernel + /// \param KernelFunc is the Kernel functor or lambda + /// \param CodeLoc contains the code location of user code + template + event parallel_for( + range<2> NumWorkItems, KernelType KernelFunc +#ifndef DISABLE_SYCL_INSTRUMENTATION_METADATA + , + const detail::code_location &CodeLoc = detail::code_location::current() +#endif + ) { +#ifdef DISABLE_SYCL_INSTRUMENTATION_METADATA + const detail::code_location &CodeLoc = {}; +#endif + return parallel_for_impl(NumWorkItems, KernelFunc, CodeLoc); + } + + /// parallel_for version with a kernel represented as a lambda + range that + /// specifies global size only. + /// + /// \param NumWorkItems is a range that specifies the work space of the kernel + /// \param KernelFunc is the Kernel functor or lambda + /// \param CodeLoc contains the code location of user code + template + event parallel_for( + range<3> NumWorkItems, KernelType KernelFunc +#ifndef DISABLE_SYCL_INSTRUMENTATION_METADATA + , + const detail::code_location &CodeLoc = detail::code_location::current() +#endif + ) { +#ifdef DISABLE_SYCL_INSTRUMENTATION_METADATA + const detail::code_location &CodeLoc = {}; +#endif + return parallel_for_impl(NumWorkItems, KernelFunc, CodeLoc); } /// parallel_for version with a kernel represented as a lambda + range that @@ -716,6 +750,25 @@ class __SYCL_EXPORT queue { /// A template-free version of submit. event submit_impl(function_class CGH, queue secondQueue, const detail::code_location &CodeLoc); + + /// parallel_for_impl with a kernel represented as a lambda + range that + /// specifies global size only. + /// + /// \param NumWorkItems is a range that specifies the work space of the kernel + /// \param KernelFunc is the Kernel functor or lambda + /// \param CodeLoc contains the code location of user code + template + event parallel_for_impl( + range NumWorkItems, KernelType KernelFunc, + const detail::code_location &CodeLoc = detail::code_location::current()) { + return submit( + [&](handler &CGH) { + CGH.template parallel_for(NumWorkItems, + KernelFunc); + }, + CodeLoc); + } }; } // namespace sycl diff --git a/sycl/test/basic_tests/queue.cpp b/sycl/test/basic_tests/queue/queue.cpp similarity index 100% rename from sycl/test/basic_tests/queue.cpp rename to sycl/test/basic_tests/queue/queue.cpp diff --git a/sycl/test/basic_tests/queue/queue_parallel_for_generic.cpp b/sycl/test/basic_tests/queue/queue_parallel_for_generic.cpp new file mode 100644 index 0000000000000..7af89c5357c3a --- /dev/null +++ b/sycl/test/basic_tests/queue/queue_parallel_for_generic.cpp @@ -0,0 +1,74 @@ +// XFAIL: cuda +// piextUSM*Alloc functions for CUDA are not behaving as described in +// https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/USM/USM.adoc +// https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/USM/cl_intel_unified_shared_memory.asciidoc +// +// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out +// RUN: env SYCL_DEVICE_TYPE=HOST %t.out +// RUN: %ACC_RUN_PLACEHOLDER %t.out +// RUN: %CPU_RUN_PLACEHOLDER %t.out +// RUN: %GPU_RUN_PLACEHOLDER %t.out + +//==- queue_parallel_for_generic.cpp - SYCL queue parallel_for generic lambda -=// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===------------------------------------------------------------------------===// + +#include +#include +#include + +int main() { + sycl::queue q{}; + auto dev = q.get_device(); + auto ctx = q.get_context(); + constexpr int N = 8; + + if (!dev.get_info()) { + return 0; + } + + auto A = static_cast(sycl::malloc_shared(N * sizeof(int), dev, ctx)); + + for (int i = 0; i < N; i++) { + A[i] = 1; + } + + q.parallel_for(N, [=](auto i) { + static_assert(std::is_same>::value, + "lambda arg type is unexpected"); + A[i]++; + }); + + q.parallel_for({N}, [=](auto i) { + static_assert(std::is_same>::value, + "lambda arg type is unexpected"); + A[i]++; + }); + + sycl::id<1> offset(0); + q.parallel_for(sycl::range<1>{N}, offset, [=](auto i) { + static_assert(std::is_same>::value, + "lambda arg type is unexpected"); + A[i]++; + }); + + sycl::nd_range<1> NDR(sycl::range<1>{N}, sycl::range<1>{2}); + q.parallel_for(NDR, [=](auto nd_i) { + static_assert(std::is_same>::value, + "lambda arg type is unexpected"); + auto i = nd_i.get_global_id(0); + A[i]++; + }); + + q.wait(); + + for (int i = 0; i < N; i++) { + if (A[i] != 5) + return 1; + } + sycl::free(A, ctx); +} diff --git a/sycl/test/basic_tests/queue/queue_parallel_for_interface.cpp b/sycl/test/basic_tests/queue/queue_parallel_for_interface.cpp new file mode 100644 index 0000000000000..38554d8d5f5f1 --- /dev/null +++ b/sycl/test/basic_tests/queue/queue_parallel_for_interface.cpp @@ -0,0 +1,78 @@ +// RUN: %clangxx -fsycl -fsyntax-only %s -o %t.out + +//==- queue_parallel_for_generic.cpp - SYCL queue parallel_for interface test -=// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===------------------------------------------------------------------------===// + +#include +#include +#include + +template +void test_range_impl(sycl::queue q, std::index_sequence, + sycl::range *) { + constexpr auto dims = sizeof...(Is); + + q.parallel_for(sycl::range{Is...}, [=](auto i) { + static_assert(std::is_same>::value, + "lambda arg type is unexpected"); + }); +} + +template +void test_range_impl(sycl::queue q, std::index_sequence, + sycl::nd_range *) { + constexpr auto dims = sizeof...(Is); + + sycl::nd_range ndr{sycl::range{Is...}, sycl::range{Is...}}; + q.parallel_for(ndr, [=](auto i) { + static_assert(std::is_same>::value, + "lambda arg type is unexpected"); + }); +} + +template class Range, std::size_t Dims> +void test_range(sycl::queue q) { + test_range_impl(q, std::make_index_sequence{}, + static_cast *>(nullptr)); +} + +void test_number_braced_init_list(sycl::queue q) { + constexpr auto n = 1; + q.parallel_for(n, [=](auto i) { + static_assert(std::is_same>::value, + "lambda arg type is unexpected"); + }); + + q.parallel_for({n}, [=](auto i) { + static_assert(std::is_same>::value, + "lambda arg type is unexpected"); + }); + + q.parallel_for({n, n}, [=](auto i) { + static_assert(std::is_same>::value, + "lambda arg type is unexpected"); + }); + + q.parallel_for({n, n, n}, [=](auto i) { + static_assert(std::is_same>::value, + "lambda arg type is unexpected"); + }); +} + +int main() { + sycl::queue q{}; + + test_range(q); + test_range(q); + test_range(q); + test_range(q); + test_range(q); + test_range(q); + + test_number_braced_init_list(q); +}