我对alglib和Cuda很陌生。我正在尝试使用Alglib进行非线性列表平方拟合。当我在VC ++(.cpp)中进行编译时,代码正在工作,但是当我尝试在cuda文件(.cu)中进行编译时,它给了我这个错误:
Error 6 error C2668: 'round' : ambiguous call to overloaded function
Error 7 error C2668: 'round' : ambiguous call to overloaded function
Error 8 error C2668: 'round' : ambiguous call to overloaded function
Error 9 error C2668: 'trunc' : ambiguous call to overloaded function
Error 10 error MSB3721:
命令““ D:\ NVIDIA \ bin \ nvcc.exe” -gencode = arch = compute_10,code = \“ sm_10,compute_10 \” --use-local-env --cl-version 2012 -ccbin“ D:\程序(x86)\ Microsoft Visual Studio 11.0 \ VC \ bin“ -ID:\ NVIDIA \ include -ID:\ NVIDIA \ include --keep-dir Release -maxrregcount = 0 --machine 32 --compile -cudart static -D_MBCS -Xcompiler“ / EHsc / W3 / nologo / O2 / Zi / MD” -o Release \ min.cu.obj“ ... \ min.cu”“以代码2退出。C:\ Program Files(x86)\ MSBuild \ Microsoft.Cpp \ v4.0 \ V110 \ BuildCustomizations \ CUDA 6.0.targets 597 9 Cuda_lsfit
这是我的代码:
# include <iostream>
# include "cuda_runtime.h"
# include "device_launch_parameters.h"
# include <cuda.h>
#include "stdafx.h"
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "interpolation.h"
using namespace alglib;
void function_cx_1_func(const real_1d_array &c, const real_1d_array &x, double &func, void *ptr)
{
// main function
func = abs(c[0]*(1-exp(-x[0]/c[1])));;
}
int main(int argc, char **argv)
{
real_2d_array x = "[[50],[400],[550],[750],[1200],[2000]]";
real_1d_array y = "[1384,792,642,258,91,868]";
real_1d_array c = "[0.5,500]";
double epsf = 0; //minimum of step size difference
double epsx = 0.000001; //minimum of function changes
ae_int_t maxits = 0; //maximum iteration 0 = unlimitted number
ae_int_t info;
lsfitstate state; // structure contains information about algoritm
lsfitreport rep;
double diffstep = 0.0001;
// Fitting
lsfitcreatef(x, y, c, diffstep, state);
lsfitsetcond(state, epsf, epsx, maxits);
alglib::lsfitfit(state, function_cx_1_func);
lsfitresults(state, info, c, rep);
printf("%d\n", int(info));
printf("%s\n", c.tostring(1).c_str());
return 0;
}
任何解决方案将不胜感激。
谢谢,
莫森
最佳答案
这似乎是CUDA在编译期间添加的数学函数的定义之间的命名空间冲突,并且将整个alglib
命名空间包括在转换单元中。拆下
using namespace alglib;
从代码中显然可以解决问题。
通常,在C ++中,无条件地将大名称空间导入另一个名称空间是一种非常糟糕的设计实践,因为它可能导致很难像这样诊断冲突,并且减慢了编译速度。