您的位置:首页 > 数据库 > MySQL

CUDA(5.5)与MySQL 5.6的rint函数定义冲突引起的VS编译器C2264错误

2013-12-23 17:14 633 查看
向CUDA project中添加了如下的包含目录后:

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.5\include;
..\include_p;
..\include_p\gdal;
..\include_p\mysql;
..\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\nvidia gpu computing toolkit\cuda\v5.5\include\math_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工程,错误消失,编译成功。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: