Skip to content

Commit 0dca88f

Browse files
committed
[SYCL] Use per-kernel mutex for all cases when the kernel is cacheable.
Signed-off-by: Alexander Flegontov <[email protected]>
1 parent fcb4e6c commit 0dca88f

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

sycl/source/detail/program_impl.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,9 @@ class program_impl {
318318
/// Tells whether a specialization constant has been set for this program.
319319
bool hasSetSpecConstants() const { return !SpecConstRegistry.empty(); }
320320

321+
/// \return true if caching is allowed for this program.
322+
bool is_cacheable() const { return MProgramAndKernelCachingAllowed; }
323+
321324
private:
322325
// Deligating Constructor used in Implementation.
323326
program_impl(ContextImplPtr Context, pi_native_handle InteropProgram,
@@ -368,9 +371,6 @@ class program_impl {
368371
/// \return a vector of devices managed by the plugin.
369372
vector_class<RT::PiDevice> get_pi_devices() const;
370373

371-
/// \return true if caching is allowed for this program.
372-
bool is_cacheable() const { return MProgramAndKernelCachingAllowed; }
373-
374374
/// \param Options is a string containing OpenCL C build options.
375375
/// \return true if caching is allowed for this program and build options.
376376
static bool is_cacheable_with_options(const string_class &Options) {

sycl/source/detail/scheduler/commands.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1804,6 +1804,18 @@ cl_int ExecCGCommand::enqueueImp() {
18041804
assert(ExecKernel->MSyclKernel->get_info<info::kernel::context>() ==
18051805
Context);
18061806
Kernel = ExecKernel->MSyclKernel->getHandleRef();
1807+
1808+
auto SyclProg = detail::getSyclObjImpl(
1809+
ExecKernel->MSyclKernel->get_info<info::kernel::program>());
1810+
if (SyclProg->is_cacheable()) {
1811+
RT::PiKernel FoundKernel = nullptr;
1812+
std::tie(FoundKernel, KernelMutex) =
1813+
detail::ProgramManager::getInstance().getOrCreateKernel(
1814+
ExecKernel->MOSModuleHandle,
1815+
ExecKernel->MSyclKernel->get_info<info::kernel::context>(),
1816+
ExecKernel->MKernelName, SyclProg.get());
1817+
assert(FoundKernel == Kernel);
1818+
}
18071819
} else {
18081820
std::tie(Kernel, KernelMutex) =
18091821
detail::ProgramManager::getInstance().getOrCreateKernel(
@@ -1873,6 +1885,7 @@ cl_int ExecCGCommand::enqueueImp() {
18731885

18741886
pi_result Error = PI_SUCCESS;
18751887
if (KernelMutex != nullptr) {
1888+
// For cacheable kernels, we use per-kernel mutex
18761889
std::lock_guard<std::mutex> Lock(*KernelMutex);
18771890
Error = SetKernelParamsAndLaunch();
18781891
} else {

0 commit comments

Comments
 (0)