Skip to content

[SYCL] Fix hang in ProgramManager class #2274

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

Merged
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
5 changes: 2 additions & 3 deletions sycl/source/detail/program_manager/program_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ RT::PiProgram ProgramManager::createPIProgram(const RTDeviceBinaryImage &Img,
: createBinaryProgram(Ctx, RawImg.BinaryStart, ImgSize);

{
auto LockGuard = Ctx->getKernelProgramCache().acquireCachedPrograms();
std::lock_guard<std::mutex> Lock(MNativeProgramsMutex);
// associate the PI program with the image it was created for
NativePrograms[Res] = &Img;
}
Expand Down Expand Up @@ -982,8 +982,7 @@ void ProgramManager::flushSpecConstants(const program_impl &Prg,
if (!Img) {
// caller hasn't provided the image object - find it
{ // make sure NativePrograms map access is synchronized
ContextImplPtr Ctx = getSyclObjImpl(Prg.get_context());
auto LockGuard = Ctx->getKernelProgramCache().acquireCachedPrograms();
std::lock_guard<std::mutex> Lock(MNativeProgramsMutex);
auto It = NativePrograms.find(NativePrg);
if (It == NativePrograms.end())
throw sycl::experimental::spec_const_error(
Expand Down
4 changes: 3 additions & 1 deletion sycl/source/detail/program_manager/program_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,11 @@ class ProgramManager {
// NOTE: keys in the map can be invalid (reference count went to zero and
// the underlying program disposed of), so the map can't be used in any way
// other than binary image lookup with known live PiProgram as the key.
// NOTE: access is synchronized via the same lock as program cache
// NOTE: access is synchronized via the MNativeProgramsMutex
std::unordered_map<pi::PiProgram, const RTDeviceBinaryImage *> NativePrograms;

/// Protects NativePrograms that can be changed by class' methods.
std::mutex MNativeProgramsMutex;
/// True iff a SPIRV file has been specified with an environment variable
bool m_UseSpvFile = false;
};
Expand Down