Skip to content

[SYCL] Join thread pool threads on Scheduler destruction (#3090) #3423

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 1 commit into from
Mar 26, 2021
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
6 changes: 6 additions & 0 deletions sycl/source/detail/queue_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,12 @@ class queue_impl {
return *MHostTaskThreadPool;
}

void stopThreadPool() {
if (MHostTaskThreadPool) {
MHostTaskThreadPool->finishAndWait();
}
}

/// Gets the native handle of the SYCL queue.
///
/// \return a native handle.
Expand Down
1 change: 1 addition & 0 deletions sycl/source/detail/scheduler/scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ Scheduler::Scheduler() {
}

Scheduler::~Scheduler() {
DefaultHostQueue->stopThreadPool();
// By specification there are several possible sync points: buffer
// destruction, wait() method of a queue or event. Stream doesn't introduce
// any synchronization point. It is guaranteed that stream is flushed and
Expand Down
19 changes: 19 additions & 0 deletions sycl/unittests/scheduler/StreamInitDependencyOnHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ class MockHandler : public sycl::handler {
static_cast<sycl::handler *>(this)->MCGType = Type;
}

template <typename KernelType, typename ArgType, int Dims,
typename KernelName>
void setHostKernel(KernelType Kernel) {
static_cast<sycl::handler *>(this)->MHostKernel.reset(
new sycl::detail::HostKernel<KernelType, ArgType, Dims, KernelName>(
Kernel));
}

template <int Dims> void setNDRangeDesc(sycl::nd_range<Dims> Range) {
static_cast<sycl::handler *>(this)->MNDRDesc.set(std::move(Range));
}

void addStream(const detail::StreamImplPtr &Stream) {
sycl::handler::addStream(Stream);
}
Expand Down Expand Up @@ -87,6 +99,13 @@ TEST_F(SchedulerTest, StreamInitDependencyOnHost) {
MockHandler MockCGH(HQueueImpl, true);
MockCGH.setType(detail::CG::KERNEL);

auto EmptyKernel = [](sycl::nd_item<1>) {};
MockCGH
.setHostKernel<decltype(EmptyKernel), sycl::nd_item<1>, 1, class Empty>(
EmptyKernel);
MockCGH.setNDRangeDesc(
sycl::nd_range<1>{sycl::range<1>{1}, sycl::range<1>{1}});

// Emulating construction of stream object inside command group
detail::StreamImplPtr StreamImpl =
std::make_shared<detail::stream_impl>(1024, 200, MockCGH);
Expand Down