Skip to content
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: 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(detail::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
70 changes: 44 additions & 26 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(detail::GSYCLStreamID)
.traceType(xpti::trace_point_type_t::node_create)
.parentEvent(detail::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(detail::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 @@ -564,14 +584,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 @@ -653,18 +671,17 @@ 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);
constexpr uint16_t NotificationTraceType =
static_cast<uint16_t>(xpti::trace_point_type_t::queue_create);
if (xptiCheckTraceEnabled(MStreamID, NotificationTraceType)) {
if (xptiCheckTraceEnabled(detail::GSYCLStreamID, NotificationTraceType)) {
xpti::utils::StringHelper SH;
std::string AddrStr = SH.addressAsString<size_t>(MQueueID);
std::string QueueName = SH.nameWithAddressString("queue", AddrStr);
Expand Down Expand Up @@ -692,9 +709,10 @@ void queue_impl::constructorNotification() {
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"));
xptiNotifySubscribers(detail::GSYCLStreamID,
(uint16_t)xpti::trace_point_type_t::queue_create,
nullptr, TEvent, MInstanceID,
static_cast<const void *>("queue_create"));
}
}
#endif
Expand All @@ -704,10 +722,10 @@ 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)) {
if (xptiCheckTraceEnabled(detail::GSYCLStreamID, NotificationTraceType)) {
// Use the cached trace event, stream id and instance IDs for the
// destructor
xptiNotifySubscribers(MStreamID, NotificationTraceType, nullptr,
xptiNotifySubscribers(detail::GSYCLStreamID, NotificationTraceType, nullptr,
(xpti::trace_event_data_t *)MTraceEvent, MInstanceID,
static_cast<const void *>("queue_destroy"));
xptiReleaseEvent((xpti::trace_event_data_t *)MTraceEvent);
Expand Down
5 changes: 2 additions & 3 deletions sycl/source/detail/queue_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,8 @@ class queue_impl : public std::enable_shared_from_this<queue_impl> {
ur_native_handle_t nativeHandle = 0;
getAdapter().call<UrApiKind::urQueueGetNativeHandle>(MQueue, nullptr,
&nativeHandle);
__SYCL_OCL_CALL(clRetainCommandQueue, ur::cast<cl_command_queue>(nativeHandle));
__SYCL_OCL_CALL(clRetainCommandQueue,
ur::cast<cl_command_queue>(nativeHandle));
return ur::cast<cl_command_queue>(nativeHandle);
}

Expand Down Expand Up @@ -1036,8 +1037,6 @@ class queue_impl : public std::enable_shared_from_this<queue_impl> {
// to ensure we have the same object layout when the macro in the library and
// SYCL app are not the same.
void *MTraceEvent = nullptr;
/// The stream under which the traces are emitted from the queue object
uint8_t MStreamID = 0;
/// The instance ID of the trace event for queue object
uint64_t MInstanceID = 0;

Expand Down
Loading