Skip to content

[SYCL] Treat profiling as not supported if submit timestamps are not #8279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions sycl/plugins/hip/pi_hip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5330,6 +5330,9 @@ pi_result hip_piTearDown(void *PluginParameter) {

pi_result hip_piGetDeviceAndHostTimer(pi_device Device, uint64_t *DeviceTime,
uint64_t *HostTime) {
if (!DeviceTime && !HostTime)
return PI_SUCCESS;

_pi_event::native_type event;

ScopedContext active(Device->get_context());
Expand Down
21 changes: 15 additions & 6 deletions sycl/source/detail/device_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,23 @@ struct get_device_info_impl<std::vector<info::fp_config>,
}
};

// Specialization for queue_profiling, OpenCL returns a bitfield
// Specialization for queue_profiling. In addition to pi_queue level profiling,
// piGetDeviceAndHostTimer support is needed for command_submit query support.
template <> struct get_device_info_impl<bool, info::device::queue_profiling> {
static bool get(RT::PiDevice dev, const plugin &Plugin) {
cl_command_queue_properties result;
static bool get(RT::PiDevice Dev, const plugin &Plugin) {
pi_queue_properties Properties;
Plugin.call<PiApiKind::piDeviceGetInfo>(
dev, PiInfoCode<info::device::queue_profiling>::value, sizeof(result),
&result, nullptr);
return (result & CL_QUEUE_PROFILING_ENABLE);
Dev, PiInfoCode<info::device::queue_profiling>::value,
sizeof(Properties), &Properties, nullptr);
if (!(Properties & PI_QUEUE_FLAG_PROFILING_ENABLE))
return false;
RT::PiResult Result =
Plugin.call_nocheck<detail::PiApiKind::piGetDeviceAndHostTimer>(
Dev, nullptr, nullptr);
if (Result == PI_ERROR_INVALID_OPERATION)
return false;
Plugin.checkPiResult(Result);
return true;
}
};

Expand Down
14 changes: 9 additions & 5 deletions sycl/source/detail/queue_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,15 @@ class queue_impl {
});
PrepareNotify.notify();
#endif
if (has_property<ext::oneapi::property::queue::discard_events>() &&
has_property<property::queue::enable_profiling>()) {
throw sycl::exception(make_error_code(errc::invalid),
"Queue cannot be constructed with both of "
"discard_events and enable_profiling.");
if (has_property<property::queue::enable_profiling>()) {
if (has_property<ext::oneapi::property::queue::discard_events>())
throw sycl::exception(make_error_code(errc::invalid),
"Queue cannot be constructed with both of "
"discard_events and enable_profiling.");
if (!MDevice->has(aspect::queue_profiling))
throw sycl::exception(make_error_code(errc::feature_not_supported),
"Cannot enable profiling, the associated device "
"does not have the queue_profiling aspect");
}
if (has_property<ext::intel::property::queue::compute_index>()) {
int Idx = get_property<ext::intel::property::queue::compute_index>()
Expand Down
8 changes: 8 additions & 0 deletions sycl/unittests/helpers/PiMockPlugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,14 @@ inline pi_result mock_piDeviceGetInfo(pi_device device,
}
return PI_SUCCESS;
}
case PI_DEVICE_INFO_QUEUE_PROPERTIES: {
assert(param_value_size == sizeof(pi_queue_properties));
if (param_value) {
*static_cast<pi_queue_properties *>(param_value) =
PI_QUEUE_FLAG_PROFILING_ENABLE;
}
return PI_SUCCESS;
}
default:
return PI_SUCCESS;
}
Expand Down
36 changes: 12 additions & 24 deletions sycl/unittests/queue/GetProfilingInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,33 +378,21 @@ pi_result redefinedFailedPiGetDeviceAndHostTimer(pi_device Device,
return PI_ERROR_INVALID_OPERATION;
}

pi_result redefinedPiPluginGetLastError(char **message) {
static char messageString[50] = "Plugin version not supported";
*message = messageString;
return PI_SUCCESS;
}

TEST(GetProfilingInfo, submission_time_exception_check) {
using namespace sycl;
unittest::PiMock Mock;
platform Plt = Mock.getPlatform();
Mock.redefine<detail::PiApiKind::piGetDeviceAndHostTimer>(
TEST(GetProfilingInfo, unsupported_device_host_time) {
sycl::unittest::PiMock Mock;
sycl::platform Plt = Mock.getPlatform();
Mock.redefine<sycl::detail::PiApiKind::piGetDeviceAndHostTimer>(
redefinedFailedPiGetDeviceAndHostTimer);
Mock.redefine<detail::PiApiKind::piPluginGetLastError>(
redefinedPiPluginGetLastError);
device Dev = Plt.get_devices()[0];
context Ctx{Dev};
queue Queue{Ctx, Dev, property::queue::enable_profiling()};
const sycl::device Dev = Plt.get_devices()[0];
sycl::context Ctx{Dev};

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