From f78395a1adcca74984e038ccbf705c7296fa89dd Mon Sep 17 00:00:00 2001 From: Sergei Vinogradov Date: Mon, 7 Apr 2025 22:34:50 +0200 Subject: [PATCH] Change `emitKernelInstrumentationData` to accept `string_view` instead of `string&` --- sycl/source/detail/scheduler/commands.cpp | 33 ++++++++++++----------- sycl/source/detail/scheduler/commands.hpp | 2 +- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/sycl/source/detail/scheduler/commands.cpp b/sycl/source/detail/scheduler/commands.cpp index b9ffdcc73ade3..0bfa89e3dfb80 100644 --- a/sycl/source/detail/scheduler/commands.cpp +++ b/sycl/source/detail/scheduler/commands.cpp @@ -136,13 +136,15 @@ struct DemangleHandle { ~DemangleHandle() { std::free(p); } }; -static std::string demangleKernelName(std::string Name) { +static std::string demangleKernelName(const std::string_view Name) { int Status = -1; // some arbitrary value to eliminate the compiler warning - DemangleHandle result(abi::__cxa_demangle(Name.c_str(), NULL, NULL, &Status)); - return (Status == 0) ? result.p : Name; + DemangleHandle result(abi::__cxa_demangle(Name.data(), NULL, NULL, &Status)); + return (Status == 0) ? result.p : std::string(Name); } #else -static std::string demangleKernelName(std::string Name) { return Name; } +static std::string demangleKernelName(const std::string_view Name) { + return std::string(Name); +} #endif static std::string accessModeToString(access::mode Mode) { @@ -1961,7 +1963,7 @@ ExecCGCommand::ExecCGCommand( #ifdef XPTI_ENABLE_INSTRUMENTATION std::string instrumentationGetKernelName( const std::shared_ptr &SyclKernel, - const std::string &FunctionName, const std::string &SyclKernelName, + const std::string_view FunctionName, const std::string_view SyclKernelName, void *&Address, std::optional &FromSource) { std::string KernelName; if (SyclKernel && SyclKernel->isCreatedFromSource()) { @@ -2049,17 +2051,17 @@ void instrumentationFillCommonData(const std::string &KernelName, xpti::payload_t Payload; if (!FileName.empty()) { // File name has a valid string - Payload = xpti::payload_t(FuncName.empty() ? KernelName.c_str() - : FuncName.c_str(), - FileName.c_str(), Line, Column, Address); + Payload = + xpti::payload_t(FuncName.empty() ? KernelName.data() : FuncName.data(), + FileName.data(), Line, Column, Address); HasSourceInfo = true; } else if (Address) { // We have a valid function name and an address - Payload = xpti::payload_t(KernelName.c_str(), Address); + Payload = xpti::payload_t(KernelName.data(), Address); } else { // In any case, we will have a valid function name and we'll use that to // create the hash - Payload = xpti::payload_t(KernelName.c_str()); + Payload = xpti::payload_t(KernelName.data()); } uint64_t CGKernelInstanceNo; @@ -2096,7 +2098,7 @@ void instrumentationFillCommonData(const std::string &KernelName, std::pair emitKernelInstrumentationData( int32_t StreamID, const std::shared_ptr &SyclKernel, const detail::code_location &CodeLoc, bool IsTopCodeLoc, - const std::string &SyclKernelName, const QueueImplPtr &Queue, + const std::string_view SyclKernelName, const QueueImplPtr &Queue, const NDRDescT &NDRDesc, const std::shared_ptr &KernelBundleImplPtr, std::vector &CGArgs) { @@ -2109,8 +2111,7 @@ std::pair emitKernelInstrumentationData( void *Address = nullptr; std::optional FromSource; std::string KernelName = instrumentationGetKernelName( - SyclKernel, std::string(CodeLoc.functionName()), SyclKernelName, Address, - FromSource); + SyclKernel, CodeLoc.functionName(), SyclKernelName, Address, FromSource); auto &[CmdTraceEvent, InstanceID] = XptiObjects; @@ -2135,9 +2136,9 @@ std::pair emitKernelInstrumentationData( if (Queue.get()) xpti::framework::stash_tuple(XPTI_QUEUE_INSTANCE_ID_KEY, getQueueID(Queue)); - instrumentationAddExtraKernelMetadata(CmdTraceEvent, NDRDesc, - KernelBundleImplPtr, SyclKernelName, - SyclKernel, Queue, CGArgs); + instrumentationAddExtraKernelMetadata( + CmdTraceEvent, NDRDesc, KernelBundleImplPtr, + std::string(SyclKernelName), SyclKernel, Queue, CGArgs); xptiNotifySubscribers( StreamID, NotificationTraceType, detail::GSYCLGraphEvent, CmdTraceEvent, diff --git a/sycl/source/detail/scheduler/commands.hpp b/sycl/source/detail/scheduler/commands.hpp index 12e605ac626d5..2ab553159f1dc 100644 --- a/sycl/source/detail/scheduler/commands.hpp +++ b/sycl/source/detail/scheduler/commands.hpp @@ -686,7 +686,7 @@ class ExecCGCommand : public Command { std::pair emitKernelInstrumentationData( int32_t StreamID, const std::shared_ptr &SyclKernel, const detail::code_location &CodeLoc, bool IsTopCodeLoc, - const std::string &SyclKernelName, const QueueImplPtr &Queue, + std::string_view SyclKernelName, const QueueImplPtr &Queue, const NDRDescT &NDRDesc, const std::shared_ptr &KernelBundleImplPtr, std::vector &CGArgs);