24
edits
Changes
→Instructions
== Instructions ==
'''How to set up the compiler and target offloading for windows, Linux with a target NVIDIA GPU''' Using LLVM/Clang with OpenMP offloading to NVIDIA GPUs on Linux. Clang 7.0 has introduced support for offloading to NVIDIA GPUs. Since Clang's OpenMP implementation for NVIDIA GPUs does not currently support multiple GPU architectures in a single binary, you must know the target GPUwhen compiling an OpenMP program. '''Before building the compiler Clang/LLVM requires some software.'''* To build an application a compiler needs to be installed. Ensure that you have GCC with at least version 4.8 installed or Clang with any version greater than 3.1 installed. * You will need standard Linux commands such as ''make'', ''tar'', and ''xz''. Most of the time these tools are built into your Linux distribution.* LLVM requires the CMake ''more'' or ''less'' commands, make sure you have CMake with at least version 3.4.3.* Runtime libraries the system needs both ''libelf'' and its development headers.* You will finally need the [https: //developer.nvidia.com/cuda-92-download-archive CUDA toolkit] by NVIDIA, with a recommended version using version 9.2. '''Download and Extract''' You will need the LLVM Core libraries, Clang and OpenMP. Enter these commands into the terminal to download the required tarballs.<pre> $ wget https://releases.llvm.org/7.0.0/llvm-7.0.0.src.tar.xz $ wget https://releases.llvm.org/7.0.0/cfe-7.0.0.src.tar.xz $ wget https://releases.llvm.org/7.0.0/openmp-7.0.0.src.tar.xz</pre> Next step is to unpack the downloaded tarballs, using the following commands.<pre> $ tar xf llvm-7.0.0.src.tar.xz $ tar xf cfe-7.0.0.src.tar.xz $ tar xf openmp-7.0.0.src.tar.xz</pre> This will leave you with 3 directories called ''llvm-7.0.0.src'', ''cfe-7.0.0.src'', and ''openmp-7.0.0.src''. Afterwards move these components into their directories so that they can be built together. Enter the following commands.<pre> $ mv cfe-7.0.0.src llvm-7.0.0.src/tools/clang $ mv openmp-7.0.0.src llvm-7.0.0.src/projects/openmp</pre> '''Building the compiler''' Lets begin to configure the build the compiler. For this project we will use CMake to build this project in a separate directory. Enter the following commands.<pre> $ mkdir build $ cd build</pre>Next use CMake to generate the Makefiles which will be used for compilation.<pre> $ cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$(Nathanpwd)/../install \ -DCLANG_OPENMP_NVPTX_DEFAULT_ARCH=sm_60 \ -DLIBOMPTARGET_NVPTX_COMPUTE_CAPABILITIES=35,60,70 ../llvm-7.0.0.src</pre>After execution of the above statement the following should display towards the end of the output.<pre>-- Found LIBOMPTARGET_DEP_LIBELF: /usr/lib64/libelf.so-- Found PkgConfig: /usr/bin/pkg-config (found version "0.27.1") -- Found LIBOMPTARGET_DEP_LIBFFI: /usr/lib64/libffi.so-- Found LIBOMPTARGET_DEP_CUDA_DRIVER: <<<REDACTED>>>/libcuda.so-- LIBOMPTARGET: Building offloading runtime library libomptarget.-- LIBOMPTARGET: Not building aarch64 offloading plugin: machine not found in the system.-- LIBOMPTARGET: Building CUDA offloading plugin.-- LIBOMPTARGET: Not building PPC64 offloading plugin: machine not found in the system.-- LIBOMPTARGET: Not building PPC64le offloading plugin: machine not found in the system.-- LIBOMPTARGET: Building x86_64 offloading plugin.-- LIBOMPTARGET: Building CUDA offloading device RTL.</pre> <pre>After enter the follow command $ make -j8 After the built libraries and binaries will have to be installed $ make -j8 install</pre> '''Rebuild OpenMP Libraries''' Now we need to rebuild the OpenMP runtime libraries with Clang. First create a new build directory:<pre> $ cd .. $ mkdir build-openmp $ cd build-openmp</pre>Then configure the project with CMake using the Clang compiler built in the previous step:<pre>$ cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$(pwd)/../install \ -DCMAKE_C_COMPILER=$(pwd)/../install/bin/clang \ -DCMAKE_CXX_COMPILER=$(pwd)/../install/bin/clang++ \ -DLIBOMPTARGET_NVPTX_COMPUTE_CAPABILITIES=35,60,70 \ ../llvm-7.0.0.src/projects/openmp</pre>Then build and install the OpenMP runtime libraries:<pre> $ make -j8 $ make -j8 install</pre>'''Using the compiler for offloading''' The following steps leading up to this should now allow you to have a fully working Clang compiler with OpenMP support for offloading. In order to use it you need to export some environment variables:<pre> $ cd .. $ export PATH=$(pwd)/install/bin:$PATH $ export LD_LIBRARY_PATH=$(pwd)/install/lib:$LD_LIBRARY_PATH</pre> After you will be able to compiler an OpenMP application with offloading with running the clang compiler and some addition flags for offloading.<pre> $ clang -fopenmp -fopenmp-targets=nvptx64 -O2 foo.c</pre>
How to set up compiler and target offloading for Linux on AMD GPU: (Elena)