@@ -152,9 +152,12 @@ class ManagedDeviceBinaries {
152152 sycl_device_binaries MBinaries;
153153};
154154
155+ // Using ordered containers for heterogenous lookup.
156+ // TODO change to unordered containers after switching to C++20.
155157using MangledKernelNameMapT = std::map<std::string, std::string, std::less<>>;
156158using KernelNameSetT = std::set<std::string, std::less<>>;
157- using KernelNameToArgMaskMap = std::unordered_map<std::string, KernelArgMask>;
159+ using KernelNameToArgMaskMap =
160+ std::map<std::string, KernelArgMask, std::less<>>;
158161
159162// Information unique to images compiled at runtime through the
160163// ext_oneapi_kernel_compiler extension.
@@ -619,32 +622,21 @@ class device_image_impl
619622#pragma warning(pop)
620623#endif
621624
622- std::string adjustKernelName (std::string_view Name) const {
623- if (MOrigins & ImageOriginSYCLBIN) {
624- constexpr std::string_view KernelPrefix = " __sycl_kernel_" ;
625- if (Name.size () > KernelPrefix.size () &&
626- Name.substr (0 , KernelPrefix.size ()) == KernelPrefix)
627- return Name.data ();
628- return std::string{KernelPrefix} + Name.data ();
629- }
630-
631- if (!MRTCBinInfo.has_value ())
632- return Name.data ();
633-
634- if (MRTCBinInfo->MLanguage == syclex::source_language::sycl) {
635- auto It = MRTCBinInfo->MMangledKernelNames .find (Name);
636- if (It != MRTCBinInfo->MMangledKernelNames .end ())
637- return It->second ;
638- }
625+ // Assumes the kernel is contained within this image.
626+ std::string_view getAdjustedKernelNameStrView (std::string_view Name) const {
627+ return getAdjustedKernelNameImpl<std::string_view>(Name);
628+ }
639629
640- return Name.data ();
630+ std::string getAdjustedKernelNameStr (std::string_view Name) const {
631+ return getAdjustedKernelNameImpl<std::string>(Name);
641632 }
642633
643634 bool hasKernelName (std::string_view Name) const {
644635 return (getOriginMask () &
645636 (ImageOriginKernelCompiler | ImageOriginSYCLBIN)) &&
646637 !Name.empty () &&
647- MKernelNames.find (adjustKernelName (Name)) != MKernelNames.end ();
638+ MKernelNames.find (getAdjustedKernelNameStr (Name)) !=
639+ MKernelNames.end ();
648640 }
649641
650642 std::shared_ptr<kernel_impl>
@@ -840,6 +832,37 @@ class device_image_impl
840832 }
841833
842834private:
835+ template <typename RetT>
836+ RetT getAdjustedKernelNameImpl (std::string_view Name) const {
837+ if (MOrigins & ImageOriginSYCLBIN) {
838+ constexpr std::string_view KernelPrefix = " __sycl_kernel_" ;
839+ if (Name.size () > KernelPrefix.size () &&
840+ Name.substr (0 , KernelPrefix.size ()) == KernelPrefix)
841+ return RetT (Name);
842+ std::string AdjustedNameStr =
843+ std::string (KernelPrefix) + std::string (Name);
844+ if constexpr (std::is_same_v<RetT, std::string>) {
845+ return AdjustedNameStr;
846+ } else {
847+ static_assert (std::is_same_v<RetT, std::string_view>);
848+ auto It = MKernelNames.find (AdjustedNameStr);
849+ assert (It != MKernelNames.end () && " Adjusted name not found" );
850+ return *It;
851+ }
852+ }
853+
854+ if (!MRTCBinInfo.has_value ())
855+ return RetT (Name);
856+
857+ if (MRTCBinInfo->MLanguage == syclex::source_language::sycl) {
858+ auto It = MRTCBinInfo->MMangledKernelNames .find (Name);
859+ if (It != MRTCBinInfo->MMangledKernelNames .end ())
860+ return It->second ;
861+ }
862+
863+ return RetT (Name);
864+ }
865+
843866 bool hasRTDeviceBinaryImage () const noexcept {
844867 return std::holds_alternative<const RTDeviceBinaryImage *>(MBinImage) &&
845868 get_bin_image_ref () != nullptr ;
0 commit comments