简体   繁体   English

在VS 2010中将CUDA代码编译为C ++文件中的二进制文件

[英]compiling CUDA code to binary inside C++ file in VS 2010

I'm working to produce a plugin for a 3d application , this plugin uses that application SDK 我正在努力为3d应用程序生成一个插件,该插件使用该应用程序SDK

in normal cases "personal test projects" , I separate .cu file and make its item type to CUDA C/C++ , and .cpp file to item type C/C++ compiler 在通常情况下的“个人测试项目”中,我将.cu文件分离,并将其项目类型转换为CUDA C / C ++,将.cpp文件转换为项目类型C / C ++编译器

here I want the whole code inside .cpp file and compile it without problems, 在这里,我想要.cpp文件中的整个代码,并且可以毫无问题地对其进行编译,

also I want to make the code (binary) so that I can hide the ptx (or kernels) 我也想使代码(二进制),以便我可以隐藏ptx(或内核)

It's not entirely clear why you want to put CUDA code in a .cpp file. 尚不清楚为什么要将CUDA代码放入.cpp文件中。 If the reason is due to some requirements of the SDK you are using, and you don't want to use nvcc , that won't work. 如果原因是由于您使用的SDK的某些要求,并且您不想使用nvcc ,那将无法正常工作。

If you simply want to allow a .cpp file to contain device code and go through nvcc instead of directly to the host compiler, you can use the -x cu option on your nvcc compile command: 如果您只想允许.cpp文件包含设备代码并通过nvcc而不是直接进入主机编译器,则可以在nvcc编译命令上使用-x cu选项:

nvcc -x cu t264.cpp -o t264

The above command will generate the same executable just as if you had done this: 上面的命令将生成与您执行此操作相同的可执行文件:

nvcc t264.cu -o t264

(assuming t264.cu and t264.cpp were identical files.) (假设t264.cut264.cpp是相同的文件。)

If you want to strip out the ptx, you can compile like this: 如果要去除ptx,可以这样编译:

nvcc  -gencode arch=compute_10,code=sm_10 -gencode arch=compute_20,code=sm_20 -gencode arch=compute_30,code=sm_30 ....

This will tell nvcc to create a fatbinary that contains executable binaries for sm_10, sm_20, or sm_30 devices, but no PTX. 这将告诉nvcc创建一个胖文件,其中包含sm_10,sm_20或sm_30设备的可执行二进制文件,但不包含PTX。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM