Skip to content

[SYCL][XPTI][NFC] Unify stream type #19399

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

Draft
wants to merge 4 commits into
base: sycl
Choose a base branch
from
Draft
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
14 changes: 7 additions & 7 deletions sycl/source/detail/event_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,11 @@ void event_impl::setSubmittedQueue(std::weak_ptr<queue_impl> SubmittedQueue) {
MSubmittedQueue = std::move(SubmittedQueue);
}

void *event_impl::instrumentationProlog(std::string &Name, int32_t StreamID,
#ifdef XPTI_ENABLE_INSTRUMENTATION
void *event_impl::instrumentationProlog(std::string &Name,
xpti::stream_id_t StreamID,
uint64_t &IId) const {
void *TraceEvent = nullptr;
#ifdef XPTI_ENABLE_INSTRUMENTATION
constexpr uint16_t NotificationTraceType = xpti::trace_wait_begin;
if (!xptiCheckTraceEnabled(StreamID, NotificationTraceType))
return TraceEvent;
Expand Down Expand Up @@ -258,14 +259,13 @@ void *event_impl::instrumentationProlog(std::string &Name, int32_t StreamID,
xptiNotifySubscribers(StreamID, NotificationTraceType, nullptr, WaitEvent,
IId, static_cast<const void *>(Name.c_str()));
TraceEvent = (void *)WaitEvent;
#endif
return TraceEvent;
}

void event_impl::instrumentationEpilog(void *TelemetryEvent,
const std::string &Name,
int32_t StreamID, uint64_t IId) const {
#ifdef XPTI_ENABLE_INSTRUMENTATION
xpti::stream_id_t StreamID,
uint64_t IId) const {
constexpr uint16_t NotificationTraceType = xpti::trace_wait_end;
if (!(xptiCheckTraceEnabled(StreamID, NotificationTraceType) &&
TelemetryEvent))
Expand All @@ -275,8 +275,8 @@ void event_impl::instrumentationEpilog(void *TelemetryEvent,
(xpti::trace_event_data_t *)TelemetryEvent;
xptiNotifySubscribers(StreamID, NotificationTraceType, nullptr, TraceEvent,
IId, static_cast<const void *>(Name.c_str()));
#endif
}
#endif // XPTI_ENABLE_INSTRUMENTATION

void event_impl::wait(bool *Success) {
if (MState == HES_Discarded)
Expand All @@ -293,7 +293,7 @@ void event_impl::wait(bool *Success) {
void *TelemetryEvent = nullptr;
uint64_t IId = 0;
std::string Name;
int32_t StreamID = xptiRegisterStream(SYCL_STREAM_NAME);
xpti::stream_id_t StreamID = xptiRegisterStream(SYCL_STREAM_NAME);
TelemetryEvent = instrumentationProlog(Name, StreamID, IId);
#endif

Expand Down
6 changes: 4 additions & 2 deletions sycl/source/detail/event_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,11 +372,13 @@ class event_impl {
protected:
// When instrumentation is enabled emits trace event for event wait begin and
// returns the telemetry event generated for the wait
void *instrumentationProlog(std::string &Name, int32_t StreamID,
#ifdef XPTI_ENABLE_INSTRUMENTATION
void *instrumentationProlog(std::string &Name, xpti::stream_id_t StreamID,
uint64_t &instance_id) const;
// Uses events generated by the Prolog and emits event wait done event
void instrumentationEpilog(void *TelementryEvent, const std::string &Name,
int32_t StreamID, uint64_t IId) const;
xpti::stream_id_t StreamID, uint64_t IId) const;
#endif
void checkProfilingPreconditions() const;

std::atomic<ur_event_handle_t> MEvent = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion sycl/source/detail/graph/graph_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ ur_exp_command_buffer_sync_point_t exec_graph_impl::enqueueNodeDirect(

#ifdef XPTI_ENABLE_INSTRUMENTATION
const bool xptiEnabled = xptiTraceEnabled();
int32_t StreamID = xpti::invalid_id<>;
auto StreamID = xpti::invalid_id<xpti::stream_id_t>;
xpti_td *CmdTraceEvent = nullptr;
uint64_t InstanceID = 0;
if (xptiEnabled) {
Expand Down
23 changes: 8 additions & 15 deletions sycl/source/detail/queue_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,15 +503,12 @@ event queue_impl::submitMemOpHelper(const std::vector<event> &DepEvents,
return submitWithHandler(DepEvents, CallerNeedsEvent, HandlerFunc);
}

#ifdef XPTI_ENABLE_INSTRUMENTATION
void *queue_impl::instrumentationProlog(const detail::code_location &CodeLoc,
std::string &Name, int32_t StreamID,
std::string &Name,
xpti::stream_id_t StreamID,
uint64_t &IId) {
void *TraceEvent = nullptr;
(void)CodeLoc;
(void)Name;
(void)StreamID;
(void)IId;
#ifdef XPTI_ENABLE_INSTRUMENTATION
constexpr uint16_t NotificationTraceType = xpti::trace_wait_begin;
if (!xptiCheckTraceEnabled(StreamID, NotificationTraceType))
return TraceEvent;
Expand Down Expand Up @@ -556,17 +553,12 @@ void *queue_impl::instrumentationProlog(const detail::code_location &CodeLoc,
static_cast<const void *>(Name.c_str()));
TraceEvent = (void *)WaitEvent;
}
#endif
return TraceEvent;
}

void queue_impl::instrumentationEpilog(void *TelemetryEvent, std::string &Name,
int32_t StreamID, uint64_t IId) {
(void)TelemetryEvent;
(void)Name;
(void)StreamID;
(void)IId;
#ifdef XPTI_ENABLE_INSTRUMENTATION
xpti::stream_id_t StreamID,
uint64_t IId) {
constexpr uint16_t NotificationTraceType = xpti::trace_wait_end;
if (!(xptiCheckTraceEnabled(StreamID, NotificationTraceType) &&
TelemetryEvent))
Expand All @@ -576,17 +568,18 @@ void queue_impl::instrumentationEpilog(void *TelemetryEvent, std::string &Name,
(xpti::trace_event_data_t *)TelemetryEvent;
xptiNotifySubscribers(StreamID, NotificationTraceType, nullptr, TraceEvent,
IId, static_cast<const void *>(Name.c_str()));
#endif
}

#endif // XPTI_ENABLE_INSTRUMENTATION

void queue_impl::wait(const detail::code_location &CodeLoc) {
(void)CodeLoc;
#ifdef XPTI_ENABLE_INSTRUMENTATION
const bool xptiEnabled = xptiTraceEnabled();
void *TelemetryEvent = nullptr;
uint64_t IId;
std::string Name;
int32_t StreamID = xpti::invalid_id<>;
auto StreamID = xpti::invalid_id<xpti::stream_id_t>;
if (xptiEnabled) {
StreamID = xptiRegisterStream(SYCL_STREAM_NAME);
TelemetryEvent = instrumentationProlog(CodeLoc, Name, StreamID, IId);
Expand Down
6 changes: 4 additions & 2 deletions sycl/source/detail/queue_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -950,14 +950,16 @@ class queue_impl : public std::enable_shared_from_this<queue_impl> {
MemMngrFuncT MemMngrFunc,
MemMngrArgTs &&...MemOpArgs);

#ifdef XPTI_ENABLE_INSTRUMENTATION
// When instrumentation is enabled emits trace event for wait begin and
// returns the telemetry event generated for the wait
void *instrumentationProlog(const detail::code_location &CodeLoc,
std::string &Name, int32_t StreamID,
std::string &Name, xpti::stream_id_t StreamID,
uint64_t &iid);
// Uses events generated by the Prolog and emits wait done event
void instrumentationEpilog(void *TelementryEvent, std::string &Name,
int32_t StreamID, uint64_t IId);
xpti::stream_id_t StreamID, uint64_t IId);
#endif

// We need to emit a queue_create notification when a queue object is created
void constructorNotification();
Expand Down
5 changes: 3 additions & 2 deletions sycl/source/detail/scheduler/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ static bool CurrentCodeLocationValid() {
(FunctionName && FunctionName[0] != '\0');
}

void emitInstrumentationGeneral(uint32_t StreamID, uint64_t InstanceID,
void emitInstrumentationGeneral(xpti::stream_id_t StreamID, uint64_t InstanceID,
xpti_td *TraceEvent, uint16_t Type,
const void *Addr) {
if (!(xptiCheckTraceEnabled(StreamID, Type) && TraceEvent))
Expand Down Expand Up @@ -2105,7 +2105,8 @@ void instrumentationFillCommonData(const std::string &KernelName,

#ifdef XPTI_ENABLE_INSTRUMENTATION
std::pair<xpti_td *, uint64_t> emitKernelInstrumentationData(
int32_t StreamID, const std::shared_ptr<detail::kernel_impl> &SyclKernel,
xpti::stream_id_t StreamID,
const std::shared_ptr<detail::kernel_impl> &SyclKernel,
const detail::code_location &CodeLoc, bool IsTopCodeLoc,
const std::string_view SyclKernelName,
KernelNameBasedCacheT *KernelNameBasedCachePtr, queue_impl *Queue,
Expand Down
13 changes: 10 additions & 3 deletions sycl/source/detail/scheduler/commands.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
#include <detail/program_manager/program_manager.hpp>
#include <sycl/access/access.hpp>

#ifdef XPTI_ENABLE_INSTRUMENTATION
#include <xpti/xpti_data_types.h>
#endif

namespace sycl {
inline namespace _V1 {

Expand All @@ -33,7 +37,7 @@ class node_impl;
namespace detail {

#ifdef XPTI_ENABLE_INSTRUMENTATION
void emitInstrumentationGeneral(uint32_t StreamID, uint64_t InstanceID,
void emitInstrumentationGeneral(xpti::stream_id_t StreamID, uint64_t InstanceID,
xpti_td *TraceEvent, uint16_t Type,
const void *Addr);
#endif
Expand Down Expand Up @@ -347,10 +351,12 @@ class Command {

/// The event for node_create and task_begin.
void *MTraceEvent = nullptr;
#ifdef XPTI_ENABLE_INSTRUMENTATION
/// The stream under which the traces are emitted.
///
/// Stream ids are positive integers and we set it to an invalid value.
int32_t MStreamID = -1;
xpti::stream_id_t MStreamID = xpti::invalid_id<xpti::stream_id_t>;
#endif
/// Reserved for storing the object address such as SPIR-V or memory object
/// address.
void *MAddress = nullptr;
Expand Down Expand Up @@ -686,7 +692,8 @@ class ExecCGCommand : public Command {
// Very close to ExecCGCommand::emitInstrumentationData content.
#ifdef XPTI_ENABLE_INSTRUMENTATION
std::pair<xpti_td *, uint64_t> emitKernelInstrumentationData(
int32_t StreamID, const std::shared_ptr<detail::kernel_impl> &SyclKernel,
xpti::stream_id_t StreamID,
const std::shared_ptr<detail::kernel_impl> &SyclKernel,
const detail::code_location &CodeLoc, bool IsTopCodeLoc,
std::string_view SyclKernelName,
KernelNameBasedCacheT *KernelNameBasedCachePtr, queue_impl *Queue,
Expand Down
2 changes: 1 addition & 1 deletion sycl/source/handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ event handler::finalize() {
#endif
auto EnqueueKernel = [&]() {
#ifdef XPTI_ENABLE_INSTRUMENTATION
int32_t StreamID = xpti::invalid_id<>;
auto StreamID = xpti::invalid_id<xpti::stream_id_t>;
xpti_td *CmdTraceEvent = nullptr;
uint64_t InstanceID = 0;
if (xptiEnabled) {
Expand Down
5 changes: 5 additions & 0 deletions sycl/unittests/scheduler/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ add_sycl_unittest(SchedulerTests OBJECT
HostTaskAndBarrier.cpp
BarrierDependencies.cpp
)

if (SYCL_ENABLE_XPTI_TRACING)
target_compile_definitions(SchedulerTests
PRIVATE XPTI_ENABLE_INSTRUMENTATION XPTI_STATIC_LIBRARY)
endif()
4 changes: 2 additions & 2 deletions xpti/include/xpti/xpti_data_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,7 @@ struct uid_t {
return p1 == rhs.p1 && p2 == rhs.p2;
}
};
} // namespace xpti

namespace xpti {
template <typename T = uint32_t>
constexpr T invalid_id = std::numeric_limits<T>::max();
constexpr uint64_t invalid_uid = 0;
Expand Down Expand Up @@ -352,6 +350,8 @@ enum class payload_flag_t {
HashAvailable = 2 << 16
};

using stream_id_t = uint8_t;

//
// Helper macros for creating new tracepoint and
// event types
Expand Down
23 changes: 13 additions & 10 deletions xpti/include/xpti/xpti_trace_framework.h
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ XPTI_EXPORT_API uint64_t xptiRegisterPayload(xpti::payload_t *payload);
/// @param stream_name The stream name that needs to be registered.
/// @return The stream ID. If the stream has already been registered, the
/// previously generated stream ID is returned.
XPTI_EXPORT_API uint8_t xptiRegisterStream(const char *stream_name);
XPTI_EXPORT_API xpti::stream_id_t xptiRegisterStream(const char *stream_name);

/// @brief Unregister a stream by its name
/// @details Unregistering a stream will invalidate the stream ID associated
Expand Down Expand Up @@ -755,7 +755,7 @@ XPTI_EXPORT_API xpti::result_t xptiDeleteTracepoint(xpti_tracepoint_t *tp);
/// 3. XPTI_RESULT_UNDELETE when the registration is for a callback
/// that had been previously unregistered.
XPTI_EXPORT_API xpti::result_t
xptiRegisterCallback(uint8_t stream_id, uint16_t trace_type,
xptiRegisterCallback(xpti::stream_id_t stream_id, uint16_t trace_type,
xpti::tracepoint_callback_api_t cb);

/// @brief Unregisters a previously registered callback for a trace point type
Expand All @@ -776,7 +776,7 @@ xptiRegisterCallback(uint8_t stream_id, uint16_t trace_type,
/// 3. XPTI_RESULT_NOTFOUND if the callback has not been previously
/// registered.
XPTI_EXPORT_API xpti::result_t
xptiUnregisterCallback(uint8_t stream_id, uint16_t trace_type,
xptiUnregisterCallback(xpti::stream_id_t stream_id, uint16_t trace_type,
xpti::tracepoint_callback_api_t cb);

/// @brief Notifies all registered subscribers that an event has occurred
Expand Down Expand Up @@ -810,7 +810,7 @@ xptiUnregisterCallback(uint8_t stream_id, uint16_t trace_type,
/// function_begin and function_end, the per_instance_user_data value
/// must be populated to not get this return value.
XPTI_EXPORT_API xpti::result_t
xptiNotifySubscribers(uint8_t stream_id, uint16_t trace_type,
xptiNotifySubscribers(xpti::stream_id_t stream_id, uint16_t trace_type,
xpti::trace_event_data_t *parent,
xpti::trace_event_data_t *object, uint64_t instance,
const void *per_instance_user_data);
Expand Down Expand Up @@ -860,7 +860,8 @@ XPTI_EXPORT_API bool xptiTraceEnabled();
/// @param stream Stream ID
/// @param ttype The trace type within the stream
/// @return bool that indicates whether it is enabled or not
XPTI_EXPORT_API bool xptiCheckTraceEnabled(uint16_t stream, uint16_t ttype = 0);
XPTI_EXPORT_API bool xptiCheckTraceEnabled(xpti::stream_id_t stream,
uint16_t ttype = 0);

/// @brief Resets internal state
/// @details This method is currently ONLY used by the tests and is NOT
Expand Down Expand Up @@ -936,7 +937,7 @@ xptiRegisterTracepointScope(const char *funcName, const char *fileName,
/// @details This function is used to get the default stream ID that is
/// currently set in the tracing framework.
/// @return The default stream ID.
XPTI_EXPORT_API uint8_t xptiGetDefaultStreamID();
XPTI_EXPORT_API xpti::stream_id_t xptiGetDefaultStreamID();

/// @brief Sets the default stream ID.
/// @details This function is used to set the default stream ID in the tracing
Expand All @@ -945,7 +946,8 @@ XPTI_EXPORT_API uint8_t xptiGetDefaultStreamID();
///
/// @param defaultStreamID The stream ID to be set as default.
/// @return Result of the operation, success or failure.
XPTI_EXPORT_API xpti::result_t xptiSetDefaultStreamID(uint8_t defaultStreamID);
XPTI_EXPORT_API xpti::result_t
xptiSetDefaultStreamID(xpti::stream_id_t defaultStreamID);

/// @brief Retrieves the default event type.
/// @details This function is used to get the default event type that is
Expand Down Expand Up @@ -1042,7 +1044,8 @@ typedef xpti::result_t (*xpti_add_metadata_t)(xpti::trace_event_data_t *,
const char *, xpti::object_id_t);
typedef xpti::metadata_t *(*xpti_query_metadata_t)(xpti::trace_event_data_t *);
typedef bool (*xpti_trace_enabled_t)();
typedef bool (*xpti_check_trace_enabled_t)(uint16_t stream, uint16_t ttype);
typedef bool (*xpti_check_trace_enabled_t)(xpti::stream_id_t stream,
uint16_t ttype);
typedef void (*xpti_force_set_trace_enabled_t)(bool);
typedef void (*xpti_release_event_t)(xpti::trace_event_data_t *);
typedef void (*xpti_enable_tracepoint_scope_notification_t)(bool);
Expand All @@ -1056,8 +1059,8 @@ typedef const xpti_tracepoint_t *(*xpti_register_tracepoint_scope_t)(
typedef xpti::result_t (*xpti_set_trace_point_scope_data_t)(
xpti_tracepoint_t *);
typedef void (*xpti_unset_trace_point_scope_data_t)();
typedef uint8_t (*xpti_get_default_stream_id_t)();
typedef xpti::result_t (*xpti_set_default_stream_id_t)(uint8_t);
typedef xpti::stream_id_t (*xpti_get_default_stream_id_t)();
typedef xpti::result_t (*xpti_set_default_stream_id_t)(xpti::stream_id_t);
typedef xpti::trace_event_type_t (*xpti_get_default_event_type_t)();
typedef xpti::result_t (*xpti_set_default_event_type_t)(
xpti::trace_event_type_t);
Expand Down
8 changes: 4 additions & 4 deletions xpti/include/xpti/xpti_trace_framework.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1124,7 +1124,7 @@ class tracepoint_scope_t {
///
/// @return The stream ID.
///
uint8_t streamId() { return MStreamId; }
stream_id_t streamId() { return MStreamId; }

/// @brief Sets the stream for the tracepoint scoped notification
///
Expand Down Expand Up @@ -1152,7 +1152,7 @@ class tracepoint_scope_t {
/// with.
/// @return tracepoint_scope_t& A reference to the tracepoint scope
///
tracepoint_scope_t &stream(uint8_t streamId) {
tracepoint_scope_t &stream(stream_id_t streamId) {
// If tracing is not enabled, don't do anything
if (xptiTraceEnabled()) {
MStreamId = streamId;
Expand Down Expand Up @@ -1355,7 +1355,7 @@ class tracepoint_scope_t {
/// from self notification
uint64_t MScopedCorrelationId = 0;
/// Stores the ID of the stream
uint8_t MStreamId = 0;
stream_id_t MStreamId = 0;
/// Stores the ID of the default stream use for self notification; the
/// system sets the default stream ID at the start of the program
uint8_t MDefaultStreamId = 0;
Expand Down Expand Up @@ -1397,7 +1397,7 @@ class notify_scope_t {
/// @param UserData The user data.
/// @param traceType The type of the trace event. Defaults to function_begin.
///
notify_scope_t(uint8_t streamId, xpti::trace_event_data_t *traceEvent,
notify_scope_t(stream_id_t streamId, xpti::trace_event_data_t *traceEvent,
const char *UserData,
uint16_t traceType = (uint16_t)
xpti::trace_point_type_t::function_begin)
Expand Down
Loading
Loading