提交 08d9caa0 编写于 作者: L liuqi

Remove unuseful code for mt opencl runtime.

上级 67f9c391
...@@ -57,7 +57,7 @@ std::unique_ptr<KVStorage> FileStorageFactory::CreateStorage( ...@@ -57,7 +57,7 @@ std::unique_ptr<KVStorage> FileStorageFactory::CreateStorage(
} }
FileStorage::FileStorage(const std::string &file_path): FileStorage::FileStorage(const std::string &file_path):
file_path_(file_path) {} data_changed_(false), file_path_(file_path) {}
int FileStorage::Load() { int FileStorage::Load() {
struct stat st; struct stat st;
...@@ -151,6 +151,7 @@ bool FileStorage::Insert(const std::string &key, ...@@ -151,6 +151,7 @@ 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_);
data_.emplace(key, value); data_.emplace(key, value);
data_changed_ = true;
return true; return true;
} }
...@@ -164,6 +165,7 @@ const std::vector<unsigned char> *FileStorage::Find(const std::string &key) { ...@@ -164,6 +165,7 @@ const std::vector<unsigned char> *FileStorage::Find(const std::string &key) {
int FileStorage::Flush() { int FileStorage::Flush() {
utils::WriteLock lock(&data_mutex_); utils::WriteLock lock(&data_mutex_);
if (!data_changed_) return 0;
int fd = open(file_path_.c_str(), O_WRONLY | O_CREAT, 0600); int fd = open(file_path_.c_str(), O_WRONLY | O_CREAT, 0600);
if (fd < 0) { if (fd < 0) {
LOG(WARNING) << "open file " << file_path_ LOG(WARNING) << "open file " << file_path_
...@@ -224,6 +226,7 @@ int FileStorage::Flush() { ...@@ -224,6 +226,7 @@ int FileStorage::Flush() {
<< " failed, error code: " << errno; << " failed, error code: " << errno;
return -1; return -1;
} }
data_changed_ = false;
return 0; return 0;
} }
......
...@@ -36,6 +36,7 @@ class FileStorage : public KVStorage { ...@@ -36,6 +36,7 @@ class FileStorage : public KVStorage {
int Flush() override; int Flush() override;
private: private:
bool data_changed_;
std::string file_path_; std::string file_path_;
std::map<std::string, std::vector<unsigned char>> data_; std::map<std::string, std::vector<unsigned char>> data_;
utils::RWMutex data_mutex_; utils::RWMutex data_mutex_;
......
...@@ -348,8 +348,6 @@ OpenCLRuntime::OpenCLRuntime(): ...@@ -348,8 +348,6 @@ OpenCLRuntime::OpenCLRuntime():
&err); &err);
MACE_CHECK_CL_SUCCESS(err); MACE_CHECK_CL_SUCCESS(err);
this->program_map_changed_ = false;
extern std::shared_ptr<KVStorageFactory> kStorageFactory; extern std::shared_ptr<KVStorageFactory> kStorageFactory;
if (kStorageFactory != nullptr) { if (kStorageFactory != nullptr) {
const std::string cl_compiled_file_name = "mace_cl_compiled_program.bin"; const std::string cl_compiled_file_name = "mace_cl_compiled_program.bin";
...@@ -512,8 +510,6 @@ void OpenCLRuntime::BuildProgramFromSource( ...@@ -512,8 +510,6 @@ void OpenCLRuntime::BuildProgramFromSource(
if (this->storage_ != nullptr) { if (this->storage_ != nullptr) {
this->storage_->Insert(built_program_key, content); this->storage_->Insert(built_program_key, content);
std::lock_guard<std::mutex> lock(program_map_changed_mutex_);
this->program_map_changed_ = true;
} }
VLOG(3) << "Program from source: " << built_program_key; VLOG(3) << "Program from source: " << built_program_key;
...@@ -567,13 +563,9 @@ cl::Kernel OpenCLRuntime::BuildKernel( ...@@ -567,13 +563,9 @@ cl::Kernel OpenCLRuntime::BuildKernel(
void OpenCLRuntime::SaveBuiltCLProgram() { void OpenCLRuntime::SaveBuiltCLProgram() {
if (storage_ != nullptr) { if (storage_ != nullptr) {
std::lock_guard<std::mutex> lock(program_map_changed_mutex_); if (storage_->Flush() != 0) {
if (program_map_changed_) { LOG(FATAL) << "Store OPENCL compiled kernel to file failed."
if (storage_->Flush() != 0) { " Please Make sure the storage directory exist.";
LOG(FATAL) << "Store OPENCL compiled kernel to file failed."
" Please Make sure the storage directory exist.";
}
program_map_changed_ = false;
} }
} }
} }
......
...@@ -125,11 +125,9 @@ class OpenCLRuntime { ...@@ -125,11 +125,9 @@ class OpenCLRuntime {
std::shared_ptr<cl::CommandQueue> command_queue_; std::shared_ptr<cl::CommandQueue> command_queue_;
std::map<std::string, cl::Program> built_program_map_; std::map<std::string, cl::Program> built_program_map_;
std::mutex program_build_mutex_; std::mutex program_build_mutex_;
std::mutex program_map_changed_mutex_;
std::string platform_info_; std::string platform_info_;
std::string opencl_version_; std::string opencl_version_;
bool out_of_range_check_; bool out_of_range_check_;
bool program_map_changed_;
uint64_t device_gloabl_mem_cache_size_; uint64_t device_gloabl_mem_cache_size_;
uint32_t device_compute_units_; uint32_t device_compute_units_;
GPUType gpu_type_; GPUType gpu_type_;
......
...@@ -43,29 +43,22 @@ class RWMutex { ...@@ -43,29 +43,22 @@ class RWMutex {
class ReadLock { class ReadLock {
public: public:
explicit ReadLock(RWMutex *rw_mutex): rw_mutex_(rw_mutex) { explicit ReadLock(RWMutex *rw_mutex): rw_mutex_(rw_mutex) {
if (rw_mutex_ == nullptr) { MACE_CHECK_NOTNULL(rw_mutex);
return;
}
std::unique_lock<std::mutex> lock(rw_mutex->mutex_); std::unique_lock<std::mutex> lock(rw_mutex->mutex_);
rw_mutex->waiting_readers_++; rw_mutex->waiting_readers_ += 1;
rw_mutex->reader_cv_.wait(lock, [&]() -> bool { rw_mutex->reader_cv_.wait(lock, [&]() -> bool {
return rw_mutex->waiting_writers_ == 0 && rw_mutex->counter_ >= 0; return rw_mutex->waiting_writers_ == 0 && rw_mutex->counter_ >= 0;
}); });
rw_mutex->waiting_readers_--; rw_mutex->waiting_readers_ -= 1;
rw_mutex->counter_++; rw_mutex->counter_ += 1;
} }
~ReadLock() { ~ReadLock() {
if (rw_mutex_ == nullptr) {
return;
}
std::unique_lock<std::mutex> lock(rw_mutex_->mutex_); std::unique_lock<std::mutex> lock(rw_mutex_->mutex_);
rw_mutex_->counter_ -= 1; rw_mutex_->counter_ -= 1;
if (rw_mutex_->waiting_writers_ > 0) { if (rw_mutex_->waiting_writers_ > 0) {
if (rw_mutex_->counter_ == 0) { if (rw_mutex_->counter_ == 0) {
rw_mutex_->writer_cv_.notify_one(); rw_mutex_->writer_cv_.notify_one();
} }
} else {
rw_mutex_->reader_cv_.notify_all();
} }
} }
ReadLock(const ReadLock &) = delete; ReadLock(const ReadLock &) = delete;
...@@ -80,21 +73,16 @@ class ReadLock { ...@@ -80,21 +73,16 @@ class ReadLock {
class WriteLock { class WriteLock {
public: public:
explicit WriteLock(RWMutex *rw_mutex): rw_mutex_(rw_mutex) { explicit WriteLock(RWMutex *rw_mutex): rw_mutex_(rw_mutex) {
if (rw_mutex_ == nullptr) { MACE_CHECK_NOTNULL(rw_mutex);
return;
}
std::unique_lock<std::mutex> lock(rw_mutex->mutex_); std::unique_lock<std::mutex> lock(rw_mutex->mutex_);
rw_mutex->waiting_writers_++; rw_mutex->waiting_writers_ += 1;
rw_mutex->writer_cv_.wait(lock, [&]() -> bool { rw_mutex->writer_cv_.wait(lock, [&]() -> bool {
return rw_mutex->counter_ == 0; return rw_mutex->counter_ == 0;
}); });
rw_mutex->waiting_writers_--; rw_mutex->waiting_writers_ -= 1;
rw_mutex->counter_--; rw_mutex->counter_ -= 1;
} }
~WriteLock() { ~WriteLock() {
if (rw_mutex_ == nullptr) {
return;
}
std::unique_lock<std::mutex> lock(rw_mutex_->mutex_); std::unique_lock<std::mutex> lock(rw_mutex_->mutex_);
rw_mutex_->counter_ = 0; rw_mutex_->counter_ = 0;
if (rw_mutex_->waiting_writers_ > 0) { if (rw_mutex_->waiting_writers_ > 0) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册