From 39b5abd9e00e8fadeb1d758857d911a92d24fc7c Mon Sep 17 00:00:00 2001 From: liuqi Date: Fri, 17 Nov 2017 11:34:27 +0800 Subject: [PATCH] Add lock at building program function. --- mace/core/net.cc | 2 -- mace/core/runtime/opencl/opencl_runtime.cc | 5 ++++- mace/core/runtime/opencl/opencl_runtime.h | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/mace/core/net.cc b/mace/core/net.cc index 2707ec51..f93089a1 100644 --- a/mace/core/net.cc +++ b/mace/core/net.cc @@ -48,8 +48,6 @@ bool SimpleNet::Run(RunMetadata *run_metadata) { LOG(ERROR) << "Operator failed: " << ProtoDebugString(op->debug_def()); return false; } - if (device_type_ == DeviceType::OPENCL) - OpenCLRuntime::Get()->command_queue().finish(); if (op_stats) { op_stats->set_op_end_rel_micros(NowInMicroSec() - op_stats->all_start_micros()); diff --git a/mace/core/runtime/opencl/opencl_runtime.cc b/mace/core/runtime/opencl/opencl_runtime.cc index 32a7bcc2..8bc2ecc1 100644 --- a/mace/core/runtime/opencl/opencl_runtime.cc +++ b/mace/core/runtime/opencl/opencl_runtime.cc @@ -104,9 +104,11 @@ cl::Device &OpenCLRuntime::device() { return device_; } cl::CommandQueue &OpenCLRuntime::command_queue() { return command_queue_; } cl::Program &OpenCLRuntime::program() { - // TODO(heliangliang) Support binary format + // TODO(liuqi) : useless, leave it for old code. return program_; } + +// TODO(heliangliang) Support binary format const std::map OpenCLRuntime::program_map_ = { {"addn", "addn.cl"}, @@ -162,6 +164,7 @@ cl::Kernel OpenCLRuntime::BuildKernel(const std::string &program_name, } std::string built_program_key = program_name + build_options_str; + std::lock_guard lock(program_build_mutex_); auto built_program_it = built_program_map_.find(built_program_key); cl::Program program; if (built_program_it != built_program_map_.end()) { diff --git a/mace/core/runtime/opencl/opencl_runtime.h b/mace/core/runtime/opencl/opencl_runtime.h index cd62ca8d..b4bda7d6 100644 --- a/mace/core/runtime/opencl/opencl_runtime.h +++ b/mace/core/runtime/opencl/opencl_runtime.h @@ -45,6 +45,7 @@ class OpenCLRuntime { cl::Device device_; cl::CommandQueue command_queue_; cl::Program program_; + std::mutex program_build_mutex_; std::string kernel_path_; static const std::map program_map_; -- GitLab