久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何在 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))
主站蜘蛛池模板: 国产成人综合网 | 中文字幕av色| 精品在线一区 | 国产中的精品av涩差av | 国产精品免费看 | 久久久久久亚洲 | 欧美日韩在线观看一区 | 91精品国产手机 | 亚洲一二三区不卡 | 欧美成人h版在线观看 | 日韩精品一区二区三区 | 97久久久久久久久 | 欧美国产日本一区 | 日韩乱码av | 欧美日韩国产一区二区三区 | 欧美成人综合 | 国产精品久久久久久久久久久久久久 | 国产精品视频偷伦精品视频 | 福利视频大全 | 国产高清久久久 | 9999精品视频 | 久久一区 | 99国产精品99久久久久久 | 国产一区二区av | 亚洲欧美中文日韩在线v日本 | 97色综合 | 久久精品国产一区 | www.五月婷婷.com | 欧美精品一区二区三区蜜桃视频 | 亚洲三级免费看 | 精品国产色| 久草网站 | 男人的天堂在线视频 | 在线观看免费av网 | 久久精品视频在线免费观看 | 国产精品久久久久久久久图文区 | 99热热 | 久久免费视频1 | 欧美成人一区二区 | 欧美aⅴ| 二区三区在线观看 |