Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 27 additions & 42 deletions cmake/AddGRBInstall.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,16 @@ 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 after the backend-specific flags
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
Expand All @@ -59,7 +68,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
Expand All @@ -70,79 +78,62 @@ 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 )
set( multiValueArgs "COMPILER_COMMAND;RUNENV;RUNNER"
function( addBackendWrapperGenOptions backend lib_dir )
set( multiValueArgs "COMPILER_COMMAND;RUNNER"
"COMPILE_DEFINITIONS;COMPILE_OPTIONS;LINK_FLAGS"
)
cmake_parse_arguments( parsed "${options}" "${oneValueArgs}"
cmake_parse_arguments( parsed "${options}" ""
"${multiValueArgs}" "${ARGN}"
)

if( NOT "${backend}" IN_LIST AVAILABLE_BACKENDS )
message( FATAL_ERROR "cannot find ${backend} among available backends")
endif()

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_RUNENV "${parsed_RUNENV}" PARENT_SCOPE )
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 )
list( APPEND __cd "${COMMON_COMPILE_DEFINITIONS}" "${parsed_COMPILE_DEFINITIONS}" )
set( ${backend}_WRAPPER_COMPILE_DEFINITIONS "${__cd}" PARENT_SCOPE )

set( ${backend}_WRAPPER_COMPILE_OPTIONS "${parsed_COMPILE_OPTIONS}" 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 )

## 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()

### 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 ''

# shared memory backends
if( WITH_REFERENCE_BACKEND )
addBackendWrapperGenOptions( "reference"
addBackendWrapperGenOptions( "reference" "${SHMEM_BACKEND_INSTALL_DIR}"
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}"
)
endif()

if( WITH_OMP_BACKEND )
addBackendWrapperGenOptions( "reference_omp"
addBackendWrapperGenOptions( "reference_omp" "${SHMEM_BACKEND_INSTALL_DIR}"
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}"
)
endif()

# dependent backends
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}"
addBackendWrapperGenOptions( "hyperdags" "${HYPERDAGS_BACKEND_INSTALL_DIR}"
COMPILE_DEFINITIONS "${HYPERDAGS_INCLUDE_DEFS};${HYPERDAGS_SELECTION_DEFS}"
)
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}"
addBackendWrapperGenOptions( "nonblocking" "${SHMEM_BACKEND_INSTALL_DIR}"
COMPILE_DEFINITIONS "${NONBLOCKING_INCLUDE_DEFS};${NONBLOCKING_SELECTION_DEFS}"
)
endif()

Expand All @@ -169,24 +160,18 @@ 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}"
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"
)
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}"
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"
)
endif()
endif()
Expand Down
39 changes: 23 additions & 16 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ 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_POST
)
assert_defined_variables( COMMON_WRAPPER_DEFINITIONS COMMON_WRAPPER_OPTIONS )

if( WITH_BSP1D_BACKEND OR WITH_HYBRID_BACKEND )
assert_valid_variables( LPFRUN_CMD MANUALRUN )
Expand All @@ -52,16 +51,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} )
Expand All @@ -75,23 +77,28 @@ 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 )
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 )

list( JOIN compiler_list " " BACKEND_COMPILERS_SPACED )
list( JOIN compile_options_list " " BACKEND_CFLAGS_SPACED )
list( JOIN link_flags_list " " BACKEND_LFLAGS_SPACED )
joinWithNewLine( compile_options_list BACKEND_CFLAGS_SPACED )
joinWithNewLine( link_flags_list BACKEND_LFLAGS_SPACED )
list( JOIN COMMON_LFLAGS_POST " " COMMON_LFLAGS_POST_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
Expand All @@ -107,7 +114,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(
Expand Down
77 changes: 63 additions & 14 deletions src/grbcxx.in
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,55 @@
# limitations under the License.
#

GRB_INSTALL_PATH="@CMAKE_INSTALL_PREFIX@"
INCLUDEDIR="@INCLUDE_INSTALL_DIR@"
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@)
UTILS_LIBRARY_NAME="@ALP_UTILS_LIBRARY_OUTPUT_NAME@"
UTILS_LIBRARY_DIR="@ALP_UTILS_INSTALL_DIR@"

declare -a ARGS
LINK=true
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
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...] [--] <compiler arguments...>"
echo
echo "ALP-specific options:"
echo " -b,--backend <backend> compile against the ALP/GraphBLAS backend <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"
echo " -- <args...> pass all the following <args...> 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"
Expand All @@ -39,16 +74,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}"
Expand All @@ -58,6 +91,9 @@ while [[ $# -gt 0 ]]; do
echo " "
ARGS+=("${option}")
;;
--help)
help="yes"
;;
--)
break
;;
Expand All @@ -75,27 +111,40 @@ for i in "${!BACKENDS[@]}"; do
break
fi
done
COMPILER="${BACKENDCOMPILERS[${BACKENDID}]}"

if [[ ${BACKENDID} -eq -1 ]]
then
echo "Could not find requested backend \`${BACKEND}'"
exit 255
fi

if [[ "${help}" == "yes" ]]; then
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


if [[ ! -d "${INCLUDEDIR}" ]]
then
echo "Could not find GraphBLAS include directory in ${INCLUDEDIR}"
exit 255
fi

LFLAGS=
if ${LINK}
then
LFLAGS=${BACKENDLFLAGS[${BACKENDID}]}
if [[ "${LINK}" == "dynamic" ]]; then
LIB="-l${UTILS_LIBRARY_NAME} -L '${UTILS_LIBRARY_DIR}' -l${BACKEND_LIBRARY_OUTPUT_NAME} -L '${LIBRARY_DIRS[${BACKENDID}]}'"
else
LIB="'${UTILS_LIBRARY_DIR}/lib${UTILS_LIBRARY_NAME}.a' '${LIBRARY_DIRS[${BACKENDID}]}/lib${BACKEND_LIBRARY_OUTPUT_NAME}.a'"
fi
LFLAGS="${LIB} ${BACKENDLFLAGS[${BACKENDID}]} @COMMON_LFLAGS_POST_SPACED@"

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}"

Loading