Skip to content

Commit f92e432

Browse files
[SYCL] Fix UserData usage for XPTIScope (#11091)
Aligned node_create usage with https://github.com/intel/llvm/blob/sycl/sycl/doc/design/SYCLInstrumentationUsingXPTI.md --------- Signed-off-by: Tikhomirova, Kseniya <[email protected]>
1 parent 83aafdd commit f92e432

File tree

5 files changed

+65
-20
lines changed

5 files changed

+65
-20
lines changed

sycl/source/detail/queue_impl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ event queue_impl::memset(const std::shared_ptr<detail::queue_impl> &Self,
6767
// information
6868
XPTIScope PrepareNotify((void *)this,
6969
(uint16_t)xpti::trace_point_type_t::node_create,
70-
SYCL_MEM_ALLOC_STREAM_NAME, "queue.memset()");
70+
SYCL_STREAM_NAME, "memory_transfer_node");
7171
PrepareNotify.addMetadata([&](auto TEvent) {
7272
xpti::addMetadata(TEvent, "sycl_device",
7373
reinterpret_cast<size_t>(
@@ -143,7 +143,7 @@ event queue_impl::memcpy(const std::shared_ptr<detail::queue_impl> &Self,
143143
// pointer.
144144
XPTIScope PrepareNotify((void *)this,
145145
(uint16_t)xpti::trace_point_type_t::node_create,
146-
SYCL_MEM_ALLOC_STREAM_NAME, "queue.memcpy()");
146+
SYCL_STREAM_NAME, "memory_transfer_node");
147147
PrepareNotify.addMetadata([&](auto TEvent) {
148148
xpti::addMetadata(TEvent, "sycl_device",
149149
reinterpret_cast<size_t>(

sycl/source/detail/xpti_registry.hpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -178,17 +178,12 @@ class XPTIScope {
178178
MTraceType(0) {
179179
detail::tls_code_loc_t Tls;
180180
auto TData = Tls.query();
181-
// If TLS is not set, we can still genertate universal IDs with user data
182-
// and CodePtr information
183-
const char *FuncName = UserData;
184-
if (TData.functionName())
185-
FuncName = TData.functionName();
186181
// Create a tracepoint object that has a lifetime of this class
187-
MTP = new TracePoint(TData.fileName(), FuncName, TData.lineNumber(),
188-
TData.columnNumber(), CodePtr);
189-
if (MTraceType == (uint16_t)xpti::trace_point_type_t::graph_create ||
190-
MTraceType == (uint16_t)xpti::trace_point_type_t::node_create ||
191-
MTraceType == (uint16_t)xpti::trace_point_type_t::edge_create)
182+
MTP = new TracePoint(TData.fileName(), TData.functionName(),
183+
TData.lineNumber(), TData.columnNumber(), CodePtr);
184+
if (TraceType == (uint16_t)xpti::trace_point_type_t::graph_create ||
185+
TraceType == (uint16_t)xpti::trace_point_type_t::node_create ||
186+
TraceType == (uint16_t)xpti::trace_point_type_t::edge_create)
192187
MTP->parent_event(GSYCLGraphEvent);
193188
// Now if tracing is enabled, create trace events and notify
194189
if (xptiTraceEnabled() && MTP) {

sycl/test-e2e/XPTI/basic_event_collection_linux.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
// CHECK-NEXT: kernel_name : virtual_node[{{.*}}]
3535
// CHECK-NEXT: Edge create
3636
// CHECK-NEXT: event : {{.*}}
37-
// CHECK-NEXT: kernel_name : virtual_node[{{.*}}]
3837
// CHECK-NEXT: Task begin
3938
// CHECK-DAG: sym_line_no : {{.*}}
4039
// CHECK-DAG: sym_source_file_name : {{.*}}
@@ -62,7 +61,22 @@
6261
// CHECK-NEXT: Wait begin
6362
// CHECK-NEXT: PI Call Begin : piEventsWait
6463
// CHECK-NEXT: Wait end
64+
// CHECK-NEXT: Node create
65+
// CHECK-DAG: memory_size : {{.*}}
66+
// CHECK-DAG: dest_memory_ptr : {{.*}}
67+
// CHECK-DAG: src_memory_ptr : {{.*}}
68+
// CHECK-DAG: sycl_device : {{.*}}
69+
// CHECK-NEXT: Task begin
70+
// CHECK-DAG: memory_size : {{.*}}
71+
// CHECK-DAG: dest_memory_ptr : {{.*}}
72+
// CHECK-DAG: src_memory_ptr : {{.*}}
73+
// CHECK-DAG: sycl_device : {{.*}}
6574
// CHECK-NEXT: PI Call Begin : piextUSMEnqueueMemcpy
75+
// CHECK-NEXT: Task end
76+
// CHECK-DAG: memory_size : {{.*}}
77+
// CHECK-DAG: dest_memory_ptr : {{.*}}
78+
// CHECK-DAG: src_memory_ptr : {{.*}}
79+
// CHECK-DAG: sycl_device : {{.*}}
6680
// CHECK-NEXT: PI Call Begin : piEventRelease
6781
// CHECK-NEXT: Wait begin
6882
// CHECK: sycl_device : {{.*}}

sycl/unittests/xpti_trace/NodeCreation.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,34 @@ TEST_F(NodeCreation, QueueParallelForWithNoGraphNode) {
8888
EXPECT_EQ(TraceType, xpti::trace_node_create);
8989
EXPECT_THAT(Message, HasSubstr("TestKernel"));
9090
}
91+
92+
TEST_F(NodeCreation, QueueMemcpyNode) {
93+
sycl::queue Q;
94+
95+
constexpr int n = 10 * sizeof(double);
96+
double HostPtr[n];
97+
double *DeviceUSMPtr = (double *)sycl::malloc_device(n, Q);
98+
Q.memcpy(DeviceUSMPtr, HostPtr, n).wait();
99+
sycl::free(DeviceUSMPtr, Q);
100+
101+
uint16_t TraceType = 0;
102+
std::string Message;
103+
ASSERT_TRUE(queryReceivedNotifications(TraceType, Message));
104+
EXPECT_EQ(TraceType, xpti::trace_node_create);
105+
EXPECT_THAT(Message, HasSubstr("memory_transfer_node"));
106+
}
107+
108+
TEST_F(NodeCreation, QueueMemsetNode) {
109+
sycl::queue Q;
110+
111+
constexpr int n = 10 * sizeof(double);
112+
double *DeviceUSMPtr = (double *)sycl::malloc_device(n, Q);
113+
Q.memset(DeviceUSMPtr, 0, n).wait();
114+
sycl::free(DeviceUSMPtr, Q);
115+
116+
uint16_t TraceType = 0;
117+
std::string Message;
118+
ASSERT_TRUE(queryReceivedNotifications(TraceType, Message));
119+
EXPECT_EQ(TraceType, xpti::trace_node_create);
120+
EXPECT_THAT(Message, HasSubstr("memory_transfer_node"));
121+
}

sycl/unittests/xpti_trace/xptitest_subscriber/XPTISubscriber.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,19 @@ XPTI_CALLBACK_API void testCallback(uint16_t TraceType,
4848
AggregatedData.append(static_cast<const char *>(UserData));
4949
GReceivedNotifications.push_back(std::make_pair(TraceType, AggregatedData));
5050
} else if (TraceType == xpti::trace_node_create) {
51-
auto Payload = xptiQueryPayload(Event);
52-
xpti::metadata_t *Metadata = xptiQueryMetadata(Event);
53-
for (const auto &Item : *Metadata) {
54-
std::string_view Key{xptiLookupString(Item.first)};
55-
if (Key == "kernel_name") {
56-
GReceivedNotifications.push_back(
57-
std::make_pair(TraceType, Payload->name));
51+
std::string UData(static_cast<const char *>(UserData));
52+
if (UData.find("command_group_node") != std::string::npos) {
53+
auto Payload = xptiQueryPayload(Event);
54+
xpti::metadata_t *Metadata = xptiQueryMetadata(Event);
55+
for (const auto &Item : *Metadata) {
56+
std::string_view Key{xptiLookupString(Item.first)};
57+
if (Key == "kernel_name") {
58+
GReceivedNotifications.push_back(
59+
std::make_pair(TraceType, UData + std::string(Payload->name)));
60+
}
5861
}
62+
} else if (UData.find("memory_transfer_node") != std::string::npos) {
63+
GReceivedNotifications.push_back(std::make_pair(TraceType, UData));
5964
}
6065
}
6166
}

0 commit comments

Comments
 (0)