GPU&VS2012&CUDA&matlab&Arrayfire杂记(七)——MFC语言与CUDA

来源:互联网 发布:mac谷歌插件安装 编辑:程序博客网 时间:2024/06/07 14:14


CUDA 与 MFC

环境:vista,vs2005,cuda2.0

前提工作:创建一个MFC工程,本例名称为cudaexam

说明:本文件中的方法仅仅是向导之一,且没有进行并行优化工作。

步骤:

1,  创建全局函数与头文件

1.1头文件

1.2函数

1.3然后查看类视图

2,  创建一个存放cuda代码的筛选器,本程序名称为cuda

2.1

2.2

3,  在筛选器cuda中创建一个cuda源代码文件,first.cu

 

 

4,  在first.cu中创建一个c扩展函数:runtest()

5,  在筛选器cuda中创建另一个cuda源代码文件:first_kernel.cu,在该函数中创建一个GPU核心函数kernel(),该函数编译后在GPU运行

 

6,  修改runtest()函数,从中调用函数kernel()

 

7,  在全局函数globalapi.cpp中添加一个c扩展函数runtest()的说明,并在global.cpp中创建一个函数testcuda(),从中调用runtest()

 

8,  修改first.cu的编译链接设置

8.1打开其属性窗口

8.2修改常规设置

8.3修改自定义生成步骤

8.3.1设置自定义生成步骤->命令行

命令行的设置可以参考http://blog.zol.com.cn/812/article_811728.html或者CUDA SDK的例子。

 

8.3.2设置自定义生成步骤->输出

 

8.3.3设置自定义生成步骤->附加依赖项

 

9,  修改工程的编译链接设置

9.1 cudaexam属性页->配置属性->连接器->常规

9.2 cudaexam属性页->配置属性->连接器->输入

 

 

我的联系方式:caoweiguo76@gmail.com

msn:caoweiguo@hotmail.com

 

 

 

曹伟国

中科院计算所

2009.3

命令行设置:

1.      Debug: "$(CUDA_BIN_PATH)\nvcc.exe"-ccbin "$(VCInstallDir)bin" -c -D_DEBUG -DWIN32 -D_CONSOLE -D_MBCS-Xcompiler /EHsc,/W3,/nologo,/Wp64,/Od,/Zi,/RTC1,/MTd-I"$(CUDA_INC_PATH)" -I./ -I../../common/inc -o$(ConfigurationName)\first.obj first.cu

2.      Release: "$(CUDA_BIN_PATH)\nvcc.exe"-ccbin "$(VCInstallDir)bin" -c -DWIN32 -D_CONSOLE -D_MBCS -Xcompiler/EHsc,/W3,/nologo,/Wp64,/O2,/Zi,/MT -I"$(CUDA_INC_PATH)" -I./-I../../common/inc -o $(ConfigurationName)\first.obj first.cu

3.      EmuDebug: "$(CUDA_BIN_PATH)\nvcc.exe"-ccbin "$(VCInstallDir)bin" -c -deviceemu -D_DEBUG -DWIN32 -D_CONSOLE-D_MBCS -Xcompiler /EHsc,/W3,/nologo,/Wp64,/Od,/Zi,/RTC1,/MTd-I"$(CUDA_INC_PATH)" -I./ -I../../common/inc -o$(ConfigurationName)\first.obj first.cu

4.      EmuRelease: "$(CUDA_BIN_PATH)\nvcc.exe"-ccbin "$(VCInstallDir)bin" -c -deviceemu -c -DWIN32 -D_CONSOLE-D_MBCS -Xcompiler /EHsc,/W3,/nologo,/Wp64,/O2,/Zi,/MT-I"$(CUDA_INC_PATH)" -I./ -I../../common/inc -o$(ConfigurationName)\first.obj first.cu

 

first.cu>>custombuild step>>general:

command line:见上(4种)

outputs: $(ConfigurationName)\first.obj

Add Dep: first_kernel.cu

 

Properties>>configproper>>Linker>>General:

   Enable Incr Linking : No (/INCREMENTAL:NO)

   Add Library Direct : $(CUDA_LIB_PATH);../../common/lib

 

Properties>>configproper>>Linker>>Input:

  Add Depend : cudart.lib

 

Properties>>configproper>>Linker>>Debugging:

  Generate Debug Info : [ALL] Yes (/DEBUG)

                       

Properties>>configproper>>Linker>>System:

    SubSystem:  [ALL] Windows(/SUBSYSTEM:WINDOWS)

转载http://wenku.baidu.com/link?url=DrQ3tPxhm6o9eDL1TpU8ASNZmtfgXpO4NHfA7rtLRD18IkpjWchI0aXNPSEvVoFIy-LyyRQ4FO86GmCB5ZGxRn9J_Q_NPM3pgUz5O_d-ZZC 曹伟国先生

 

0 0