天天看點

CUDA samples 2.3節 用CUDA示例來建立CUDA項目

2.3.1. Creating CUDA Projects for Windows

2.3.2  Creating CUDA Projects for Linux

預設的samples的安裝路徑 <SAMPLES_INSTALL_PATH> 是 NVIDIA_CUDA_5.5_Samples 并且示例程式的分為六類 : 0_Simple,1_Utilities, 2_Graphics, 3_Imaging, 4_Finance, 5_Simulations,6_Advanced, 7_CUDALibraries.

用 NVIDIA CUDA Samples infrastructure構造一個心的CUDA項目很容易。我們提供了一個模闆或者 運作時模闆項目可以直接拷貝修改,滿足使用者的要求。

隻有以下幾個步驟:

    1.拷貝模闆或者運作時模闆項目:

    cd <SAMPLES_INSTALL_PATH>/<category>

    cp -r template <myproject>

    or (using template_runtime):

    cd <SAMPLES_INSTALL_PATH>/<category>

    cp -r template_runtime <myproject>

    2. 把項目中的檔案名改成自己想要的檔案名:

    mv template.cu myproject.cu

    mv template_kernel.cu myproject_kernel.cu

    mv template_gold.cpp myproject_gold.cpp

   or (using template_runtime):

   mv main.cu

   myproject.cu

    3. 編輯Makefile和源檔案.

   隻需要在目錄下的makefile裡找出template和template_runtime,改成自己的項目名稱就可以了。

   4. 建立這個項目 :

    make

    要建立項目并且調試, 用 "make dbg=1":

     make dbg=1

5. 運作這個項目:

    ../../bin/x86_64/linux/release/myproject

6. 調整代碼達到你想要的目标.

    詳細請見CUDA程式設計指南.

2.3.3 Creating CUDA Projects for Mac OS X

繼續閱讀