Skip to content

[SYCL] Keep CG ownership for run_on_host_intel command nodes #5823

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 25, 2022
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
7 changes: 0 additions & 7 deletions sycl/source/detail/scheduler/commands.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,13 +557,6 @@ class ExecCGCommand : public Command {
// the cleanup process.
EmptyCommand *MEmptyCmd = nullptr;

// This function is only usable for native kernel to prevent access to free'd
// memory in DispatchNativeKernel.
// TODO remove when native kernel support is terminated.
void releaseCG() {
MCommandGroup.release();
}

bool producesPiEvent() const final;

bool supportsPostEnqueueCleanup() const final;
Expand Down
3 changes: 0 additions & 3 deletions sycl/source/detail/scheduler/scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,6 @@ EventImplPtr Scheduler::addCG(std::unique_ptr<detail::CG> CommandGroup,

auto CleanUp = [&]() {
if (NewCmd && (NewCmd->MDeps.size() == 0 && NewCmd->MUsers.size() == 0)) {
if (Type == CG::RunOnHostIntel)
static_cast<ExecCGCommand *>(NewCmd)->releaseCG();

NewEvent->setCommand(nullptr);
delete NewCmd;
}
Expand Down
1 change: 1 addition & 0 deletions sycl/unittests/scheduler/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ add_sycl_unittest(SchedulerTests OBJECT
utils.cpp
LeafLimitDiffContexts.cpp
InOrderQueueSyncCheck.cpp
RunOnHostIntelCG.cpp
)
45 changes: 45 additions & 0 deletions sycl/unittests/scheduler/RunOnHostIntelCG.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//==----------- RunOnHostIntelCG.cpp --- Scheduler unit tests --------------==//
//
// 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 "SchedulerTest.hpp"
#include "SchedulerTestUtils.hpp"

#include <detail/event_impl.hpp>

using namespace sycl;

bool CGDeleted = false;
class MockCGExecKernel : public detail::CGExecKernel {
public:
MockCGExecKernel(detail::NDRDescT NDRDesc,
std::unique_ptr<detail::HostKernelBase> HostKernel)
: CGExecKernel(NDRDesc, std::move(HostKernel), /*SyclKernel*/ nullptr,
/*ArgsStorage*/ {}, /*AccStorage*/ {},
/*SharedPtrStorage*/ {}, /*Requirements*/ {},
/*Events*/ {}, /*Args*/ {}, /*KernelName*/ "",
detail::OSUtil::ExeModuleHandle, /*Streams*/ {},
/*AuxilaryResources*/ {}, detail::CG::RunOnHostIntel) {}
~MockCGExecKernel() override { CGDeleted = true; }
};

// Check that the command group associated with run_on_host_intel is properly
// released on command destruction.
TEST_F(SchedulerTest, RunOnHostIntelCG) {
MockScheduler MS;
detail::QueueImplPtr QueueImpl = detail::getSyclObjImpl(MQueue);

detail::NDRDescT NDRDesc;
NDRDesc.set(range<1>{1}, id<1>{0});
std::unique_ptr<detail::HostKernelBase> HostKernel{
new detail::HostKernel<std::function<void()>, void, 1>([]() {})};
std::unique_ptr<detail::CG> CommandGroup{
new MockCGExecKernel(std::move(NDRDesc), std::move(HostKernel))};
MS.addCG(std::move(CommandGroup), QueueImpl);
EXPECT_TRUE(CGDeleted);
}