Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

Commit 89c007b

Browse files
[SYCL][XPTI] Enable XPTI and XPTI Framework E2E tests (#458)
Co-authored-by: Romanov Vlad <[email protected]>
1 parent 9debe19 commit 89c007b

File tree

4 files changed

+294
-0
lines changed

4 files changed

+294
-0
lines changed

.github/CODEOWNERS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,6 @@ SYCL/BFloat16 @AlexeySotkin @MrSidims
7878

7979
# Deprecated features
8080
SYCL/DeprecatedFeatures @intel/llvm-reviewers-runtime
81+
82+
# XPTI and XPTI Framework
83+
SYCL/XPTI @intel/llvm-reviewers-runtime

SYCL/XPTI/Inputs/test_collector.cpp

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
#include "xpti/xpti_trace_framework.hpp"
2+
3+
#include <iostream>
4+
#include <mutex>
5+
#include <string_view>
6+
7+
std::mutex GMutex;
8+
9+
XPTI_CALLBACK_API void syclCallback(uint16_t, xpti::trace_event_data_t *,
10+
xpti::trace_event_data_t *, uint64_t,
11+
const void *);
12+
XPTI_CALLBACK_API void syclPiCallback(uint16_t, xpti::trace_event_data_t *,
13+
xpti::trace_event_data_t *, uint64_t,
14+
const void *);
15+
16+
XPTI_CALLBACK_API void xptiTraceInit(unsigned int MajorVersion,
17+
unsigned int MinorVersion,
18+
const char *VersionStr,
19+
const char *StreamName) {
20+
std::cout << "xptiTraceInit: Stream Name = " << StreamName << "\n";
21+
std::string_view NameView{StreamName};
22+
23+
if (NameView == "sycl.pi") {
24+
uint8_t StreamID = xptiRegisterStream(StreamName);
25+
xptiRegisterCallback(
26+
StreamID,
27+
static_cast<uint16_t>(xpti::trace_point_type_t::function_begin),
28+
syclPiCallback);
29+
xptiRegisterCallback(
30+
StreamID,
31+
static_cast<uint16_t>(xpti::trace_point_type_t::function_with_args_end),
32+
syclPiCallback);
33+
}
34+
if (NameView == "sycl") {
35+
uint8_t StreamID = xptiRegisterStream(StreamName);
36+
xptiRegisterCallback(
37+
StreamID, static_cast<uint16_t>(xpti::trace_point_type_t::graph_create),
38+
syclCallback);
39+
xptiRegisterCallback(
40+
StreamID, static_cast<uint16_t>(xpti::trace_point_type_t::node_create),
41+
syclCallback);
42+
xptiRegisterCallback(
43+
StreamID, static_cast<uint16_t>(xpti::trace_point_type_t::edge_create),
44+
syclCallback);
45+
xptiRegisterCallback(
46+
StreamID, static_cast<uint16_t>(xpti::trace_point_type_t::task_begin),
47+
syclCallback);
48+
xptiRegisterCallback(
49+
StreamID, static_cast<uint16_t>(xpti::trace_point_type_t::task_end),
50+
syclCallback);
51+
xptiRegisterCallback(
52+
StreamID, static_cast<uint16_t>(xpti::trace_point_type_t::signal),
53+
syclCallback);
54+
xptiRegisterCallback(
55+
StreamID,
56+
static_cast<uint16_t>(xpti::trace_point_type_t::barrier_begin),
57+
syclCallback);
58+
xptiRegisterCallback(
59+
StreamID, static_cast<uint16_t>(xpti::trace_point_type_t::barrier_end),
60+
syclCallback);
61+
xptiRegisterCallback(
62+
StreamID, static_cast<uint16_t>(xpti::trace_point_type_t::wait_begin),
63+
syclCallback);
64+
xptiRegisterCallback(
65+
StreamID, static_cast<uint16_t>(xpti::trace_point_type_t::wait_end),
66+
syclCallback);
67+
xptiRegisterCallback(
68+
StreamID, static_cast<uint16_t>(xpti::trace_point_type_t::signal),
69+
syclCallback);
70+
}
71+
}
72+
73+
XPTI_CALLBACK_API void xptiTraceFinish(const char *streamName) {
74+
std::cout << "xptiTraceFinish: Stream Name = " << streamName << "\n";
75+
}
76+
77+
XPTI_CALLBACK_API void syclPiCallback(uint16_t TraceType,
78+
xpti::trace_event_data_t *,
79+
xpti::trace_event_data_t *, uint64_t,
80+
const void *UserData) {
81+
std::lock_guard Lock{GMutex};
82+
auto Type = static_cast<xpti::trace_point_type_t>(TraceType);
83+
const char *funcName = static_cast<const char *>(UserData);
84+
if (Type == xpti::trace_point_type_t::function_begin) {
85+
std::cout << "PI Call Begin : ";
86+
} else if (Type == xpti::trace_point_type_t::function_end) {
87+
std::cout << "PI Call End : ";
88+
}
89+
std::cout << funcName << "\n";
90+
}
91+
92+
XPTI_CALLBACK_API void syclCallback(uint16_t TraceType,
93+
xpti::trace_event_data_t *,
94+
xpti::trace_event_data_t *Event, uint64_t,
95+
const void *UserData) {
96+
std::lock_guard Lock{GMutex};
97+
auto Type = static_cast<xpti::trace_point_type_t>(TraceType);
98+
switch (Type) {
99+
case xpti::trace_point_type_t::graph_create:
100+
std::cout << "Graph create\n";
101+
break;
102+
case xpti::trace_point_type_t::node_create:
103+
std::cout << "Node create\n";
104+
break;
105+
case xpti::trace_point_type_t::edge_create:
106+
std::cout << "Edge create\n";
107+
break;
108+
case xpti::trace_point_type_t::task_begin:
109+
std::cout << "Task begin\n";
110+
break;
111+
case xpti::trace_point_type_t::task_end:
112+
std::cout << "Task end\n";
113+
break;
114+
case xpti::trace_point_type_t::signal:
115+
std::cout << "Signal\n";
116+
break;
117+
case xpti::trace_point_type_t::wait_begin:
118+
std::cout << "Wait begin\n";
119+
break;
120+
case xpti::trace_point_type_t::wait_end:
121+
std::cout << "Wait end\n";
122+
break;
123+
case xpti::trace_point_type_t::barrier_begin:
124+
std::cout << "Barrier begin\n";
125+
break;
126+
case xpti::trace_point_type_t::barrier_end:
127+
std::cout << "Barrier end\n";
128+
break;
129+
default:
130+
std::cout << "Unknown tracepoint\n";
131+
}
132+
133+
xpti::metadata_t *Metadata = xptiQueryMetadata(Event);
134+
for (auto &Item : *Metadata) {
135+
std::cout << " " << xptiLookupString(Item.first) << " : "
136+
<< xptiLookupString(Item.second) << "\n";
137+
}
138+
}

SYCL/XPTI/basic_event_collection.cpp

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
// REQUIRES: xptifw, opencl
2+
// RUN: %clangxx %s -DXPTI_COLLECTOR -DXPTI_CALLBACK_API_EXPORTS %xptifw_lib %shared_lib %fPIC %cxx_std_optionc++17 -o %t_collector.dll
3+
// RUN: %clangxx -fsycl -fsycl-unnamed-lambda -fsycl-targets=%sycl_triple %s -o %t.out
4+
// RUN: env XPTI_TRACE_ENABLE=1 env XPTI_FRAMEWORK_DISPATCHER=%xptifw_dispatcher env XPTI_SUBSCRIBERS=%t_collector.dll env SYCL_DEVICE_FILTER=opencl %t.out | FileCheck %s 2>&1
5+
6+
#ifdef XPTI_COLLECTOR
7+
8+
#include "Inputs/test_collector.cpp"
9+
10+
#else
11+
12+
#include <sycl/sycl.hpp>
13+
14+
int main() {
15+
sycl::queue Q{sycl::default_selector{}};
16+
17+
auto Ptr = sycl::malloc_device<int>(1, Q);
18+
19+
auto Evt1 = Q.single_task([=]() { Ptr[0] = 1; });
20+
21+
auto Evt2 = Q.submit([&](sycl::handler &CGH) {
22+
CGH.depends_on(Evt1);
23+
CGH.single_task([=]() { Ptr[0]++; });
24+
});
25+
26+
Evt2.wait();
27+
28+
int Res = 0;
29+
Q.memcpy(&Res, Ptr, 1);
30+
Q.wait();
31+
32+
assert(Res == 2);
33+
34+
return 0;
35+
}
36+
37+
#endif
38+
39+
// CHECK: xptiTraceInit: Stream Name = sycl
40+
// CHECK-NEXT: Graph create
41+
// CHECK-NEXT: xptiTraceInit: Stream Name = sycl.pi
42+
// CHECK-NEXT: xptiTraceInit: Stream Name = sycl.pi.debug
43+
// CHECK-NEXT: PI Call Begin : piPlatformsGet
44+
// CHECK-NEXT: PI Call Begin : piPlatformsGet
45+
// CHECK-NEXT: PI Call Begin : piDevicesGet
46+
// CHECK-NEXT: PI Call Begin : piDevicesGet
47+
// CHECK-NEXT: PI Call Begin : piDeviceGetInfo
48+
// CHECK-NEXT: PI Call Begin : piDeviceGetInfo
49+
// CHECK-NEXT: PI Call Begin : piDeviceGetInfo
50+
// CHECK-NEXT: PI Call Begin : piDeviceRetain
51+
// CHECK-NEXT: PI Call Begin : piDeviceGetInfo
52+
// CHECK-NEXT: PI Call Begin : piDeviceGetInfo
53+
// CHECK-NEXT: PI Call Begin : piPlatformGetInfo
54+
// CHECK-NEXT: PI Call Begin : piPlatformGetInfo
55+
// CHECK-NEXT: PI Call Begin : piDeviceRelease
56+
// CHECK: PI Call Begin : piContextCreate
57+
// CHECK-NEXT: PI Call Begin : piQueueCreate
58+
// CHECK-NEXT: PI Call Begin : piextUSMDeviceAlloc
59+
// CHECK-NEXT: PI Call Begin : piextDeviceSelectBinary
60+
// CHECK-NEXT: PI Call Begin : piDeviceGetInfo
61+
// CHECK: PI Call Begin : piKernelCreate
62+
// CHECK-NEXT: PI Call Begin : piKernelSetExecInfo
63+
// CHECK-NEXT: PI Call Begin : piextKernelSetArgPointer
64+
// CHECK-NEXT: PI Call Begin : piKernelGetGroupInfo
65+
// CHECK-NEXT: PI Call Begin : piEnqueueKernelLaunch
66+
// CHECK-NEXT: Node create
67+
// CHECK-NEXT: sym_line_no : 21
68+
// CHECK-NEXT: sym_source_file_name : {{.*}}
69+
// CHECK-NEXT: sym_function_name : typeinfo name for main::{lambda(cl::sycl::handler&)#1}::operator()(cl::sycl::handler&) const::{lambda()#1}
70+
// CHECK-NEXT: from_source : false
71+
// CHECK-NEXT: kernel_name : typeinfo name for main::{lambda(cl::sycl::handler&)#1}::operator()(cl::sycl::handler&) const::{lambda()#1}
72+
// CHECK-NEXT: sycl_device : {{.*}}
73+
// CHECK-NEXT: Node create
74+
// CHECK-NEXT: kernel_name : virtual_node[{{.*}}]
75+
// CHECK-NEXT: Edge create
76+
// CHECK-NEXT: event : Event[{{.*}}]
77+
// CHECK-NEXT: Task begin
78+
// CHECK-NEXT: sym_line_no : 21
79+
// CHECK-NEXT: sym_source_file_name : {{.*}}
80+
// CHECK-NEXT: sym_function_name : typeinfo name for main::{lambda(cl::sycl::handler&)#1}::operator()(cl::sycl::handler&) const::{lambda()#1}
81+
// CHECK-NEXT: from_source : false
82+
// CHECK-NEXT: kernel_name : typeinfo name for main::{lambda(cl::sycl::handler&)#1}::operator()(cl::sycl::handler&) const::{lambda()#1}
83+
// CHECK-NEXT: sycl_device : {{.*}}
84+
// CHECK-NEXT: PI Call Begin : piKernelCreate
85+
// CHECK-NEXT: PI Call Begin : piKernelSetExecInfo
86+
// CHECK-NEXT: PI Call Begin : piextKernelSetArgPointer
87+
// CHECK-NEXT: PI Call Begin : piKernelGetGroupInfo
88+
// CHECK-NEXT: PI Call Begin : piEnqueueKernelLaunch
89+
// CHECK-NEXT: Signal
90+
// CHECK-NEXT: sym_line_no : 21
91+
// CHECK-NEXT: sym_source_file_name : {{.*}}
92+
// CHECK-NEXT: sym_function_name : typeinfo name for main::{lambda(cl::sycl::handler&)#1}::operator()(cl::sycl::handler&) const::{lambda()#1}
93+
// CHECK-NEXT: from_source : false
94+
// CHECK-NEXT: kernel_name : typeinfo name for main::{lambda(cl::sycl::handler&)#1}::operator()(cl::sycl::handler&) const::{lambda()#1}
95+
// CHECK-NEXT: sycl_device : {{.*}}
96+
// CHECK-NEXT: Task end
97+
// CHECK-NEXT: sym_line_no : 21
98+
// CHECK-NEXT: sym_source_file_name : {{.*}}
99+
// CHECK-NEXT: sym_function_name : typeinfo name for main::{lambda(cl::sycl::handler&)#1}::operator()(cl::sycl::handler&) const::{lambda()#1}
100+
// CHECK-NEXT: from_source : false
101+
// CHECK-NEXT: kernel_name : typeinfo name for main::{lambda(cl::sycl::handler&)#1}::operator()(cl::sycl::handler&) const::{lambda()#1}
102+
// CHECK-NEXT: sycl_device : {{.*}}
103+
// CHECK-NEXT: Wait begin
104+
// CHECK-NEXT: PI Call Begin : piEventsWait
105+
// CHECK-NEXT: Wait end
106+
// CHECK-NEXT: PI Call Begin : piextUSMEnqueueMemcpy
107+
// CHECK-NEXT: PI Call Begin : piEventRelease
108+
// CHECK-NEXT: Wait begin
109+
// CHECK-NEXT: sycl_device : {{.*}}
110+
// CHECK-NEXT: PI Call Begin : piQueueFinish
111+
// CHECK-NEXT: Wait end
112+
// CHECK-NEXT: sycl_device : {{.*}}
113+
// CHECK-NEXT: PI Call Begin : piEventRelease
114+
// CHECK-NEXT: PI Call Begin : piEventRelease
115+
// CHECK-NEXT: PI Call Begin : piQueueRelease
116+
// CHECK-NEXT: PI Call Begin : piContextRelease
117+
// CHECK-NEXT: PI Call Begin : piKernelRelease
118+
// CHECK-NEXT: PI Call Begin : piKernelRelease
119+
// CHECK-NEXT: PI Call Begin : piProgramRelease
120+
// CHECK-NEXT: PI Call Begin : piDeviceRelease
121+
// CHECK-NEXT: PI Call Begin : piTearDown

SYCL/lit.cfg.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,16 @@
142142
config.substitutions.append( ('%include_option', '/FI' ) )
143143
config.substitutions.append( ('%debug_option', '/DEBUG' ) )
144144
config.substitutions.append( ('%cxx_std_option', '/std:' ) )
145+
config.substitutions.append( ('%fPIC', '') )
146+
config.substitutions.append( ('%shared_lib', '/LD') )
145147
else:
146148
config.substitutions.append( ('%sycl_options', ' -lsycl -I' +
147149
config.sycl_include + ' -I' + os.path.join(config.sycl_include, 'sycl')) )
148150
config.substitutions.append( ('%include_option', '-include' ) )
149151
config.substitutions.append( ('%debug_option', '-g' ) )
150152
config.substitutions.append( ('%cxx_std_option', '-std=' ) )
153+
config.substitutions.append( ('%fPIC', '-fPIC') )
154+
config.substitutions.append( ('%shared_lib', '-shared') )
151155

152156
if not config.gpu_aot_target_opts:
153157
config.gpu_aot_target_opts = '"-device *"'
@@ -326,6 +330,34 @@
326330
if find_executable('sycl-ls'):
327331
config.available_features.add('sycl-ls')
328332

333+
# TODO properly set XPTIFW include and runtime dirs
334+
xptifw_lib_dir = os.path.join(config.dpcpp_root_dir, 'lib')
335+
xptifw_dispatcher = ""
336+
if platform.system() == "Linux":
337+
xptifw_dispatcher = os.path.join(xptifw_lib_dir, 'libxptifw.so')
338+
elif platform.system() == "Windows":
339+
xptifw_dispatcher = os.path.join(config.dpcpp_root_dir, 'bin', 'xptifw.dll')
340+
xptifw_includes = os.path.join(config.dpcpp_root_dir, 'include')
341+
if os.path.exists(xptifw_lib) and os.path.exists(os.path.join(xptifw_includes, 'xpti', 'xpti_trace_framework.h')):
342+
config.available_features.add('xptifw')
343+
config.substitutions.append(('%xptifw_dispatcher', xptifw_dispatcher))
344+
if platform.system() == "Linux":
345+
config.substitutions.append(('%xptifw_lib', " {}/xptifw.lib".format(xptifw_lib_dir)))
346+
elif platform.system() == "Windows":
347+
config.substitutions.append(('%xptifw_lib', "-L{} -I{} -lxptifw".format(xptifw_lib_dir, xptifw_includes)))
348+
349+
350+
llvm_tools = ["llvm-spirv", "llvm-link"]
351+
for llvm_tool in llvm_tools:
352+
llvm_tool_path = find_executable(llvm_tool)
353+
if llvm_tool_path:
354+
lit_config.note("Found " + llvm_tool)
355+
config.available_features.add(llvm_tool)
356+
config.substitutions.append( ('%' + llvm_tool.replace('-', '_'),
357+
os.path.realpath(llvm_tool_path)) )
358+
else:
359+
lit_config.warning("Can't find " + llvm_tool)
360+
329361
if find_executable('cmc'):
330362
config.available_features.add('cm-compiler')
331363

0 commit comments

Comments
 (0)