Skip to content

[SYCL][XPTI] Use xptiTraceEnabled version with filter #10241

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 3 commits into from
Jul 7, 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
11 changes: 7 additions & 4 deletions sycl/source/detail/event_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ void *event_impl::instrumentationProlog(std::string &Name, int32_t StreamID,
uint64_t &IId) const {
void *TraceEvent = nullptr;
#ifdef XPTI_ENABLE_INSTRUMENTATION
if (!xptiTraceEnabled())
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
Expand All @@ -197,7 +198,7 @@ void *event_impl::instrumentationProlog(std::string &Name, int32_t StreamID,

// Record the current instance ID for use by Epilog
IId = InstanceID++;
xptiNotifySubscribers(StreamID, xpti::trace_wait_begin, nullptr, WaitEvent,
xptiNotifySubscribers(StreamID, NotificationTraceType, nullptr, WaitEvent,
IId, static_cast<const void *>(Name.c_str()));
TraceEvent = (void *)WaitEvent;
#endif
Expand All @@ -208,12 +209,14 @@ void event_impl::instrumentationEpilog(void *TelemetryEvent,
const std::string &Name,
int32_t StreamID, uint64_t IId) const {
#ifdef XPTI_ENABLE_INSTRUMENTATION
if (!(xptiTraceEnabled() && TelemetryEvent))
constexpr uint16_t NotificationTraceType = xpti::trace_wait_end;
if (!(xptiCheckTraceEnabled(StreamID, NotificationTraceType) &&
TelemetryEvent))
return;
// Close the wait() scope
xpti::trace_event_data_t *TraceEvent =
(xpti::trace_event_data_t *)TelemetryEvent;
xptiNotifySubscribers(StreamID, xpti::trace_wait_end, nullptr, TraceEvent,
xptiNotifySubscribers(StreamID, NotificationTraceType, nullptr, TraceEvent,
IId, static_cast<const void *>(Name.c_str()));
#endif
}
Expand Down
40 changes: 20 additions & 20 deletions sycl/source/detail/memory_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ uint64_t emitMemAllocBeginTrace(uintptr_t ObjHandle, size_t AllocSize,
(void)GuardZone;
uint64_t CorrelationID = 0;
#ifdef XPTI_ENABLE_INSTRUMENTATION
if (xptiTraceEnabled()) {
constexpr uint16_t NotificationTraceType =
static_cast<uint16_t>(xpti::trace_point_type_t::mem_alloc_begin);
if (xptiCheckTraceEnabled(GMemAllocStreamID, NotificationTraceType)) {
xpti::mem_alloc_data_t MemAlloc{ObjHandle, 0 /* alloc ptr */, AllocSize,
GuardZone};

CorrelationID = xptiGetUniqueId();
xptiNotifySubscribers(
GMemAllocStreamID,
static_cast<uint16_t>(xpti::trace_point_type_t::mem_alloc_begin),
GMemAllocEvent, nullptr, CorrelationID, &MemAlloc);
xptiNotifySubscribers(GMemAllocStreamID, NotificationTraceType,
GMemAllocEvent, nullptr, CorrelationID, &MemAlloc);
}
#endif
return CorrelationID;
Expand All @@ -64,13 +64,13 @@ void emitMemAllocEndTrace(uintptr_t ObjHandle, uintptr_t AllocPtr,
(void)GuardZone;
(void)CorrelationID;
#ifdef XPTI_ENABLE_INSTRUMENTATION
if (xptiTraceEnabled()) {
constexpr uint16_t NotificationTraceType =
static_cast<uint16_t>(xpti::trace_point_type_t::mem_alloc_end);
if (xptiCheckTraceEnabled(GMemAllocStreamID, NotificationTraceType)) {
xpti::mem_alloc_data_t MemAlloc{ObjHandle, AllocPtr, AllocSize, GuardZone};

xptiNotifySubscribers(
GMemAllocStreamID,
static_cast<uint16_t>(xpti::trace_point_type_t::mem_alloc_end),
GMemAllocEvent, nullptr, CorrelationID, &MemAlloc);
xptiNotifySubscribers(GMemAllocStreamID, NotificationTraceType,
GMemAllocEvent, nullptr, CorrelationID, &MemAlloc);
}
#endif
}
Expand All @@ -80,15 +80,15 @@ uint64_t emitMemReleaseBeginTrace(uintptr_t ObjHandle, uintptr_t AllocPtr) {
(void)AllocPtr;
uint64_t CorrelationID = 0;
#ifdef XPTI_ENABLE_INSTRUMENTATION
if (xptiTraceEnabled()) {
constexpr uint16_t NotificationTraceType =
static_cast<uint16_t>(xpti::trace_point_type_t::mem_release_begin);
if (xptiCheckTraceEnabled(GMemAllocStreamID, NotificationTraceType)) {
xpti::mem_alloc_data_t MemAlloc{ObjHandle, AllocPtr, 0 /* alloc size */,
0 /* guard zone */};

CorrelationID = xptiGetUniqueId();
xptiNotifySubscribers(
GMemAllocStreamID,
static_cast<uint16_t>(xpti::trace_point_type_t::mem_release_begin),
GMemAllocEvent, nullptr, CorrelationID, &MemAlloc);
xptiNotifySubscribers(GMemAllocStreamID, NotificationTraceType,
GMemAllocEvent, nullptr, CorrelationID, &MemAlloc);
}
#endif
return CorrelationID;
Expand All @@ -100,14 +100,14 @@ void emitMemReleaseEndTrace(uintptr_t ObjHandle, uintptr_t AllocPtr,
(void)AllocPtr;
(void)CorrelationID;
#ifdef XPTI_ENABLE_INSTRUMENTATION
if (xptiTraceEnabled()) {
constexpr uint16_t NotificationTraceType =
static_cast<uint16_t>(xpti::trace_point_type_t::mem_release_end);
if (xptiCheckTraceEnabled(GMemAllocStreamID, NotificationTraceType)) {
xpti::mem_alloc_data_t MemAlloc{ObjHandle, AllocPtr, 0 /* alloc size */,
0 /* guard zone */};

xptiNotifySubscribers(
GMemAllocStreamID,
static_cast<uint16_t>(xpti::trace_point_type_t::mem_release_end),
GMemAllocEvent, nullptr, CorrelationID, &MemAlloc);
xptiNotifySubscribers(GMemAllocStreamID, NotificationTraceType,
GMemAllocEvent, nullptr, CorrelationID, &MemAlloc);
}
#endif
}
Expand Down
52 changes: 30 additions & 22 deletions sycl/source/detail/pi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ xpti_td *GPICallEvent = nullptr;
xpti_td *GPIArgCallEvent = nullptr;
xpti_td *GPIArgCallActiveEvent = nullptr;

uint8_t PiCallStreamID = 0;
uint8_t PiDebugCallStreamID = 0;

#endif // XPTI_ENABLE_INSTRUMENTATION

template <sycl::backend BE> void *getPluginOpaqueData(void *OpaqueDataParam) {
Expand Down Expand Up @@ -108,28 +111,30 @@ uint64_t emitFunctionBeginTrace(const char *FName) {
/// xptiNotifySubscribers(stream_id, pi_func_begin, parent, event, instance,
/// (void *)argument_data);
/// \endcode
if (xptiTraceEnabled()) {
uint8_t StreamID = xptiRegisterStream(SYCL_PICALL_STREAM_NAME);
constexpr uint16_t NotificationTraceType =
(uint16_t)xpti::trace_point_type_t::function_begin;
if (xptiCheckTraceEnabled(PiCallStreamID, NotificationTraceType)) {
CorrelationID = xptiGetUniqueId();
xptiNotifySubscribers(
StreamID, (uint16_t)xpti::trace_point_type_t::function_begin,
GPICallEvent, nullptr, CorrelationID, static_cast<const void *>(FName));
xptiNotifySubscribers(PiCallStreamID, NotificationTraceType, GPICallEvent,
nullptr, CorrelationID,
static_cast<const void *>(FName));
}
#endif // XPTI_ENABLE_INSTRUMENTATION
return CorrelationID;
}

void emitFunctionEndTrace(uint64_t CorrelationID, const char *FName) {
#ifdef XPTI_ENABLE_INSTRUMENTATION
if (xptiTraceEnabled()) {
constexpr uint16_t NotificationTraceType =
(uint16_t)xpti::trace_point_type_t::function_end;
if (xptiCheckTraceEnabled(PiCallStreamID, NotificationTraceType)) {
// CorrelationID is the unique ID that ties together a function_begin and
// function_end pair of trace calls. The splitting of a scoped_notify into
// two function calls incurs an additional overhead as the StreamID must
// be looked up twice.
uint8_t StreamID = xptiRegisterStream(SYCL_PICALL_STREAM_NAME);
xptiNotifySubscribers(
StreamID, (uint16_t)xpti::trace_point_type_t::function_end,
GPICallEvent, nullptr, CorrelationID, static_cast<const void *>(FName));
xptiNotifySubscribers(PiCallStreamID, NotificationTraceType, GPICallEvent,
nullptr, CorrelationID,
static_cast<const void *>(FName));
}
#endif // XPTI_ENABLE_INSTRUMENTATION
}
Expand All @@ -139,9 +144,9 @@ uint64_t emitFunctionWithArgsBeginTrace(uint32_t FuncID, const char *FuncName,
pi_plugin Plugin) {
uint64_t CorrelationID = 0;
#ifdef XPTI_ENABLE_INSTRUMENTATION
if (xptiTraceEnabled()) {
uint8_t StreamID = xptiRegisterStream(SYCL_PIDEBUGCALL_STREAM_NAME);

constexpr uint16_t NotificationTraceType =
(uint16_t)xpti::trace_point_type_t::function_with_args_begin;
if (xptiCheckTraceEnabled(PiDebugCallStreamID, NotificationTraceType)) {
xpti::function_with_args_t Payload{FuncID, FuncName, ArgsData, nullptr,
&Plugin};
{
Expand All @@ -158,9 +163,9 @@ uint64_t emitFunctionWithArgsBeginTrace(uint32_t FuncID, const char *FuncName,
}

CorrelationID = xptiGetUniqueId();
xptiNotifySubscribers(
StreamID, (uint16_t)xpti::trace_point_type_t::function_with_args_begin,
GPIArgCallEvent, GPIArgCallActiveEvent, CorrelationID, &Payload);
xptiNotifySubscribers(PiDebugCallStreamID, NotificationTraceType,
GPIArgCallEvent, GPIArgCallActiveEvent, CorrelationID,
&Payload);
}
#endif
return CorrelationID;
Expand All @@ -170,15 +175,15 @@ void emitFunctionWithArgsEndTrace(uint64_t CorrelationID, uint32_t FuncID,
const char *FuncName, unsigned char *ArgsData,
pi_result Result, pi_plugin Plugin) {
#ifdef XPTI_ENABLE_INSTRUMENTATION
if (xptiTraceEnabled()) {
uint8_t StreamID = xptiRegisterStream(SYCL_PIDEBUGCALL_STREAM_NAME);

constexpr uint16_t NotificationTraceType =
(uint16_t)xpti::trace_point_type_t::function_with_args_end;
if (xptiCheckTraceEnabled(PiDebugCallStreamID, NotificationTraceType)) {
xpti::function_with_args_t Payload{FuncID, FuncName, ArgsData, &Result,
&Plugin};

xptiNotifySubscribers(
StreamID, (uint16_t)xpti::trace_point_type_t::function_with_args_end,
GPIArgCallEvent, GPIArgCallActiveEvent, CorrelationID, &Payload);
xptiNotifySubscribers(PiDebugCallStreamID, NotificationTraceType,
GPIArgCallEvent, GPIArgCallActiveEvent, CorrelationID,
&Payload);
GPIArgCallActiveEvent = nullptr;
}
#endif
Expand Down Expand Up @@ -524,6 +529,9 @@ static void initializePlugins(std::vector<PluginPtr> &Plugins) {
GPIArgCallEvent = xptiMakeEvent("PI Layer with arguments", &PIArgPayload,
xpti::trace_algorithm_event, xpti_at::active,
&PiArgInstanceNo);

PiCallStreamID = xptiRegisterStream(SYCL_PICALL_STREAM_NAME);
PiDebugCallStreamID = xptiRegisterStream(SYCL_PIDEBUGCALL_STREAM_NAME);
#endif
}

Expand Down
15 changes: 9 additions & 6 deletions sycl/source/detail/queue_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,8 @@ void *queue_impl::instrumentationProlog(const detail::code_location &CodeLoc,
(void)StreamID;
(void)IId;
#ifdef XPTI_ENABLE_INSTRUMENTATION
xpti::trace_event_data_t *WaitEvent = nullptr;
if (!xptiTraceEnabled())
constexpr uint16_t NotificationTraceType = xpti::trace_wait_begin;
if (!xptiCheckTraceEnabled(StreamID, NotificationTraceType))
return TraceEvent;

xpti::payload_t Payload;
Expand All @@ -407,8 +407,9 @@ void *queue_impl::instrumentationProlog(const detail::code_location &CodeLoc,
// event based on the code location info and if this has been seen before, a
// previously created event will be returned.
uint64_t QWaitInstanceNo = 0;
WaitEvent = xptiMakeEvent(Name.c_str(), &Payload, xpti::trace_graph_event,
xpti_at::active, &QWaitInstanceNo);
xpti::trace_event_data_t *WaitEvent =
xptiMakeEvent(Name.c_str(), &Payload, xpti::trace_graph_event,
xpti_at::active, &QWaitInstanceNo);
IId = QWaitInstanceNo;
if (WaitEvent) {
device D = get_device();
Expand Down Expand Up @@ -448,12 +449,14 @@ void queue_impl::instrumentationEpilog(void *TelemetryEvent, std::string &Name,
(void)StreamID;
(void)IId;
#ifdef XPTI_ENABLE_INSTRUMENTATION
if (!(xptiTraceEnabled() && TelemetryEvent))
constexpr uint16_t NotificationTraceType = xpti::trace_wait_end;
if (!(xptiCheckTraceEnabled(StreamID, NotificationTraceType) &&
TelemetryEvent))
return;
// Close the wait() scope
xpti::trace_event_data_t *TraceEvent =
(xpti::trace_event_data_t *)TelemetryEvent;
xptiNotifySubscribers(StreamID, xpti::trace_wait_end, nullptr, TraceEvent,
xptiNotifySubscribers(StreamID, NotificationTraceType, nullptr, TraceEvent,
IId, static_cast<const void *>(Name.c_str()));
#endif
}
Expand Down
87 changes: 48 additions & 39 deletions sycl/source/detail/queue_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,29 +117,32 @@ class queue_impl {
#if XPTI_ENABLE_INSTRUMENTATION
/// This section of code is relying on scoped objects, so they cannot be
/// encapsulated in a function
XPTIScope PrepareNotify((void *)this,
(uint16_t)xpti::trace_point_type_t::queue_create,
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 (xptiTraceEnabled()) {
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();
}
// 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
if (has_property<property::queue::enable_profiling>()) {
if (has_property<ext::oneapi::property::queue::discard_events>())
Expand Down Expand Up @@ -201,29 +204,33 @@ class queue_impl {
#if XPTI_ENABLE_INSTRUMENTATION
/// This section of code is relying on scoped objects, so they cannot be
/// encapsulated in a function
XPTIScope PrepareNotify((void *)this,
(uint16_t)xpti::trace_point_type_t::queue_create,
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 (xptiTraceEnabled()) {
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);
});
PrepareNotify.notify();
}
// 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
if (has_property<ext::oneapi::property::queue::discard_events>() &&
has_property<property::queue::enable_profiling>()) {
Expand Down Expand Up @@ -292,12 +299,14 @@ class queue_impl {
// lifetime of the queue object as member variables when ABI breakage is
// allowed. This example shows MTraceEvent as a member variable.
#if XPTI_ENABLE_INSTRUMENTATION
if (xptiTraceEnabled()) {
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, (uint16_t)xpti::trace_point_type_t::queue_destroy, nullptr,
(xpti::trace_event_data_t *)MTraceEvent, MInstanceID,
static_cast<const void *>("queue_destroy"));
xptiNotifySubscribers(MStreamID, NotificationTraceType, nullptr,
(xpti::trace_event_data_t *)MTraceEvent,
MInstanceID,
static_cast<const void *>("queue_destroy"));
}
#endif
throw_asynchronous();
Expand Down
Loading