From aec4f32464ebcbe76202fad15944c98143613482 Mon Sep 17 00:00:00 2001 From: Alexander Flegontov Date: Thu, 6 Aug 2020 10:54:35 +0300 Subject: [PATCH 1/4] [SYCL] Fix hang in ProgramManager class Signed-off-by: Alexander Flegontov --- sycl/source/detail/program_manager/program_manager.cpp | 4 ++-- sycl/source/detail/program_manager/program_manager.hpp | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/sycl/source/detail/program_manager/program_manager.cpp b/sycl/source/detail/program_manager/program_manager.cpp index a4d7f162c1ab6..a1639ea2a149a 100644 --- a/sycl/source/detail/program_manager/program_manager.cpp +++ b/sycl/source/detail/program_manager/program_manager.cpp @@ -330,7 +330,7 @@ RT::PiProgram ProgramManager::createPIProgram(const RTDeviceBinaryImage &Img, : createBinaryProgram(Ctx, RawImg.BinaryStart, ImgSize); { - auto LockGuard = Ctx->getKernelProgramCache().acquireCachedPrograms(); + std::lock_guard Lock(MMutex); // associate the PI program with the image it was created for NativePrograms[Res] = &Img; } @@ -983,7 +983,7 @@ void ProgramManager::flushSpecConstants(const program_impl &Prg, // 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 Lock(MMutex); auto It = NativePrograms.find(NativePrg); if (It == NativePrograms.end()) throw sycl::experimental::spec_const_error( diff --git a/sycl/source/detail/program_manager/program_manager.hpp b/sycl/source/detail/program_manager/program_manager.hpp index 9246d295cdc66..08ae70e2af9e2 100644 --- a/sycl/source/detail/program_manager/program_manager.hpp +++ b/sycl/source/detail/program_manager/program_manager.hpp @@ -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 MMutex std::unordered_map NativePrograms; + /// Protects NativePrograms that can be changed by class' methods. + mutex_class MMutex; /// True iff a SPIRV file has been specified with an environment variable bool m_UseSpvFile = false; }; From e2395a12eb195b2f9d6f0573c0acab9431fe1e9f Mon Sep 17 00:00:00 2001 From: Alexander Flegontov Date: Mon, 10 Aug 2020 12:29:07 +0300 Subject: [PATCH 2/4] [SYCL] Remove extra line Signed-off-by: Alexander Flegontov --- sycl/source/detail/program_manager/program_manager.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/sycl/source/detail/program_manager/program_manager.cpp b/sycl/source/detail/program_manager/program_manager.cpp index a1639ea2a149a..651b3fc71f80f 100644 --- a/sycl/source/detail/program_manager/program_manager.cpp +++ b/sycl/source/detail/program_manager/program_manager.cpp @@ -982,7 +982,6 @@ 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()); std::lock_guard Lock(MMutex); auto It = NativePrograms.find(NativePrg); if (It == NativePrograms.end()) From 94f422733cedbfc7a80362ea42a14d2dd8c8c534 Mon Sep 17 00:00:00 2001 From: Alexander Flegontov Date: Mon, 10 Aug 2020 14:25:47 +0300 Subject: [PATCH 3/4] [SYCL] Rename MMutex to MNativeProgramsMutex Signed-off-by: Alexander Flegontov --- sycl/source/detail/program_manager/program_manager.cpp | 4 ++-- sycl/source/detail/program_manager/program_manager.hpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sycl/source/detail/program_manager/program_manager.cpp b/sycl/source/detail/program_manager/program_manager.cpp index 651b3fc71f80f..260af8018abaa 100644 --- a/sycl/source/detail/program_manager/program_manager.cpp +++ b/sycl/source/detail/program_manager/program_manager.cpp @@ -330,7 +330,7 @@ RT::PiProgram ProgramManager::createPIProgram(const RTDeviceBinaryImage &Img, : createBinaryProgram(Ctx, RawImg.BinaryStart, ImgSize); { - std::lock_guard Lock(MMutex); + std::lock_guard Lock(MNativeProgramsMutex); // associate the PI program with the image it was created for NativePrograms[Res] = &Img; } @@ -982,7 +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 - std::lock_guard Lock(MMutex); + std::lock_guard Lock(MNativeProgramsMutex); auto It = NativePrograms.find(NativePrg); if (It == NativePrograms.end()) throw sycl::experimental::spec_const_error( diff --git a/sycl/source/detail/program_manager/program_manager.hpp b/sycl/source/detail/program_manager/program_manager.hpp index 08ae70e2af9e2..93f0c0526d8ae 100644 --- a/sycl/source/detail/program_manager/program_manager.hpp +++ b/sycl/source/detail/program_manager/program_manager.hpp @@ -181,11 +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 MMutex + // NOTE: access is synchronized via the MNativeProgramsMutex std::unordered_map NativePrograms; /// Protects NativePrograms that can be changed by class' methods. - mutex_class MMutex; + mutex_class MNativeProgramsMutex; /// True iff a SPIRV file has been specified with an environment variable bool m_UseSpvFile = false; }; From f19c973626e759eda0a16e682db3920fed74168e Mon Sep 17 00:00:00 2001 From: Alexander Flegontov Date: Mon, 10 Aug 2020 16:45:37 +0300 Subject: [PATCH 4/4] [SYCL] Change MNativeProgramsMutex's type to std::mutex for consistency Signed-off-by: Alexander Flegontov --- sycl/source/detail/program_manager/program_manager.cpp | 4 ++-- sycl/source/detail/program_manager/program_manager.hpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sycl/source/detail/program_manager/program_manager.cpp b/sycl/source/detail/program_manager/program_manager.cpp index 260af8018abaa..1af968f8ff075 100644 --- a/sycl/source/detail/program_manager/program_manager.cpp +++ b/sycl/source/detail/program_manager/program_manager.cpp @@ -330,7 +330,7 @@ RT::PiProgram ProgramManager::createPIProgram(const RTDeviceBinaryImage &Img, : createBinaryProgram(Ctx, RawImg.BinaryStart, ImgSize); { - std::lock_guard Lock(MNativeProgramsMutex); + std::lock_guard Lock(MNativeProgramsMutex); // associate the PI program with the image it was created for NativePrograms[Res] = &Img; } @@ -982,7 +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 - std::lock_guard Lock(MNativeProgramsMutex); + std::lock_guard Lock(MNativeProgramsMutex); auto It = NativePrograms.find(NativePrg); if (It == NativePrograms.end()) throw sycl::experimental::spec_const_error( diff --git a/sycl/source/detail/program_manager/program_manager.hpp b/sycl/source/detail/program_manager/program_manager.hpp index 93f0c0526d8ae..4a7b1045054bb 100644 --- a/sycl/source/detail/program_manager/program_manager.hpp +++ b/sycl/source/detail/program_manager/program_manager.hpp @@ -185,7 +185,7 @@ class ProgramManager { std::unordered_map NativePrograms; /// Protects NativePrograms that can be changed by class' methods. - mutex_class MNativeProgramsMutex; + std::mutex MNativeProgramsMutex; /// True iff a SPIRV file has been specified with an environment variable bool m_UseSpvFile = false; };