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_;
}
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();
}
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);
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);
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.);
}
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) {
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.);
}
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) {