Skip to content

Commit

Permalink
simplify micro arch selection; set default micro arch to x86-64-v2
Browse files Browse the repository at this point in the history
  • Loading branch information
smuzaffar committed Apr 29, 2024
1 parent ea09de9 commit 2293273
Show file tree
Hide file tree
Showing 20 changed files with 136 additions and 112 deletions.
24 changes: 21 additions & 3 deletions OpenBLAS.spec
Original file line number Diff line number Diff line change
@@ -1,22 +1,40 @@
### RPM external OpenBLAS 0.3.15
## INCLUDE compilation_flags
## INCLUDE microarch_flags
Source: https://github.com/xianyi/OpenBLAS/archive/v%{realversion}.tar.gz
Patch0: OpenBLAS-fix-dynamic-arch
Patch1: OpenBLAS-disable-tests

# Will be part of future release

%prep
%setup -n %{n}-%{realversion}
%patch0 -p1
%patch1 -p1

%build

%ifarch x86_64
XTARGETS="sse3=CORE2"
for t in nehalem sandybridge haswell ; do
XTARGETS="${XTARGETS} $t=$(echo $t | tr 'a-z' 'A-Z')"
done
XTARGETS="${XTARGETS} skylake-avx512=SKYLAKEX"
XTARGETS="${XTARGETS} x86-64-v2=NEHALEM"
XTARGETS="${XTARGETS} x86-64-v3=HASWELL"
XTARGETS="${XTARGETS} x86-64-v4=SKYLAKEX"
STARGET=$(echo %{selected_microarch} | sed 's|^-m||;s|^arch=||')
TARGET_ARCH=$(echo ${XTARGETS} | tr ' ' '\n' | grep "^${STARGET}=" | sed "s|^${STARGET}=||")
if [ "${TARGET_ARCH}" == "" ] ; then
echo "ERROR: Unable to match OpenBlas build target '${STARGET}'. Available build targets are"
echo "${XTARGETS}" | tr ' ' '\n' | sed 's|=.*||'
echo "Please use one of the supported targets or add support for $%{STARGET}'"
exit 1
fi
%endif

# PRESCOTT is a generic x86-64 target https://github.com/xianyi/OpenBLAS/issues/685
%define build_opts FC=gfortran BINARY=64 NUM_THREADS=256 DYNAMIC_ARCH=0 MAKE_NB_JOBS=%{compiling_processes}
%ifarch x86_64
make %{build_opts} TARGET=CORE2
make %{build_opts} TARGET=${TARGET_ARCH}
%endif
%ifarch aarch64
make %{build_opts} TARGET=ARMV8 CFLAGS="%{arch_build_flags}"
Expand Down
2 changes: 2 additions & 0 deletions cmssw-vectorization.file
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
%ifarch x86_64
%define vectorized_packages zlib fastjet tensorflow-sources tensorflow OpenBLAS rivet gbl lwtnn opencv pytorch
%{expand:%(for t in %{vectorized_packages} ; do echo Requires: $t; for v in %{package_vectorization}; do echo Requires: ${t}_${v}; done; done)}
%endif
6 changes: 3 additions & 3 deletions cmssw.spec
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
### RPM cms cmssw CMSSW_12_0_0
### RPM cms cmssw CMSSW_14_1_X_2024-03-31-2400

Requires: cmssw-tool-conf

%define runGlimpse yes
%define saveDeps yes
%define branch master
%define gitcommit %{realversion}
%define gitcommit CMSSW_14_1_X_2024-03-31-2300
# build with debug symbols, and package them in a separate rpm
%define subpackageDebug yes
#define subpackageDebug yes

## INCLUDE cmssw-queue-override

Expand Down
6 changes: 2 additions & 4 deletions fastjet.spec
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
### RPM external fastjet 3.4.1
## INITENV +PATH PYTHON3PATH %{i}/${PYTHON3_LIB_SITE_PACKAGES}
## INCLUDE compilation_flags
## INCLUDE microarch_flags

BuildRequires: autotools
Requires: python3
Expand All @@ -23,11 +24,8 @@ chmod +x ./config.{sub,guess}
cp ./config.sub ./plugins/SISCone/siscone/config.sub
cp ./config.guess ./plugins/SISCone/siscone/config.guess

CXXFLAGS="-O3 -Wall -ffast-math -ftree-vectorize"
CXXFLAGS="-O3 -Wall -ffast-math -ftree-vectorize %{selected_microarch}"

%ifarch x86_64
CXXFLAGS="${CXXFLAGS} -msse3"
%endif
%if "%{?arch_build_flags}"
CXXFLAGS="${CXXFLAGS} %{arch_build_flags}"
%endif
Expand Down
7 changes: 2 additions & 5 deletions gbl.spec
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### RPM external gbl V03-01-01
## INCLUDE cpp-standard
## INCLUDE microarch_flags
%define tag 59c2d99ea96bc739321fd251096504c91467be24
Source: git+https://gitlab.desy.de/claus.kleinwort/general-broken-lines.git?obj=main/%{tag}&export=%{n}-%{realversion}&output=/%{n}-%{realversion}.tgz
Source99: scram-tools.file/tools/eigen/env
Expand All @@ -24,11 +25,7 @@ cmake ../cpp \
-DCMAKE_VERBOSE_MAKEFILE=ON \
-DEIGEN3_INCLUDE_DIR=${EIGEN_ROOT}/include/eigen3 \
-DSUPPORT_ROOT=False \
%ifarch x86_64
-DCMAKE_CXX_FLAGS="$CMS_EIGEN_CXX_FLAGS -msse3"
%else
-DCMAKE_CXX_FLAGS="$CMS_EIGEN_CXX_FLAGS"
%endif
-DCMAKE_CXX_FLAGS="$CMS_EIGEN_CXX_FLAGS %{selected_microarch}"

make %{makeprocesses}

Expand Down
7 changes: 2 additions & 5 deletions lwtnn.spec
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### RPM external lwtnn 2.14.1
## INCLUDE cpp-standard
## INCLUDE microarch_flags

Source: https://github.com/lwtnn/lwtnn/archive/v%{realversion}.tar.gz
Source99: scram-tools.file/tools/eigen/env
Expand All @@ -20,11 +21,7 @@ source %{_sourcedir}/env
cmake ../%{n}-%{realversion} \
-G Ninja \
-DCMAKE_CXX_COMPILER="g++" \
%ifarch x86_64
-DCMAKE_CXX_FLAGS="-fPIC $CMS_EIGEN_CXX_FLAGS -msse3" \
%else
-DCMAKE_CXX_FLAGS="-fPIC $CMS_EIGEN_CXX_FLAGS" \
%endif
-DCMAKE_CXX_FLAGS="-fPIC $CMS_EIGEN_CXX_FLAGS %{selected_microarch}" \
-DCMAKE_INSTALL_PREFIX:PATH="%{i}" \
-DCMAKE_BUILD_TYPE=Release \
-DBUILTIN_BOOST=OFF \
Expand Down
11 changes: 11 additions & 0 deletions microarch_flags.file
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
%ifarch x86_64
%define default_microarch -mx86-64-v2
%if "%{?override_microarch:set}" == "set"
%define selected_microarch %{override_microarch}
%else
%define selected_microarch %{default_microarch}
%endif
%else
%define selected_microarch %{nil}
%define default_microarch %{nil}
%endif
8 changes: 3 additions & 5 deletions opencv.spec
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
### RPM external opencv 4.9.0
## INITENV +PATH PYTHON3PATH %{i}/${PYTHON3_LIB_SITE_PACKAGES}
## INCLUDE cpp-standard
## INCLUDE microarch_flags

%define tag %{realversion}
%define branch master
%define github_user opencv
Expand Down Expand Up @@ -33,11 +35,7 @@ cmake ../%{n}-%{realversion} \
-DPYTHON3_INCLUDE_DIR:PATH="${PYTHON3_ROOT}/include/python%{cms_python3_major_minor_version}" \
-DPYTHON3_LIBRARY:FILEPATH="${PYTHON3_ROOT}/lib/libpython%{cms_python3_major_minor_version}.so" \
-DCMAKE_BUILD_TYPE=Release \
%ifarch x86_64
-DCMAKE_CXX_FLAGS="$CMS_EIGEN_CXX_FLAGS -msse3" \
%else
-DCMAKE_CXX_FLAGS="$CMS_EIGEN_CXX_FLAGS" \
%endif
-DCMAKE_CXX_FLAGS="$CMS_EIGEN_CXX_FLAGS %{selected_microarch}" \
-DCMAKE_PREFIX_PATH="${LIBPNG_ROOT};${LIBTIFF_ROOT};${LIBJPEG_TURBO_ROOT};${ZLIB_ROOT};${PYTHON3_ROOT};${PY2_NUMPY_ROOT};${PY3_NUMPY_ROOT};${EIGEN_ROOT};${OPENBLAS_ROOT}"

ninja -v %{makeprocesses}
Expand Down
36 changes: 29 additions & 7 deletions pgo/cmsdist_packages.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,39 @@
from os.path import dirname, join
pgo_packages = ["geant4", "vecgeom", "g4hepem", "dd4hep", "cmssw", "cmssw-patch", "cmssw-tool-conf"]
pgo_packages = ["geant4", "vecgeom", "OpenBLAS", "g4hepem", "dd4hep", "cmssw", "cmssw-patch", "cmssw-tool-conf"]

def packages(virtual_packages, *args):
opts = args[0].options
try:
if (not opts.PGOGenerate) and (not opts.PGOUse): return
except:
return

def process_pkg(vpkg, pkg):
xindex = 0
pkgspec = "%s.spec" % pkg
spec = []
if vpkg in virtual_packages:
for line in virtual_packages[vpkg]:
if not pkgspec in line:
xindex += 1
spec.append(line)
else: break
spec.append('%define pgo_path_prefix {0}'.format('@LOCALTOP@' if pkg in ["cmssw-tool-conf"] else '%{_builddir}'))
spec.append('%define pgo_package_name {0}'.format('cmssw' if pkg in ["cmssw-tool-conf"] else vpkg))
spec.append('%define {0} 1'.format('pgo_generate' if opts.PGOGenerate else 'pgo_use'))
spec.append('## INCLUDE pgo/compilation_flags_pgo')
if not vpkg in virtual_packages:
spec.append("cmd: cat {0}/{1}".format(opts.cmsdist, pkgspec))
else:
spec += virtual_packages[vpkg][xindex:]
virtual_packages[vpkg] = spec[:]
return

for pkg in pgo_packages:
spec = " echo '%%define pgo_path_prefix %s'" % ('@LOCALTOP@' if pkg in ["cmssw-tool-conf"] else '%{_builddir}')
spec += "; echo '%%define pgo_package_name %s'" % ('cmssw' if pkg in ["cmssw-tool-conf"] else pkg)
spec += "; echo '%%define %s 1'" % ('pgo_generate' if opts.PGOGenerate else 'pgo_use')
spec += "; echo '## INCLUDE pgo/compilation_flags_pgo'"
spec += "; cat %s/%s.spec" % (opts.cmsdist, pkg)
virtual_packages[pkg] = spec
process_pkg(pkg, pkg)
for v in opts.vectorization:
vpkg = "%s_%s" % (pkg,v)
if vpkg in virtual_packages:
pgo_packages.append(vpkg)
process_pkg(vpkg, pkg)
return
7 changes: 2 additions & 5 deletions pytorch.spec
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### RPM external pytorch 2.1.1
## INCLUDE cuda-flags
## INCLUDE microarch_flags

%define cuda_arch_float $(echo %{cuda_arch} | tr ' ' '\\n' | sed -E 's|([0-9])$|.\\1|' | tr '\\n' ' ')
%define tag bb938bbe9f53414dda1e1159795b7536dbffd041
Expand Down Expand Up @@ -76,11 +77,7 @@ cmake ../%{n}-%{realversion} \
-DUSE_SYSTEM_FXDIV=ON \
-DUSE_SYSTEM_PYBIND11=ON \
-DUSE_SYSTEM_BENCHMARK=ON \
%ifarch x86_64
-DCMAKE_CXX_FLAGS="$CMS_EIGEN_CXX_FLAGS -msse3" \
%else
-DCMAKE_CXX_FLAGS="$CMS_EIGEN_CXX_FLAGS" \
%endif
-DCMAKE_CXX_FLAGS="$CMS_EIGEN_CXX_FLAGS %{selected_microarch}" \
-DCMAKE_PREFIX_PATH="%{cmake_prefix_path}" \
-DPYTHON_EXECUTABLE=${PYTHON3_ROOT}/bin/python3

Expand Down
6 changes: 2 additions & 4 deletions rivet.spec
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### RPM external rivet 3.1.10
## INCLUDE cpp-standard
## INCLUDE microarch_flags
## INITENV +PATH PYTHON3PATH %{i}/${PYTHON3_LIB_SITE_PACKAGES}
## OLD GENSER Source: http://cern.ch/service-spi/external/MCGenerators/distribution/rivet/rivet-%{realversion}-src.tgz
Source: git+https://gitlab.com/hepcedar/rivet.git?obj=master/%{n}-%{realversion}&export=%{n}-%{realversion}&output=/%{n}-%{realversion}.tgz
Expand Down Expand Up @@ -39,10 +40,7 @@ autoreconf -fiv
%ifarch aarch64
sed -i -e 's|^ax_openmp_flags=".*"|ax_openmp_flags="none"|' ./configure
%endif
CXXFLAGS="-std=c++%{cms_cxx_standard} $CMS_EIGEN_CXX_FLAGS"
%ifarch x86_64
CXXFLAGS="${CXXFLAGS} -msse3"
%endif
CXXFLAGS="-std=c++%{cms_cxx_standard} $CMS_EIGEN_CXX_FLAGS %{selected_microarch}"
sed -i "/_pow10 only defined for positive powers/d" include/Rivet/Tools/ParticleIdUtils.hh

PYTHON=$(which python3) \
Expand Down
28 changes: 13 additions & 15 deletions scram-project-build.file
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,6 @@
%define scram_home_suffix %(echo %{directpkgreqs} | grep -q /SCRAMV1/V2_ && echo /src || true)
%define scram_script_prefix %(echo %{directpkgreqs} | grep -q /SCRAMV1/V2_ && echo .pl || echo .py)

%if "%{?pkgname}" != "coral"
%if "%{?package_vectorization}" != ""
%define vectorized_build yes
%if "%{?scram_target_default:set}" != "set"
%define scram_target_default default
%endif
%endif
%endif

%if "%{?pgo_generate}"
%undefine runGlimpse
%undefine saveDeps
Expand Down Expand Up @@ -129,9 +120,16 @@ echo %{configtag} > %_builddir/config/config_tag
--keys ENABLE_PGO=0
%endif

%if "%{?vectorized_build:set}" == "set"
sed -i -e 's| SCRAM_TARGETS=.*"| SCRAM_TARGETS="%{package_vectorization}"|' %_builddir/config/Self.xml
sed -i -e 's|</tool>| <runtime name="SCRAM_TARGET" value="%{scram_target_default}"/>\n <runtime name="USER_TARGETS_ALL" value="1"/>\n</tool>|' %_builddir/config/Self.xml
MULTIVEC_ENABLED=false
%if "%{package_vectorization}"
%if "%{?scram_target_default:set}" != "set"
%define scram_target_default default
%endif
if [ -e ${%{toolconf}}/vectorized_packages.txt ] ; then
MULTIVEC_ENABLED=true
sed -i -e 's| SCRAM_TARGETS=.*"| SCRAM_TARGETS="%{package_vectorization}"|' %_builddir/config/Self.xml
sed -i -e 's|</tool>| <runtime name="SCRAM_TARGET" value="%{scram_target_default}"/>\n <runtime name="USER_TARGETS_ALL" value="1"/>\n</tool>|' %_builddir/config/Self.xml
fi
%endif

%if "%{?release_usercxxflags:set}" == "set"
Expand Down Expand Up @@ -194,9 +192,9 @@ export SCRAM_NOSYMCHECK=true
%if "%{?pgo_generate:set}" != "set"
case %{n} in (cmssw|cmssw-patch) %scramcmd b -f -k %{makeprocesses} llvm-ccdb </dev/null || true ;; esac
%endif
%if "%{?vectorized_build:set}" == "set"
touch %{i}/.SCRAM/%{cmsplatf}/multi-targets
%endif
if $MULTIVEC_ENABLED ; then
touch %{i}/.SCRAM/%{cmsplatf}/multi-targets
fi
%scramcmd b --verbose -f %{compileOptions} %{extraOptions} %{makeprocesses} %{buildtarget} </dev/null || { touch ../build-errors && %scramcmd b -f outputlog && [ "%{?ignore_compile_errors:set}" == "set" ]; }

%if "%{?additionalBuildTarget0:set}" == "set"
Expand Down
11 changes: 10 additions & 1 deletion scram-tool-conf.file
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@
## NO_AUTO_RUNPATH
## NO_AUTO_DEPENDENCY
## INCLUDE toolflags
## INCLUDE microarch_flags

BuildRequires: SCRAMV1
Source99: scram-tools
Source: none
%{expand:%(i=90; for v in %{package_vectorization}; do let i=$i+1 ; echo Source${i}: vectorization/$v; done)}

%if "%{package_vectorization}"
%if "%{?vectorized_packages:set}" != "set"
%define vectorized_packages %{nil}
%else
%{expand:%(i=90; for v in %{package_vectorization}; do let i=$i+1 ; echo Source${i}: vectorization/$v; done)}
%endif
%endif

%prep
Expand Down Expand Up @@ -39,6 +43,9 @@ for tool in %requiredtools; do
done
%{_sourcedir}/scram-tools/bin/get_tools "" "system" %i "systemtools"

%if "%{package_vectorization}"
%if "%{vectorized_packages}"
echo %{vectorized_packages} > %i/vectorized_packages.txt
for vec in %{package_vectorization}; do \
ucvec=`echo $vec | tr '[a-z-]' '[A-Z_]'`
for tool in %{vectorized_packages}; do \
Expand All @@ -52,6 +59,8 @@ for vec in %{package_vectorization}; do \
sed -i -e "s#</tool># <flags CXXFLAGS_TARGETS_${ucvec}=\"${f}\"/>\n</tool>#" %i/tools/selected/gcc-cxxcompiler.xml
fi
done
%endif
%endif

for stool in $(echo %skipreqtools | tr '[A-Z]' '[a-z]') ; do
[ -f %i/tools/selected/${stool}.xml ] || continue
Expand Down
5 changes: 2 additions & 3 deletions scram-tools.file/tool-env.file
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
## INCLUDE microarch_flags
export ROOT_CXXMODULES="0"
export PKG_VECTORIZATION="%{?package_vectorization}"
export CMSDIST_DIR="%{cmsdist_directory}"
export CMS_CXX_STANDARD=%{cms_cxx_standard}

%ifarch x86_64
export COMPILER_CXXFLAGS="$(%{cmsdist_directory}/vectorization/cmsdist_packages.py)"
%endif
export COMPILER_CXXFLAGS="%{selected_microarch}"
%if "%{?arch_build_flags}"
export COMPILER_CXXFLAGS="%{arch_build_flags}"
%endif
Expand Down
11 changes: 7 additions & 4 deletions tensorflow-sources.file
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ BuildRequires: bazel java-env git
## INCLUDE cpp-standard
## INCLUDE tensorflow-requires
## INCLUDE compilation_flags
## INCLUDE microarch_flags

#Set tensorflow_mkldnn_contraction_kernel option
#https://github.com/tensorflow/tensorflow/blob/v2.12.1/tensorflow/core/kernels/BUILD#L79-L89
Expand Down Expand Up @@ -42,15 +43,17 @@ export GCC_HOST_COMPILER_PATH="$(which gcc)"
export CC_OPT_FLAGS="-Wno-sign-compare"

BAZEL_OPTS="--batch --output_user_root ../build build -s --verbose_failures --distinct_host_configuration=false"
%ifarch x86_64
BAZEL_OPTS="$BAZEL_OPTS --copt=%{vectorize_flag}"
%else
%if "%{selected_microarch}"
BAZEL_OPTS="$BAZEL_OPTS --copt=%{selected_microarch}"
%if "%{selected_microarch}" != "%{default_microarch}"
BAZEL_OPTS="$BAZEL_OPTS --distinct_host_configuration=true"
%endif
%endif
%if "%{?arch_build_flags}"
BAZEL_OPTS="$BAZEL_OPTS $(echo %{arch_build_flags} | tr ' ' '\n' | grep -v '^$' | sed -e 's|^|--copt=|' | tr '\n' ' ')"
%else
BAZEL_OPTS="$BAZEL_OPTS --copt=-mcpu=native --copt=-mtune=native"
%endif
%endif
BAZEL_OPTS="$BAZEL_OPTS --config=%{build_type} --cxxopt=-std=c++%{cms_cxx_standard} --host_cxxopt=-std=c++%{cms_cxx_standard} %{makeprocesses}"
BAZEL_OPTS="$BAZEL_OPTS --config=noaws --config=nogcp --config=nohdfs --config=nonccl"
%if "%{enable_tf_mkldnn}" == "0"
Expand Down
1 change: 0 additions & 1 deletion tensorflow-sources.spec
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@
%define python_env PYTHON3PATH
%define build_type opt
%define pythonOnly no
%define vectorize_flag -msse3
## INCLUDE tensorflow-sources
Loading

0 comments on commit 2293273

Please sign in to comment.