Skip to content

Commit

Permalink
[OpenMP] Initial implementation of OpenMP offloading library - libomp…
Browse files Browse the repository at this point in the history
…target.

This is the patch upstreaming the device-agnostic part of libomptarget.

Differential Revision: https://reviews.llvm.org/D14031

llvm-svn: 293094
  • Loading branch information
George Rokos committed Jan 25, 2017
1 parent c0fc253 commit 2467df6
Show file tree
Hide file tree
Showing 15 changed files with 3,357 additions and 0 deletions.
1 change: 1 addition & 0 deletions openmp/CMakeLists.txt
Expand Up @@ -3,3 +3,4 @@ cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
set(OPENMP_LLVM_TOOLS_DIR "" CACHE PATH "Path to LLVM tools for testing")

add_subdirectory(runtime)
add_subdirectory(libomptarget)
142 changes: 142 additions & 0 deletions openmp/libomptarget/Build_With_CMake.txt
@@ -0,0 +1,142 @@
#
#//===----------------------------------------------------------------------===//
#//
#// The LLVM Compiler Infrastructure
#//
#// This file is dual licensed under the MIT and the University of Illinois Open
#// Source Licenses. See LICENSE.txt for details.
#//
#//===----------------------------------------------------------------------===//
#

=====================================================================
How to Build the LLVM* OpenMP* Offloading Runtime Library using CMake
=====================================================================

==== Version of CMake required: v2.8.0 or above ====

============================================
How to call cmake initially, then repeatedly
============================================
- When calling cmake for the first time, all needed compiler options
must be specified on the command line. After this initial call to
cmake, the compiler definitions must not be included for further calls
to cmake. Other options can be specified on the command line multiple
times including all definitions in the Build options section below.
- Example of configuring, building, reconfiguring, rebuilding:
$ mkdir build
$ cd build
$ cmake -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ .. # Initial configuration
$ make
...
$ make clean
$ cmake -DCMAKE_BUILD_TYPE=Debug .. # Second configuration
$ make
...
$ rm -rf *
$ cmake -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ .. # Third configuration
$ make
- Notice in the example how the compiler definitions are only specified
for an empty build directory, but other Build options are used at any time.
- The file CMakeCache.txt which is created after the first call to cmake
is a configuration file which holds all the values for the Build options.
These configuration values can be changed using a text editor to modify
CMakeCache.txt as opposed to using definitions on the command line.
- To have cmake create a particular type of build generator file simply
inlude the -G <Generator name> option:
$ cmake -G "Unix Makefiles" ...
You can see a list of generators cmake supports by executing cmake with
no arguments and a list will be printed.

=====================
Instructions to Build
=====================
$ cd libomptarget_top_level/ [ directory with plugins/ , deviceRTLs/ , etc. ]
$ mkdir build
$ cd build

[ Unix* Libraries ]
$ cmake -DCMAKE_C_COMPILER=<C Compiler> -DCMAKE_CXX_COMPILER=<C++ Compiler> ..

$ make
$ make install

===========
Tests
===========
After the library has been built, there are optional tests that can be
performed. Some will be skipped based upon the platform.
To run the tests,
$ make check-libomptarget

=============
CMake options
=============
-DCMAKE_C_COMPILER=<C compiler name>
Specify the C compiler

-DCMAKE_CXX_COMPILER=<C++ compiler name>
Specify the C++ compiler

==== First values listed are the default value ====
-DCMAKE_BUILD_TYPE=Release|Debug|RelWithDebInfo
Build type can be Release, Debug, or RelWithDebInfo.

-DLIBOMPTARGET_ENABLE_WERROR=true|false
Should consider warnings as errors.

-DLIBOMPTARGET_LLVM_LIT_EXECUTABLE=""
Full path to the llvm-lit tool. Required for testing in out-of-tree builds.

-DLIBOMPTARGET_FILECHECK_EXECUTABLE=""
Full path to the FileCheck tool. Required for testing in out-of-tree builds.

-DLIBOMPTARGET_OPENMP_HEADER_FOLDER=""
Path of the folder that contains omp.h. This is required for testing
out-of-tree builds.

-DLIBOMPTARGET_OPENMP_HOST_RTL_FOLDER=""
Path of the folder that contains libomp.so. This is required for testing
out-of-tree builds.

==== NVPTX device RTL specific ====
-DLIBOMPTARGET_NVPTX_ENABLE_BCLIB=false|true
Enable CUDA LLVM bitcode offloading device RTL. This is used for
link time optimization of the omp runtime and application code.

-DLIBOMPTARGET_NVPTX_CUDA_COMPILER=<CUDA compiler name>
Location of a CUDA compiler capable of emitting LLVM bitcode.
Currently only the Clang compiler is supported. This is only used
when building the CUDA LLVM bitcode offloading device RTL. If
unspecified, the default paths are inspected.

-DLIBOMPTARGET_NVPTX_BC_LINKER=<LLVM bitcode linker>
Location of a linker capable of linking LLVM bitcode objects.
This is only used when building the CUDA LLVM bitcode offloading
device RTL. If unspecified, the default paths are inspected.

-DLIBOMPTARGET_NVPTX_ALTERNATE_HOST_COMPILER=""
Host compiler to use with NVCC. This compiler is not going to be used to produce
any binary. Instead, this is used to overcome the input compiler checks done by
NVCC. E.g. if using a default host compiler that is not compatible with NVCC,
this option can be use to pass to NVCC a valid compiler to avoid the error.

-DLIBOMPTARGET_NVPTX_COMPUTE_CAPABILITY="35"
Comma-separated list of CUDA compute capabilities that should be supported by
the NVPTX device RTL. E.g. for compute capabilities 3.0 and 3.5, the option
"30,35" should be used.

=======================
Example usages of CMake
=======================
---- Typical usage ----
cmake -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ ..
cmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ ..

---- Request an NVPTX runtime library that supports compute capability 5.0 ----
cmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DLIBOMPTARGET_NVPTX_COMPUTE_CAPABILITY="50"

=========
Footnotes
=========
[*] Other names and brands may be claimed as the property of others.
115 changes: 115 additions & 0 deletions openmp/libomptarget/CMakeLists.txt
@@ -0,0 +1,115 @@
##===----------------------------------------------------------------------===##
#
# The LLVM Compiler Infrastructure
#
# This file is dual licensed under the MIT and the University of Illinois Open
# Source Licenses. See LICENSE.txt for details.
#
##===----------------------------------------------------------------------===##
#
# Build offloading library libomptarget.so.
#
##===----------------------------------------------------------------------===##

# CMAKE libomptarget
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)

# Add cmake directory to search for custom cmake functions.
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules ${CMAKE_MODULE_PATH})

# Standalone build or part of LLVM?
set(LIBOMPTARGET_STANDALONE_BUILD FALSE)
if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}" OR
"${CMAKE_SOURCE_DIR}/libomptarget" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
project(libomptarget C CXX)
set(LIBOMPTARGET_STANDALONE_BUILD TRUE)
endif()


if(${LIBOMPTARGET_STANDALONE_BUILD})
set(LIBOMPTARGET_ENABLE_WERROR FALSE CACHE BOOL
"Enable -Werror flags to turn warnings into errors for supporting compilers.")
# CMAKE_BUILD_TYPE was not defined, set default to Release
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
set(LIBOMPTARGET_LIBDIR_SUFFIX "" CACHE STRING
"suffix of lib installation directory, e.g. 64 => lib64")
else()
set(LIBOMPTARGET_ENABLE_WERROR ${LLVM_ENABLE_WERROR})
# If building in tree, we honor the same install suffix LLVM uses.
set(LIBOMPTARGET_LIBDIR_SUFFIX ${LLVM_LIBDIR_SUFFIX})
endif()

# Compiler flag checks.
include(config-ix)

# Message utilities.
include(LibomptargetUtils)

# Get dependencies for the different components of the project.
include(LibomptargetGetDependencies)

# This is a list of all the targets that are supported/tested right now.
set (LIBOMPTARGET_ALL_TARGETS "${LIBOMPTARGET_ALL_TARGETS} powerpc64le-ibm-linux-gnu")
set (LIBOMPTARGET_ALL_TARGETS "${LIBOMPTARGET_ALL_TARGETS} powerpc64-ibm-linux-gnu")
set (LIBOMPTARGET_ALL_TARGETS "${LIBOMPTARGET_ALL_TARGETS} x86_64-pc-linux-gnu")
set (LIBOMPTARGET_ALL_TARGETS "${LIBOMPTARGET_ALL_TARGETS} nvptx64-nvidia-cuda")

# Once the plugins for the different targets are validated, they will be added to
# the list of supported targets in the current system.
set (LIBOMPTARGET_SYSTEM_TARGETS "")

# Set base directories - required for lit to locate the tests.
set(LIBOMPTARGET_BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(LIBOMPTARGET_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})

# We need C++11 support.
if(LIBOMPTARGET_HAVE_STD_CPP11_FLAG)

libomptarget_say("Building offloading runtime library libomptarget.")

# Enable support for C++11.
add_definitions(-std=c++11)

if(LIBOMPTARGET_ENABLE_WERROR AND LIBOMPTARGET_HAVE_WERROR_FLAG)
add_definitions(-Werror)
endif()

# If building this library in debug mode, we define a macro to enable
# dumping progress messages at runtime.
string( TOLOWER "${CMAKE_BUILD_TYPE}" LIBOMPTARGET_CMAKE_BUILD_TYPE)
if(LIBOMPTARGET_CMAKE_BUILD_TYPE MATCHES debug)
add_definitions(-DOMPTARGET_DEBUG)
add_definitions(-g)
add_definitions(-O0)
endif()

set(src_files
src/omptarget.cpp
)

include_directories(src/)

# Build libomptarget library with libdl dependency.
add_library(omptarget SHARED ${src_files})
target_link_libraries(omptarget
dl
"-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exports")

# Install libomptarget under the lib destination folder.
install(TARGETS omptarget LIBRARY DESTINATION lib${LIBOMPTARGET_LIBDIR_SUFFIX})

# Retrieve the path to the resulting library so that it can be used for
# testing.
get_target_property(LIBOMPTARGET_LIBRARY_DIR omptarget LIBRARY_OUTPUT_DIRECTORY)
if(NOT LIBOMPTARGET_LIBRARY_DIR)
set(LIBOMPTARGET_LIBRARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
endif()

# Add tests.
add_subdirectory(test)

else(LIBOMPTARGET_HAVE_STD_CPP11_FLAG)
libomptarget_say("Not building offloading runtime library libomptarget: host compiler must have c++11 support.")
endif(LIBOMPTARGET_HAVE_STD_CPP11_FLAG)
72 changes: 72 additions & 0 deletions openmp/libomptarget/README.txt
@@ -0,0 +1,72 @@

README for the LLVM* OpenMP* Offloading Runtime Library (libomptarget)
======================================================================

How to Build the LLVM* OpenMP* Offloading Runtime Library (libomptarget)
========================================================================
In-tree build:

$ cd where-you-want-to-live
Check out openmp (libomptarget lives under ./libomptarget) into llvm/projects
$ cd where-you-want-to-build
$ mkdir build && cd build
$ cmake path/to/llvm -DCMAKE_C_COMPILER=<C compiler> -DCMAKE_CXX_COMPILER=<C++ compiler>
$ make omptarget

Out-of-tree build:

$ cd where-you-want-to-live
Check out openmp (libomptarget lives under ./libomptarget)
$ cd where-you-want-to-live/openmp/libomptarget
$ mkdir build && cd build
$ cmake path/to/openmp -DCMAKE_C_COMPILER=<C compiler> -DCMAKE_CXX_COMPILER=<C++ compiler>
$ make

For details about building, please look at Build_With_CMake.txt

Architectures Supported
=======================
The current library has been only tested in Linux operating system and the
following host architectures:
* Intel(R) 64 architecture
* IBM(R) Power architecture (big endian)
* IBM(R) Power architecture (little endian)

The currently supported offloading device architectures are:
* Intel(R) 64 architecture (generic 64-bit plugin - mostly for testing purposes)
* IBM(R) Power architecture (big endian) (generic 64-bit plugin - mostly for testing purposes)
* IBM(R) Power architecture (little endian) (generic 64-bit plugin - mostly for testing purposes)
* CUDA(R) enabled 64-bit NVIDIA(R) GPU architectures

Supported RTL Build Configurations
==================================
Supported Architectures: Intel(R) 64, IBM(R) Power 7 and Power 8

---------------------------
| gcc | clang |
--------------|------------|------------|
| Linux* OS | Yes(1) | Yes(2) |
-----------------------------------------

(1) gcc version 4.8.2 or later is supported.
(2) clang version 3.7 or later is supported.


Front-end Compilers that work with this RTL
===========================================

The following compilers are known to do compatible code generation for
this RTL:
- clang (from https://github.com/clang-ykt )
- clang (development branch at http://clang.llvm.org - several features still
under development)

-----------------------------------------------------------------------

Notices
=======
This library and related compiler support is still under development, so the
employed interface is likely to change in the future.

*Other names and brands may be claimed as the property of others.

0 comments on commit 2467df6

Please sign in to comment.