Skip to content

Commit 22cefab

Browse files
authored
[SYCL] Throw correct exception when passing unbound accessor to command (#8131)
According to 4.7.6.9 of SYCL2020 spec, if a placeholder accessor is passed to a command without being bound to a command group, an exception should be thrown. Prior to this change, the exception was only thrown if an unbound placeholder accessor is used, not only passed. Also, prior to this change, if we passed one unbound accessor and one (or more) bound accessors to a command, the exception thrown was incorrect. Closes #3078. --------- Signed-off-by: Maronas, Marcos <[email protected]>
1 parent 5b41dde commit 22cefab

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

sycl/source/detail/scheduler/commands.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1978,10 +1978,8 @@ static pi_result SetKernelParamsAndLaunch(
19781978
Requirement *Req = (Requirement *)(Arg.MPtr);
19791979
if (Req->MAccessRange == range<3>({0, 0, 0}))
19801980
break;
1981-
if (getMemAllocationFunc == nullptr)
1982-
throw sycl::exception(make_error_code(errc::kernel_argument),
1983-
"placeholder accessor must be bound by calling "
1984-
"handler::require() before it can be used.");
1981+
assert(getMemAllocationFunc != nullptr &&
1982+
"We should have caught this earlier.");
19851983

19861984
RT::PiMem MemArg = (RT::PiMem)getMemAllocationFunc(Req);
19871985
if (Plugin.getBackend() == backend::opencl) {

sycl/source/handler.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,26 @@ event handler::finalize() {
9494
return MLastEvent;
9595
MIsFinalized = true;
9696

97+
// According to 4.7.6.9 of SYCL2020 spec, if a placeholder accessor is passed
98+
// to a command without being bound to a command group, an exception should
99+
// be thrown. There should be as many requirements as unique accessors,
100+
// otherwise some of the accessors are unbound, and thus we throw.
101+
{
102+
// A counter is not good enough since we can have the same accessor several
103+
// times as arg
104+
std::unordered_set<void *> accessors;
105+
for (const auto &arg : MArgs) {
106+
if (arg.MType != detail::kernel_param_kind_t::kind_accessor)
107+
continue;
108+
109+
accessors.insert(arg.MPtr);
110+
}
111+
if (accessors.size() > MRequirements.size())
112+
throw sycl::exception(make_error_code(errc::kernel_argument),
113+
"placeholder accessor must be bound by calling "
114+
"handler::require() before it can be used.");
115+
}
116+
97117
const auto &type = getType();
98118
if (type == detail::CG::Kernel) {
99119
// If there were uses of set_specialization_constant build the kernel_bundle

0 commit comments

Comments
 (0)