Skip to content

Commit

Permalink
Merge pull request BVLC#521 from sguada/set_device_id_at_init
Browse files Browse the repository at this point in the history
Set device_id at the beginning of Solver.Init()
  • Loading branch information
sergeyk committed Jun 20, 2014
2 parents 1726257 + 29f593c commit b1e1e23
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/caffe/solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ void Solver<Dtype>::Init(const SolverParameter& param) {
LOG(INFO) << "Initializing solver from parameters: " << std::endl
<< param.DebugString();
param_ = param;
if (param_.solver_mode() == SolverParameter_SolverMode_GPU &&
param_.has_device_id()) {
Caffe::SetDevice(param_.device_id());
}
Caffe::set_mode(Caffe::Brew(param_.solver_mode()));
if (param_.random_seed() >= 0) {
Caffe::set_random_seed(param_.random_seed());
}
Expand Down Expand Up @@ -74,14 +79,8 @@ void Solver<Dtype>::Init(const SolverParameter& param) {
LOG(INFO) << "Solver scaffolding done.";
}


template <typename Dtype>
void Solver<Dtype>::Solve(const char* resume_file) {
Caffe::set_mode(Caffe::Brew(param_.solver_mode()));
if (param_.solver_mode() == SolverParameter_SolverMode_GPU &&
param_.has_device_id()) {
Caffe::SetDevice(param_.device_id());
}
Caffe::set_phase(Caffe::TRAIN);
LOG(INFO) << "Solving " << net_->name();
PreSolve();
Expand Down

0 comments on commit b1e1e23

Please sign in to comment.