I feel that a slightly safer way is to do

if (param_.has_device_id()) {
  Caffe::SetDevice(param_.device_id());
}

just in case a user has hard-coded a device id outside the solver and does not specify the device id in the solver param. Currently, if nothing is set, the solver will always use the 0th device, which might not be desired.