Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

psABI micro-archs support #100

Merged
merged 2 commits into from
Jan 18, 2024
Merged
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
2 changes: 1 addition & 1 deletion SCRAM/GMake/Makefile.bigedm.rules
Original file line number Diff line number Diff line change
Expand Up @@ -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),\
Expand Down
2 changes: 1 addition & 1 deletion SCRAM/GMake/Makefile.rules
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
114 changes: 76 additions & 38 deletions SCRAM/hooks/runtime/90-cmssw-vectorize
Original file line number Diff line number Diff line change
Expand Up @@ -13,57 +13,95 @@ 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
break
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

Expand Down