Skip to content

Commit 28089e4

Browse files
[SYCL][Graph] Exception if profiling is called on an event returned from a queue in record mode. (#12217)
Throws an appropriate message if profiling is called on an event returned from a queue in record mode. Adds a test to check the exception message thrown.
1 parent b892f48 commit 28089e4

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

sycl/source/event.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ event::get_info() const {
8181
template <typename Param>
8282
typename detail::is_event_profiling_info_desc<Param>::return_type
8383
event::get_profiling_info() const {
84+
if (impl->getCommandGraph()) {
85+
throw sycl::exception(make_error_code(errc::invalid),
86+
"Profiling information is unavailable for events "
87+
"returned from a submission to a queue in the "
88+
"recording state.");
89+
}
90+
8491
if constexpr (!std::is_same_v<Param, info::event_profiling::command_submit>) {
8592
impl->wait(impl);
8693
}

sycl/unittests/Extensions/CommandGraph.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,6 +1941,25 @@ TEST_F(CommandGraphTest, GraphPartitionsMerging) {
19411941
ASSERT_FALSE(PartitionsList[4]->isHostTask());
19421942
}
19431943

1944+
TEST_F(CommandGraphTest, ProfilingException) {
1945+
Graph.begin_recording(Queue);
1946+
auto Event1 = Queue.submit(
1947+
[&](sycl::handler &cgh) { cgh.single_task<TestKernel<>>([]() {}); });
1948+
auto Event2 = Queue.submit(
1949+
[&](sycl::handler &cgh) { cgh.single_task<TestKernel<>>([]() {}); });
1950+
Graph.end_recording(Queue);
1951+
1952+
try {
1953+
Event1.get_profiling_info<sycl::info::event_profiling::command_start>();
1954+
} catch (exception &Exception) {
1955+
ASSERT_FALSE(
1956+
std::string(Exception.what())
1957+
.find("Profiling information is unavailable for events returned "
1958+
"from a submission to a queue in the recording state.") ==
1959+
std::string::npos);
1960+
}
1961+
}
1962+
19441963
class MultiThreadGraphTest : public CommandGraphTest {
19451964
public:
19461965
MultiThreadGraphTest()

0 commit comments

Comments
 (0)