Skip to content

[SYCL] Fix an issue with queue shortcuts with offsets #6440

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions sycl/include/sycl/queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,54 @@ class __SYCL_EXPORT queue {
return parallel_for_impl<KernelName>(Range, DepEvents, Rest...);
}

// While other shortcuts with offsets are able to go through parallel_for(...,
// RestT &&...Rest), those that accept dependency events vector have to be
// overloaded to allow implicit construction from an init-list.
/// parallel_for version with a kernel represented as a lambda + range and
/// offset that specify global size and global offset correspondingly.
///
/// \param Range specifies the global work space of the kernel
/// \param WorkItemOffset specifies the offset for each work item id
/// \param KernelFunc is the Kernel functor or lambda
/// \param CodeLoc contains the code location of user code
template <typename KernelName = detail::auto_name, typename KernelType>
event parallel_for(range<1> Range, id<1> WorkItemOffset,
const std::vector<event> &DepEvents,
_KERNELFUNCPARAM(KernelFunc)) {
return parallel_for_impl<KernelName>(Range, WorkItemOffset, DepEvents,
KernelFunc);
}

/// parallel_for version with a kernel represented as a lambda + range and
/// offset that specify global size and global offset correspondingly.
///
/// \param Range specifies the global work space of the kernel
/// \param WorkItemOffset specifies the offset for each work item id
/// \param KernelFunc is the Kernel functor or lambda
/// \param CodeLoc contains the code location of user code
template <typename KernelName = detail::auto_name, typename KernelType>
event parallel_for(range<2> Range, id<2> WorkItemOffset,
const std::vector<event> &DepEvents,
_KERNELFUNCPARAM(KernelFunc)) {
return parallel_for_impl<KernelName>(Range, WorkItemOffset, DepEvents,
KernelFunc);
}

/// parallel_for version with a kernel represented as a lambda + range and
/// offset that specify global size and global offset correspondingly.
///
/// \param Range specifies the global work space of the kernel
/// \param WorkItemOffset specifies the offset for each work item id
/// \param KernelFunc is the Kernel functor or lambda
/// \param CodeLoc contains the code location of user code
template <typename KernelName = detail::auto_name, typename KernelType>
event parallel_for(range<3> Range, id<3> WorkItemOffset,
const std::vector<event> &DepEvents,
_KERNELFUNCPARAM(KernelFunc)) {
return parallel_for_impl<KernelName>(Range, WorkItemOffset, DepEvents,
KernelFunc);
}

/// parallel_for version with a kernel represented as a lambda + range and
/// offset that specify global size and global offset correspondingly.
///
Expand Down
26 changes: 26 additions & 0 deletions sycl/test/basic_tests/queue/queue_offset_shortcut_initlist.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// RUN: %clangxx -fsycl -fsyntax-only %s -o %t.out
//=---queue_offset_shortcut_initlist.cpp - SYCL queue offset shortcuts 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 <sycl/sycl.hpp>

class KernelNameA;
class KernelNameB;
class KernelNameC;

int main() {
sycl::queue q;
sycl::event e;
// Check that init-list works here.
q.parallel_for<KernelNameA>(sycl::range<1>{1}, sycl::id<1>{0}, {e},
[=](sycl::item<1> i) {});
q.parallel_for<KernelNameB>(sycl::range<2>{1, 1}, sycl::id<2>{0, 0}, {e},
[=](sycl::item<2> i) {});
q.parallel_for<KernelNameC>(sycl::range<3>{1, 1, 1}, sycl::id<3>{0, 0, 0},
{e}, [=](sycl::item<3> i) {});
}