configfrag.ac revision 1.5 1 # Plugins for offload execution, configure.ac fragment. -*- mode: autoconf -*-
2 #
3 # Copyright (C) 2014-2019 Free Software Foundation, Inc.
4 #
5 # Contributed by Mentor Embedded.
6 #
7 # This file is part of the GNU Offloading and Multi Processing Library
8 # (libgomp).
9 #
10 # Libgomp is free software; you can redistribute it and/or modify it
11 # under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 3, or (at your option)
13 # any later version.
14 #
15 # Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
16 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 # more details.
19 #
20 # Under Section 7 of GPL version 3, you are granted additional
21 # permissions described in the GCC Runtime Library Exception, version
22 # 3.1, as published by the Free Software Foundation.
23 #
24 # You should have received a copy of the GNU General Public License and
25 # a copy of the GCC Runtime Library Exception along with this program;
26 # see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
27 # <http://www.gnu.org/licenses/>.
28
29 plugin_support=yes
30 AC_CHECK_LIB(dl, dlsym, , [plugin_support=no])
31 if test x"$plugin_support" = xyes; then
32 AC_DEFINE(PLUGIN_SUPPORT, 1,
33 [Define if all infrastructure, needed for plugins, is supported.])
34 elif test "x${enable_offload_targets-no}" != xno; then
35 AC_MSG_ERROR([Can't support offloading without support for plugins])
36 fi
37 AC_CHECK_HEADERS_ONCE(unistd.h)
38 AC_CHECK_FUNCS_ONCE(secure_getenv __secure_getenv getuid geteuid getgid getegid)
39
40
41 # Look for the CUDA driver package.
42 CUDA_DRIVER_INCLUDE=
43 CUDA_DRIVER_LIB=
44 AC_SUBST(CUDA_DRIVER_INCLUDE)
45 AC_SUBST(CUDA_DRIVER_LIB)
46 CUDA_DRIVER_CPPFLAGS=
47 CUDA_DRIVER_LDFLAGS=
48 AC_ARG_WITH(cuda-driver,
49 [AS_HELP_STRING([--with-cuda-driver=PATH],
50 [specify prefix directory for installed CUDA driver package.
51 Equivalent to --with-cuda-driver-include=PATH/include
52 plus --with-cuda-driver-lib=PATH/lib])])
53 AC_ARG_WITH(cuda-driver-include,
54 [AS_HELP_STRING([--with-cuda-driver-include=PATH],
55 [specify directory for installed CUDA driver include files])])
56 AC_ARG_WITH(cuda-driver-lib,
57 [AS_HELP_STRING([--with-cuda-driver-lib=PATH],
58 [specify directory for the installed CUDA driver library])])
59 case "x$with_cuda_driver" in
60 x) ;;
61 xno)
62 CUDA_DRIVER_INCLUDE=no
63 CUDA_DRIVER_LIB=no
64 ;;
65 *) CUDA_DRIVER_INCLUDE=$with_cuda_driver/include
66 CUDA_DRIVER_LIB=$with_cuda_driver/lib
67 ;;
68 esac
69 if test "x$with_cuda_driver_include" != x; then
70 CUDA_DRIVER_INCLUDE=$with_cuda_driver_include
71 fi
72 if test "x$with_cuda_driver_lib" != x; then
73 CUDA_DRIVER_LIB=$with_cuda_driver_lib
74 fi
75 if test "x$CUDA_DRIVER_INCLUDE" != x \
76 && test "x$CUDA_DRIVER_INCLUDE" != xno; then
77 CUDA_DRIVER_CPPFLAGS=-I$CUDA_DRIVER_INCLUDE
78 fi
79 if test "x$CUDA_DRIVER_LIB" != x \
80 && test "x$CUDA_DRIVER_LIB" != xno; then
81 CUDA_DRIVER_LDFLAGS=-L$CUDA_DRIVER_LIB
82 fi
83
84 PLUGIN_NVPTX=0
85 PLUGIN_NVPTX_CPPFLAGS=
86 PLUGIN_NVPTX_LDFLAGS=
87 PLUGIN_NVPTX_LIBS=
88 PLUGIN_NVPTX_DYNAMIC=0
89 AC_SUBST(PLUGIN_NVPTX)
90 AC_SUBST(PLUGIN_NVPTX_CPPFLAGS)
91 AC_SUBST(PLUGIN_NVPTX_LDFLAGS)
92 AC_SUBST(PLUGIN_NVPTX_LIBS)
93
94 # Look for HSA run-time, its includes and libraries
95
96 HSA_RUNTIME_INCLUDE=
97 HSA_RUNTIME_LIB=
98 AC_SUBST(HSA_RUNTIME_INCLUDE)
99 AC_SUBST(HSA_RUNTIME_LIB)
100 HSA_RUNTIME_CPPFLAGS=
101 HSA_RUNTIME_LDFLAGS=
102
103 AC_ARG_WITH(hsa-runtime,
104 [AS_HELP_STRING([--with-hsa-runtime=PATH],
105 [specify prefix directory for installed HSA run-time package.
106 Equivalent to --with-hsa-runtime-include=PATH/include
107 plus --with-hsa-runtime-lib=PATH/lib])])
108 AC_ARG_WITH(hsa-runtime-include,
109 [AS_HELP_STRING([--with-hsa-runtime-include=PATH],
110 [specify directory for installed HSA run-time include files])])
111 AC_ARG_WITH(hsa-runtime-lib,
112 [AS_HELP_STRING([--with-hsa-runtime-lib=PATH],
113 [specify directory for the installed HSA run-time library])])
114 if test "x$with_hsa_runtime" != x; then
115 HSA_RUNTIME_INCLUDE=$with_hsa_runtime/include
116 HSA_RUNTIME_LIB=$with_hsa_runtime/lib
117 fi
118 if test "x$with_hsa_runtime_include" != x; then
119 HSA_RUNTIME_INCLUDE=$with_hsa_runtime_include
120 fi
121 if test "x$with_hsa_runtime_lib" != x; then
122 HSA_RUNTIME_LIB=$with_hsa_runtime_lib
123 fi
124 if test "x$HSA_RUNTIME_INCLUDE" != x; then
125 HSA_RUNTIME_CPPFLAGS=-I$HSA_RUNTIME_INCLUDE
126 fi
127 if test "x$HSA_RUNTIME_LIB" != x; then
128 HSA_RUNTIME_LDFLAGS=-L$HSA_RUNTIME_LIB
129 fi
130
131 PLUGIN_HSA=0
132 PLUGIN_HSA_CPPFLAGS=
133 PLUGIN_HSA_LDFLAGS=
134 PLUGIN_HSA_LIBS=
135 AC_SUBST(PLUGIN_HSA)
136 AC_SUBST(PLUGIN_HSA_CPPFLAGS)
137 AC_SUBST(PLUGIN_HSA_LDFLAGS)
138 AC_SUBST(PLUGIN_HSA_LIBS)
139
140 # Parse '--enable-offload-targets', figure out the corresponding libgomp
141 # plugins, and configure to find the corresponding offload compilers.
142 # 'offload_plugins' and 'offload_targets' will be populated in the same order.
143 offload_plugins=
144 offload_targets=
145 AC_SUBST(offload_plugins)
146 AC_SUBST(offload_targets)
147 offload_additional_options=
148 offload_additional_lib_paths=
149 AC_SUBST(offload_additional_options)
150 AC_SUBST(offload_additional_lib_paths)
151 if test x"$enable_offload_targets" != x; then
152 for tgt in `echo $enable_offload_targets | sed -e 's#,# #g'`; do
153 tgt_dir=`echo $tgt | grep '=' | sed 's/.*=//'`
154 tgt=`echo $tgt | sed 's/=.*//'`
155 tgt_plugin=
156 case $tgt in
157 *-intelmic-* | *-intelmicemul-*)
158 tgt_plugin=intelmic
159 ;;
160 nvptx*)
161 tgt_plugin=nvptx
162 PLUGIN_NVPTX=$tgt
163 if test "x$CUDA_DRIVER_LIB" != xno \
164 && test "x$CUDA_DRIVER_LIB" != xno; then
165 PLUGIN_NVPTX_CPPFLAGS=$CUDA_DRIVER_CPPFLAGS
166 PLUGIN_NVPTX_LDFLAGS=$CUDA_DRIVER_LDFLAGS
167 PLUGIN_NVPTX_LIBS='-lcuda'
168
169 PLUGIN_NVPTX_save_CPPFLAGS=$CPPFLAGS
170 CPPFLAGS="$PLUGIN_NVPTX_CPPFLAGS $CPPFLAGS"
171 PLUGIN_NVPTX_save_LDFLAGS=$LDFLAGS
172 LDFLAGS="$PLUGIN_NVPTX_LDFLAGS $LDFLAGS"
173 PLUGIN_NVPTX_save_LIBS=$LIBS
174 LIBS="$PLUGIN_NVPTX_LIBS $LIBS"
175 AC_LINK_IFELSE(
176 [AC_LANG_PROGRAM(
177 [#include "cuda.h"],
178 [CUresult r = cuCtxPushCurrent (NULL);])],
179 [PLUGIN_NVPTX=1])
180 CPPFLAGS=$PLUGIN_NVPTX_save_CPPFLAGS
181 LDFLAGS=$PLUGIN_NVPTX_save_LDFLAGS
182 LIBS=$PLUGIN_NVPTX_save_LIBS
183 fi
184 case $PLUGIN_NVPTX in
185 nvptx*)
186 if (test "x$CUDA_DRIVER_INCLUDE" = x \
187 || test "x$CUDA_DRIVER_INCLUDE" = xno) \
188 && (test "x$CUDA_DRIVER_LIB" = x \
189 || test "x$CUDA_DRIVER_LIB" = xno); then
190 PLUGIN_NVPTX=1
191 PLUGIN_NVPTX_CPPFLAGS='-I$(srcdir)/plugin/cuda'
192 PLUGIN_NVPTX_LIBS='-ldl'
193 PLUGIN_NVPTX_DYNAMIC=1
194 else
195 PLUGIN_NVPTX=0
196 AC_MSG_ERROR([CUDA driver package required for nvptx support])
197 fi
198 ;;
199 esac
200 ;;
201 hsa*)
202 case "${target}" in
203 x86_64-*-*)
204 case " ${CC} ${CFLAGS} " in
205 *" -m32 "*)
206 PLUGIN_HSA=0
207 ;;
208 *)
209 tgt_plugin=hsa
210 PLUGIN_HSA=$tgt
211 PLUGIN_HSA_CPPFLAGS=$HSA_RUNTIME_CPPFLAGS
212 PLUGIN_HSA_LDFLAGS="$HSA_RUNTIME_LDFLAGS"
213 PLUGIN_HSA_LIBS="-ldl"
214
215 PLUGIN_HSA_save_CPPFLAGS=$CPPFLAGS
216 CPPFLAGS="$PLUGIN_HSA_CPPFLAGS $CPPFLAGS"
217 PLUGIN_HSA_save_LDFLAGS=$LDFLAGS
218 LDFLAGS="$PLUGIN_HSA_LDFLAGS $LDFLAGS"
219 PLUGIN_HSA_save_LIBS=$LIBS
220 LIBS="$PLUGIN_HSA_LIBS $LIBS"
221
222 PLUGIN_HSA=1
223 CPPFLAGS=$PLUGIN_HSA_save_CPPFLAGS
224 LDFLAGS=$PLUGIN_HSA_save_LDFLAGS
225 LIBS=$PLUGIN_HSA_save_LIBS
226 case $PLUGIN_HSA in
227 hsa*)
228 HSA_PLUGIN=0
229 AC_MSG_ERROR([HSA run-time package required for HSA support])
230 ;;
231 esac
232 ;;
233 esac
234 ;;
235 *-*-*)
236 PLUGIN_HSA=0
237 ;;
238 esac
239 ;;
240 *)
241 AC_MSG_ERROR([unknown offload target specified])
242 ;;
243 esac
244 if test x"$tgt_plugin" = x; then
245 # Not configuring libgomp for this offload target if we're not building
246 # the corresponding offload plugin.
247 continue
248 elif test x"$offload_plugins" = x; then
249 offload_plugins=$tgt_plugin
250 offload_targets=$tgt
251 else
252 offload_plugins=$offload_plugins,$tgt_plugin
253 offload_targets=$offload_targets,$tgt
254 fi
255 # Configure additional search paths.
256 if test "$tgt_plugin" = hsa; then
257 # Offloading compilation is all handled by the target compiler.
258 :
259 elif test x"$tgt_dir" != x; then
260 offload_additional_options="$offload_additional_options -B$tgt_dir/libexec/gcc/\$(target_alias)/\$(gcc_version) -B$tgt_dir/bin"
261 offload_additional_lib_paths="$offload_additional_lib_paths:$tgt_dir/lib64:$tgt_dir/lib:$tgt_dir/lib32"
262 else
263 offload_additional_options="$offload_additional_options -B\$(libexecdir)/gcc/\$(target_alias)/\$(gcc_version) -B\$(bindir)"
264 offload_additional_lib_paths="$offload_additional_lib_paths:$toolexeclibdir"
265 fi
266 done
267 fi
268 AC_DEFINE_UNQUOTED(OFFLOAD_PLUGINS, "$offload_plugins",
269 [Define to offload plugins, separated by commas.])
270 AM_CONDITIONAL([PLUGIN_NVPTX], [test $PLUGIN_NVPTX = 1])
271 AC_DEFINE_UNQUOTED([PLUGIN_NVPTX], [$PLUGIN_NVPTX],
272 [Define to 1 if the NVIDIA plugin is built, 0 if not.])
273 AC_DEFINE_UNQUOTED([PLUGIN_NVPTX_DYNAMIC], [$PLUGIN_NVPTX_DYNAMIC],
274 [Define to 1 if the NVIDIA plugin should dlopen libcuda.so.1, 0 if it should be linked against it.])
275 AM_CONDITIONAL([PLUGIN_HSA], [test $PLUGIN_HSA = 1])
276 AC_DEFINE_UNQUOTED([PLUGIN_HSA], [$PLUGIN_HSA],
277 [Define to 1 if the HSA plugin is built, 0 if not.])
278
279 if test "$HSA_RUNTIME_LIB" != ""; then
280 HSA_RUNTIME_LIB="$HSA_RUNTIME_LIB/"
281 fi
282
283 AC_DEFINE_UNQUOTED([HSA_RUNTIME_LIB], ["$HSA_RUNTIME_LIB"],
284 [Define path to HSA runtime.])
285