Skip to content

Commit 1219972

Browse files
[SYCL] Remove build options from fast kernel cache key (#16101)
Build options were removed from Kernel cache key in #11351 to reduce the kernel lookup overhead. This PR removes build options from fast kernel cache key as well. Quoting #11351 > This can be done because they are either empty or set by the environment variable so they stay the same for the entire program lifecycle for the purposes of in-memory caching.
1 parent 69572a2 commit 1219972

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

sycl/source/detail/kernel_program_cache.hpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,19 @@ class KernelProgramCache {
163163
::boost::unordered_map<ur_program_handle_t, KernelByNameT>;
164164

165165
using KernelFastCacheKeyT =
166-
std::tuple<SerializedObj, ur_device_handle_t, std::string, std::string>;
166+
std::tuple<SerializedObj, /* Serialized spec constants. */
167+
ur_device_handle_t, /* UR device handle pointer */
168+
std::string /* Kernel Name */
169+
>;
170+
167171
using KernelFastCacheValT =
168-
std::tuple<ur_kernel_handle_t, std::mutex *, const KernelArgMask *,
169-
ur_program_handle_t>;
172+
std::tuple<ur_kernel_handle_t, /* UR kernel handle pointer. */
173+
std::mutex *, /* Mutex guarding this kernel. */
174+
const KernelArgMask *, /* Eliminated kernel argument mask. */
175+
ur_program_handle_t /* UR program handle corresponding to this
176+
kernel. */
177+
>;
178+
170179
// This container is used as a fast path for retrieving cached kernels.
171180
// unordered_flat_map is used here to reduce lookup overhead.
172181
// The slow path is used only once for each newly created kernel, so the
@@ -283,7 +292,7 @@ class KernelProgramCache {
283292
std::unique_lock<std::mutex> Lock(MKernelFastCacheMutex);
284293
auto It = MKernelFastCache.find(CacheKey);
285294
if (It != MKernelFastCache.end()) {
286-
traceKernel("Kernel fetched.", std::get<3>(CacheKey), true);
295+
traceKernel("Kernel fetched.", std::get<2>(CacheKey), true);
287296
return It->second;
288297
}
289298
return std::make_tuple(nullptr, nullptr, nullptr, nullptr);
@@ -294,7 +303,7 @@ class KernelProgramCache {
294303
std::unique_lock<std::mutex> Lock(MKernelFastCacheMutex);
295304
// if no insertion took place, thus some other thread has already inserted
296305
// smth in the cache
297-
traceKernel("Kernel inserted.", std::get<3>(CacheKey), true);
306+
traceKernel("Kernel inserted.", std::get<2>(CacheKey), true);
298307
MKernelFastCache.emplace(CacheKey, CacheVal);
299308
}
300309

sycl/source/detail/program_manager/program_manager.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -969,17 +969,11 @@ ProgramManager::getOrCreateKernel(const ContextImplPtr &ContextImpl,
969969
using KernelArgMaskPairT = KernelProgramCache::KernelArgMaskPairT;
970970

971971
KernelProgramCache &Cache = ContextImpl->getKernelProgramCache();
972-
973-
std::string CompileOpts, LinkOpts;
974972
SerializedObj SpecConsts;
975-
applyOptionsFromEnvironment(CompileOpts, LinkOpts);
976-
// Should always come last!
977-
appendCompileEnvironmentVariablesThatAppend(CompileOpts);
978-
appendLinkEnvironmentVariablesThatAppend(LinkOpts);
973+
979974
ur_device_handle_t UrDevice = DeviceImpl->getHandleRef();
980975

981-
auto key = std::make_tuple(std::move(SpecConsts), UrDevice,
982-
CompileOpts + LinkOpts, KernelName);
976+
auto key = std::make_tuple(std::move(SpecConsts), UrDevice, KernelName);
983977
if (SYCLConfig<SYCL_CACHE_IN_MEM>::get()) {
984978
auto ret_tuple = Cache.tryToGetKernelFast(key);
985979
constexpr size_t Kernel = 0; // see KernelFastCacheValT tuple

0 commit comments

Comments
 (0)