From f43300e0eade7c692090b0fe792a70833a225534 Mon Sep 17 00:00:00 2001 From: Jeff Donahue Date: Fri, 11 Apr 2014 16:07:43 -0700 Subject: [PATCH] add unit tests for cpu/gpu copy functions --- src/caffe/test/test_math_functions.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/caffe/test/test_math_functions.cpp b/src/caffe/test/test_math_functions.cpp index 3ddd320..c2c896f 100644 --- a/src/caffe/test/test_math_functions.cpp +++ b/src/caffe/test/test_math_functions.cpp @@ -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 -- 2.7.4