Skip to content

Commit 9d1d3ac

Browse files
committed
don't call xpti if there are no subscribers
This avoids the overhead of preparing data for xpti, and the cost of the xpti call itself, if nothing is subscribed to the ur.call xpti call stream.
1 parent e3eeb4e commit 9d1d3ac

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ if(UR_ENABLE_TRACING)
137137

138138
if (UR_BUILD_XPTI_LIBS)
139139
# fetch xpti proxy library for the tracing layer
140-
FetchContentSparse_Declare(xpti https://github.com/intel/llvm.git "sycl-nightly/20230703" "xpti")
140+
FetchContentSparse_Declare(xpti https://github.com/intel/llvm.git "nightly-2024-10-22" "xpti")
141141
FetchContent_MakeAvailable(xpti)
142142

143143
# set -fPIC for xpti since we are linking it with a shared library
@@ -149,7 +149,7 @@ if(UR_ENABLE_TRACING)
149149
set(XPTI_DIR ${xpti_SOURCE_DIR})
150150
set(XPTI_ENABLE_TESTS OFF CACHE INTERNAL "Turn off xptifw tests")
151151

152-
FetchContentSparse_Declare(xptifw https://github.com/intel/llvm.git "sycl-nightly/20230703" "xptifw")
152+
FetchContentSparse_Declare(xptifw https://github.com/intel/llvm.git "nightly-2024-10-22" "xptifw")
153153

154154
FetchContent_MakeAvailable(xptifw)
155155

examples/collector/collector.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,7 @@ XPTI_CALLBACK_API void xptiTraceInit(unsigned int major_version,
125125
return;
126126
}
127127
if (std::string_view(stream_name) != UR_STREAM_NAME) {
128-
std::cout << "Invalid stream name: " << stream_name << ". Expected "
129-
<< UR_STREAM_NAME << ". Aborting." << std::endl;
128+
// we expect ur.call, but this can also be xpti.framework.
130129
return;
131130
}
132131

source/loader/layers/tracing/ur_tracing_layer.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "xpti/xpti_data_types.h"
1616
#include "xpti/xpti_trace_framework.h"
1717
#include <atomic>
18+
#include <cstdint>
1819
#include <optional>
1920
#include <sstream>
2021

@@ -59,6 +60,12 @@ void context_t::notify(uint16_t trace_type, uint32_t id, const char *name,
5960
}
6061

6162
uint64_t context_t::notify_begin(uint32_t id, const char *name, void *args) {
63+
// we use UINT64_MAX as a special value that means "tracing disabled",
64+
// so that we don't have to repeat this check in notify_end.
65+
if (!xptiCheckTraceEnabled(call_stream_id)) {
66+
return UINT64_MAX;
67+
}
68+
6269
if (auto loc = codelocData.get_codeloc()) {
6370
xpti::payload_t payload =
6471
xpti::payload_t(loc->functionName, loc->sourceFile, loc->lineNumber,
@@ -77,6 +84,10 @@ uint64_t context_t::notify_begin(uint32_t id, const char *name, void *args) {
7784

7885
void context_t::notify_end(uint32_t id, const char *name, void *args,
7986
ur_result_t *resultp, uint64_t instance) {
87+
if (instance == UINT64_MAX) { // tracing disabled
88+
return;
89+
}
90+
8091
notify((uint16_t)xpti::trace_point_type_t::function_with_args_end, id, name,
8192
args, resultp, instance);
8293
}

test/layers/tracing/test_collector.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ XPTI_CALLBACK_API void xptiTraceInit(unsigned int major_version,
4949
return;
5050
}
5151
if (std::string_view(stream_name) != UR_STREAM_NAME) {
52-
std::cout << "Invalid stream name: " << stream_name << ". Expected "
53-
<< UR_STREAM_NAME << ". Aborting." << std::endl;
52+
// we expect ur.call, but this can also be xpti.framework.
5453
return;
5554
}
5655

0 commit comments

Comments
 (0)