Skip to content

Commit 2467df6

Browse files
author
George Rokos
committed
[OpenMP] Initial implementation of OpenMP offloading library - libomptarget.
This is the patch upstreaming the device-agnostic part of libomptarget. Differential Revision: https://reviews.llvm.org/D14031 llvm-svn: 293094
1 parent c0fc253 commit 2467df6

15 files changed

+3357
-0
lines changed

openmp/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
33
set(OPENMP_LLVM_TOOLS_DIR "" CACHE PATH "Path to LLVM tools for testing")
44

55
add_subdirectory(runtime)
6+
add_subdirectory(libomptarget)
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
#
2+
#//===----------------------------------------------------------------------===//
3+
#//
4+
#// The LLVM Compiler Infrastructure
5+
#//
6+
#// This file is dual licensed under the MIT and the University of Illinois Open
7+
#// Source Licenses. See LICENSE.txt for details.
8+
#//
9+
#//===----------------------------------------------------------------------===//
10+
#
11+
12+
=====================================================================
13+
How to Build the LLVM* OpenMP* Offloading Runtime Library using CMake
14+
=====================================================================
15+
16+
==== Version of CMake required: v2.8.0 or above ====
17+
18+
============================================
19+
How to call cmake initially, then repeatedly
20+
============================================
21+
- When calling cmake for the first time, all needed compiler options
22+
must be specified on the command line. After this initial call to
23+
cmake, the compiler definitions must not be included for further calls
24+
to cmake. Other options can be specified on the command line multiple
25+
times including all definitions in the Build options section below.
26+
- Example of configuring, building, reconfiguring, rebuilding:
27+
$ mkdir build
28+
$ cd build
29+
$ cmake -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ .. # Initial configuration
30+
$ make
31+
...
32+
$ make clean
33+
$ cmake -DCMAKE_BUILD_TYPE=Debug .. # Second configuration
34+
$ make
35+
...
36+
$ rm -rf *
37+
$ cmake -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ .. # Third configuration
38+
$ make
39+
- Notice in the example how the compiler definitions are only specified
40+
for an empty build directory, but other Build options are used at any time.
41+
- The file CMakeCache.txt which is created after the first call to cmake
42+
is a configuration file which holds all the values for the Build options.
43+
These configuration values can be changed using a text editor to modify
44+
CMakeCache.txt as opposed to using definitions on the command line.
45+
- To have cmake create a particular type of build generator file simply
46+
inlude the -G <Generator name> option:
47+
$ cmake -G "Unix Makefiles" ...
48+
You can see a list of generators cmake supports by executing cmake with
49+
no arguments and a list will be printed.
50+
51+
=====================
52+
Instructions to Build
53+
=====================
54+
$ cd libomptarget_top_level/ [ directory with plugins/ , deviceRTLs/ , etc. ]
55+
$ mkdir build
56+
$ cd build
57+
58+
[ Unix* Libraries ]
59+
$ cmake -DCMAKE_C_COMPILER=<C Compiler> -DCMAKE_CXX_COMPILER=<C++ Compiler> ..
60+
61+
$ make
62+
$ make install
63+
64+
===========
65+
Tests
66+
===========
67+
After the library has been built, there are optional tests that can be
68+
performed. Some will be skipped based upon the platform.
69+
To run the tests,
70+
$ make check-libomptarget
71+
72+
=============
73+
CMake options
74+
=============
75+
-DCMAKE_C_COMPILER=<C compiler name>
76+
Specify the C compiler
77+
78+
-DCMAKE_CXX_COMPILER=<C++ compiler name>
79+
Specify the C++ compiler
80+
81+
==== First values listed are the default value ====
82+
-DCMAKE_BUILD_TYPE=Release|Debug|RelWithDebInfo
83+
Build type can be Release, Debug, or RelWithDebInfo.
84+
85+
-DLIBOMPTARGET_ENABLE_WERROR=true|false
86+
Should consider warnings as errors.
87+
88+
-DLIBOMPTARGET_LLVM_LIT_EXECUTABLE=""
89+
Full path to the llvm-lit tool. Required for testing in out-of-tree builds.
90+
91+
-DLIBOMPTARGET_FILECHECK_EXECUTABLE=""
92+
Full path to the FileCheck tool. Required for testing in out-of-tree builds.
93+
94+
-DLIBOMPTARGET_OPENMP_HEADER_FOLDER=""
95+
Path of the folder that contains omp.h. This is required for testing
96+
out-of-tree builds.
97+
98+
-DLIBOMPTARGET_OPENMP_HOST_RTL_FOLDER=""
99+
Path of the folder that contains libomp.so. This is required for testing
100+
out-of-tree builds.
101+
102+
==== NVPTX device RTL specific ====
103+
-DLIBOMPTARGET_NVPTX_ENABLE_BCLIB=false|true
104+
Enable CUDA LLVM bitcode offloading device RTL. This is used for
105+
link time optimization of the omp runtime and application code.
106+
107+
-DLIBOMPTARGET_NVPTX_CUDA_COMPILER=<CUDA compiler name>
108+
Location of a CUDA compiler capable of emitting LLVM bitcode.
109+
Currently only the Clang compiler is supported. This is only used
110+
when building the CUDA LLVM bitcode offloading device RTL. If
111+
unspecified, the default paths are inspected.
112+
113+
-DLIBOMPTARGET_NVPTX_BC_LINKER=<LLVM bitcode linker>
114+
Location of a linker capable of linking LLVM bitcode objects.
115+
This is only used when building the CUDA LLVM bitcode offloading
116+
device RTL. If unspecified, the default paths are inspected.
117+
118+
-DLIBOMPTARGET_NVPTX_ALTERNATE_HOST_COMPILER=""
119+
Host compiler to use with NVCC. This compiler is not going to be used to produce
120+
any binary. Instead, this is used to overcome the input compiler checks done by
121+
NVCC. E.g. if using a default host compiler that is not compatible with NVCC,
122+
this option can be use to pass to NVCC a valid compiler to avoid the error.
123+
124+
-DLIBOMPTARGET_NVPTX_COMPUTE_CAPABILITY="35"
125+
Comma-separated list of CUDA compute capabilities that should be supported by
126+
the NVPTX device RTL. E.g. for compute capabilities 3.0 and 3.5, the option
127+
"30,35" should be used.
128+
129+
=======================
130+
Example usages of CMake
131+
=======================
132+
---- Typical usage ----
133+
cmake -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ ..
134+
cmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ ..
135+
136+
---- Request an NVPTX runtime library that supports compute capability 5.0 ----
137+
cmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DLIBOMPTARGET_NVPTX_COMPUTE_CAPABILITY="50"
138+
139+
=========
140+
Footnotes
141+
=========
142+
[*] Other names and brands may be claimed as the property of others.

openmp/libomptarget/CMakeLists.txt

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
##===----------------------------------------------------------------------===##
2+
#
3+
# The LLVM Compiler Infrastructure
4+
#
5+
# This file is dual licensed under the MIT and the University of Illinois Open
6+
# Source Licenses. See LICENSE.txt for details.
7+
#
8+
##===----------------------------------------------------------------------===##
9+
#
10+
# Build offloading library libomptarget.so.
11+
#
12+
##===----------------------------------------------------------------------===##
13+
14+
# CMAKE libomptarget
15+
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
16+
17+
# Add cmake directory to search for custom cmake functions.
18+
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules ${CMAKE_MODULE_PATH})
19+
20+
# Standalone build or part of LLVM?
21+
set(LIBOMPTARGET_STANDALONE_BUILD FALSE)
22+
if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}" OR
23+
"${CMAKE_SOURCE_DIR}/libomptarget" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
24+
project(libomptarget C CXX)
25+
set(LIBOMPTARGET_STANDALONE_BUILD TRUE)
26+
endif()
27+
28+
29+
if(${LIBOMPTARGET_STANDALONE_BUILD})
30+
set(LIBOMPTARGET_ENABLE_WERROR FALSE CACHE BOOL
31+
"Enable -Werror flags to turn warnings into errors for supporting compilers.")
32+
# CMAKE_BUILD_TYPE was not defined, set default to Release
33+
if(NOT CMAKE_BUILD_TYPE)
34+
set(CMAKE_BUILD_TYPE Release)
35+
endif()
36+
set(LIBOMPTARGET_LIBDIR_SUFFIX "" CACHE STRING
37+
"suffix of lib installation directory, e.g. 64 => lib64")
38+
else()
39+
set(LIBOMPTARGET_ENABLE_WERROR ${LLVM_ENABLE_WERROR})
40+
# If building in tree, we honor the same install suffix LLVM uses.
41+
set(LIBOMPTARGET_LIBDIR_SUFFIX ${LLVM_LIBDIR_SUFFIX})
42+
endif()
43+
44+
# Compiler flag checks.
45+
include(config-ix)
46+
47+
# Message utilities.
48+
include(LibomptargetUtils)
49+
50+
# Get dependencies for the different components of the project.
51+
include(LibomptargetGetDependencies)
52+
53+
# This is a list of all the targets that are supported/tested right now.
54+
set (LIBOMPTARGET_ALL_TARGETS "${LIBOMPTARGET_ALL_TARGETS} powerpc64le-ibm-linux-gnu")
55+
set (LIBOMPTARGET_ALL_TARGETS "${LIBOMPTARGET_ALL_TARGETS} powerpc64-ibm-linux-gnu")
56+
set (LIBOMPTARGET_ALL_TARGETS "${LIBOMPTARGET_ALL_TARGETS} x86_64-pc-linux-gnu")
57+
set (LIBOMPTARGET_ALL_TARGETS "${LIBOMPTARGET_ALL_TARGETS} nvptx64-nvidia-cuda")
58+
59+
# Once the plugins for the different targets are validated, they will be added to
60+
# the list of supported targets in the current system.
61+
set (LIBOMPTARGET_SYSTEM_TARGETS "")
62+
63+
# Set base directories - required for lit to locate the tests.
64+
set(LIBOMPTARGET_BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
65+
set(LIBOMPTARGET_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
66+
67+
# We need C++11 support.
68+
if(LIBOMPTARGET_HAVE_STD_CPP11_FLAG)
69+
70+
libomptarget_say("Building offloading runtime library libomptarget.")
71+
72+
# Enable support for C++11.
73+
add_definitions(-std=c++11)
74+
75+
if(LIBOMPTARGET_ENABLE_WERROR AND LIBOMPTARGET_HAVE_WERROR_FLAG)
76+
add_definitions(-Werror)
77+
endif()
78+
79+
# If building this library in debug mode, we define a macro to enable
80+
# dumping progress messages at runtime.
81+
string( TOLOWER "${CMAKE_BUILD_TYPE}" LIBOMPTARGET_CMAKE_BUILD_TYPE)
82+
if(LIBOMPTARGET_CMAKE_BUILD_TYPE MATCHES debug)
83+
add_definitions(-DOMPTARGET_DEBUG)
84+
add_definitions(-g)
85+
add_definitions(-O0)
86+
endif()
87+
88+
set(src_files
89+
src/omptarget.cpp
90+
)
91+
92+
include_directories(src/)
93+
94+
# Build libomptarget library with libdl dependency.
95+
add_library(omptarget SHARED ${src_files})
96+
target_link_libraries(omptarget
97+
dl
98+
"-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exports")
99+
100+
# Install libomptarget under the lib destination folder.
101+
install(TARGETS omptarget LIBRARY DESTINATION lib${LIBOMPTARGET_LIBDIR_SUFFIX})
102+
103+
# Retrieve the path to the resulting library so that it can be used for
104+
# testing.
105+
get_target_property(LIBOMPTARGET_LIBRARY_DIR omptarget LIBRARY_OUTPUT_DIRECTORY)
106+
if(NOT LIBOMPTARGET_LIBRARY_DIR)
107+
set(LIBOMPTARGET_LIBRARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
108+
endif()
109+
110+
# Add tests.
111+
add_subdirectory(test)
112+
113+
else(LIBOMPTARGET_HAVE_STD_CPP11_FLAG)
114+
libomptarget_say("Not building offloading runtime library libomptarget: host compiler must have c++11 support.")
115+
endif(LIBOMPTARGET_HAVE_STD_CPP11_FLAG)

openmp/libomptarget/README.txt

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
2+
README for the LLVM* OpenMP* Offloading Runtime Library (libomptarget)
3+
======================================================================
4+
5+
How to Build the LLVM* OpenMP* Offloading Runtime Library (libomptarget)
6+
========================================================================
7+
In-tree build:
8+
9+
$ cd where-you-want-to-live
10+
Check out openmp (libomptarget lives under ./libomptarget) into llvm/projects
11+
$ cd where-you-want-to-build
12+
$ mkdir build && cd build
13+
$ cmake path/to/llvm -DCMAKE_C_COMPILER=<C compiler> -DCMAKE_CXX_COMPILER=<C++ compiler>
14+
$ make omptarget
15+
16+
Out-of-tree build:
17+
18+
$ cd where-you-want-to-live
19+
Check out openmp (libomptarget lives under ./libomptarget)
20+
$ cd where-you-want-to-live/openmp/libomptarget
21+
$ mkdir build && cd build
22+
$ cmake path/to/openmp -DCMAKE_C_COMPILER=<C compiler> -DCMAKE_CXX_COMPILER=<C++ compiler>
23+
$ make
24+
25+
For details about building, please look at Build_With_CMake.txt
26+
27+
Architectures Supported
28+
=======================
29+
The current library has been only tested in Linux operating system and the
30+
following host architectures:
31+
* Intel(R) 64 architecture
32+
* IBM(R) Power architecture (big endian)
33+
* IBM(R) Power architecture (little endian)
34+
35+
The currently supported offloading device architectures are:
36+
* Intel(R) 64 architecture (generic 64-bit plugin - mostly for testing purposes)
37+
* IBM(R) Power architecture (big endian) (generic 64-bit plugin - mostly for testing purposes)
38+
* IBM(R) Power architecture (little endian) (generic 64-bit plugin - mostly for testing purposes)
39+
* CUDA(R) enabled 64-bit NVIDIA(R) GPU architectures
40+
41+
Supported RTL Build Configurations
42+
==================================
43+
Supported Architectures: Intel(R) 64, IBM(R) Power 7 and Power 8
44+
45+
---------------------------
46+
| gcc | clang |
47+
--------------|------------|------------|
48+
| Linux* OS | Yes(1) | Yes(2) |
49+
-----------------------------------------
50+
51+
(1) gcc version 4.8.2 or later is supported.
52+
(2) clang version 3.7 or later is supported.
53+
54+
55+
Front-end Compilers that work with this RTL
56+
===========================================
57+
58+
The following compilers are known to do compatible code generation for
59+
this RTL:
60+
- clang (from https://github.com/clang-ykt )
61+
- clang (development branch at http://clang.llvm.org - several features still
62+
under development)
63+
64+
-----------------------------------------------------------------------
65+
66+
Notices
67+
=======
68+
This library and related compiler support is still under development, so the
69+
employed interface is likely to change in the future.
70+
71+
*Other names and brands may be claimed as the property of others.
72+

0 commit comments

Comments
 (0)