-
Notifications
You must be signed in to change notification settings - Fork 4
/
configure.ac
375 lines (307 loc) · 11.1 KB
/
configure.ac
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
#
# QMCkl - Quantum Monte Carlo kernel library (GPU addon)
#
# BSD 3-Clause License
#
# Copyright (c) 2020, TREX Center of Excellence
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. 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.
#
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# 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.
AC_PREREQ([2.69])
AC_INIT([qmckl_gpu],[1.0.0],[https://github.com/TREX-CoE/qmckl_gpu/issues],[],[https://trex-coe.github.io/qmckl/index.html] )
AM_INIT_AUTOMAKE([-Wall subdir-objects])
AM_PROG_AR
AC_PROG_CC
AC_PROG_FC
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
# Initialize Makefile
LT_INIT
AC_CONFIG_MACRO_DIRS([m4])
AC_ENABLE_SHARED
AC_ENABLE_STATIC
# Add mandatory CFLAGS/FCFLAGS
CFLAGS="-Iinclude ${CFLAGS}"
FCFLAGS="-Iinclude ${FCFLAGS}"
###
# TREXIO
###
# Get TREXIO path if any
AC_ARG_ENABLE([trexio],
[AS_HELP_STRING([--[enable|disable]-trexio],
[enable or disable support for TREXIO (configure will try to enable it by default)])],
[have_trexio=$enableval],
[have_trexio=yes])
AS_CASE([$have_trexio],
# Explicitely disabled
[no], [
AC_OUTPUT
echo \
"Note: TREXIO explicitely disabled, skipping it."
],
# Implicitely enabled (not mandatory)
[yes],
[AC_CHECK_LIB([trexio], [trexio_open], [],
[PKG_CHECK_MODULES([TREXIO], [trexio]) ])
CFLAGS="$CFLAGS $TREXIO_CFLAGS"
LIBS="$LIBS $TREXIO_LIBS"
AC_CHECK_HEADERS([trexio.h], [
ARGS="${ARGS} trexio"
have_trexio=yes
], [
AC_OUTPUT
echo \
"Warning: TREXIO not found. Library will be built without it."
have_trexio=no
])
ARGS="${ARGS} trexio"],
# Default case : explicitely enabled with specified path (mandatory)
[AS_IF([test ! -d "$enableval"], [
AC_MSG_ERROR([--enable-trexio=$enableval: argument is not a directory])])
AC_CHECK_HEADERS([trexio.h], [
TREXIO_LIBS="-L$have_trexio/lib -ltrexio"
TREXIO_CFLAGS="-I$have_trexio/include"
CFLAGS="$CFLAGS $TREXIO_CFLAGS"
LIBS="$LIBS $TREXIO_LIBS"
ARGS="${ARGS} trexio"
have_trexio=yes
],
[
AC_MSG_ERROR("trexio.h not found")
])
])
###
# cuBLAS / cuSolver (optional, enables additional kernels)
# TODO We should probably add compilation flags to link cuBLAS / solver automatically
# in case the flag is enabled
###
AC_ARG_ENABLE([cublas],
[AS_HELP_STRING([--enable-cublas],
[Enable compilation of kernels that use cuBLAS and cuSolver])],
[have_cublas=yes],
[have_cublas=no])
AC_ARG_ENABLE([floatmos],
[AS_HELP_STRING([--enable-floatmos],
[Use single precision to compute MOs (with --enable-cublas only)])],
[have_floatmos=yes],
[have_floatmos=no])
AC_ARG_ENABLE([cusparse],
[AS_HELP_STRING([--enable-cusparse],
[Enable compilation of kernels that use cuSPARSE])],
[have_cusparse=yes],
[have_cusparse=no])
AS_IF([ test "x$have_cublas" = "xyes" -a "x$have_cusparse" = "xyes" ], [
AC_OUTPUT
echo \
"Warning: cannot activate cuBLAS and cuSPARSE at the same time, activating cuBLAS only."
have_cusparse="no"
])
AS_IF([ test "x$have_floatmos" = "xyes" -a "x$have_cublas" = "xno" ], [
AC_OUTPUT
echo \
"Warning: --enable-floatmos working only with --enable-cublas, deactivating. "
have_floatmos="no"
])
####
## Enable OpenMP / OpenACC
####
# OpenMP + device pointers
AC_ARG_ENABLE(omp, [AS_HELP_STRING([--enable-omp],[Enable OpenMP device pointers functions])], have_omp=yes, have_omp=no)
# OpenACC + device pointers
AC_ARG_ENABLE(acc, [AS_HELP_STRING([--enable-acc],[Enable OpenACC device pointers functions])], have_acc=yes, have_acc=no)
# Auto offloading flags
AC_ARG_ENABLE(autoflags, [AS_HELP_STRING([--disable-autoflags],[By default, configure will try to infer and add offloading compiler flags by itself. Disable this option and set your flags manually if you encounter issues.])], have_autoflags=no, have_autoflags=yes)
AS_IF([test "x$have_autoflags" = "xyes"], [
echo "Autoflags have been kept enabled"
], [
echo "Autoflags have been disabled"
])
####
## Enable the optional Fortran interface
####
AC_ARG_ENABLE(fortran-interface, [AS_HELP_STRING([--enable-fortran-interface],[Enable the optional Fortran interface])], have_fortran_interface=yes, have_fortran_interface=no)
####
## Perform checks on what has been enabled (at least one function type, no OpenACC and OpenMP at the same time)
####
# Fallback solution if nothing is enabled :
# (probably because no GPU argument have been provided)
# Enable OpenMP offload by default
AS_IF([ test "x$have_omp" = "xno" -a "x$have_acc" = "xno"], [
AC_OUTPUT
echo \
"Warning: Neither OpenMP or OpenACC could be enabled using the passed arguments. Attempting to enable OpenMP as fallback."
have_omp="yes"
])
# Make sure that OpenMP and OpenACC are not enabled at the same time
AS_IF([test "x$have_omp" = "xyes" -a "x$have_acc" = "xyes"], [
AC_OUTPUT
echo \
"Error: Enabling both OpenMP and OpenACC at the same time is not enabled"
exit 1
])
####
## Enable gpu_blas lib
####
AC_ARG_WITH(libgpublas, [AS_HELP_STRING([--with-libgpublas],[Specify the support of blas for GPU])], have_gpublas=$withval, have_gpublas=no)
AS_IF([test "x$have_gpublas" != "xno"], [
AC_DEFINE([HAVE_LIBGPUBLAS], [1], [Enable libgpublas])
CFLAGS="$CFLAGS -L${have_gpublas}/lib -I${have_gpublas} -lgpublas"
])
####
## Set compiler flags
####
## Add compilers flags depending on what has been enabled
AS_IF([test "x$have_autoflags" = "xyes" -a "x$have_omp" = "xyes"], [
case $CC in
*gcc*)
CFLAGS="$CFLAGS -fopenmp -foffload=-lm"
FCFLAGS="$FCFLAGS -fopenmp -foffload=-lm"
;;
*nvc*)
CFLAGS="$CFLAGS -mp=gpu,noautopar"
FCFLAGS="$FCFLAGS -mp=gpu,noautopar"
;;
*clang*)
CFLAGS="$CFLAGS -fopenmp "
FCFLAGS="$FCFLAGS -fopenmp "
;;
*)
echo "Warning : compiler not recognized for OpenMP. Make sure to add necessary offload flags manually."
esac
])
AS_IF([test "x$have_autoflags" = "xyes" -a "x$have_acc" = "xyes"], [
case $CC in
*gcc*)
CFLAGS="$CFLAGS -fopenacc -foffload=-lm"
FCFLAGS="$FCFLAGS -fopenacc -foffload=-lm"
LDFLAGS="$LDFLAGS -lm -fopenacc"
;;
*nvc*)
CFLAGS="$CFLAGS -acc=gpu,noautopar -gpu=nordc"
FCFLAGS="$FCFLAGS -acc=gpu,noautopar -gpu=nordc"
;;
*)
echo "Warning : compiler not supported for OpenACC. Make sure to add necessary offload flags manually."
esac
])
# If TREXIO or cuBLAS have been enabled, define Automake & preprocessors variables
AS_IF([test "x$have_trexio" = "xyes"], [
AC_DEFINE([HAVE_TREXIO], [1], [Enable compilation of TREXIO functions])
])
AS_IF([test "x$have_cublas" = "xyes"], [
AC_DEFINE([HAVE_CUBLAS], [1], [Enable compilation of cuBLAS/cuSolver functions])
case $CC in
*nvc*)
CFLAGS="$CFLAGS -cudalib=cublas,cusolver"
;;
*)
echo "Warning : compiler not supported for cuBLAs linking"
esac
])
AS_IF([test "x$have_cusparse" = "xyes"], [
AC_DEFINE([HAVE_CUSPARSE], [1], [Enable compilation of cuSPARSE functions])
case $CC in
*nvc*)
echo "Warning : cuSPARSE needs cuda>=11.8. Setting -gpu=cuda11.8, change if another version is present inthe system."
CFLAGS="$CFLAGS -gpu=cuda11.8 -cudalib=cusparse"
;;
*)
echo "Warning : compiler not supported for cuBLAs linking"
esac
])
AS_IF([test "x$have_floatmos" = "xyes"], [
AC_DEFINE([HAVE_FLOATMOS], [1], [Using single-precision cuBLAS])
])
# Specific options required with some compilers
AS_CASE([$FC],
[*nvfortran*], [FCFLAGS="$FCFLAGS -fPIC"],
[*pgf90*], [FCFLAGS="$FCFLAGS -fPIC"],
[*pgf77*], [FCFLAGS="$FCFLAGS -fPIC"],
[])
####
## Define Makefile variables from configure flags
####
AM_CONDITIONAL([HAVE_TREXIO], [test "x$have_trexio" = "xyes"])
AM_CONDITIONAL([HAVE_OMP_DEVICE], [test "x$have_omp" = "xyes"])
AM_CONDITIONAL([HAVE_ACC_DEVICE], [test "x$have_acc" = "xyes"])
AM_CONDITIONAL([HAVE_FORTRAN_INTERFACE], [test "x$have_fortran_interface" = "xyes"])
AM_CONDITIONAL([HAVE_DEVICE_POINTERS], [test "x$have_omp" = "xyes" -o "x$have_acc" = "xyes"])
AM_CONDITIONAL([HAVE_CUBLAS], [test "x$have_cublas" = "xyes"])
AM_CONDITIONAL([HAVE_LIBGPUBLAS], [test "xhave_gpublas" != "xno"])
####
# Print configure status
####
AS_IF([test "x$have_fortran_interface" = "xyes"], [
AC_OUTPUT
echo \
"-------------------------------------------------
${PACKAGE_NAME} Version ${PACKAGE_VERSION}
Prefix: '${prefix}'
CC.................: ${CC}
FC.................: ${FC}
CFLAGS.............: ${CFLAGS}
FCFLAGS............: ${CFLAGS}
LDFLAGS:...........: ${LDFLAGS}
Autoflags .........: ${have_autoflags}
Fortran interface .: ${have_fortran_interface}
GPUBLAS ...........: ${have_gpublas}
TREXIO ............: ${have_trexio}
cuBLAS ............: ${have_cublas}
cuSPARSE ..........: ${have_cusparse}
OpenMP ............: ${have_omp}
OpenACC ...........: ${have_acc}
Now type 'make @<:@<target>@:>@'
where the optional <target> is:
all - build ${PACKAGE_NAME}
check - run tests
install - install
--------------------------------------------------"
], [
AC_OUTPUT
echo \
"-------------------------------------------------
${PACKAGE_NAME} Version ${PACKAGE_VERSION}
Prefix: '${prefix}'
CC.................: ${CC}
CFLAGS.............: ${CFLAGS}
LDFLAGS:...........: ${LDFLAGS}
Autoflags .........: ${have_autoflags}
Fortran interface .: ${have_fortran_interface}
GPUBLAS ...........: ${have_gpublas}
TREXIO ............: ${have_trexio}
cuBLAS ............: ${have_cublas}
cuSPARSE ..........: ${have_cusparse}
OpenMP ............: ${have_omp}
OpenACC ...........: ${have_acc}
Now type 'make @<:@<target>@:>@'
where the optional <target> is:
all - build ${PACKAGE_NAME}
check - run tests
install - install
--------------------------------------------------"
])