From 9d1d3ac4de1e28a78acd4fd34e00d78812937edd Mon Sep 17 00:00:00 2001 From: Piotr Balcer Date: Tue, 22 Oct 2024 14:20:17 +0200 Subject: [PATCH] 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. --- CMakeLists.txt | 4 ++-- examples/collector/collector.cpp | 3 +-- source/loader/layers/tracing/ur_tracing_layer.cpp | 11 +++++++++++ test/layers/tracing/test_collector.cpp | 3 +-- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e970e2759..375f727d1c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -137,7 +137,7 @@ if(UR_ENABLE_TRACING) if (UR_BUILD_XPTI_LIBS) # fetch xpti proxy library for the tracing layer - FetchContentSparse_Declare(xpti https://github.com/intel/llvm.git "sycl-nightly/20230703" "xpti") + FetchContentSparse_Declare(xpti https://github.com/intel/llvm.git "nightly-2024-10-22" "xpti") FetchContent_MakeAvailable(xpti) # set -fPIC for xpti since we are linking it with a shared library @@ -149,7 +149,7 @@ if(UR_ENABLE_TRACING) set(XPTI_DIR ${xpti_SOURCE_DIR}) set(XPTI_ENABLE_TESTS OFF CACHE INTERNAL "Turn off xptifw tests") - FetchContentSparse_Declare(xptifw https://github.com/intel/llvm.git "sycl-nightly/20230703" "xptifw") + FetchContentSparse_Declare(xptifw https://github.com/intel/llvm.git "nightly-2024-10-22" "xptifw") FetchContent_MakeAvailable(xptifw) diff --git a/examples/collector/collector.cpp b/examples/collector/collector.cpp index cc9580bc4f..6312dba549 100644 --- a/examples/collector/collector.cpp +++ b/examples/collector/collector.cpp @@ -125,8 +125,7 @@ XPTI_CALLBACK_API void xptiTraceInit(unsigned int major_version, return; } if (std::string_view(stream_name) != UR_STREAM_NAME) { - std::cout << "Invalid stream name: " << stream_name << ". Expected " - << UR_STREAM_NAME << ". Aborting." << std::endl; + // we expect ur.call, but this can also be xpti.framework. return; } diff --git a/source/loader/layers/tracing/ur_tracing_layer.cpp b/source/loader/layers/tracing/ur_tracing_layer.cpp index 7a3f30d9a8..614f649a3c 100644 --- a/source/loader/layers/tracing/ur_tracing_layer.cpp +++ b/source/loader/layers/tracing/ur_tracing_layer.cpp @@ -15,6 +15,7 @@ #include "xpti/xpti_data_types.h" #include "xpti/xpti_trace_framework.h" #include +#include #include #include @@ -59,6 +60,12 @@ void context_t::notify(uint16_t trace_type, uint32_t id, const char *name, } uint64_t context_t::notify_begin(uint32_t id, const char *name, void *args) { + // we use UINT64_MAX as a special value that means "tracing disabled", + // so that we don't have to repeat this check in notify_end. + if (!xptiCheckTraceEnabled(call_stream_id)) { + return UINT64_MAX; + } + if (auto loc = codelocData.get_codeloc()) { xpti::payload_t payload = 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) { void context_t::notify_end(uint32_t id, const char *name, void *args, ur_result_t *resultp, uint64_t instance) { + if (instance == UINT64_MAX) { // tracing disabled + return; + } + notify((uint16_t)xpti::trace_point_type_t::function_with_args_end, id, name, args, resultp, instance); } diff --git a/test/layers/tracing/test_collector.cpp b/test/layers/tracing/test_collector.cpp index 2e412427a7..db0940ad14 100644 --- a/test/layers/tracing/test_collector.cpp +++ b/test/layers/tracing/test_collector.cpp @@ -49,8 +49,7 @@ XPTI_CALLBACK_API void xptiTraceInit(unsigned int major_version, return; } if (std::string_view(stream_name) != UR_STREAM_NAME) { - std::cout << "Invalid stream name: " << stream_name << ". Expected " - << UR_STREAM_NAME << ". Aborting." << std::endl; + // we expect ur.call, but this can also be xpti.framework. return; }