From f29d3bc3ac5be8d02afa848384352b3221afae66 Mon Sep 17 00:00:00 2001 From: Tao Sang Date: Thu, 1 Dec 2022 21:40:20 -0500 Subject: [PATCH] SWDEV-370659 - Add lock for HSAIL only Add lock for HSAIL only in order to fix test failures in math brute force and integer_ops tests. Change-Id: I5f14cdcaa4ee9867fdae63fff197a0f21ee5f1d4 --- rocclr/platform/program.cpp | 17 +++++++++++++++++ rocclr/platform/program.hpp | 13 +++++++++++++ 2 files changed, 30 insertions(+) diff --git a/rocclr/platform/program.cpp b/rocclr/platform/program.cpp index 05fd58d19e..c21b58451a 100644 --- a/rocclr/platform/program.cpp +++ b/rocclr/platform/program.cpp @@ -227,6 +227,10 @@ device::Program* Program::getDeviceProgram(const Device& device) const { return it->second; } +#if defined(WITH_COMPILER_LIB) +Monitor Program::buildLock_("OCL build program", true); +#endif + static bool adjustOptionsOnIgnoreEnv(std::string &cppstr) { // if there is a -ignore-env, adjust options. bool optionChangable = true; @@ -248,6 +252,9 @@ int32_t Program::compile(const std::vector& devices, size_t numHeaders, const char** headerIncludeNames, const char* options, void(CL_CALLBACK* notifyFptr)(cl_program, void*), void* data, bool optionChangable) { +#if defined(WITH_COMPILER_LIB) + ScopedLock sl(!amd::IS_HIP && useHsail(devices) ? &buildLock_ : nullptr); +#endif int32_t retval = CL_SUCCESS; // Clear the program object @@ -317,6 +324,9 @@ int32_t Program::link(const std::vector& devices, size_t numInputs, const std::vector& inputPrograms, const char* options, void(CL_CALLBACK* notifyFptr)(cl_program, void*), void* data, bool optionChangable) { +#if defined(WITH_COMPILER_LIB) + ScopedLock sl(!amd::IS_HIP && useHsail(devices) ? &buildLock_ : nullptr); +#endif int32_t retval = CL_SUCCESS; if (symbolTable_ == NULL) { @@ -484,6 +494,9 @@ void Program::StubProgramSource(const std::string& app_name) { int32_t Program::build(const std::vector& devices, const char* options, void(CL_CALLBACK* notifyFptr)(cl_program, void*), void* data, bool optionChangable, bool newDevProg) { +#if defined(WITH_COMPILER_LIB) + ScopedLock sl(!amd::IS_HIP && useHsail(devices) ? &buildLock_ : nullptr); +#endif int32_t retval = CL_SUCCESS; if (symbolTable_ == NULL) { @@ -590,6 +603,10 @@ int32_t Program::build(const std::vector& devices, const char* options, } bool Program::load(const std::vector& devices) { +#if defined(WITH_COMPILER_LIB) + ScopedLock sl(!amd::IS_HIP && useHsail(devices) ? &buildLock_ : nullptr); +#endif + for (const auto& it : devicePrograms_) { const Device& device = *(it.first); diff --git a/rocclr/platform/program.hpp b/rocclr/platform/program.hpp index ddd5ad7c1d..47f64886b7 100644 --- a/rocclr/platform/program.hpp +++ b/rocclr/platform/program.hpp @@ -126,6 +126,19 @@ class Program : public RuntimeObject { //! Clears the program object if the app attempts to rebuild the program void clear(); +#if defined(WITH_COMPILER_LIB) + //! Global HSAIL build lock (remove when HSAIL is thread-safe). + static Monitor buildLock_; + + //! Check if any device uses HSAIL + bool useHsail(const std::vector& devices) const { + for (const auto& it : devices) { + if (!it->settings().useLightning_) return true; + } + return false; + } +#endif + public: //! Construct a new program to be compiled from the given source code. Program(Context& context, const std::string& sourceCode, Language language,