pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

如何在 Visual Studio 2008 中啟動新的 CUDA 項目?

How do I start a new CUDA project in Visual Studio 2008?(如何在 Visual Studio 2008 中啟動新的 CUDA 項目?)
本文介紹了如何在 Visual Studio 2008 中啟動新的 CUDA 項目?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

這是一個非常基本的問題,但如何在 Visual Studio 2008 中啟動一個新的 CUDA 項目?我找到了大量關于 CUDA 相關問題的文檔,但沒有找到關于如何開始一個新項目的文檔.我正在使用 Windows 7 x64 Visual Studio 2008 C++.我真的很想找到某種非常非常基本的 Hello World 應用程序來編譯和運行基本程序.

我試過你的步驟湯姆.我設置了一個控制臺應用程序.然后我刪除了它放入的默認 .cpp 并復制了模板項目中的三個文件,只是為了編譯一些東西.當我編譯它時,template_gold.cpp 抱怨沒有包含 stdafx.h,所以我包含了它.現在構建失敗了:

<前>1>------ 構建開始:項目:CUDASandbox,配置:調試 x64 ------1>編譯...1>template_gold.cpp1>鏈接...1>LIBCMT.lib(crt0.obj): 錯誤 LNK2019: 函數 __tmainCRTStartup 中引用的未解析的外部符號 main1>D:StuffProgrammingVisual Studio 2008ProjectsCUDASandboxx64DebugCUDASandbox.exe:致命錯誤 LNK1120:1 個未解析的外部1>構建日志保存在file://d:StuffProgrammingVisual Studio 2008ProjectsCUDASandboxCUDASandboxx64DebugBuildLog.htm"1>CUDASandbox - 2 個錯誤,0 個警告========== 構建:0 成功,1 失敗,0 最新,0 跳過 ==========

解決方案

注意 隨著 CUDA Toolkit 3.2 版的發布,NVIDIA 現在包含了 rules 文件與 Toolkit 而不是 SDK.因此,我將這個答案分為兩部分,請使用適用于您的 Toolkit 版本的正確說明.

注意這些說明適用于 Visual Studio 2005 和 2008.對于 Visual Studio 2010,請參閱 這個答案.

<小時>

CUDA TOOLKIT 3.2 及更高版本

我推薦使用NVIDIA提供的NvCudaRuntimeApi.rules文件(或者NvCudaDriverApi.rules如果使用驅動API),這是隨工具包發布的,支持最新的編譯器以友好的方式標記.我個人建議不要使用 VS 向導,但這只是因為我真的認為您不需要它.

規則文件(安裝在 Program FilesMicrosoft Visual Studio 9.0VCVCProjectDefaults 目錄中)教導"Visual Studio 如何編譯項目中的任何 .cu 文件并將其鏈接到應用程序中.

  • 使用標準 MS 向導創建一個新項目(例如一個空的控制臺項目)
  • 在 .c 或 .cpp 文件中實現您的主機(串行)代碼
  • 在 .cu 文件中實現包裝器和內核
  • 添加NvCudaRuntimeApi.rules(右擊項目,自定義構建規則,勾選相關框),見注釋1
  • 添加 CUDA 運行時庫(右鍵單擊項目并選擇 Properties,然后在 Linker -> General 中添加 $(CUDA_PATH)lib$(PlatformName)Additional Library Directory 并在 Linker -> Input 中將 cudart.lib 添加到 Additional Dependencies),見注釋 [2] 和 [3]
  • 可選擇將 CUDA 包含文件添加到搜索路徑,如果您在 .cpp 文件(而不是 .cu 文件)中包含任何 CUDA 文件,則需要(右鍵單擊項目并選擇屬性,然后在 C/C++ -> General 中將 $(CUDA_PATH)include 添加到 Additional Include Directories),參見注釋 [3]
  • 然后只需構建您的項目,.cu 文件將被編譯為 .obj 并自動添加到鏈接中

其他一些提示:

  • 更改代碼生成以使用靜態加載的 C 運行時以匹配 CUDA 運行時;右鍵單擊項目并選擇 Properties,然后在 C/C++ -> Code Generation 中將 Runtime Library 更改為/MT(或/MTd對于調試,在這種情況下,您需要在 Runtime API -> Host -> Runtime Library 中進行鏡像,請參閱注釋 [4]
  • 使用 SDK 附帶的 usertype.dat 文件啟用語法高亮,請參閱 <sdk_install_dir>Cdocsyntax_highlightingvisual_studio_8
  • 中的 readme.txt

我還建議使用以下注冊表項啟用 Intellisense 支持(將 9.0 替換為 VS2005 而不是 VS2008 的 8.0):

[HKEY_CURRENT_USERSoftwareMicrosoftVisualStudio9.0LanguagesLanguage ServicesC/C++]"NCB 默認 C/C++ 擴展"=".cpp;.cxx;.c;.cc;.h;.hh;.hxx;.hpp;.inl;.tlh;.tli;.cu;.cuh;.CL"

順便說一句,如果可能的話,我會提倡避免cutil,而是自己進行檢查.Cutil 不受 NVIDIA 支持,它只是用來嘗試使 SDK 中的示例專注于實際程序和算法設計,并避免在每個示例中重復相同的事情(例如命令行解析).如果您自己編寫,那么您將有更好的控制權,并且會知道發生了什么.例如,如果函數失敗,cutilSafeCall 包裝器會調用 exit() - 真正的應用程序(而不是示例)可能應該更優雅地處理失敗!

<小時>

CUDA TOOLKIT 3.1 及更早版本

我會將 NVIDIA 提供的 Cuda.rules 文件與 SDK 一起使用,它與工具包一起發布,并以友好的方式支持最新的編譯器標志.我個人建議不要使用 VS 向導,但這只是因為我真的認為您不需要它.

規則文件(位于 SDK 的 Ccommon 目錄中)教導"Visual Studio 如何編譯項目中的任何 .cu 文件并將其鏈接到應用程序中.

  • 使用標準 MS 向導創建一個新項目(例如一個空的控制臺項目)
  • 在 .c 或 .cpp 文件中實現您的主機(串行)代碼
  • 在 .cu 文件中實現包裝器和內核
  • 添加Cuda.rules(右鍵單擊項目,自定義構建規則,瀏覽規則文件并確保勾選)
  • 添加 CUDA 運行時庫(右鍵單擊項目并選擇 Properties,然后在 Linker -> General 中添加 $(CUDA_LIB_PATH)Additional Library Directory 并在 Linker -> Input 中添加 cudart.libAdditional Dependencies),見請注意下面的 [2]
  • 可選擇將 CUDA 包含文件添加到搜索路徑,如果您在 .cpp 文件(而不是 .cu 文件)中包含任何 CUDA 文件,則需要(右鍵單擊項目并選擇屬性,然后在 C/C++ -> General 中將 $(CUDA_INC_PATH) 添加到 Additional Include Directories)
  • 然后只需構建您的項目,.cu 文件將被編譯為 .obj 并自動添加到鏈接中

其他一些提示:

  • 將代碼生成更改為使用靜態加載的 C 運行時以匹配 CUDA 運行時,右鍵單擊項目并選擇屬性,然后在 C/C++ -> 代碼生成Runtime Library 更改為/MT(或/MTd 用于調試,在這種情況下,您需要在 CUDA Build Rule -> Hybrid CUDA/C++ Options 中進行鏡像), 見注釋 [4]
  • 使用 SDK 附帶的 usertype.dat 文件啟用語法高亮,請參閱 <sdk_install_dir>Cdocsyntax_highlightingvisual_studio_8
  • 中的 readme.txt

我還建議使用以下注冊表項啟用 Intellisense 支持(將 9.0 替換為 VS2005 而不是 VS2008 的 8.0):

[HKEY_CURRENT_USERSoftwareMicrosoftVisualStudio9.0LanguagesLanguage ServicesC/C++]"NCB 默認 C/C++ 擴展"=".cpp;.cxx;.c;.cc;.h;.hh;.hxx;.hpp;.inl;.tlh;.tli;.cu;.cuh;.CL"

順便說一句,如果可能的話,我會提倡避免cutil,而是自己進行檢查.Cutil 不受 NVIDIA 支持,它只是用來嘗試使 SDK 中的示例專注于實際程序和算法設計,并避免在每個示例中重復相同的事情(例如命令行解析).如果您自己編寫,那么您將有更好的控制權,并且會知道發生了什么.例如,如果函數失敗,cutilSafeCall 包裝器會調用 exit() - 真正的應用程序(而不是示例)可能應該更優雅地處理失敗!

<小時>

注意

  1. 您還可以使用特定于 Toolkit 版本的規則,例如NvCudaRuntimeApi.v3.2.rules.這意味著不是在 %CUDA_PATH% 中查找 CUDA Toolkit,而是在 %CUDA_PATH_V3_2% 中查找,這反過來意味著您可以在您的系統上安裝多個版本的 CUDA Toolkit,并且不同的項目可以針對不同的版本.另見注釋 [3].
  2. 規則文件無法修改 C/C++ 編譯和鏈接器設置,因為它只是為 CUDA 代碼添加編譯設置.因此,您需要手動執行此步驟.請記住對所有配置都執行此操作!
  3. 如果您想在特定的 CUDA Toolkit 版本上保持穩定,那么您應該將 CUDA_PATH 替換為 CUDA_PATH_V3_2.另請參閱注釋 1.
  4. C 運行時版本不匹配會導致各種問題;特別是如果您有任何關于 LIBCMT 的錯誤(例如 LNK4098: defaultlib 'LIBCMT' 與其他庫的使用發生沖突)或標準庫函數的多重定義符號,那么這應該是您的第一個懷疑對象.莉>

This is an incredibly basic question, but how do I start a new CUDA project in Visual Studio 2008? I have found tons and tons of documentation about CUDA related matters, but nothing about how to start a new project. I am working with Windows 7 x64 Visual Studio 2008 C++. I would really like to find some sort of really really basic Hello World app to just get a basic program compiling and running.

Edit:

I tried your steps Tom. I setup a console app. I then deleted the default .cpp it drops in and copied over the three files from the template project just to have something to compile. When I compile that, template_gold.cpp complained about not having stdafx.h included, so i included that. Now the build fails with this:

1>------ Build started: Project: CUDASandbox, Configuration: Debug x64 ------
1>Compiling...
1>template_gold.cpp
1>Linking...
1>LIBCMT.lib(crt0.obj) : error LNK2019: unresolved external symbol main referenced in function __tmainCRTStartup
1>D:StuffProgrammingVisual Studio 2008ProjectsCUDASandboxx64DebugCUDASandbox.exe : fatal error LNK1120: 1 unresolved externals
1>Build log was saved at "file://d:StuffProgrammingVisual Studio 2008ProjectsCUDASandboxCUDASandboxx64DebugBuildLog.htm"
1>CUDASandbox - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

解決方案

NOTE With the release of version 3.2 of the CUDA Toolkit, NVIDIA now includes the rules file with the Toolkit as opposed to the SDK. Therefore I've split this answer into two halves, use the correct instructions for your version of the Toolkit.

NOTE These instructions are valid for Visual Studio 2005 and 2008. For Visual Studio 2010 see this answer.


CUDA TOOLKIT 3.2 and later

I recommend using the NvCudaRuntimeApi.rules file (or NvCudaDriverApi.rules if using the driver API) provided by NVIDIA, this is released with the toolkit and supports the latest compiler flags in a friendly manner. Personally I would advise against using the VS wizard, but only because I really don't think you need it.

The rules file (installed into the Program FilesMicrosoft Visual Studio 9.0VCVCProjectDefaults directory) "teaches" Visual Studio how to compile and link any .cu files in your project into your application.

  • Create a new project using the standard MS wizards (e.g. an empty console project)
  • Implement your host (serial) code in .c or .cpp files
  • Implement your wrappers and kernels in .cu files
  • Add the NvCudaRuntimeApi.rules (right click on the project, Custom Build Rules, tick the relevant box), see note 1
  • Add the CUDA runtime library (right click on the project and choose Properties, then in Linker -> General add $(CUDA_PATH)lib$(PlatformName) to the Additional Library Directories and in Linker -> Input add cudart.lib to the Additional Dependencies), see notes [2] and [3]
  • Optionally add the CUDA include files to the search path, required if you include any CUDA files in your .cpp files (as opposed to .cu files) (right click on the project and choose Properties, then in C/C++ -> General add $(CUDA_PATH)include to the Additional Include Directories), see note [3]
  • Then just build your project and the .cu files will be compiled to .obj and added to the link automatically

Some other tips:

  • Change the code generation to use statically loaded C runtime to match the CUDA runtime; right click on the project and choose Properties, then in C/C++ -> Code Generation change the Runtime Library to /MT (or /MTd for debug, in which case you will need to mirror this in Runtime API -> Host -> Runtime Library), see note [4]
  • Enable syntax highlighting using the usertype.dat file included with the SDK, see the readme.txt in <sdk_install_dir>Cdocsyntax_highlightingvisual_studio_8

I'd also recommend enabling Intellisense support with the following registry entry (replace 9.0 with 8.0 for VS2005 instead of VS2008):

[HKEY_CURRENT_USERSoftwareMicrosoftVisualStudio9.0LanguagesLanguage ServicesC/C++]
"NCB Default C/C++ Extensions"=".cpp;.cxx;.c;.cc;.h;.hh;.hxx;.hpp;.inl;.tlh;.tli;.cu;.cuh;.cl"

Incidentally I would advocate avoiding cutil if possible, instead roll your own checking. Cutil is not supported by NVIDIA, it's just used to try to keep the examples in the SDK focussed on the actual program and algorithm design and avoid repeating the same things in every example (e.g. command line parsing). If you write your own then you will have much better control and will know what is happening. For example, the cutilSafeCall wrapper calls exit() if the function fails - a real application (as opposed to a sample) should probably handle the failure more elegantly!


CUDA TOOLKIT 3.1 and earlier

I would use the Cuda.rules file provided by NVIDIA with the SDK, this is released alongside the toolkit and supports the latest compiler flags in a friendly manner. Personally I would advise against using the VS wizard, but only because I really don't think you need it.

The rules file (in the Ccommon directory of the SDK) "teaches" Visual Studio how to compile and link any .cu files in your project into your application.

  • Create a new project using the standard MS wizards (e.g. an empty console project)
  • Implement your host (serial) code in .c or .cpp files
  • Implement your wrappers and kernels in .cu files
  • Add the Cuda.rules (right click on the project, Custom Build Rules, browse for the rules file and ensure it is ticked)
  • Add the CUDA runtime library (right click on the project and choose Properties, then in Linker -> General add $(CUDA_LIB_PATH) to the Additional Library Directories and in Linker -> Input add cudart.lib to the Additional Dependencies), see note [2] below
  • Optionally add the CUDA include files to the search path, required if you include any CUDA files in your .cpp files (as opposed to .cu files) (right click on the project and choose Properties, then in C/C++ -> General add $(CUDA_INC_PATH) to the Additional Include Directories)
  • Then just build your project and the .cu files will be compiled to .obj and added to the link automatically

Some other tips:

  • Change the code generation to use statically loaded C runtime to match the CUDA runtime, right click on the project and choose Properties, then in C/C++ -> Code Generation change the Runtime Library to /MT (or /MTd for debug, in which case you will need to mirror this in CUDA Build Rule -> Hybrid CUDA/C++ Options), see note [4]
  • Enable syntax highlighting using the usertype.dat file included with the SDK, see the readme.txt in <sdk_install_dir>Cdocsyntax_highlightingvisual_studio_8

I'd also recommend enabling Intellisense support with the following registry entry (replace 9.0 with 8.0 for VS2005 instead of VS2008):

[HKEY_CURRENT_USERSoftwareMicrosoftVisualStudio9.0LanguagesLanguage ServicesC/C++]
"NCB Default C/C++ Extensions"=".cpp;.cxx;.c;.cc;.h;.hh;.hxx;.hpp;.inl;.tlh;.tli;.cu;.cuh;.cl"

Incidentally I would advocate avoiding cutil if possible, instead roll your own checking. Cutil is not supported by NVIDIA, it's just used to try to keep the examples in the SDK focussed on the actual program and algorithm design and avoid repeating the same things in every example (e.g. command line parsing). If you write your own then you will have much better control and will know what is happening. For example, the cutilSafeCall wrapper calls exit() if the function fails - a real application (as opposed to a sample) should probably handle the failure more elegantly!


NOTE

  1. You can also use a Toolkit-version-specific rules fule e.g. NvCudaRuntimeApi.v3.2.rules. This means that instead of looking for the CUDA Toolkit in %CUDA_PATH% it will look in %CUDA_PATH_V3_2%, which in turn means that you can have multiple versions of the CUDA Toolkit installed on your system and different projects can target different versions. See also note [3].
  2. The rules file cannot modify the C/C++ compilation and linker settings, since it is simply adding compilation settings for the CUDA code. Therefore you need to do this step manually. Remember to do it for all configurations!
  3. If you want to stabilise on a specific CUDA Toolkit version then you should replace CUDA_PATH with CUDA_PATH_V3_2. See also note 1.
  4. Having mismatched version of the C runtime can cause a variety of problems; in particular if you have any errors regarding LIBCMT (e.g. LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs) or multiply defined symbols for standard library functions, then this should be your first suspect.

這篇關于如何在 Visual Studio 2008 中啟動新的 CUDA 項目?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How do I set the icon for my application in visual studio 2008?(如何在 Visual Studio 2008 中為我的應用程序設置圖標?)
Convert CString to const char*(將 CString 轉換為 const char*)
Remove secure warnings (_CRT_SECURE_NO_WARNINGS) from projects by default in Visual Studio(默認情況下,在 Visual Studio 中從項目中刪除安全警告 (_CRT_SECURE_NO_WARNINGS))
Exporting classes containing `std::` objects (vector, map etc.) from a DLL(從 DLL 導出包含 `std::` 對象(向量、映射等)的類)
What are some reasons a Release build would run differently than a Debug build(發布版本與調試版本的運行方式不同的一些原因是什么)
How to set up Google C++ Testing Framework (gtest) with Visual Studio 2005(如何使用 Visual Studio 2005 設置 Google C++ 測試框架 (gtest))
主站蜘蛛池模板: H型钢切割机,相贯线切割机,数控钻床,数控平面钻,钢结构设备,槽钢切割机,角钢切割机,翻转机,拼焊矫一体机 | 空调风机,低噪声离心式通风机,不锈钢防爆风机,前倾皮带传动风机,后倾空调风机-山东捷风风机有限公司 | 深圳市源和塑胶电子有限公司-首页 | 365文案网_全网创意文案句子素材站 | 福建自考_福建自学考试网| 紧急切断阀_气动切断阀_不锈钢阀门_截止阀_球阀_蝶阀_闸阀-上海上兆阀门制造有限公司 | 菏泽商标注册_菏泽版权登记_商标申请代理_菏泽商标注册去哪里 | 法兰连接型电磁流量计-蒸汽孔板节流装置流量计-北京凯安达仪器仪表有限公司 | 河北中仪伟创试验仪器有限公司是专业生产沥青,土工,水泥,混凝土等试验仪器的厂家,咨询电话:13373070969 | 便携式XPDM露点仪-在线式防爆露点仪-增强型烟气分析仪-约克仪器 冰雕-冰雪世界-大型冰雕展制作公司-赛北冰雕官网 | 山东锐智科电检测仪器有限公司_超声波测厚仪,涂层测厚仪,里氏硬度计,电火花检漏仪,地下管线探测仪 | 重庆监控_电子围栏设备安装公司_门禁停车场管理系统-劲浪科技公司 | 万烁建筑设计院-建筑设计公司加盟,设计院加盟分公司,市政设计加盟 | 粘度计NDJ-5S,粘度计NDJ-8S,越平水分测定仪-上海右一仪器有限公司 | 江西高职单独招生-江西单招考试-江西高职单招网 | 【连江县榕彩涂料有限公司】官方网站| 武汉刮刮奖_刮刮卡印刷厂_为企业提供门票印刷_武汉合格证印刷_现金劵代金券印刷制作 - 武汉泽雅印刷有限公司 | 广州活动策划公司-15+年专业大型公关活动策划执行管理经验-睿阳广告 | 钢托盘,钢制托盘,立库钢托盘,金属托盘制造商_南京飞天金属制品实业有限公司 | 2025世界机器人大会_IC China_半导体展_集成电路博览会_智能制造展览网 | 手持式线材张力计-套帽式风量罩-深圳市欧亚精密仪器有限公司 | 月嫂_保姆_育婴_催乳_母婴护理_产后康复_养老护理-吉祥到家家政 硫酸亚铁-聚合硫酸铁-除氟除磷剂-复合碳源-污水处理药剂厂家—长隆科技 | Maneurop/美优乐压缩机,活塞压缩机,型号规格,技术参数,尺寸图片,价格经销商 | 煤矿支护网片_矿用勾花菱形网_缝管式_管缝式锚杆-邯郸市永年区志涛工矿配件有限公司 | 定做大型恒温循环水浴槽-工业用不锈钢恒温水箱-大容量低温恒温水槽-常州精达仪器 | Dataforth隔离信号调理模块-信号放大模块-加速度振动传感器-北京康泰电子有限公司 | 欧美日韩国产一区二区三区不_久久久久国产精品无码不卡_亚洲欧洲美洲无码精品AV_精品一区美女视频_日韩黄色性爱一级视频_日本五十路人妻斩_国产99视频免费精品是看4_亚洲中文字幕无码一二三四区_国产小萍萍挤奶喷奶水_亚洲另类精品无码在线一区 | 深圳富泰鑫五金_五金冲压件加工_五金配件加工_精密零件加工厂 | 手表腕表维修保养鉴定售后服务中心网点 - 名表维修保养 | 半自动预灌装机,卡式瓶灌装机,注射器灌装机,给药器灌装机,大输液灌装机,西林瓶灌装机-长沙一星制药机械有限公司 | 工业机械三维动画制作 环保设备原理三维演示动画 自动化装配产线三维动画制作公司-南京燃动数字 聚合氯化铝_喷雾聚氯化铝_聚合氯化铝铁厂家_郑州亿升化工有限公司 | 壹车网 | 第一时间提供新车_资讯_报价_图片_排行! | 骨灰存放架|骨灰盒寄存架|骨灰架厂家|智慧殡葬|公墓陵园管理系统|网上祭奠|告别厅智能化-厦门慈愿科技 | 恒湿机_除湿加湿一体机_恒湿净化消毒一体机厂家-杭州英腾电器有限公司 | 山东艾德实业有限公司| 集装袋吨袋生产厂家-噸袋廠傢-塑料编织袋-纸塑复合袋-二手吨袋-太空袋-曹县建烨包装 | 河北码上网络科技|邯郸小程序开发|邯郸微信开发|邯郸网站建设 | 玻璃钢板-玻璃钢防腐瓦-玻璃钢材料-广东壹诺 | 湖州织里童装_女童男童中大童装_款式多尺码全_织里儿童网【官网】-嘉兴嘉乐网络科技有限公司 | 石膏基自流平砂浆厂家-高强石膏基保温隔声自流平-轻质抹灰石膏粉砂浆批发-永康市汇利建设有限公司 | 无菌实验室规划装修设计-一体化实验室承包-北京洁净净化工程建设施工-北京航天科恩实验室装备工程技术有限公司 |