From ce484988abaeede3112ff0683ce2835184f7fed9 Mon Sep 17 00:00:00 2001 From: Mats Petersson <6831237+Leporacanthicus@users.noreply.github.com> Date: Fri, 7 Aug 2020 12:25:06 +0100 Subject: [PATCH] Add lock around compiling (#871) The compiler tries to compile the same source multiple times and more importantly write out to the same filename. Adding a lock to prevent simultaneous compilation solves this issue. This is particularly noticeable in integer_ops testing when using offline compilation, but just in case, hold the lock for the entire program creation. Signed-off-by: Mats Petersson Signed-off-by: Stuart Brady --- test_common/harness/kernelHelpers.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test_common/harness/kernelHelpers.cpp b/test_common/harness/kernelHelpers.cpp index bfe7f3aa..194de05c 100644 --- a/test_common/harness/kernelHelpers.cpp +++ b/test_common/harness/kernelHelpers.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #if defined(_WIN32) std::string slash = "\\"; @@ -35,6 +36,8 @@ std::string slash = "\\"; std::string slash = "/"; #endif +static std::mutex gCompilerMutex; + static cl_int get_first_device_id(const cl_context context, cl_device_id &device); long get_file_size(const std::string &fileName) @@ -717,6 +720,8 @@ static int create_single_kernel_helper_create_program(cl_context context, const bool openclCXX, CompilationMode compilationMode) { + std::lock_guard compiler_lock(gCompilerMutex); + std::string filePrefix = get_unique_filename_prefix(numKernelLines, kernelProgram, buildOptions);