diff options
author | Sergio <sguada@gmail.com> | 2014-06-18 18:49:14 -0700 |
---|---|---|
committer | Sergio <sguada@gmail.com> | 2014-06-27 18:54:21 -0700 |
commit | 2dd0bc13b51d456a1cd1aaa2dbaf7372baeda7b3 (patch) | |
tree | 34e88ba7bb8e43322a52ec02fe18c9a9a3a3e65d /src | |
parent | 06da1a7de277763164c8bf0c700429785b531c09 (diff) | |
download | caffeonacl-2dd0bc13b51d456a1cd1aaa2dbaf7372baeda7b3.tar.gz caffeonacl-2dd0bc13b51d456a1cd1aaa2dbaf7372baeda7b3.tar.bz2 caffeonacl-2dd0bc13b51d456a1cd1aaa2dbaf7372baeda7b3.zip |
Check that pointers are different before copying in caffe_copy and caffe_gpu_copy
Diffstat (limited to 'src')
-rw-r--r-- | src/caffe/util/math_functions.cpp | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/caffe/util/math_functions.cpp b/src/caffe/util/math_functions.cpp index 67274ef7..90df5124 100644 --- a/src/caffe/util/math_functions.cpp +++ b/src/caffe/util/math_functions.cpp @@ -151,22 +151,30 @@ void caffe_add_scalar(const int N, const double alpha, double* Y) { template <> void caffe_copy<float>(const int N, const float* X, float* Y) { - cblas_scopy(N, X, 1, Y, 1); + if (X != Y) { + cblas_scopy(N, X, 1, Y, 1); + } } template <> void caffe_copy<double>(const int N, const double* X, double* Y) { - cblas_dcopy(N, X, 1, Y, 1); + if (X != Y) { + cblas_dcopy(N, X, 1, Y, 1); + } } template <> void caffe_gpu_copy<float>(const int N, const float* X, float* Y) { - CUBLAS_CHECK(cublasScopy(Caffe::cublas_handle(), N, X, 1, Y, 1)); + if (X != Y) { + CUBLAS_CHECK(cublasScopy(Caffe::cublas_handle(), N, X, 1, Y, 1)); + } } template <> void caffe_gpu_copy<double>(const int N, const double* X, double* Y) { - CUBLAS_CHECK(cublasDcopy(Caffe::cublas_handle(), N, X, 1, Y, 1)); + if (X != Y) { + CUBLAS_CHECK(cublasDcopy(Caffe::cublas_handle(), N, X, 1, Y, 1)); + } } template <> |