Changes between Version 22 and Version 23 of GPUApp


Ignore:
Timestamp:
Mar 13, 2013, 4:05:29 AM (12 years ago)
Author:
charlief
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • GPUApp

    v22 v23  
    11= Building BOINC applications with Cuda and OpenCL =
    2 
    32[[PageOutline]]
    43
    5 We have built sample BOINC-Cuda and BOINC-OpenCL applications as templates
    6 for making your own app.
    7 The source files are in the [SourceCode BOINC source tree]
    8 in samples/nvcuda, samples/nvopencl, and samples/atiopencl.
     4We have built sample BOINC-Cuda and BOINC-OpenCL applications as templates for making your own app. The source files are in the [http://boinc.berkeley.edu/trac/wiki/SourceCodeGit BOINC source tree] in samples/nvcuda and samples/openclapp.
     5
     6Before starting, you must install the appropriate SDK for the GPU you wish to support: [https://developer.nvidia.com/cuda-downloads NVIDIA SDK] or [http://developer.amd.com/tools/heterogeneous-computing/amd-accelerated-parallel-processing-app-sdk/downloads/ ATI / AMD SDK].  This document assumes version 5 of the NVIDIA SDK or version 2.8 of the AMD SDK.  (Exception: no SDK is required for the OpenCL sample on Mac OS X, which has OpenCL support built in.)
     7
     8== OpenCL Sample Notes == #openclnotes
     9The openclapp sample calls boinc_get_opencl_ids(), which reads an init_data.xml file to determine which GPU to use.  Actual project applications must also do this.  Please see the `ReadMe.txt` file for more information. 
     10
     11This same sample is designed to run with AMD, NVIDIA and Intel Ivy Bridge GPUs.  It is supplied with 3 minimal init_data.xml files, one for each of these 3 vendors (GPU "types".)  Copy the appropriate init_data.xml file into the directory containing the openclapp executable. 
    912
    1013== Windows == #windows
    11 
    12 The 32-bit Windows compile under Visual Studio
     14The 32-bit Windows samples compile under Visual Studio.
    1315
    1416=== NVIDIA Cuda ===
     17The VS project file, example_app_nvcuda.vcproj, is in `boinc/win_build/`. Note that NVIDIA Cuda SDK 3.0 or older supports device emulation mode. If your machine doesn't have a CUDA-enabled GPU, then you should build the sample application in the device emulation mode. Do so by setting `Build -> Configuration Manager -> Configuration` to either Emudebug or Emurelease.
    1518
    16 The VS project file, example_app_nvcuda.vcproj, is in "boinc/win_build/".
    17 Note that NVIDIA Cuda SDK 3.0 or older supports device emulation mode.
    18 If your machine doesn't have a CUDA-enabled GPU,
    19 then you should build the sample application in the device emulation mode.
    20 Do so by setting "Build -> Configuration Manager -> Configuration" to either Emudebug or Emurelease.
    21 
    22 The executable file can be found at "boinc/win_build/Build/Win32/build_mode/"
    23 (build_mode could be release, debug, emurelease or emudebug).
     19The executable file can be found at `boinc/win_build/Build/Win32/build_mode/` (build_mode could be release, debug, emurelease or emudebug).
    2420
    2521=== NVIDIA OpenCL ===
     22The project file, example_app_nvopencl.vcproj, is in `boinc/win_build/`.
    2623
    27 The project file, example_app_nvopencl.vcproj, is in "boinc/win_build/".
    28 
    29 The executable file can be found at "boinc/win_build/Build/Win32/build_mode/"
    30 (build_mode could be release or debug).
     24The executable file can be found at `boinc/win_build/Build/Win32/build_mode/` (build_mode could be release or debug).
    3125
    3226Upon running the executable file, you might encounter the following error:
     27
    3328{{{
    3429This application has failed to start because OpenCL.dll was not found. Re-installing the application may fix this problem.
    3530}}}
    36 To fix this problem, you will need to install the Cuda Developer Driver for Windows,
    37 which can only be done when your machine has an NVIDIA Cuda-enabled GPU.
    38  
     31To fix this problem, you will need to install the Cuda Developer Driver for Windows,  which can only be done when your machine has an NVIDIA Cuda-enabled GPU.
     32
     33Please read the [#openclnotes OpenCL Sample Notes] section above.
     34
    3935=== ATI Stream OpenCL ===
     36The project file, example_app_atiopencl.vcproj, is in `boinc/win_build/`. It uses the same source files as NVIDIA OpenCL.
    4037
    41 The project file, example_app_atiopencl.vcproj, is in "boinc/win_build/".
    42 It is identical to NVIDIA OpenCL.
     38Please read the [#openclnotes OpenCL Sample Notes] section above.
    4339
    4440== Linux == #linux
     41The OpenCL samples assume 32-bit Ubuntu.  You may need to modify them for other Linux configurations.
    4542
    4643=== NVIDIA Cuda ===
    47 
    48 Before running the Makefile, you will need to install gcc 4.3 and g++ 4.3.
    49 This is because the NVIDIA Cuda SDK 3.0 has not yet worked with gcc 4.0 and g++ 4.0.
    50 There should be no issue compiling cuda files with gcc 4.3 and g++ 4.3 on newer NVIDIA Cuda SDK versions.
    51 For a successful compilation, please follow these steps:
     44Before running the 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:
    5245
    53461) Install gcc-4.3 and g++-4.3:
     47
    5448{{{
    5549$ sudo aptitude install gcc-4.3 g++-4.3
    5650}}}
     512) Go to SDK source directory:
    5752
    58 2) Go to SDK source directory:
    5953{{{
    6054$ cd ~/NVIDIA_GPU_Computing_SDK/C
    6155}}}
     563) Create a directory and create symlinks to gcc-4.3/g++-4.3
    6257
    63 3) Create a directory and create symlinks to gcc-4.3/g++-4.3
    6458{{{
    6559$ mkdir mygcc
     
    6862$ ln -s $(which gcc-4.3) gcc
    6963}}}
     64The 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 application. 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.
    7065
    71 The Makefile for Linux is made with the assumption that the NVIDIA Cuda SDK
    72 is installed at the default location "$(ROOT)/home/USER_NAME/NVIDIA_GPU_Computing_SDK/".
    73 On my Linux machine, for example, it would be "$(ROOT)/home/tuanle/NVIDIA_GPU_Computing_SDK/".
    74 Since the absolute path is used in Makefile,
    75 you will probably need to edit file "common.mk" before compiling the sample application.
    76 Do so by looking for "/home/tuanle/NVIDIA_GPU_Computing_SDK" in file "common.mk"
    77 and replace this path with an appropriate path on your machine.
     66You will also need to build the necessary Cuda SDK libraries by running makefile in `~/NVIDIA_GPU_Computing_SDK/C/`. The resulting libraries such as `libcutil_i386` are  created in `~/NVIDIA_GPU_Computing_SDK/C/lib/`. Notice that if these libraries are not built, running nvcuda-sample-app makefile could result in the following error:
    7867
    79 You will also need to build the necessary Cuda SDK libraries by running makefile in
    80 "~/NVIDIA_GPU_Computing_SDK/C/". The resulting libraries such as "libcutil_i386" are
    81 created in "~/NVIDIA_GPU_Computing_SDK/C/lib/". Notice that if these libraries are not built,
    82 running nvcuda-sample-app makefile could result in the following error:
    8368{{{
    8469/usr/bin/ld: cannot find -lcutil_i386
    8570}}}
    86 If your machine doesn't have an NVIDIA Cuda-enabled GPU,
    87 you can compile and run your app in emulation mode.
    88 As far as we know, NVIDIA Cuda SDK 3.1 no longer supports emulation mode.
    89 Thus, you will need to install an older Cuda SDK version, like version 3.0, on your machine.
    90 To build the sample application in emulation mode, simply type:
     71If your machine doesn't have an NVIDIA Cuda-enabled GPU, 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 build the sample application in emulation mode, simply type:
     72
    9173{{{
    9274make emu=1
    9375}}}
    94 The executable file is created in "/boinc/samples/nvcuda/linux/build_mode/" (build_mode could be release or emurelease).
    95 Also, note that you will need to define some environment variables before running the executable file.
     76The executable file is created in `/boinc/samples/nvcuda/linux/build_mode/` (build_mode could be release or emurelease). Also, note that you will need to define some environment variables before running the executable file.
     77
    9678{{{
    9779export PATH=/usr/local/cuda/bin:$PATH
     
    9981}}}
    10082This will resolve the following error:
     83
    10184{{{
    10285./example_app_nvcuda: error while loading shared libraries: libcudart.so.3: cannot open shared object file: No such file or directory
    10386}}}
     87=== NVIDIA OpenCL ===
     88It appears that NVIDIA OpenCL SDK is missing shared library file libOpenCL.so which is needed at compile time. This library file comes with the kernel driver package which can be installed only when your machine has an NVIDIA Cuda-enabled GPU. Thus, any attempt to compile OpenCL sample codes on a non-cuda-enabled GPU machine might result in the following error:
    10489
    105 === NVIDIA OpenCL ===
    106 
    107 It appears that NVIDIA OpenCL SDK is missing shared library file libOpenCL.so which is needed at compile time.
    108 This library file comes with the kernel driver package
    109 which can be installed only when your machine has an NVIDIA Cuda-enabled GPU.
    110 Thus, any attempt to compile OpenCL sample codes on a non-cuda-enabled GPU machine might result in the following error:
    11190{{{
    11291/usr/bin/ld: cannot find -lOpenCL
    11392}}}
    114 The Makefile for Linux is made with the assumption that the NVIDIA Cuda SDK
    115 is installed at the default location "$(ROOT)/home/USER_NAME/NVIDIA_GPU_Computing_SDK/".
    116 On my Linux machine, for example, it would be "$(ROOT)/home/tuanle/NVIDIA_GPU_Computing_SDK/".
    117 Since the absolute path is used in Makefile, you will probably need to edit file "common_opencl.mk" before
    118 compiling the sample application. Do so by looking for "/home/tuanle/NVIDIA_GPU_Computing_SDK" in file
    119 "common_opencl.mk" and replace this path with an appropriate path on your machine.
     93The Makefile for Linux is made with the assumption that the NVIDIA Cuda SDK is installed at the default location `/usr/local/cuda/` with subdirectories `include` and `lib`.  Some versions of Ubuntu have a bug which can prevent the `LD_LIBRARY_PATH` environment variable from being honored as described [https://help.ubuntu.com/community/EnvironmentVariables#File-location_related_variables here], so the Makefile hard codes the path to the standard libraries as '/lib/i386-linux-gnu'.  You may need to modify the Makefile if any of these are at different locations.
    12094
    121 You will also need to build the necessary Cuda SDK libraries by running makefile in
    122 "~/NVIDIA_GPU_Computing_SDK/OpenCL/". The resulting libraries such as "liboclUtil_i386" are
    123 created in "~/NVIDIA_GPU_Computing_SDK/OpenCL/common/lib/". Notice that if these libraries are not built,
    124 running nvopencl-sample-app makefile could result in the following error:
    125 {{{
    126 /usr/bin/ld: cannot find -loclUtil_i386
    127 }}}
    128 
    129 The executable file is created in "/boinc/samples/nvopencl/linux/release/".
     95Please read the [#openclnotes OpenCL Sample Notes] section above.
    13096
    13197=== ATI Stream OpenCL ===
     98The Makefile for Linux is made with the assumption that the environment variable `AMDAPPSDKROOT` contains the path to the ATI Stream OpenCL SDK. This environment variable should be set automatically when you install the SDK.
    13299
    133 The Makefile for Linux is made with the assumption that the ATI Stream OpenCL
    134 SDK version 2.1 for 32-bit Linux and BOINC source code are installed in the same parent directory,
    135 i.e. "ati-stream-sdk-v.2.1-lnx32" directory and "boinc" directory are both installed at "$(ROOT)/home/" directory.
    136 If you are using the SDK v2.1 for 64-bit Linux, or if BOINC source code and the OpenCL SDK
    137 are not installed in the same parent directory,
    138 then Makefile needs to be edited prior to any compilation.
    139 Do so by looking for
    140 {{{
    141 CXXFLAGS = -g \
    142      ...
    143      -I ../../../ati-stream-sdk-v2.1-lnx32/include \
    144      ...
    145 
    146 atiopencl: atiopencl.o libstdc++.a
    147      ...
    148      -lOpenCL -L../../../ati-stream-sdk-v2.1-lnx32/lib/x86 \
    149      ...
    150 }}}
    151 in file "Makefile" and replace these paths with appropriate paths on your machine.
    152 
    153 Most problems related to running the ATI Stream OpenCL executable files
    154 can be found in ATI_Stream_SDK_Installation_Notes.pdf section 2.2.
    155 Here are the two most common run-time errors:
    156 
    157 1) ./atiopencl: error while loading shared libraries: libOpenCL.so: cannot open shared object file: No such file or directory -> Solution:
    158 Set the environment variable ATISTREAMSDKROOT
    159 {{{
    160 $ export ATISTREAMSDKROOT=<location where Stream SDK is extracted>
    161 }}}
    162 
    163 Set the library path LD_LIBRARY_PATH
    164 - For 32-bit systems:
    165 {{{
    166 $ export LD_LIBRARY_PATH=$ATISTREAMSDKROOT/lib/x86:$LD_LIBRARY_PATH
    167 }}}
    168 - For 64-bit systems:
    169 {{{
    170 $ export LD_LIBRARY_PATH=$ATISTREAMSDKROOT/lib/x86_64:$LD_LIBRARY_PATH
    171 }}}
    172 - For the 32-bit SDK to run on 64-bit systems:
    173 {{{
    174 $ export LD_LIBRARY_PATH=$ATISTREAMSDKROOT/lib/x86:$ATISTREAMSDKROOT/lib/x86_64:$LD_LIBRARY_PATH
    175 }}}
    176 
    177 2) ./atiopencl: error CL_PLATFORM_NOT_FOUND ->
    178 
    179 Solution: Register the OpenCL ICD by following these steps:
    180  * Download icd-registration.tgz at http://developer.amd.com/Downloads/icd-registration.tgz
    181  * In the command shell, type "cd /"
    182  * Type "ls", you will see a directory named "etc".
    183   The icd-registration.tgz needs to be unzipped to that directory.
    184  * Now copy icd-registration.tgz to "cd /" by typing "sudo cp -r /home/tuanle/Downloads/icd-registration.tgz ."
    185  * You will need to replace the specified path above with the appropriate path on your machine, and don't forget "sudo".
    186   Otherwise you will get a "Permission denied".
    187  * Unzip by typing "sudo tar xzf icd-registration.tgz"
    188  * Now you should be able to find an "OpenCL" directory in "etc".
    189   Check etc/OpenCL/vendors/, make sure there are "atiocl32.icd" and "atiocl64.icd" there.
    190  * Done!
     100Please read the [#openclnotes OpenCL Sample Notes] section above.
    191101
    192102== Mac OS X == #mac
    193 
    194 The Mac versions are built using gcc/make (not xcode).
     103The Mac versions are built using gcc/make (not xcode).
    195104
    196105=== NVIDIA Cuda ===
     106Unlike Windows and Linux, the 'nvcc' cuda compiler for Mac has some trouble compiling .cu files that contain both BOINC and Cuda code. Any attempt to compile such .cu files might result in errors like these:
    197107
    198 Unlike Windows and Linux, the 'nvcc' cuda compiler for Mac
    199 has some trouble compiling .cu files that contain both BOINC and Cuda code.
    200 Any attempt to compile such .cu files might result in errors like
    201 these:
    202108{{{
    203 /usr/lib/gcc/i686-apple-darwin9/4.0.1/include/mmintrin.h(55): error: identifier "__builtin_ia32_emms" is undefined
    204 /usr/lib/gcc/i686-apple-darwin9/4.0.1/include/mmintrin.h(68): error: identifier "__builtin_ia32_vec_init_v2si" is undefined
    205 /usr/lib/gcc/i686-apple-darwin9/4.0.1/include/mmintrin.h(111): error: identifier "__builtin_ia32_vec_ext_v2si" is undefined
     109/usr/lib/gcc/i686-apple-darwin9/4.0.1/include/mmintrin.h(55): error: identifier `__builtin_ia32_emms` is undefined
     110/usr/lib/gcc/i686-apple-darwin9/4.0.1/include/mmintrin.h(68): error: identifier `__builtin_ia32_vec_init_v2si` is undefined
     111/usr/lib/gcc/i686-apple-darwin9/4.0.1/include/mmintrin.h(111): error: identifier `__builtin_ia32_vec_ext_v2si` is undefined
    206112...
    207113}}}
    208 The solution that we came up with is to compile BOINC and Cuda separately,
    209 meaning that compile .c files that have BOINC codes with
    210 gcc and compile .u files that have Cuda codes such as kernel definitions with nvcc
    211 (This can simply be done by putting .cu and .c
    212 file names at corresponding "CUFILES := " and "CCFILES := " entries in Makefile_mac).
    213 To handle the results computed by the kernels,
    214 you will need to write external functions.
    215 The function definitions that make kernel calls will be put in .cu file
    216 while the function headers with the "extern" prefix are put in .c file and can be called in main function or elsewhere.
     114The solution that we came up with is to compile BOINC and Cuda separately, 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 the `extern` prefix are put in .c file and can be called in main function or elsewhere.
    217115
    218 If your machine doesn't have an NVIDIA Cuda-enabled GPU,
    219 you can compile and run your app in emulation mode.
    220 As far as we know, NVIDIA Cuda SDK 3.1 no longer supports emulation mode.
    221 Thus, you will need to install an older Cuda SDK version, like version 3.0, on your machine.
     116If your machine doesn't have an NVIDIA Cuda-enabled GPU,  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.
    222117
    223 The makefile for Mac is made with the assumption that the NVIDIA Cuda SDK is installed at the default location:
    224 "$ROOT/Developer/GPU Computing/" on Mac. If it is installed at a different location on your machine,
    225 then you will need to edit file "common_mac.mk". Do so by looking for "ROOTDIR  ?= /Developer/GPU\ Computing"
    226 in file "common_mac.mk" and replace this path with an appropriate path on your machine.
     118The 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` and replace this path with an appropriate path on your machine.
    227119
    228120To build the sample application in emulation mode, simply type:
     121
    229122{{{
    230123make -f Makefile_mac emu=1
    231124}}}
    232 The executable file is created in "/boinc/samples/nvcuda/darwin/build_mode/" (build_mode could be release or emurelease).
    233 Also, note that you will need to define some environment variables before running the executable file.
     125The executable file is created in `/boinc/samples/nvcuda/darwin/build_mode/` (build_mode could be release or emurelease).  Also, note that you will need to define some environment variables before running the executable file.
     126
    234127{{{
    235128export PATH=/usr/local/cuda/bin:$PATH
    236129export DYLD_LIBRARY_PATH=/usr/local/cuda/lib:$DYLD_LIBRARY_PATH
    237130}}}
     131=== OpenCL ===
     132Mac OS X has built in support for OpenCL.  No additional SDK is needed to build and run the OpenCL sample, provided that you have an OpenCL-capable GPU.
    238133
    239 === NVIDIA OpenCL ===
     134Use the Terminal application to build the sample application.  In Terminal, `cd` to the `samples/openclapp` directory and type:
     135{{{
     136$ make -f Makefile_mac
     137}}}
    240138
    241 The NVIDIA OpenCL SDK for MacOS doesn't contain the OpenCL library file. This file often comes with the kernel
    242 driver package for MacOS which can be installed only when your machine has an NVIDIA Cuda-enabled GPU.
    243 The other way to obtain this file is to have Mac OS X 10.6 installed on your machine.
    244 
    245 The makefile for Mac is made with the assumption that the NVIDIA Cuda SDK is installed at the default location:
    246 "$ROOT/Developer/GPU Computing/" on Mac. If it is installed at a different location on your machine,
    247 then you will need to edit file "common_opencl_mac.mk". Do so by looking for "ROOTDIR ?= /Developer/GPU\ Computing"
    248 in file "common_opencl_mac.mk" and replace this path with an appropriate path on your machine.
    249 
    250 To build the sample application, simply type:
    251 {{{
    252 make -f Makefile_mac
    253 }}}
    254 The executable file is then created in "/boinc/samples/nvopencl/darwin/release/".
    255 
    256 === ATI Stream OpenCL ===
    257 
    258 ATI Stream does not have a separate OpenCL SDK for MacOS users to download. Thus, the only way to build OpenCL
    259 applications on your Mac is to have Mac OS X 10.6 version (which supports OpenCL) installed on your machine.
    260 
    261 To build the sample application, simply type:
    262 {{{
    263 make -f Makefile_mac
    264 }}}
    265 The executable file is then created in "/boinc/samples/atiopencl/".
     139Please read the [#openclnotes OpenCL Sample Notes] section above.