From 09c37451fc2c45fdbacceceb7b0a46dbba67fac9 Mon Sep 17 00:00:00 2001 From: Alberto Scolari Date: Mon, 5 Feb 2024 14:33:38 +0100 Subject: [PATCH 01/10] issue #171: changing default linking mode in grbcxx wrapper --- cmake/AddGRBInstall.cmake | 31 ++++++++++++++++--------------- src/CMakeLists.txt | 23 ++++++++++++++++------- src/grbcxx.in | 23 ++++++++++++----------- 3 files changed, 44 insertions(+), 33 deletions(-) diff --git a/cmake/AddGRBInstall.cmake b/cmake/AddGRBInstall.cmake index 94bd58f31..5dcdae642 100644 --- a/cmake/AddGRBInstall.cmake +++ b/cmake/AddGRBInstall.cmake @@ -72,7 +72,7 @@ set( HYBRID_BACKEND_INSTALL_DIR "${BINARY_LIBRARIES_INSTALL_DIR}/hybrid" ) # function( addBackendWrapperGenOptions backend ) set( multiValueArgs "COMPILER_COMMAND;RUNENV;RUNNER" - "COMPILE_DEFINITIONS;COMPILE_OPTIONS;LINK_FLAGS" + "COMPILE_DEFINITIONS;COMPILE_OPTIONS;LINK_FLAGS;LIB_DIR" ) cmake_parse_arguments( parsed "${options}" "${oneValueArgs}" "${multiValueArgs}" "${ARGN}" @@ -82,12 +82,15 @@ function( addBackendWrapperGenOptions backend ) message( FATAL_ERROR "cannot find ${backend} among available backends") endif() + assert_valid_variables( parsed_LIB_DIR ) + set( ${backend}_WRAPPER_COMPILER_COMMAND "${parsed_COMPILER_COMMAND}" PARENT_SCOPE ) if( NOT parsed_COMPILER_COMMAND ) set( ${backend}_WRAPPER_COMPILER_COMMAND "${CMAKE_CXX_COMPILER}" PARENT_SCOPE ) endif() set( ${backend}_WRAPPER_RUNENV "${parsed_RUNENV}" PARENT_SCOPE ) set( ${backend}_WRAPPER_RUNNER "${parsed_RUNNER}" PARENT_SCOPE ) + set( ${backend}_LIB_DIR "${parsed_LIB_DIR}" PARENT_SCOPE ) set( ${backend}_WRAPPER_COMPILE_DEFINITIONS "${parsed_COMPILE_DEFINITIONS}" PARENT_SCOPE ) @@ -116,16 +119,16 @@ endif() if( WITH_REFERENCE_BACKEND ) addBackendWrapperGenOptions( "reference" COMPILE_DEFINITIONS "${REFERENCE_SELECTION_DEFS}" - LINK_FLAGS "'${SHMEM_BACKEND_INSTALL_DIR}/lib${BACKEND_LIBRARY_OUTPUT_NAME}.a'" - "'${ALP_UTILS_INSTALL_DIR}/lib${ALP_UTILS_LIBRARY_OUTPUT_NAME}.a'" "${NUMA_LFLAG}" + LIB_DIR "${SHMEM_BACKEND_INSTALL_DIR}" + LINK_FLAGS "${NUMA_LFLAG}" ) endif() if( WITH_OMP_BACKEND ) addBackendWrapperGenOptions( "reference_omp" COMPILE_DEFINITIONS "${REFERENCE_OMP_SELECTION_DEFS}" - LINK_FLAGS "'${SHMEM_BACKEND_INSTALL_DIR}/lib${BACKEND_LIBRARY_OUTPUT_NAME}.a'" - "'${ALP_UTILS_INSTALL_DIR}/lib${ALP_UTILS_LIBRARY_OUTPUT_NAME}.a'" "${NUMA_LFLAG}" + LIB_DIR "${SHMEM_BACKEND_INSTALL_DIR}" + LINK_FLAGS "${NUMA_LFLAG}" ) endif() @@ -133,16 +136,16 @@ endif() if( WITH_HYPERDAGS_BACKEND ) addBackendWrapperGenOptions( "hyperdags" COMPILE_DEFINITIONS "${HYPERDAGS_SELECTION_DEFS};${HYPERDAGS_INCLUDE_DEFS}" - LINK_FLAGS "'${HYPERDAGS_BACKEND_INSTALL_DIR}/lib${BACKEND_LIBRARY_OUTPUT_NAME}.a'" - "'${ALP_UTILS_INSTALL_DIR}/lib${ALP_UTILS_LIBRARY_OUTPUT_NAME}.a'" "${NUMA_LFLAG}" + LIB_DIR "${HYPERDAGS_BACKEND_INSTALL_DIR}" + LINK_FLAGS "${NUMA_LFLAG}" ) endif() if( WITH_NONBLOCKING_BACKEND ) addBackendWrapperGenOptions( "nonblocking" COMPILE_DEFINITIONS "${NONBLOCKING_SELECTION_DEFS};${NONBLOCKING_INCLUDE_DEFS}" - LINK_FLAGS "'${SHMEM_BACKEND_INSTALL_DIR}/lib${BACKEND_LIBRARY_OUTPUT_NAME}.a'" - "'${ALP_UTILS_INSTALL_DIR}/lib${ALP_UTILS_LIBRARY_OUTPUT_NAME}.a'" "${NUMA_LFLAG}" + LIB_DIR "${SHMEM_BACKEND_INSTALL_DIR}" + LINK_FLAGS "${NUMA_LFLAG}" ) endif() @@ -173,9 +176,8 @@ if( WITH_BSP1D_BACKEND OR WITH_HYBRID_BACKEND ) COMPILER_COMMAND "${LPF_CXX_COMPILER}" RUNNER "${LPFRUN_CMD}" COMPILE_DEFINITIONS "${LPF_INCLUDE_DEFS};${BSP1D_SELECTION_DEFS}" - LINK_FLAGS "'${BSP1D_BACKEND_INSTALL_DIR}/lib${BACKEND_LIBRARY_OUTPUT_NAME}.a'" - "'${ALP_UTILS_INSTALL_DIR}/lib${ALP_UTILS_LIBRARY_OUTPUT_NAME}.a'" "${NUMA_LFLAG}" - "-llpf_hl" "-lpthread" "-lm" "-ldl" + LIB_DIR "${BSP1D_BACKEND_INSTALL_DIR}" + LINK_FLAGS "${NUMA_LFLAG}" "-lpthread" "-lm" ) endif() @@ -184,9 +186,8 @@ if( WITH_BSP1D_BACKEND OR WITH_HYBRID_BACKEND ) COMPILER_COMMAND "${LPF_CXX_COMPILER}" RUNNER "${LPFRUN_CMD}" COMPILE_DEFINITIONS "${LPF_INCLUDE_DEFS};${HYBRID_SELECTION_DEFS}" - LINK_FLAGS "'${HYBRID_BACKEND_INSTALL_DIR}/lib${BACKEND_LIBRARY_OUTPUT_NAME}.a'" - "'${ALP_UTILS_INSTALL_DIR}/lib${ALP_UTILS_LIBRARY_OUTPUT_NAME}.a'" "${NUMA_LFLAG}" - "-llpf_hl" "-lpthread" "-lm" "-ldl" + LIB_DIR "${HYBRID_BACKEND_INSTALL_DIR}" + LINK_FLAGS "${NUMA_LFLAG}" "-lpthread" "-lm" ) endif() endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 50e731a30..77b386f54 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -59,6 +59,7 @@ foreach( backend ${AVAILABLE_BACKENDS} ) list( APPEND backend_list "\"${backend}\"" ) joinAndAppend( compiler_list ${backend}_WRAPPER_COMPILER_COMMAND ) + joinAndAppend( library_dir ${backend}_LIB_DIR ) joinAndAppend( runenv_list ${backend}_WRAPPER_RUNENV ) joinAndAppend( runner_list ${backend}_WRAPPER_RUNNER ) @@ -75,7 +76,13 @@ endforeach( ) # sourcing the resulting setenv makes the quotes seem as part of the # executable name. Until this is fixed, we do not support spaces in # the LPF install path (FIXME) -list( JOIN backend_list " " AVAILABLE_BACKENDS_SPACED ) + +macro( joinWithNewLine inListName outListName ) + list( JOIN ${inListName} "\n" tmp_spaced ) + set( ${outListName} "\n${tmp_spaced}\n" ) +endmacro( joinWithNewLine ) + +joinWithNewLine( backend_list AVAILABLE_BACKENDS_SPACED ) list( JOIN LPFRUN_CMD " " LPFRUN_CMD_SPACED ) list( JOIN MANUALRUN " " MANUALRUN_SPACED ) configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/setenv.in ${CMAKE_CURRENT_BINARY_DIR}/setenv @ONLY ) @@ -85,13 +92,15 @@ list( TRANSFORM cflags PREPEND "-D" ) list( APPEND cflags "${COMMON_WRAPPER_OPTIONS}" ) joinAndAppend( COMMON_FLAGS_SPACED cflags ) -list( JOIN compiler_list " " BACKEND_COMPILERS_SPACED ) -list( JOIN compile_options_list " " BACKEND_CFLAGS_SPACED ) -list( JOIN link_flags_list " " BACKEND_LFLAGS_SPACED ) +joinWithNewLine( compiler_list BACKEND_COMPILERS_SPACED ) +joinWithNewLine( library_dir LIBRARY_DIRS_SPACED ) + +joinWithNewLine( compile_options_list BACKEND_CFLAGS_SPACED ) +joinWithNewLine( link_flags_list BACKEND_LFLAGS_SPACED ) configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/grbcxx.in ${CMAKE_CURRENT_BINARY_DIR}/grbcxx @ONLY ) -list( JOIN runenv_list " " BACKEND_RUNENV_SPACED ) -list( JOIN runner_list " " BACKEND_RUNNER_SPACED ) +joinWithNewLine( runenv_list BACKEND_RUNENV_SPACED ) +joinWithNewLine( runner_list BACKEND_RUNNER_SPACED ) configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/grbrun.in ${CMAKE_CURRENT_BINARY_DIR}/grbrun @ONLY ) # install them to the install folder with execute permission @@ -107,7 +116,7 @@ install( FILES ${CMAKE_CURRENT_BINARY_DIR}/setenv ### GENERATE CMAKE INFRASTRUCTURE INSIDE INSTALLATION DIRECTORY -include(CMakePackageConfigHelpers) +include( CMakePackageConfigHelpers ) # write file with version information write_basic_package_version_file( diff --git a/src/grbcxx.in b/src/grbcxx.in index 3f30dfb2f..0170649fd 100644 --- a/src/grbcxx.in +++ b/src/grbcxx.in @@ -24,9 +24,11 @@ BACKENDCFLAGS=(@BACKEND_CFLAGS_SPACED@) BACKENDLFLAGS=(@BACKEND_LFLAGS_SPACED@) COMMONCFLAGS=@COMMON_FLAGS_SPACED@ VERSION="@VERSION@" +BACKEND_LIBRARY_OUTPUT_NAME="@BACKEND_LIBRARY_OUTPUT_NAME@" +LIBRARY_DIRS=(@LIBRARY_DIRS_SPACED@) declare -a ARGS -LINK=true +LINK="dynamic" SHOW="eval" BACKEND=${BACKENDS[0]} CXXSTD=c++11 @@ -39,16 +41,14 @@ while [[ $# -gt 0 ]]; do BACKEND=$1 shift ;; - -c) - ARGS+=("-c") - LINK=false + --link-alp-static) + LINK="static" ;; --show) SHOW=echo ;; --std=*) CXXSTD="${option#*=}" - shift ;; --version) echo "This is ALP/GraphBLAS version ${VERSION}" @@ -88,14 +88,15 @@ then exit 255 fi -LFLAGS= -if ${LINK} -then - LFLAGS=${BACKENDLFLAGS[${BACKENDID}]} +if [[ "${LINK}" == "dynamic" ]]; then + LIB="-L '${LIBRARY_DIRS[${BACKENDID}]}' -l${BACKEND_LIBRARY_OUTPUT_NAME}" +else + LIB="'${LIBRARY_DIRS[${BACKENDID}]}/lib${BACKEND_LIBRARY_OUTPUT_NAME}.a'" fi +LFLAGS="${LIB} ${BACKENDLFLAGS[${BACKENDID}]}" -COMPILER=${BACKENDCOMPILERS[${BACKENDID}]} +COMPILER="${BACKENDCOMPILERS[${BACKENDID}]}" -CMD="${COMPILER} -std=${CXXSTD} -I'${INCLUDEDIR}' ${COMMONCFLAGS} ${BACKENDCFLAGS[${BACKENDID}]} "${ARGS[@]}" "$@" ${LFLAGS}" +CMD="${COMPILER} -std=${CXXSTD} -I'${INCLUDEDIR}' ${COMMONCFLAGS} ${BACKENDCFLAGS[${BACKENDID}]} ${ARGS[@]} "$@" ${LFLAGS}" ${SHOW} "${CMD}" From 56a734d2250bdfb15ad3c23bd15b9cdc7a5c0dd5 Mon Sep 17 00:00:00 2001 From: Alberto Scolari Date: Mon, 5 Feb 2024 15:40:43 +0100 Subject: [PATCH 02/10] adding path with libraries to grbrun --- cmake/AddGRBInstall.cmake | 4 +--- src/CMakeLists.txt | 9 ++++++--- src/grbrun.in | 9 ++------- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/cmake/AddGRBInstall.cmake b/cmake/AddGRBInstall.cmake index 5dcdae642..6a2c83f22 100644 --- a/cmake/AddGRBInstall.cmake +++ b/cmake/AddGRBInstall.cmake @@ -59,7 +59,6 @@ set( HYBRID_BACKEND_INSTALL_DIR "${BINARY_LIBRARIES_INSTALL_DIR}/hybrid" ) # backend: (mandatory) argument name # COMPILER_COMMAND: (optional) Bash command (also including options, as a CMake list) # to invoke the compiler; if left empty, it is set to CMAKE_CXX_COMPILER -# RUNENV: (optional) environment variables for running the executable # RUNNER: (optional) runner command (also including options, as a CMake list) to # run the executable # COMPILE_DEFINITIONS: (optional) definitions for compilation, as "SYMBOL" or @@ -71,7 +70,7 @@ set( HYBRID_BACKEND_INSTALL_DIR "${BINARY_LIBRARIES_INSTALL_DIR}/hybrid" ) # since they are expanded as macro arguments # function( addBackendWrapperGenOptions backend ) - set( multiValueArgs "COMPILER_COMMAND;RUNENV;RUNNER" + set( multiValueArgs "COMPILER_COMMAND;RUNNER" "COMPILE_DEFINITIONS;COMPILE_OPTIONS;LINK_FLAGS;LIB_DIR" ) cmake_parse_arguments( parsed "${options}" "${oneValueArgs}" @@ -88,7 +87,6 @@ function( addBackendWrapperGenOptions backend ) if( NOT parsed_COMPILER_COMMAND ) set( ${backend}_WRAPPER_COMPILER_COMMAND "${CMAKE_CXX_COMPILER}" PARENT_SCOPE ) endif() - set( ${backend}_WRAPPER_RUNENV "${parsed_RUNENV}" PARENT_SCOPE ) set( ${backend}_WRAPPER_RUNNER "${parsed_RUNNER}" PARENT_SCOPE ) set( ${backend}_LIB_DIR "${parsed_LIB_DIR}" PARENT_SCOPE ) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 77b386f54..e09e085ea 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -52,17 +52,19 @@ endmacro( joinAndAppend ) # of values to be stored inside the wrappers foreach( backend ${AVAILABLE_BACKENDS} ) assert_valid_variables( ${backend}_WRAPPER_COMPILER_COMMAND ) - assert_defined_variables( ${backend}_WRAPPER_RUNENV ${backend}_WRAPPER_RUNNER + assert_defined_variables( ${backend}_WRAPPER_RUNNER ${backend}_WRAPPER_LINK_FLAGS ${backend}_WRAPPER_COMPILE_DEFINITIONS ${backend}_WRAPPER_COMPILE_OPTIONS - ${backend}_WRAPPER_LINK_FLAGS ) list( APPEND backend_list "\"${backend}\"" ) joinAndAppend( compiler_list ${backend}_WRAPPER_COMPILER_COMMAND ) joinAndAppend( library_dir ${backend}_LIB_DIR ) - joinAndAppend( runenv_list ${backend}_WRAPPER_RUNENV ) joinAndAppend( runner_list ${backend}_WRAPPER_RUNNER ) + + string( TOUPPER ${backend} _bname ) + list( APPEND backend_dir_list "ALP_${_bname}_LIBRARY_PATH=\"${${backend}_LIB_DIR}\"" ) + joinAndAppend( runenv_list ${backend}_LIB_DIR ) set( compile_options "${${backend}_WRAPPER_COMPILE_DEFINITIONS}" ) list( TRANSFORM compile_options PREPEND "-D" ) list( APPEND compile_options ${${backend}_WRAPPER_COMPILE_OPTIONS} ) @@ -85,6 +87,7 @@ endmacro( joinWithNewLine ) joinWithNewLine( backend_list AVAILABLE_BACKENDS_SPACED ) list( JOIN LPFRUN_CMD " " LPFRUN_CMD_SPACED ) list( JOIN MANUALRUN " " MANUALRUN_SPACED ) +joinWithNewLine( backend_dir_list BACKEND_DIR_LIST ) configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/setenv.in ${CMAKE_CURRENT_BINARY_DIR}/setenv @ONLY ) set( cflags "${COMMON_WRAPPER_DEFINITIONS}" ) diff --git a/src/grbrun.in b/src/grbrun.in index 1289eb3ec..7189b0d26 100644 --- a/src/grbrun.in +++ b/src/grbrun.in @@ -60,11 +60,6 @@ then fi RUNNER=${BACKENDRUNNER[${BACKENDID}]} +LD_PATH="@ALP_UTILS_INSTALL_DIR@:${BACKENDRUNENV[${BACKENDID}]}" -EXPENV=${BACKENDRUNENV[${BACKENDID}]} -if [ -n "${EXPENV}" ]; then - export ${EXPENV} -fi - -${SHOW} ${RUNNER} "${ARGS[@]}" "$@" - +${SHOW} LD_LIBRARY_PATH="${LD_PATH}:${LD_LIBRARY_PATH}" ${RUNNER} "${ARGS[@]}" "$@" From fe8e2da2ba7db0a1a3589a19b785762ee9d06840 Mon Sep 17 00:00:00 2001 From: Alberto Scolari Date: Mon, 5 Feb 2024 15:44:10 +0100 Subject: [PATCH 03/10] adding backend-specific env variables to setenv script --- src/setenv.in | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/setenv.in b/src/setenv.in index 072b66c3c..7230737fd 100644 --- a/src/setenv.in +++ b/src/setenv.in @@ -14,13 +14,20 @@ # limitations under the License. # -DEPDIR="@CMAKE_INSTALL_PREFIX@" +if [[ "${ALP_SETENV}" != "1" ]]; then -LD_LIBRARY_PATH=${DEPDIR}/lib/:${DEPDIR}/lib64/:${LD_LIBRARY_PATH} -LIBRARY_PATH=${DEPDIR}/lib/:${DEPDIR}/lib64/:${LIBRARY_PATH} -export PATH=${DEPDIR}/bin:${PATH} -unset DEPDIR + export ALP_SETENV="1" -export LPFRUN="@LPFRUN_CMD_SPACED@" -export MANUALRUN="@MANUALRUN_SPACED@" -export BACKENDS=(@AVAILABLE_BACKENDS_SPACED@) + DEPDIR="@CMAKE_INSTALL_PREFIX@" + @BACKEND_DIR_LIST@ + + LD_LIBRARY_PATH=${DEPDIR}/lib/:${LD_LIBRARY_PATH} + LIBRARY_PATH=${DEPDIR}/lib/:${LIBRARY_PATH} + export PATH=${DEPDIR}/bin:${PATH} + unset DEPDIR + + export LPFRUN="@LPFRUN_CMD_SPACED@" + export MANUALRUN="@MANUALRUN_SPACED@" + export BACKENDS=(@AVAILABLE_BACKENDS_SPACED@) + +fi From 86301783fe3ee8544787c0b2f1283d3b1477620f Mon Sep 17 00:00:00 2001 From: Alberto Scolari Date: Wed, 14 Feb 2024 17:00:56 +0100 Subject: [PATCH 04/10] cleaning installation infrastructure, removing global compiler flags for wrappers --- cmake/AddGRBInstall.cmake | 68 +++++++++++++++++---------------------- src/CMakeLists.txt | 6 ---- src/grbcxx.in | 3 +- 3 files changed, 31 insertions(+), 46 deletions(-) diff --git a/cmake/AddGRBInstall.cmake b/cmake/AddGRBInstall.cmake index 6a2c83f22..fe2f0233e 100644 --- a/cmake/AddGRBInstall.cmake +++ b/cmake/AddGRBInstall.cmake @@ -48,8 +48,6 @@ set( HYPERDAGS_BACKEND_INSTALL_DIR "${BINARY_LIBRARIES_INSTALL_DIR}/hyperdags" ) set( BSP1D_BACKEND_INSTALL_DIR "${BINARY_LIBRARIES_INSTALL_DIR}/spmd" ) set( HYBRID_BACKEND_INSTALL_DIR "${BINARY_LIBRARIES_INSTALL_DIR}/hybrid" ) - - # addBackendWrapperGenOptions # creates the variables to store the settings for a backend, in order to create # the wrapper scripts for the installation; unless otherwise specified, arguments @@ -69,11 +67,11 @@ set( HYBRID_BACKEND_INSTALL_DIR "${BINARY_LIBRARIES_INSTALL_DIR}/hybrid" ) # WARNING! do NOT turn this into a macro, otherwise escaped paths don't work anymore # since they are expanded as macro arguments # -function( addBackendWrapperGenOptions backend ) +function( addBackendWrapperGenOptions backend lib_dir ) set( multiValueArgs "COMPILER_COMMAND;RUNNER" - "COMPILE_DEFINITIONS;COMPILE_OPTIONS;LINK_FLAGS;LIB_DIR" + "COMPILE_DEFINITIONS;COMPILE_OPTIONS;LINK_FLAGS" ) - cmake_parse_arguments( parsed "${options}" "${oneValueArgs}" + cmake_parse_arguments( parsed "${options}" "" "${multiValueArgs}" "${ARGN}" ) @@ -81,30 +79,19 @@ function( addBackendWrapperGenOptions backend ) message( FATAL_ERROR "cannot find ${backend} among available backends") endif() - assert_valid_variables( parsed_LIB_DIR ) + assert_valid_variables( lib_dir ) set( ${backend}_WRAPPER_COMPILER_COMMAND "${parsed_COMPILER_COMMAND}" PARENT_SCOPE ) if( NOT parsed_COMPILER_COMMAND ) set( ${backend}_WRAPPER_COMPILER_COMMAND "${CMAKE_CXX_COMPILER}" PARENT_SCOPE ) endif() set( ${backend}_WRAPPER_RUNNER "${parsed_RUNNER}" PARENT_SCOPE ) - set( ${backend}_LIB_DIR "${parsed_LIB_DIR}" PARENT_SCOPE ) - + set( ${backend}_LIB_DIR "${lib_dir}" PARENT_SCOPE ) set( ${backend}_WRAPPER_COMPILE_DEFINITIONS "${parsed_COMPILE_DEFINITIONS}" PARENT_SCOPE ) - set( ${backend}_WRAPPER_COMPILE_OPTIONS "${parsed_COMPILE_OPTIONS}" PARENT_SCOPE ) set( ${backend}_WRAPPER_LINK_FLAGS "${parsed_LINK_FLAGS}" PARENT_SCOPE ) endfunction( addBackendWrapperGenOptions ) -## compile definitions and options common to all backends: do not change! -set( COMMON_WRAPPER_DEFINITIONS - "${REFERENCE_INCLUDE_DEFS}" - "${REFERENCE_OMP_INCLUDE_DEFS}" -) -set( COMMON_WRAPPER_OPTIONS - "${OpenMP_CXX_FLAGS}" -) - if( WITH_NUMA ) set( NUMA_LFLAG "-lnuma" ) endif() @@ -113,36 +100,39 @@ endif() # for each enabled backend, add its information for the wrapper generation # paths may have spaces, hence wrap them inside single quotes '' +# all backends include both REFERENCE_INCLUDE_DEFS and REFERENCE_OMP_INCLUDE_DEFS, +# due to the dependency on OpenMP -- to be resolved + # shared memory backends if( WITH_REFERENCE_BACKEND ) - addBackendWrapperGenOptions( "reference" - COMPILE_DEFINITIONS "${REFERENCE_SELECTION_DEFS}" - LIB_DIR "${SHMEM_BACKEND_INSTALL_DIR}" + addBackendWrapperGenOptions( "reference" "${SHMEM_BACKEND_INSTALL_DIR}" + COMPILE_DEFINITIONS + "${REFERENCE_INCLUDE_DEFS};${REFERENCE_OMP_INCLUDE_DEFS};${REFERENCE_SELECTION_DEFS}" LINK_FLAGS "${NUMA_LFLAG}" ) endif() if( WITH_OMP_BACKEND ) - addBackendWrapperGenOptions( "reference_omp" - COMPILE_DEFINITIONS "${REFERENCE_OMP_SELECTION_DEFS}" - LIB_DIR "${SHMEM_BACKEND_INSTALL_DIR}" + addBackendWrapperGenOptions( "reference_omp" "${SHMEM_BACKEND_INSTALL_DIR}" + COMPILE_DEFINITIONS + "${REFERENCE_INCLUDE_DEFS};${REFERENCE_OMP_INCLUDE_DEFS};${REFERENCE_OMP_SELECTION_DEFS}" + COMPILE_OPTIONS "-fopenmp" LINK_FLAGS "${NUMA_LFLAG}" ) endif() # dependent backends if( WITH_HYPERDAGS_BACKEND ) - addBackendWrapperGenOptions( "hyperdags" - COMPILE_DEFINITIONS "${HYPERDAGS_SELECTION_DEFS};${HYPERDAGS_INCLUDE_DEFS}" - LIB_DIR "${HYPERDAGS_BACKEND_INSTALL_DIR}" + addBackendWrapperGenOptions( "hyperdags" "${HYPERDAGS_BACKEND_INSTALL_DIR}" + COMPILE_DEFINITIONS + "${REFERENCE_INCLUDE_DEFS};${REFERENCE_OMP_INCLUDE_DEFS};${HYPERDAGS_INCLUDE_DEFS};${HYPERDAGS_SELECTION_DEFS}" LINK_FLAGS "${NUMA_LFLAG}" ) endif() if( WITH_NONBLOCKING_BACKEND ) - addBackendWrapperGenOptions( "nonblocking" - COMPILE_DEFINITIONS "${NONBLOCKING_SELECTION_DEFS};${NONBLOCKING_INCLUDE_DEFS}" - LIB_DIR "${SHMEM_BACKEND_INSTALL_DIR}" + addBackendWrapperGenOptions( "nonblocking" "${SHMEM_BACKEND_INSTALL_DIR}" + COMPILE_DEFINITIONS "${NONBLOCKING_INCLUDE_DEFS};${NONBLOCKING_SELECTION_DEFS}" LINK_FLAGS "${NUMA_LFLAG}" ) endif() @@ -170,22 +160,24 @@ if( WITH_BSP1D_BACKEND OR WITH_HYBRID_BACKEND ) set( MANUALRUN "${LPFRUN_CMD}" "${MANUALRUN_ARGS}" ) if( WITH_BSP1D_BACKEND ) - addBackendWrapperGenOptions( "bsp1d" + addBackendWrapperGenOptions( "bsp1d" "${BSP1D_BACKEND_INSTALL_DIR}" COMPILER_COMMAND "${LPF_CXX_COMPILER}" RUNNER "${LPFRUN_CMD}" - COMPILE_DEFINITIONS "${LPF_INCLUDE_DEFS};${BSP1D_SELECTION_DEFS}" - LIB_DIR "${BSP1D_BACKEND_INSTALL_DIR}" - LINK_FLAGS "${NUMA_LFLAG}" "-lpthread" "-lm" + COMPILE_DEFINITIONS + "${REFERENCE_INCLUDE_DEFS};${REFERENCE_OMP_INCLUDE_DEFS};${LPF_INCLUDE_DEFS};${BSP1D_SELECTION_DEFS}" + COMPILE_OPTIONS "-fopenmp" + LINK_FLAGS "${NUMA_LFLAG}" ) endif() if( WITH_HYBRID_BACKEND ) - addBackendWrapperGenOptions( "hybrid" + addBackendWrapperGenOptions( "hybrid" "${HYBRID_BACKEND_INSTALL_DIR}" COMPILER_COMMAND "${LPF_CXX_COMPILER}" RUNNER "${LPFRUN_CMD}" - COMPILE_DEFINITIONS "${LPF_INCLUDE_DEFS};${HYBRID_SELECTION_DEFS}" - LIB_DIR "${HYBRID_BACKEND_INSTALL_DIR}" - LINK_FLAGS "${NUMA_LFLAG}" "-lpthread" "-lm" + COMPILE_DEFINITIONS + "${REFERENCE_INCLUDE_DEFS};${REFERENCE_OMP_INCLUDE_DEFS};${LPF_INCLUDE_DEFS};${HYBRID_SELECTION_DEFS}" + COMPILE_OPTIONS "-fopenmp" + LINK_FLAGS "${NUMA_LFLAG}" ) endif() endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e09e085ea..ea6ea760e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -30,7 +30,6 @@ add_subdirectory( transition ) assert_valid_variables( AVAILABLE_BACKENDS CMAKE_INSTALL_PREFIX INCLUDE_INSTALL_DIR VERSION BIN_INSTALL_DIR ) -assert_defined_variables( COMMON_WRAPPER_DEFINITIONS COMMON_WRAPPER_OPTIONS ) if( WITH_BSP1D_BACKEND OR WITH_HYBRID_BACKEND ) assert_valid_variables( LPFRUN_CMD MANUALRUN ) @@ -90,11 +89,6 @@ list( JOIN MANUALRUN " " MANUALRUN_SPACED ) joinWithNewLine( backend_dir_list BACKEND_DIR_LIST ) configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/setenv.in ${CMAKE_CURRENT_BINARY_DIR}/setenv @ONLY ) -set( cflags "${COMMON_WRAPPER_DEFINITIONS}" ) -list( TRANSFORM cflags PREPEND "-D" ) -list( APPEND cflags "${COMMON_WRAPPER_OPTIONS}" ) -joinAndAppend( COMMON_FLAGS_SPACED cflags ) - joinWithNewLine( compiler_list BACKEND_COMPILERS_SPACED ) joinWithNewLine( library_dir LIBRARY_DIRS_SPACED ) diff --git a/src/grbcxx.in b/src/grbcxx.in index 0170649fd..5a6031494 100644 --- a/src/grbcxx.in +++ b/src/grbcxx.in @@ -22,7 +22,6 @@ BACKENDS=(@AVAILABLE_BACKENDS_SPACED@) BACKENDCOMPILERS=(@BACKEND_COMPILERS_SPACED@) BACKENDCFLAGS=(@BACKEND_CFLAGS_SPACED@) BACKENDLFLAGS=(@BACKEND_LFLAGS_SPACED@) -COMMONCFLAGS=@COMMON_FLAGS_SPACED@ VERSION="@VERSION@" BACKEND_LIBRARY_OUTPUT_NAME="@BACKEND_LIBRARY_OUTPUT_NAME@" LIBRARY_DIRS=(@LIBRARY_DIRS_SPACED@) @@ -97,6 +96,6 @@ LFLAGS="${LIB} ${BACKENDLFLAGS[${BACKENDID}]}" COMPILER="${BACKENDCOMPILERS[${BACKENDID}]}" -CMD="${COMPILER} -std=${CXXSTD} -I'${INCLUDEDIR}' ${COMMONCFLAGS} ${BACKENDCFLAGS[${BACKENDID}]} ${ARGS[@]} "$@" ${LFLAGS}" +CMD="${COMPILER} -std=${CXXSTD} -I'${INCLUDEDIR}' ${BACKENDCFLAGS[${BACKENDID}]} ${ARGS[@]} "$@" ${LFLAGS}" ${SHOW} "${CMD}" From cbacf7f4509bd067220ca3968c2cd5d98835a3c4 Mon Sep 17 00:00:00 2001 From: Alberto Scolari Date: Fri, 16 Feb 2024 17:07:06 +0100 Subject: [PATCH 05/10] adding all needed compilation and link flags to compiler, including ALP utils --- cmake/AddGRBInstall.cmake | 54 +++++++++++++++++++-------------------- src/CMakeLists.txt | 4 ++- src/grbcxx.in | 5 ++-- 3 files changed, 31 insertions(+), 32 deletions(-) diff --git a/cmake/AddGRBInstall.cmake b/cmake/AddGRBInstall.cmake index fe2f0233e..2c0bf1d7e 100644 --- a/cmake/AddGRBInstall.cmake +++ b/cmake/AddGRBInstall.cmake @@ -48,6 +48,21 @@ set( HYPERDAGS_BACKEND_INSTALL_DIR "${BINARY_LIBRARIES_INSTALL_DIR}/hyperdags" ) set( BSP1D_BACKEND_INSTALL_DIR "${BINARY_LIBRARIES_INSTALL_DIR}/spmd" ) set( HYBRID_BACKEND_INSTALL_DIR "${BINARY_LIBRARIES_INSTALL_DIR}/hybrid" ) +# definitions and options common to all backends: all backends include +# REFERENCE_INCLUDE_DEFS, REFERENCE_OMP_INCLUDE_DEFS and -fopenmp due to the +# dependency on OpenMP -- to be resolved +set( COMMON_COMPILE_DEFINITIONS "${REFERENCE_INCLUDE_DEFS};${REFERENCE_OMP_INCLUDE_DEFS}" ) +set( COMMON_COMPILE_OPTIONS "-fopenmp" ) + +# link flags common to all backends, to be inserted before and after the +# backend-specific flags +set( COMMON_LFLAGS_PRE + "-l${ALP_UTILS_LIBRARY_OUTPUT_NAME};-L '${BINARY_LIBRARIES_INSTALL_DIR}'" +) +if( WITH_NUMA ) + list( APPEND COMMON_LFLAGS_POST "-lnuma" ) +endif() + # addBackendWrapperGenOptions # creates the variables to store the settings for a backend, in order to create # the wrapper scripts for the installation; unless otherwise specified, arguments @@ -87,53 +102,42 @@ function( addBackendWrapperGenOptions backend lib_dir ) endif() set( ${backend}_WRAPPER_RUNNER "${parsed_RUNNER}" PARENT_SCOPE ) set( ${backend}_LIB_DIR "${lib_dir}" PARENT_SCOPE ) - set( ${backend}_WRAPPER_COMPILE_DEFINITIONS "${parsed_COMPILE_DEFINITIONS}" PARENT_SCOPE ) - set( ${backend}_WRAPPER_COMPILE_OPTIONS "${parsed_COMPILE_OPTIONS}" PARENT_SCOPE ) + + list( APPEND __cd "${COMMON_COMPILE_DEFINITIONS}" "${parsed_COMPILE_DEFINITIONS}" ) + set( ${backend}_WRAPPER_COMPILE_DEFINITIONS "${__cd}" PARENT_SCOPE ) + + list( APPEND __co "${COMMON_COMPILE_OPTIONS}" "${parsed_COMPILE_OPTIONS}" ) + set( ${backend}_WRAPPER_COMPILE_OPTIONS "${__co}" PARENT_SCOPE ) set( ${backend}_WRAPPER_LINK_FLAGS "${parsed_LINK_FLAGS}" PARENT_SCOPE ) endfunction( addBackendWrapperGenOptions ) -if( WITH_NUMA ) - set( NUMA_LFLAG "-lnuma" ) -endif() - ### POPULATING WRAPPER INFORMATION FOR INSTALLATION TARGETS # for each enabled backend, add its information for the wrapper generation # paths may have spaces, hence wrap them inside single quotes '' -# all backends include both REFERENCE_INCLUDE_DEFS and REFERENCE_OMP_INCLUDE_DEFS, -# due to the dependency on OpenMP -- to be resolved - # shared memory backends if( WITH_REFERENCE_BACKEND ) addBackendWrapperGenOptions( "reference" "${SHMEM_BACKEND_INSTALL_DIR}" - COMPILE_DEFINITIONS - "${REFERENCE_INCLUDE_DEFS};${REFERENCE_OMP_INCLUDE_DEFS};${REFERENCE_SELECTION_DEFS}" - LINK_FLAGS "${NUMA_LFLAG}" + COMPILE_DEFINITIONS "${REFERENCE_SELECTION_DEFS}" ) endif() if( WITH_OMP_BACKEND ) addBackendWrapperGenOptions( "reference_omp" "${SHMEM_BACKEND_INSTALL_DIR}" - COMPILE_DEFINITIONS - "${REFERENCE_INCLUDE_DEFS};${REFERENCE_OMP_INCLUDE_DEFS};${REFERENCE_OMP_SELECTION_DEFS}" - COMPILE_OPTIONS "-fopenmp" - LINK_FLAGS "${NUMA_LFLAG}" + COMPILE_DEFINITIONS "${REFERENCE_OMP_SELECTION_DEFS}" ) endif() # dependent backends if( WITH_HYPERDAGS_BACKEND ) addBackendWrapperGenOptions( "hyperdags" "${HYPERDAGS_BACKEND_INSTALL_DIR}" - COMPILE_DEFINITIONS - "${REFERENCE_INCLUDE_DEFS};${REFERENCE_OMP_INCLUDE_DEFS};${HYPERDAGS_INCLUDE_DEFS};${HYPERDAGS_SELECTION_DEFS}" - LINK_FLAGS "${NUMA_LFLAG}" + COMPILE_DEFINITIONS "${HYPERDAGS_INCLUDE_DEFS};${HYPERDAGS_SELECTION_DEFS}" ) endif() if( WITH_NONBLOCKING_BACKEND ) addBackendWrapperGenOptions( "nonblocking" "${SHMEM_BACKEND_INSTALL_DIR}" COMPILE_DEFINITIONS "${NONBLOCKING_INCLUDE_DEFS};${NONBLOCKING_SELECTION_DEFS}" - LINK_FLAGS "${NUMA_LFLAG}" ) endif() @@ -163,10 +167,7 @@ if( WITH_BSP1D_BACKEND OR WITH_HYBRID_BACKEND ) addBackendWrapperGenOptions( "bsp1d" "${BSP1D_BACKEND_INSTALL_DIR}" COMPILER_COMMAND "${LPF_CXX_COMPILER}" RUNNER "${LPFRUN_CMD}" - COMPILE_DEFINITIONS - "${REFERENCE_INCLUDE_DEFS};${REFERENCE_OMP_INCLUDE_DEFS};${LPF_INCLUDE_DEFS};${BSP1D_SELECTION_DEFS}" - COMPILE_OPTIONS "-fopenmp" - LINK_FLAGS "${NUMA_LFLAG}" + COMPILE_DEFINITIONS "${LPF_INCLUDE_DEFS};${BSP1D_SELECTION_DEFS}" ) endif() @@ -174,10 +175,7 @@ if( WITH_BSP1D_BACKEND OR WITH_HYBRID_BACKEND ) addBackendWrapperGenOptions( "hybrid" "${HYBRID_BACKEND_INSTALL_DIR}" COMPILER_COMMAND "${LPF_CXX_COMPILER}" RUNNER "${LPFRUN_CMD}" - COMPILE_DEFINITIONS - "${REFERENCE_INCLUDE_DEFS};${REFERENCE_OMP_INCLUDE_DEFS};${LPF_INCLUDE_DEFS};${HYBRID_SELECTION_DEFS}" - COMPILE_OPTIONS "-fopenmp" - LINK_FLAGS "${NUMA_LFLAG}" + COMPILE_DEFINITIONS "${LPF_INCLUDE_DEFS};${HYBRID_SELECTION_DEFS}" ) endif() endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ea6ea760e..801d85e29 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -28,7 +28,7 @@ add_subdirectory( transition ) ### BUILD WRAPPER SCRIPTS FOR INSTALLATION assert_valid_variables( AVAILABLE_BACKENDS CMAKE_INSTALL_PREFIX INCLUDE_INSTALL_DIR - VERSION BIN_INSTALL_DIR + VERSION BIN_INSTALL_DIR COMMON_LFLAGS_PRE COMMON_LFLAGS_POST ) if( WITH_BSP1D_BACKEND OR WITH_HYBRID_BACKEND ) @@ -94,6 +94,8 @@ joinWithNewLine( library_dir LIBRARY_DIRS_SPACED ) joinWithNewLine( compile_options_list BACKEND_CFLAGS_SPACED ) joinWithNewLine( link_flags_list BACKEND_LFLAGS_SPACED ) +list( JOIN COMMON_LFLAGS_PRE " " COMMON_LFLAGS_PRE_SPACED ) +list( JOIN COMMON_LFLAGS_POST " " COMMON_LFLAGS_POST_SPACED ) configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/grbcxx.in ${CMAKE_CURRENT_BINARY_DIR}/grbcxx @ONLY ) joinWithNewLine( runenv_list BACKEND_RUNENV_SPACED ) diff --git a/src/grbcxx.in b/src/grbcxx.in index 5a6031494..f60354076 100644 --- a/src/grbcxx.in +++ b/src/grbcxx.in @@ -16,7 +16,6 @@ # limitations under the License. # -GRB_INSTALL_PATH="@CMAKE_INSTALL_PREFIX@" INCLUDEDIR="@INCLUDE_INSTALL_DIR@" BACKENDS=(@AVAILABLE_BACKENDS_SPACED@) BACKENDCOMPILERS=(@BACKEND_COMPILERS_SPACED@) @@ -88,11 +87,11 @@ then fi if [[ "${LINK}" == "dynamic" ]]; then - LIB="-L '${LIBRARY_DIRS[${BACKENDID}]}' -l${BACKEND_LIBRARY_OUTPUT_NAME}" + LIB="-l${BACKEND_LIBRARY_OUTPUT_NAME} -L '${LIBRARY_DIRS[${BACKENDID}]}'" else LIB="'${LIBRARY_DIRS[${BACKENDID}]}/lib${BACKEND_LIBRARY_OUTPUT_NAME}.a'" fi -LFLAGS="${LIB} ${BACKENDLFLAGS[${BACKENDID}]}" +LFLAGS="@COMMON_LFLAGS_PRE_SPACED@ ${LIB} ${BACKENDLFLAGS[${BACKENDID}]} @COMMON_LFLAGS_POST_SPACED@" COMPILER="${BACKENDCOMPILERS[${BACKENDID}]}" From 93e31893c9bc78e4a505467ee5019a6a8ac2fe21 Mon Sep 17 00:00:00 2001 From: Alberto Scolari Date: Tue, 20 Feb 2024 13:36:20 +0100 Subject: [PATCH 06/10] adding --help argument to grbcxx --- src/grbcxx.in | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/src/grbcxx.in b/src/grbcxx.in index f60354076..a4b09cf18 100644 --- a/src/grbcxx.in +++ b/src/grbcxx.in @@ -30,6 +30,36 @@ LINK="dynamic" SHOW="eval" BACKEND=${BACKENDS[0]} CXXSTD=c++11 +help="no" + +function print_help { + local this_bin="$1" + local BACKEND=$2 + local COMPILER=$3 + local help_arg="--help" + if [[ "${BACKEND}" == "bsp1d" || "${BACKEND}" == "hybrid" ]]; then + # LPF's lpfcxx doesn't recognize "--help", just "-help" + help_arg="-help" + fi + + echo "* Compiles an ALP/GraphBLAS application by calling an underlying compiler and by passing needed flags." + echo + echo "USAGE: ${this_bin} [ALP-specific options...] [--] " + echo + echo "ALP-specific options:" + echo " -b,--backend compile against the ALP/GraphBLAS backend ; possible values: ${BACKENDS[@]}; default: reference" + echo " --link-alp-static link the specified ALP/GraphBLAS backend statically (default linking is dynamic)" + echo " --show show the full compilation command WITHOUT executing it" + echo " --version display the current ALP/GraphBLAS version" + echo " --help display this help" + echo " -- pass all the following arguments directly to the underlying compiler" + echo + echo "* Selected backend: ${BACKEND}" + echo "* Underlying compiler: ${COMPILER}" + echo "* Underlying compiler help:" + echo + exec ${COMPILER} ${help_arg} +} while [[ $# -gt 0 ]]; do option="$1" @@ -56,6 +86,9 @@ while [[ $# -gt 0 ]]; do echo " " ARGS+=("${option}") ;; + --help) + help="yes" + ;; --) break ;; @@ -73,6 +106,7 @@ for i in "${!BACKENDS[@]}"; do break fi done +COMPILER="${BACKENDCOMPILERS[${BACKENDID}]}" if [[ ${BACKENDID} -eq -1 ]] then @@ -80,6 +114,12 @@ then exit 255 fi +if [[ "${help}" == "yes" ]]; then + print_help "$(realpath $0)" ${BACKEND} ${COMPILER} + exit 0 +fi + + if [[ ! -d "${INCLUDEDIR}" ]] then echo "Could not find GraphBLAS include directory in ${INCLUDEDIR}" @@ -93,8 +133,7 @@ else fi LFLAGS="@COMMON_LFLAGS_PRE_SPACED@ ${LIB} ${BACKENDLFLAGS[${BACKENDID}]} @COMMON_LFLAGS_POST_SPACED@" -COMPILER="${BACKENDCOMPILERS[${BACKENDID}]}" - CMD="${COMPILER} -std=${CXXSTD} -I'${INCLUDEDIR}' ${BACKENDCFLAGS[${BACKENDID}]} ${ARGS[@]} "$@" ${LFLAGS}" ${SHOW} "${CMD}" + From 9a1112c38bd1bfa218c64e53368909652c1f0709 Mon Sep 17 00:00:00 2001 From: Alberto Scolari Date: Tue, 20 Feb 2024 13:56:25 +0100 Subject: [PATCH 07/10] adding help to runner --- src/grbrun.in | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/src/grbrun.in b/src/grbrun.in index 7189b0d26..581b7256b 100644 --- a/src/grbrun.in +++ b/src/grbrun.in @@ -23,6 +23,34 @@ BACKENDRUNNER=(@BACKEND_RUNNER_SPACED@) declare -a ARGS SHOW="eval" BACKEND=${BACKENDS[0]} +help="no" + +function print_help { + local this_bin="$1" + local BACKEND=$2 + local RUNNER=$3 + + echo "* Runs an ALP/GraphBLAS binary by calling an underlying runner and by passing needed flags." + echo + echo "USAGE: ${this_bin} [ALP-specific options...] [--] [runner arguments...] [binary arguments...]" + echo + echo "ALP-specific options:" + echo " -b,--backend run against the ALP/GraphBLAS backend ; possible values: ${BACKENDS[@]}; default: reference" + echo " --show show the full run command WITHOUT executing it" + echo " --help display this help" + echo " -- pass all the following arguments directly to the underlying runner" + echo + echo "* Selected backend: ${BACKEND}" + if [[ -z "${RUNNER}" ]]; then + # shared-memory backends have no runner + echo "* No custom runner: running the given ALP/GraphBLAS binary directly" + else + echo "* Underlying runner: ${RUNNER}" + echo "* Underlying runner help:" + echo + exec ${RUNNER} --help + fi +} while [[ $# -gt 0 ]]; do option="$1" @@ -35,6 +63,9 @@ while [[ $# -gt 0 ]]; do --show) SHOW=echo ;; + --help) + help="yes" + ;; --) break ;; @@ -62,4 +93,10 @@ fi RUNNER=${BACKENDRUNNER[${BACKENDID}]} LD_PATH="@ALP_UTILS_INSTALL_DIR@:${BACKENDRUNENV[${BACKENDID}]}" -${SHOW} LD_LIBRARY_PATH="${LD_PATH}:${LD_LIBRARY_PATH}" ${RUNNER} "${ARGS[@]}" "$@" +if [[ "${help}" == "yes" ]]; then + print_help "$(realpath $0)" ${BACKEND} ${RUNNER} + exit 0 +fi + +${SHOW} LD_LIBRARY_PATH="\"${LD_PATH}:${LD_LIBRARY_PATH}\"" ${RUNNER} "${ARGS[@]}" "$@" + From c21ee11bd38203c0f3d7d417450c848259c649c6 Mon Sep 17 00:00:00 2001 From: Alberto Scolari Date: Wed, 21 Feb 2024 10:44:44 +0100 Subject: [PATCH 08/10] linking also utils lib statically in wrapper --- cmake/AddGRBInstall.cmake | 6 +----- src/CMakeLists.txt | 3 +-- src/grbcxx.in | 8 +++++--- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/cmake/AddGRBInstall.cmake b/cmake/AddGRBInstall.cmake index 2c0bf1d7e..999f82d8e 100644 --- a/cmake/AddGRBInstall.cmake +++ b/cmake/AddGRBInstall.cmake @@ -54,11 +54,7 @@ set( HYBRID_BACKEND_INSTALL_DIR "${BINARY_LIBRARIES_INSTALL_DIR}/hybrid" ) set( COMMON_COMPILE_DEFINITIONS "${REFERENCE_INCLUDE_DEFS};${REFERENCE_OMP_INCLUDE_DEFS}" ) set( COMMON_COMPILE_OPTIONS "-fopenmp" ) -# link flags common to all backends, to be inserted before and after the -# backend-specific flags -set( COMMON_LFLAGS_PRE - "-l${ALP_UTILS_LIBRARY_OUTPUT_NAME};-L '${BINARY_LIBRARIES_INSTALL_DIR}'" -) +# link flags common to all backends, to be inserted after the backend-specific flags if( WITH_NUMA ) list( APPEND COMMON_LFLAGS_POST "-lnuma" ) endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 801d85e29..2aa33bbfb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -28,7 +28,7 @@ add_subdirectory( transition ) ### BUILD WRAPPER SCRIPTS FOR INSTALLATION assert_valid_variables( AVAILABLE_BACKENDS CMAKE_INSTALL_PREFIX INCLUDE_INSTALL_DIR - VERSION BIN_INSTALL_DIR COMMON_LFLAGS_PRE COMMON_LFLAGS_POST + VERSION BIN_INSTALL_DIR COMMON_LFLAGS_POST ) if( WITH_BSP1D_BACKEND OR WITH_HYBRID_BACKEND ) @@ -94,7 +94,6 @@ joinWithNewLine( library_dir LIBRARY_DIRS_SPACED ) joinWithNewLine( compile_options_list BACKEND_CFLAGS_SPACED ) joinWithNewLine( link_flags_list BACKEND_LFLAGS_SPACED ) -list( JOIN COMMON_LFLAGS_PRE " " COMMON_LFLAGS_PRE_SPACED ) list( JOIN COMMON_LFLAGS_POST " " COMMON_LFLAGS_POST_SPACED ) configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/grbcxx.in ${CMAKE_CURRENT_BINARY_DIR}/grbcxx @ONLY ) diff --git a/src/grbcxx.in b/src/grbcxx.in index a4b09cf18..86e8a1af2 100644 --- a/src/grbcxx.in +++ b/src/grbcxx.in @@ -24,6 +24,8 @@ BACKENDLFLAGS=(@BACKEND_LFLAGS_SPACED@) VERSION="@VERSION@" BACKEND_LIBRARY_OUTPUT_NAME="@BACKEND_LIBRARY_OUTPUT_NAME@" LIBRARY_DIRS=(@LIBRARY_DIRS_SPACED@) +UTILS_LIBRARY_NAME="@ALP_UTILS_LIBRARY_OUTPUT_NAME@" +UTILS_LIBRARY_DIR="@ALP_UTILS_INSTALL_DIR@" declare -a ARGS LINK="dynamic" @@ -127,11 +129,11 @@ then fi if [[ "${LINK}" == "dynamic" ]]; then - LIB="-l${BACKEND_LIBRARY_OUTPUT_NAME} -L '${LIBRARY_DIRS[${BACKENDID}]}'" + LIB="-l${UTILS_LIBRARY_NAME} -L '${UTILS_LIBRARY_DIR}' -l${BACKEND_LIBRARY_OUTPUT_NAME} -L '${LIBRARY_DIRS[${BACKENDID}]}'" else - LIB="'${LIBRARY_DIRS[${BACKENDID}]}/lib${BACKEND_LIBRARY_OUTPUT_NAME}.a'" + LIB="'${UTILS_LIBRARY_DIR}/lib${UTILS_LIBRARY_NAME}.a' '${LIBRARY_DIRS[${BACKENDID}]}/lib${BACKEND_LIBRARY_OUTPUT_NAME}.a'" fi -LFLAGS="@COMMON_LFLAGS_PRE_SPACED@ ${LIB} ${BACKENDLFLAGS[${BACKENDID}]} @COMMON_LFLAGS_POST_SPACED@" +LFLAGS="${LIB} ${BACKENDLFLAGS[${BACKENDID}]} @COMMON_LFLAGS_POST_SPACED@" CMD="${COMPILER} -std=${CXXSTD} -I'${INCLUDEDIR}' ${BACKENDCFLAGS[${BACKENDID}]} ${ARGS[@]} "$@" ${LFLAGS}" From c6f841c56e897f7c7f4495dd1ecf2ac2431677a8 Mon Sep 17 00:00:00 2001 From: Alberto Scolari Date: Wed, 21 Feb 2024 11:39:58 +0100 Subject: [PATCH 09/10] improving --help output --- src/grbcxx.in | 17 +++++++++++++---- src/grbrun.in | 10 ++++++++-- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/grbcxx.in b/src/grbcxx.in index 86e8a1af2..a9b594dce 100644 --- a/src/grbcxx.in +++ b/src/grbcxx.in @@ -43,14 +43,17 @@ function print_help { # LPF's lpfcxx doesn't recognize "--help", just "-help" help_arg="-help" fi + local ALL_BACKENDS="${BACKENDS[@]}" echo "* Compiles an ALP/GraphBLAS application by calling an underlying compiler and by passing needed flags." echo - echo "USAGE: ${this_bin} [ALP-specific options...] [--] " + echo "Usage: ${this_bin} [ALP-specific options...] [--] " echo echo "ALP-specific options:" - echo " -b,--backend compile against the ALP/GraphBLAS backend ; possible values: ${BACKENDS[@]}; default: reference" - echo " --link-alp-static link the specified ALP/GraphBLAS backend statically (default linking is dynamic)" + echo " -b,--backend compile against the ALP/GraphBLAS backend ;" + echo " possible values: ${ALL_BACKENDS// /, };" + echo " default: ${BACKENDS[0]}" + echo " --link-alp-static link the specified ALP/GraphBLAS backend and the utility library statically (default linking is dynamic)" echo " --show show the full compilation command WITHOUT executing it" echo " --version display the current ALP/GraphBLAS version" echo " --help display this help" @@ -117,7 +120,13 @@ then fi if [[ "${help}" == "yes" ]]; then - print_help "$(realpath $0)" ${BACKEND} ${COMPILER} + full_path="$0" + # try calling realpath (if it exists) to get the full path + real_path="$(realpath $0 2>&1)" + if [[ "$?" == "0" ]]; then + full_path=${real_path} + fi + print_help "${full_path}" "${BACKEND}" "${COMPILER}" exit 0 fi diff --git a/src/grbrun.in b/src/grbrun.in index 581b7256b..efe73f44b 100644 --- a/src/grbrun.in +++ b/src/grbrun.in @@ -32,7 +32,7 @@ function print_help { echo "* Runs an ALP/GraphBLAS binary by calling an underlying runner and by passing needed flags." echo - echo "USAGE: ${this_bin} [ALP-specific options...] [--] [runner arguments...] [binary arguments...]" + echo "Usage: ${this_bin} [ALP-specific options...] [--] [runner arguments...] [binary arguments...]" echo echo "ALP-specific options:" echo " -b,--backend run against the ALP/GraphBLAS backend ; possible values: ${BACKENDS[@]}; default: reference" @@ -94,7 +94,13 @@ RUNNER=${BACKENDRUNNER[${BACKENDID}]} LD_PATH="@ALP_UTILS_INSTALL_DIR@:${BACKENDRUNENV[${BACKENDID}]}" if [[ "${help}" == "yes" ]]; then - print_help "$(realpath $0)" ${BACKEND} ${RUNNER} + full_path="$0" + # try calling realpath (if it exists) to get the full path + real_path="$(realpath $0 2>&1)" + if [[ "$?" == "0" ]]; then + full_path=${real_path} + fi + print_help "${full_path}" "${BACKEND}" "${RUNNER}" exit 0 fi From 2d0a4b61d85dc93d032982e1d532df78515c040f Mon Sep 17 00:00:00 2001 From: Alberto Scolari Date: Wed, 21 Feb 2024 17:30:32 +0100 Subject: [PATCH 10/10] also in grbrun the --help output now is on multiple lines --- src/grbrun.in | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/grbrun.in b/src/grbrun.in index efe73f44b..d6aa0dce3 100644 --- a/src/grbrun.in +++ b/src/grbrun.in @@ -29,13 +29,16 @@ function print_help { local this_bin="$1" local BACKEND=$2 local RUNNER=$3 + local ALL_BACKENDS="${BACKENDS[@]}" echo "* Runs an ALP/GraphBLAS binary by calling an underlying runner and by passing needed flags." echo echo "Usage: ${this_bin} [ALP-specific options...] [--] [runner arguments...] [binary arguments...]" echo echo "ALP-specific options:" - echo " -b,--backend run against the ALP/GraphBLAS backend ; possible values: ${BACKENDS[@]}; default: reference" + echo " -b,--backend run against the ALP/GraphBLAS backend ;" + echo " possible values: ${ALL_BACKENDS// /, };" + echo " default: ${BACKENDS[0]}" echo " --show show the full run command WITHOUT executing it" echo " --help display this help" echo " -- pass all the following arguments directly to the underlying runner"