removed the net proto test that relies on external data
[platform/upstream/caffeonacl.git] / src / caffe / blob.hpp
1 // Copyright 2013 Yangqing Jia
2
3 #ifndef CAFFE_BLOB_HPP_
4 #define CAFFE_BLOB_HPP_
5
6 #include "caffe/common.hpp"
7 #include "caffe/syncedmem.hpp"
8 #include "caffe/proto/caffe.pb.h"
9
10 namespace caffe {
11
12 template <typename Dtype>
13 class Blob {
14  public:
15   Blob()
16        : num_(0), channels_(0), height_(0), width_(0), count_(0), data_(),
17        diff_() {}
18   explicit Blob(const int num, const int channels, const int height,
19     const int width);
20   virtual ~Blob() {}
21   void Reshape(const int num, const int height,
22       const int width, const int channels);
23   inline int num() const { return num_; }
24   inline int channels() const { return channels_; }
25   inline int height() const { return height_; }
26   inline int width() const { return width_; }
27   inline int count() const {return count_; }
28   inline int offset(const int n, const int c = 0, const int h = 0,
29       const int w = 0) const {
30     return ((n * channels_ + c) * height_ + h) * width_ + w;
31   }
32   // Copy from source. If copy_diff is false, we copy the data; if copy_diff
33   // is true, we copy the diff.
34   void CopyFrom(const Blob<Dtype>& source, bool copy_diff = false,
35       bool reshape = false);
36
37   inline Dtype data_at(const int n, const int c, const int h,
38       const int w) const {
39     return *(cpu_data() + offset(n, c, h, w));
40   }
41
42   inline Dtype diff_at(const int n, const int c, const int h,
43       const int w) const {
44     return *(cpu_diff() + offset(n, c, h, w));
45   }
46
47   const Dtype* cpu_data() const;
48   const Dtype* gpu_data() const;
49   const Dtype* cpu_diff() const;
50   const Dtype* gpu_diff() const;
51   Dtype* mutable_cpu_data();
52   Dtype* mutable_gpu_data();
53   Dtype* mutable_cpu_diff();
54   Dtype* mutable_gpu_diff();
55   void Update();
56   void FromProto(const BlobProto& proto);
57   void ToProto(BlobProto* proto, bool write_diff = false) const;
58
59  protected:
60   shared_ptr<SyncedMemory> data_;
61   shared_ptr<SyncedMemory> diff_;
62   int num_;
63   int channels_;
64   int height_;
65   int width_;
66   int count_;
67
68   DISABLE_COPY_AND_ASSIGN(Blob);
69 };  // class Blob
70
71 }  // namespace caffe
72
73 #endif  // CAFFE_BLOB_HPP_