Skip to content

Commit 80d17b2

Browse files
Ivan Karachunromanovvlad
Ivan Karachun
authored andcommitted
[SYCL] Enqueue leaves after host accessor destruction (#899)
Need to enqueue all leaves of the graph to start execution after unblocking. Signed-off-by: Ivan Karachun <[email protected]>
1 parent d854643 commit 80d17b2

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

sycl/source/detail/scheduler/scheduler.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,17 @@ EventImplPtr Scheduler::addHostAccessor(Requirement *Req) {
145145

146146
void Scheduler::releaseHostAccessor(Requirement *Req) {
147147
Req->MBlockedCmd->MCanEnqueue = true;
148+
MemObjRecord* Record = Req->MSYCLMemObj->MRecord.get();
149+
auto EnqueueLeaves = [](std::vector<Command *> &Leaves) {
150+
for (Command *Cmd : Leaves) {
151+
EnqueueResultT Res;
152+
bool Enqueued = GraphProcessor::enqueueCommand(Cmd, Res);
153+
if (!Enqueued && EnqueueResultT::FAILED == Res.MResult)
154+
throw runtime_error("Enqueue process failed.");
155+
}
156+
};
157+
EnqueueLeaves(Record->MReadLeaves);
158+
EnqueueLeaves(Record->MWriteLeaves);
148159
}
149160

150161
Scheduler::Scheduler() {
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// RUN: %clangxx -fsycl %s -o %t.out
2+
// RUN: env SYCL_PI_TRACE=1 %CPU_RUN_PLACEHOLDER %t.out 2>&1 %CPU_CHECK_PLACEHOLDER
3+
//==---------------------- HostAccDestruction.cpp --------------------------==//
4+
//
5+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
6+
// See https://llvm.org/LICENSE.txt for license information.
7+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8+
//
9+
//===----------------------------------------------------------------------===//
10+
11+
#include <CL/sycl.hpp>
12+
13+
int main() {
14+
size_t size = 3;
15+
16+
cl::sycl::buffer<int, 1> buf(size);
17+
{
18+
cl::sycl::queue q;
19+
auto host_acc = buf.get_access<cl::sycl::access::mode::read_write>();
20+
q.submit([&](cl::sycl::handler &cgh) {
21+
auto acc = buf.get_access<cl::sycl::access::mode::read_write>(cgh);
22+
cgh.parallel_for<class SingleTask>(
23+
cl::sycl::range<1>{size},
24+
[=](cl::sycl::id<1> id) { (void)acc[id]; });
25+
});
26+
std::cout << "host acc destructor call" << std::endl;
27+
}
28+
std::cout << "end of scope" << std::endl;
29+
30+
return 0;
31+
}
32+
33+
// CHECK:host acc destructor call
34+
// CHECK:---> piEnqueueKernelLaunch(
35+
// CHECK:end of scope

0 commit comments

Comments
 (0)