diff --git a/paddle/fluid/framework/data_set.cc b/paddle/fluid/framework/data_set.cc index c511526c3159d6ddc3a7e78c22ded064fb2223f6..1b5db8380514d552ed56ae3c65a338a082f02bdc 100644 --- a/paddle/fluid/framework/data_set.cc +++ b/paddle/fluid/framework/data_set.cc @@ -463,6 +463,11 @@ void DatasetImpl::WaitPreLoadDone() { // release memory data template void DatasetImpl::ReleaseMemory() { + release_thread_ = new std::thread(&DatasetImpl::ReleaseMemoryFun, this); +} + +template +void DatasetImpl::ReleaseMemoryFun() { VLOG(3) << "DatasetImpl::ReleaseMemory() begin"; if (input_channel_) { input_channel_->Clear(); diff --git a/paddle/fluid/framework/data_set.h b/paddle/fluid/framework/data_set.h index b41f701548f3f17d80a8a3f5e3b3ac05c80786e7..58223a2f28b4f5951b270411a1266fefe3e5efcd 100644 --- a/paddle/fluid/framework/data_set.h +++ b/paddle/fluid/framework/data_set.h @@ -63,6 +63,7 @@ class Dataset { virtual void SetTrainerNum(int trainer_num) = 0; // set fleet send batch size virtual void SetFleetSendBatchSize(int64_t size) = 0; + virtual void ReleaseMemoryFun() = 0; // set fs name and ugi virtual void SetHdfsConfig(const std::string& fs_name, const std::string& fs_ugi) = 0; @@ -168,8 +169,13 @@ template class DatasetImpl : public Dataset { public: DatasetImpl(); - virtual ~DatasetImpl() {} + virtual ~DatasetImpl() { + if (release_thread_ != nullptr) { + release_thread_->join(); + } + } virtual void SetFileList(const std::vector& filelist); + virtual void ReleaseMemoryFun(); virtual void SetThreadNum(int thread_num); virtual void SetTrainerNum(int trainer_num); virtual void SetFleetSendBatchSize(int64_t size); @@ -295,6 +301,7 @@ class DatasetImpl : public Dataset { int64_t fleet_send_batch_size_; int64_t fleet_send_sleep_seconds_; std::vector preload_threads_; + std::thread* release_thread_ = nullptr; bool merge_by_insid_; bool parse_ins_id_; bool parse_content_;