Skip to content

Commit 06cc9ba

Browse files
author
Maxime France-Pillois
committed
[SYCL][Graph] Throw exception when calling profiling
Throws an invalid exception when calling `event::get_profiling_info()` on an event returned by a graph submission. Adds unitests checking that exceptions are throws if `event::get_profiling_info()` is called on an event returned from a queue in recording mode or an event returned by a graph submission.
1 parent bf827a2 commit 06cc9ba

File tree

4 files changed

+86
-0
lines changed

4 files changed

+86
-0
lines changed

sycl/source/detail/event_impl.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,11 @@ void event_impl::checkProfilingPreconditions() const {
274274
"Profiling information is unavailable as the queue associated with "
275275
"the event does not have the 'enable_profiling' property.");
276276
}
277+
if (EventFromSubmitedExecCommandBuffer) {
278+
throw sycl::exception(make_error_code(sycl::errc::invalid),
279+
"Profiling information is unavailable for events "
280+
"returned by a graph submission.");
281+
}
277282
}
278283

279284
template <>

sycl/source/detail/event_impl.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,14 @@ class event_impl {
278278
return MGraph.lock();
279279
}
280280

281+
void setEventFromSubmitedExecCommandBuffer(bool value) {
282+
EventFromSubmitedExecCommandBuffer = value;
283+
}
284+
285+
bool isEventFromSubmitedExecCommandBuffer() const {
286+
return EventFromSubmitedExecCommandBuffer;
287+
}
288+
281289
protected:
282290
// When instrumentation is enabled emits trace event for event wait begin and
283291
// returns the telemetry event generated for the wait
@@ -327,6 +335,8 @@ class event_impl {
327335
/// Store the command graph associated with this event, if any.
328336
/// This event is also be stored in the graph so a weak_ptr is used.
329337
std::weak_ptr<ext::oneapi::experimental::detail::graph_impl> MGraph;
338+
/// Indicates that the event results from a command graph submission
339+
bool EventFromSubmitedExecCommandBuffer = false;
330340

331341
// If this event represents a submission to a
332342
// sycl::detail::pi::PiExtCommandBuffer the sync point for that submission is

sycl/source/detail/graph_impl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,7 @@ exec_graph_impl::enqueue(const std::shared_ptr<sycl::detail::queue_impl> &Queue,
536536
auto NewEvent = std::make_shared<sycl::detail::event_impl>(Queue);
537537
NewEvent->setContextImpl(Queue->getContextImplPtr());
538538
NewEvent->setStateIncomplete();
539+
NewEvent->setEventFromSubmitedExecCommandBuffer(true);
539540
return NewEvent;
540541
});
541542

sycl/unittests/Extensions/CommandGraph.cpp

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,6 +1443,76 @@ TEST_F(CommandGraphTest, BindlessExceptionCheck) {
14431443
sycl::free(ImgMemUSM, Ctxt);
14441444
}
14451445

1446+
TEST_F(CommandGraphTest, GetProfilingInfoExceptionCheck) {
1447+
sycl::context Ctx{Dev};
1448+
sycl::queue QueueProfile{
1449+
Ctx, Dev, sycl::property_list{sycl::property::queue::enable_profiling{}}};
1450+
experimental::command_graph<experimental::graph_state::modifiable>
1451+
GraphProfile{QueueProfile.get_context(), Dev};
1452+
1453+
GraphProfile.begin_recording(QueueProfile);
1454+
auto Event = QueueProfile.submit(
1455+
[&](sycl::handler &cgh) { cgh.single_task<TestKernel<>>([]() {}); });
1456+
1457+
// Checks that exception is thrown when get_profile_info is called on "event"
1458+
// returned by a queue in recording mode.
1459+
std::error_code ExceptionCode = make_error_code(sycl::errc::success);
1460+
try {
1461+
Event.get_profiling_info<sycl::info::event_profiling::command_submit>();
1462+
} catch (exception &Exception) {
1463+
ExceptionCode = Exception.code();
1464+
}
1465+
ASSERT_EQ(ExceptionCode, sycl::errc::invalid);
1466+
1467+
ExceptionCode = make_error_code(sycl::errc::success);
1468+
try {
1469+
Event.get_profiling_info<sycl::info::event_profiling::command_start>();
1470+
} catch (exception &Exception) {
1471+
ExceptionCode = Exception.code();
1472+
}
1473+
ASSERT_EQ(ExceptionCode, sycl::errc::invalid);
1474+
1475+
ExceptionCode = make_error_code(sycl::errc::success);
1476+
try {
1477+
Event.get_profiling_info<sycl::info::event_profiling::command_end>();
1478+
} catch (exception &Exception) {
1479+
ExceptionCode = Exception.code();
1480+
}
1481+
ASSERT_EQ(ExceptionCode, sycl::errc::invalid);
1482+
1483+
GraphProfile.end_recording();
1484+
1485+
auto GraphExec = GraphProfile.finalize();
1486+
auto EventSub = QueueProfile.submit(
1487+
[&](sycl::handler &CGH) { CGH.ext_oneapi_graph(GraphExec); });
1488+
1489+
// Checks that exception is thrown when get_profile_info is called on "event"
1490+
// returned by a graph submission.
1491+
ExceptionCode = make_error_code(sycl::errc::success);
1492+
try {
1493+
EventSub.get_profiling_info<sycl::info::event_profiling::command_submit>();
1494+
} catch (exception &Exception) {
1495+
ExceptionCode = Exception.code();
1496+
}
1497+
ASSERT_EQ(ExceptionCode, sycl::errc::invalid);
1498+
1499+
ExceptionCode = make_error_code(sycl::errc::success);
1500+
try {
1501+
EventSub.get_profiling_info<sycl::info::event_profiling::command_start>();
1502+
} catch (exception &Exception) {
1503+
ExceptionCode = Exception.code();
1504+
}
1505+
ASSERT_EQ(ExceptionCode, sycl::errc::invalid);
1506+
1507+
ExceptionCode = make_error_code(sycl::errc::success);
1508+
try {
1509+
EventSub.get_profiling_info<sycl::info::event_profiling::command_end>();
1510+
} catch (exception &Exception) {
1511+
ExceptionCode = Exception.code();
1512+
}
1513+
ASSERT_EQ(ExceptionCode, sycl::errc::invalid);
1514+
}
1515+
14461516
class MultiThreadGraphTest : public CommandGraphTest {
14471517
public:
14481518
MultiThreadGraphTest()

0 commit comments

Comments
 (0)