From 22bb9e57ec949be8def77c08dd0d290c9e0e4a13 Mon Sep 17 00:00:00 2001 From: Piotr Balcer Date: Tue, 22 Oct 2024 14:20:17 +0200 Subject: [PATCH 1/2] 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 d3707f4879..def5abc8a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -133,7 +133,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 @@ -145,7 +145,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 c6fd4ca40d..63fd8b526b 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; } From 62113c0ae683b3fc87c07057362a5a0f5a8c84ed Mon Sep 17 00:00:00 2001 From: Piotr Balcer Date: Thu, 31 Oct 2024 09:50:42 +0100 Subject: [PATCH 2/2] set version to 0.10.11 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index def5abc8a5..8de55fd701 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception cmake_minimum_required(VERSION 3.20.0 FATAL_ERROR) -project(unified-runtime VERSION 0.10.10) +project(unified-runtime VERSION 0.10.11) # Check if unified runtime is built as a standalone project. if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR UR_STANDALONE_BUILD)