提交 d9a58a5e 编写于 作者: L liuqi

Fix opencl cache update bug.

上级 b2a64047
......@@ -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<unsigned char> &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;
}
......
......@@ -30,6 +30,7 @@ class FileStorage : public KVStorage {
public:
int Load() override;
void Clear() override;
bool Insert(const std::string &key,
const std::vector<unsigned char> &value) override;
const std::vector<unsigned char> *Find(const std::string &key) override;
......
......@@ -393,6 +393,7 @@ OpenCLRuntime::OpenCLRuntime():
MACE_CHECK_CL_SUCCESS(err);
extern std::shared_ptr<KVStorageFactory> 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;
......
......@@ -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_;
......
......@@ -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<unsigned char> &value) = 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.
先完成此消息的编辑!
想要评论请 注册