Skip to content

Commit 2e86cd4

Browse files
authored
[SYCL] Improve sycl::event::get_profiling_info exception message if default constructed (#6476)
The default constructed sycl::event would emit a misleading message when querying profiling information. The message would assume a queue is attached to such sycl::event, even if it's not the case. Added a condition to handle such case, and emit a more proper message, and updated appropriate unit test.
1 parent c22a5d3 commit 2e86cd4

File tree

2 files changed

+66
-15
lines changed

2 files changed

+66
-15
lines changed

sycl/source/detail/event_impl.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,18 @@ void event_impl::cleanupCommand(
281281
}
282282

283283
void event_impl::checkProfilingPreconditions() const {
284-
if (!MIsProfilingEnabled) {
284+
std::weak_ptr<queue_impl> EmptyPtr;
285+
286+
if (!EmptyPtr.owner_before(MQueue) && !MQueue.owner_before(EmptyPtr)) {
285287
throw sycl::exception(make_error_code(sycl::errc::invalid),
286-
"get_profiling_info() can't be used without set "
287-
"'enable_profiling' queue property");
288+
"Profiling information is unavailable as the event "
289+
"has no associated queue.");
290+
}
291+
if (!MIsProfilingEnabled) {
292+
throw sycl::exception(
293+
make_error_code(sycl::errc::invalid),
294+
"Profiling information is unavailable as the queue associated with "
295+
"the event does not have the 'enable_profiling' property.");
288296
}
289297
}
290298

sycl/unittests/queue/GetProfilingInfo.cpp

Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,10 @@ TEST(GetProfilingInfo, command_exception_check) {
163163
(void)submit_time;
164164
FAIL();
165165
} catch (sycl::exception &e) {
166-
EXPECT_STREQ(e.what(), "get_profiling_info() can't be used without set "
167-
"'enable_profiling' queue property");
166+
EXPECT_STREQ(
167+
e.what(),
168+
"Profiling information is unavailable as the queue associated with "
169+
"the event does not have the 'enable_profiling' property.");
168170
}
169171
}
170172
{
@@ -180,8 +182,10 @@ TEST(GetProfilingInfo, command_exception_check) {
180182
FAIL();
181183
} catch (sycl::exception const &e) {
182184
std::cerr << e.what() << std::endl;
183-
EXPECT_STREQ(e.what(), "get_profiling_info() can't be used without set "
184-
"'enable_profiling' queue property");
185+
EXPECT_STREQ(
186+
e.what(),
187+
"Profiling information is unavailable as the queue associated with "
188+
"the event does not have the 'enable_profiling' property.");
185189
}
186190
}
187191
{
@@ -195,12 +199,45 @@ TEST(GetProfilingInfo, command_exception_check) {
195199
(void)end_time;
196200
FAIL();
197201
} catch (sycl::exception const &e) {
198-
EXPECT_STREQ(e.what(), "get_profiling_info() can't be used without set "
199-
"'enable_profiling' queue property");
202+
EXPECT_STREQ(
203+
e.what(),
204+
"Profiling information is unavailable as the queue associated with "
205+
"the event does not have the 'enable_profiling' property.");
200206
}
201207
}
202208
}
203209

210+
TEST(GetProfilingInfo, exception_check_no_queue) {
211+
sycl::event E;
212+
try {
213+
auto info =
214+
E.get_profiling_info<sycl::info::event_profiling::command_submit>();
215+
(void)info;
216+
FAIL();
217+
} catch (sycl::exception const &e) {
218+
EXPECT_STREQ(e.what(), "Profiling information is unavailable as the event "
219+
"has no associated queue.");
220+
}
221+
try {
222+
auto info =
223+
E.get_profiling_info<sycl::info::event_profiling::command_start>();
224+
(void)info;
225+
FAIL();
226+
} catch (sycl::exception const &e) {
227+
EXPECT_STREQ(e.what(), "Profiling information is unavailable as the event "
228+
"has no associated queue.");
229+
}
230+
try {
231+
auto info =
232+
E.get_profiling_info<sycl::info::event_profiling::command_end>();
233+
(void)info;
234+
FAIL();
235+
} catch (sycl::exception const &e) {
236+
EXPECT_STREQ(e.what(), "Profiling information is unavailable as the event "
237+
"has no associated queue.");
238+
}
239+
}
240+
204241
TEST(GetProfilingInfo, check_if_now_dead_queue_property_set) {
205242
sycl::platform Plt{sycl::default_selector{}};
206243
if (Plt.is_host()) {
@@ -302,8 +339,10 @@ TEST(GetProfilingInfo, check_if_now_dead_queue_property_not_set) {
302339
(void)submit_time;
303340
FAIL();
304341
} catch (sycl::exception &e) {
305-
EXPECT_STREQ(e.what(), "get_profiling_info() can't be used without set "
306-
"'enable_profiling' queue property");
342+
EXPECT_STREQ(
343+
e.what(),
344+
"Profiling information is unavailable as the queue associated with "
345+
"the event does not have the 'enable_profiling' property.");
307346
}
308347
}
309348
{
@@ -314,8 +353,10 @@ TEST(GetProfilingInfo, check_if_now_dead_queue_property_not_set) {
314353
(void)start_time;
315354
FAIL();
316355
} catch (sycl::exception &e) {
317-
EXPECT_STREQ(e.what(), "get_profiling_info() can't be used without set "
318-
"'enable_profiling' queue property");
356+
EXPECT_STREQ(
357+
e.what(),
358+
"Profiling information is unavailable as the queue associated with "
359+
"the event does not have the 'enable_profiling' property.");
319360
}
320361
}
321362
{
@@ -325,8 +366,10 @@ TEST(GetProfilingInfo, check_if_now_dead_queue_property_not_set) {
325366
(void)end_time;
326367
FAIL();
327368
} catch (sycl::exception &e) {
328-
EXPECT_STREQ(e.what(), "get_profiling_info() can't be used without set "
329-
"'enable_profiling' queue property");
369+
EXPECT_STREQ(
370+
e.what(),
371+
"Profiling information is unavailable as the queue associated with "
372+
"the event does not have the 'enable_profiling' property.");
330373
}
331374
}
332375
// The test passes without this, but keep it still, just in case.

0 commit comments

Comments
 (0)