Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
33 changes: 24 additions & 9 deletions sycl/source/detail/scheduler/scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +156,33 @@ void Scheduler::cleanupFinishedCommands(EventImplPtr FinishedEvent) {
}

void Scheduler::removeMemoryObject(detail::SYCLMemObjI *MemObj) {
MemObjRecord *Record = nullptr;
std::unique_lock<std::shared_timed_mutex> Lock(MGraphLock, std::defer_lock);
lockSharedTimedMutex(Lock);

MemObjRecord *Record = MGraphBuilder.getMemObjRecord(MemObj);
if (!Record)
// No operations were performed on the mem object
return;
{
lockSharedTimedMutex(Lock);

Record = MGraphBuilder.getMemObjRecord(MemObj);
if (!Record)
// No operations were performed on the mem object
return;

waitForRecordToFinish(Record);
MGraphBuilder.decrementLeafCountersForRecord(Record);
MGraphBuilder.cleanupCommandsForRecord(Record);
MGraphBuilder.removeRecordForMemObj(MemObj);
Lock.unlock();
}

{
// This only need a shared mutex as it only involves enqueueing and awaiting
// for events
std::shared_lock<std::shared_timed_mutex> Lock(MGraphLock);
waitForRecordToFinish(Record);
}

{
lockSharedTimedMutex(Lock);
MGraphBuilder.decrementLeafCountersForRecord(Record);
MGraphBuilder.cleanupCommandsForRecord(Record);
MGraphBuilder.removeRecordForMemObj(MemObj);
}
}

EventImplPtr Scheduler::addHostAccessor(Requirement *Req) {
Expand Down
60 changes: 60 additions & 0 deletions sycl/test/host-interop-task/host-task-failure.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
// RUN: %CPU_RUN_PLACEHOLDER %t.out
// RUN: %GPU_RUN_PLACEHOLDER %t.out
// RUN: %ACC_RUN_PLACEHOLDER %t.out

#include <CL/sycl.hpp>
#include <CL/sycl/backend/opencl.hpp>
#include <CL/sycl/detail/cl.h>

using namespace cl::sycl;
using namespace cl::sycl::access;

static constexpr size_t BUFFER_SIZE = 1024;

template <typename T>
class Modifier;

template <typename T>
class Init;

template <typename DataT>
void copy(buffer<DataT, 1> &Src, buffer<DataT, 1> &Dst, queue &Q) {
Q.submit([&](handler &CGH) {
auto SrcA = Src.template get_access<mode::read>(CGH);
auto DstA = Dst.template get_access<mode::write>(CGH);

CGH.codeplay_host_task([=]() {
for (size_t Idx = 0; Idx < SrcA.get_count(); ++Idx)
DstA[Idx] = SrcA[Idx];
});
});
}

template <typename DataT>
void init(buffer<DataT, 1> &B1, buffer<DataT, 1> &B2, queue &Q) {
Q.submit([&](handler &CGH) {
auto Acc1 = B1.template get_access<mode::write>(CGH);
auto Acc2 = B2.template get_access<mode::write>(CGH);

CGH.parallel_for<Init<DataT>>(BUFFER_SIZE, [=](item<1> Id) {
Acc1[Id] = -1;
Acc2[Id] = -2;
});
});
}

void test() {
queue Q;
buffer<int, 1> Buffer1{BUFFER_SIZE};
buffer<int, 1> Buffer2{BUFFER_SIZE};

init<int>(Buffer1, Buffer2, Q);

copy(Buffer1, Buffer2, Q);
}

int main() {
test();
return 0;
}