File tree Expand file tree Collapse file tree 4 files changed +38
-1
lines changed Expand file tree Collapse file tree 4 files changed +38
-1
lines changed Original file line number Diff line number Diff line change @@ -133,11 +133,15 @@ class event_impl {
133
133
134
134
// / Returns command that is associated with the event.
135
135
// /
136
+ // / Scheduler mutex must be locked in read mode when this is called.
137
+ // /
136
138
// / @return a generic pointer to Command object instance.
137
139
void *getCommand () { return MCommand; }
138
140
139
141
// / Associates this event with the command.
140
142
// /
143
+ // / Scheduler mutex must be locked in write mode when this is called.
144
+ // /
141
145
// / @param Command is a generic pointer to Command object instance.
142
146
void setCommand (void *Command) { MCommand = Command; }
143
147
Original file line number Diff line number Diff line change @@ -38,7 +38,11 @@ Scheduler::GraphProcessor::getWaitList(EventImplPtr Event) {
38
38
39
39
void Scheduler::GraphProcessor::waitForEvent (EventImplPtr Event) {
40
40
Command *Cmd = getCommand (Event);
41
- assert (Cmd && " Event has no associated command?" );
41
+ // Command can be nullptr if user creates cl::sycl::event explicitly or the
42
+ // event has been waited on by another thread
43
+ if (!Cmd)
44
+ return ;
45
+
42
46
EnqueueResultT Res;
43
47
bool Enqueued = enqueueCommand (Cmd, Res, BLOCKING);
44
48
if (!Enqueued && EnqueueResultT::SyclEnqueueFailed == Res.MResult )
Original file line number Diff line number Diff line change @@ -5,5 +5,6 @@ add_sycl_unittest(SchedulerTests OBJECT
5
5
LeafLimit.cpp
6
6
MemObjCommandCleanup.cpp
7
7
CommandsWaitForEvents.cpp
8
+ WaitAfterCleanup.cpp
8
9
utils.cpp
9
10
)
Original file line number Diff line number Diff line change
1
+ // ==------------ WaitAfterCleanup.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
+ #include " SchedulerTest.hpp"
10
+ #include " SchedulerTestUtils.hpp"
11
+
12
+ using namespace cl ::sycl;
13
+
14
+ TEST_F (SchedulerTest, WaitAfterCleanup) {
15
+ auto Cmd = new MockCommand (detail::getSyclObjImpl (MQueue));
16
+ auto Event = Cmd->getEvent ();
17
+ ASSERT_NE (Event, nullptr ) << " Command must have an event\n " ;
18
+
19
+ detail::Scheduler::getInstance ().waitForEvent (Event);
20
+ ASSERT_EQ (Event->getCommand (), Cmd)
21
+ << " Command should not have been cleaned up yet\n " ;
22
+
23
+ detail::Scheduler::getInstance ().cleanupFinishedCommands (Event);
24
+ ASSERT_EQ (Event->getCommand (), nullptr )
25
+ << " Command should have been cleaned up\n " ;
26
+
27
+ detail::Scheduler::getInstance ().waitForEvent (Event);
28
+ }
You can’t perform that action at this time.
0 commit comments