From e18687dd48d11c7ca96d057128cf44941135d61c Mon Sep 17 00:00:00 2001 From: Shahzad Malik Muzaffar Date: Wed, 17 Jan 2024 11:51:03 +0100 Subject: [PATCH 1/2] added suport for psABI --- SCRAM/hooks/runtime/90-cmssw-vectorize | 114 ++++++++++++++++--------- 1 file changed, 76 insertions(+), 38 deletions(-) diff --git a/SCRAM/hooks/runtime/90-cmssw-vectorize b/SCRAM/hooks/runtime/90-cmssw-vectorize index 3478d6d..24e83d9 100755 --- a/SCRAM/hooks/runtime/90-cmssw-vectorize +++ b/SCRAM/hooks/runtime/90-cmssw-vectorize @@ -13,49 +13,83 @@ elif [ "${SCRAM_TARGET}" = "" ] ; then fi #No need to overirde LD_LIBRARY_PATH if SCRAM_TARGET is not set or set to "default" if [ "${SCRAM_TARGET}" = "" ] || [ "${SCRAM_TARGET}" = "default" ] ; then exit 0 ; fi +BUILD_ARCHS="$(${SCRAM} tool info self | grep '^SCRAM_TARGETS+=' | sed 's|.*=||')" +[ "${BUILD_ARCHS}" = "" ] && exit 0 -nocona="" -core2="nocona ${nocona}" -nehalem="core2 ${core2}" -westmere="nehalem ${nehalem}" -bonnell="core2 ${core2}" -silvermont="westmere bonnell ${westmere} ${bonnell}" -sandybridge="westmere ${westmere}" -ivybridge="sandybridge ${sandybridge}" -haswell="bonnell ivybridge ${bonnell} ${ivybridge}" -skylake="silvermont haswell ${silvermont} ${haswell}" -skylake_avx512="skylake ${skylake}" -cascadelake="skylake-avx512 ${skylake_avx512}" -cannonlake="skylake ${skylake}" -icelake_client="cascadelake cannonlake ${cascadelake} ${cannonlake}" -icelake_server="icelake-client ${icelake_client}" -tigerlake="icelake-server ${icelake_server}" -goldmont="silvermont ${silvermont}" -cooperlake="cascadelake ${cascadelake}" -sapphirerapids="cooperlake ${cooperlake}" -broadwell="silvermont haswell ${silvermont} ${haswell}" -goldmont_plus="goldmont ${goldmont}" -knl="silvermont haswell ${silvermont} ${haswell}" -knm="knl ${knl}" -alderlake="skylake ${skylake}" -tremont="goldmont-plus ${goldmont_plus}" +PSABI_ARCH_PREFIX="x86-64-v" +SCRAM_NON_PSABI_ARCHS=$(echo ${BUILD_ARCHS} | tr ' ' '\n' | grep -v "${PSABI_ARCH_PREFIX}") +SCRAM_PSABI_ARCHS=$(echo ${BUILD_ARCHS} | tr ' ' '\n' | grep "${PSABI_ARCH_PREFIX}") -LD_ENV=$(${SCRAM} tool info gcc-cxxcompiler | grep '^LD_LIBRARY_PATH='):${LD_LIBRARY_PATH} -PATH_ENV=$(${SCRAM} tool info gcc-cxxcompiler | grep '^PATH='):${PATH} -eval "export $LD_ENV; export $PATH_ENV" -NATIVE_ARCH=$(gcc -march=native -Q --help=target | grep -- '^ *-march=' | sed 's|.*=\s*||') -SUPPORTED_ARCHS="$(${SCRAM} tool info self | grep '^SCRAM_TARGETS+=' | sed 's|.*=||')" -[ "${NATIVE_ARCH}" = "" ] && exit 0 -[ "${SUPPORTED_ARCHS}" = "" ] && exit 0 +#Micro-archs compatibility: https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html +NATIVE_ARCH="" +if [ "${SCRAM_NON_PSABI_ARCHS}" != "" ] ; then + nocona="" + core2="nocona ${nocona}" + nehalem="core2 ${core2}" + westmere="nehalem ${nehalem}" + bonnell="core2 ${core2}" + silvermont="westmere bonnell ${westmere} ${bonnell}" + sandybridge="westmere ${westmere}" + ivybridge="sandybridge ${sandybridge}" + haswell="bonnell ivybridge ${bonnell} ${ivybridge}" + skylake="silvermont haswell ${silvermont} ${haswell}" + skylake_avx512="skylake ${skylake}" + cascadelake="skylake-avx512 ${skylake_avx512}" + cannonlake="skylake ${skylake}" + icelake_client="cascadelake cannonlake ${cascadelake} ${cannonlake}" + icelake_server="icelake-client ${icelake_client}" + tigerlake="icelake-server ${icelake_server}" + goldmont="silvermont ${silvermont}" + cooperlake="cascadelake ${cascadelake}" + sapphirerapids="cooperlake ${cooperlake}" + broadwell="silvermont haswell ${silvermont} ${haswell}" + goldmont_plus="goldmont ${goldmont}" + knl="silvermont haswell ${silvermont} ${haswell}" + knm="knl ${knl}" + alderlake="skylake ${skylake}" + tremont="goldmont-plus ${goldmont_plus}" + + LD_ENV=$(${SCRAM} tool info gcc-cxxcompiler | grep '^LD_LIBRARY_PATH='):${LD_LIBRARY_PATH} + PATH_ENV=$(${SCRAM} tool info gcc-cxxcompiler | grep '^PATH='):${PATH} + eval "export $LD_ENV; export $PATH_ENV" + NATIVE_ARCH=$(gcc -march=native -Q --help=target | grep -- '^ *-march=' | sed 's|.*=\s*||') + [ "${NATIVE_ARCH}" = "" ] || NATIVE_ARCHS="$(eval echo \$$(echo ${NATIVE_ARCH} | tr - _ ))" +fi + +#psABI micro architectures support +PSABI_ARCHS="" +if [ "${SCRAM_PSABI_ARCHS}" != "" ] ; then + PSABI_ARCHS=$(ld.so --help | grep -E " ${PSABI_ARCH_PREFIX}[0-9]+ " | grep -i supported | sed 's|^ *||;s| .*||' | tr '\n' ' ') +fi + +#Use default target if can not find native arch or supported psABI micro-archs +[ "${NATIVE_ARCH}${PSABI_ARCHS}" = "" ] && exit 0 + +SEL_TARGETS="" +if [ "${SCRAM_TARGET}" = "auto" ] ; then + [ "${PSABI_ARCHS}" = "" ] || SEL_TARGETS="${PSABI_ARCHS}" + #Prefer native arch over any other micro-arch + [ "${NATIVE_ARCH}" = "" ] || SEL_TARGETS="${NATIVE_ARCH} ${SEL_TARGETS} ${NATIVE_ARCHS}" +else + if [ $(echo ${SCRAM_TARGET} | grep "${PSABI_ARCH_PREFIX}[1-9]" | wc -l) -gt 0 ] ; then + if [ "${PSABI_ARCHS}" != "" ] ; then + psABI_NUM=$(echo ${SCRAM_TARGET} | sed "s|${PSABI_ARCH_PREFIX}||") + while [ $psABI_NUM -gt 1 ] ; do + SEL_TARGETS="${SEL_TARGETS} ${PSABI_ARCH_PREFIX}${psABI_NUM}" + let psABI_NUM=${psABI_NUM}-1 + done + fi + elif [ "${NATIVE_ARCH}" != "" ] ; then + SEL_TARGETS="${NATIVE_ARCH} ${NATIVE_ARCHS}" + fi +fi -SEL_TARGET="${SCRAM_TARGET}" -if [ "${SCRAM_TARGET}" = "auto" ] ; then SEL_TARGET="${NATIVE_ARCH}" ; fi MATCHED_TARGET="" -for t in ${SEL_TARGET} $(eval echo \$$(echo ${SEL_TARGET} | tr - _ )) ; do - if [ $(echo " ${SUPPORTED_ARCHS} " | grep " ${t} " | wc -l) -eq 1 ] ; then +for t in ${SEL_TARGETS}; do + if [ $(echo " ${BUILD_ARCHS} " | grep " ${t} " | wc -l) -eq 1 ] ; then if [ "${SCRAM_TARGET}" != "auto" ] ; then if [ "${SCRAM_TARGET}" != "${t}" ] ; then - echo "WARNING: Target ${SCRAM_TARGET} requested but best match found is ${t} from the available supported targets '${SUPPORTED_ARCHS}'." 1>&2 + echo "WARNING: Target ${SCRAM_TARGET} requested but best match found is ${t} from the available supported targets '${BUILD_ARCHS}'." 1>&2 fi fi MATCHED_TARGET=$t @@ -63,7 +97,11 @@ for t in ${SEL_TARGET} $(eval echo \$$(echo ${SEL_TARGET} | tr - _ )) ; do fi done if [ "${MATCHED_TARGET}" = "" ] ; then - echo "WARNING: Native target ${NATIVE_ARCH} does not match any of the supported targets '${SUPPORTED_ARCHS}'. Using default target." 1>&2 + if [ "${SCRAM_TARGET}" = "auto" ] ; then + echo "WARNING: System micro-arch(s) native:'${NATIVE_ARCH}', psABI:'${PSABI_ARCHS}' do not match any of the cmssw supported micro-archs '${BUILD_ARCHS}'. Using default target." 1>&2 + else + echo "WARNING: Requested arch '${SCRAM_TARGET}' does not match any of the cmssw targets '${BUILD_ARCHS}'. Using default target." 1>&2 + fi exit 0 fi From 6c1298cc0700735f893b9927e29dc62823b83aad Mon Sep 17 00:00:00 2001 From: Shahzad Malik Muzaffar Date: Thu, 18 Jan 2024 13:37:42 +0100 Subject: [PATCH 2/2] 6281806efa5f31597f5b71359e0a7826a6506388 --- SCRAM/GMake/Makefile.bigedm.rules | 2 +- SCRAM/GMake/Makefile.rules | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/SCRAM/GMake/Makefile.bigedm.rules b/SCRAM/GMake/Makefile.bigedm.rules index 9686655..cf75f1c 100644 --- a/SCRAM/GMake/Makefile.bigedm.rules +++ b/SCRAM/GMake/Makefile.bigedm.rules @@ -118,7 +118,7 @@ $($(1)_objdir)/bigobj/$(3)/$(1).$(BIGLIB_OBJEXT): $(subst $($(1)_objdir)/,$($(1) $$(call big_obj,$(2),$(1),$$^,$(SCRAMSTORENAME_OBJS),$3) endef define TargetBigPlugin -$(1)_$(3)_BUILD_ENV:=CMSSW_CPU_TYPE=$(patsubst scram_%,%$3) && +$(1)_$(3)_BUILD_ENV:=CMSSW_CPU_TYPE=$(patsubst scram_%,%,$3) && $(1)_objs_$3:=$(foreach o,$($(1)_objs),$(eval n:=$(basename $(notdir $o)))\ $(if $(strip $(filter $3,$($(n)_LOC_FLAGS_TARGETS))),\ $(subst /$(n).$(BIGLIB_OBJEXT),/$3/$(n).$(BIGLIB_OBJEXT),$o),\ diff --git a/SCRAM/GMake/Makefile.rules b/SCRAM/GMake/Makefile.rules index 12e4254..f9d0157 100644 --- a/SCRAM/GMake/Makefile.rules +++ b/SCRAM/GMake/Makefile.rules @@ -1297,7 +1297,7 @@ endef #safename,path,safepath,scriptstore,scripts,libstore,logprodstore,plugintype define Library $(1)_plugintype:=$(8) -ifeq ($(SCRAM_MULTI_TARGET),1) +ifeq ($(strip $(SCRAM_MULTI_TARGET)$(filter alpaka/cuda alpaka/rocm,$($(1)_PRODUCT_TYPE))),1) ifeq ($(strip $(USER_TARGETS_ALL)),1) $(1)_LOC_FLAGS_TARGETS:=$(call GetCompilerData,$1,SCRAM_TARGETS) else ifeq ($(strip $($(1)_LOC_FLAGS_TARGETS)),1)