Skip to content

Commit 473bea3

Browse files
[SYCL] Treat profiling as not supported if submit timestamps are not (#8279)
With the recent fix to command_submit profiling information query it now requires that the plugin supports piGetDeviceAndHostTimer API. Because of that, we should not report queue profiling as a supported aspect unless both the underlying pi_queue supports profiling and piGetDeviceAndHostTimer is available. In addition, add a feature_not_supported exception when a queue is constructed with enable_profiling property and a device that does not support profiling.
1 parent a1787de commit 473bea3

File tree

5 files changed

+47
-35
lines changed

5 files changed

+47
-35
lines changed

sycl/plugins/hip/pi_hip.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5330,6 +5330,9 @@ pi_result hip_piTearDown(void *PluginParameter) {
53305330

53315331
pi_result hip_piGetDeviceAndHostTimer(pi_device Device, uint64_t *DeviceTime,
53325332
uint64_t *HostTime) {
5333+
if (!DeviceTime && !HostTime)
5334+
return PI_SUCCESS;
5335+
53335336
_pi_event::native_type event;
53345337

53355338
ScopedContext active(Device->get_context());

sycl/source/detail/device_info.hpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,14 +242,23 @@ struct get_device_info_impl<std::vector<info::fp_config>,
242242
}
243243
};
244244

245-
// Specialization for queue_profiling, OpenCL returns a bitfield
245+
// Specialization for queue_profiling. In addition to pi_queue level profiling,
246+
// piGetDeviceAndHostTimer support is needed for command_submit query support.
246247
template <> struct get_device_info_impl<bool, info::device::queue_profiling> {
247-
static bool get(RT::PiDevice dev, const plugin &Plugin) {
248-
cl_command_queue_properties result;
248+
static bool get(RT::PiDevice Dev, const plugin &Plugin) {
249+
pi_queue_properties Properties;
249250
Plugin.call<PiApiKind::piDeviceGetInfo>(
250-
dev, PiInfoCode<info::device::queue_profiling>::value, sizeof(result),
251-
&result, nullptr);
252-
return (result & CL_QUEUE_PROFILING_ENABLE);
251+
Dev, PiInfoCode<info::device::queue_profiling>::value,
252+
sizeof(Properties), &Properties, nullptr);
253+
if (!(Properties & PI_QUEUE_FLAG_PROFILING_ENABLE))
254+
return false;
255+
RT::PiResult Result =
256+
Plugin.call_nocheck<detail::PiApiKind::piGetDeviceAndHostTimer>(
257+
Dev, nullptr, nullptr);
258+
if (Result == PI_ERROR_INVALID_OPERATION)
259+
return false;
260+
Plugin.checkPiResult(Result);
261+
return true;
253262
}
254263
};
255264

sycl/source/detail/queue_impl.hpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,15 @@ class queue_impl {
132132
});
133133
PrepareNotify.notify();
134134
#endif
135-
if (has_property<ext::oneapi::property::queue::discard_events>() &&
136-
has_property<property::queue::enable_profiling>()) {
137-
throw sycl::exception(make_error_code(errc::invalid),
138-
"Queue cannot be constructed with both of "
139-
"discard_events and enable_profiling.");
135+
if (has_property<property::queue::enable_profiling>()) {
136+
if (has_property<ext::oneapi::property::queue::discard_events>())
137+
throw sycl::exception(make_error_code(errc::invalid),
138+
"Queue cannot be constructed with both of "
139+
"discard_events and enable_profiling.");
140+
if (!MDevice->has(aspect::queue_profiling))
141+
throw sycl::exception(make_error_code(errc::feature_not_supported),
142+
"Cannot enable profiling, the associated device "
143+
"does not have the queue_profiling aspect");
140144
}
141145
if (has_property<ext::intel::property::queue::compute_index>()) {
142146
int Idx = get_property<ext::intel::property::queue::compute_index>()

sycl/unittests/helpers/PiMockPlugin.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,14 @@ inline pi_result mock_piDeviceGetInfo(pi_device device,
216216
}
217217
return PI_SUCCESS;
218218
}
219+
case PI_DEVICE_INFO_QUEUE_PROPERTIES: {
220+
assert(param_value_size == sizeof(pi_queue_properties));
221+
if (param_value) {
222+
*static_cast<pi_queue_properties *>(param_value) =
223+
PI_QUEUE_FLAG_PROFILING_ENABLE;
224+
}
225+
return PI_SUCCESS;
226+
}
219227
default:
220228
return PI_SUCCESS;
221229
}

sycl/unittests/queue/GetProfilingInfo.cpp

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -378,33 +378,21 @@ pi_result redefinedFailedPiGetDeviceAndHostTimer(pi_device Device,
378378
return PI_ERROR_INVALID_OPERATION;
379379
}
380380

381-
pi_result redefinedPiPluginGetLastError(char **message) {
382-
static char messageString[50] = "Plugin version not supported";
383-
*message = messageString;
384-
return PI_SUCCESS;
385-
}
386-
387-
TEST(GetProfilingInfo, submission_time_exception_check) {
388-
using namespace sycl;
389-
unittest::PiMock Mock;
390-
platform Plt = Mock.getPlatform();
391-
Mock.redefine<detail::PiApiKind::piGetDeviceAndHostTimer>(
381+
TEST(GetProfilingInfo, unsupported_device_host_time) {
382+
sycl::unittest::PiMock Mock;
383+
sycl::platform Plt = Mock.getPlatform();
384+
Mock.redefine<sycl::detail::PiApiKind::piGetDeviceAndHostTimer>(
392385
redefinedFailedPiGetDeviceAndHostTimer);
393-
Mock.redefine<detail::PiApiKind::piPluginGetLastError>(
394-
redefinedPiPluginGetLastError);
395-
device Dev = Plt.get_devices()[0];
396-
context Ctx{Dev};
397-
queue Queue{Ctx, Dev, property::queue::enable_profiling()};
386+
const sycl::device Dev = Plt.get_devices()[0];
387+
sycl::context Ctx{Dev};
398388

389+
ASSERT_FALSE(Dev.has(sycl::aspect::queue_profiling));
399390
try {
400-
event E = Queue.submit(
401-
[&](handler &cgh) { cgh.single_task<TestKernel<>>([]() {}); });
402-
FAIL();
391+
sycl::queue q{Ctx, Dev, {sycl::property::queue::enable_profiling()}};
392+
FAIL() << "No exception was thrown";
403393
} catch (sycl::exception &e) {
404-
EXPECT_STREQ(
405-
e.what(),
406-
"Unable to get command group submission time: "
407-
"Device and/or backend does not support querying timestamp: "
408-
"Plugin version not supported -59 (PI_ERROR_INVALID_OPERATION)");
394+
EXPECT_EQ(e.code(), sycl::errc::feature_not_supported);
395+
EXPECT_STREQ(e.what(), "Cannot enable profiling, the associated device "
396+
"does not have the queue_profiling aspect");
409397
}
410398
}

0 commit comments

Comments
 (0)