@@ -381,6 +381,7 @@ class kernel_bundle_impl {
381
381
kernel_bundle_impl (
382
382
context Ctx, std::vector<device> Devs,
383
383
const std::vector<kernel_id> &KernelIDs,
384
+ std::vector<std::string> &&KernelNames,
384
385
std::unordered_map<std::string, std::string> &&MangledKernelNames,
385
386
sycl_device_binaries Binaries, std::string &&Prefix,
386
387
syclex::source_language Lang)
@@ -393,6 +394,7 @@ class kernel_bundle_impl {
393
394
// loaded via the program manager have `kernel_id`s, they can't be looked up
394
395
// from the (unprefixed) kernel name.
395
396
MIsInterop = true ;
397
+ MKernelNames = std::move (KernelNames);
396
398
MMangledKernelNames = std::move (MangledKernelNames);
397
399
MDeviceBinaries = Binaries;
398
400
MPrefix = std::move (Prefix);
@@ -530,6 +532,7 @@ class kernel_bundle_impl {
530
532
PM.addImages (Binaries);
531
533
532
534
std::vector<kernel_id> KernelIDs;
535
+ std::vector<std::string> KernelNames;
533
536
std::unordered_map<std::string, std::string> MangledKernelNames;
534
537
// `jit_compiler::compileSYCL(..)` uses `CompilationID + '$'` as prefix
535
538
// for offload entry names.
@@ -539,18 +542,14 @@ class kernel_bundle_impl {
539
542
if (KernelName.find (Prefix) == 0 ) {
540
543
KernelIDs.push_back (KernelID);
541
544
KernelName.remove_prefix (Prefix.length ());
545
+ KernelNames.emplace_back (KernelName);
542
546
static constexpr std::string_view SYCLKernelMarker{" __sycl_kernel_" };
543
547
if (KernelName.find (SYCLKernelMarker) == 0 ) {
544
- // extern "C" declaration, register kernel without the marker.
548
+ // extern "C" declaration, implicitly register kernel without the
549
+ // marker.
545
550
std::string_view KernelNameWithoutMarker{KernelName};
546
551
KernelNameWithoutMarker.remove_prefix (SYCLKernelMarker.length ());
547
552
MangledKernelNames.emplace (KernelNameWithoutMarker, KernelName);
548
- } else {
549
- // The marker is baked into the mangling, and we cannot easily
550
- // adjust it. Register an identity mapping as an escape hatch.
551
- // Users shall use `registered_kernel_names` instead, as there's
552
- // practically no way to guess the mangled name.
553
- MangledKernelNames.emplace (KernelName, KernelName);
554
553
}
555
554
}
556
555
}
@@ -569,8 +568,9 @@ class kernel_bundle_impl {
569
568
}
570
569
571
570
return std::make_shared<kernel_bundle_impl>(
572
- MContext, MDevices, KernelIDs, std::move (MangledKernelNames),
573
- Binaries, std::move (Prefix), MLanguage);
571
+ MContext, MDevices, KernelIDs, std::move (KernelNames),
572
+ std::move (MangledKernelNames), Binaries, std::move (Prefix),
573
+ MLanguage);
574
574
}
575
575
576
576
ur_program_handle_t UrProgram = nullptr ;
@@ -676,48 +676,46 @@ class kernel_bundle_impl {
676
676
KernelNames, MLanguage);
677
677
}
678
678
679
- std::string adjust_kernel_name (const std::string &Name,
680
- syclex::source_language Lang) {
681
- // Once name demangling support is in, we won't need this.
682
- if (Lang != syclex::source_language::sycl &&
683
- Lang != syclex::source_language::sycl_jit)
684
- return Name;
679
+ std::string adjust_kernel_name (const std::string &Name) {
680
+ if (MLanguage == syclex::source_language::sycl_jit) {
681
+ auto It = MMangledKernelNames.find (Name);
682
+ return It == MMangledKernelNames.end () ? Name : It->second ;
683
+ }
684
+
685
+ if (MLanguage == syclex::source_language::sycl) {
686
+ bool isMangled = Name.find (" __sycl_kernel_" ) != std::string::npos;
687
+ return isMangled ? Name : " __sycl_kernel_" + Name;
688
+ }
689
+
690
+ return Name;
691
+ }
685
692
686
- bool isMangled = Name.find (" __sycl_kernel_" ) != std::string::npos;
687
- return isMangled ? Name : " __sycl_kernel_" + Name;
693
+ bool is_kernel_name (const std::string &Name) {
694
+ return std::find (MKernelNames.begin (), MKernelNames.end (), Name) !=
695
+ MKernelNames.end ();
688
696
}
689
697
690
698
bool ext_oneapi_has_kernel (const std::string &Name) {
691
- if (MLanguage == syclex::source_language::sycl_jit) {
692
- return MMangledKernelNames.count (Name);
693
- }
694
- auto it = std::find (MKernelNames.begin (), MKernelNames.end (),
695
- adjust_kernel_name (Name, MLanguage));
696
- return it != MKernelNames.end ();
699
+ return is_kernel_name (adjust_kernel_name (Name));
697
700
}
698
701
699
702
kernel
700
703
ext_oneapi_get_kernel (const std::string &Name,
701
704
const std::shared_ptr<kernel_bundle_impl> &Self) {
702
- if (MLanguage == syclex::source_language::sycl_jit) {
703
- if (MMangledKernelNames.empty ()) {
704
- throw sycl::exception (
705
- make_error_code (errc::invalid),
706
- " 'ext_oneapi_get_kernel' is only available in kernel_bundles "
707
- " successfully built from "
708
- " kernel_bundle<bundle_state::ext_oneapi_source>." );
709
- }
705
+ if (MKernelNames.empty ())
706
+ throw sycl::exception (make_error_code (errc::invalid),
707
+ " 'ext_oneapi_get_kernel' is only available in "
708
+ " kernel_bundles successfully built from "
709
+ " kernel_bundle<bundle_state::ext_oneapi_source>." );
710
710
711
- auto It = MMangledKernelNames.find (Name);
712
- if (It == MMangledKernelNames.end ()) {
713
- throw sycl::exception (make_error_code (errc::invalid),
714
- " kernel '" + Name +
715
- " ' not found in kernel_bundle" );
716
- }
711
+ std::string AdjustedName = adjust_kernel_name (Name);
712
+ if (!is_kernel_name (AdjustedName))
713
+ throw sycl::exception (make_error_code (errc::invalid),
714
+ " kernel '" + Name + " ' not found in kernel_bundle" );
717
715
718
- const std::string &MangledName = It-> second ;
716
+ if (MLanguage == syclex::source_language::sycl_jit) {
719
717
auto &PM = ProgramManager::getInstance ();
720
- auto KID = PM.getSYCLKernelID (MPrefix + MangledName );
718
+ auto KID = PM.getSYCLKernelID (MPrefix + AdjustedName );
721
719
722
720
for (const auto &DevImgWithDeps : MDeviceImages) {
723
721
const auto &DevImg = DevImgWithDeps.getMain ();
@@ -727,7 +725,7 @@ class kernel_bundle_impl {
727
725
const auto &DevImgImpl = getSyclObjImpl (DevImg);
728
726
auto UrProgram = DevImgImpl->get_ur_program_ref ();
729
727
auto [UrKernel, CacheMutex, ArgMask] =
730
- PM.getOrCreateKernel (MContext, MangledName ,
728
+ PM.getOrCreateKernel (MContext, AdjustedName ,
731
729
/* PropList=*/ {}, UrProgram);
732
730
auto KernelImpl = std::make_shared<kernel_impl>(
733
731
UrKernel, getSyclObjImpl (MContext), DevImgImpl, Self, ArgMask,
@@ -738,18 +736,6 @@ class kernel_bundle_impl {
738
736
assert (false && " Malformed RTC kernel bundle" );
739
737
}
740
738
741
- if (MKernelNames.empty ())
742
- throw sycl::exception (make_error_code (errc::invalid),
743
- " 'ext_oneapi_get_kernel' is only available in "
744
- " kernel_bundles successfully built from "
745
- " kernel_bundle<bundle_state:ext_oneapi_source>." );
746
-
747
- std::string AdjustedName = adjust_kernel_name (Name, MLanguage);
748
- if (!ext_oneapi_has_kernel (Name))
749
- throw sycl::exception (make_error_code (errc::invalid),
750
- " kernel '" + AdjustedName +
751
- " ' not found in kernel_bundle" );
752
-
753
739
assert (MDeviceImages.size () > 0 );
754
740
const std::shared_ptr<detail::device_image_impl> &DeviceImageImpl =
755
741
detail::getSyclObjImpl (MDeviceImages[0 ].getMain ());
0 commit comments