Cuda Nhapmon

  • View
    15

  • Download
    0

Embed Size (px)

DESCRIPTION

Cuda nhap mon

Text of Cuda Nhapmon

  • Hng Dn Cch Thit Lp D n CUDA Ngo Quoc Vinh

    Kyoto Japan 2008

    1. Cu hnh phn cng v phn mm cn thit

    nh ngha:

    CUDA ngha l Compute Unified Device Architecture l 1 kin trc phn mm v

    phn cng cho mc ch pht trin tnh ton trn GPU. Trong h thng a nhim

    vic s dng GPU trong vic tnh ton (Lp trnh CUDA) v ha c th xy ra ng

    thi.

    Phn mm cn thit:

    Cuda SDK version2.0 c th dng cho windows XP 32-bit hoc 64-bit.

    Trong windows bn cn s dng chng trnh Microsoft Visual C++ 2005 vit 1 d

    n CUDA

    Phn cng cn thit: vit 1 chng trnh CUDA, ngoi cc phn mm h tr ta cn c phn cng

    chng trnh hot ng (khng phi ch m phng)

    Cc thit b phn cng c NVIDIA h tr trong lp trnh cuda, c th tham kho

    tai site: http://www.nvidia.com/object/cuda_learn_products.html (trong trng hp

    trn ch s dng 1 graphics card nu c bn c th s dng nhiu hn 1 graphics

    card).

    Tham kho:

    Ti site ny c th tham kho cc ti liu lien quan n cuda s dng ting anh

    http://forums.nvidia.com/index.php?showtopic=36286

    Ti site ny c th tham kho cc ti liu lien quan n cuda s dng ting nht

    http://www.nvidia.co.jp/object/cuda_home_jp.html.

  • 2. Cch ci t CUDA driver, CUDA tool kit v cuda SDK

    1 chng trnh cuda hot ng c trong mi trng windows xp. Bn cn phi c

    cc th vin h tr. Cc th vin ny c cha trong b SDK do NVIDIA cung cp.

    Cch download CUDA driver

    Driver c download t http://www.nvidia.com/object/cuda_get.html#windows tng

    ng vi s serial ca card. Nu ng ting nht bn c th download ti site:

    http://www.nvidia.co.jp/object/cuda_get_jp.html#windows

    Trong site ny bn chn vo mc NVIDIA driver for Microsoft Windows XP with CUDA

    support (174.55). nu bn dng OS l Windows 32-bit thi chon vo x86 trong muc

    Architecture download (Figure 1).

    Figure 1

    1. Tip theo 1 site NVIDIA Driver Download s xut hin v bn click vo text click

    here download.Figure 2.

    Figure 2

    Hp thoi File Download xut hin v bn click Save. Figure 3.

    Save

    Figure 3

  • 2. hp thoi Save As hin th ra hi bn ni mun save file driver, lc ny bn

    chn ng dn ni mun save file v click Save (Figure 4). Ch 1 thi gian

    chng trnh t dng download file c hon tt.

    Figure 4

    Cch ci t CUDA driver.

    Sau khi download xong, bn double click vo file *.exe download ( v d trong

    trng hp ny l file 169.21_forceware_winxp_32bit_english_whql dung cho

    Geforce8800GT, Operation System Window XP, language English(US)).

    Tip theo bn chn I accept the terms in the license agreement ri click Next.

    Chng trnh s ni m bn mun ci chng trnh. Theo ti bn nn mc nh

    c:\NVIDIA\Win2k\169.21\English (Figure 5)

    Figure 5

    Click Next chng trnh load cc file cn ci t,

    Click Next chng trnh ci t t ng (Figure 6).

    Figure 6

    Ch trong giy lt, sau khi chng trnh ci t xong bn click Finish khi ng

    my li.

  • Download file SDK v Toolkit.

    Sau khi ci dat driver cho card ban cn phi ci b cng c h tr lp trnh cho

    CUDA

    Bn cn download 2 file NVIDIA_CUDA_Toolkit_1.0.exe v

    NVIDIA_CUDA_SKD_1.0.exe ti site

    http://www.nvidia.com/object/cuda_get.html#windows . ty thuc vo OS ca my bn

    l 32 hay 64-bit (nu 32-bit bn chn Architecture l x86 v nu l 64-bit bn chon

    x86-64) (hinh 4.1).Cch download 2 file ny hon ton ging nhau.

    Sau khi click vo kiu Architecture, mt site mi s xut hin tip theo bn click vo

    click here download file. thc h in download file bn thc hin cc bc 1,2,3

    ca mc 4.1.1

    Ci t CUDA Toolkit.

    NVIDIA_CUDA_Toolkit_1.0.exe file ny cha cng c cc th vin h tr trong lp trnh

    cuda v cc ti liu hng dn lp trnh.

    Cch install file Toolkit.

    Sau khi download file NVIDIA_CUDA_Toolkit_1.0.exe (hoc mi hn) bn double

    click vo file ny ci t vo h thng. sau khi double click vo file ny th chng

    trnh ci t t ng Install Shied Wizard s c kch hot.

    Click button Next ci t chng trnh. Tip theo bn chn I accept the terms of

    license Agrement v click Next (hnh 4.10), lc ny chng trinh s hi ni bn mun

    ci t (theo ti bn nn ch default C:\CUDA)

    Figure 7

    Click Next tip tc qua bc tip theo. Bn click Install ci t phn mm

    sau khi qua cc bc m chng trnh Install Shied Wizard hng dn. ch 1

    vi pht sau khi chng trnh ci t xong bn click Finish kt thc vic ci t.

    Ci t SDK NVIDIA_CUDA_SKD_1.0.exe y l b SDK ca NVIDIA. Trong file ny sau khi ci t

    s cha cc d n mu. cc d n ny rt quan trng trong vic t nghin cu ca

    ban.

    1. Sau khi download file NVIDIA_CUDA_SDK_1.0.exe (ho mi hn) bn double

    click vo file ny ci t vo h thng. sau khi double click vo file ny th chng

    trnh ci t t ng Install Shied Wizard s c kch hot.

  • 2. Click button Next ci t chng trnh. Tip theo bn chn I accept the

    terms of license Agrement v click Next.bc ny c thc hin tng t bc 2

    ca cch install file Toolkit.

    3. Chng trinh s hi mt s thng tin ca bn. Bn cn phi in tn vo

    textbox Name. in tn cng ty hoc t chc vo Textbox Organization, v in

    a ch Email ca bn vo Email(Optional).(Figure 8)

    NameOrganization

    Email

    Next

    Figure 8

    4. Click Next tip tc. chng trnh s yu cu bn ch r ni bn mun ci

    t (theo ti bn nn ch default C:\Program Files\NVIDIA

    Corporation\NVIDIA CUDA SDK) ri click Next tip tc qua bc tip theo.

    5. Click Install ci t phn mm sau khi qua cc bc m chng trnh

    Install Shied Wizard hng dn. ch 1 vi pht sau khi chng trnh ci t

    xong bn click Finish kt thc vic ci t.

    Hu ht cc chng trnh cuda mu c NVIDIA cung cp chy trn nn Visual C++.

    V th bn cn phi c phn mm Microsoft Visual C++, c th dng bng Microsoft

    Visual Studio C++ Express,c cung cp min ph.

    Sau khi hon tt vic ci t, bn c th m d n mu deviceQuery ca NVIDIA

    cung cp trong C:\Program Files\NVIDIA Corporation\NVIDIA CUDA

    SDK\bin\win32\Release v chy th, nu thnh cng chng trnh s hin th cu

    hnh card GPU ca bn v hin th thong bo TEST

    3. Cch ci t chng trnh Visual profiler

    Visual profiler c cung cp bi NVIDIA dng phn tch v nh gi 1 chng trnh

    cuda.

    Download visual profiler t site: http://www.nvidia.com/object/cuda_get.html#windows.

    Trong site ny bn s tm thy dng text Cuda Visual Profiler trong bng Cuda for

    Windows(hnh 4.9).

    Vic download chng trnh ny tng t nh bc 7,8,9 ca mc 4.1.1.

    Sau bn extract file CudaVisualProfiler_0.2_beta_windows.zip

    Sau khi extract s xut hin folder CudaVisualProfiler trong cha 2 folders bin v

    Projects.

    Folder project s cha thng tin ca 1 d n cuda sau khi c phn tch.

  • Folder bin cha cc file *.dll v 1 file cudaprof.exe y l file chng trnh Cuda

    Visual Profiler.

    Chy chng trnh Cuda Visual Profiler bng cch double click vo file cudaprof.exe

    (Figure 9).

    Figure 9

    Chng trnh ny s hot ng m khng cn phi ci t.

    4. To highlighting cho syntax ca 1 file cuda (*.cu)

    1 file ngun cuda c m rng bng *.cu. nu bn dng Microsoft Visual C++ m

    file ny th n s hin th dng file text (s khng trc quan bi v cc bin, tu kha u

    l mu en.) tng kh nng trc quan cho chng rnh d quan st. NVIDIA cung

    cp 1 file nhng vo Microsoft Visual C++ file *.cu hin th trc quan di Microsoft

    Visual C++ nh 1 file *.cpp.

    1. Bn vo ng dn C:\Program Files\NVIDIA CUDA

    SDK\doc\syntax_highlighting\visual_studio_8 v copy file

    usertype.dat vo C:\Program Files\Microsoft Visual Studio 8\Common7\IDE.

    2. Tip theo bn vo menu tool ->options trong hp thoi Options bn vo Text

    Editor->File Extension (hnh 4.15).

    Pha bn phi hp thoi trong Extension: text bn g vo cu (tn m rng ca

    chng trnh cuda)

    3. Tip theo trong listbox Editor: bn chn Microsoft Visual C++ (mi trng hot

    ng ca cuda file).

    Sau bn click button Apply and then click OK.khi ng li Microsoft Visual

    studio hon tt (Figure 10).

  • (2)(3)

    Figure 10

    By gi bn hon tt vic lm highlighting 1 file *.cu, lm chng trnh sang sa d

    c hn

    5. Cch thit lp 1 d n CUDA trn Microsoft Visual C++ 2005

    Nhng phn trc gii thiu cc ci t lien quan n 1 d n CUDA.trong mc 4.4 gii

    thiu cch hot ng 1 chng trnh mu c NVIDIA SDK cung cp km theo. Tuy nhin

    bn c th chy bt c chng trnh mu no ca NVIDIA SDK cung cp.

    Trong phn ny s ch ra phng php to t mnh to ra 1 d n CUDA.

    n gin ta s to 1 d n console

    M Microsoft Visual C++, vo menu File->New->Project hp thoi New Project

    hin th bn vo Visual C++->Win32 sau chn Win32 Console Application.

    Bn c th t tn cho d n l CudaStep1 v solution CudaProgram. Sau

    bn click OK->Next->Finish. Cho n thi im ny bn c 1 d n console

    nhng cha phi l d n cuda (Figure 11).

    Figure 11

    Vo ca s Solution Explorer click phi vo Header Files->Add->New Item

    hp thoi Add new Item- CudaStep1 hin th. Tip theo bn vo Visual C++-

    >Code chn Header File(.h) v t tn CudaHeader.h ri click Add (Figure 12).

    File ny s cha thng tin v cu hnh ca chng trnh cuda v prototype ca

    cc hm kernel m bn s vit.

  • Name

    Figure 12

    Tip theo cn to 1 file cha m ngun cho 1 chng trnh cuda, file ny s c

    m rng bng .cu tng t nh bc 2 bn

    vo ca s Solution Explorer click phi vo Header Files->Add->New Item hp

    thoi Add new Item- CudaStep1 hin th. Tip theo bn vo Visual C++->Utility

    chn Text File (.txt) v t tn l CudaFunction.cu ri click Add.

    Cho n lc ny bn to ra 1 d n cud