From 0f8b473777286836c4628bb555617148968a9166 Mon Sep 17 00:00:00 2001 From: Marcel R Date: Tue, 19 Dec 2023 17:31:35 +0100 Subject: [PATCH 1/7] Port XLA/AOT from 14_0_X. --- cmssw-vectorization.file | 2 +- pip/cmsml.file | 2 +- pip/execnet.file | 1 + pip/pytest-xdist.file | 1 + pip/requirements.txt | 14 +++++--- pip/tabulate.file | 1 + pip/tensorflow.file | 2 +- python_tools.spec | 1 + .../tensorflow-xla-runtime.xml | 9 ++++++ tensorflow-sources.file | 6 ++-- tensorflow-xla-runtime.spec | 32 +++++++++++++++++++ 11 files changed, 61 insertions(+), 10 deletions(-) create mode 100644 pip/execnet.file create mode 100644 pip/pytest-xdist.file create mode 100644 pip/tabulate.file create mode 100644 scram-tools.file/tools/tensorflow-xla-runtime/tensorflow-xla-runtime.xml create mode 100644 tensorflow-xla-runtime.spec diff --git a/cmssw-vectorization.file b/cmssw-vectorization.file index cf72bd747de..03b7dd9c5b4 100644 --- a/cmssw-vectorization.file +++ b/cmssw-vectorization.file @@ -1,2 +1,2 @@ -%define vectorized_packages zlib fastjet tensorflow-sources tensorflow OpenBLAS rivet gbl +%define vectorized_packages zlib fastjet tensorflow-sources tensorflow tensorflow-xla-runtime OpenBLAS rivet gbl %{expand:%(for t in %{vectorized_packages} ; do echo Requires: $t; for v in %{package_vectorization}; do echo Requires: ${t}_${v}; done; done)} diff --git a/pip/cmsml.file b/pip/cmsml.file index 7c962a18c6b..a432e9b83d1 100644 --- a/pip/cmsml.file +++ b/pip/cmsml.file @@ -1 +1 @@ -Requires: py3-six +Requires: py3-six py3-tabulate py3-pytest py3-pytest-xdist diff --git a/pip/execnet.file b/pip/execnet.file new file mode 100644 index 00000000000..ec0e0493a68 --- /dev/null +++ b/pip/execnet.file @@ -0,0 +1 @@ +BuildRequires: py3-hatchling py3-hatch-vcs diff --git a/pip/pytest-xdist.file b/pip/pytest-xdist.file new file mode 100644 index 00000000000..aa9bc23218a --- /dev/null +++ b/pip/pytest-xdist.file @@ -0,0 +1 @@ +Requires: py3-pytest py3-execnet diff --git a/pip/requirements.txt b/pip/requirements.txt index d2033f3ac17..c5b9e51ae6d 100644 --- a/pip/requirements.txt +++ b/pip/requirements.txt @@ -56,7 +56,7 @@ charset-normalizer==3.1.0 cleo==2.0.1 click==8.1.3 clikit==0.6.2 -cmsml==0.1.2 +cmsml==0.2.2 contourpy==1.0.7 correctionlib==2.2.2 crashtest==0.4.1 @@ -94,6 +94,7 @@ docutils==0.19 dulwich==0.21.3 editables==0.3 entrypoints==0.4 +execnet==2.0.2 executing==1.2.0 exceptiongroup==1.1.1 fasteners==0.18 @@ -170,13 +171,13 @@ keras-preprocessing==1.1.2 keras2onnx==1.7.0 keyring==23.13.1 kiwisolver==1.4.4 -law==0.1.12 +law==0.1.18 lazy-object-proxy==1.9.0 lizard==1.17.10 #llvmlite==v0.41.0dev0 locket==1.0.0 lockfile==0.12.2 -luigi==3.2.1 +luigi==3.5.0 lxml==4.9.2 lz4==4.3.2 make==0.1.6.post2 @@ -284,6 +285,7 @@ pysqlite3==0.5.0 pytest==7.4.0 pytest-cov==4.0.0 pytest-runner==6.0.0 +pytest-xdist==3.5.0 python-daemon==3.0.1 python-dateutil==2.8.2 python-json-logger==2.0.7 @@ -313,7 +315,7 @@ schema==0.7.5 scikit-build==0.16.7 scikit-build-core==0.3.0 scikit-learn==1.2.2 -scinum==1.4.6 +scinum==2.0.2 scipy==1.10.1 secretstorage==3.3.3 semantic-version==2.10.0 @@ -337,6 +339,7 @@ stevedore==5.0.0 subprocess32==3.5.4 sympy==1.11.1 tables==3.8.0 +tabulate==0.9.0 tenacity==8.2.2 #NO_AUTO_UPDATE:1: Force to use tensorflow 2.6.4; this should match the version in tensorflow-sources.spec tensorflow==2.12.0 @@ -379,7 +382,8 @@ Werkzeug==3.0.1 #NO_AUTO_UPDATE:1: you need wheel to build wheel wheel==0.40.0 widgetsnbextension==4.0.7 -wrapt==1.15.0 +#NO_AUTO_UPDATE: wrapt >=1.15.0 breaks tensorflow saved model, https://github.com/GrahamDumpleton/wrapt/issues/231 +wrapt==1.14.1 xgboost==1.7.5 yarl==1.8.2 zipp==3.15.0 diff --git a/pip/tabulate.file b/pip/tabulate.file new file mode 100644 index 00000000000..ec0e0493a68 --- /dev/null +++ b/pip/tabulate.file @@ -0,0 +1 @@ +BuildRequires: py3-hatchling py3-hatch-vcs diff --git a/pip/tensorflow.file b/pip/tensorflow.file index c8d7fc33dc2..63f7bfca211 100644 --- a/pip/tensorflow.file +++ b/pip/tensorflow.file @@ -1,7 +1,7 @@ Requires: py3-tensorboard py3-opt-einsum py3-tensorflow-estimator py3-wrapt py3-google-pasta py3-scipy Requires: tensorflow-sources %define PipPreBuildPy PIPFILE=${TENSORFLOW_SOURCES_ROOT}/tensorflow-%{realversion}-cp%{cms_python3_major_minor}-cp%{cms_python3_major_minor}-linux_%{_arch}.whl -%define PipPostBuild rm -f %{i}/bin/tensorboard* ; ls %{i}/bin/* | xargs -i mv '{}' '{}3' +%define PipPostBuild rm -f %{i}/bin/tensorboard* ; rm -r %{i}/lib/python%{cms_python3_major_minor_version}/site-packages/tensorflow/xla_aot_runtime_src ; ls %{i}/bin/* | xargs -i mv '{}' '{}3' %define PipDepsPost | grep -v libclang ## INCLUDE tensorflow-requires Requires: py3-funcsigs py3-pbr py3-packaging py3-appdirs py3-pyparsing py3-mock py3-Werkzeug diff --git a/python_tools.spec b/python_tools.spec index 0e60f74844e..19c9fdf261a 100644 --- a/python_tools.spec +++ b/python_tools.spec @@ -17,6 +17,7 @@ Requires: py3-law Requires: py3-protobuf Requires: py3-tables +Requires: py3-tabulate Requires: py3-numexpr Requires: py3-histogrammar Requires: py3-pandas diff --git a/scram-tools.file/tools/tensorflow-xla-runtime/tensorflow-xla-runtime.xml b/scram-tools.file/tools/tensorflow-xla-runtime/tensorflow-xla-runtime.xml new file mode 100644 index 00000000000..2976fcb58b4 --- /dev/null +++ b/scram-tools.file/tools/tensorflow-xla-runtime/tensorflow-xla-runtime.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/tensorflow-sources.file b/tensorflow-sources.file index 395ae2d9558..8c60c21729d 100644 --- a/tensorflow-sources.file +++ b/tensorflow-sources.file @@ -74,7 +74,7 @@ export TF_NEED_CUDA=%{enable_gpu} export TF_NEED_JEMALLOC=0 export TF_NEED_HDFS=0 export TF_NEED_GCP=0 -export TF_ENABLE_XLA=0 +export TF_ENABLE_XLA=1 export TF_NEED_OPENCL=0 export TF_NEED_VERBS=0 export TF_NEED_MKL=0 @@ -150,6 +150,7 @@ bazel $BAZEL_OPTS //tensorflow/compiler/tf2xla:xla_compiled_cpu_function #bazel $BAZEL_OPTS //tensorflow/compiler/aot:tfcompile bazel $BAZEL_OPTS //tensorflow/core/profiler bazel $BAZEL_OPTS //tensorflow:install_headers +bazel $BAZEL_OPTS //tensorflow/compiler/tf2xla:tf2xla_supported_ops # rebuild *.pb.{h|cc} files using the external protobuf compiler chmod -R a+rwX $PWD/bazel-bin/tensorflow/include @@ -192,8 +193,9 @@ for l in tensorflow_cc tensorflow_framework tensorflow ; do done #cp -p $srcdir/compiler/aot/tfcompile $bindir +cp -p $srcdir/compiler/tf2xla/tf2xla_supported_ops $bindir for name in tensorflow absl re2 third_party ; do - cp -r -p $srcdir/include/$name $incdir + cp -r -p $srcdir/include/$name $incdir done # copy headers from downloaded dependencies diff --git a/tensorflow-xla-runtime.spec b/tensorflow-xla-runtime.spec new file mode 100644 index 00000000000..98bece9cba3 --- /dev/null +++ b/tensorflow-xla-runtime.spec @@ -0,0 +1,32 @@ +### RPM external tensorflow-xla-runtime 2.12.0 + +Requires: eigen tensorflow-sources +BuildRequires: cmake + +%prep +unzip -q -o ${TENSORFLOW_SOURCES_ROOT}/tensorflow-%{realversion}-cp%{cms_python3_major_minor}-cp%{cms_python3_major_minor}-linux_%{_arch}.whl + +%build + +# fix a single comparison between size_t and int +sed -i -r 's/assert\(\(arg_size\(index\)/assert\(\(\(size_t\)arg_size\(index\)/' tensorflow/include/tensorflow/compiler/tf2xla/xla_compiled_cpu_function.h + +export CPATH="${CPATH}:${EIGEN_ROOT}/include/eigen3" +export CPATH="${CPATH}:%{i}/tensorflow/include" +export CPATH="${CPATH}:%{i}/tensorflow/include/third_party/eigen3" + +pushd tensorflow/xla_aot_runtime_src + cmake . -DCMAKE_CXX_FLAGS="-fPIC" + make %{makeprocesses} + # this builds a shared library, but when used some symbols are missig (e.g `tsl::mutex::unlock()') + # so it does not seem intended to be used as a shared lib + gcc -shared -o libtf_xla_runtime.so -Wl,--whole-archive libtf_xla_runtime.a -Wl,--no-whole-archive +popd + +%install + +mv tensorflow/include %{i} + +mkdir -p %{i}/lib/archive +mv tensorflow/xla_aot_runtime_src/libtf_xla_runtime.a %{i}/lib/archive/libtf_xla_runtime-static.a +mv tensorflow/xla_aot_runtime_src/libtf_xla_runtime.so %{i}/lib/libtf_xla_runtime.so From cf12ea3cfa2e4c1fe358ad9bfc15750fb48dbb14 Mon Sep 17 00:00:00 2001 From: Marcel Rieger Date: Mon, 12 Feb 2024 14:59:15 +0100 Subject: [PATCH 2/7] Add tensorflow-xla-runtime to vectorization/cmsdist_packages.py. --- vectorization/cmsdist_packages.py | 1 + 1 file changed, 1 insertion(+) diff --git a/vectorization/cmsdist_packages.py b/vectorization/cmsdist_packages.py index ac3e599c1cf..afe4a9b4c70 100755 --- a/vectorization/cmsdist_packages.py +++ b/vectorization/cmsdist_packages.py @@ -16,6 +16,7 @@ "fastjet", "tensorflow-sources", "tensorflow", + "tensorflow-xla-runtime", "OpenBLAS", "rivet", "gbl", From e40b72c5dc9de75f9f6fe36e69844919939553c4 Mon Sep 17 00:00:00 2001 From: Marcel Rieger Date: Mon, 12 Feb 2024 15:12:32 +0100 Subject: [PATCH 3/7] Add "-msse3" flag in tensorflow-xla-runtime.spec. --- tensorflow-xla-runtime.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensorflow-xla-runtime.spec b/tensorflow-xla-runtime.spec index 98bece9cba3..5bc996e5bf2 100644 --- a/tensorflow-xla-runtime.spec +++ b/tensorflow-xla-runtime.spec @@ -16,7 +16,7 @@ export CPATH="${CPATH}:%{i}/tensorflow/include" export CPATH="${CPATH}:%{i}/tensorflow/include/third_party/eigen3" pushd tensorflow/xla_aot_runtime_src - cmake . -DCMAKE_CXX_FLAGS="-fPIC" + cmake . -DCMAKE_CXX_FLAGS="-fPIC -msse3" make %{makeprocesses} # this builds a shared library, but when used some symbols are missig (e.g `tsl::mutex::unlock()') # so it does not seem intended to be used as a shared lib From cc33bb353b02d771471e2dc5e4458fa0958e4b74 Mon Sep 17 00:00:00 2001 From: Marcel Rieger Date: Mon, 12 Feb 2024 16:25:21 +0100 Subject: [PATCH 4/7] Add tensorflow-xla-runtime to cmssw-tool-conf.spec. --- cmssw-tool-conf.spec | 1 + 1 file changed, 1 insertion(+) diff --git a/cmssw-tool-conf.spec b/cmssw-tool-conf.spec index 1a91f0a58eb..7a2d8271051 100644 --- a/cmssw-tool-conf.spec +++ b/cmssw-tool-conf.spec @@ -97,6 +97,7 @@ Requires: hls Requires: opencv Requires: grpc Requires: onnxruntime +Requires: tensorflow-xla-runtime Requires: TOoLLiP Requires: triton-inference-client Requires: hdf5 From f77258ca249a6ee935625a3239b31605844ba9a5 Mon Sep 17 00:00:00 2001 From: Marcel R Date: Wed, 14 Feb 2024 14:21:25 +0100 Subject: [PATCH 5/7] Address review comments by @smuzaffar. --- pip/tensorflow.file | 5 +++-- .../tools/py3-tensorflow/py3-tensorflow.xml | 6 ++++++ .../py3-tensorflow/tensorflow-includes.xml | 6 ++++++ .../tensorflow-xla-runtime.xml | 1 + .../tensorflow-xla-runtime/vectorized.tmpl | 5 +++++ tensorflow-xla-runtime.spec | 19 +++++-------------- 6 files changed, 26 insertions(+), 16 deletions(-) create mode 100644 scram-tools.file/tools/py3-tensorflow/py3-tensorflow.xml create mode 100644 scram-tools.file/tools/py3-tensorflow/tensorflow-includes.xml create mode 100644 scram-tools.file/tools/tensorflow-xla-runtime/vectorized.tmpl diff --git a/pip/tensorflow.file b/pip/tensorflow.file index 63f7bfca211..80bd7e135c8 100644 --- a/pip/tensorflow.file +++ b/pip/tensorflow.file @@ -1,7 +1,7 @@ Requires: py3-tensorboard py3-opt-einsum py3-tensorflow-estimator py3-wrapt py3-google-pasta py3-scipy Requires: tensorflow-sources %define PipPreBuildPy PIPFILE=${TENSORFLOW_SOURCES_ROOT}/tensorflow-%{realversion}-cp%{cms_python3_major_minor}-cp%{cms_python3_major_minor}-linux_%{_arch}.whl -%define PipPostBuild rm -f %{i}/bin/tensorboard* ; rm -r %{i}/lib/python%{cms_python3_major_minor_version}/site-packages/tensorflow/xla_aot_runtime_src ; ls %{i}/bin/* | xargs -i mv '{}' '{}3' +%define PipPostBuild rm -f %{i}/bin/tensorboard* ; ls %{i}/bin/* | xargs -i mv '{}' '{}3' %define PipDepsPost | grep -v libclang ## INCLUDE tensorflow-requires Requires: py3-funcsigs py3-pbr py3-packaging py3-appdirs py3-pyparsing py3-mock py3-Werkzeug @@ -19,7 +19,8 @@ Requires: llvm %define PipPostInstall \ for f in %{RelocateFiles} ; do \ [ ! -f %{i}/$f ] || sed -i -e 's|/[^ ]*/%{cmsplatf}/external/|%{cmsroot}/%{cmsplatf}/external/|' %{i}/$f \ - done + done ; \ + sed -i 's/assert((arg_size(index)/assert(((size_t)arg_size(index)/' %{i}/lib/python%{cms_python3_major_minor_version}/site-packages/tensorflow/include/tensorflow/compiler/tf2xla/xla_compiled_cpu_function.h %define PipPostPost \ for f in %{RelocateFiles} ; do \ diff --git a/scram-tools.file/tools/py3-tensorflow/py3-tensorflow.xml b/scram-tools.file/tools/py3-tensorflow/py3-tensorflow.xml new file mode 100644 index 00000000000..944d82f7fbb --- /dev/null +++ b/scram-tools.file/tools/py3-tensorflow/py3-tensorflow.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/scram-tools.file/tools/py3-tensorflow/tensorflow-includes.xml b/scram-tools.file/tools/py3-tensorflow/tensorflow-includes.xml new file mode 100644 index 00000000000..588e64bb8ba --- /dev/null +++ b/scram-tools.file/tools/py3-tensorflow/tensorflow-includes.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/scram-tools.file/tools/tensorflow-xla-runtime/tensorflow-xla-runtime.xml b/scram-tools.file/tools/tensorflow-xla-runtime/tensorflow-xla-runtime.xml index 2976fcb58b4..1eb48313f87 100644 --- a/scram-tools.file/tools/tensorflow-xla-runtime/tensorflow-xla-runtime.xml +++ b/scram-tools.file/tools/tensorflow-xla-runtime/tensorflow-xla-runtime.xml @@ -6,4 +6,5 @@ + diff --git a/scram-tools.file/tools/tensorflow-xla-runtime/vectorized.tmpl b/scram-tools.file/tools/tensorflow-xla-runtime/vectorized.tmpl new file mode 100644 index 00000000000..505109e960f --- /dev/null +++ b/scram-tools.file/tools/tensorflow-xla-runtime/vectorized.tmpl @@ -0,0 +1,5 @@ + + + + + diff --git a/tensorflow-xla-runtime.spec b/tensorflow-xla-runtime.spec index 5bc996e5bf2..079795866e2 100644 --- a/tensorflow-xla-runtime.spec +++ b/tensorflow-xla-runtime.spec @@ -1,32 +1,23 @@ ### RPM external tensorflow-xla-runtime 2.12.0 +## INCLUDE cpp-standard -Requires: eigen tensorflow-sources +Requires: eigen py3-tensorflow BuildRequires: cmake %prep -unzip -q -o ${TENSORFLOW_SOURCES_ROOT}/tensorflow-%{realversion}-cp%{cms_python3_major_minor}-cp%{cms_python3_major_minor}-linux_%{_arch}.whl -%build +cp -r ${PY3_TENSORFLOW_ROOT}/lib/python%{cms_python3_major_minor_version}/site-packages/tensorflow . -# fix a single comparison between size_t and int -sed -i -r 's/assert\(\(arg_size\(index\)/assert\(\(\(size_t\)arg_size\(index\)/' tensorflow/include/tensorflow/compiler/tf2xla/xla_compiled_cpu_function.h +%build export CPATH="${CPATH}:${EIGEN_ROOT}/include/eigen3" -export CPATH="${CPATH}:%{i}/tensorflow/include" -export CPATH="${CPATH}:%{i}/tensorflow/include/third_party/eigen3" pushd tensorflow/xla_aot_runtime_src - cmake . -DCMAKE_CXX_FLAGS="-fPIC -msse3" + cmake . -DCMAKE_CXX_FLAGS="-fPIC -msse3" -DCMAKE_CXX_STANDARD=%{cms_cxx_standard} -DBUILD_SHARED_LIBS=OFF make %{makeprocesses} - # this builds a shared library, but when used some symbols are missig (e.g `tsl::mutex::unlock()') - # so it does not seem intended to be used as a shared lib - gcc -shared -o libtf_xla_runtime.so -Wl,--whole-archive libtf_xla_runtime.a -Wl,--no-whole-archive popd %install -mv tensorflow/include %{i} - mkdir -p %{i}/lib/archive mv tensorflow/xla_aot_runtime_src/libtf_xla_runtime.a %{i}/lib/archive/libtf_xla_runtime-static.a -mv tensorflow/xla_aot_runtime_src/libtf_xla_runtime.so %{i}/lib/libtf_xla_runtime.so From 12f9496dce4d93e2e7ec7d561771a4285275001f Mon Sep 17 00:00:00 2001 From: Marcel R Date: Wed, 14 Feb 2024 14:31:33 +0100 Subject: [PATCH 6/7] Remove include. --- .../tools/tensorflow-xla-runtime/tensorflow-xla-runtime.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/scram-tools.file/tools/tensorflow-xla-runtime/tensorflow-xla-runtime.xml b/scram-tools.file/tools/tensorflow-xla-runtime/tensorflow-xla-runtime.xml index 1eb48313f87..c022bc11694 100644 --- a/scram-tools.file/tools/tensorflow-xla-runtime/tensorflow-xla-runtime.xml +++ b/scram-tools.file/tools/tensorflow-xla-runtime/tensorflow-xla-runtime.xml @@ -2,7 +2,6 @@ - From c2096d0274a8bd296393c2fdefe192a37237d48b Mon Sep 17 00:00:00 2001 From: Marcel Rieger Date: Wed, 13 Mar 2024 18:13:44 +0100 Subject: [PATCH 7/7] Remove tensorflow-xla-runtime from vectorization file. --- cmssw-vectorization.file | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmssw-vectorization.file b/cmssw-vectorization.file index 32755d1d354..11215188d2e 100644 --- a/cmssw-vectorization.file +++ b/cmssw-vectorization.file @@ -1,2 +1,2 @@ -%define vectorized_packages zlib fastjet tensorflow-sources tensorflow tensorflow-xla-runtime OpenBLAS rivet gbl lwtnn opencv pytorch +%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)}