@@ -64,8 +64,6 @@ ParallelExecutor::ParallelExecutor(
64
64
const ExecutionStrategy &exec_strategy, const BuildStrategy &build_strategy,
65
65
size_t num_trainers, size_t trainer_id)
66
66
: member_(new ParallelExecutorPrivate(places)) {
67
- is_alive_.test_and_set ();
68
-
69
67
member_->global_scope_ = scope;
70
68
member_->use_cuda_ = exec_strategy.use_cuda_ ;
71
69
member_->use_all_reduce_ =
@@ -248,15 +246,6 @@ void ParallelExecutor::BCastParamsToDevices(
248
246
249
247
void ParallelExecutor::Run (const std::vector<std::string> &fetch_tensors,
250
248
const std::string &fetched_var_name) {
251
- // If ParallelExecutor has been destructed
252
- // just return
253
- if (!is_alive_.test_and_set ()) return ;
254
-
255
- // If ParallelExecutor is running
256
- if (is_running_.test_and_set ()) {
257
- PADDLE_THROW (" The previous ParallelExecutor::Run() has not stopped" );
258
- }
259
-
260
249
platform::RecordBlock b (0 );
261
250
#ifdef PADDLE_WITH_CUDA
262
251
if (!gcs_.empty ()) {
@@ -270,17 +259,9 @@ void ParallelExecutor::Run(const std::vector<std::string> &fetch_tensors,
270
259
}
271
260
}
272
261
#endif
273
- try {
274
- auto fetch_data = member_->executor_ ->Run (fetch_tensors);
275
- *member_->global_scope_ ->Var (fetched_var_name)
276
- ->GetMutable <FeedFetchList>() = fetch_data;
277
- is_running_.clear ();
278
- } catch (...) {
279
- is_running_.clear ();
280
- if (is_alive_.test_and_set ()) {
281
- std::rethrow_exception (std::current_exception ());
282
- }
283
- }
262
+ auto fetch_data = member_->executor_ ->Run (fetch_tensors);
263
+ *member_->global_scope_ ->Var (fetched_var_name)->GetMutable <FeedFetchList>() =
264
+ fetch_data;
284
265
}
285
266
286
267
void ParallelExecutor::FeedTensorsIntoLocalScopes (
@@ -318,7 +299,6 @@ void ParallelExecutor::FeedAndSplitTensorIntoLocalScopes(
318
299
}
319
300
320
301
ParallelExecutor::~ParallelExecutor () {
321
- is_alive_.clear ();
322
302
if (member_->own_local_scope_ ) {
323
303
for (size_t i = 1 ; i < member_->local_scopes_ .size (); ++i) {
324
304
Scope *local_scope = member_->local_scopes_ [i];
@@ -328,10 +308,8 @@ ParallelExecutor::~ParallelExecutor() {
328
308
}
329
309
}
330
310
331
- while (is_running_.test_and_set ()) {
332
- // wait unitl all threads have been stopped
333
- }
334
-
311
+ // member_ must be destructed before gcs_ since the destructor of
312
+ // ReferenceCountOpHandle use raw pointers of gcs_ inside.
335
313
member_.reset ();
336
314
}
337
315
0 commit comments