7ac1c9d719ee7a07c0c0012479dfe7a60a1605f7
1 #include "caffeine/blob.hpp"
2 #include "caffeine/common.hpp"
3 #include "caffeine/syncedmem.hpp"
5 namespace caffeine {
7 template <typename Dtype>
8 void Blob<Dtype>::Reshape(const int num, const int channels, const int height,
9 const int width) {
10 num_ = num;
11 channels_ = channels;
12 height_ = height;
13 width_ = width;
14 count_ = num_ * channels_ * height_ * width_;
15 data_.reset(SyncedMemory(count_ * sizeof(Dtype)));
16 diff_.reset(SyncedMemory(count_ * sizeof(Dtype)));
17 }
19 template <typename Dtype>
20 const Dtype* Blob<Dtype>::cpu_data() {
21 check_data();
22 return data_->cpu_data();
23 }
25 template <typename Dtype>
26 const Dtype* Blob<Dtype>::gpu_data() {
27 check_data();
28 return data_->gpu_data();
29 }
31 template <typename Dtype>
32 const Dtype* Blob<Dtype>::cpu_diff() {
33 check_diff();
34 return diff_->cpu_data();
35 }
37 template <typename Dtype>
38 const Dtype* Blob<Dtype>::gpu_diff() {
39 check_diff();
40 return diff_->gpu_data();
41 }
43 template <typename Dtype>
44 Dtype* Blob<Dtype>::mutable_cpu_data() {
45 check_data();
46 return data_->mutable_cpu_data();
47 }
49 template <typename Dtype>
50 Dtype* Blob<Dtype>::mutable_gpu_data() {
51 check_data();
52 return data_->mutable_gpu_data();
53 }
55 template <typename Dtype>
56 Dtype* Blob<Dtype>::mutable_cpu_diff() {
57 check_diff();
58 return diff_->mutable_cpu_data();
59 }
61 template <typename Dtype>
62 Dtype* Blob<Dtype>::mutable_gpu_diff() {
63 check_diff();
64 return diff_->mutable_gpu_data();
65 }
67 } // namespace caffeine