add unit tests for cpu/gpu copy functions
authorJeff Donahue <jeff.donahue@gmail.com>
Fri, 11 Apr 2014 23:07:43 +0000 (16:07 -0700)
committerJeff Donahue <jeff.donahue@gmail.com>
Sat, 12 Apr 2014 06:49:46 +0000 (23:49 -0700)
src/caffe/test/test_math_functions.cpp

index 3ddd320..c2c896f 100644 (file)
@@ -207,4 +207,26 @@ TYPED_TEST(MathFunctionsTest, TestScaleGPU) {
   }
 }
 
+TYPED_TEST(MathFunctionsTest, TestCopyCPU) {
+  const int n = this->blob_bottom_->count();
+  const TypeParam* bottom_data = this->blob_bottom_->cpu_data();
+  TypeParam* top_data = this->blob_top_->mutable_cpu_data();
+  caffe_copy(n, bottom_data, top_data);
+  for (int i = 0; i < n; ++i) {
+    EXPECT_EQ(bottom_data[i], top_data[i]);
+  }
+}
+
+TYPED_TEST(MathFunctionsTest, TestCopyGPU) {
+  const int n = this->blob_bottom_->count();
+  const TypeParam* bottom_data = this->blob_bottom_->gpu_data();
+  TypeParam* top_data = this->blob_top_->mutable_gpu_data();
+  caffe_gpu_copy(n, bottom_data, top_data);
+  bottom_data = this->blob_bottom_->cpu_data();
+  top_data = this->blob_top_->mutable_cpu_data();
+  for (int i = 0; i < n; ++i) {
+    EXPECT_EQ(bottom_data[i], top_data[i]);
+  }
+}
+
 }  // namespace caffe