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工程,错误消失,编译成功。

  • 相关阅读:
    vue iview 导入excel文件(upload)
    iview table 中用根据不同状态改变颜色(用render)
    vue项目中导出excel表格数据
    iview table 中 render 时间格式化
    微信浏览器的部分特效更接近浏览器IE 9
    ABP 拦截器不工作
    vue + webpack 添加的引用不编译成ES6的问题
    把vue组件添加到body下
    vue+vuex+router实现阻止浏览器回退
    webpack使用vue-moment-libs 在PC微信浏览器下显示空白
  • 原文地址:https://www.cnblogs.com/yeahgis/p/3487779.html
Copyright © 2011-2022 走看看