From 56cda368a9d0419b90919d6c24f285b6d9c38a61 Mon Sep 17 00:00:00 2001 From: Giovanni La Mura <giovanni.lamura@inaf.it> Date: Thu, 5 Sep 2024 17:31:50 +0000 Subject: [PATCH] Implement fall-back search for cudart --- build/configure | 118 +++++++++++++++++++++++++-------------------- build/configure.ac | 59 +++++++++++++---------- 2 files changed, 99 insertions(+), 78 deletions(-) diff --git a/build/configure b/build/configure index 22808d5f..5fa0692f 100755 --- a/build/configure +++ b/build/configure @@ -25366,33 +25366,40 @@ then : fi # end of 64-bit decision tree pkg-config --version > /dev/null use_pkg_config=$? - if test "x$use_pkg_config" = "x0"; then - # pkg-config is available - declare -a pkg_array=$(pkg-config --list-all | grep cudart) - for i in "${pkg_array[@]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep cudart > /dev/null - result=$? - if test "x$result" = "x0"; then - # CUDA runtime detected - cuda_pkg=$(for i in "${pkg_array[@]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep cudart) - CUDAFLAGS=$(pkg-config --cflags ${cuda_pkg}) - CUDALDFLAGS=$(pkg-config --libs ${cuda_pkg}) - fi # end of CUDA runtime decision tree - else - # pkg-config is not available - if test -f /usr/local/cuda/include/cuda.h; then - CUDAFLAGS="-I/usr/local/cuda/include" - CUDALDFLAGS="-L/usr/local/cuda/lib64 -lcudart" - elif test -f /usr/include/cuda.h; then - CUDAFLAGS="-I/usr/include" - CUDALDFLAGS="-lcudart" - elif test "x$CUDA_HOME" != "x"; then - CUDAFLAGS="-I${CUDA_HOME}/include" - CUDALDFLAGS="-L${CUDA_HOME}/lib64 -lcudart" - fi - fi # end of pkg-config decision tree + if test "x${CUDAFLAGS}${CUDALDFLAGS}" = "x"; then + if test "x$use_pkg_config" = "x0"; then + # pkg-config is available + declare -a pkg_array=$(pkg-config --list-all | grep cudart) + for i in "${pkg_array[@]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep cudart > /dev/null + result=$? + if test "x$result" = "x0"; then + # CUDA runtime detected + cuda_pkg=$(for i in "${pkg_array[@]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep cudart) + CUDAFLAGS=$(pkg-config --cflags ${cuda_pkg}) + CUDALDFLAGS=$(pkg-config --libs ${cuda_pkg}) + fi # end of CUDA runtime decision tree + echo $CUDALDFLAGS | grep cudart > /dev/null + cudart_check=$? + if test "x${cudart_check}" != "x0"; then + CUDALDFLAGS="$CUDALDFLAGS -lcudart" + fi + else + # pkg-config is not available + if test -f /usr/local/cuda/include/cuda.h; then + CUDAFLAGS="-I/usr/local/cuda/include" + CUDALDFLAGS="-L/usr/local/cuda/lib64 -lcudart" + elif test -f /usr/include/cuda.h; then + CUDAFLAGS="-I/usr/include" + CUDALDFLAGS="-lcudart" + elif test "x$CUDA_HOME" != "x"; then + CUDAFLAGS="-I${CUDA_HOME}/include" + CUDALDFLAGS="-L${CUDA_HOME}/lib64 -lcudart" + fi + fi # end of pkg-config decision tree + fi # end of CUDAFLAGS user override protection if test "x${MAGMA_ROOT}${MAGMA_HOME}${MAGMA_DIR}" = "x"; then # MAGMA environment is not defined - if "x$use_pkg_config" = "x0"; then + if test "x$use_pkg_config" = "x0"; then # use pkg-config to search for MAGMA declare -a pkg_array=$(pkg-config --list-all | grep magma) for i in "${pkg_array[@]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep magma > /dev/null @@ -25401,7 +25408,7 @@ then : # MAGMA was found magma_pkg=$(for i in "${pkg_array[@]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep magma) MAGMA_INCLUDE=$(pkg-config --cflags-only-I ${magma_pkg}) - MAGMA_LIBS_DIR=$(pkg-config --cflags-only-L ${magma_pkg}) + MAGMA_LIBS_DIR=$(pkg-config --libs-only-L ${magma_pkg}) export MAGMAFLAGS="-DUSE_MAGMA ${MAGMA_ILP64_FLAG} $CUDAFLAGS ${MAGMA_INCLUDE}" export MAGMALDFLAGS="$CUDALDFLAGS ${MAGMA_LIBS_DIR} -lmagma" fi # end of MAGMA decision tree @@ -25459,33 +25466,40 @@ else case e in #( fi # end of 64-bit decision tree pkg-config --version > /dev/null use_pkg_config=$? - if test "x$use_pkg_config" = "x0"; then - # pkg-config is available - declare -a pkg_array=$(pkg-config --list-all | grep cudart) - for i in "${pkg_array[@]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep cudart > /dev/null - result=$? - if test "x$result" = "x0"; then - # CUDA runtime detected - cuda_pkg=$(for i in "${pkg_array[@]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep cudart) - CUDAFLAGS=$(pkg-config --cflags ${cuda_pkg}) - CUDALDFLAGS=$(pkg-config --libs ${cuda_pkg}) - fi # end of CUDA runtime decision tree - else - # pkg-config is not available - if test -f /usr/local/cuda/include/cuda.h; then - CUDAFLAGS="-I/usr/local/cuda/include" - CUDALDFLAGS="-L/usr/local/cuda/lib64 -lcudart" - elif test -f /usr/include/cuda.h; then - CUDAFLAGS="-I/usr/include" - CUDALDFLAGS="-lcudart" - elif test "x$CUDA_HOME" != "x"; then - CUDAFLAGS="-I${CUDA_HOME}/include" - CUDALDFLAGS="-L${CUDA_HOME}/lib64 -lcudart" - fi - fi # end of pkg-config decision tree + if test "x${CUDAFLAGS}${CUDALDFLAGS}" = "x"; then + if test "x$use_pkg_config" = "x0"; then + # pkg-config is available + declare -a pkg_array=$(pkg-config --list-all | grep cudart) + for i in "${pkg_array[@]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep cudart > /dev/null + result=$? + if test "x$result" = "x0"; then + # CUDA runtime detected + cuda_pkg=$(for i in "${pkg_array[@]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep cudart) + CUDAFLAGS=$(pkg-config --cflags ${cuda_pkg}) + CUDALDFLAGS=$(pkg-config --libs ${cuda_pkg}) + fi # end of CUDA runtime decision tree + echo $CUDALDFLAGS | grep cudart > /dev/null + cudart_check=$? + if test "x${cudart_check}" != "x0"; then + CUDALDFLAGS="$CUDALDFLAGS -lcudart" + fi + else + # pkg-config is not available + if test -f /usr/local/cuda/include/cuda.h; then + CUDAFLAGS="-I/usr/local/cuda/include" + CUDALDFLAGS="-L/usr/local/cuda/lib64 -lcudart" + elif test -f /usr/include/cuda.h; then + CUDAFLAGS="-I/usr/include" + CUDALDFLAGS="-lcudart" + elif test "x$CUDA_HOME" != "x"; then + CUDAFLAGS="-I${CUDA_HOME}/include" + CUDALDFLAGS="-L${CUDA_HOME}/lib64 -lcudart" + fi + fi # end of pkg-config decision tree + fi # end of CUDAFLAGS user override protection if test "x${MAGMA_ROOT}${MAGMA_HOME}${MAGMA_DIR}" = "x"; then # MAGMA environment is not defined - if "x$use_pkg_config" = "x0"; then + if test "x$use_pkg_config" = "x0"; then # use pkg-config to search for MAGMA declare -a pkg_array=$(pkg-config --list-all | grep magma) for i in "${pkg_array[@]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep magma > /dev/null @@ -25494,7 +25508,7 @@ else case e in #( # MAGMA was found magma_pkg=$(for i in "${pkg_array[@]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep magma) MAGMA_INCLUDE=$(pkg-config --cflags-only-I ${magma_pkg}) - MAGMA_LIBS_DIR=$(pkg-config --cflags-only-L ${magma_pkg}) + MAGMA_LIBS_DIR=$(pkg-config --libs-only-L ${magma_pkg}) export MAGMAFLAGS="-DUSE_MAGMA ${MAGMA_ILP64_FLAG} $CUDAFLAGS ${MAGMA_INCLUDE}" export MAGMALDFLAGS="$CUDALDFLAGS ${MAGMA_LIBS_DIR} -lmagma" fi # end of MAGMA decision tree diff --git a/build/configure.ac b/build/configure.ac index 5b30c9aa..7ff1a35c 100644 --- a/build/configure.ac +++ b/build/configure.ac @@ -160,33 +160,40 @@ m4_define( fi # end of 64-bit decision tree pkg-config --version > /dev/null use_pkg_config=$? - if test "x$use_pkg_config" = "x0"; then - # pkg-config is available - declare -a pkg_array=$(pkg-config --list-all | grep cudart) - for i in "${pkg_array[[@]]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep cudart > /dev/null - result=$? - if test "x$result" = "x0"; then - # CUDA runtime detected - cuda_pkg=$(for i in "${pkg_array[[@]]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep cudart) - CUDAFLAGS=$(pkg-config --cflags ${cuda_pkg}) - CUDALDFLAGS=$(pkg-config --libs ${cuda_pkg}) - fi # end of CUDA runtime decision tree - else - # pkg-config is not available - if test -f /usr/local/cuda/include/cuda.h; then - CUDAFLAGS="-I/usr/local/cuda/include" - CUDALDFLAGS="-L/usr/local/cuda/lib64 -lcudart" - elif test -f /usr/include/cuda.h; then - CUDAFLAGS="-I/usr/include" - CUDALDFLAGS="-lcudart" - elif test "x$CUDA_HOME" != "x"; then - CUDAFLAGS="-I${CUDA_HOME}/include" - CUDALDFLAGS="-L${CUDA_HOME}/lib64 -lcudart" - fi - fi # end of pkg-config decision tree + if test "x${CUDAFLAGS}${CUDALDFLAGS}" = "x"; then + if test "x$use_pkg_config" = "x0"; then + # pkg-config is available + declare -a pkg_array=$(pkg-config --list-all | grep cudart) + for i in "${pkg_array[[@]]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep cudart > /dev/null + result=$? + if test "x$result" = "x0"; then + # CUDA runtime detected + cuda_pkg=$(for i in "${pkg_array[[@]]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep cudart) + CUDAFLAGS=$(pkg-config --cflags ${cuda_pkg}) + CUDALDFLAGS=$(pkg-config --libs ${cuda_pkg}) + fi # end of CUDA runtime decision tree + echo $CUDALDFLAGS | grep cudart > /dev/null + cudart_check=$? + if test "x${cudart_check}" != "x0"; then + CUDALDFLAGS="$CUDALDFLAGS -lcudart" + fi + else + # pkg-config is not available + if test -f /usr/local/cuda/include/cuda.h; then + CUDAFLAGS="-I/usr/local/cuda/include" + CUDALDFLAGS="-L/usr/local/cuda/lib64 -lcudart" + elif test -f /usr/include/cuda.h; then + CUDAFLAGS="-I/usr/include" + CUDALDFLAGS="-lcudart" + elif test "x$CUDA_HOME" != "x"; then + CUDAFLAGS="-I${CUDA_HOME}/include" + CUDALDFLAGS="-L${CUDA_HOME}/lib64 -lcudart" + fi + fi # end of pkg-config decision tree + fi # end of CUDAFLAGS user override protection if test "x${MAGMA_ROOT}${MAGMA_HOME}${MAGMA_DIR}" = "x"; then # MAGMA environment is not defined - if "x$use_pkg_config" = "x0"; then + if test "x$use_pkg_config" = "x0"; then # use pkg-config to search for MAGMA declare -a pkg_array=$(pkg-config --list-all | grep magma) for i in "${pkg_array[[@]]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep magma > /dev/null @@ -195,7 +202,7 @@ m4_define( # MAGMA was found magma_pkg=$(for i in "${pkg_array[[@]]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep magma) MAGMA_INCLUDE=$(pkg-config --cflags-only-I ${magma_pkg}) - MAGMA_LIBS_DIR=$(pkg-config --cflags-only-L ${magma_pkg}) + MAGMA_LIBS_DIR=$(pkg-config --libs-only-L ${magma_pkg}) export MAGMAFLAGS="-DUSE_MAGMA ${MAGMA_ILP64_FLAG} $CUDAFLAGS ${MAGMA_INCLUDE}" export MAGMALDFLAGS="$CUDALDFLAGS ${MAGMA_LIBS_DIR} -lmagma" fi # end of MAGMA decision tree -- GitLab