| 431 | |
| 432 | template <typename Dtype> |
| 433 | void Blob<Dtype>::CopyFrom(const Blob& source, bool copy_diff, bool reshape) { |
| 434 | if (source.count() != count_ || source.shape() != shape_) { |
| 435 | if (reshape) { |
| 436 | ReshapeLike(source); |
| 437 | } else { |
| 438 | LOG(FATAL) << "Trying to copy blobs of different sizes."; |
| 439 | } |
| 440 | } |
| 441 | switch (Caffe::mode()) { |
| 442 | case Caffe::GPU: |
| 443 | if (copy_diff) { |
| 444 | caffe_copy(count_, source.gpu_diff(), |
| 445 | static_cast<Dtype*>(diff_->mutable_gpu_data())); |
| 446 | } else { |
| 447 | caffe_copy(count_, source.gpu_data(), |
| 448 | static_cast<Dtype*>(data_->mutable_gpu_data())); |
| 449 | } |
| 450 | break; |
| 451 | case Caffe::CPU: |
| 452 | if (copy_diff) { |
| 453 | caffe_copy(count_, source.cpu_diff(), |
| 454 | static_cast<Dtype*>(diff_->mutable_cpu_data())); |
| 455 | } else { |
| 456 | caffe_copy(count_, source.cpu_data(), |
| 457 | static_cast<Dtype*>(data_->mutable_cpu_data())); |
| 458 | } |
| 459 | break; |
| 460 | default: |
| 461 | LOG(FATAL) << "Unknown caffe mode."; |
| 462 | } |
| 463 | } |
| 464 | |
| 465 | template <typename Dtype> |
| 466 | void Blob<Dtype>::FromProto(const BlobProto& proto, bool reshape) { |