Skip to content
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

[SYCL][XPTI] Refactoring framework to use 128-bit keys for collision elimination #14467

Merged
merged 46 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
12a61e4
[XPTI][INFRO] Support for scope notification at runtime
tovinkere Jun 21, 2024
d04a1c1
[XPTI][INFRA] Switched from std::unordered_map to emhash8
tovinkere Jun 22, 2024
72324dd
[XPTI][INFRA] Enabled 128-bit keys and 64-bit mapping for legacy
tovinkere Jun 25, 2024
120a824
Merge remote-tracking branch 'origin' into xpti_refactoring_compat
tovinkere Jun 25, 2024
955f805
[XPTI][INFRA] Added supporting API to enable 128-bit keys
tovinkere Jun 28, 2024
5b060da
[XPTI][INFRA] Updated performance tests to include new APIs
tovinkere Jun 28, 2024
dc15a7c
[XPTI][INFRA] Support both 64-bit and 128-bit modes
tovinkere Jun 29, 2024
7e00d87
[XPTI][INFRA] Completed transition to 128-bit, 64-bit co-existence
tovinkere Jul 1, 2024
5019c69
Merge remote-tracking branch 'origin' into xpti_refactoring_compat
tovinkere Jul 2, 2024
ece9bd0
[SYCL][XPTI] Updated trace event creation to happen for every instance
tovinkere Jul 3, 2024
749f075
[SYCL][XPTI] Updating queue.wait events with right contexts
tovinkere Jul 4, 2024
cd64e97
[XPTI][INFRA] Helper macros in support of URT integration
tovinkere Jul 5, 2024
1cbf8c7
[SYCL][XPTI] Addresses a migration issue + fixes warnings
tovinkere Jul 5, 2024
52321bd
[SYCL][XPTI] Removing debug statement
tovinkere Jul 5, 2024
5386f2d
Merge remote-tracking branch 'origin' into xpti_refactoring_compat
tovinkere Jul 6, 2024
efbb76f
[SYCL][XPTI] Updated documentation and tests
tovinkere Jul 6, 2024
05bf6e1
[SYCL][XPTI] clang format
tovinkere Jul 6, 2024
5b4c18d
[XPTI][INFRA] Moved to 'emhash' from 'parallel_hashmap'
tovinkere Jul 9, 2024
db18ee8
Merge remote-tracking branch 'origin' into xpti_refactoring_compat
tovinkere Jul 9, 2024
e98d31c
[XPTI][INFRA] Using "parallel_hashmap" along with "emhash"
tovinkere Jul 9, 2024
e4b01ee
[XPTI][INFRA] External file clang format failure
tovinkere Jul 9, 2024
7e71519
{SYCL][XPTI] Addresses review feedback
tovinkere Jul 19, 2024
c7e26fb
Merge remote-tracking branch 'origin' into xpti_refactoring_compat
tovinkere Jul 19, 2024
ebab90c
[SYCL][XPTI] Initialization
tovinkere Jul 19, 2024
908c103
[XPTI] Ctor initialization order
tovinkere Jul 19, 2024
9ccc216
[SYCL][XPTI] clang-format
tovinkere Jul 19, 2024
0e4128a
[SYCL] clang-format
tovinkere Jul 19, 2024
26f1bce
[XPTI] Windows builtin macro fix
tovinkere Jul 19, 2024
351e9c9
[XPTI] Using builtins for MSFT as VS2019/2022 support them
tovinkere Jul 20, 2024
b0118e7
[XPTI][INFRA] clang-format
tovinkere Jul 20, 2024
ca9a437
[XPTI][INFRA] clang-format
tovinkere Jul 20, 2024
205fdc3
[XPTI][INFRA] clang-format
tovinkere Jul 20, 2024
2b028fb
[XPTI][INFRA] clang-format
tovinkere Jul 20, 2024
c2a405b
Merge remote-tracking branch 'upstream/sycl' into xpti_refactoring_co…
KseniyaTikhomirova Aug 2, 2024
f722748
fix clang-format
KseniyaTikhomirova Aug 2, 2024
47722da
Merge remote-tracking branch 'upstream/sycl' into xpti_refactoring_co…
KseniyaTikhomirova Aug 8, 2024
dacb7e1
ignore clang format mismatch in third party projects
KseniyaTikhomirova Aug 9, 2024
230dd7f
fix format
KseniyaTikhomirova Aug 9, 2024
984ec95
Revert "fix format"
KseniyaTikhomirova Aug 9, 2024
e2cc25e
Revert "ignore clang format mismatch in third party projects"
KseniyaTikhomirova Aug 9, 2024
ab81cfe
[XPTI][INFRA] Removed reference to C++14 requirement
tovinkere Aug 13, 2024
04c5f2d
Merge remote-tracking branch 'origin' into xpti_refactoring_compat
tovinkere Aug 13, 2024
fc74bd3
Merge remote-tracking branch 'origin/sycl' into tovinkere_xpti_refact…
againull Aug 26, 2024
547cb71
Link with required thread library
againull Aug 26, 2024
02944f3
Fetch third-party headers at build time
Aug 13, 2024
ec3b345
Merge remote-tracking branch 'origin/sycl' into tovinkere_xpti_refact…
againull Aug 27, 2024
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
154 changes: 77 additions & 77 deletions sycl/doc/design/SYCLInstrumentationUsingXPTI.md

Large diffs are not rendered by default.

20 changes: 13 additions & 7 deletions sycl/source/detail/event_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,6 @@ void *event_impl::instrumentationProlog(std::string &Name, int32_t StreamID,
constexpr uint16_t NotificationTraceType = xpti::trace_wait_begin;
if (!xptiCheckTraceEnabled(StreamID, NotificationTraceType))
return TraceEvent;
// Use a thread-safe counter to get a unique instance ID for the wait() on the
// event
static std::atomic<uint64_t> InstanceID = {1};
xpti::trace_event_data_t *WaitEvent = nullptr;

// Create a string with the event address so it
Expand All @@ -193,11 +190,20 @@ void *event_impl::instrumentationProlog(std::string &Name, int32_t StreamID,
Command *Cmd = (Command *)MCommand;
WaitEvent = Cmd->MTraceEvent ? static_cast<xpti_td *>(Cmd->MTraceEvent)
: GSYCLGraphEvent;
} else
WaitEvent = GSYCLGraphEvent;

} else {
// If queue.wait() is used, we want to make sure the information about the
// queue is available with the eait events. We check to see if the
Copy link
Contributor

Choose a reason for hiding this comment

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

mistype, "wait"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

// TraceEvent is available in the Queue object.
void *TraceEvent;
if (QueueImplPtr Queue = MQueue.lock()) {
TraceEvent = Queue->getTraceEvent();
WaitEvent =
(TraceEvent ? static_cast<xpti_td *>(TraceEvent) : GSYCLGraphEvent);
} else
WaitEvent = GSYCLGraphEvent;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: the following looks a bit more simpler

void *TraceEvent = nullptr;
if (QueueImplPtr Queue = MQueue.lock()) {
TraceEvent = Queue->getTraceEvent();

WaitEvent = (TraceEvent ? static_cast<xpti_td *>(TraceEvent) : GSYCLGraphEvent);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Shouldn't we handle the if(QueueImplPtr Queue = MQueue.lock()) being false case?

}
// Record the current instance ID for use by Epilog
IId = InstanceID++;
IId = xptiGetUniqueId();
xptiNotifySubscribers(StreamID, NotificationTraceType, nullptr, WaitEvent,
IId, static_cast<const void *>(Name.c_str()));
TraceEvent = (void *)WaitEvent;
Expand Down
62 changes: 60 additions & 2 deletions sycl/source/detail/queue_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ event queue_impl::memset(const std::shared_ptr<detail::queue_impl> &Self,
// information
XPTIScope PrepareNotify((void *)this,
(uint16_t)xpti::trace_point_type_t::node_create,
SYCL_STREAM_NAME, "memory_transfer_node");
SYCL_STREAM_NAME, "memory_transfer_node::memset");
PrepareNotify.addMetadata([&](auto TEvent) {
xpti::addMetadata(TEvent, "sycl_device",
reinterpret_cast<size_t>(MDevice->getHandleRef()));
Expand Down Expand Up @@ -203,7 +203,7 @@ event queue_impl::memcpy(const std::shared_ptr<detail::queue_impl> &Self,
// pointer.
XPTIScope PrepareNotify((void *)this,
(uint16_t)xpti::trace_point_type_t::node_create,
SYCL_STREAM_NAME, "memory_transfer_node");
SYCL_STREAM_NAME, "memory_transfer_node::memcpy");
PrepareNotify.addMetadata([&](auto TEvent) {
xpti::addMetadata(TEvent, "sycl_device",
reinterpret_cast<size_t>(MDevice->getHandleRef()));
Expand Down Expand Up @@ -632,6 +632,64 @@ void queue_impl::wait(const detail::code_location &CodeLoc) {
#endif
}

void queue_impl::constructorNotification() {
#if XPTI_ENABLE_INSTRUMENTATION
if (xptiTraceEnabled()) {
MStreamID = xptiRegisterStream(SYCL_STREAM_NAME);
constexpr uint16_t NotificationTraceType =
static_cast<uint16_t>(xpti::trace_point_type_t::queue_create);
if (xptiCheckTraceEnabled(MStreamID, NotificationTraceType)) {
xpti::utils::StringHelper SH;
std::string AddrStr = SH.addressAsString<size_t>(MQueueID);
std::string QueueName = SH.nameWithAddressString("queue", AddrStr);
// Create a payload for the queue create event as we do not get code
// location for the queue create event
xpti::payload_t QPayload(QueueName.c_str());
MInstanceID = xptiGetUniqueId();
uint64_t RetInstanceNo;
xpti_td *TEvent =
xptiMakeEvent("queue_create", &QPayload,
(uint16_t)xpti::trace_event_type_t::algorithm,
xpti_at::active, &RetInstanceNo);
// Cache the trace event, stream id and instance IDs for the destructor
MTraceEvent = (void *)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->getHandleRef()));
}
xpti::addMetadata(TEvent, "is_inorder", MIsInorder);
xpti::addMetadata(TEvent, "queue_id", MQueueID);
xpti::addMetadata(TEvent, "queue_handle",
reinterpret_cast<size_t>(getHandleRef()));
// Also publish to TLS before notification
xpti::framework::stash_tuple(XPTI_QUEUE_INSTANCE_ID_KEY, MQueueID);
xptiNotifySubscribers(
MStreamID, (uint16_t)xpti::trace_point_type_t::queue_create, nullptr,
TEvent, MInstanceID, static_cast<const void *>("queue_create"));
}
}
#endif
}

void queue_impl::destructorNotification() {
#if XPTI_ENABLE_INSTRUMENTATION
constexpr uint16_t NotificationTraceType =
static_cast<uint16_t>(xpti::trace_point_type_t::queue_destroy);
if (xptiCheckTraceEnabled(MStreamID, NotificationTraceType)) {
// Use the cached trace event, stream id and instance IDs for the
// destructor
xptiNotifySubscribers(MStreamID, NotificationTraceType, nullptr,
(xpti::trace_event_data_t *)MTraceEvent, MInstanceID,
static_cast<const void *>("queue_destroy"));
xptiReleaseEvent((xpti::trace_event_data_t *)MTraceEvent);
}
#endif
}

pi_native_handle queue_impl::getNative(int32_t &NativeHandleDesc) const {
const PluginPtr &Plugin = getPlugin();
if (getContextImplPtr()->getBackend() == backend::opencl)
Expand Down
91 changes: 21 additions & 70 deletions sycl/source/detail/queue_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,37 +174,10 @@ class queue_impl {
// 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
constexpr uint16_t NotificationTraceType =
static_cast<uint16_t>(xpti::trace_point_type_t::queue_create);
// Using the instance override constructor for use with queues as queues
// maintain instance IDs in the object
XPTIScope PrepareNotify((void *)this, NotificationTraceType,
SYCL_STREAM_NAME, MQueueID, "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->getHandleRef()));
}
xpti::addMetadata(TEvent, "is_inorder", MIsInorder);
xpti::addMetadata(TEvent, "queue_id", MQueueID);
xpti::addMetadata(TEvent, "queue_handle",
reinterpret_cast<size_t>(getHandleRef()));
});
// Also publish to TLS
xpti::framework::stash_tuple(XPTI_QUEUE_INSTANCE_ID_KEY, MQueueID);
PrepareNotify.notify();
}
// Emit a trace event for queue creation; we currently do not get code
// location information, so all queueus will have the same UID with a
// different instance ID until this gets added.
constructorNotification();
#endif
}

Expand Down Expand Up @@ -237,35 +210,10 @@ class queue_impl {
// 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, MQueueID, "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->getHandleRef()));
}
xpti::addMetadata(TEvent, "is_inorder", MIsInorder);
xpti::addMetadata(TEvent, "queue_id", MQueueID);
xpti::addMetadata(TEvent, "queue_handle", getHandleRef());
});
// Also publish to TLS before notification
xpti::framework::stash_tuple(XPTI_QUEUE_INSTANCE_ID_KEY, MQueueID);
PrepareNotify.notify();
}
// Emit a trace event for queue creation; we currently do not get code
// location information, so all queueus will have the same UID with a
// different instance ID until this gets added.
constructorNotification();
#endif
}

Expand Down Expand Up @@ -311,16 +259,10 @@ class queue_impl {
// lifetime of the queue object as member variables when ABI breakage is
Copy link
Contributor

Choose a reason for hiding this comment

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

probably old comment should be removed now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done! It was a stale comment.

// allowed. This example shows MTraceEvent as a member variable.
#if XPTI_ENABLE_INSTRUMENTATION
constexpr uint16_t NotificationTraceType =
static_cast<uint16_t>(xpti::trace_point_type_t::queue_destroy);
if (xptiCheckTraceEnabled(MStreamID, NotificationTraceType)) {
// Used cached information in member variables
xptiNotifySubscribers(MStreamID, NotificationTraceType, nullptr,
(xpti::trace_event_data_t *)MTraceEvent,
MInstanceID,
static_cast<const void *>("queue_destroy"));
xptiReleaseEvent((xpti::trace_event_data_t *)MTraceEvent);
}
// The trace event created in the constructor should be active through the
// lifetime of the queue object as member variable. We will send a
// notification and destroy the trace event for this queue.
destructorNotification();
#endif
throw_asynchronous();
cleanup_fusion_cmd();
Expand Down Expand Up @@ -739,6 +681,8 @@ class queue_impl {

unsigned long long getQueueID() { return MQueueID; }

void *getTraceEvent() { return MTraceEvent; }

void setExternalEvent(const event &Event) {
std::lock_guard<std::mutex> Lock(MInOrderExternalEventMtx);
MInOrderExternalEvent = Event;
Expand Down Expand Up @@ -925,6 +869,13 @@ class queue_impl {
void instrumentationEpilog(void *TelementryEvent, std::string &Name,
int32_t StreamID, uint64_t IId);

// We need to emit a queue_create notification when a queue object is created
void constructorNotification();

// We need to emit a queue_destroy notification when a queue object is
// destroyed
void destructorNotification();

/// queue_impl.addEvent tracks events with weak pointers
/// but some events have no other owners. addSharedEvent()
/// follows events with a shared pointer.
Expand Down
Loading
Loading