Skip to content

Commit

Permalink
[SYCL] Don't copy string when tracing is not enabled (#16596)
Browse files Browse the repository at this point in the history
Currently we pass by value and always copy the path even if tracing is
not enabled which is expensive. Fix to pass by reference and do the
copy/modification only if tracing is enabled.
  • Loading branch information
againull authored Jan 13, 2025
1 parent eba4c68 commit 1a7e2f0
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions sycl/source/detail/persistent_device_code_cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,21 +208,23 @@ class PersistentDeviceCodeCache {
const ur_program_handle_t &NativePrg);

/* Sends message to std:cerr stream when SYCL_CACHE_TRACE environemnt is set*/
static void trace(const std::string &msg, std::string path = "") {
static void trace(const std::string &msg, const std::string &path = "") {
static const bool traceEnabled =
SYCLConfig<SYCL_CACHE_TRACE>::isTraceDiskCache();
if (traceEnabled) {
std::replace(path.begin(), path.end(), '\\', '/');
std::cerr << "[Persistent Cache]: " << msg << path << std::endl;
auto outputPath = path;
std::replace(outputPath.begin(), outputPath.end(), '\\', '/');
std::cerr << "[Persistent Cache]: " << msg << outputPath << std::endl;
}
}
static void trace_KernelCompiler(const std::string &msg,
std::string path = "") {
const std::string &path = "") {
static const bool traceEnabled =
SYCLConfig<SYCL_CACHE_TRACE>::isTraceKernelCompiler();
if (traceEnabled) {
std::replace(path.begin(), path.end(), '\\', '/');
std::cerr << "[kernel_compiler Persistent Cache]: " << msg << path
auto outputPath = path;
std::replace(outputPath.begin(), outputPath.end(), '\\', '/');
std::cerr << "[kernel_compiler Persistent Cache]: " << msg << outputPath
<< std::endl;
}
}
Expand Down

0 comments on commit 1a7e2f0

Please sign in to comment.