Skip to content

Commit 86cf56a

Browse files
[SYCL] Keep CG ownership for run_on_host_intel command nodes (#5823)
As of commit 5373ccb, DispatchNativeKernel uses copies of the required data instead of using the associated command group object directly. This change removes the release of CG ownership from the command node since the CG is no longer deleted by DispatchNativeKernel.
1 parent c818709 commit 86cf56a

File tree

4 files changed

+46
-10
lines changed

4 files changed

+46
-10
lines changed

sycl/source/detail/scheduler/commands.hpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -557,13 +557,6 @@ class ExecCGCommand : public Command {
557557
// the cleanup process.
558558
EmptyCommand *MEmptyCmd = nullptr;
559559

560-
// This function is only usable for native kernel to prevent access to free'd
561-
// memory in DispatchNativeKernel.
562-
// TODO remove when native kernel support is terminated.
563-
void releaseCG() {
564-
MCommandGroup.release();
565-
}
566-
567560
bool producesPiEvent() const final;
568561

569562
bool supportsPostEnqueueCleanup() const final;

sycl/source/detail/scheduler/scheduler.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,6 @@ EventImplPtr Scheduler::addCG(std::unique_ptr<detail::CG> CommandGroup,
121121

122122
auto CleanUp = [&]() {
123123
if (NewCmd && (NewCmd->MDeps.size() == 0 && NewCmd->MUsers.size() == 0)) {
124-
if (Type == CG::RunOnHostIntel)
125-
static_cast<ExecCGCommand *>(NewCmd)->releaseCG();
126-
127124
NewEvent->setCommand(nullptr);
128125
delete NewCmd;
129126
}

sycl/unittests/scheduler/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ add_sycl_unittest(SchedulerTests OBJECT
2121
utils.cpp
2222
LeafLimitDiffContexts.cpp
2323
InOrderQueueSyncCheck.cpp
24+
RunOnHostIntelCG.cpp
2425
)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//==----------- RunOnHostIntelCG.cpp --- Scheduler unit tests --------------==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
10+
#include "SchedulerTest.hpp"
11+
#include "SchedulerTestUtils.hpp"
12+
13+
#include <detail/event_impl.hpp>
14+
15+
using namespace sycl;
16+
17+
bool CGDeleted = false;
18+
class MockCGExecKernel : public detail::CGExecKernel {
19+
public:
20+
MockCGExecKernel(detail::NDRDescT NDRDesc,
21+
std::unique_ptr<detail::HostKernelBase> HostKernel)
22+
: CGExecKernel(NDRDesc, std::move(HostKernel), /*SyclKernel*/ nullptr,
23+
/*ArgsStorage*/ {}, /*AccStorage*/ {},
24+
/*SharedPtrStorage*/ {}, /*Requirements*/ {},
25+
/*Events*/ {}, /*Args*/ {}, /*KernelName*/ "",
26+
detail::OSUtil::ExeModuleHandle, /*Streams*/ {},
27+
/*AuxilaryResources*/ {}, detail::CG::RunOnHostIntel) {}
28+
~MockCGExecKernel() override { CGDeleted = true; }
29+
};
30+
31+
// Check that the command group associated with run_on_host_intel is properly
32+
// released on command destruction.
33+
TEST_F(SchedulerTest, RunOnHostIntelCG) {
34+
MockScheduler MS;
35+
detail::QueueImplPtr QueueImpl = detail::getSyclObjImpl(MQueue);
36+
37+
detail::NDRDescT NDRDesc;
38+
NDRDesc.set(range<1>{1}, id<1>{0});
39+
std::unique_ptr<detail::HostKernelBase> HostKernel{
40+
new detail::HostKernel<std::function<void()>, void, 1>([]() {})};
41+
std::unique_ptr<detail::CG> CommandGroup{
42+
new MockCGExecKernel(std::move(NDRDesc), std::move(HostKernel))};
43+
MS.addCG(std::move(CommandGroup), QueueImpl);
44+
EXPECT_TRUE(CGDeleted);
45+
}

0 commit comments

Comments
 (0)