1. 程式人生 > >code::blocks配置編譯cuda並進行第一個demo的測試

code::blocks配置編譯cuda並進行第一個demo的測試

清晰 .html dia 作者 anti 先來 world! 一個 ber

我們先新建個NVCC的編譯器。

技術分享

使用復制GCC編譯器的方式進行新建,然後我們進行下面的路徑配置

技術分享

先來看看鏈接庫,將我們常常使用的cuda庫鏈接進來。

技術分享

然後鏈接cuda的頭文件:

技術分享

接著配置調試工具以及編譯鏈接的工具:

技術分享

然後最重要的就是編輯以下的內容。這樣可以確保你可以編譯過。

技術分享

技術分享

面對這種警告。我們選擇yes就ok。

技術分享

裏面的內容是:

$compiler --compiler-options "$options" $includes -c $file -o $object

圖片僅僅是為了讓大家可以清晰的看到。

選擇Compiler error,然後把regular expression中的內容替換成:

有就是在Output parsing標簽頁中選擇Instantiated from info。然後把Regular expression中的內容替換成:

([][{}() #%$~A-Za-z0-9_:+//.-]+)[(:]([0-9]+)/)?:[ ]+([iI]nstantiated from .*)

這裏不放圖片了,大家看到這裏應該都知道怎樣配置了。

選擇Compiler warning。然後把regular expression中的內容替換成:

([][{}() #%$~A-Za-z0-9_:+//.-]+)[(:]([0-9]+)/)?

:[ ]([Ww]arning:[ ].*)

選擇Compiler error,然後把regular expression中的內容替換成:


([][{}() #%$~A-Za-z0-9_:+//.-]+)[(:]([0-9]+)/)?:[ ](.*)

都 當然別高興太早,這樣還是不夠滴。還須要將.cu的文件增加鏈接和編譯的文件裏。

在左邊項目文件關系樹的.cu文件上點擊右鍵,然後點擊Propertiies

  • 在Build標簽頁中。選中Compile file 和 Link file


技術分享

技術分享

技術分享

#include <stdio.h>
#include <cuda_runtime.h>  //頭文件

//核函數聲明,前面的關鍵字__global__
__global__ void kernel( void ) {
}

int
main( void ) { //核函數的調用。註意<<<1,1>>>,第一個1,代表線程格裏僅僅有一個線程塊。第二個1,代表一個線程塊裏僅僅有一個線程。

kernel<<<1,1>>>(); printf( "Hello, World!\n" ); return 0; }


為了表示我對原作者的尊重附上兩個鏈接:

http://bookc.github.io/2014/05/08/my-summery-the-book-cuda-by-example-an-introduction-to-general-purpose-gpu-programming/

上面是代碼的來源。

以下是配置cuda到code block的文章的來源:

http://benbarsdell.blogspot.com/2009/03/cuda-in-codeblocks-first-things-second.html

歡迎參考。

https://devtalk.nvidia.com/default/topic/411413/c-cuda-integration-with-code-blocks/


code::blocks配置編譯cuda並進行第一個demo的測試