提交 d9a58a5e 编写于 作者: L liuqi

Fix opencl cache update bug.

上级 b2a64047
...@@ -121,13 +121,20 @@ int FileStorage::Load() { ...@@ -121,13 +121,20 @@ int FileStorage::Load() {
return 0; return 0;
} }
void FileStorage::Clear() {
utils::WriteLock lock(&data_mutex_);
data_.clear();
data_changed_ = true;
}
bool FileStorage::Insert(const std::string &key, bool FileStorage::Insert(const std::string &key,
const std::vector<unsigned char> &value) { const std::vector<unsigned char> &value) {
utils::WriteLock lock(&data_mutex_); utils::WriteLock lock(&data_mutex_);
auto res = data_.emplace(key, value); auto res = data_.emplace(key, value);
if (res.second) { if (!res.second) {
data_changed_ = true; data_[key] = value;
} }
data_changed_ = true;
return true; return true;
} }
......
...@@ -30,6 +30,7 @@ class FileStorage : public KVStorage { ...@@ -30,6 +30,7 @@ class FileStorage : public KVStorage {
public: public:
int Load() override; int Load() override;
void Clear() override;
bool Insert(const std::string &key, bool Insert(const std::string &key,
const std::vector<unsigned char> &value) override; const std::vector<unsigned char> &value) override;
const std::vector<unsigned char> *Find(const std::string &key) override; const std::vector<unsigned char> *Find(const std::string &key) override;
......
...@@ -393,6 +393,7 @@ OpenCLRuntime::OpenCLRuntime(): ...@@ -393,6 +393,7 @@ OpenCLRuntime::OpenCLRuntime():
MACE_CHECK_CL_SUCCESS(err); MACE_CHECK_CL_SUCCESS(err);
extern std::shared_ptr<KVStorageFactory> kStorageFactory; extern std::shared_ptr<KVStorageFactory> kStorageFactory;
std::string cached_binary_platform_info;
if (kStorageFactory != nullptr) { if (kStorageFactory != nullptr) {
cache_storage_ = cache_storage_ =
kStorageFactory->CreateStorage(kPrecompiledProgramFileName); kStorageFactory->CreateStorage(kPrecompiledProgramFileName);
...@@ -405,13 +406,16 @@ OpenCLRuntime::OpenCLRuntime(): ...@@ -405,13 +406,16 @@ OpenCLRuntime::OpenCLRuntime():
auto platform_info_array = auto platform_info_array =
this->cache_storage_->Find(kOpenCLPlatformInfoKey); this->cache_storage_->Find(kOpenCLPlatformInfoKey);
if (platform_info_array != nullptr) { if (platform_info_array != nullptr) {
cached_binary_platform_info_ = cached_binary_platform_info =
std::string(platform_info_array->begin(), std::string(platform_info_array->begin(),
platform_info_array->end()); 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()) { if (OpenCLRuntime::kPrecompiledBinaryPath.empty()) {
LOG(WARNING) << "There is no precompiled OpenCL binary in" LOG(WARNING) << "There is no precompiled OpenCL binary in"
" all OpenCL binary paths"; " all OpenCL binary paths";
...@@ -476,11 +480,6 @@ bool OpenCLRuntime::BuildProgramFromCache( ...@@ -476,11 +480,6 @@ bool OpenCLRuntime::BuildProgramFromCache(
cl::Program *program) { cl::Program *program) {
// Find from binary // Find from binary
if (this->cache_storage_ == nullptr) return false; 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); auto content = this->cache_storage_->Find(built_program_key);
if (content == nullptr) { if (content == nullptr) {
return false; return false;
......
...@@ -136,7 +136,6 @@ class OpenCLRuntime { ...@@ -136,7 +136,6 @@ class OpenCLRuntime {
std::string platform_info_; std::string platform_info_;
OpenCLVersion opencl_version_; OpenCLVersion opencl_version_;
std::string precompiled_binary_platform_info_; std::string precompiled_binary_platform_info_;
std::string cached_binary_platform_info_;
bool out_of_range_check_; bool out_of_range_check_;
uint64_t device_gloabl_mem_cache_size_; uint64_t device_gloabl_mem_cache_size_;
uint32_t device_compute_units_; uint32_t device_compute_units_;
......
...@@ -51,6 +51,7 @@ class KVStorage { ...@@ -51,6 +51,7 @@ class KVStorage {
public: public:
// return: 0 for success, -1 for error // return: 0 for success, -1 for error
virtual int Load() = 0; virtual int Load() = 0;
virtual void Clear() = 0;
virtual bool Insert(const std::string &key, virtual bool Insert(const std::string &key,
const std::vector<unsigned char> &value) = 0; const std::vector<unsigned char> &value) = 0;
virtual const std::vector<unsigned char> *Find(const std::string &key) = 0; virtual const std::vector<unsigned char> *Find(const std::string &key) = 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册