Skip to content

Commit e374c69

Browse files
authored
[SYCL][Graph] Make calling begin_recording repeatedly an error (#15192)
Since future features may add more properties/state to queue recording it is now an error to call `begin_recording()` on the same queue more than once, rather than a no-op. This is particularly relevant in scenarios where a recording queue is shared between multiple threads. Applications are now encouraged to manage queue state from a single thread rather than freely call `begin/end_recording()` from any thread. - Calling begin_recording on a recording queue is now always an error. - Update spec, implementation and unit tests to reflect changes.
1 parent 921f559 commit e374c69

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

sycl/doc/extensions/experimental/sycl_ext_oneapi_graph.asciidoc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,7 +1284,7 @@ begin_recording(queue& recordingQueue,
12841284
----
12851285

12861286
|Synchronously changes the state of `recordingQueue` to the
1287-
`queue_state::recording` state. This operation is a no-op if `recordingQueue`
1287+
`queue_state::recording` state. This operation is an error if `recordingQueue`
12881288
is already in the `queue_state::recording` state.
12891289

12901290
Parameters:
@@ -1299,7 +1299,7 @@ Parameters:
12991299
Exceptions:
13001300

13011301
* Throws synchronously with error code `invalid` if `recordingQueue` is
1302-
already recording to a different graph.
1302+
already recording to a graph.
13031303

13041304
* Throws synchronously with error code `invalid` if `recordingQueue` is
13051305
associated with a device or context that is different from the device
@@ -1314,7 +1314,7 @@ begin_recording(const std::vector<queue>& recordingQueues,
13141314
----
13151315

13161316
|Synchronously changes the state of each queue in `recordingQueues` to the
1317-
`queue_state::recording` state. This operation is a no-op for any queue in
1317+
`queue_state::recording` state. This operation is an error for any queue in
13181318
`recordingQueues` that is already in the `queue_state::recording` state.
13191319

13201320
Parameters:
@@ -1328,8 +1328,8 @@ Parameters:
13281328

13291329
Exceptions:
13301330

1331-
* Throws synchronously with error code `invalid` if the any queue in
1332-
`recordingQueues` is already recording to a different graph.
1331+
* Throws synchronously with error code `invalid` if any queue in
1332+
`recordingQueues` is already recording to a graph.
13331333

13341334
* Throws synchronously with error code `invalid` if any of `recordingQueues`
13351335
is associated with a device or context that is different from the device

sycl/source/detail/graph_impl.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,6 +1586,14 @@ void modifiable_command_graph::begin_recording(
15861586

15871587
auto QueueImpl = sycl::detail::getSyclObjImpl(RecordingQueue);
15881588
assert(QueueImpl);
1589+
1590+
auto QueueGraph = QueueImpl->getCommandGraph();
1591+
if (QueueGraph != nullptr) {
1592+
throw sycl::exception(sycl::make_error_code(errc::invalid),
1593+
"begin_recording cannot be called for a queue which "
1594+
"is already in the recording state.");
1595+
}
1596+
15891597
if (QueueImpl->get_context() != impl->getContext()) {
15901598
throw sycl::exception(sycl::make_error_code(errc::invalid),
15911599
"begin_recording called for a queue whose context "
@@ -1603,13 +1611,6 @@ void modifiable_command_graph::begin_recording(
16031611
"can NOT be recorded.");
16041612
}
16051613

1606-
auto QueueGraph = QueueImpl->getCommandGraph();
1607-
if (QueueGraph != nullptr && QueueGraph != impl) {
1608-
throw sycl::exception(sycl::make_error_code(errc::invalid),
1609-
"begin_recording called for a queue which is already "
1610-
"recording to a different graph.");
1611-
}
1612-
16131614
impl->beginRecording(QueueImpl);
16141615
}
16151616

sycl/unittests/Extensions/CommandGraph/CommandGraph.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,19 +131,20 @@ TEST_F(CommandGraphTest, BeginEndRecording) {
131131
sycl::queue Queue2{Queue.get_context(), Dev};
132132

133133
// Test throwing behaviour
134-
// Check we can repeatedly begin recording on the same queues
134+
// Check that repeatedly calling begin recording on the same queues is an
135+
// error
135136
ASSERT_NO_THROW(Graph.begin_recording(Queue));
136-
ASSERT_NO_THROW(Graph.begin_recording(Queue));
137-
ASSERT_NO_THROW(Graph.begin_recording(Queue2));
137+
ASSERT_ANY_THROW(Graph.begin_recording(Queue));
138138
ASSERT_NO_THROW(Graph.begin_recording(Queue2));
139+
ASSERT_ANY_THROW(Graph.begin_recording(Queue2));
139140
// Check we can repeatedly end recording on the same queues
140141
ASSERT_NO_THROW(Graph.end_recording(Queue));
141142
ASSERT_NO_THROW(Graph.end_recording(Queue));
142143
ASSERT_NO_THROW(Graph.end_recording(Queue2));
143144
ASSERT_NO_THROW(Graph.end_recording(Queue2));
144145
// Vector versions
145146
ASSERT_NO_THROW(Graph.begin_recording({Queue, Queue2}));
146-
ASSERT_NO_THROW(Graph.begin_recording({Queue, Queue2}));
147+
ASSERT_ANY_THROW(Graph.begin_recording({Queue, Queue2}));
147148
ASSERT_NO_THROW(Graph.end_recording({Queue, Queue2}));
148149
ASSERT_NO_THROW(Graph.end_recording({Queue, Queue2}));
149150

0 commit comments

Comments
 (0)