Project

General

Profile

Install local NVIDIA GPU Computing SDK

download a cuda toolkit on cluck

install CUDA SDK on cluck

  • setup cuda environment
    export PATH=${PATH}:/usr/local/cuda/bin  
    export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/cuda/lib64:/usr/local/cuda/lib
    
  • run the binary and hit the return key for install pathes with default or give your preferred path
    chmod +x gpucomputingsdk_4.0.17_linux.run
    ./gpucomputingsdk_4.0.17_linux.run
    ......
    Enter install path (default ~/NVIDIA_GPU_Computing_SDK):
    Enter CUDA install path (default /usr/local/cuda): 
    
  • the SDK 4.0 is compatible with gcc version < 4.5. check the gcc version used for your nvidia driver
    cat /proc/driver/nvidia/version
    gcc --version  
    
  • compile examples
    cd ~/NVIDIA_GPU_Computing_SDK/C
    make
    
  • check binaries of examples
    ./bin/linux/release/deviceQuery
    
    deviceQuery: Tesla M2070 GPU

build your CUDA application with cmake

  • create a working directory and write your CUDA application (in this example, HelloWorldCUDA.cu)
    #include <stdio.h>
    __global__ void kernel(void) {
    }
    
    int main(void) {
        kernel<<<1,1>>>();
        printf("Hello, World from GPU!\n");
        return 0;
    }
    
  • create CMakeLists.txt file (this example is based on a camke file provided by Qiming)
    # use cmake 2.8 or later
    cmake_minimum_required (VERSION 2.8)
    
    PROJECT(HelloWorldCUDA)
    
    set( CMAKE_CXX_FLAGS "-O2" )
    
    #boost
    set ( BOOST_ROOT       $ENV{BOOST_DIR} )
    set ( BOOST_INCLUDEDIR $ENV{BOOST_INC} )
    set ( BOOST_LIBRARYDIR $ENV{BOOST_LIB} )
    
    find_package(Boost COMPONENTS thread)
    include_directories ( ${Boost_INCLUDE_DIRS} )
    link_directories ( ${Boost_LIBRARY_DIRS} )
    
    #cuda
    SET(CUDA_SDK_ROOT_DIR "/usr/local/NVIDIA_GPU_Computing_SDK")
    SET(CUDA_TOOLKIT_ROOT_DIR "/usr/local/cuda")
    SET(CUDA_NVCC_FLAGS -arch=sm_20 --use_fast_math --ptxas-options=-v)
    
    FIND_PACKAGE(CUDA REQUIRED)
    
    INCLUDE_DIRECTORIES( ${CUDA_SDK_ROOT_DIR}/C/common/inc
                         ${CUDA_SDK_ROOT_DIR}/shared/inc 
                         ${CUDA_TOOLKIT_ROOT_DIR}/include )
    
    LINK_DIRECTORIES( ${CUDA_SDK_ROOT_DIR}/C/lib
                      ${CUDA_SDK_ROOT_DIR}/shared/lib 
                      ${CUDA_TOOLKIT_ROOT_DIR}/lib64 )
    
    # executables
    cuda_add_executable ( HelloWorld
                          HelloWorld.cu
                        )
    
    target_link_libraries ( HelloWorld
                            boost_thread
                          )
    
    
  • build and run executable
    (in this example, we need to setup boost and unsetup gcc)
    mkdir build
    cd build
    cmake ../
    make
    ./HelloWorld
    Hello, World from GPU!