-
Notifications
You must be signed in to change notification settings - Fork 0
/
jetson-openmp-builder
executable file
·161 lines (147 loc) · 4.89 KB
/
jetson-openmp-builder
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# BSD 2-Clause License
#
# Copyright (c) 2020, Alessandro Capotondi
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#!/bin/bash
#LLVM Version
LLVM_VER=10.0.0
# Jetson TX1,Nano CP 5.3
# Jetson TX2 CP 6.2
# Jetson AGX Xavier CP 7.2
NVIDIA_ARCH_DEFAULT=53
NVIDIA_ARCH_LIST=53,62,72
LLVM_PATH=/usr/local
# Source code directory
LLVM_SRC=$HOME
LLVM_OMP_SRC=$HOME/projects/openmp
WHEREAMI=$PWD
# NUM_JOBS is the number of jobs to run simultaneously when using make
# This will default to the number of CPU cores (on the Nano, that's 4)
# If you are using a SD card, you may want to change this
# to 1. Also, you may want to increase the size of your swap file
NUM_JOBS=8
function usage() {
echo "usage: $0 [-s sourcedir | -i installdir | -j number of threads | -o openmpdir | -h ]"
echo "-j | --jobs Number of threads used for building the compiler (default: $NUM_JOBS)"
echo "-s | --sourcedir Directory in which to place the Clang/LLVM sources (default: $LLVM_SRC)"
echo "-o | --openmpdir Directory in which to place the OpenMP sources (default: $LLVM_OMP_SRC)"
echo "-i | --installdir Directory in which to install Clang/LLVM libraries (default $LLVM_PATH)"
echo "-v | --version clang/LLVM version (default: $LLVM_VER)"
echo "-h | --help This message"
}
# Iterate through command line inputs
while [ "$1" != "" ]; do
case $1 in
-s | --sourcedir)
shift
LLVM_SRC=$1
;;
-i | --installdir)
shift
LLVM_PATH=$1
;;
-o | --openmpdir)
shift
LLVM_OMP_SRC=$1
;;
-j | --jobs)
shift
NUM_JOBS=$1
;;
-h | --help)
usage
exit
;;
-v | --version)
shift
LLVM_VER=$1
;;
*)
usage
exit 1
;;
esac
shift
done
CMAKE_INSTALL_PREFIX=$LLVM_PATH
# Print out the current configuration
echo "Build configuration: "
echo " NVIDIA Jetson Nano"
echo " Clang/LLVM binaries will be installed in: $CMAKE_INSTALL_PREFIX"
echo " Clang/LLVM Source will be installed in: $LLVM_SRC"
export PATH=$LLVM_PATH:$PATH
export LD_LIBRARY_PATH=$LLVM_PATH/libexec:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=$LLVM_PATH/lib:$LD_LIBRARY_PATH
export LIBRARY_PATH=$LLVM_PATH/libexec:$LIBRARY_PATH
export LIBRARY_PATH=$LLVM_PATH/lib:$LIBRARY_PATH
export MANPATH=$LLVM_PATH/share/man:$MANPATH
export C_INCLUDE_PATH=$LLVM_PATH/include:$C_INCLUDE_PATH
export CPLUS_INCLUDE_PATH=$LLVM_PATH/include:CPLUS_INCLUDE_PATH
cd $LLVM_SRC
mkdir -p build-openmp-$LLVM_VER
cd build-openmp-$LLVM_VER
echo "[$PWD] Build LLVM/OpenMP Project..."
time cmake -G "Unix Makefiles" \
-D CMAKE_BUILD_TYPE=Release \
-D CMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} \
-D CMAKE_C_COMPILER=${LLVM_PATH}/bin/clang \
-D CMAKE_CXX_COMPILER=${LLVM_PATH}/bin/clang++ \
-D LIBOMPTARGET_NVPTX_COMPUTE_CAPABILITIES=${NVIDIA_ARCH_LIST} \
$LLVM_OMP_SRC
if [ $? -eq 0 ]; then
echo "CMake configuration make successful"
else
# Try to make again
echo "CMake issues " >&2
echo "Please check the configuration being used"
exit 1
fi
time make -j$NUM_JOBS
if [ $? -eq 0 ]; then
echo "LLVM/OpenMP make successful"
else
# Try to make again; Sometimes there are issues with the build
# because of lack of resources or concurrency issues
echo "Make did not build " >&2
echo "Retrying ... "
# Single thread this time
time make
if [ $? -eq 0 ]; then
echo "LLVM/OpenMP make successful"
else
# Try to make again
echo "Make did not successfully build" >&2
echo "Please fix issues and retry build"
exit 1
fi
fi
echo "Installing ... "
time make install -j$NUM_JOBS
if [ $? -eq 0 ]; then
echo "Clang/LLVM v$LLVM_VER installed in: $CMAKE_INSTALL_PREFIX"
else
echo "There was an issue with the final installation"
exit 1
fi
#Happy offloading!!