Skip to content

Commit b78f7af

Browse files
committed
Cache found service kernels
Signed-off-by: Steffen Larsen <[email protected]>
1 parent 25411f5 commit b78f7af

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

sycl/source/detail/program_manager/program_manager.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,6 @@ ProgramManager &ProgramManager::getInstance() {
6464
return GlobalHandler::instance().getProgramManager();
6565
}
6666

67-
// This function allows for identifying "service" kernels. A SYCL service kernel
68-
// is a kernel that has not been defined by the user but is instead generated by
69-
// the SYCL runtime. Service kernel name types must be declared in the
70-
// sycl::detail::__sycl_service_kernel__ namespace which is exclusively used for
71-
// this purpose. As such service kernels can be identified by
72-
// __sycl_service_kernel__ appearing in the mangled kernel name.
73-
static bool isServiceKernel(const std::string &KernelName) {
74-
return KernelName.find("__sycl_service_kernel__") != std::string::npos;
75-
}
76-
7767
static RT::PiProgram
7868
createBinaryProgram(const ContextImplPtr Context, const device &Device,
7969
const unsigned char *Data, size_t DataLen,
@@ -1055,9 +1045,14 @@ void ProgramManager::addImages(pi_device_binaries DeviceBinary) {
10551045
(void)Result;
10561046
assert(Result.second && "Kernel sets are not disjoint");
10571047

1058-
// Skip creating unique kernel ID if it is a service kernel
1059-
if (isServiceKernel(EntriesIt->name))
1048+
// Skip creating unique kernel ID if it is a service kernel.
1049+
// SYCL service kernels are identified by having
1050+
// __sycl_service_kernel__ in the mangled name, primarily as part of
1051+
// the namespace of the name type.
1052+
if (std::strstr(EntriesIt->name, "__sycl_service_kernel__")) {
1053+
m_ServiceKernels.insert(EntriesIt->name);
10601054
continue;
1055+
}
10611056

10621057
// ... and create a unique kernel ID for the entry
10631058
std::shared_ptr<detail::kernel_id_impl> KernelIDImpl =
@@ -1351,7 +1346,8 @@ ProgramManager::getSYCLDeviceImagesWithCompatibleState(
13511346

13521347
if (KernelID == m_KernelIDs.end()) {
13531348
// Service kernels do not have kernel IDs
1354-
assert(isServiceKernel(EntriesIt->name) &&
1349+
assert(m_ServiceKernels.find(EntriesIt->name) !=
1350+
m_ServiceKernels.end() &&
13551351
"Kernel ID in device binary missing from cache");
13561352
continue;
13571353
}

sycl/source/detail/program_manager/program_manager.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <map>
2323
#include <memory>
2424
#include <unordered_map>
25+
#include <unordered_set>
2526
#include <vector>
2627

2728
// +++ Entry points referenced by the offload wrapper object {
@@ -284,6 +285,13 @@ class ProgramManager {
284285
/// \ref Sync::getGlobalLock() while holding this mutex.
285286
std::mutex m_KernelIDsMutex;
286287

288+
/// Caches all found service kernels to expedite future checks. A SYCL service
289+
/// kernel is a kernel that has not been defined by the user but is instead
290+
/// generated by the SYCL runtime. Service kernel name types must be declared
291+
/// in the sycl::detail::__sycl_service_kernel__ namespace which is
292+
/// exclusively used for this purpose.
293+
std::unordered_set<std::string> m_ServiceKernels;
294+
287295
// Keeps track of pi_program to image correspondence. Needed for:
288296
// - knowing which specialization constants are used in the program and
289297
// injecting their current values before compiling the SPIR-V; the binary

0 commit comments

Comments
 (0)