1010#include < CL/sycl/backend_types.hpp>
1111#include < CL/sycl/detail/common.hpp>
1212#include < CL/sycl/detail/pi.hpp>
13+ #include < CL/sycl/detail/type_traits.hpp>
1314#include < CL/sycl/stl.hpp>
1415#include < detail/plugin_printers.hpp>
1516#include < memory>
@@ -25,7 +26,62 @@ namespace sycl {
2526namespace detail {
2627#ifdef XPTI_ENABLE_INSTRUMENTATION
2728extern xpti::trace_event_data_t *GPICallEvent;
29+ extern xpti::trace_event_data_t *GPIArgCallEvent;
2830#endif
31+
32+ template <PiApiKind Kind, size_t Idx, typename ... Args>
33+ struct array_fill_helper ;
34+
35+ template <PiApiKind Kind> struct PiApiArgTuple ;
36+
37+ #define _PI_API (api ) \
38+ template <> struct PiApiArgTuple <PiApiKind::api> { \
39+ using type = typename function_traits<decltype (api)>::args_type; \
40+ };
41+
42+ #include < CL/sycl/detail/pi.def>
43+ #undef _PI_API
44+
45+ template <PiApiKind Kind, size_t Idx, typename T>
46+ struct array_fill_helper <Kind, Idx, T> {
47+ static void fill (unsigned char *Dst, T &&Arg) {
48+ using ArgsTuple = typename PiApiArgTuple<Kind>::type;
49+ // C-style cast is required here.
50+ auto RealArg = (std::tuple_element_t <Idx, ArgsTuple>)(Arg);
51+ *(std::remove_cv_t <std::tuple_element_t <Idx, ArgsTuple>> *)Dst = RealArg;
52+ }
53+ };
54+
55+ template <PiApiKind Kind, size_t Idx, typename T, typename ... Args>
56+ struct array_fill_helper <Kind, Idx, T, Args...> {
57+ static void fill (unsigned char *Dst, const T &&Arg, Args &&... Rest) {
58+ using ArgsTuple = typename PiApiArgTuple<Kind>::type;
59+ // C-style cast is required here.
60+ auto RealArg = (std::tuple_element_t <Idx, ArgsTuple>)(Arg);
61+ *(std::remove_cv_t <std::tuple_element_t <Idx, ArgsTuple>> *)Dst = RealArg;
62+ array_fill_helper<Kind, Idx + 1 , Args...>::fill (
63+ Dst + sizeof (decltype (RealArg)), std::forward<Args>(Rest)...);
64+ }
65+ };
66+
67+ template <typename ... Ts>
68+ constexpr size_t totalSize (const std::tuple<Ts...> &) {
69+ return (sizeof (Ts) + ...);
70+ }
71+
72+ template <PiApiKind Kind, typename ... ArgsT>
73+ auto packCallArguments (ArgsT &&... Args) {
74+ using ArgsTuple = typename PiApiArgTuple<Kind>::type;
75+
76+ constexpr size_t TotalSize = totalSize (ArgsTuple{});
77+
78+ std::array<unsigned char , TotalSize> ArgsData;
79+ array_fill_helper<Kind, 0 , ArgsT...>::fill (ArgsData.data (),
80+ std::forward<ArgsT>(Args)...);
81+
82+ return ArgsData;
83+ }
84+
2985// / The plugin class provides a unified interface to the underlying low-level
3086// / runtimes for the device-agnostic SYCL runtime.
3187// /
@@ -85,6 +141,10 @@ class plugin {
85141 // the per_instance_user_data field.
86142 const char *PIFnName = PiCallInfo.getFuncName ();
87143 uint64_t CorrelationID = pi::emitFunctionBeginTrace (PIFnName);
144+ auto ArgsData =
145+ packCallArguments<PiApiOffset>(std::forward<ArgsT>(Args)...);
146+ uint64_t CorrelationIDWithArgs = pi::emitFunctionWithArgsBeginTrace (
147+ static_cast <uint32_t >(PiApiOffset), PIFnName, ArgsData.data ());
88148#endif
89149 RT::PiResult R;
90150 if (pi::trace (pi::TraceLevel::PI_TRACE_CALLS)) {
@@ -103,6 +163,9 @@ class plugin {
103163#ifdef XPTI_ENABLE_INSTRUMENTATION
104164 // Close the function begin with a call to function end
105165 pi::emitFunctionEndTrace (CorrelationID, PIFnName);
166+ pi::emitFunctionWithArgsEndTrace (CorrelationIDWithArgs,
167+ static_cast <uint32_t >(PiApiOffset),
168+ PIFnName, ArgsData.data (), R);
106169#endif
107170 return R;
108171 }
0 commit comments