Skip to content

Commit 81f584b

Browse files
[SYCL][XPTI][NFC] Unify stream type (#19399)
Data type which identifies an XPTI stream wasn't uniformly the same, even within XPTI itself different APIs expected different data type as a stream identifier. This PR introduces the `xpti::stream_id_t` type alias and uses it everywhere. Motivation for this PR is to address warnings produced by `-Wconversion`. We don't have that flag enabled yet, but it is a requirement per our SDL processes. It will be enabled in #19306
1 parent 1833f44 commit 81f584b

File tree

14 files changed

+102
-79
lines changed

14 files changed

+102
-79
lines changed

sycl/source/detail/event_impl.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,11 @@ void event_impl::setSubmittedQueue(std::weak_ptr<queue_impl> SubmittedQueue) {
220220
MSubmittedQueue = std::move(SubmittedQueue);
221221
}
222222

223-
void *event_impl::instrumentationProlog(std::string &Name, int32_t StreamID,
223+
#ifdef XPTI_ENABLE_INSTRUMENTATION
224+
void *event_impl::instrumentationProlog(std::string &Name,
225+
xpti::stream_id_t StreamID,
224226
uint64_t &IId) const {
225227
void *TraceEvent = nullptr;
226-
#ifdef XPTI_ENABLE_INSTRUMENTATION
227228
constexpr uint16_t NotificationTraceType = xpti::trace_wait_begin;
228229
if (!xptiCheckTraceEnabled(StreamID, NotificationTraceType))
229230
return TraceEvent;
@@ -258,14 +259,13 @@ void *event_impl::instrumentationProlog(std::string &Name, int32_t StreamID,
258259
xptiNotifySubscribers(StreamID, NotificationTraceType, nullptr, WaitEvent,
259260
IId, static_cast<const void *>(Name.c_str()));
260261
TraceEvent = (void *)WaitEvent;
261-
#endif
262262
return TraceEvent;
263263
}
264264

265265
void event_impl::instrumentationEpilog(void *TelemetryEvent,
266266
const std::string &Name,
267-
int32_t StreamID, uint64_t IId) const {
268-
#ifdef XPTI_ENABLE_INSTRUMENTATION
267+
xpti::stream_id_t StreamID,
268+
uint64_t IId) const {
269269
constexpr uint16_t NotificationTraceType = xpti::trace_wait_end;
270270
if (!(xptiCheckTraceEnabled(StreamID, NotificationTraceType) &&
271271
TelemetryEvent))
@@ -275,8 +275,8 @@ void event_impl::instrumentationEpilog(void *TelemetryEvent,
275275
(xpti::trace_event_data_t *)TelemetryEvent;
276276
xptiNotifySubscribers(StreamID, NotificationTraceType, nullptr, TraceEvent,
277277
IId, static_cast<const void *>(Name.c_str()));
278-
#endif
279278
}
279+
#endif // XPTI_ENABLE_INSTRUMENTATION
280280

281281
void event_impl::wait(bool *Success) {
282282
if (MState == HES_Discarded)
@@ -293,7 +293,7 @@ void event_impl::wait(bool *Success) {
293293
void *TelemetryEvent = nullptr;
294294
uint64_t IId = 0;
295295
std::string Name;
296-
int32_t StreamID = xptiRegisterStream(SYCL_STREAM_NAME);
296+
xpti::stream_id_t StreamID = xptiRegisterStream(SYCL_STREAM_NAME);
297297
TelemetryEvent = instrumentationProlog(Name, StreamID, IId);
298298
#endif
299299

sycl/source/detail/event_impl.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,11 +372,13 @@ class event_impl {
372372
protected:
373373
// When instrumentation is enabled emits trace event for event wait begin and
374374
// returns the telemetry event generated for the wait
375-
void *instrumentationProlog(std::string &Name, int32_t StreamID,
375+
#ifdef XPTI_ENABLE_INSTRUMENTATION
376+
void *instrumentationProlog(std::string &Name, xpti::stream_id_t StreamID,
376377
uint64_t &instance_id) const;
377378
// Uses events generated by the Prolog and emits event wait done event
378379
void instrumentationEpilog(void *TelementryEvent, const std::string &Name,
379-
int32_t StreamID, uint64_t IId) const;
380+
xpti::stream_id_t StreamID, uint64_t IId) const;
381+
#endif
380382
void checkProfilingPreconditions() const;
381383

382384
std::atomic<ur_event_handle_t> MEvent = nullptr;

sycl/source/detail/graph/graph_impl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ ur_exp_command_buffer_sync_point_t exec_graph_impl::enqueueNodeDirect(
737737

738738
#ifdef XPTI_ENABLE_INSTRUMENTATION
739739
const bool xptiEnabled = xptiTraceEnabled();
740-
int32_t StreamID = xpti::invalid_id<>;
740+
auto StreamID = xpti::invalid_id<xpti::stream_id_t>;
741741
xpti_td *CmdTraceEvent = nullptr;
742742
uint64_t InstanceID = 0;
743743
if (xptiEnabled) {

sycl/source/detail/queue_impl.cpp

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -503,15 +503,12 @@ event queue_impl::submitMemOpHelper(const std::vector<event> &DepEvents,
503503
return submitWithHandler(DepEvents, CallerNeedsEvent, HandlerFunc);
504504
}
505505

506+
#ifdef XPTI_ENABLE_INSTRUMENTATION
506507
void *queue_impl::instrumentationProlog(const detail::code_location &CodeLoc,
507-
std::string &Name, int32_t StreamID,
508+
std::string &Name,
509+
xpti::stream_id_t StreamID,
508510
uint64_t &IId) {
509511
void *TraceEvent = nullptr;
510-
(void)CodeLoc;
511-
(void)Name;
512-
(void)StreamID;
513-
(void)IId;
514-
#ifdef XPTI_ENABLE_INSTRUMENTATION
515512
constexpr uint16_t NotificationTraceType = xpti::trace_wait_begin;
516513
if (!xptiCheckTraceEnabled(StreamID, NotificationTraceType))
517514
return TraceEvent;
@@ -556,17 +553,12 @@ void *queue_impl::instrumentationProlog(const detail::code_location &CodeLoc,
556553
static_cast<const void *>(Name.c_str()));
557554
TraceEvent = (void *)WaitEvent;
558555
}
559-
#endif
560556
return TraceEvent;
561557
}
562558

563559
void queue_impl::instrumentationEpilog(void *TelemetryEvent, std::string &Name,
564-
int32_t StreamID, uint64_t IId) {
565-
(void)TelemetryEvent;
566-
(void)Name;
567-
(void)StreamID;
568-
(void)IId;
569-
#ifdef XPTI_ENABLE_INSTRUMENTATION
560+
xpti::stream_id_t StreamID,
561+
uint64_t IId) {
570562
constexpr uint16_t NotificationTraceType = xpti::trace_wait_end;
571563
if (!(xptiCheckTraceEnabled(StreamID, NotificationTraceType) &&
572564
TelemetryEvent))
@@ -576,17 +568,18 @@ void queue_impl::instrumentationEpilog(void *TelemetryEvent, std::string &Name,
576568
(xpti::trace_event_data_t *)TelemetryEvent;
577569
xptiNotifySubscribers(StreamID, NotificationTraceType, nullptr, TraceEvent,
578570
IId, static_cast<const void *>(Name.c_str()));
579-
#endif
580571
}
581572

573+
#endif // XPTI_ENABLE_INSTRUMENTATION
574+
582575
void queue_impl::wait(const detail::code_location &CodeLoc) {
583576
(void)CodeLoc;
584577
#ifdef XPTI_ENABLE_INSTRUMENTATION
585578
const bool xptiEnabled = xptiTraceEnabled();
586579
void *TelemetryEvent = nullptr;
587580
uint64_t IId;
588581
std::string Name;
589-
int32_t StreamID = xpti::invalid_id<>;
582+
auto StreamID = xpti::invalid_id<xpti::stream_id_t>;
590583
if (xptiEnabled) {
591584
StreamID = xptiRegisterStream(SYCL_STREAM_NAME);
592585
TelemetryEvent = instrumentationProlog(CodeLoc, Name, StreamID, IId);

sycl/source/detail/queue_impl.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -950,14 +950,16 @@ class queue_impl : public std::enable_shared_from_this<queue_impl> {
950950
MemMngrFuncT MemMngrFunc,
951951
MemMngrArgTs &&...MemOpArgs);
952952

953+
#ifdef XPTI_ENABLE_INSTRUMENTATION
953954
// When instrumentation is enabled emits trace event for wait begin and
954955
// returns the telemetry event generated for the wait
955956
void *instrumentationProlog(const detail::code_location &CodeLoc,
956-
std::string &Name, int32_t StreamID,
957+
std::string &Name, xpti::stream_id_t StreamID,
957958
uint64_t &iid);
958959
// Uses events generated by the Prolog and emits wait done event
959960
void instrumentationEpilog(void *TelementryEvent, std::string &Name,
960-
int32_t StreamID, uint64_t IId);
961+
xpti::stream_id_t StreamID, uint64_t IId);
962+
#endif
961963

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

sycl/source/detail/scheduler/commands.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ static bool CurrentCodeLocationValid() {
9090
(FunctionName && FunctionName[0] != '\0');
9191
}
9292

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

21062106
#ifdef XPTI_ENABLE_INSTRUMENTATION
21072107
std::pair<xpti_td *, uint64_t> emitKernelInstrumentationData(
2108-
int32_t StreamID, const std::shared_ptr<detail::kernel_impl> &SyclKernel,
2108+
xpti::stream_id_t StreamID,
2109+
const std::shared_ptr<detail::kernel_impl> &SyclKernel,
21092110
const detail::code_location &CodeLoc, bool IsTopCodeLoc,
21102111
const std::string_view SyclKernelName,
21112112
KernelNameBasedCacheT *KernelNameBasedCachePtr, queue_impl *Queue,

sycl/source/detail/scheduler/commands.hpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
#include <detail/program_manager/program_manager.hpp>
2424
#include <sycl/access/access.hpp>
2525

26+
#ifdef XPTI_ENABLE_INSTRUMENTATION
27+
#include <xpti/xpti_data_types.h>
28+
#endif
29+
2630
namespace sycl {
2731
inline namespace _V1 {
2832

@@ -33,7 +37,7 @@ class node_impl;
3337
namespace detail {
3438

3539
#ifdef XPTI_ENABLE_INSTRUMENTATION
36-
void emitInstrumentationGeneral(uint32_t StreamID, uint64_t InstanceID,
40+
void emitInstrumentationGeneral(xpti::stream_id_t StreamID, uint64_t InstanceID,
3741
xpti_td *TraceEvent, uint16_t Type,
3842
const void *Addr);
3943
#endif
@@ -347,10 +351,12 @@ class Command {
347351

348352
/// The event for node_create and task_begin.
349353
void *MTraceEvent = nullptr;
354+
#ifdef XPTI_ENABLE_INSTRUMENTATION
350355
/// The stream under which the traces are emitted.
351356
///
352357
/// Stream ids are positive integers and we set it to an invalid value.
353-
int32_t MStreamID = -1;
358+
xpti::stream_id_t MStreamID = xpti::invalid_id<xpti::stream_id_t>;
359+
#endif
354360
/// Reserved for storing the object address such as SPIR-V or memory object
355361
/// address.
356362
void *MAddress = nullptr;
@@ -686,7 +692,8 @@ class ExecCGCommand : public Command {
686692
// Very close to ExecCGCommand::emitInstrumentationData content.
687693
#ifdef XPTI_ENABLE_INSTRUMENTATION
688694
std::pair<xpti_td *, uint64_t> emitKernelInstrumentationData(
689-
int32_t StreamID, const std::shared_ptr<detail::kernel_impl> &SyclKernel,
695+
xpti::stream_id_t StreamID,
696+
const std::shared_ptr<detail::kernel_impl> &SyclKernel,
690697
const detail::code_location &CodeLoc, bool IsTopCodeLoc,
691698
std::string_view SyclKernelName,
692699
KernelNameBasedCacheT *KernelNameBasedCachePtr, queue_impl *Queue,

sycl/source/handler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ event handler::finalize() {
580580
#endif
581581
auto EnqueueKernel = [&]() {
582582
#ifdef XPTI_ENABLE_INSTRUMENTATION
583-
int32_t StreamID = xpti::invalid_id<>;
583+
auto StreamID = xpti::invalid_id<xpti::stream_id_t>;
584584
xpti_td *CmdTraceEvent = nullptr;
585585
uint64_t InstanceID = 0;
586586
if (xptiEnabled) {

sycl/unittests/scheduler/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,8 @@ add_sycl_unittest(SchedulerTests OBJECT
2323
HostTaskAndBarrier.cpp
2424
BarrierDependencies.cpp
2525
)
26+
27+
if (SYCL_ENABLE_XPTI_TRACING)
28+
target_compile_definitions(SchedulerTests
29+
PRIVATE XPTI_ENABLE_INSTRUMENTATION XPTI_STATIC_LIBRARY)
30+
endif()

xpti/include/xpti/xpti_data_types.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,7 @@ struct uid_t {
318318
return p1 == rhs.p1 && p2 == rhs.p2;
319319
}
320320
};
321-
} // namespace xpti
322321

323-
namespace xpti {
324322
template <typename T = uint32_t>
325323
constexpr T invalid_id = std::numeric_limits<T>::max();
326324
constexpr uint64_t invalid_uid = 0;
@@ -352,6 +350,8 @@ enum class payload_flag_t {
352350
HashAvailable = 2 << 16
353351
};
354352

353+
using stream_id_t = uint8_t;
354+
355355
//
356356
// Helper macros for creating new tracepoint and
357357
// event types

0 commit comments

Comments
 (0)