Skip to content

Commit a0717a7

Browse files
author
Ivan Karachun
committed
Added a test and applied suggestions
Signed-off-by: Ivan Karachun <[email protected]>
1 parent 7eed02c commit a0717a7

File tree

2 files changed

+46
-12
lines changed

2 files changed

+46
-12
lines changed

sycl/source/detail/scheduler/scheduler.cpp

+10-12
Original file line numberDiff line numberDiff line change
@@ -146,18 +146,16 @@ EventImplPtr Scheduler::addHostAccessor(Requirement *Req) {
146146
void Scheduler::releaseHostAccessor(Requirement *Req) {
147147
Req->MBlockedCmd->MCanEnqueue = true;
148148
MemObjRecord* Record = Req->MSYCLMemObj->MRecord.get();
149-
for (Command *Cmd : Record->MReadLeafs) {
150-
EnqueueResultT Res;
151-
bool Enqueued = GraphProcessor::enqueueCommand(Cmd, Res);
152-
if (!Enqueued && EnqueueResultT::FAILED == Res.MResult)
153-
throw runtime_error("Enqueue process failed.");
154-
}
155-
for (Command *Cmd : Record->MWriteLeafs) {
156-
EnqueueResultT Res;
157-
bool Enqueued = GraphProcessor::enqueueCommand(Cmd, Res);
158-
if (!Enqueued && EnqueueResultT::FAILED == Res.MResult)
159-
throw runtime_error("Enqueue process failed.");
160-
}
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);
161159
}
162160

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

0 commit comments

Comments
 (0)