error: function "atomicAdd(double *, double)" has already been defined

本文解决了在使用CUDA8.0编译DeepLab_v2时遇到的原子操作定义冲突问题。通过修改common.cuh文件中的原子加操作实现,确保了与CUDA8.0的兼容性。

在编译deeplab_V2的时候,用Cuda-8.0,出现上述错误。
之前在cuda-7.5的时候,没有出现这个错误。在网上找到错误的原因,记录下来。
原文地址

CUDA 8.0 provides a definition of atomicAdd on double quantities that was not present in previous CUDA toolkits. The code you are working with also apparently provides its own definition/implementation, and this is the source of the error message. The correct fix is to make source code changes to the software in question to make it compatible with CUDA 8.

I had to modify the file common.cuh from the DeepLab_v2 master branch in the following way:

#ifndef CAFFE_COMMON_CUH_
#define CAFFE_COMMON_CUH_

#include <cuda.h>

  #if !defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 600

  #else
  static __inline__ __device__ double atomicAdd(double *address, double val) {
    unsigned long long int* address_as_ull = (unsigned long long int*)address;
    unsigned long long int old = *address_as_ull, assumed;
    if (val==0.0)
      return __longlong_as_double(old);
    do {
      assumed = old;
      old = atomicCAS(address_as_ull, assumed, __double_as_longlong(val +__longlong_as_double(assumed)));
    } while (assumed != old);
    return __longlong_as_double(old);
  }


  #endif
#endif
Build started: Project: OLED *** Using Compiler 'V5.06 update 6 (build 750)', folder: 'D:\keil\ARM\ARMCC\Bin' Build target 'OLED' compiling DistanceFunctions.c... D:/keil/ARM/CMSIS-DSP/1.15.0/Source/DistanceFunctions/arm_dtw_distance_f32.c(96): error: #254: type name is not allowed for(uint32_t q=0 ; q < queryLength; q++) D:/keil/ARM/CMSIS-DSP/1.15.0/Source/DistanceFunctions/arm_dtw_distance_f32.c(96): error: #65: expected a ";" for(uint32_t q=0 ; q < queryLength; q++) D:/keil/ARM/CMSIS-DSP/1.15.0/Source/DistanceFunctions/arm_dtw_distance_f32.c(96): error: #20: identifier "q" is undefined for(uint32_t q=0 ; q < queryLength; q++) D:/keil/ARM/CMSIS-DSP/1.15.0/Source/DistanceFunctions/arm_dtw_distance_f32.c(98): error: #254: type name is not allowed for(uint32_t t= 0; t < templateLength; t++) D:/keil/ARM/CMSIS-DSP/1.15.0/Source/DistanceFunctions/arm_dtw_distance_f32.c(98): error: #65: expected a ";" for(uint32_t t= 0; t < templateLength; t++) D:/keil/ARM/CMSIS-DSP/1.15.0/Source/DistanceFunctions/arm_dtw_distance_f32.c(98): error: #20: identifier "t" is undefined for(uint32_t t= 0; t < templateLength; t++) D:/keil/ARM/CMSIS-DSP/1.15.0/Source/DistanceFunctions/arm_dtw_distance_f32.c(105): error: #254: type name is not allowed for(uint32_t q = 1; q < queryLength; q++) D:/keil/ARM/CMSIS-DSP/1.15.0/Source/DistanceFunctions/arm_dtw_distance_f32.c(105): error: #65: expected a ";" for(uint32_t q = 1; q < queryLength; q++) D:/keil/ARM/CMSIS-DSP/1.15.0/Source/DistanceFunctions/arm_dtw_distance_f32.c(114): error: #254: type name is not allowed for(uint32_t t = 1; t < templateLength; t++) D:/keil/ARM/CMSIS-DSP/1.15.0/Source/DistanceFunctions/arm_dtw_distance_f32.c(114): error: #65: expected a ";" for(uint32_t t = 1; t < templateLength; t++) D:/keil/ARM/CMSIS-DSP/1.15.0/Source/DistanceFunctions/arm_dtw_distance_f32.c(114): error: #20: identifier "t" is undefined for(uint32_t t = 1; t < templateLength; t++) D:/keil/ARM/CMSIS-DSP/1.15.0/Source/DistanceFunctions/arm_dtw_distance_f32.c(124): error: #254: type name is not allowed for(uint32_t q = 1; q < queryLength; q++) D:/keil/ARM/CMSIS-DSP/1.15.0/Source/DistanceFunctions/arm_dtw_distance_f32.c(124): error: #65: expected a ";" for(uint32_t q = 1; q < queryLength; q++) D:/keil/ARM/CMSIS-DSP/1.15.0/Source/DistanceFunctions/arm_dtw_distance_f32.c(126): error: #254: type name is not allowed for(uint32_t t = 1; t < templateLength; t++) D:/keil/ARM/CMSIS-DSP/1.15.0/Source/DistanceFunctions/arm_dtw_distance_f32.c(126): error: #65: expected a ";" for(uint32_t t = 1; t < templateLength; t++) D:/keil/ARM/CMSIS-DSP/1.15.0/Source/DistanceFunctions/arm_dtw_path_f32.c(144): error: #268: declaration may not appear after executable statement in block int16_t *fh,*sh; D:/keil/ARM/CMSIS-DSP/1.15.0/Source/DistanceFunctions/arm_dtw_path_f32.c(147): error: #268: declaration may not appear after executable statement in block int halfLength = (*pathLength)>>1; D:/keil/ARM/CMSIS-DSP/1.15.0/Source/DistanceFunctions/arm_dtw_path_f32.c(148): error: #29: expected an expression for(int i = 0; i< halfLength; i++) D:/keil/ARM/CMSIS-DSP/1.15.0/Source/DistanceFunctions/arm_dtw_path_f32.c(148): error: #20: identifier "i" is undefined for(int i = 0; i< halfLength; i++) D:/keil/ARM/CMSIS-DSP/1.15.0/Source/DistanceFunctions/DistanceFunctions.c(54): warning: #1-D: last line of file ends without a newline #include "arm_dtw_init_window_q7.c" D:/keil/ARM/CMSIS-DSP/1.15.0/Source/DistanceFunctions/arm_dtw_init_window_q7.c(71): error: #254: type name is not allowed for(int32_t q = 0; q < queryLength; q++) D:/keil/ARM/CMSIS-DSP/1.15.0/Source/DistanceFunctions/arm_dtw_init_window_q7.c(71): error: #65: expected a ";" for(int32_t q = 0; q < queryLength; q++) D:/keil/ARM/CMSIS-DSP/1.15.0/Source/DistanceFunctions/arm_dtw_init_window_q7.c(71): error: #20: identifier "q" is undefined for(int32_t q = 0; q < queryLength; q++) D:/keil/ARM/CMSIS-DSP/1.15.0/Source/DistanceFunctions/arm_dtw_init_window_q7.c(73): error: #254: type name is not allowed for(int32_t t = 0; t < templateLength; t++) D:/keil/ARM/CMSIS-DSP/1.15.0/Source/DistanceFunctions/arm_dtw_init_window_q7.c(73): error: #65: expected a ";" for(int32_t t = 0; t < templateLength; t++) D:/keil/ARM/CMSIS-DSP/1.15.0/Source/DistanceFunctions/arm_dtw_init_window_q7.c(73): error: #20: identifier "t" is undefined for(int32_t t = 0; t < templateLength; t++) D:/keil/ARM/CMSIS-DSP/1.15.0/Source/DistanceFunctions/arm_dtw_init_window_q7.c(99): error: #254: type name is not allowed for(int32_t q = 0; q < queryLength; q++) D:/keil/ARM/CMSIS-DSP/1.15.0/Source/DistanceFunctions/arm_dtw_init_window_q7.c(99): error: #65: expected a ";" for(int32_t q = 0; q < queryLength; q++) D:/keil/ARM/CMSIS-DSP/1.15.0/Source/DistanceFunctions/arm_dtw_init_window_q7.c(99): error: #20: identifier "q" is undefined for(int32_t q = 0; q < queryLength; q++) D:/keil/ARM/CMSIS-DSP/1.15.0/Source/DistanceFunctions/arm_dtw_init_window_q7.c(101): error: #254: type name is not allowed for(int32_t t = 0; t < templateLength; t++) D:/keil/ARM/CMSIS-DSP/1.15.0/Source/DistanceFunctions/arm_dtw_init_window_q7.c(101): error: #65: expected a ";" for(int32_t t = 0; t < templateLength; t++) D:/keil/ARM/CMSIS-DSP/1.15.0/Source/DistanceFunctions/DistanceFunctions.c: 1 warning, 30 errors compiling MatrixFunctions.c... D:/keil/ARM/CMSIS-DSP/1.15.0/Source/MatrixFunctions/arm_mat_ldlt_f32.c(396): error: #29: expected an expression for(int w=k+1;w<n;w++) D:/keil/ARM/CMSIS-DSP/1.15.0/Source/MatrixFunctions/arm_mat_ldlt_f32.c(396): error: #20: identifier "w" is undefined for(int w=k+1;w<n;w++) D:/keil/ARM/CMSIS-DSP/1.15.0/Source/MatrixFunctions/arm_mat_ldlt_f32.c(405): error: #29: expected an expression for(int w=k+1;w<n;w++) D:/keil/ARM/CMSIS-DSP/1.15.0/Source/MatrixFunctions/arm_mat_ldlt_f64.c(135): error: #29: expected an expression for(int w=k+1;w<n;w++) D:/keil/ARM/CMSIS-DSP/1.15.0/Source/MatrixFunctions/arm_mat_ldlt_f64.c(135): error: #20: identifier "w" is undefined for(int w=k+1;w<n;w++) D:/keil/ARM/CMSIS-DSP/1.15.0/Source/MatrixFunctions/arm_mat_ldlt_f64.c(144): error: #29: expected an expression for(int w=k+1;w<n;w++) D:/keil/ARM/CMSIS-DSP/1.15.0/Source/MatrixFunctions/arm_mat_qr_f32.c(841): error: #268: declaration may not appear after executable statement in block arm_status status = ARM_MATH_SUCCESS; D:/keil/ARM/CMSIS-DSP/1.15.0/Source/MatrixFunctions/arm_mat_qr_f64.c(299): error: #268: declaration may not appear after executable statement in block arm_status status = ARM_MATH_SUCCESS; D:/keil/ARM/CMSIS-DSP/1.15.0/Source/MatrixFunctions/MatrixFunctions.c: 0 warnings, 8 errors compiling main.c... D:\keil\ARM\CMSIS\5.9.0\CMSIS\Core\Include\cmsis_armcc.h(208): error: #247: function "__REV16" has already been defined __attribute__((section(".rev16_text"))) __STATIC_INLINE __ASM uint32_t __REV16(uint32_t value) D:\keil\ARM\CMSIS\5.9.0\CMSIS\Core\Include\cmsis_armcc.h(223): error: #247: function "__REVSH" has already been defined __attribute__((section(".revsh_text"))) __STATIC_INLINE __ASM int16_t __REVSH(int16_t value) D:\keil\ARM\CMSIS\5.9.0\CMSIS\Core\Include\cmsis_armcc.h(300): warning: #47-D: incompatible redefinition of macro "__LDREXB" (declared at line 193 of "..\CORE\core_cmInstr.h") #define __LDREXB(ptr) _Pragma("push") _Pragma("diag_suppress 3731") ((uint8_t ) __ldrex(ptr)) _Pragma("pop") D:\keil\ARM\CMSIS\5.9.0\CMSIS\Core\Include\cmsis_armcc.h(313): warning: #47-D: incompatible redefinition of macro "__LDREXH" (declared at line 203 of "..\CORE\core_cmInstr.h") #define __LDREXH(ptr) _Pragma("push") _Pragma("diag_suppress 3731") ((uint16_t) __ldrex(ptr)) _Pragma("pop") D:\keil\ARM\CMSIS\5.9.0\CMSIS\Core\Include\cmsis_armcc.h(326): warning: #47-D: incompatible redefinition of macro "__LDREXW" (declared at line 213 of "..\CORE\core_cmInstr.h") #define __LDREXW(ptr) _Pragma("push") _Pragma("diag_suppress 3731") ((uint32_t ) __ldrex(ptr)) _Pragma("pop") D:\keil\ARM\CMSIS\5.9.0\CMSIS\Core\Include\cmsis_armcc.h(341): warning: #47-D: incompatible redefinition of macro "__STREXB" (declared at line 225 of "..\CORE\core_cmInstr.h") #define __STREXB(value, ptr) _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr) _Pragma("pop") D:\keil\ARM\CMSIS\5.9.0\CMSIS\Core\Include\cmsis_armcc.h(356): warning: #47-D: incompatible redefinition of macro "__STREXH" (declared at line 237 of "..\CORE\core_cmInstr.h") #define __STREXH(value, ptr) _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr) _Pragma("pop") D:\keil\ARM\CMSIS\5.9.0\CMSIS\Core\Include\cmsis_armcc.h(371): warning: #47-D: incompatible redefinition of macro "__STREXW" (declared at line 249 of "..\CORE\core_cmInstr.h") #define __STREXW(value, ptr) _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr) _Pragma("pop") D:\keil\ARM\CMSIS\5.9.0\CMSIS\Core\Include\cmsis_armcc.h(555): error: #247: function "__get_CONTROL" has already been defined __STATIC_INLINE uint32_t __get_CONTROL(void) D:\keil\ARM\CMSIS\5.9.0\CMSIS\Core\Include\cmsis_armcc.h(567): error: #247: function "__set_CONTROL" has already been defined __STATIC_INLINE void __set_CONTROL(uint32_t control) D:\keil\ARM\CMSIS\5.9.0\CMSIS\Core\Include\cmsis_armcc.h(580): error: #247: function "__get_IPSR" has already been defined __STATIC_INLINE uint32_t __get_IPSR(void) D:\keil\ARM\CMSIS\5.9.0\CMSIS\Core\Include\cmsis_armcc.h(592): error: #247: function "__get_APSR" has already been defined __STATIC_INLINE uint32_t __get_APSR(void) D:\keil\ARM\CMSIS\5.9.0\CMSIS\Core\Include\cmsis_armcc.h(604): error: #247: function "__get_xPSR" has already been defined __STATIC_INLINE uint32_t __get_xPSR(void) D:\keil\ARM\CMSIS\5.9.0\CMSIS\Core\Include\cmsis_armcc.h(616): error: #247: function "__get_PSP" has already been defined __STATIC_INLINE uint32_t __get_PSP(void) D:\keil\ARM\CMSIS\5.9.0\CMSIS\Core\Include\cmsis_armcc.h(628): error: #247: function "__set_PSP" has already been defined __STATIC_INLINE void __set_PSP(uint32_t topOfProcStack) D:\keil\ARM\CMSIS\5.9.0\CMSIS\Core\Include\cmsis_armcc.h(640): error: #247: function "__get_MSP" has already been defined __STATIC_INLINE uint32_t __get_MSP(void) D:\keil\ARM\CMSIS\5.9.0\CMSIS\Core\Include\cmsis_armcc.h(652): error: #247: function "__set_MSP" has already been defined __STATIC_INLINE void __set_MSP(uint32_t topOfMainStack) D:\keil\ARM\CMSIS\5.9.0\CMSIS\Core\Include\cmsis_armcc.h(664): error: #247: function "__get_PRIMASK" has already been defined __STATIC_INLINE uint32_t __get_PRIMASK(void) D:\keil\ARM\CMSIS\5.9.0\CMSIS\Core\Include\cmsis_armcc.h(676): error: #247: function "__set_PRIMASK" has already been defined __STATIC_INLINE void __set_PRIMASK(uint32_t priMask) D:\keil\ARM\CMSIS\5.9.0\CMSIS\Core\Include\cmsis_armcc.h(707): error: #247: function "__get_BASEPRI" has already been defined __STATIC_INLINE uint32_t __get_BASEPRI(void) D:\keil\ARM\CMSIS\5.9.0\CMSIS\Core\Include\cmsis_armcc.h(719): error: #247: function "__set_BASEPRI" has already been defined __STATIC_INLINE void __set_BASEPRI(uint32_t basePri) D:\keil\ARM\CMSIS\5.9.0\CMSIS\Core\Include\cmsis_armcc.h(744): error: #247: function "__get_FAULTMASK" has already been defined __STATIC_INLINE uint32_t __get_FAULTMASK(void) D:\keil\ARM\CMSIS\5.9.0\CMSIS\Core\Include\cmsis_armcc.h(756): error: #247: function "__set_FAULTMASK" has already been defined __STATIC_INLINE void __set_FAULTMASK(uint32_t faultMask) D:\keil\ARM\CMSIS\5.9.0\CMSIS\Core\Include\cmsis_armcc.h(771): error: #247: function "__get_FPSCR" has already been defined __STATIC_INLINE uint32_t __get_FPSCR(void) D:\keil\ARM\CMSIS\5.9.0\CMSIS\Core\Include\cmsis_armcc.h(788): error: #247: function "__set_FPSCR" has already been defined __STATIC_INLINE void __set_FPSCR(uint32_t fpscr) D:\keil\ARM\CMSIS\5.9.0\CMSIS\Core\Include\cmsis_armcc.h(877): warning: #47-D: incompatible redefinition of macro "__SMMLA" (declared at line 127 of "..\CORE\core_cm4_simd.h") #define __SMMLA(ARG1,ARG2,ARG3) ( (int32_t)((((int64_t)(ARG1) * (ARG2)) + \ main.c(167): warning: #177-D: variable "idex" was declared but never referenced u32 idex; main.c(168): warning: #177-D: variable "temp" was declared but never referenced float temp; main.c(201): warning: #223-D: function "fft_getpeak" declared implicitly freamplen=fft_getpeak(fft_inputbuf,fft_outputbuf+1,freamp,FFT_LENGTH/2,10,5,0.2);//寻找基波和谐波 main.c(184): warning: #177-D: variable "temp" was declared but never referenced u8 temp[40]; main.c(185): warning: #177-D: variable "i" was declared but never referenced int i; main.c(186): warning: #550-D: variable "freamplen" was set but never used u16 freamplen; // freamp长度的一半 main.c(249): error: #159: declaration is incompatible with previous "fft_getpeak" (declared at line 201) int fft_getpeak(float *inputx,float *input,float *output,u16 inlen,u8 x,u8 N,float y) // intlen 输入数组长度,x寻找长度 main.c(266): warning: #1035-D: single-precision operand implicitly converted to double-precision if(1.5*sum/(2*N)<datas) main.c(269): warning: #1035-D: single-precision operand implicitly converted to double-precision output[3*outlen+1] = 1.0*(2*datas)/FFT_LENGTH; //计算幅度 main.c(286): warning: #177-D: variable "t" was declared but never referenced u8 t=' '; main.c(335): error: At end of source: #67: expected a "}" main.c: 16 warnings, 21 errors "..\OBJ\OLED.axf" - 59 Error(s), 17 Warning(s). Target not created. Build Time Elapsed: 00:00:03
06-12
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值