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
|
#
#
# Copyright (C) 2000-2021 the YAMBO team
# http://www.yambo-code.org
#
# Authors (see AUTHORS file for details): DS
#
# This file is distributed under the terms of the GNU
# General Public License. You can redistribute it and/or
# modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation;
# either version 2, or (at your option) any later version.
#
# This program is distributed in the hope that it will
# be useful, but WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free
# Software Foundation, Inc., 59 Temple Place - Suite 330,Boston,
# MA 02111-1307, USA or visit http://www.gnu.org/copyleft/gpl.txt.
#
AC_DEFUN([ACX_LIB_GPU], [
dnl Check if the library was given in the command line
dnl if not, use environment variables or defaults
AC_ARG_WITH(cuda_libs, [AS_HELP_STRING([--with-cuda-libs=<libs>],
[Use libcuda libraries <libs>],[32])])
AC_ARG_WITH(cuda_incs, [AS_HELP_STRING([--with-cuda-incs=<incs>],
[Use libcuda include options <incs>],[32])])
#
AC_ARG_WITH(cuda_libdir, [AS_HELP_STRING([--with-cuda-libdir=<path>],
[Path to the libcuda lib directory],[32])])
AC_ARG_WITH(cuda_includedir, [AS_HELP_STRING([--with-cuda-includedir=<path>],
[Path to the libcuda include directory],[32])])
#
AC_ARG_WITH(cuda_path, [AS_HELP_STRING([--with-cuda-path=<path>],
[Path to libcuda install directory],[32])])
#
AC_ARG_WITH(rocm_libdir, [AS_HELP_STRING([--with-rocm-libdir=<path>],
[Path to the rocm lib directory],[32])])
AC_ARG_WITH(rocm_includedir, [AS_HELP_STRING([--with-rocm-includedir=<path>],
[Path to the rocm include directory],[32])])
#
AC_ARG_WITH(rocm_path, [AS_HELP_STRING([--with-rocm-path=<path>],
[Path to rocm install directory],[32])])
#
#AC_ARG_ENABLE([cuda-libs-check],
# [AS_HELP_STRING([--enable-cuda-libs-check=yes],[The configure script will check CUDA installation and report problems @<:@default=yes@:>@])],
# [],[enable_cuda_libs_check=yes])
acx_libcuda_ok="no"
internal_libcuda="no"
compile_libcuda="no"
use_libcuda="no"
# Cuda and ROCm libraries are needed only in one of the three following cases
if test x"$enable_cuda_fortran" != "xno" || test x"$enable_openacc" != "xno" || test x"$enable_openmp" != "xno" ; then
#
dnl Heuristics to detect CUDA dir
if test "x$with_cuda_path" = "x" ; then with_cuda_path="$CUDA_PATH" ; fi
if test "x$with_cuda_path" = "x" ; then with_cuda_path="$CUDA_ROOT" ; fi
if test "x$with_cuda_path" = "x" ; then with_cuda_path="$CUDA_HOME" ; fi
LIBCUDA_PATH="$with_cuda_path"
#
dnl Heuristics to detect ROCm dir
if test "x$with_rocm_path" = "x" ; then with_rocm_path="$ROCM_PATH" ; fi
if test "x$with_rocm_path" = "x" ; then with_rocm_path="$ROCM_ROOT" ; fi
if test "x$with_rocm_path" = "x" ; then with_rocm_path="$ROCM_HOME" ; fi
LIBROCM_PATH="$with_rocm_path"
if test -d "$with_cuda_path"; then
libcuda_incdir="$with_cuda_path/include"
libcuda_libdir="$with_cuda_path/lib"
if ! test -d "$libcuda_libdir" ; then libcuda_libdir="$with_cuda_path/lib64" ; fi
fi
if test -d "$with_cuda_includedir"; then libcuda_incdir="$with_cuda_includedir" ; fi
if test -d "$with_cuda_libdir"; then libcuda_libdir="$with_cuda_libdir" ; fi
if test -d "$with_rocm_path"; then
librocm_incdir="$with_rocm_path/include"
librocm_libdir="$with_rocm_path/lib"
if ! test -d "$librocm_libdir" ; then librocm_libdir="$with_rocm_path/lib" ; fi
fi
if test -d "$with_rocm_includedir"; then librocm_incdir="$with_rocm_includedir" ; fi
if test -d "$with_rocm_libdir"; then librocm_libdir="$with_rocm_libdir" ; fi
LIBROCM_LIBS="-L$librocm_libdir -lrocblas"
LIBROCM_INCS="-I$librocm_incdir"
dnl Backup LIBS and FCFLAGS
acx_libcuda_save_LIBS="$LIBS"
acx_libcuda_save_FCFLAGS="$FCFLAGS"
#Test to be finalized, for now it is always going to succeed
dnl The tests
AC_LANG_PUSH(Fortran)
dnl The following program should work with all version of libcuda
testprog="AC_LANG_PROGRAM([],[
integer ierr
ierr=cuInit
ierr=cudaMalloc
ierr=cublasInit
ierr=cufftPlanMany
])"
LIBCUDA_INCS=""
if test x"$CUDA_INCS" != "x" ; then LIBCUDA_INCS="$CUDA_INCS" ; fi
if test x"$libcuda_incdir" != "x" ; then LIBCUDA_INCS="$imod$libcuda_incdir" ; fi
if test x"$with_cuda_incs" != "x" ; then LIBCUDA_INCS="$with_cuda_incs" ; fi
FCFLAGS="$LIBCUDA_INCS $acx_libcuda_save_FCFLAGS"
# set from environment variable, if not blank
if test ! -z "$CUDA_LIBS"; then
AC_MSG_CHECKING([for libcuda from environment])
LIBCUDA_LIBS="$CUDA_LIBS"
LIBS="$LIBCUDA_LIBS"
dnl $acx_libcuda_save_LIBS"
AC_LINK_IFELSE($testprog, [acx_libcuda_ok=yes], [])
fi
# set from --with-cuda-libs flag
if test x"$acx_libcuda_ok" = xno && test ! -z "$with_cuda_libs" ; then
AC_MSG_CHECKING([for libcuda from --with-cuda-libs])
LIBCUDA_LIBS="$with_cuda_libs"
LIBS="$LIBCUDA_LIBS"
dnl $acx_libcuda_save_LIBS"
AC_LINK_IFELSE($testprog, [acx_libcuda_ok=yes], [])
fi
# dynamic linkage, separate Fortran interface
if test x"$acx_libcuda_ok" = xno; then
AC_MSG_CHECKING([for libcuda from specified libcuda path, dynamic])
LIBCUDA_LIBS="-L$libcuda_libdir -lcufft -lcusolver -lcublas -lcudart -lcuda"
LIBS="$LIBCUDA_LIBS"
dnl $acx_libcuda_save_LIBS"
AC_LINK_IFELSE($testprog, [acx_libcuda_ok=yes], [])
fi
# static linkage, separate Fortran interface
if test x"$acx_libcuda_ok" = xno; then
AC_MSG_CHECKING([static])
LIBCUDA_LIBS="$libcuda_libdir/libcuda.a"
LIBS="$LIBCUDA_LIBS"
dnl $acx_libcuda_save_LIBS"
AC_LINK_IFELSE($testprog, [acx_libcuda_ok=yes], [])
fi
dnl Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
if test x"$acx_libcuda_ok" = xyes; then
use_libcuda=yes
compile_libcuda=no
internal_libcuda=no
#
AC_DEFINE(HAVE_LIBCUDA, 1, [Defined if you have the LIBCUDA library.])
AC_MSG_RESULT([yes.])
else
AC_MSG_RESULT([not found.])
use_libcuda=no
compile_libcuda=no
internal_libcuda=no
LIBCUDA_LIBS=""
LIBCUDA_INCS=""
LIBCUDA_PATH=""
fi
AC_LANG_POP(Fortran)
fi
#
# Internal libcuda not available at the moment
#
#if test x"$acx_libcuda_ok" = xno; then
# internal_libcuda="yes"
# LIBCUDA_LIBS="${extlibs_path}/${FCKIND}/${FC}/lib/libcuda.a"
# LIBCUDA_INCS="$imod${extlibs_path}/${FCKIND}/${FC}/include"
# if test -e "${extlibs_path}/${FCKIND}/${FC}/lib/libcuda.a"; then
# compile_libcuda="no"
# AC_MSG_RESULT([Compatible external DevXlib not found/specified. Found internal already compiled.])
# else
# compile_libcuda="yes"
# AC_MSG_RESULT([Compatible external DevXlib not found/specified. Internal to be compiled.])
# fi
#fi
AC_SUBST(LIBCUDA_LIBS)
AC_SUBST(LIBCUDA_INCS)
AC_SUBST(LIBCUDA_PATH)
AC_SUBST(LIBROCM_LIBS)
AC_SUBST(LIBROCM_INCS)
AC_SUBST(LIBROCM_PATH)
AC_SUBST(use_libcuda)
AC_SUBST(compile_libcuda)
AC_SUBST(internal_libcuda)
FCFLAGS="$acx_libcuda_save_FCFLAGS"
LIBS="$acx_libcuda_save_LIBS"
])
|