@@ -152,9 +152,12 @@ class ManagedDeviceBinaries {
152
152
sycl_device_binaries MBinaries;
153
153
};
154
154
155
+ // Using ordered containers for heterogenous lookup.
156
+ // TODO change to unordered containers after switching to C++20.
155
157
using MangledKernelNameMapT = std::map<std::string, std::string, std::less<>>;
156
158
using 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<>>;
158
161
159
162
// Information unique to images compiled at runtime through the
160
163
// ext_oneapi_kernel_compiler extension.
@@ -619,32 +622,21 @@ class device_image_impl
619
622
#pragma warning(pop)
620
623
#endif
621
624
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
+ }
639
629
640
- return Name.data ();
630
+ std::string getAdjustedKernelNameStr (std::string_view Name) const {
631
+ return getAdjustedKernelNameImpl<std::string>(Name);
641
632
}
642
633
643
634
bool hasKernelName (std::string_view Name) const {
644
635
return (getOriginMask () &
645
636
(ImageOriginKernelCompiler | ImageOriginSYCLBIN)) &&
646
637
!Name.empty () &&
647
- MKernelNames.find (adjustKernelName (Name)) != MKernelNames.end ();
638
+ MKernelNames.find (getAdjustedKernelNameStr (Name)) !=
639
+ MKernelNames.end ();
648
640
}
649
641
650
642
std::shared_ptr<kernel_impl>
@@ -840,6 +832,37 @@ class device_image_impl
840
832
}
841
833
842
834
private:
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
+
843
866
bool hasRTDeviceBinaryImage () const noexcept {
844
867
return std::holds_alternative<const RTDeviceBinaryImage *>(MBinImage) &&
845
868
get_bin_image_ref () != nullptr ;
0 commit comments