Skip to content

[SYCL][XPTI] Add unique queue ID to trace #11548

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 26 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
0e65df8
[SYCL] Add unique queue ID to xpti traces:queue_create and queue_destroy
KseniyaTikhomirova Oct 13, 2023
03381f8
add queue ID to task_begin traces
KseniyaTikhomirova Oct 13, 2023
d38e386
draft
KseniyaTikhomirova Oct 16, 2023
563a94f
add test case
KseniyaTikhomirova Oct 17, 2023
e02636e
add tests
KseniyaTikhomirova Oct 18, 2023
348431d
add trace to kernel shortcut + test
KseniyaTikhomirova Oct 18, 2023
27ef055
add handle to test
KseniyaTikhomirova Oct 19, 2023
1f8e0c2
add xptiReleaseEvent
KseniyaTikhomirova Oct 20, 2023
719873d
fix some comments
KseniyaTikhomirova Oct 23, 2023
25bdb2b
fix format
KseniyaTikhomirova Oct 23, 2023
05b29d6
fix format in xpti sources
KseniyaTikhomirova Oct 23, 2023
30778b3
remove prints
KseniyaTikhomirova Oct 23, 2023
b538afa
add queue_create/destroy to sycl-trace sycl print
KseniyaTikhomirova Oct 23, 2023
f78f389
add task_begin/end trace to sycl-trace tool
KseniyaTikhomirova Oct 23, 2023
13ca4e2
fix subscribers and test
KseniyaTikhomirova Oct 23, 2023
336acad
add E2E test
KseniyaTikhomirova Oct 24, 2023
b75e9cb
add doc. part 1
KseniyaTikhomirova Oct 24, 2023
cc0a7b8
add doc. part 1 with fix
KseniyaTikhomirova Oct 24, 2023
595e8b2
add doc. part 1 with fix 2
KseniyaTikhomirova Oct 24, 2023
dd05ab5
add queue_id to node_create
KseniyaTikhomirova Oct 25, 2023
a49fbe2
fix test
KseniyaTikhomirova Oct 25, 2023
a48d8be
fix E2E test
KseniyaTikhomirova Oct 25, 2023
ae227b0
add note
KseniyaTikhomirova Oct 25, 2023
4b43eb7
add one more test and fix
KseniyaTikhomirova Oct 25, 2023
625a357
fix test
KseniyaTikhomirova Oct 25, 2023
8e7693c
fix comments
KseniyaTikhomirova Oct 25, 2023
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
6 changes: 3 additions & 3 deletions sycl/doc/design/SYCLInstrumentationUsingXPTI.md

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion sycl/source/detail/queue_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
namespace sycl {
inline namespace _V1 {
namespace detail {

std::atomic<unsigned long long> queue_impl::MNextAvailableQueueID = 0;

template <>
uint32_t queue_impl::get_info<info::queue::reference_count>() const {
sycl::detail::pi::PiResult result = PI_SUCCESS;
Expand Down Expand Up @@ -75,6 +78,7 @@ event queue_impl::memset(const std::shared_ptr<detail::queue_impl> &Self,
xpti::addMetadata(TEvent, "memory_ptr", reinterpret_cast<size_t>(Ptr));
xpti::addMetadata(TEvent, "value_set", Value);
xpti::addMetadata(TEvent, "memory_size", Count);
xpti::addMetadata(TEvent, "queue_id", MQueueID);
});
// Notify XPTI about the memset submission
PrepareNotify.notify();
Expand Down Expand Up @@ -152,6 +156,7 @@ event queue_impl::memcpy(const std::shared_ptr<detail::queue_impl> &Self,
xpti::addMetadata(TEvent, "dest_memory_ptr",
reinterpret_cast<size_t>(Dest));
xpti::addMetadata(TEvent, "memory_size", Count);
xpti::addMetadata(TEvent, "queue_id", MQueueID);
});
// Notify XPTI about the memset submission
PrepareNotify.notify();
Expand Down Expand Up @@ -448,7 +453,7 @@ void *queue_impl::instrumentationProlog(const detail::code_location &CodeLoc,
DevStr = "ACCELERATOR";
else
DevStr = "UNKNOWN";
xpti::addMetadata(WaitEvent, "sycl_device", DevStr);
xpti::addMetadata(WaitEvent, "sycl_device_type", DevStr);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

if (HasSourceInfo) {
xpti::addMetadata(WaitEvent, "sym_function_name", CodeLoc.functionName());
xpti::addMetadata(WaitEvent, "sym_source_file_name", CodeLoc.fileName());
Expand Down
105 changes: 59 additions & 46 deletions sycl/source/detail/queue_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,39 +113,9 @@ class queue_impl {
has_property<ext::oneapi::property::queue::discard_events>()),
MIsProfilingEnabled(has_property<property::queue::enable_profiling>()),
MHasDiscardEventsSupport(MDiscardEvents &&
(MHostQueue ? true : MIsInorder)) {
// We enable XPTI tracing events using the TLS mechanism; if the code
// location data is available, then the tracing data will be rich.
#if XPTI_ENABLE_INSTRUMENTATION
/// This section of code is relying on scoped objects, so they cannot be
/// encapsulated in a function
constexpr uint16_t NotificationTraceType =
static_cast<uint16_t>(xpti::trace_point_type_t::queue_create);
XPTIScope PrepareNotify((void *)this, NotificationTraceType,
SYCL_STREAM_NAME, "queue_create");
// Cache the trace event, stream id and instance IDs for the destructor
if (xptiCheckTraceEnabled(PrepareNotify.streamID(),
NotificationTraceType)) {
MTraceEvent = (void *)PrepareNotify.traceEvent();
MStreamID = PrepareNotify.streamID();
MInstanceID = PrepareNotify.instanceID();
// Add the function to capture meta data for the XPTI trace event
PrepareNotify.addMetadata([&](auto TEvent) {
xpti::addMetadata(TEvent, "sycl_context",
reinterpret_cast<size_t>(MContext->getHandleRef()));
if (MDevice) {
xpti::addMetadata(TEvent, "sycl_device_name",
MDevice->getDeviceName());
xpti::addMetadata(
TEvent, "sycl_device",
reinterpret_cast<size_t>(
MDevice->is_host() ? 0 : MDevice->getHandleRef()));
}
xpti::addMetadata(TEvent, "is_inorder", MIsInorder);
});
PrepareNotify.notify();
}
#endif
(MHostQueue ? true : MIsInorder)),
MQueueID{
MNextAvailableQueueID.fetch_add(1, std::memory_order_relaxed)} {
if (has_property<property::queue::enable_profiling>()) {
if (has_property<ext::oneapi::property::queue::discard_events>())
throw sycl::exception(make_error_code(errc::invalid),
Expand Down Expand Up @@ -196,28 +166,19 @@ class queue_impl {
// This section is the second part of the instrumentation that uses the
// tracepoint information and notifies
}
}

private:
void queue_impl_interop(sycl::detail::pi::PiQueue PiQueue) {
// The following commented section provides a guideline on how to use the
// TLS enabled mechanism to create a tracepoint and notify using XPTI. This
// is the prolog section and the epilog section will initiate the
// notification.
// We enable XPTI tracing events using the TLS mechanism; if the code
// location data is available, then the tracing data will be rich.
#if XPTI_ENABLE_INSTRUMENTATION
/// This section of code is relying on scoped objects, so they cannot be
/// encapsulated in a function
constexpr uint16_t NotificationTraceType =
static_cast<uint16_t>(xpti::trace_point_type_t::queue_create);
XPTIScope PrepareNotify((void *)this, NotificationTraceType,
SYCL_STREAM_NAME, "queue_create");
// Cache the trace event, stream id and instance IDs for the destructor
if (xptiCheckTraceEnabled(PrepareNotify.streamID(),
NotificationTraceType)) {
// Cache the trace event, stream id and instance IDs for the destructor
MTraceEvent = (void *)PrepareNotify.traceEvent();
MStreamID = PrepareNotify.streamID();
MInstanceID = PrepareNotify.instanceID();

// Add the function to capture meta data for the XPTI trace event
PrepareNotify.addMetadata([&](auto TEvent) {
xpti::addMetadata(TEvent, "sycl_context",
Expand All @@ -231,10 +192,18 @@ class queue_impl {
MDevice->is_host() ? 0 : MDevice->getHandleRef()));
}
xpti::addMetadata(TEvent, "is_inorder", MIsInorder);
xpti::addMetadata(TEvent, "queue_id", MQueueID);
if (!MHostQueue)
xpti::addMetadata(TEvent, "queue_handle",
reinterpret_cast<size_t>(getHandleRef()));
});
PrepareNotify.notify();
}
#endif
}

private:
void queue_impl_interop(sycl::detail::pi::PiQueue PiQueue) {
if (has_property<ext::oneapi::property::queue::discard_events>() &&
has_property<property::queue::enable_profiling>()) {
throw sycl::exception(make_error_code(errc::invalid),
Expand All @@ -255,6 +224,42 @@ class queue_impl {
make_error_code(errc::invalid),
"Device provided by native Queue not found in Context.");
}
// The following commented section provides a guideline on how to use the
// TLS enabled mechanism to create a tracepoint and notify using XPTI. This
// is the prolog section and the epilog section will initiate the
// notification.
#if XPTI_ENABLE_INSTRUMENTATION
constexpr uint16_t NotificationTraceType =
static_cast<uint16_t>(xpti::trace_point_type_t::queue_create);
XPTIScope PrepareNotify((void *)this, NotificationTraceType,
SYCL_STREAM_NAME, "queue_create");
if (xptiCheckTraceEnabled(PrepareNotify.streamID(),
NotificationTraceType)) {
// Cache the trace event, stream id and instance IDs for the destructor
MTraceEvent = (void *)PrepareNotify.traceEvent();
MStreamID = PrepareNotify.streamID();
MInstanceID = PrepareNotify.instanceID();

// Add the function to capture meta data for the XPTI trace event
PrepareNotify.addMetadata([&](auto TEvent) {
xpti::addMetadata(TEvent, "sycl_context",
reinterpret_cast<size_t>(MContext->getHandleRef()));
if (MDevice) {
xpti::addMetadata(TEvent, "sycl_device_name",
MDevice->getDeviceName());
xpti::addMetadata(
TEvent, "sycl_device",
reinterpret_cast<size_t>(
MDevice->is_host() ? 0 : MDevice->getHandleRef()));
}
xpti::addMetadata(TEvent, "is_inorder", MIsInorder);
xpti::addMetadata(TEvent, "queue_id", MQueueID);
if (!MHostQueue)
xpti::addMetadata(TEvent, "queue_handle", getHandleRef());
});
PrepareNotify.notify();
}
#endif
}

public:
Expand All @@ -273,7 +278,9 @@ class queue_impl {
has_property<ext::oneapi::property::queue::discard_events>()),
MIsProfilingEnabled(has_property<property::queue::enable_profiling>()),
MHasDiscardEventsSupport(MDiscardEvents &&
(MHostQueue ? true : MIsInorder)) {
(MHostQueue ? true : MIsInorder)),
MQueueID{
MNextAvailableQueueID.fetch_add(1, std::memory_order_relaxed)} {
queue_impl_interop(PiQueue);
}

Expand Down Expand Up @@ -310,6 +317,7 @@ class queue_impl {
(xpti::trace_event_data_t *)MTraceEvent,
MInstanceID,
static_cast<const void *>("queue_destroy"));
xptiReleaseEvent((xpti::trace_event_data_t *)MTraceEvent);
}
#endif
throw_asynchronous();
Expand Down Expand Up @@ -695,6 +703,8 @@ class queue_impl {
return MGraph.lock();
}

unsigned long long getQueueID() { return MQueueID; }

protected:
// Hook to the scheduler to clean up any fusion command held on destruction.
void cleanup_fusion_cmd();
Expand Down Expand Up @@ -873,6 +883,9 @@ class queue_impl {
// recording commands to it.
std::weak_ptr<ext::oneapi::experimental::detail::graph_impl> MGraph{};

unsigned long long MQueueID;
static std::atomic<unsigned long long> MNextAvailableQueueID;

friend class sycl::ext::oneapi::experimental::detail::node_impl;
};

Expand Down
Loading