| 413 | |
| 414 | template <typename Dtype> |
| 415 | void Blob<Dtype>::CopyFrom(const Blob& source, bool copy_diff, bool reshape) { |
| 416 | if (source.count() != count_ || source.shape() != shape_) { |
| 417 | if (reshape) { |
| 418 | ReshapeLike(source); |
| 419 | } else { |
| 420 | LOG(FATAL) << "Trying to copy blobs of different sizes."; |
| 421 | } |
| 422 | } |
| 423 | switch (Caffe::mode()) { |
| 424 | case Caffe::GPU: |
| 425 | if (copy_diff) { |
| 426 | caffe_copy(count_, source.gpu_diff(), |
| 427 | static_cast<Dtype*>(diff_->mutable_gpu_data())); |
| 428 | } else { |
| 429 | caffe_copy(count_, source.gpu_data(), |
| 430 | static_cast<Dtype*>(data_->mutable_gpu_data())); |
| 431 | } |
| 432 | break; |
| 433 | case Caffe::CPU: |
| 434 | if (copy_diff) { |
| 435 | caffe_copy(count_, source.cpu_diff(), |
| 436 | static_cast<Dtype*>(diff_->mutable_cpu_data())); |
| 437 | } else { |
| 438 | caffe_copy(count_, source.cpu_data(), |
| 439 | static_cast<Dtype*>(data_->mutable_cpu_data())); |
| 440 | } |
| 441 | break; |
| 442 | default: |
| 443 | LOG(FATAL) << "Unknown caffe mode."; |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | template <typename Dtype> |
| 448 | void Blob<Dtype>::FromProto(const BlobProto& proto, bool reshape) { |