Skip to content

Commit 9bf81eb

Browse files
authored
[SYCL][XPTI] Instrumentation of SYCL runtime with XPTI (#1129)
+ XPTI proxy library to provide entry points into the xpti instrumentation framework + Header specification of the XPTI framework API calls + Documentation describing the changes to SYCL runtime available under xpti/doc + SYCL runtime instrumentation using XPTI proxy library to monitor the creation of the asynchronous task graph (nodes and dependencies) + Instrumentation of entry points in queue to capture the end-user source code locations of calls to submit, parallel_for etc. + Updates to the CMakeLists.txt to soft enable the XPTI instrumentation and linking of the SYCL library with the XPTI proxy/stub library + Updates to the CI scripts to include XPTI proxy library in building along with enabling of the instrumentation in the SYCL library Signed-off-by: Vasanth Tovinkere <[email protected]>
1 parent fc03fda commit 9bf81eb

30 files changed

+3650
-259
lines changed

buildbot/configure.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ def do_configure(args):
1010
llvm_dir = os.path.join(args.src_dir, "llvm")
1111
sycl_dir = os.path.join(args.src_dir, "sycl")
1212
spirv_dir = os.path.join(args.src_dir, "llvm-spirv")
13+
xpti_dir = os.path.join(args.src_dir, "xpti")
1314
ocl_header_dir = os.path.join(args.obj_dir, "OpenCL-Headers")
1415
icd_loader_lib = os.path.join(args.obj_dir, "OpenCL-ICD-Loader", "build")
1516
llvm_targets_to_build = 'X86'
16-
llvm_enable_projects = 'clang;llvm-spirv;sycl;opencl-aot'
17+
llvm_enable_projects = 'clang;llvm-spirv;sycl;opencl-aot;xpti'
1718
libclc_targets_to_build = ''
1819
sycl_build_pi_cuda = 'OFF'
1920
llvm_enable_assertions = 'ON'
@@ -44,9 +45,10 @@ def do_configure(args):
4445
"-DCMAKE_BUILD_TYPE={}".format(args.build_type),
4546
"-DLLVM_ENABLE_ASSERTIONS={}".format(llvm_enable_assertions),
4647
"-DLLVM_TARGETS_TO_BUILD={}".format(llvm_targets_to_build),
47-
"-DLLVM_EXTERNAL_PROJECTS=sycl;llvm-spirv;opencl-aot",
48+
"-DLLVM_EXTERNAL_PROJECTS=sycl;llvm-spirv;opencl-aot;xpti",
4849
"-DLLVM_EXTERNAL_SYCL_SOURCE_DIR={}".format(sycl_dir),
4950
"-DLLVM_EXTERNAL_LLVM_SPIRV_SOURCE_DIR={}".format(spirv_dir),
51+
"-DLLVM_EXTERNAL_XPTI_SOURCE_DIR={}".format(xpti_dir),
5052
"-DLLVM_ENABLE_PROJECTS={}".format(llvm_enable_projects),
5153
"-DLIBCLC_TARGETS_TO_BUILD={}".format(libclc_targets_to_build),
5254
"-DOpenCL_INCLUDE_DIR={}".format(ocl_header_dir),
@@ -57,6 +59,7 @@ def do_configure(args):
5759
"-DCMAKE_INSTALL_PREFIX={}".format(install_dir),
5860
"-DSYCL_INCLUDE_TESTS=ON", # Explicitly include all kinds of SYCL tests.
5961
"-DLLVM_ENABLE_DOXYGEN={}".format(llvm_enable_doxygen),
62+
"-DSYCL_ENABLE_XPTI_TRACING=ON", # Explicitly turn on XPTI tracing
6063
llvm_dir
6164
]
6265

sycl/CMakeLists.txt

+11
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ if(SYCL_ENABLE_WERROR)
2626
endif()
2727
endif()
2828

29+
# Create a soft option for enabling or disabling the instrumentation
30+
# of the SYCL runtime and expect enabling
31+
option(SYCL_ENABLE_XPTI_TRACING "Enable tracing of SYCL constructs" OFF)
32+
2933
if(MSVC)
3034
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
3135
# Skip asynchronous C++ exceptions catching and assume "extern C" functions
@@ -218,6 +222,13 @@ add_custom_target( sycl-toolchain
218222
COMMENT "Building SYCL compiler toolchain..."
219223
)
220224

225+
if (SYCL_ENABLE_XPTI_TRACING)
226+
add_dependencies( sycl-toolchain xpti)
227+
if (MSVC)
228+
add_dependencies( sycl-toolchain xptid)
229+
endif()
230+
endif()
231+
221232
if (NOT DEFINED LLVM_INCLUDE_TESTS)
222233
set(LLVM_INCLUDE_TESTS ON)
223234
endif()

sycl/include/CL/sycl/detail/cg.hpp

+41-18
Original file line numberDiff line numberDiff line change
@@ -368,11 +368,21 @@ class CG {
368368
vector_class<detail::AccessorImplPtr> AccStorage,
369369
vector_class<shared_ptr_class<const void>> SharedPtrStorage,
370370
vector_class<Requirement *> Requirements,
371-
vector_class<detail::EventImplPtr> Events)
371+
vector_class<detail::EventImplPtr> Events, detail::code_location loc = {})
372372
: MType(Type), MArgsStorage(std::move(ArgsStorage)),
373373
MAccStorage(std::move(AccStorage)),
374374
MSharedPtrStorage(std::move(SharedPtrStorage)),
375-
MRequirements(std::move(Requirements)), MEvents(std::move(Events)) {}
375+
MRequirements(std::move(Requirements)), MEvents(std::move(Events)) {
376+
// Capture the user code-location from Q.submit(), Q.parallel_for()
377+
// etc for later use; if code location information is not available,
378+
// the file name and function name members will be empty strings
379+
if (loc.functionName())
380+
MFunctionName = loc.functionName();
381+
if (loc.fileName())
382+
MFileName = loc.fileName();
383+
MLine = loc.lineNumber();
384+
MColumn = loc.columnNumber();
385+
}
376386

377387
CG(CG &&CommandGroup) = default;
378388

@@ -397,6 +407,12 @@ class CG {
397407
vector_class<Requirement *> MRequirements;
398408
// List of events that order the execution of this CG
399409
vector_class<detail::EventImplPtr> MEvents;
410+
// Member variables to capture the user code-location
411+
// information from Q.submit(), Q.parallel_for() etc
412+
// Storage for function name and source file name
413+
string_class MFunctionName, MFileName;
414+
// Storage for line and column of code location
415+
int32_t MLine, MColumn;
400416
};
401417

402418
// The class which represents "execute kernel" command group.
@@ -420,10 +436,10 @@ class CGExecKernel : public CG {
420436
vector_class<ArgDesc> Args, string_class KernelName,
421437
detail::OSModuleHandle OSModuleHandle,
422438
vector_class<shared_ptr_class<detail::stream_impl>> Streams,
423-
CGTYPE Type)
439+
CGTYPE Type, detail::code_location loc = {})
424440
: CG(Type, std::move(ArgsStorage), std::move(AccStorage),
425441
std::move(SharedPtrStorage), std::move(Requirements),
426-
std::move(Events)),
442+
std::move(Events), std::move(loc)),
427443
MNDRDesc(std::move(NDRDesc)), MHostKernel(std::move(HKernel)),
428444
MSyclKernel(std::move(SyclKernel)), MArgs(std::move(Args)),
429445
MKernelName(std::move(KernelName)), MOSModuleHandle(OSModuleHandle),
@@ -450,10 +466,11 @@ class CGCopy : public CG {
450466
vector_class<detail::AccessorImplPtr> AccStorage,
451467
vector_class<shared_ptr_class<const void>> SharedPtrStorage,
452468
vector_class<Requirement *> Requirements,
453-
vector_class<detail::EventImplPtr> Events)
469+
vector_class<detail::EventImplPtr> Events,
470+
detail::code_location loc = {})
454471
: CG(CopyType, std::move(ArgsStorage), std::move(AccStorage),
455472
std::move(SharedPtrStorage), std::move(Requirements),
456-
std::move(Events)),
473+
std::move(Events), std::move(loc)),
457474
MSrc(Src), MDst(Dst) {}
458475
void *getSrc() { return MSrc; }
459476
void *getDst() { return MDst; }
@@ -470,10 +487,11 @@ class CGFill : public CG {
470487
vector_class<detail::AccessorImplPtr> AccStorage,
471488
vector_class<shared_ptr_class<const void>> SharedPtrStorage,
472489
vector_class<Requirement *> Requirements,
473-
vector_class<detail::EventImplPtr> Events)
490+
vector_class<detail::EventImplPtr> Events,
491+
detail::code_location loc = {})
474492
: CG(FILL, std::move(ArgsStorage), std::move(AccStorage),
475493
std::move(SharedPtrStorage), std::move(Requirements),
476-
std::move(Events)),
494+
std::move(Events), std::move(loc)),
477495
MPattern(std::move(Pattern)), MPtr((Requirement *)Ptr) {}
478496
Requirement *getReqToFill() { return MPtr; }
479497
};
@@ -487,10 +505,11 @@ class CGUpdateHost : public CG {
487505
vector_class<detail::AccessorImplPtr> AccStorage,
488506
vector_class<shared_ptr_class<const void>> SharedPtrStorage,
489507
vector_class<Requirement *> Requirements,
490-
vector_class<detail::EventImplPtr> Events)
508+
vector_class<detail::EventImplPtr> Events,
509+
detail::code_location loc = {})
491510
: CG(UPDATE_HOST, std::move(ArgsStorage), std::move(AccStorage),
492511
std::move(SharedPtrStorage), std::move(Requirements),
493-
std::move(Events)),
512+
std::move(Events), std::move(loc)),
494513
MPtr((Requirement *)Ptr) {}
495514

496515
Requirement *getReqToUpdate() { return MPtr; }
@@ -508,10 +527,11 @@ class CGCopyUSM : public CG {
508527
vector_class<detail::AccessorImplPtr> AccStorage,
509528
vector_class<shared_ptr_class<const void>> SharedPtrStorage,
510529
vector_class<Requirement *> Requirements,
511-
vector_class<detail::EventImplPtr> Events)
530+
vector_class<detail::EventImplPtr> Events,
531+
detail::code_location loc = {})
512532
: CG(COPY_USM, std::move(ArgsStorage), std::move(AccStorage),
513533
std::move(SharedPtrStorage), std::move(Requirements),
514-
std::move(Events)),
534+
std::move(Events), std::move(loc)),
515535
MSrc(Src), MDst(Dst), MLength(Length) {}
516536

517537
void *getSrc() { return MSrc; }
@@ -531,10 +551,11 @@ class CGFillUSM : public CG {
531551
vector_class<detail::AccessorImplPtr> AccStorage,
532552
vector_class<shared_ptr_class<const void>> SharedPtrStorage,
533553
vector_class<Requirement *> Requirements,
534-
vector_class<detail::EventImplPtr> Events)
554+
vector_class<detail::EventImplPtr> Events,
555+
detail::code_location loc = {})
535556
: CG(FILL_USM, std::move(ArgsStorage), std::move(AccStorage),
536557
std::move(SharedPtrStorage), std::move(Requirements),
537-
std::move(Events)),
558+
std::move(Events), std::move(loc)),
538559
MPattern(std::move(Pattern)), MDst(DstPtr), MLength(Length) {}
539560
void *getDst() { return MDst; }
540561
size_t getLength() { return MLength; }
@@ -552,10 +573,11 @@ class CGPrefetchUSM : public CG {
552573
vector_class<detail::AccessorImplPtr> AccStorage,
553574
vector_class<shared_ptr_class<const void>> SharedPtrStorage,
554575
vector_class<Requirement *> Requirements,
555-
vector_class<detail::EventImplPtr> Events)
576+
vector_class<detail::EventImplPtr> Events,
577+
detail::code_location loc = {})
556578
: CG(PREFETCH_USM, std::move(ArgsStorage), std::move(AccStorage),
557579
std::move(SharedPtrStorage), std::move(Requirements),
558-
std::move(Events)),
580+
std::move(Events), std::move(loc)),
559581
MDst(DstPtr), MLength(Length) {}
560582
void *getDst() { return MDst; }
561583
size_t getLength() { return MLength; }
@@ -570,10 +592,11 @@ class CGInteropTask : public CG {
570592
std::vector<detail::AccessorImplPtr> AccStorage,
571593
std::vector<std::shared_ptr<const void>> SharedPtrStorage,
572594
std::vector<Requirement *> Requirements,
573-
std::vector<detail::EventImplPtr> Events, CGTYPE Type)
595+
std::vector<detail::EventImplPtr> Events, CGTYPE Type,
596+
detail::code_location loc = {})
574597
: CG(Type, std::move(ArgsStorage), std::move(AccStorage),
575598
std::move(SharedPtrStorage), std::move(Requirements),
576-
std::move(Events)),
599+
std::move(Events), std::move(loc)),
577600
MInteropTask(std::move(InteropTask)) {}
578601
};
579602

sycl/include/CL/sycl/detail/common.hpp

+64-4
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,84 @@
1616
#include <CL/cl.h>
1717
#include <CL/cl_ext.h>
1818
#include <CL/cl_ext_intel.h>
19+
20+
#include <cstdint>
1921
#include <string>
2022
#include <type_traits>
2123

2224
#define STRINGIFY_LINE_HELP(s) #s
2325
#define STRINGIFY_LINE(s) STRINGIFY_LINE_HELP(s)
2426

27+
// Default signature enables the passing of user code location information to
28+
// public methods as a default argument. If the end-user wants to disable the
29+
// code location information, they must compile the code with
30+
// -DDISABLE_SYCL_INSTRUMENTATION_METADATA flag
31+
__SYCL_INLINE_NAMESPACE(cl) {
32+
namespace sycl {
33+
namespace detail {
34+
// We define a sycl stream name and this will
35+
// be used by the instrumentation framework
36+
constexpr const char *SYCL_STREAM_NAME = "sycl";
37+
// Data structure that captures the user code
38+
// location information using the builtin capabilities
39+
// of the compiler
40+
struct code_location {
41+
#ifdef _MSC_VER
42+
// Since MSVC does not support the required builtins, we
43+
// implement the version with "unknown"s which is handled
44+
// correctly by the instrumentation
45+
static constexpr code_location current(const char *fileName = nullptr,
46+
const char *funcName = nullptr,
47+
unsigned long lineNo = 0,
48+
unsigned long columnNo = 0) noexcept {
49+
return code_location(fileName, funcName, lineNo, columnNo);
50+
}
51+
#else
52+
static constexpr code_location
53+
current(const char *fileName = __builtin_FILE(),
54+
const char *funcName = __builtin_FUNCTION(),
55+
unsigned long lineNo = __builtin_LINE(),
56+
unsigned long columnNo = 0) noexcept {
57+
return code_location(fileName, funcName, lineNo, columnNo);
58+
}
59+
#endif
60+
61+
constexpr code_location(const char *file, const char *func, int line,
62+
int col) noexcept
63+
: MFileName(file), MFunctionName(func), MLineNo(line), MColumnNo(col) {}
64+
65+
constexpr code_location() noexcept
66+
: MFileName(nullptr), MFunctionName(nullptr), MLineNo(0), MColumnNo(0) {}
67+
68+
constexpr unsigned long lineNumber() const noexcept { return MLineNo; }
69+
constexpr unsigned long columnNumber() const noexcept { return MColumnNo; }
70+
constexpr const char *fileName() const noexcept { return MFileName; }
71+
constexpr const char *functionName() const noexcept { return MFunctionName; }
72+
73+
private:
74+
const char *MFileName;
75+
const char *MFunctionName;
76+
unsigned long MLineNo;
77+
unsigned long MColumnNo;
78+
};
79+
} // namespace detail
80+
} // namespace sycl
81+
} // __SYCL_INLINE_NAMESPACE(cl)
82+
2583
__SYCL_INLINE_NAMESPACE(cl) {
2684
namespace sycl {
2785
namespace detail {
2886

2987
const char *stringifyErrorCode(cl_int error);
3088

31-
static inline std::string codeToString(cl_int code){
32-
return std::string(std::to_string(code) + " (" +
33-
stringifyErrorCode(code) + ")");
89+
static inline std::string codeToString(cl_int code) {
90+
return std::string(std::to_string(code) + " (" + stringifyErrorCode(code) +
91+
")");
3492
}
3593

36-
}}} // __SYCL_INLINE_NAMESPACE(cl)::sycl::detail
94+
} // namespace detail
95+
} // namespace sycl
96+
} // __SYCL_INLINE_NAMESPACE(cl)
3797

3898
#ifdef __SYCL_DEVICE_ONLY__
3999
// TODO remove this when 'assert' is supported in device code

sycl/include/CL/sycl/detail/pi.hpp

+7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@
1818
#include <cassert>
1919
#include <string>
2020

21+
#ifdef XPTI_ENABLE_INSTRUMENTATION
22+
// Forward declarations
23+
namespace xpti {
24+
struct trace_event_data_t;
25+
}
26+
#endif
27+
2128
__SYCL_INLINE_NAMESPACE(cl) {
2229
namespace sycl {
2330
namespace detail {

sycl/include/CL/sycl/handler.hpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,9 @@ class handler {
194194
/// It's expected that the method is the latest method executed before
195195
/// object destruction.
196196
///
197-
/// \return a SYCL event object representing the command group.
198-
event finalize();
197+
/// \param Payload contains the code location of user code
198+
/// \return a SYCL event object representing the command group
199+
event finalize(const cl::sycl::detail::code_location &Payload = {});
199200

200201
/// Saves streams associated with this handler.
201202
///

0 commit comments

Comments
 (0)