]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - jacinto-ai/caffe-jacinto.git/commitdiff
misc update
authorYangqing Jia <jiayq84@gmail.com>
Tue, 17 Sep 2013 22:09:18 +0000 (15:09 -0700)
committerYangqing Jia <jiayq84@gmail.com>
Tue, 17 Sep 2013 22:09:18 +0000 (15:09 -0700)
src/caffeine/blob.cpp
src/caffeine/blob.hpp
src/caffeine/layer.hpp
src/caffeine/layers/inner_product_layer.cu
src/caffeine/test/test_blob.cpp
src/caffeine/test/test_caffeine_main.cpp

index ab56551543c694ddcb83627fe320c282c8d0f0af..0c16be62acaae6073d9daa4ae33e2437756ffb92 100644 (file)
@@ -29,25 +29,40 @@ Blob<Dtype>::Blob(const int num, const int height,
 }
 
 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();
 }
@@ -114,8 +129,7 @@ void Blob<Dtype>::ToProto(BlobProto* proto) {
   }
 }
 
-template class Blob<float>;
-template class Blob<double>;
+INSTANTIATE_CLASS(Blob);
 
 }  // namespace caffeine
 
index e3aad86530ac304f3aea81a7828c6a88d13dede1..12e3825f255a321cfa6ba2a4298c45d0acd8f567 100644 (file)
@@ -15,19 +15,20 @@ class Blob {
        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();
index 554507616dae41d2f33cf554d5131d0e1a1146b7..6bdacb1fa4e20fa98f1e5a179b8a9e566fa01052 100644 (file)
@@ -32,6 +32,8 @@ class Layer {
       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_;
index 8c06dfdbb4d8162699394449ef1ef6084619b727..baeca0e8729797e308155f81d8994db095fbd1db 100644 (file)
@@ -30,25 +30,23 @@ void InnerProductLayer<Dtype>::SetUp(const vector<Blob<Dtype>*>& bottom,
                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]);
        }
 };
 
index ba564229988dd3debf0a6bfeff92a9e104c4ca5a..edb8bbeb18815555891660fcb34dc906c78b44dd 100644 (file)
@@ -4,6 +4,7 @@
 #include "gtest/gtest.h"
 #include "caffeine/common.hpp"
 #include "caffeine/blob.hpp"
+#include "caffeine/filler.hpp"
 
 namespace caffeine {
   
@@ -52,5 +53,17 @@ TYPED_TEST(BlobSimpleTest, TestReshape) {
   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]);
+  }
+}
 
 }
index a3a3b9275dc7bd4b3d9dd093547e040b6dbf8d76..f76cc26cc72c882eb5305e2592c1781a5ae764b8 100644 (file)
@@ -21,19 +21,19 @@ int main(int argc, char** argv) {
   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"));