MCPcopy Create free account
hub / github.com/BVLC/caffe / InternalThreadEntry

Method InternalThreadEntry

src/caffe/parallel.cpp:270–318  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

268
269 protected:
270 void InternalThreadEntry() {
271 // Create solver and install callbacks
272 SolverParameter param(rank0_->param());
273 param.set_device_id(device_);
274#ifdef DEBUG
275 int device;
276 CUDA_CHECK(cudaGetDevice(&device));
277 CHECK_EQ(device, device_);
278#endif
279 param.set_type(rank0_->type());
280 shared_ptr<Solver<Dtype> > s(SolverRegistry<Dtype>::CreateSolver(param));
281 CHECK_EQ(s->type(), rank0_->type());
282 if (restore_) {
283 // Could not make NCCL broadcast solver state, it seems to crash
284 // if called in a tight loop, regardless of barriers etc. so
285 // restore all solvers from file.
286 s->Restore(restore_);
287 }
288 NCCL<Dtype> nccl(s);
289 nccl.set_barrier(barrier_);
290 s->add_callback(&nccl);
291 if (s->param().layer_wise_reduce()) {
292 s->net()->add_after_backward(&nccl);
293 }
294 (*nccls_)[Caffe::solver_rank()] = &nccl;
295 // Wait for other threads
296 barrier_->wait();
297 // Wait for NCCL init
298 barrier_->wait();
299 // Broadcast rank 0 state
300 nccl.Broadcast();
301 // Solve
302 s->Step(param.max_iter() - s->iter());
303 barrier_->wait();
304#ifdef DEBUG
305 // Check all solvers have same state
306 SGDSolver<Dtype>* sa = static_cast<SGDSolver<Dtype>*>(rank0_.get());
307 SGDSolver<Dtype>* sb = static_cast<SGDSolver<Dtype>*>(s.get());
308 for (int h = 0; h < sa->history().size(); ++h) {
309 CUDA_CHECK(cudaSetDevice(sa->param().device_id()));
310 const Dtype* a = sa->history()[h]->cpu_data();
311 CUDA_CHECK(cudaSetDevice(sb->param().device_id()));
312 const Dtype* b = sb->history()[h]->cpu_data();
313 for (int v = 0; v < sa->history()[h]->count(); ++v) {
314 CHECK_DOUBLE_EQ(a[v], b[v]);
315 }
316 }
317#endif
318 }
319
320 shared_ptr<Solver<Dtype> > rank0_;
321 int device_;

Callers

nothing calls this directly

Calls 13

RestoreMethod · 0.80
set_barrierMethod · 0.80
add_callbackMethod · 0.80
add_after_backwardMethod · 0.80
netMethod · 0.80
BroadcastMethod · 0.80
StepMethod · 0.80
iterMethod · 0.80
countMethod · 0.80
typeMethod · 0.45
getMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected