zoukankan      html  css  js  c++  java
  • CUDA(5.5)与MySQL 5.6的rint函数定义冲突引起的VS编译器C2264错误

    向CUDA project中添加了如下的包含目录后:

    C:Program FilesNVIDIA GPU Computing ToolkitCUDAv5.5include;
    ..include_p;
    ..include_pgdal;
    ..include_pmysql;
    ..include;
    ..include_cg;
    $(IncludePath)

    在main.cu中添加如下包含文件:

    #include <stdlib.h>
    #include <stdio.h>
    #include <string>
    #include <cuda_runtime.h>
    #include <cuda_runtime_api.h>
    #include <cuda_device_runtime_api.h>
    
    #include "cuda_helloworld_kernel.cu"
    #include "host_rapc_cuda.cu"

    而host_rapc_cuda.cu文件又包含了:

    #include "gt_geometry.h"
    #include "phd_rapc_vtx.h"//该文件包含了gt_datasource.h文件,后者又包含了mysql_global.h文件,与CUDA的math_functions.h中定义的相同名称的rint函数引起了冲突
    #include "gt_geometryoverlay_phdpaper.h"

    编译项目,出现下面的症状:

    错误    433    error C2264: “rint”: 函数定义或声明中有错误;未调用函数    c:program files
    vidia gpu computing toolkitcudav5.5includemath_functions.h    11639

    分析:

    CUDA的rint函数定义在math_functions.h中,实现如下:

    static __inline__ __host__ __device__ float rint(float a)
    {
      return rintf(a);
    }

    mysql的rint的函数定义在my_global.h中,实现如下:

    #ifndef HAVE_RINT
    /**
      All integers up to this number can be represented exactly as double precision
      values (DBL_MANT_DIG == 53 for IEEE 754 hardware).
    */
    #define MAX_EXACT_INTEGER ((1LL << DBL_MANT_DIG) - 1)
    
    /**
      rint(3) implementation for platforms that do not have it.
      Always rounds to the nearest integer with ties being rounded to the nearest
      even integer to mimic glibc's rint() behavior in the "round-to-nearest"
      FPU mode. Hardware-specific optimizations are possible (frndint on x86).
      Unlike this implementation, hardware will also honor the FPU rounding mode.
    */
    
    static inline double rint(double x)
    {
      double f, i;
      f = modf(x, &i);
    
      /*
        All doubles with absolute values > MAX_EXACT_INTEGER are even anyway,
        no need to check it.
      */
      if (x > 0.0)
        i += (double) ((f > 0.5) || (f == 0.5 &&
                                     i <= (double) MAX_EXACT_INTEGER &&
                                     (longlong) i % 2));
      else
        i -= (double) ((f < -0.5) || (f == -0.5 &&
                                      i >= (double) -MAX_EXACT_INTEGER &&
                                      (longlong) i % 2));
      return i;
    }
    #endif /* HAVE_RINT */

    由此可见,mysql和CUDA中对rint函数的重复定义在编译时引起了混淆,而mysql中的rint函数可以通过定义HAVE_RINT宏进行控制,我们在gts_cg_port.h头文件中添加定义:

    #define HAVE_RINT 1

    重新编译gtcg库后,再重新编译我们的CUDA工程,错误消失,编译成功。

  • 相关阅读:
    阿里云CentOS安装firefox闪退
    error: QApplication: No such file or directory
    CentOS下自动登陆root帐户
    Linux下常用软件
    【记录】haphost免费vps初始配置
    检测Linux VPS是Xen、OpenVZ还是KVM真假方法
    使用VNC远程管理VPS(Centos系统)
    配置suricata
    NGUI的输入框制作(attach- input filed script的使用)
    NGUI技能CD效果制作(sprite的type:filled)
  • 原文地址:https://www.cnblogs.com/yeahgis/p/3487779.html
Copyright © 2011-2022 走看看