diff --git a/sycl/include/sycl/detail/kernel_name_str_t.hpp b/sycl/include/sycl/detail/kernel_name_str_t.hpp index 77481d75eeef9..e0079ffb09c7e 100644 --- a/sycl/include/sycl/detail/kernel_name_str_t.hpp +++ b/sycl/include/sycl/detail/kernel_name_str_t.hpp @@ -5,6 +5,7 @@ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// +#pragma once #include #include @@ -23,6 +24,14 @@ using KernelNameStrRefT = const std::string &; using ABINeutralKernelNameStrT = detail::string; #endif +inline KernelNameStrT toKernelNameStrT(const ABINeutralKernelNameStrT &str) { +#ifdef __INTEL_PREVIEW_BREAKING_CHANGES + return std::string_view(str); +#else + return str.data(); +#endif +} + } // namespace detail } // namespace _V1 } // namespace sycl diff --git a/sycl/include/sycl/detail/string.hpp b/sycl/include/sycl/detail/string.hpp index 63cd9fb81a620..f2846069a93d6 100644 --- a/sycl/include/sycl/detail/string.hpp +++ b/sycl/include/sycl/detail/string.hpp @@ -16,7 +16,7 @@ namespace detail { // This class and detail::string_view class are intended to support // different ABIs between libsycl and the user program. -// This class is not inteded to replace std::string for general purpose usage. +// This class is not intended to replace std::string for general purpose usage. class string { char *str = nullptr; diff --git a/sycl/include/sycl/detail/string_view.hpp b/sycl/include/sycl/detail/string_view.hpp index 00770210fa4e9..6e3a55e753080 100644 --- a/sycl/include/sycl/detail/string_view.hpp +++ b/sycl/include/sycl/detail/string_view.hpp @@ -17,33 +17,80 @@ namespace detail { // This class and detail::string class are intended to support // different ABIs between libsycl and the user program. -// This class is not inteded to replace std::string_view for general purpose +// This class is not intended to replace std::string_view for general purpose // usage. + class string_view { const char *str = nullptr; +#ifdef __INTEL_PREVIEW_BREAKING_CHANGES + size_t len = 0; +#endif public: string_view() noexcept = default; string_view(const string_view &strn) noexcept = default; string_view(string_view &&strn) noexcept = default; - string_view(std::string_view strn) noexcept : str(strn.data()) {} - string_view(const sycl::detail::string &strn) noexcept : str(strn.c_str()) {} + string_view(std::string_view strn) noexcept + : str(strn.data()) +#ifdef __INTEL_PREVIEW_BREAKING_CHANGES + , + len(strn.size()) +#endif + { + } + string_view(const sycl::detail::string &strn) noexcept + : str(strn.c_str()) +#ifdef __INTEL_PREVIEW_BREAKING_CHANGES + , + len(strlen(strn.c_str())) +#endif + { + } string_view &operator=(string_view &&strn) noexcept = default; string_view &operator=(const string_view &strn) noexcept = default; string_view &operator=(std::string_view strn) noexcept { str = strn.data(); +#ifdef __INTEL_PREVIEW_BREAKING_CHANGES + len = strn.size(); +#endif return *this; } string_view &operator=(const sycl::detail::string &strn) noexcept { str = strn.c_str(); +#ifdef __INTEL_PREVIEW_BREAKING_CHANGES + len = strlen(strn.c_str()); +#endif return *this; } const char *data() const noexcept { return str ? str : ""; } + explicit operator std::string_view() const noexcept { +#ifdef __INTEL_PREVIEW_BREAKING_CHANGES + return std::string_view(str, len); +#else + return std::string_view(str); +#endif + } + +#ifdef __INTEL_PREVIEW_BREAKING_CHANGES + friend bool operator==(string_view lhs, std::string_view rhs) noexcept { + return rhs == std::string_view(lhs); + } + friend bool operator==(std::string_view lhs, string_view rhs) noexcept { + return lhs == std::string_view(rhs); + } + + friend bool operator!=(string_view lhs, std::string_view rhs) noexcept { + return rhs != std::string_view(lhs); + } + friend bool operator!=(std::string_view lhs, string_view rhs) noexcept { + return lhs != std::string_view(rhs); + } +#else friend bool operator==(string_view lhs, std::string_view rhs) noexcept { return rhs == lhs.data(); } @@ -57,6 +104,7 @@ class string_view { friend bool operator!=(std::string_view lhs, string_view rhs) noexcept { return lhs != rhs.data(); } +#endif }; } // namespace detail diff --git a/sycl/include/sycl/handler.hpp b/sycl/include/sycl/handler.hpp index 494b78a2326e8..180766f874661 100644 --- a/sycl/include/sycl/handler.hpp +++ b/sycl/include/sycl/handler.hpp @@ -537,11 +537,12 @@ class __SYCL_EXPORT handler { template bool lambdaAndKernelHaveEqualName() { // TODO It is unclear a kernel and a lambda/functor must to be equal or not // for parallel_for with sycl::kernel and lambda/functor together - // Now if they are equal we extract argumets from lambda/functor for the + // Now if they are equal we extract arguments from lambda/functor for the // kernel. Else it is necessary use set_atg(s) for resolve the order and // values of arguments for the kernel. assert(MKernel && "MKernel is not initialized"); - const std::string LambdaName = detail::getKernelName(); + constexpr std::string_view LambdaName = + detail::getKernelName(); detail::ABINeutralKernelNameStrT KernelName = getKernelName(); return KernelName == LambdaName; } @@ -865,7 +866,9 @@ class __SYCL_EXPORT handler { &(detail::getKernelParamDesc), detail::isKernelESIMD(), HasSpecialCapt); - MKernelName = detail::getKernelName(); + constexpr std::string_view KernelNameStr = + detail::getKernelName(); + MKernelName = KernelNameStr; } else { // In case w/o the integration header it is necessary to process // accessors from the list(which are associated with this handler) as @@ -1325,8 +1328,9 @@ class __SYCL_EXPORT handler { KernelWrapper::wrap(this, KernelFunc); #ifndef __SYCL_DEVICE_ONLY__ - verifyUsedKernelBundleInternal( - detail::string_view{detail::getKernelName()}); + constexpr std::string_view Name{detail::getKernelName()}; + + verifyUsedKernelBundleInternal(detail::string_view{Name}); processProperties(), PropertiesT>(Props); detail::checkValueRange(UserRange); setNDRangeDescriptor(std::move(UserRange)); diff --git a/sycl/source/backend/opencl.cpp b/sycl/source/backend/opencl.cpp index 196f02f03866a..c8d0f13d8ff3a 100644 --- a/sycl/source/backend/opencl.cpp +++ b/sycl/source/backend/opencl.cpp @@ -35,7 +35,7 @@ __SYCL_EXPORT bool has_extension(const sycl::platform &SyclPlatform, std::string ExtensionsString = urGetInfoString( *getSyclObjImpl(SyclPlatform), UR_PLATFORM_INFO_EXTENSIONS); - return ExtensionsString.find(std::string_view{Extension.data()}) != + return ExtensionsString.find(std::string_view{Extension}) != std::string::npos; } @@ -50,7 +50,7 @@ __SYCL_EXPORT bool has_extension(const sycl::device &SyclDevice, std::string ExtensionsString = urGetInfoString( *getSyclObjImpl(SyclDevice), UR_DEVICE_INFO_EXTENSIONS); - return ExtensionsString.find(std::string_view{Extension.data()}) != + return ExtensionsString.find(std::string_view{Extension}) != std::string::npos; } } // namespace detail diff --git a/sycl/source/detail/device_image_impl.hpp b/sycl/source/detail/device_image_impl.hpp index 2a0392df05ec9..dc7fc89f23cd9 100644 --- a/sycl/source/detail/device_image_impl.hpp +++ b/sycl/source/detail/device_image_impl.hpp @@ -853,7 +853,7 @@ class device_image_impl { extractXsFlags(const std::vector &BuildOptions) { std::stringstream SS; for (sycl::detail::string_view Option : BuildOptions) { - std::string_view OptionSV{Option.data()}; + std::string_view OptionSV{Option}; auto Where = OptionSV.find("-Xs"); if (Where != std::string_view::npos) { Where += 3; diff --git a/sycl/source/detail/graph_impl.cpp b/sycl/source/detail/graph_impl.cpp index 1a328507808b8..cac078f4e055e 100644 --- a/sycl/source/detail/graph_impl.cpp +++ b/sycl/source/detail/graph_impl.cpp @@ -1918,7 +1918,7 @@ void modifiable_command_graph::end_recording( void modifiable_command_graph::print_graph(sycl::detail::string_view pathstr, bool verbose) const { - std::string path{pathstr.data()}; + std::string path{std::string_view(pathstr)}; graph_impl::ReadLock Lock(impl->MMutex); if (path.substr(path.find_last_of(".") + 1) == "dot") { impl->printGraphAsDot(std::move(path), verbose); diff --git a/sycl/source/detail/helpers.cpp b/sycl/source/detail/helpers.cpp index 095eb6db55238..5568d28b56eb6 100644 --- a/sycl/source/detail/helpers.cpp +++ b/sycl/source/detail/helpers.cpp @@ -38,7 +38,7 @@ markBufferAsInternal(const std::shared_ptr &BufImpl) { } std::tuple -retrieveKernelBinary(queue_impl &Queue, const char *KernelName, +retrieveKernelBinary(queue_impl &Queue, KernelNameStrRefT KernelName, CGExecKernel *KernelCG) { device_impl &Dev = Queue.getDeviceImpl(); bool isNvidia = Dev.getBackend() == backend::ext_oneapi_cuda; diff --git a/sycl/source/detail/helpers.hpp b/sycl/source/detail/helpers.hpp index dd93ac60b39e5..1a2d1e49aaeb2 100644 --- a/sycl/source/detail/helpers.hpp +++ b/sycl/source/detail/helpers.hpp @@ -6,6 +6,8 @@ // //===----------------------------------------------------------------------===// +#include + #include #include @@ -27,7 +29,7 @@ void waitEvents(std::vector DepEvents); #endif std::tuple -retrieveKernelBinary(queue_impl &Queue, const char *KernelName, +retrieveKernelBinary(queue_impl &Queue, KernelNameStrRefT KernelName, CGExecKernel *CGKernel = nullptr); } // namespace detail } // namespace _V1 diff --git a/sycl/source/detail/scheduler/commands.cpp b/sycl/source/detail/scheduler/commands.cpp index 11c52f09849dd..c8db04e8e298b 100644 --- a/sycl/source/detail/scheduler/commands.cpp +++ b/sycl/source/detail/scheduler/commands.cpp @@ -3264,7 +3264,7 @@ ur_result_t ExecCGCommand::enqueueImpQueue() { const RTDeviceBinaryImage *BinImage = nullptr; if (detail::SYCLConfig::get()) { std::tie(BinImage, std::ignore) = - retrieveKernelBinary(*MQueue, KernelName.data()); + retrieveKernelBinary(*MQueue, KernelName); assert(BinImage && "Failed to obtain a binary image."); } enqueueImpKernel( diff --git a/sycl/source/device.cpp b/sycl/source/device.cpp index 7b9e3260983ad..255bde38ad75e 100644 --- a/sycl/source/device.cpp +++ b/sycl/source/device.cpp @@ -118,7 +118,7 @@ template __SYCL_EXPORT std::vector device::create_sub_devices< info::partition_property::ext_intel_partition_by_cslice>() const; bool device::has_extension(detail::string_view ext_name) const { - return impl->has_extension(ext_name.data()); + return impl->has_extension(std::string(std::string_view(ext_name))); } template @@ -292,7 +292,7 @@ bool device::ext_oneapi_supports_cl_c_feature(detail::string_view Feature) { return false; return ext::oneapi::experimental::detail::OpenCLC_Feature_Available( - Feature.data(), ipVersion); + std::string(std::string_view(Feature)), ipVersion); } bool device::ext_oneapi_supports_cl_c_version( @@ -321,7 +321,7 @@ bool device::ext_oneapi_supports_cl_extension( return false; return ext::oneapi::experimental::detail::OpenCLC_Supports_Extension( - Name.data(), VersionPtr, ipVersion); + std::string(std::string_view(Name)), VersionPtr, ipVersion); } detail::string device::ext_oneapi_cl_profile_impl() const { diff --git a/sycl/source/device_selector.cpp b/sycl/source/device_selector.cpp index 2a4e43230e206..40b3f40f95eb8 100644 --- a/sycl/source/device_selector.cpp +++ b/sycl/source/device_selector.cpp @@ -283,7 +283,8 @@ int accelerator_selector::operator()(const device &dev) const { namespace ext::oneapi { filter_selector::filter_selector(sycl::detail::string_view Input) - : impl(std::make_shared(Input.data())) {} + : impl(std::make_shared( + std::string(std::string_view(Input)))) {} int filter_selector::operator()(const device &Dev) const { return impl->operator()(Dev); diff --git a/sycl/source/handler.cpp b/sycl/source/handler.cpp index 2c52e52db4db8..59cbcb5384b8e 100644 --- a/sycl/source/handler.cpp +++ b/sycl/source/handler.cpp @@ -480,13 +480,13 @@ event handler::finalize() { !(MKernel && MKernel->isInterop()) && (KernelBundleImpPtr->empty() || KernelBundleImpPtr->hasSYCLOfflineImages()) && - !KernelBundleImpPtr->tryGetKernel(MKernelName.data(), + !KernelBundleImpPtr->tryGetKernel(toKernelNameStrT(MKernelName), KernelBundleImpPtr)) { auto Dev = impl->MGraph ? impl->MGraph->getDevice() : MQueue->get_device(); kernel_id KernelID = detail::ProgramManager::getInstance().getSYCLKernelID( - MKernelName.data()); + toKernelNameStrT(MKernelName)); bool KernelInserted = KernelBundleImpPtr->add_kernel(KernelID, Dev); // If kernel was not inserted and the bundle is in input mode we try // building it and trying to find the kernel in executable mode @@ -550,7 +550,7 @@ event handler::finalize() { bool KernelUsesAssert = !(MKernel && MKernel->isInterop()) && detail::ProgramManager::getInstance().kernelUsesAssert( - MKernelName.data(), impl->MKernelNameBasedCachePtr); + toKernelNameStrT(MKernelName), impl->MKernelNameBasedCachePtr); DiscardEvent = !KernelUsesAssert; } @@ -581,14 +581,15 @@ event handler::finalize() { #endif const detail::RTDeviceBinaryImage *BinImage = nullptr; if (detail::SYCLConfig::get()) { - std::tie(BinImage, std::ignore) = - detail::retrieveKernelBinary(*MQueue, MKernelName.data()); + std::tie(BinImage, std::ignore) = detail::retrieveKernelBinary( + *MQueue, toKernelNameStrT(MKernelName)); assert(BinImage && "Failed to obtain a binary image."); } enqueueImpKernel( MQueue, impl->MNDRDesc, impl->MArgs, KernelBundleImpPtr, - MKernel.get(), MKernelName.data(), impl->MKernelNameBasedCachePtr, - RawEvents, DiscardEvent ? nullptr : LastEventImpl.get(), nullptr, + MKernel.get(), toKernelNameStrT(MKernelName), + impl->MKernelNameBasedCachePtr, RawEvents, + DiscardEvent ? nullptr : LastEventImpl.get(), nullptr, impl->MKernelCacheConfig, impl->MKernelIsCooperative, impl->MKernelUsesClusterLaunch, impl->MKernelWorkGroupMemorySize, BinImage, impl->MKernelFuncPtr, impl->MKernelNumArgs, @@ -638,13 +639,15 @@ event handler::finalize() { std::unique_ptr CommandGroup; switch (type) { case detail::CGType::Kernel: { +#ifndef __INTEL_PREVIEW_BREAKING_CHANGES // Copy kernel name here instead of move so that it's available after // running of this method by reductions implementation. This allows for // assert feature to check if kernel uses assertions +#endif CommandGroup.reset(new detail::CGExecKernel( std::move(impl->MNDRDesc), std::move(MHostKernel), std::move(MKernel), std::move(impl->MKernelBundle), std::move(impl->CGData), - std::move(impl->MArgs), MKernelName.data(), + std::move(impl->MArgs), toKernelNameStrT(MKernelName), impl->MKernelNameBasedCachePtr, std::move(MStreamStorage), std::move(impl->MAuxiliaryResources), getType(), impl->MKernelCacheConfig, impl->MKernelIsCooperative, @@ -2093,7 +2096,7 @@ backend handler::getDeviceBackend() const { void handler::ext_intel_read_host_pipe(detail::string_view Name, void *Ptr, size_t Size, bool Block) { - impl->HostPipeName = Name.data(); + impl->HostPipeName = std::string_view(Name); impl->HostPipePtr = Ptr; impl->HostPipeTypeSize = Size; impl->HostPipeBlocking = Block; @@ -2103,7 +2106,7 @@ void handler::ext_intel_read_host_pipe(detail::string_view Name, void *Ptr, void handler::ext_intel_write_host_pipe(detail::string_view Name, void *Ptr, size_t Size, bool Block) { - impl->HostPipeName = Name.data(); + impl->HostPipeName = std::string_view(Name); impl->HostPipePtr = Ptr; impl->HostPipeTypeSize = Size; impl->HostPipeBlocking = Block; diff --git a/sycl/source/kernel_bundle.cpp b/sycl/source/kernel_bundle.cpp index 6c567b52081d2..ab12ff67e8590 100644 --- a/sycl/source/kernel_bundle.cpp +++ b/sycl/source/kernel_bundle.cpp @@ -131,31 +131,35 @@ bool kernel_bundle_plain::is_specialization_constant_set( } bool kernel_bundle_plain::ext_oneapi_has_kernel(detail::string_view name) { - return impl->ext_oneapi_has_kernel(name.data()); + return impl->ext_oneapi_has_kernel(std::string(std::string_view(name))); } kernel kernel_bundle_plain::ext_oneapi_get_kernel(detail::string_view name) { - return impl->ext_oneapi_get_kernel(name.data(), impl); + return impl->ext_oneapi_get_kernel(std::string(std::string_view(name)), impl); } detail::string kernel_bundle_plain::ext_oneapi_get_raw_kernel_name(detail::string_view name) { - return detail::string{impl->ext_oneapi_get_raw_kernel_name(name.data())}; + return detail::string{impl->ext_oneapi_get_raw_kernel_name( + std::string(std::string_view(name)))}; } bool kernel_bundle_plain::ext_oneapi_has_device_global( detail::string_view name) { - return impl->ext_oneapi_has_device_global(name.data()); + return impl->ext_oneapi_has_device_global( + std::string(std::string_view(name))); } void *kernel_bundle_plain::ext_oneapi_get_device_global_address( detail::string_view name, const device &dev) { - return impl->ext_oneapi_get_device_global_address(name.data(), dev); + return impl->ext_oneapi_get_device_global_address( + std::string(std::string_view(name)), dev); } size_t kernel_bundle_plain::ext_oneapi_get_device_global_size( detail::string_view name) { - return impl->ext_oneapi_get_device_global_size(name.data()); + return impl->ext_oneapi_get_device_global_size( + std::string(std::string_view(name))); } ////////////////////////////////// @@ -177,7 +181,14 @@ removeDuplicateDevices(const std::vector &Devs) { kernel_id get_kernel_id_impl(string_view KernelName) { return detail::ProgramManager::getInstance().getSYCLKernelID( - KernelName.data()); +#ifndef __INTEL_PREVIEW_BREAKING_CHANGES + std::string( +#endif + std::string_view(KernelName) +#ifndef __INTEL_PREVIEW_BREAKING_CHANGES + ) +#endif + ); } detail::KernelBundleImplPtr @@ -460,12 +471,13 @@ make_kernel_bundle_from_source(const context &SyclContext, // TODO: if we later support a "reason" why support isn't present // (like a missing shared library etc.) it'd be nice to include it in // the exception message here. - std::string Source{SourceView.data()}; + std::string Source{std::string_view(SourceView)}; include_pairs_t IncludePairs; size_t n = IncludePairViews.size(); IncludePairs.reserve(n); for (auto &p : IncludePairViews) - IncludePairs.push_back({p.first.data(), p.second.data()}); + IncludePairs.push_back({std::string{std::string_view(p.first)}, + std::string{std::string_view(p.second)}}); if (!is_source_kernel_bundle_supported(Language, SyclContext)) throw sycl::exception(make_error_code(errc::invalid), diff --git a/sycl/source/platform.cpp b/sycl/source/platform.cpp index 073460e8ea13f..4611184e94be0 100644 --- a/sycl/source/platform.cpp +++ b/sycl/source/platform.cpp @@ -43,7 +43,7 @@ platform::platform(const device_selector &dev_selector) { cl_platform_id platform::get() const { return impl->get(); } bool platform::has_extension(detail::string_view ExtName) const { - return impl->has_extension(ExtName.data()); + return impl->has_extension(std::string(std::string_view(ExtName))); } std::vector platform::get_devices(info::device_type DeviceType) const {