include/caffe/common.cuh: error: function "atomicAdd(double *, double)" has already bee(代码

Posted _云深不知处

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了include/caffe/common.cuh: error: function "atomicAdd(double *, double)" has already bee(代码相关的知识,希望对你有一定的参考价值。

编译caffe时出现:

include/caffe/common.cuh(9): error: function "atomicAdd(double *, double)" has already been defined

原因是CUDA 8.0 提供了对atomicAdd函数的定义,但atomicAdd在之前的CUDA toolkit中并未出现,因此一些程序自定义了atomicAdd函数。

解决方法:打开./include/caffe/common.cuh文件,在atomicAdd前添加宏判断即可。

改为如下所示:

 1 #ifndef CAFFE_COMMON_CUH_
 2 #define CAFFE_COMMON_CUH_
 3 
 4 #include <cuda.h>
 5 
 6   #if !defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 600
 7 
 8   #else
 9   static __inline__ __device__ double atomicAdd(double *address, double val) {
10     unsigned long long int* address_as_ull = (unsigned long long int*)address;
11     unsigned long long int old = *address_as_ull, assumed;
12     if (val==0.0)
13       return __longlong_as_double(old);
14     do {
15       assumed = old;
16       old = atomicCAS(address_as_ull, assumed, __double_as_longlong(val +__longlong_as_double(assumed)));
17     } while (assumed != old);
18     return __longlong_as_double(old);
19   }
20 
21 
22   #endif
23 #endif

 

以上是关于include/caffe/common.cuh: error: function "atomicAdd(double *, double)" has already bee(代码的主要内容,如果未能解决你的问题,请参考以下文章