change Adopt -> Share as suggested by kloudkl
authorJeff Donahue <jeff.donahue@gmail.com>
Sat, 12 Apr 2014 07:52:15 +0000 (00:52 -0700)
committerJeff Donahue <jeff.donahue@gmail.com>
Sat, 12 Apr 2014 07:52:15 +0000 (00:52 -0700)
include/caffe/blob.hpp
src/caffe/blob.cpp
src/caffe/layers/flatten_layer.cpp
src/caffe/layers/flatten_layer.cu
src/caffe/layers/split_layer.cpp
src/caffe/layers/split_layer.cu

index 7b8989b..712fc05 100644 (file)
@@ -73,8 +73,13 @@ class Blob {
   void FromProto(const BlobProto& proto);
   void ToProto(BlobProto* proto, bool write_diff = false) const;
 
-  void AdoptData(const Blob& other);
-  void AdoptDiff(const Blob& other);
+  // Set the data_/diff_ shared_ptr to point to the SyncedMemory holding the
+  // data_/diff_ of Blob other -- useful in layers which simply perform a copy
+  // in their forward or backward pass.
+  // This deallocates the SyncedMemory holding this blob's data/diff, as
+  // shared_ptr calls its destructor when reset with the = operator.
+  void ShareData(const Blob& other);
+  void ShareDiff(const Blob& other);
 
  protected:
   shared_ptr<SyncedMemory> data_;
index e17b8bf..54b6992 100644 (file)
@@ -86,13 +86,13 @@ Dtype* Blob<Dtype>::mutable_gpu_diff() {
 }
 
 template <typename Dtype>
-void Blob<Dtype>::AdoptData(const Blob& other) {
+void Blob<Dtype>::ShareData(const Blob& other) {
   CHECK_EQ(count_, other.count());
   data_ = other.data();
 }
 
 template <typename Dtype>
-void Blob<Dtype>::AdoptDiff(const Blob& other) {
+void Blob<Dtype>::ShareDiff(const Blob& other) {
   CHECK_EQ(count_, other.count());
   diff_ = other.diff();
 }
index 83d0502..e954030 100644 (file)
@@ -24,14 +24,14 @@ void FlattenLayer<Dtype>::SetUp(const vector<Blob<Dtype>*>& bottom,
 template <typename Dtype>
 Dtype FlattenLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,
       vector<Blob<Dtype>*>* top) {
-  (*top)[0]->AdoptData(*bottom[0]);
+  (*top)[0]->ShareData(*bottom[0]);
   return Dtype(0.);
 }
 
 template <typename Dtype>
 void FlattenLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top,
       const bool propagate_down, vector<Blob<Dtype>*>* bottom) {
-  (*bottom)[0]->AdoptDiff(*top[0]);
+  (*bottom)[0]->ShareDiff(*top[0]);
 }
 
 INSTANTIATE_CLASS(FlattenLayer);
index a28018d..157eeb1 100644 (file)
@@ -11,14 +11,14 @@ namespace caffe {
 template <typename Dtype>
 Dtype FlattenLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,
       vector<Blob<Dtype>*>* top) {
-  (*top)[0]->AdoptData(*bottom[0]);
+  (*top)[0]->ShareData(*bottom[0]);
   return Dtype(0.);
 }
 
 template <typename Dtype>
 void FlattenLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,
       const bool propagate_down, vector<Blob<Dtype>*>* bottom) {
-  (*bottom)[0]->AdoptDiff(*top[0]);
+  (*bottom)[0]->ShareDiff(*top[0]);
 }
 
 INSTANTIATE_CLASS(FlattenLayer);
index 59a6604..aa2b6f6 100644 (file)
@@ -31,7 +31,7 @@ template <typename Dtype>
 Dtype SplitLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,
       vector<Blob<Dtype>*>* top) {
   for (int i = 0; i < top->size(); ++i) {
-    (*top)[i]->AdoptData(*bottom[0]);
+    (*top)[i]->ShareData(*bottom[0]);
   }
   return Dtype(0.);
 }
@@ -40,7 +40,7 @@ template <typename Dtype>
 void SplitLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top,
       const bool propagate_down, vector<Blob<Dtype>*>* bottom) {
   if (propagate_down) {
-    (*bottom)[0]->AdoptDiff(*top[0]);
+    (*bottom)[0]->ShareDiff(*top[0]);
     // Add remaining top blob diffs.
     Dtype* bottom_diff = (*bottom)[0]->mutable_cpu_diff();
     for (int i = 1; i < top.size(); ++i) {
index a50e3e8..e2269b8 100644 (file)
@@ -12,7 +12,7 @@ template <typename Dtype>
 Dtype SplitLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,
       vector<Blob<Dtype>*>* top) {
   for (int i = 0; i < top->size(); ++i) {
-    (*top)[i]->AdoptData(*bottom[0]);
+    (*top)[i]->ShareData(*bottom[0]);
   }
   return Dtype(0.);
 }
@@ -21,7 +21,7 @@ template <typename Dtype>
 void SplitLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,
       const bool propagate_down, vector<Blob<Dtype>*>* bottom) {
   if (propagate_down) {
-    (*bottom)[0]->AdoptDiff(*top[0]);
+    (*bottom)[0]->ShareDiff(*top[0]);
     // Add remaining top blob diffs.
     Dtype* bottom_diff = (*bottom)[0]->mutable_gpu_diff();
     for (int i = 1; i < top.size(); ++i) {