}
template <typename Dtype>
-const Dtype* Blob<Dtype>::cpu_data() {
+Blob<Dtype>::Blob(const Blob<Dtype>& source) {
+ if (source.count() == 0) {
+ Blob();
+ } else {
+ Reshape(source.num(), source.height(), source.width(), source.count());
+ // create the synced memories.
+ data_.reset(new SyncedMemory(count_ * sizeof(Dtype)));
+ diff_.reset(new SyncedMemory(count_ * sizeof(Dtype)));
+ // Copy the data.
+ memcpy(data_->mutable_cpu_data(), source.cpu_data(), count_ * sizeof(Dtype));
+ memcpy(diff_->mutable_cpu_data(), source.cpu_diff(), count_ * sizeof(Dtype));
+ }
+}
+
+template <typename Dtype>
+const Dtype* Blob<Dtype>::cpu_data() const {
CHECK(data_);
return (const Dtype*)data_->cpu_data();
}
template <typename Dtype>
-const Dtype* Blob<Dtype>::gpu_data() {
+const Dtype* Blob<Dtype>::gpu_data() const {
CHECK(data_);
return (const Dtype*)data_->gpu_data();
}
template <typename Dtype>
-const Dtype* Blob<Dtype>::cpu_diff() {
+const Dtype* Blob<Dtype>::cpu_diff() const {
CHECK(diff_);
return (const Dtype*)diff_->cpu_data();
}
template <typename Dtype>
-const Dtype* Blob<Dtype>::gpu_diff() {
+const Dtype* Blob<Dtype>::gpu_diff() const {
CHECK(diff_);
return (const Dtype*)diff_->gpu_data();
}
}
}
-template class Blob<float>;
-template class Blob<double>;
+INSTANTIATE_CLASS(Blob);
} // namespace caffeine
diff_() {};
explicit Blob(const int num, const int height,
const int width, const int channels);
+ Blob(const Blob<Dtype>& source);
virtual ~Blob() {};
void Reshape(const int num, const int height,
const int width, const int channels);
- inline int num() { return num_; }
- inline int height() { return height_; }
- inline int width() { return width_; }
- inline int channels() { return channels_; }
- inline int count() {return count_; }
+ inline int num() const { return num_; }
+ inline int height() const { return height_; }
+ inline int width() const { return width_; }
+ inline int channels() const { return channels_; }
+ inline int count() const {return count_; }
- const Dtype* cpu_data();
- const Dtype* gpu_data();
- const Dtype* cpu_diff();
- const Dtype* gpu_diff();
+ const Dtype* cpu_data() const;
+ const Dtype* gpu_data() const;
+ const Dtype* cpu_diff() const;
+ const Dtype* gpu_diff() const;
Dtype* mutable_cpu_data();
Dtype* mutable_gpu_data();
Dtype* mutable_cpu_diff();
const bool propagate_down,
vector<Blob<Dtype>*>* bottom);
+ vector<Blob<Dtype> >& params() { return blobs_; };
+
protected:
// The protobuf that stores the layer parameters
LayerParameter layer_param_;
N_ = num_output;
(*top)[0]->Reshape(bottom[0]->num(), 1, 1, num_output);
}
- if (biasterm_) {
- this->blobs_.resize(2);
- } else {
- this->blobs_.resize(1);
- }
+ if (biasterm_) {
+ this->blobs_.resize(2);
+ } else {
+ this->blobs_.resize(1);
+ }
// Intialize the weight
- Blob<Dtype>& weight = this->blobs_[0];
- weight.Reshape(1, 1, K_, N_);
+ this->blobs_[0].Reshape(1, 1, K_, N_);
// fill the weights
shared_ptr<Filler<Dtype> > weight_filler(
GetFiller<Dtype>(this->layer_param_.weight_filler()));
- weight_filler->Fill(&weight);
+ weight_filler->Fill(&this->blobs_[0]);
// If necessary, intiialize and fill the bias term
if (biasterm_) {
- Blob<Dtype>& bias = this->blobs_[1];
- bias.Reshape(1, 1, 1, N_);
+ this->blobs_[1].Reshape(1, 1, 1, N_);
shared_ptr<Filler<Dtype> > bias_filler(
GetFiller<Dtype>(this->layer_param_.bias_filler()));
- bias_filler->Fill(&bias);
+ bias_filler->Fill(&this->blobs_[1]);
}
};
#include "gtest/gtest.h"
#include "caffeine/common.hpp"
#include "caffeine/blob.hpp"
+#include "caffeine/filler.hpp"
namespace caffeine {
EXPECT_EQ(this->blob_->count(), 120);
}
+TYPED_TEST(BlobSimpleTest, TestCopyConstructor) {
+ Blob<TypeParam> source(2, 3, 4, 5);
+ FillerParameter filler_param;
+ UniformFiller<TypeParam> filler(filler_param);
+ filler.Fill(&source);
+ Blob<TypeParam> target(source);
+ const TypeParam* source_data = source.cpu_data();
+ const TypeParam* target_data = target.cpu_data();
+ for (int i = 0; i < source.count(); ++i) {
+ EXPECT_EQ(source_data[i], target_data[i]);
+ }
+}
}
printf("Major revision number: %d\n", CAFFEINE_TEST_CUDA_PROP.major);
printf("Minor revision number: %d\n", CAFFEINE_TEST_CUDA_PROP.minor);
printf("Name: %s\n", CAFFEINE_TEST_CUDA_PROP.name);
- printf("Total global memory: %u\n", CAFFEINE_TEST_CUDA_PROP.totalGlobalMem);
- printf("Total shared memory per block: %u\n", CAFFEINE_TEST_CUDA_PROP.sharedMemPerBlock);
+ printf("Total global memory: %lu\n", CAFFEINE_TEST_CUDA_PROP.totalGlobalMem);
+ printf("Total shared memory per block: %lu\n", CAFFEINE_TEST_CUDA_PROP.sharedMemPerBlock);
printf("Total registers per block: %d\n", CAFFEINE_TEST_CUDA_PROP.regsPerBlock);
printf("Warp size: %d\n", CAFFEINE_TEST_CUDA_PROP.warpSize);
- printf("Maximum memory pitch: %u\n", CAFFEINE_TEST_CUDA_PROP.memPitch);
+ printf("Maximum memory pitch: %lu\n", CAFFEINE_TEST_CUDA_PROP.memPitch);
printf("Maximum threads per block: %d\n", CAFFEINE_TEST_CUDA_PROP.maxThreadsPerBlock);
for (int i = 0; i < 3; ++i)
printf("Maximum dimension %d of block: %d\n", i, CAFFEINE_TEST_CUDA_PROP.maxThreadsDim[i]);
for (int i = 0; i < 3; ++i)
printf("Maximum dimension %d of grid: %d\n", i, CAFFEINE_TEST_CUDA_PROP.maxGridSize[i]);
printf("Clock rate: %d\n", CAFFEINE_TEST_CUDA_PROP.clockRate);
- printf("Total constant memory: %u\n", CAFFEINE_TEST_CUDA_PROP.totalConstMem);
- printf("Texture alignment: %u\n", CAFFEINE_TEST_CUDA_PROP.textureAlignment);
+ printf("Total constant memory: %lu\n", CAFFEINE_TEST_CUDA_PROP.totalConstMem);
+ printf("Texture alignment: %lu\n", CAFFEINE_TEST_CUDA_PROP.textureAlignment);
printf("Concurrent copy and execution: %s\n", (CAFFEINE_TEST_CUDA_PROP.deviceOverlap ? "Yes" : "No"));
printf("Number of multiprocessors: %d\n", CAFFEINE_TEST_CUDA_PROP.multiProcessorCount);
printf("Kernel execution timeout: %s\n", (CAFFEINE_TEST_CUDA_PROP.kernelExecTimeoutEnabled ? "Yes" : "No"));