编译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