Skip to content

[SYCL][XPTI] Organize XPTI objects in one location(XPTI Registry) #19630

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

Open
wants to merge 5 commits into
base: sycl
Choose a base branch
from
Open
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: 0 additions & 3 deletions sycl/source/detail/buffer_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
namespace sycl {
inline namespace _V1 {
namespace detail {
#ifdef XPTI_ENABLE_INSTRUMENTATION
uint8_t GBufferStreamID;
#endif
void *buffer_impl::allocateMem(context_impl *Context, bool InitFromUserData,
void *HostPtr,
ur_event_handle_t &OutEventToWait) {
Expand Down
10 changes: 2 additions & 8 deletions sycl/source/detail/event_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <chrono>

#ifdef XPTI_ENABLE_INSTRUMENTATION
#include "xpti/xpti_trace_framework.hpp"
#include <atomic>
#include <detail/xpti_registry.hpp>
#include <sstream>
Expand All @@ -28,10 +27,6 @@
namespace sycl {
inline namespace _V1 {
namespace detail {
#ifdef XPTI_ENABLE_INSTRUMENTATION
extern xpti::trace_event_data_t *GSYCLGraphEvent;
#endif

// If we do not yet have a context, use the default one.
void event_impl::initContextIfNeeded() {
if (MContext || !MIsDefaultConstructed)
Expand Down Expand Up @@ -293,8 +288,7 @@ void event_impl::wait(bool *Success) {
void *TelemetryEvent = nullptr;
uint64_t IId = 0;
std::string Name;
xpti::stream_id_t StreamID = xptiRegisterStream(SYCL_STREAM_NAME);
TelemetryEvent = instrumentationProlog(Name, StreamID, IId);
TelemetryEvent = instrumentationProlog(Name, GSYCLStreamID, IId);
#endif

auto EventHandle = getHandle();
Expand All @@ -306,7 +300,7 @@ void event_impl::wait(bool *Success) {
detail::Scheduler::getInstance().waitForEvent(*this, Success);

#ifdef XPTI_ENABLE_INSTRUMENTATION
instrumentationEpilog(TelemetryEvent, Name, StreamID, IId);
instrumentationEpilog(TelemetryEvent, Name, GSYCLStreamID, IId);
#endif
}

Expand Down
34 changes: 8 additions & 26 deletions sycl/source/detail/global_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,46 +77,28 @@ std::atomic_uint ObjectUsageCounter::MCounter{0};
GlobalHandler::GlobalHandler() = default;
GlobalHandler::~GlobalHandler() = default;

void GlobalHandler::InitXPTI() {
#ifdef XPTI_ENABLE_INSTRUMENTATION
// Let subscribers know a new stream is being initialized
getXPTIRegistry().initializeStream(SYCL_STREAM_NAME, GMajVer, GMinVer,
GVerStr);
xpti::payload_t SYCLPayload("SYCL Runtime Exceptions");
uint64_t SYCLInstanceNo;
GSYCLCallEvent = xptiMakeEvent("SYCL Try-catch Exceptions", &SYCLPayload,
xpti::trace_algorithm_event, xpti_at::active,
&SYCLInstanceNo);
#endif
}

void GlobalHandler::TraceEventXPTI(const char *Message) {
if (!Message)
return;
#ifdef XPTI_ENABLE_INSTRUMENTATION
static std::once_flag InitXPTIFlag;
// This section is used to emit XPTI trace events when exceptions occur
if (xptiTraceEnabled()) {
std::call_once(InitXPTIFlag, [&]() { InitXPTI(); });
GlobalHandler::instance().getXPTIRegistry().initializeFrameworkOnce();

// We have to handle the cases where: (1) we may have just the code location
// set and not UID and (2) UID set
detail::tls_code_loc_t Tls;
auto CodeLocation = Tls.query();

// Creating a tracepoint will convert a CodeLocation to UID, if not set
xpti::framework::tracepoint_t TP(
// Creating a tracepoint using the stashed code location and notifying the
// subscriber with the diagnostic message
xpti::framework::tracepoint_scope_t TP(
CodeLocation.fileName(), CodeLocation.functionName(),
CodeLocation.lineNumber(), CodeLocation.columnNumber(), nullptr);

// The call to notify will have the signature of:
// (1) the stream defined in .stream()
// (2) The trace type equal to what is set by .trace_type()
// (3) Parent event set to NULL
// (4) Current event set to one created from CodeLocation and UID
// (5) An instance ID that records the number of times this code location
// has been seen (6) The message generated by the exception handler
TP.stream(SYCL_STREAM_NAME)
.trace_type(xpti::trace_point_type_t::diagnostics)
TP.stream(GSYCLStreamID)
.traceType(xpti::trace_point_type_t::diagnostics)
.parentEvent(GSYCLCallEvent)
.notify(static_cast<const void *>(Message));
}

Expand Down
5 changes: 0 additions & 5 deletions sycl/source/detail/global_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,12 @@ class GlobalHandler {
void drainThreadPool();
void prepareSchedulerToRelease(bool Blocking);

void InitXPTI();
void TraceEventXPTI(const char *Message);

// For testing purposes only
void attachScheduler(Scheduler *Scheduler);

private:
#ifdef XPTI_ENABLE_INSTRUMENTATION
void *GSYCLCallEvent = nullptr;
#endif

bool OkToDefer = true;

friend void shutdown_early(bool);
Expand Down
19 changes: 10 additions & 9 deletions sycl/source/detail/graph/graph_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -729,23 +729,23 @@ ur_exp_command_buffer_sync_point_t exec_graph_impl::enqueueNodeDirect(

#ifdef XPTI_ENABLE_INSTRUMENTATION
const bool xptiEnabled = xptiTraceEnabled();
auto StreamID = xpti::invalid_id<xpti::stream_id_t>;
xpti_td *CmdTraceEvent = nullptr;
uint64_t InstanceID = 0;
if (xptiEnabled) {
StreamID = xptiRegisterStream(sycl::detail::SYCL_STREAM_NAME);
sycl::detail::CGExecKernel *CGExec =
static_cast<sycl::detail::CGExecKernel *>(Node.MCommandGroup.get());
sycl::detail::code_location CodeLoc(CGExec->MFileName.c_str(),
CGExec->MFunctionName.c_str(),
CGExec->MLine, CGExec->MColumn);
std::tie(CmdTraceEvent, InstanceID) = emitKernelInstrumentationData(
StreamID, CGExec->MSyclKernel, CodeLoc, CGExec->MIsTopCodeLoc,
CGExec->MKernelName.data(), CGExec->MKernelNameBasedCachePtr, nullptr,
CGExec->MNDRDesc, CGExec->MKernelBundle.get(), CGExec->MArgs);
sycl::detail::GSYCLStreamID, CGExec->MSyclKernel, CodeLoc,
CGExec->MIsTopCodeLoc, CGExec->MKernelName.data(),
CGExec->MKernelNameBasedCachePtr, nullptr, CGExec->MNDRDesc,
CGExec->MKernelBundle.get(), CGExec->MArgs);
if (CmdTraceEvent)
sycl::detail::emitInstrumentationGeneral(
StreamID, InstanceID, CmdTraceEvent, xpti::trace_task_begin, nullptr);
sycl::detail::emitInstrumentationGeneral(sycl::detail::GSYCLStreamID,
InstanceID, CmdTraceEvent,
xpti::trace_task_begin, nullptr);
}
#endif

Expand All @@ -765,8 +765,9 @@ ur_exp_command_buffer_sync_point_t exec_graph_impl::enqueueNodeDirect(

#ifdef XPTI_ENABLE_INSTRUMENTATION
if (xptiEnabled && CmdTraceEvent)
sycl::detail::emitInstrumentationGeneral(
StreamID, InstanceID, CmdTraceEvent, xpti::trace_task_end, nullptr);
sycl::detail::emitInstrumentationGeneral(sycl::detail::GSYCLStreamID,
InstanceID, CmdTraceEvent,
xpti::trace_task_end, nullptr);
#endif

return NewSyncPoint;
Expand Down
3 changes: 0 additions & 3 deletions sycl/source/detail/image_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
namespace sycl {
inline namespace _V1 {
namespace detail {
#ifdef XPTI_ENABLE_INSTRUMENTATION
uint8_t GImageStreamID;
#endif

template <typename Param>
static bool checkImageValueRange(devices_range Devices, const size_t Value) {
Expand Down
5 changes: 0 additions & 5 deletions sycl/source/detail/memory_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ namespace sycl {
inline namespace _V1 {
namespace detail {

#ifdef XPTI_ENABLE_INSTRUMENTATION
uint8_t GMemAllocStreamID;
xpti::trace_event_data_t *GMemAllocEvent;
#endif

uint64_t emitMemAllocBeginTrace(uintptr_t ObjHandle, size_t AllocSize,
size_t GuardZone) {
(void)ObjHandle;
Expand Down
59 changes: 39 additions & 20 deletions sycl/source/detail/queue_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include <utility>

#ifdef XPTI_ENABLE_INSTRUMENTATION
#include "xpti/xpti_trace_framework.hpp"
#include <detail/xpti_registry.hpp>
#include <sstream>
#endif
Expand Down Expand Up @@ -156,24 +155,39 @@ event queue_impl::memset(void *Ptr, int Value, size_t Count,
// We need a code pointer value and we use the object ptr; if code location
// information is available, we will have function name and source file
// information
XPTIScope PrepareNotify((void *)this,
(uint16_t)xpti::trace_point_type_t::node_create,
SYCL_STREAM_NAME, "memory_transfer_node::memset");
PrepareNotify.addMetadata([&](auto TEvent) {
const char *UserData = "memory_transfer_node::memset", *FuncName = nullptr;
// We have to get the stashed code location when not available
detail::tls_code_loc_t Tls;
auto CodeLocation = Tls.query();
if (!CodeLocation.functionName())
// If the code location is not available, we use the user data
FuncName = UserData;
else
FuncName = CodeLocation.functionName();
xpti::framework::tracepoint_scope_t TP(
CodeLocation.fileName(), FuncName, CodeLocation.lineNumber(),
CodeLocation.columnNumber(), (void *)this);
TP.stream(GSYCLStreamID)
.traceType(xpti::trace_point_type_t::node_create)
.parentEvent(GSYCLGraphEvent);

TP.addMetadata([&](auto TEvent) {
xpti::addMetadata(TEvent, "sycl_device",
reinterpret_cast<size_t>(MDevice.getHandleRef()));
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);
});

// Before we notifiy the subscribers, we broadcast the 'queue_id', which was a
// metadata entry to TLS for use by callback handlers
xpti::framework::stash_tuple(XPTI_QUEUE_INSTANCE_ID_KEY, MQueueID);
// Notify XPTI about the memset submission
PrepareNotify.notify();
// Notify XPTI about the memset submission, which will create a memory object
// node
TP.notify(UserData);
// Emit a begin/end scope for this call
PrepareNotify.scopedNotify((uint16_t)xpti::trace_point_type_t::task_begin);
TP.scopedNotify((uint16_t)xpti::trace_point_type_t::task_begin, UserData);
#endif
const std::vector<unsigned char> Pattern{static_cast<unsigned char>(Value)};
return submitMemOpHelper(
Expand Down Expand Up @@ -202,10 +216,14 @@ event queue_impl::memcpy(void *Dest, const void *Src, size_t Count,
// We need a code pointer value and we duse the object ptr; If code location
// is available, we use the source file information along with the object
// pointer.
XPTIScope PrepareNotify((void *)this,
(uint16_t)xpti::trace_point_type_t::node_create,
SYCL_STREAM_NAME, "memory_transfer_node::memcpy");
PrepareNotify.addMetadata([&](auto TEvent) {
xpti::framework::tracepoint_scope_t TP(
CodeLoc.fileName(), CodeLoc.functionName(), CodeLoc.lineNumber(),
CodeLoc.columnNumber(), (void *)this);
TP.stream(GSYCLStreamID)
.traceType(xpti::trace_point_type_t::node_create)
.parentEvent(GSYCLGraphEvent);
const char *UserData = "memory_transfer_node::memcpy";
TP.addMetadata([&](auto TEvent) {
xpti::addMetadata(TEvent, "sycl_device",
reinterpret_cast<size_t>(MDevice.getHandleRef()));
xpti::addMetadata(TEvent, "src_memory_ptr", reinterpret_cast<size_t>(Src));
Expand All @@ -214,11 +232,13 @@ event queue_impl::memcpy(void *Dest, const void *Src, size_t Count,
xpti::addMetadata(TEvent, "memory_size", Count);
xpti::addMetadata(TEvent, "queue_id", MQueueID);
});
// Before we notify the subscribers, we stash the 'queue_id', which was a
// metadata entry to TLS for use by callback handlers
xpti::framework::stash_tuple(XPTI_QUEUE_INSTANCE_ID_KEY, MQueueID);
// Notify XPTI about the memcpy submission
PrepareNotify.notify();
TP.notify(UserData);
// Emit a begin/end scope for this call
PrepareNotify.scopedNotify((uint16_t)xpti::trace_point_type_t::task_begin);
TP.scopedNotify((uint16_t)xpti::trace_point_type_t::task_begin, UserData);
#endif

if ((!Src || !Dest) && Count != 0) {
Expand Down Expand Up @@ -576,14 +596,12 @@ void queue_impl::instrumentationEpilog(void *TelemetryEvent, std::string &Name,
void queue_impl::wait(const detail::code_location &CodeLoc) {
(void)CodeLoc;
#ifdef XPTI_ENABLE_INSTRUMENTATION
const bool xptiEnabled = xptiTraceEnabled();
const bool xptiEnabled = xptiCheckTraceEnabled(GSYCLStreamID);
void *TelemetryEvent = nullptr;
uint64_t IId;
std::string Name;
auto StreamID = xpti::invalid_id<xpti::stream_id_t>;
if (xptiEnabled) {
StreamID = xptiRegisterStream(SYCL_STREAM_NAME);
TelemetryEvent = instrumentationProlog(CodeLoc, Name, StreamID, IId);
TelemetryEvent = instrumentationProlog(CodeLoc, Name, GSYCLStreamID, IId);
}
#endif

Expand Down Expand Up @@ -665,15 +683,16 @@ void queue_impl::wait(const detail::code_location &CodeLoc) {

#ifdef XPTI_ENABLE_INSTRUMENTATION
if (xptiEnabled) {
instrumentationEpilog(TelemetryEvent, Name, StreamID, IId);
instrumentationEpilog(TelemetryEvent, Name, GSYCLStreamID, IId);
}
#endif
}

void queue_impl::constructorNotification() {
#if XPTI_ENABLE_INSTRUMENTATION
if (xptiTraceEnabled()) {
MStreamID = xptiRegisterStream(SYCL_STREAM_NAME);
// Making it ABI compatible and not removing the member variable
MStreamID = GSYCLStreamID;
constexpr uint16_t NotificationTraceType =
static_cast<uint16_t>(xpti::trace_point_type_t::queue_create);
if (xptiCheckTraceEnabled(MStreamID, NotificationTraceType)) {
Expand Down
14 changes: 5 additions & 9 deletions sycl/source/detail/scheduler/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
#endif

#ifdef XPTI_ENABLE_INSTRUMENTATION
#include "xpti/xpti_trace_framework.hpp"
#include <detail/xpti_registry.hpp>
#endif

Expand Down Expand Up @@ -78,8 +77,6 @@ ur_result_t callMemOpHelperRet(MemOpRet &MemOpResult, MemOpFuncT &MemOpFunc,
}

#ifdef XPTI_ENABLE_INSTRUMENTATION
// Global graph for the application
extern xpti::trace_event_data_t *GSYCLGraphEvent;

static bool CurrentCodeLocationValid() {
detail::tls_code_loc_t Tls;
Expand Down Expand Up @@ -576,8 +573,9 @@ Command::Command(
#ifdef XPTI_ENABLE_INSTRUMENTATION
if (!xptiTraceEnabled())
return;
// Obtain the stream ID so all commands can emit traces to that stream
MStreamID = xptiRegisterStream(SYCL_STREAM_NAME);
// Obtain the stream ID so all commands can emit traces to that stream;
// copying it to the member variable to avoid ABI breakage
MStreamID = GSYCLStreamID;
#endif
}

Expand Down Expand Up @@ -1813,8 +1811,7 @@ void EmptyCommand::printDot(std::ostream &Stream) const {
Stream << "\"" << this << "\" [style=filled, fillcolor=\"#8d8f29\", label=\"";

Stream << "ID = " << this << "\\n";
Stream << "EMPTY NODE"
<< "\\n";
Stream << "EMPTY NODE" << "\\n";

Stream << "\"];" << std::endl;

Expand Down Expand Up @@ -3964,8 +3961,7 @@ void UpdateCommandBufferCommand::printDot(std::ostream &Stream) const {
Stream << "\"" << this << "\" [style=filled, fillcolor=\"#8d8f29\", label=\"";

Stream << "ID = " << this << "\\n";
Stream << "CommandBuffer Command Update"
<< "\\n";
Stream << "CommandBuffer Command Update" << "\\n";

Stream << "\"];" << std::endl;

Expand Down
Loading
Loading