无法在 Visual Studio 2008 中构建 CUDA 项目
我是贝尔格莱德大学计算机科学专业的一年级学生。我的软计算项目是比较不同基于群体的算法(例如遗传算法、蚁群优化、蜂群、萤火虫和 PSO)的 CUDA 实现的性能。由于我是一年级学生,所以我不需要编写所有这些代码。我的任务只是尝试找到代码、运行它们并测量 CPU 和 GPU 实现之间的性能差异。
一些好心人给我发了一个在 Linux 下开发的遗传算法的 CUDA 实现。由于我对 Linux 不太熟悉,我在 Windows 上的 Visual Studio 中构建和运行 CUDA 项目时遇到了麻烦。
Make 文件包含在项目中,但我认为它不完整。 Make 文件包含另一个我没有的 make 文件。我尝试在win 7下运行,但不成功,所以我安装了win xp、Visual Studio 2008、CUDA SDK 2.3和匹配的驱动程序。无论我尝试什么,我总是遇到同样的问题。
首先,我得到 u_int32_t is undefined
(u_int32_t
是自定义定义类型),因此我将其替换为 __int32
,这解决了问题。 之后,我收到以下错误:rint is not Defined
和 log2 is not Defined
。我不知道为什么会收到这些错误,因为 math_functions.h
是通过 common_functions.h
间接包含在项目中的。然后我将这些函数的两行放在注释下,并为这些变量提供一些固定值。
之后我收到链接器错误。例如:
错误 3 错误 LNK2019:函数“public: __thiscallGa::Ga(int *,char * *) 中引用了无法解析的外部符号 _h_fit
有什么我可以做的吗?另外,如果有人愿意发给我,我将非常感激遗传算法的 CUDA 实现在我的个人资料中。
编辑:
我设置了包含 pats 到所有 h 文件,我还设置了 CUDA 构建规则,我可以构建和运行其他 CUDA 项目。很好。
I'm a first year student Computer Science major at the University of Belgrade.My Soft Computing project is to compare a performance of CUDA implementations of different population based algorithms, such as Genetic algorithms, Ant Colony Optimization, Bee Colony, Firefly and PSO. It is not expected from me to write all these codes, since I am a first year student.My assignment is just to try to find codes, run them and measure the performance difference between CPU and GPU implementations.
A few good people sent me a CUDA implementation of Genetic Algorithm that was developed under Linux. Since I am not very familiar with Linux, I am having trouble to build and run CUDA project in visual studio on windows.
Make file is included in project but I think that it is not complete. Make file includes another make file which I do not have. I tried to run it under win 7, but it was unsuccessful, so I installed win xp, visual studio 2008, CUDA SDK 2.3 and matching drivers. Whatever I try, I am always having same problems.
First, I got u_int32_t is undefined
(u_int32_t
is custom defined type), so I replace it with __int32
, and that solves the problem.
After that I get the following errors: rint is not defined
and log2 is not defined
. I don't know why I get these errors since math_functions.h
is included indirectly in project via common_functions.h
. Then I put two lines with these function under comments, and give some fixed values to that variables.
And after that I get linker errors. For example:
Error 3 error LNK2019: unresolved external symbol _h_fit referenced in function "public: __thiscallGa::Ga(int *,char * *)
Is there anything that I can do? In addition, I would be very thankful if anyone is willing to send me CUDA implementation of Genetic Algorithm that works. My e-mail address is in my profile.
EDIT:
I set include pats to all h files, link pats to lib files. I also set CUDA build rule. I can build and run other CUDA projects just fine.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
安装 NSight 1.51。这将为您设置构建规则等。
可以确保项目配置属性中的“包含目录”属性| VC++ 目录选项卡包含 SDK 包含的路径。类似于:
C:\Program Files\NVIDIA GPU Compute Toolkit\CUDA\v3.2\include
确保链接器 |输入选项卡将 cudart.lib 作为附加依赖项之一
链接器错误看起来好像找不到像 Ga(int *,char * *) 这样的方法,我假设它是 GA 算法的一部分。您是否尝试将 CUDA 项目链接到另一个 VS 项目以使用 CUDA GA 库?如果是这样,您需要确保向其他代码公开 GA 库的类被标记为
以便 DLL 导出该类,并且其他 VS 项目需要包含对 CUDA 项目的依赖项。如果不了解您的解决方案是如何配置的,就很难说更多。
这里有两个关于 CUDA 和 Visual C++ 2010 入门的教程,其中大部分适用于 VS 2008:
http://blog.cuvilib.com/2011/02/24/how-to-run-cuda-in-visual-studio-2010/
http: //www.ademiller.com/blogs/tech/2011/03/using-cuda-and-thrust-with-visual-studio-2010/
NVIDIA 论坛上还有一个帖子:
http://forums.nvidia.com/index.php?showtopic=184539
Install NSight 1.51. This will get the build rules etc all set up for you.
May sure that the Include Directories property in the projects Configuration Properties | VC++ Directories tab include a path to the SDK's includes. Something like:
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v3.2\include
Make sure that the Linker | Input tab has cudart.lib as one of the Additional Dependencies
The linker error looks like it can't find methods like Ga(int *,char * *) which I'm assuming is part of your GA algorithm. Are you trying to link a CUDA project to another VS project to use the CUDA GA library? If so you need to make sure that the class that exploses the GA library to other code is marked as
So that the DLL exports the class and the other VS project needs to include a dependency to the CUDA project. Without seeing how your solution is configured it's hard to say more.
Here are two tutorials on getting started with CUDA and Visual C++ 2010, most of this applies to VS 2008:
http://blog.cuvilib.com/2011/02/24/how-to-run-cuda-in-visual-studio-2010/
http://www.ademiller.com/blogs/tech/2011/03/using-cuda-and-thrust-with-visual-studio-2010/
There's also a post on the NVIDIA forum:
http://forums.nvidia.com/index.php?showtopic=184539
确保您已设置 h 文件的包含路径,
lib 文件的链接路径,
构建复制 dll 的事件。
(所有这些都是为了更正Toolkit和SDK中的路径。)
并使用CUDA的规则文件来设置构建工具
对于 cu 文件。
Make sure you have set include path to h files,
link path to lib files,
build event to copy dlls.
(All to correct paths in Toolkit and SDK.)
And also use CUDA's rule file to set up build tool
for cu files.