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 <mats.petersson@arm.com>
Signed-off-by: Stuart Brady <stuart.brady@arm.com>
This commit is contained in:
Mats Petersson
2020-08-07 12:25:06 +01:00
committed by GitHub
parent c9f4ef23f6
commit ce484988ab

View File

@@ -28,6 +28,7 @@
#include <fstream>
#include <sstream>
#include <iomanip>
#include <mutex>
#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<std::mutex> compiler_lock(gCompilerMutex);
std::string filePrefix = get_unique_filename_prefix(numKernelLines,
kernelProgram,
buildOptions);