diff --git a/mace/core/file_storage.cc b/mace/core/file_storage.cc index 960cbf6120a3c1f523c15a62150693f538846b82..de9a67fa73a197d8bfe73ec27652fff2f0afd85f 100644 --- a/mace/core/file_storage.cc +++ b/mace/core/file_storage.cc @@ -49,25 +49,29 @@ std::unique_ptr FileStorageFactory::CreateStorage( FileStorage::FileStorage(const std::string &file_path): file_path_(file_path) {} -KVStorageStatus FileStorage::Load() { +int FileStorage::Load() { struct stat st; if (stat(file_path_.c_str(), &st) == -1) { if (errno == ENOENT) { - return KVStorageStatus::STORAGE_FILE_NOT_EXIST; + LOG(INFO) << "File " << file_path_ + << " does not exist"; + return 0; } else { - LOG(WARNING) << "stat file " << file_path_ + LOG(WARNING) << "Stat file " << file_path_ << " failed, error code: " << errno; - return KVStorageStatus::STORAGE_ERROR; + return -1; } } int fd = open(file_path_.c_str(), O_RDONLY); if (fd < 0) { if (errno == ENOENT) { - return KVStorageStatus::STORAGE_FILE_NOT_EXIST; + LOG(INFO) << "File " << file_path_ + << " does not exist"; + return 0; } else { LOG(WARNING) << "open file " << file_path_ << " failed, error code: " << errno; - return KVStorageStatus::STORAGE_ERROR; + return -1; } } size_t file_size = st.st_size; @@ -84,7 +88,7 @@ KVStorageStatus FileStorage::Load() { LOG(WARNING) << "close file " << file_path_ << " failed, error code: " << errno; } - return KVStorageStatus::STORAGE_ERROR; + return -1; } unsigned char *file_data_ptr = file_data; @@ -121,15 +125,15 @@ KVStorageStatus FileStorage::Load() { LOG(WARNING) << "close file " << file_path_ << " failed, error code: " << errno; } - return KVStorageStatus::STORAGE_ERROR; + return -1; } res = close(fd); if (res != 0) { LOG(WARNING) << "close file " << file_path_ << " failed, error code: " << errno; - return KVStorageStatus::STORAGE_ERROR; + return -1; } - return KVStorageStatus::STORAGE_SUCCESS; + return 0; } bool FileStorage::Insert(const std::string &key, @@ -145,12 +149,12 @@ const std::vector *FileStorage::Find(const std::string &key) { return &(iter->second); } -KVStorageStatus FileStorage::Flush() { +int FileStorage::Flush() { int fd = open(file_path_.c_str(), O_WRONLY | O_CREAT, 0600); if (fd < 0) { LOG(WARNING) << "open file " << file_path_ << " failed, error code:" << errno; - return KVStorageStatus::STORAGE_ERROR; + return -1; } const size_t int_size = sizeof(int32_t); @@ -194,7 +198,7 @@ KVStorageStatus FileStorage::Flush() { LOG(WARNING) << "close file " << file_path_ << " failed, error code: " << errno; } - return KVStorageStatus::STORAGE_ERROR; + return -1; } remain_size -= buffer_size; buffer_ptr += buffer_size; @@ -204,9 +208,9 @@ KVStorageStatus FileStorage::Flush() { if (res != 0) { LOG(WARNING) << "close file " << file_path_ << " failed, error code: " << errno; - return KVStorageStatus::STORAGE_ERROR; + return -1; } - return KVStorageStatus::STORAGE_SUCCESS; + return 0; } }; // namespace mace diff --git a/mace/core/file_storage.h b/mace/core/file_storage.h index 716cf336db31d705acf913c9c544a06953340f37..c29628cdd657d7a16d494128cfee908dfdc1f18f 100644 --- a/mace/core/file_storage.h +++ b/mace/core/file_storage.h @@ -18,11 +18,11 @@ class FileStorage : public KVStorage { explicit FileStorage(const std::string &file_path); public: - KVStorageStatus Load() override; + int Load() override; bool Insert(const std::string &key, const std::vector &value) override; const std::vector *Find(const std::string &key) override; - KVStorageStatus Flush() override; + int Flush() override; private: std::string file_path_; diff --git a/mace/core/runtime/opencl/opencl_runtime.cc b/mace/core/runtime/opencl/opencl_runtime.cc index 44be3e959ca265020789982fe4d5487011136978..43f51c69ae086eb29015f92b1f26d2bcc203573f 100644 --- a/mace/core/runtime/opencl/opencl_runtime.cc +++ b/mace/core/runtime/opencl/opencl_runtime.cc @@ -317,7 +317,7 @@ OpenCLRuntime::OpenCLRuntime(GPUPerfHint gpu_perf_hint, storage_ = kStorageFactory->CreateStorage(cl_compiled_file_name); if (platform_info_ != kCompiledProgramPlatform) { - if (storage_->Load() == KVStorageStatus::STORAGE_ERROR) { + if (storage_->Load() != 0) { LOG(FATAL) << "Load opencl compiled kernel file failed"; } } @@ -506,7 +506,7 @@ cl::Kernel OpenCLRuntime::BuildKernel( void OpenCLRuntime::SaveBuiltCLProgram() { if (program_map_changed_ && storage_ != nullptr) { - if (storage_->Flush() != KVStorageStatus::STORAGE_SUCCESS) { + if (storage_->Flush() != 0) { LOG(FATAL) << "Store opencl compiled kernel to file failed"; } program_map_changed_ = false; diff --git a/mace/public/mace_runtime.h b/mace/public/mace_runtime.h index 09de430cd77a877a1a30bd4f64303cbad5d7f4aa..8acb1cace385a876e97d62a2c2563c0bd13bd497 100644 --- a/mace/public/mace_runtime.h +++ b/mace/public/mace_runtime.h @@ -31,19 +31,15 @@ enum GPUPriorityHint { enum CPUPowerOption { DEFAULT = 0, HIGH_PERFORMANCE = 1, BATTERY_SAVE = 2 }; -enum KVStorageStatus { - STORAGE_SUCCESS = 0, - STORAGE_FILE_NOT_EXIST = 1, - STORAGE_ERROR = 2 -}; - class KVStorage { public: - virtual KVStorageStatus Load() = 0; + // return: 0 for success, -1 for error + virtual int Load() = 0; virtual bool Insert(const std::string &key, const std::vector &value) = 0; virtual const std::vector *Find(const std::string &key) = 0; - virtual KVStorageStatus Flush() = 0; + // return: 0 for success, -1 for error + virtual int Flush() = 0; }; class KVStorageFactory {