configfrag.ac revision 1.4
1# Plugins for offload execution, configure.ac fragment.  -*- mode: autoconf -*-
2#
3# Copyright (C) 2014-2018 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
29offload_targets=
30AC_SUBST(offload_targets)
31plugin_support=yes
32AC_CHECK_LIB(dl, dlsym, , [plugin_support=no])
33if test x"$plugin_support" = xyes; then
34  AC_DEFINE(PLUGIN_SUPPORT, 1,
35    [Define if all infrastructure, needed for plugins, is supported.])
36elif test "x${enable_offload_targets-no}" != xno; then
37  AC_MSG_ERROR([Can't support offloading without support for plugins])
38fi
39AC_CHECK_HEADERS_ONCE(unistd.h)
40AC_CHECK_FUNCS_ONCE(secure_getenv __secure_getenv getuid geteuid getgid getegid)
41
42
43# Look for the CUDA driver package.
44CUDA_DRIVER_INCLUDE=
45CUDA_DRIVER_LIB=
46AC_SUBST(CUDA_DRIVER_INCLUDE)
47AC_SUBST(CUDA_DRIVER_LIB)
48CUDA_DRIVER_CPPFLAGS=
49CUDA_DRIVER_LDFLAGS=
50AC_ARG_WITH(cuda-driver,
51	[AS_HELP_STRING([--with-cuda-driver=PATH],
52		[specify prefix directory for installed CUDA driver package.
53		 Equivalent to --with-cuda-driver-include=PATH/include
54		 plus --with-cuda-driver-lib=PATH/lib])])
55AC_ARG_WITH(cuda-driver-include,
56	[AS_HELP_STRING([--with-cuda-driver-include=PATH],
57		[specify directory for installed CUDA driver include files])])
58AC_ARG_WITH(cuda-driver-lib,
59	[AS_HELP_STRING([--with-cuda-driver-lib=PATH],
60		[specify directory for the installed CUDA driver library])])
61case "x$with_cuda_driver" in
62  x | xno) ;;
63  *) CUDA_DRIVER_INCLUDE=$with_cuda_driver/include
64     CUDA_DRIVER_LIB=$with_cuda_driver/lib
65     ;;
66esac
67if test "x$with_cuda_driver_include" != x; then
68  CUDA_DRIVER_INCLUDE=$with_cuda_driver_include
69fi
70if test "x$with_cuda_driver_lib" != x; then
71  CUDA_DRIVER_LIB=$with_cuda_driver_lib
72fi
73if test "x$CUDA_DRIVER_INCLUDE" != x; then
74  CUDA_DRIVER_CPPFLAGS=-I$CUDA_DRIVER_INCLUDE
75fi
76if test "x$CUDA_DRIVER_LIB" != x; then
77  CUDA_DRIVER_LDFLAGS=-L$CUDA_DRIVER_LIB
78fi
79
80PLUGIN_NVPTX=0
81PLUGIN_NVPTX_CPPFLAGS=
82PLUGIN_NVPTX_LDFLAGS=
83PLUGIN_NVPTX_LIBS=
84PLUGIN_NVPTX_DYNAMIC=0
85AC_SUBST(PLUGIN_NVPTX)
86AC_SUBST(PLUGIN_NVPTX_CPPFLAGS)
87AC_SUBST(PLUGIN_NVPTX_LDFLAGS)
88AC_SUBST(PLUGIN_NVPTX_LIBS)
89
90# Look for HSA run-time, its includes and libraries
91
92HSA_RUNTIME_INCLUDE=
93HSA_RUNTIME_LIB=
94AC_SUBST(HSA_RUNTIME_INCLUDE)
95AC_SUBST(HSA_RUNTIME_LIB)
96HSA_RUNTIME_CPPFLAGS=
97HSA_RUNTIME_LDFLAGS=
98
99AC_ARG_WITH(hsa-runtime,
100	[AS_HELP_STRING([--with-hsa-runtime=PATH],
101		[specify prefix directory for installed HSA run-time package.
102		 Equivalent to --with-hsa-runtime-include=PATH/include
103		 plus --with-hsa-runtime-lib=PATH/lib])])
104AC_ARG_WITH(hsa-runtime-include,
105	[AS_HELP_STRING([--with-hsa-runtime-include=PATH],
106		[specify directory for installed HSA run-time include files])])
107AC_ARG_WITH(hsa-runtime-lib,
108	[AS_HELP_STRING([--with-hsa-runtime-lib=PATH],
109		[specify directory for the installed HSA run-time library])])
110if test "x$with_hsa_runtime" != x; then
111  HSA_RUNTIME_INCLUDE=$with_hsa_runtime/include
112  HSA_RUNTIME_LIB=$with_hsa_runtime/lib
113fi
114if test "x$with_hsa_runtime_include" != x; then
115  HSA_RUNTIME_INCLUDE=$with_hsa_runtime_include
116fi
117if test "x$with_hsa_runtime_lib" != x; then
118  HSA_RUNTIME_LIB=$with_hsa_runtime_lib
119fi
120if test "x$HSA_RUNTIME_INCLUDE" != x; then
121  HSA_RUNTIME_CPPFLAGS=-I$HSA_RUNTIME_INCLUDE
122fi
123if test "x$HSA_RUNTIME_LIB" != x; then
124  HSA_RUNTIME_LDFLAGS=-L$HSA_RUNTIME_LIB
125fi
126
127PLUGIN_HSA=0
128PLUGIN_HSA_CPPFLAGS=
129PLUGIN_HSA_LDFLAGS=
130PLUGIN_HSA_LIBS=
131AC_SUBST(PLUGIN_HSA)
132AC_SUBST(PLUGIN_HSA_CPPFLAGS)
133AC_SUBST(PLUGIN_HSA_LDFLAGS)
134AC_SUBST(PLUGIN_HSA_LIBS)
135
136# Get offload targets and path to install tree of offloading compiler.
137offload_additional_options=
138offload_additional_lib_paths=
139AC_SUBST(offload_additional_options)
140AC_SUBST(offload_additional_lib_paths)
141if test x"$enable_offload_targets" != x; then
142  for tgt in `echo $enable_offload_targets | sed -e 's#,# #g'`; do
143    tgt_dir=`echo $tgt | grep '=' | sed 's/.*=//'`
144    tgt=`echo $tgt | sed 's/=.*//'`
145    tgt_name=
146    case $tgt in
147      *-intelmic-* | *-intelmicemul-*)
148	tgt_name=intelmic
149	;;
150      nvptx*)
151        tgt_name=nvptx
152	PLUGIN_NVPTX=$tgt
153	PLUGIN_NVPTX_CPPFLAGS=$CUDA_DRIVER_CPPFLAGS
154	PLUGIN_NVPTX_LDFLAGS=$CUDA_DRIVER_LDFLAGS
155	PLUGIN_NVPTX_LIBS='-lcuda'
156
157	PLUGIN_NVPTX_save_CPPFLAGS=$CPPFLAGS
158	CPPFLAGS="$PLUGIN_NVPTX_CPPFLAGS $CPPFLAGS"
159	PLUGIN_NVPTX_save_LDFLAGS=$LDFLAGS
160	LDFLAGS="$PLUGIN_NVPTX_LDFLAGS $LDFLAGS"
161	PLUGIN_NVPTX_save_LIBS=$LIBS
162	LIBS="$PLUGIN_NVPTX_LIBS $LIBS"
163	AC_LINK_IFELSE(
164	  [AC_LANG_PROGRAM(
165	    [#include "cuda.h"],
166	      [CUresult r = cuCtxPushCurrent (NULL);])],
167	  [PLUGIN_NVPTX=1])
168	CPPFLAGS=$PLUGIN_NVPTX_save_CPPFLAGS
169	LDFLAGS=$PLUGIN_NVPTX_save_LDFLAGS
170	LIBS=$PLUGIN_NVPTX_save_LIBS
171	case $PLUGIN_NVPTX in
172	  nvptx*)
173	    if test "x$CUDA_DRIVER_INCLUDE" = x \
174	       && test "x$CUDA_DRIVER_LIB" = x; then
175	      PLUGIN_NVPTX=1
176	      PLUGIN_NVPTX_CPPFLAGS='-I$(srcdir)/plugin/cuda'
177	      PLUGIN_NVPTX_LIBS='-ldl'
178	      PLUGIN_NVPTX_DYNAMIC=1
179	    else
180	      PLUGIN_NVPTX=0
181	      AC_MSG_ERROR([CUDA driver package required for nvptx support])
182	    fi
183	  ;;
184	esac
185	;;
186      hsa*)
187	case "${target}" in
188	  x86_64-*-*)
189	    case " ${CC} ${CFLAGS} " in
190	      *" -m32 "*)
191	        PLUGIN_HSA=0
192		;;
193	      *)
194	        tgt_name=hsa
195	        PLUGIN_HSA=$tgt
196	        PLUGIN_HSA_CPPFLAGS=$HSA_RUNTIME_CPPFLAGS
197	        PLUGIN_HSA_LDFLAGS="$HSA_RUNTIME_LDFLAGS"
198	        PLUGIN_HSA_LIBS="-ldl"
199
200	        PLUGIN_HSA_save_CPPFLAGS=$CPPFLAGS
201	        CPPFLAGS="$PLUGIN_HSA_CPPFLAGS $CPPFLAGS"
202	        PLUGIN_HSA_save_LDFLAGS=$LDFLAGS
203	        LDFLAGS="$PLUGIN_HSA_LDFLAGS $LDFLAGS"
204	        PLUGIN_HSA_save_LIBS=$LIBS
205	        LIBS="$PLUGIN_HSA_LIBS $LIBS"
206
207	        PLUGIN_HSA=1
208	        CPPFLAGS=$PLUGIN_HSA_save_CPPFLAGS
209	        LDFLAGS=$PLUGIN_HSA_save_LDFLAGS
210	        LIBS=$PLUGIN_HSA_save_LIBS
211	        case $PLUGIN_HSA in
212	          hsa*)
213	            HSA_PLUGIN=0
214	            AC_MSG_ERROR([HSA run-time package required for HSA support])
215	            ;;
216	        esac
217		;;
218	      esac
219    	    ;;
220	  *-*-*)
221	    PLUGIN_HSA=0
222            ;;
223        esac
224        ;;
225      *)
226	AC_MSG_ERROR([unknown offload target specified])
227	;;
228    esac
229    if test x"$tgt_name" = x; then
230      # Don't configure libgomp for this offloading target if we don't build
231      # the corresponding plugin.
232      continue
233    elif test x"$offload_targets" = x; then
234      offload_targets=$tgt_name
235    else
236      offload_targets=$offload_targets,$tgt_name
237    fi
238    if test "$tgt_name" = hsa; then
239      # Offloading compilation is all handled by the target compiler.
240      :
241    elif test x"$tgt_dir" != x; then
242      offload_additional_options="$offload_additional_options -B$tgt_dir/libexec/gcc/\$(target_alias)/\$(gcc_version) -B$tgt_dir/bin"
243      offload_additional_lib_paths="$offload_additional_lib_paths:$tgt_dir/lib64:$tgt_dir/lib:$tgt_dir/lib32"
244    else
245      offload_additional_options="$offload_additional_options -B\$(libexecdir)/gcc/\$(target_alias)/\$(gcc_version) -B\$(bindir)"
246      offload_additional_lib_paths="$offload_additional_lib_paths:$toolexeclibdir"
247    fi
248  done
249fi
250AC_DEFINE_UNQUOTED(OFFLOAD_TARGETS, "$offload_targets",
251  [Define to offload targets, separated by commas.])
252AM_CONDITIONAL([PLUGIN_NVPTX], [test $PLUGIN_NVPTX = 1])
253AC_DEFINE_UNQUOTED([PLUGIN_NVPTX], [$PLUGIN_NVPTX],
254  [Define to 1 if the NVIDIA plugin is built, 0 if not.])
255AC_DEFINE_UNQUOTED([PLUGIN_NVPTX_DYNAMIC], [$PLUGIN_NVPTX_DYNAMIC],
256  [Define to 1 if the NVIDIA plugin should dlopen libcuda.so.1, 0 if it should be linked against it.])
257AM_CONDITIONAL([PLUGIN_HSA], [test $PLUGIN_HSA = 1])
258AC_DEFINE_UNQUOTED([PLUGIN_HSA], [$PLUGIN_HSA],
259  [Define to 1 if the HSA plugin is built, 0 if not.])
260
261if test "$HSA_RUNTIME_LIB" != ""; then
262  HSA_RUNTIME_LIB="$HSA_RUNTIME_LIB/"
263fi
264
265AC_DEFINE_UNQUOTED([HSA_RUNTIME_LIB], ["$HSA_RUNTIME_LIB"],
266  [Define path to HSA runtime.])
267