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

  • 相关阅读:
    ECshop 二次开发模板教程4
    ECshop 二次开发模板教程3
    ECshop 二次开发模板教程2
    ECshop 二次开发模板教程1
    ecshop 二次开发及模板标签
    ECSHOP seo修改建议
    Ecshop ajax 局部刷新购物车功能
    ECSHOP
    echo二次开发 ecshop 函数列表
    Ecshop文件结构,二次开发
  • 原文地址:https://www.cnblogs.com/yeahgis/p/3487779.html
Copyright © 2011-2022 走看看