Skip to content

Commit abdc0fe

Browse files
authored
[SYCL] Fix handler::require() to accept a non-placeholder arg (#7786)
1 parent 236a09d commit abdc0fe

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

sycl/include/sycl/handler.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,18 +1469,18 @@ class __SYCL_EXPORT handler {
14691469
use_kernel_bundle(const kernel_bundle<bundle_state::executable> &ExecBundle);
14701470

14711471
/// Requires access to the memory object associated with the placeholder
1472-
/// accessor.
1472+
/// accessor. Calling this function with a non-placeholder accessor has no
1473+
/// effect.
14731474
///
14741475
/// The command group has a requirement to gain access to the given memory
14751476
/// object before executing.
14761477
///
14771478
/// \param Acc is a SYCL accessor describing required memory region.
14781479
template <typename DataT, int Dims, access::mode AccMode,
1479-
access::target AccTarget>
1480-
void
1481-
require(accessor<DataT, Dims, AccMode, AccTarget, access::placeholder::true_t>
1482-
Acc) {
1483-
associateWithHandler(&Acc, AccTarget);
1480+
access::target AccTarget, access::placeholder isPlaceholder>
1481+
void require(accessor<DataT, Dims, AccMode, AccTarget, isPlaceholder> Acc) {
1482+
if (Acc.is_placeholder())
1483+
associateWithHandler(&Acc, AccTarget);
14841484
}
14851485

14861486
/// Registers event dependencies on this command group.

sycl/unittests/handler/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
add_sycl_unittest(HandlerTests OBJECT
22
SetArgForLocalAccessor.cpp
3+
require.cpp
34
)

sycl/unittests/handler/require.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <gtest/gtest.h>
2+
#include <helpers/PiMock.hpp>
3+
4+
#include <sycl/sycl.hpp>
5+
6+
TEST(Require, RequireWithNonPlaceholderAccessor) {
7+
sycl::unittest::PiMock Mock;
8+
sycl::queue Q;
9+
int data = 5;
10+
{
11+
sycl::buffer<int, 1> buf(&data, 1);
12+
Q.submit([&](sycl::handler &h) {
13+
auto acc = buf.get_access<sycl::access::mode::read_write>(h);
14+
// It should be compilable and does nothing according to the spec
15+
h.require(acc);
16+
});
17+
Q.wait();
18+
}
19+
}

0 commit comments

Comments
 (0)