wiki:GPUApp

Version 4 (modified by TuanLe, 14 years ago) (diff)

--

Building BOINC applications with Cuda and OpenCL

We have built sample BOINC-Cuda and BOINC-OpenCL applications as templates for making your own app.

Windows

Linux

  • NVIDIA Cuda (BOINC-NVCuda sample app for Linux can be found at "/boinc/samples/nvcuda/")
    Makefile; common.mk; cuda_kernel.cu; cuda.cu; cuda_config.h; readme.txt
    

Before running Makefile, you will need to install gcc 4.3 and g++ 4.3. This is because the NVIDIA Cuda SDK 3.0 has not yet worked with gcc 4.0 and g++ 4.0. There should be no issue compiling cuda files with gcc 4.3 and g++ 4.3 on newer NVIDIA Cuda SDK versions. For a successful compilation, please follow these steps:

1) Install gcc-4.3 and g++-4.3:
   $ sudo aptitude install gcc-4.3 g++-4.3

2) Go to SDK source directory:
   $ cd ~/NVIDIA_GPU_Computing_SDK/C

3) Create a directory and create symlinks to gcc-4.3/g++-4.3
   $ mkdir mygcc
   $ cd mygcc
   $ ln -s $(which g++-4.3) g++
   $ ln -s $(which gcc-4.3) gcc

The Makefile for Linux is made with the assumption that the NVIDIA Cuda SDK is installed at the default location "$(ROOT)/home/USER_NAME/NVIDIA_GPU_Computing_SDK/". On my Linux machine, for example, it would be "$(ROOT)/home/tuanle/NVIDIA_GPU_Computing_SDK/". Since the absolute path is used in Makefile, you will probably need to edit file "common.mk" before compiling the sample app. Do so by looking for "/home/tuanle/NVIDIA_GPU_Computing_SDK" in file "common.mk" and replace this path with an appropriate path on your machine.

What if your machine doesn't have an NVIDIA Cuda-enabled GPU? Then, you can compile and run your app in emulation mode. As far as we know, NVIDIA Cuda SDK 3.1 no longer supports emulation mode. Thus, you will need to install an older Cuda SDK version, like version 3.0, on your machine. To make an executable file in emulation mode, simply type "make emu=1".

Also, note that you will need to define some environment variables before running the executable file.

export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib:$LD_LIBRARY_PATH
  • NVIDIA OpenCL (BOINC-NVOpenCL sample app for Linux can be found at "/boin/samples/nvopencl/")
    Makefile; common_opencl; nvopencl.h; nvopencl.cpp; nvopencl_kernels; readme.txt
    

Mac OS X

  • NVIDIA Cuda (BOINC-Cuda sample app for Mac OS X can be found at "/boinc/samples/nvcuda/")
    Makefile_mac; common_mac.mk; cuda_kernel_mac.cu; cuda_mac.c; cuda_config.h; readme_mac.txt
    

Unlike Windows and Linux, the 'nvcc' cuda compiler for Mac has some trouble compiling .cu files that contain both BOINC and Cuda codes. Any attempt to compile such .cu files might result in errors like these:

/usr/lib/gcc/i686-apple-darwin9/4.0.1/include/mmintrin.h(55): error: identifier "__builtin_ia32_emms" is undefined
/usr/lib/gcc/i686-apple-darwin9/4.0.1/include/mmintrin.h(68): error: identifier "__builtin_ia32_vec_init_v2si" is undefined
/usr/lib/gcc/i686-apple-darwin9/4.0.1/include/mmintrin.h(111): error: identifier "__builtin_ia32_vec_ext_v2si" is undefined
/usr/lib/gcc/i686-apple-darwin9/4.0.1/include/mmintrin.h(150): error: identifier "__builtin_ia32_packsswb" is undefined
/usr/lib/gcc/i686-apple-darwin9/4.0.1/include/mmintrin.h(165): error: identifier "__builtin_ia32_packssdw" is undefined
...
...

The solution that we came up with is to compile BOINC and Cuda seperately, meaning that compile .c files that have BOINC codes with gcc and compile .u files that have Cuda codes such as kernel definitions with nvcc (This can simply be done by putting .cu and .c file names at corresponding "CUFILES := " and "CCFILES := " entries in Makefile_mac). To handle the results computed by the kernels, you will need to write external functions. The function definitions that make kernel calls will be put in .cu file while the function headers with "extern" prefix are put in .c file and can be called in main function or elsewhere.

What if your machine doesn't have an NVIDIA Cuda-enabled GPU? Then, you can compile and run your app in emulation mode. As far as we know, NVIDIA Cuda SDK 3.1 no longer supports emulation mode. Thus, you will need to install an older Cuda SDK version, like version 3.0, on your machine. To make an executable file in emulation mode, simply type "make -f Makefile_mac emu=1".

Also, note that you will need to define some environment variables before running the executable file.

export PATH=/usr/local/cuda/bin:$PATH
export DYLD_LIBRARY_PATH=/usr/local/cuda/lib:$DYLD_LIBRARY_PATH

One last thing to mention, the makefile for Mac is made with the assumption that the NVIDIA Cuda SDK is installed at the default location: "$ROOT/Developer/GPU Computing/" on Mac. If it is installed at a different location on your machine, then you will need to edit file "common_mac.mk". Do so by looking for "ROOTDIR ?= /Developer/GPU\ Computing" in file "common_mac.mk" file and replace this path with an appropriate path on your machine.