From 29f593c6b6db63c9e2a04da8023a81f0eb5e7a48 Mon Sep 17 00:00:00 2001 From: Sergio Date: Thu, 19 Jun 2014 12:55:48 -0700 Subject: [PATCH] Set device_id at the begining of Solver.Init() to avoid using memory in the default GPU --- src/caffe/solver.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/caffe/solver.cpp b/src/caffe/solver.cpp index 6a8f18f1331..769618175ac 100644 --- a/src/caffe/solver.cpp +++ b/src/caffe/solver.cpp @@ -36,6 +36,11 @@ void Solver::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()); } @@ -74,14 +79,8 @@ void Solver::Init(const SolverParameter& param) { LOG(INFO) << "Solver scaffolding done."; } - template void Solver::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();