C ++和Cuda速度在Visual studio 2013 [英] C++ and Cuda speed in Visual studio 2013

查看:166
本文介绍了C ++和Cuda速度在Visual studio 2013的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在VS 2013上运行数据挖掘算法。
我实现了基于CPU的版本(使用.cpp文件)和基于GPU的版本(使用cuda 7.5 .cu文件)。

I'm running Data mining algorithm on VS 2013. I've implement CPU based version (with .cpp file) and GPU based version (with cuda 7.5 .cu file).

两个版本按预期运行。基于CPU的版本大约需要1500秒,GPU版本大约为500秒。

Both version run as expected. CPU based version takes about 1500 seconds and GPU version 500 seconds.

然后,我将两个文件合并成单个.cu文件,并控制哪个版本使用标志运行,我发现CPU版本变得更快在.cu文件与所有其他参数和代码保持不变,只需要大约600秒。

I then combine both file into single .cu file, and control which version to run with a flag, and I found the CPU version become faster in .cu file with all other parameters and code stayed the same, it only takes about 600 seconds.

然后我试图运行相同的的c ++代码(无cuda)在空C ++项目和CUDA项目中单独找到的结果一致。 cu版本需要600秒,而cpp一次需要1500秒。

Then I tried to run same pieces of c++ code (without cuda) in Empty C++ project and CUDA project seperately and found the result consistent. The cu version takes 600 seconds while cpp one takes 1500 seconds.

为什么会发生这种情况?这是来自不同的编译器还是VS项目的不同的初始环境?

Why would this happen? Is this come from different compiler or different initial environment of VS project?

推荐答案

nvcc 传递给主机编译器通常不是由程序员编写的 .cu 文件的主机部分的逐字复制。相反, nvcc 解析和预处理代码并向主机编译器发送语义相同的代码(查看作为一部分生成的中间文件 nvcc 编译轨迹将揭示细节)。由于宿主编译器代码生成中的工件,这可能导致宿主代码在合并到 .cu 文件中时运行速度更快或更慢,与独立版本相比, code> .cpp 文件。

Host code that nvcc passes to the host compiler is usually not a verbatim copy of the host portion of the .cu file as written by the programmer. Instead, nvcc parses and pre-processes the code and sends semantically identical code to the host compiler (a look at the intermediate files generated as part of the nvcc compilation trajectory will reveal the details). Due to artifacts in the host compiler's code generation, this could result in host code that runs faster or slower when incorporated into .cu file compared to the stand-alone version in a .cpp file.

通常,结果的性能差异很小,在我的经验中高达约10%。因此,这里报告的非常显着的不同性能差异是上述情况的极端异常值,或者(更可能,在我的观点中)编译中存在其他差异。

Usually, the resulting performance differences are quite small, up to about 10% in my experience. So the very significant different performance difference reported here is either an extreme outlier of the scenario outlined above, or (more likely, in my opionion) there are other differences in the compilation.

例如,不同的编译器选项不同的优化级别,可以作为CUDA编译与独立编译的一部分传递给主机编译器。如果在MSVS中启用编译过程的详细日志,以显示主机编译器调用的详细信息,则应该显而易见是否是这种情况。

For example, different compiler options, e.g. different optimization levels, could have been passed to the host compiler as part of the CUDA compilation vs stand-alone compilation. If you enable a verbose log of the compilation process in MSVS that shows the details of host compiler invocation, it should become apparent whether that is the case.

这篇关于C ++和Cuda速度在Visual studio 2013的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆