diff --git a/mace/core/file_storage.cc b/mace/core/file_storage.cc index 2d2b941af020273e9b6e42adca6595067cd00b57..99af2c1902089ed57238288f1b38cc15b2633d2a 100644 --- a/mace/core/file_storage.cc +++ b/mace/core/file_storage.cc @@ -121,13 +121,20 @@ int FileStorage::Load() { return 0; } +void FileStorage::Clear() { + utils::WriteLock lock(&data_mutex_); + data_.clear(); + data_changed_ = true; +} + bool FileStorage::Insert(const std::string &key, const std::vector &value) { utils::WriteLock lock(&data_mutex_); auto res = data_.emplace(key, value); - if (res.second) { - data_changed_ = true; + if (!res.second) { + data_[key] = value; } + data_changed_ = true; return true; } diff --git a/mace/core/file_storage.h b/mace/core/file_storage.h index 799719f3373d449b41a337dac754ea032ec80e4b..3b648c23379c0502d5272ee720d52d7ae792b9b2 100644 --- a/mace/core/file_storage.h +++ b/mace/core/file_storage.h @@ -30,6 +30,7 @@ class FileStorage : public KVStorage { public: int Load() override; + void Clear() override; bool Insert(const std::string &key, const std::vector &value) override; const std::vector *Find(const std::string &key) override; diff --git a/mace/core/runtime/opencl/opencl_runtime.cc b/mace/core/runtime/opencl/opencl_runtime.cc index 05e0825799b0b735ddafb23a30d8cfad1a68ec0f..c5809ffd0fde462260a8a52ef138957faca1c029 100644 --- a/mace/core/runtime/opencl/opencl_runtime.cc +++ b/mace/core/runtime/opencl/opencl_runtime.cc @@ -393,6 +393,7 @@ OpenCLRuntime::OpenCLRuntime(): MACE_CHECK_CL_SUCCESS(err); extern std::shared_ptr kStorageFactory; + std::string cached_binary_platform_info; if (kStorageFactory != nullptr) { cache_storage_ = kStorageFactory->CreateStorage(kPrecompiledProgramFileName); @@ -405,13 +406,16 @@ OpenCLRuntime::OpenCLRuntime(): auto platform_info_array = this->cache_storage_->Find(kOpenCLPlatformInfoKey); if (platform_info_array != nullptr) { - cached_binary_platform_info_ = + cached_binary_platform_info = std::string(platform_info_array->begin(), platform_info_array->end()); + if (cached_binary_platform_info != platform_info_) { + cache_storage_->Clear(); + } } } - if (cached_binary_platform_info_ != platform_info_) { + if (cached_binary_platform_info != platform_info_) { if (OpenCLRuntime::kPrecompiledBinaryPath.empty()) { LOG(WARNING) << "There is no precompiled OpenCL binary in" " all OpenCL binary paths"; @@ -476,11 +480,6 @@ bool OpenCLRuntime::BuildProgramFromCache( cl::Program *program) { // Find from binary if (this->cache_storage_ == nullptr) return false; - if (cached_binary_platform_info_ != platform_info_) { - VLOG(3) << "cached OpenCL binary version is not same" - " with current version"; - return false; - } auto content = this->cache_storage_->Find(built_program_key); if (content == nullptr) { return false; diff --git a/mace/core/runtime/opencl/opencl_runtime.h b/mace/core/runtime/opencl/opencl_runtime.h index 01a255d20c9dd93e4505b627b7b22400699087d5..f87b458053d0fa3c209a110d278c98e6ae4965fc 100644 --- a/mace/core/runtime/opencl/opencl_runtime.h +++ b/mace/core/runtime/opencl/opencl_runtime.h @@ -136,7 +136,6 @@ class OpenCLRuntime { std::string platform_info_; OpenCLVersion opencl_version_; std::string precompiled_binary_platform_info_; - std::string cached_binary_platform_info_; bool out_of_range_check_; uint64_t device_gloabl_mem_cache_size_; uint32_t device_compute_units_; diff --git a/mace/public/mace_runtime.h b/mace/public/mace_runtime.h index a6a628b6b66a179325d9f75a64fb1d121d6bc7c9..6fac6ec51ebc0eec1757f775749aab5fb7f57131 100644 --- a/mace/public/mace_runtime.h +++ b/mace/public/mace_runtime.h @@ -51,6 +51,7 @@ class KVStorage { public: // return: 0 for success, -1 for error virtual int Load() = 0; + virtual void Clear() = 0; virtual bool Insert(const std::string &key, const std::vector &value) = 0; virtual const std::vector *Find(const std::string &key) = 0;