Skip to content

[SYCL] Cache kernel assert usage #18538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: sycl
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sycl/source/detail/kernel_name_based_cache_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <sycl/detail/ur.hpp>

#include <mutex>
#include <optional>

#include <boost/unordered/unordered_flat_map.hpp>

Expand All @@ -36,6 +37,7 @@ struct FastKernelSubcacheT {

struct KernelNameBasedCacheT {
FastKernelSubcacheT FastKernelSubcache;
std::optional<bool> UsesAssert;
};

} // namespace detail
Expand Down
13 changes: 11 additions & 2 deletions sycl/source/detail/program_manager/program_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <detail/device_global_map_entry.hpp>
#include <detail/host_pipe_map_entry.hpp>
#include <detail/kernel_arg_mask.hpp>
#include <detail/kernel_name_based_cache_t.hpp>
#include <detail/spec_constant_impl.hpp>
#include <sycl/detail/cg_types.hpp>
#include <sycl/detail/common.hpp>
Expand Down Expand Up @@ -359,8 +360,16 @@ class ProgramManager {
~ProgramManager() = default;

template <typename NameT>
bool kernelUsesAssert(const NameT &KernelName) const {
return m_KernelUsesAssert.find(KernelName) != m_KernelUsesAssert.end();
bool kernelUsesAssert(const NameT &KernelName,
KernelNameBasedCacheT *KernelNameBasedCachePtr) const {
if (!KernelNameBasedCachePtr)
return m_KernelUsesAssert.find(KernelName) != m_KernelUsesAssert.end();
Comment on lines +365 to +366
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What conditions could lead to us having a kernel name but no cache associated with it?

Copy link
Contributor Author

@sergey-semenov sergey-semenov May 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An application that hasn't been recompiled since the cache was added to the headers.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, wow, okay.

Would it make sense to mark this as #ifndef __INTEL_PREVIEW_BREAKING_CHANGES? My thinking is:

  • An application must recompile to use the preview library, and will need to recompile after the ABI break;
  • In the case where somebody has recompiled, we can skip a branch; and
  • Decorating this with the #ifdef will make sure it gets taken out at the next ABI break.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I think it makes sense. Since this is also applicable to the UR kernel cache logic introduced by the original cache PR, I'd rather apply this to both in a separate PR.


std::optional<bool> &UsesAssert = KernelNameBasedCachePtr->UsesAssert;
if (!UsesAssert.has_value())
UsesAssert =
m_KernelUsesAssert.find(KernelName) != m_KernelUsesAssert.end();
return UsesAssert.value();
}

SanitizerType kernelUsesSanitizer() const { return m_SanitizerFoundInImage; }
Expand Down
3 changes: 2 additions & 1 deletion sycl/source/detail/queue_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,8 @@ class queue_impl {
KernelUsesAssert =
(!Handler.MKernel || Handler.MKernel->hasSYCLMetadata()) &&
ProgramManager::getInstance().kernelUsesAssert(
Handler.MKernelName.data());
Handler.MKernelName.data(),
Handler.impl->MKernelNameBasedCachePtr);

auto &PostProcess = *PostProcessorFunc;
PostProcess(IsKernel, KernelUsesAssert, Event);
Expand Down
3 changes: 2 additions & 1 deletion sycl/source/detail/scheduler/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3269,7 +3269,8 @@ ur_result_t ExecCGCommand::enqueueImpQueue() {
// Kernel only uses assert if it's non interop one
bool KernelUsesAssert =
(!SyclKernel || SyclKernel->hasSYCLMetadata()) &&
ProgramManager::getInstance().kernelUsesAssert(KernelName);
ProgramManager::getInstance().kernelUsesAssert(
KernelName, ExecKernel->MKernelNameBasedCachePtr);
if (KernelUsesAssert) {
EventImpl = MEvent.get();
}
Expand Down
2 changes: 1 addition & 1 deletion sycl/source/handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ event handler::finalize() {
bool KernelUsesAssert =
!(MKernel && MKernel->isInterop()) &&
detail::ProgramManager::getInstance().kernelUsesAssert(
MKernelName.data());
MKernelName.data(), impl->MKernelNameBasedCachePtr);
DiscardEvent = !KernelUsesAssert;
}

Expand Down
Loading