Skip to content

[SYCL] Enqueue leaves after host accessor destruction #899

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
Dec 24, 2019
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
11 changes: 11 additions & 0 deletions sycl/source/detail/scheduler/scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,17 @@ EventImplPtr Scheduler::addHostAccessor(Requirement *Req) {

void Scheduler::releaseHostAccessor(Requirement *Req) {
Req->MBlockedCmd->MCanEnqueue = true;
MemObjRecord* Record = Req->MSYCLMemObj->MRecord.get();
auto EnqueueLeaves = [](std::vector<Command *> &Leaves) {
for (Command *Cmd : Leaves) {
EnqueueResultT Res;
bool Enqueued = GraphProcessor::enqueueCommand(Cmd, Res);
if (!Enqueued && EnqueueResultT::FAILED == Res.MResult)
throw runtime_error("Enqueue process failed.");
}
};
EnqueueLeaves(Record->MReadLeaves);
EnqueueLeaves(Record->MWriteLeaves);
}

Scheduler::Scheduler() {
Expand Down
35 changes: 35 additions & 0 deletions sycl/test/scheduler/HostAccDestruction.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// RUN: %clangxx -fsycl %s -o %t.out
// RUN: env SYCL_PI_TRACE=1 %CPU_RUN_PLACEHOLDER %t.out 2>&1 %CPU_CHECK_PLACEHOLDER
//==---------------------- HostAccDestruction.cpp --------------------------==//
//
// 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 <CL/sycl.hpp>

int main() {
size_t size = 3;

cl::sycl::buffer<int, 1> buf(size);
{
cl::sycl::queue q;
auto host_acc = buf.get_access<cl::sycl::access::mode::read_write>();
q.submit([&](cl::sycl::handler &cgh) {
auto acc = buf.get_access<cl::sycl::access::mode::read_write>(cgh);
cgh.parallel_for<class SingleTask>(
cl::sycl::range<1>{size},
[=](cl::sycl::id<1> id) { (void)acc[id]; });
});
std::cout << "host acc destructor call" << std::endl;
}
std::cout << "end of scope" << std::endl;

return 0;
}

// CHECK:host acc destructor call
// CHECK:---> piEnqueueKernelLaunch(
// CHECK:end of scope