0

我对 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;
}

任何解决方案将不胜感激。

谢谢,莫森

4

1 回答 1

1

这似乎是 CUDA 在编译期间添加的数学函数定义之间的命名空间冲突,并将整个alglib命名空间包含在翻译单元中。移除

using namespace alglib;

从代码显然解决了这个问题。

一般来说,无条件地将一个大型命名空间导入另一个命名空间在 C++ 中是一种非常糟糕的设计实践,因为它会导致非常难以诊断此类冲突,并且会减慢编译速度。

于 2016-02-22T06:35:10.260 回答