%global lockver 1 %global pkgvers 0 %global scdate0 20221115 %global schash0 1b8f5c396f0c016ebe81fe1af029e6f205c926a4 %global branch0 r2.8 %global source0 https://github.com/tensorflow/tensorflow.git %global sshort0 %{expand:%%{lua:print(('%{schash0}'):sub(1,8))}} %global ssvers0 %{expand:%%{lua:print(('%{branch0}'):sub(2,-1))}} %global vcu_maj 11 %global vcu_min 8 %define ext_flatbuf 1 %define ext_protbuf 1 %define ext_grpcdev 1 Name: tensorflow-%{ssvers0} Version: %(curl -s "https://raw.githubusercontent.com/tensorflow/tensorflow/%{schash0}/tensorflow/tensorflow.bzl" | grep "VERSION =" | cut -d'"' -f2) Release: %{scdate0}.%{pkgvers}.git%{sshort0}.cu%{vcu_maj}_%{vcu_min}%{?dist} Summary: Tensorflow Neural Network Package License: BSD URL: https://www.tensorflow.org ExclusiveArch: x86_64 aarch64 ppc64le BuildRequires: gcc-c++ git unzip curl bazel5 python3 python3-devel python3-setuptools BuildRequires: libicu-devel pcre-devel libjpeg-turbo-devel libpng-devel giflib-devel BuildRequires: sqlite-devel double-conversion-devel libcurl-devel lmdb-devel BuildRequires: python3dist(cython) python3dist(wheel) python3dist(wrapt) >= 1.11.0 python3dist(six) >= 1.12.0 BuildRequires: python3dist(packaging) python3dist(requests) python3dist(typing-extensions) >= 3.6.6 python3dist(numpy) >= 1.20 BuildRequires: python3dist(opt-einsum) >= 2.3.2 python3dist(dill) python3dist(gast) >= 0.2.1 python3dist(absl-py) >= 0.4.0 BuildRequires: python3dist(astor) python3dist(keras-preprocessing) >= 1.1.1 python3dist(astunparse) >= 1.6.0 BuildRequires: python3dist(flatbuffers) >= 1.12 python3dist(protobuf) < 3.20 python3dist(protobuf) >= 3.9.2 #BuildRequires: re2-devel snappy-devel %if 0%{?rhel} == 8 BuildRequires: python3dist(dataclasses) Requires: python3dist(dataclasses) %endif %if ! (0%{?rhel} == 9) BuildRequires: python3dist(tblib) Requires: python3dist(tblib) %endif %if %{ext_flatbuf} BuildRequires: flatbuffers-devel >= 1.12 /usr/bin/flatc %endif %if %{ext_protbuf} BuildRequires: protobuf-devel < 3.20 protobuf-devel >= 3.9.2 %endif %if %{ext_grpcdev} BuildRequires: grpc < 2.0 grpc >= 1.24.3 grpc-plugins grpc-devel %if ! 0%{?rhel} == 8 BuildRequires: grpc-cpp %endif %endif Requires: python3dist(numpy) >= 1.20 python3dist(packaging) python3dist(requests) python3dist(termcolor) >= 1.1 Requires: python3dist(six) >= 1.12.0 python3dist(typing-extensions) >= 3.6.6 python3dist(astor) python3dist(wrapt) >= 1.11.0 Requires: python3dist(astunparse) >= 1.6.0 python3dist(gast) >= 0.2.1 python3dist(flatbuffers) >= 1.12 python3dist(h5py) >= 2.9.0 Requires: python3dist(protobuf) < 3.20 python3dist(protobuf) >= 3.9.2 python3dist(grpcio) < 2.0 python3dist(grpcio) >= 1.24.3 Requires: python3dist(opt-einsum) >= 2.3.2 python3dist(dill) python3dist(keras-preprocessing) >= 1.1.1 python3dist(absl-py) >= 0.4.0 Requires: python3dist(google-pasta) >= 0.1.1 Recommends: keras-2.8 Recommends: tensorboard-2.8 Recommends: tensorflow-estimator-2.8 Recommends: python3dist(tensorflow-io-gcs-filesystem) >= 0.23.1 Recommends: python3dist(libclang) >= 9.0.1 %define have_cuda 1 %define have_tensorrt 0 %define have_cuda_gcc 1 %define gpu_target_arch "6.1,3.5" %bcond_without cuda %if %{without cuda} %define have_cuda 0 %endif %if %{have_cuda} %if %{have_cuda_gcc} %if (0%{?fedora} > 34) || (0%{?rhel} > 8) BuildRequires: cuda-gcc-c++ %endif %endif BuildRequires: cuda-nvcc-%{vcu_maj}-%{vcu_min} BuildRequires: cuda-nvtx-%{vcu_maj}-%{vcu_min} BuildRequires: cuda-cudart-devel-%{vcu_maj}-%{vcu_min} BuildRequires: cuda-nvml-devel-%{vcu_maj}-%{vcu_min} BuildRequires: cuda-nvrtc-devel-%{vcu_maj}-%{vcu_min} BuildRequires: cuda-driver-devel-%{vcu_maj}-%{vcu_min} BuildRequires: cuda-profiler-api-%{vcu_maj}-%{vcu_min} BuildRequires: cuda-nvprune-%{vcu_maj}-%{vcu_min} BuildRequires: cuda-cupti-%{vcu_maj}-%{vcu_min} BuildRequires: libcublas-devel-%{vcu_maj}-%{vcu_min} BuildRequires: libcufft-devel-%{vcu_maj}-%{vcu_min} BuildRequires: libcurand-devel-%{vcu_maj}-%{vcu_min} BuildRequires: libcusparse-devel-%{vcu_maj}-%{vcu_min} BuildRequires: libcusolver-devel-%{vcu_maj}-%{vcu_min} BuildRequires: libnccl-devel BuildRequires: libcudnn8-devel Requires: cuda-cudart-%{vcu_maj}-%{vcu_min} Requires: cuda-nvrtc-%{vcu_maj}-%{vcu_min} Requires: libcublas-%{vcu_maj}-%{vcu_min} Requires: libcufft-%{vcu_maj}-%{vcu_min} Requires: libcurand-%{vcu_maj}-%{vcu_min} Requires: libcusparse-%{vcu_maj}-%{vcu_min} Requires: libcusolver-%{vcu_maj}-%{vcu_min} %endif %if %{have_tensorrt} BuildRequires: libnvinfer-plugin-devel libnvonnxparsers-devel %endif Provides: tensorflow = %{version} %global debug_package %{nil} %global _lto_cflags %{nil} %undefine _hardened_build %undefine _annotated_build %description Open Source Machine Learning Framework for Everyone %package tflite Summary: Libraries for tensoflow lite Requires: %{name} = %{version}-%{release} Provides: tensorflow-tflite = %{version} %description tflite This package contains libraries for tensorflow lite. %package devel Summary: Development files for tensoflow Requires: %{name} = %{version}-%{release} Requires: %{name}-tflite = %{version}-%{release} Provides: tensorflow-devel = %{version} %description devel This package contains development files for tensorflow. %prep %setup -T -c %{name} -n %{name} git clone --depth 1 -n -b %{branch0} %{source0} %{name} git -C %{name} fetch --depth 1 origin %{schash0} git -C %{name} reset --hard %{schash0} git -C %{name} log --format=fuller # % patch3 -p1 -b .proto~ # % patch4 -p1 -b .mlir~ # % patch5 -p1 -b .aarch64~ # % patch6 -p1 -b .ppc64le~ # no cub for cuda >= 11.x find . -name 'BUILD' -exec sed -i '/cub_archive/d' {} + sed -i 's|third_party/cub/|cub/|g' %{name}/tensorflow/core/kernels/gpu_prim.h # cuda libs versioning sed -i '/"cudart": /,/static/s/cuda_config.cuda_version/version = None/g' %{name}/third_party/gpus/cuda_configure.bzl sed -i '/"cusolver": /,/static/s/cuda_config.cusolver_version/version = None/g' %{name}/third_party/gpus/cuda_configure.bzl # python >= 3.10 sed -i 's|from distutils import sysconfig|import sysconfig|' %{name}/third_party/py/python_configure.bzl sed -i 's|print(sysconfig.get_python_inc())|print(sysconfig.get_paths()[\\\"include\\\"])|' %{name}/third_party/py/python_configure.bzl # buildsys python3 shebang sed -i 's|name = "py3_runtime",|name = "py3_runtime",\n stub_shebang = "#!/usr/bin/env python3",|' %{name}/third_party/py/BUILD.tpl # other python3 shebang sed -i 's|python|python3|' %{name}/tensorflow/lite/tools/visualize.py sed -i 's|python|python3|' %{name}/tensorflow/tools/ci_build/builds/check_system_libs.py sed -i 's|python|python3|' %{name}/third_party/gpus/crosstool/clang/bin/crosstool_wrapper_driver_is_not_gcc.tpl sed -i 's|python|python3|' %{name}/third_party/gpus/crosstool/clang/bin/crosstool_wrapper_driver_rocm.tpl sed -i 's|python|python3|' %{name}/third_party/gpus/crosstool/windows/msvc_wrapper_for_nvcc.py.tpl # protobuf missings sed -i 's|-lprotoc|%{_libdir}/libstdc++.so.6 -lprotoc|' %{name}/third_party/systemlibs/protobuf.BUILD sed -i 's|-lprotobuf|%{_libdir}/libstdc++.so.6 -lprotobuf|' %{name}/third_party/systemlibs/protobuf.BUILD # grpc missings sed -i 's|-lgrpc|-Wl,--copy-dt-needed-entries -lgrpc|g' %{name}/third_party/systemlibs/grpc.BUILD # regenerate schema %if %{ext_flatbuf} rm %{name}/tensorflow/lite/schema/schema_generated.h flatc --no-union-value-namespacing --gen-object-api \ -o %{name}/tensorflow/lite/schema \ -c %{name}/tensorflow/lite/schema/schema.fbs rm %{name}/tensorflow/lite/experimental/acceleration/configuration/configuration_generated.h flatc --proto \ -o %{name}/tensorflow/lite/experimental/acceleration/configuration/ \ %{name}/tensorflow/lite/experimental/acceleration/configuration/configuration.proto sed -i 's/tflite.proto/tflite/' %{name}/tensorflow/lite/experimental/acceleration/configuration/configuration.fbs flatc --no-union-value-namespacing --gen-object-api \ -o %{name}/tensorflow/lite/experimental/acceleration/configuration/ \ -c %{name}/tensorflow/lite/experimental/acceleration/configuration/configuration.fbs %endif %build pushd %{name} bazel --version | awk '{print $2}' > .bazelversion echo 'build --host_force_python=PY3' > .tf_configure.bazelrc echo 'build --python_path="%{python3}"' >> .tf_configure.bazelrc echo 'build --action_env PYTHON_BIN_PATH="%{python3}"' >> .tf_configure.bazelrc echo 'build --action_env PYTHON_LIB_PATH="%{python3_sitearch}"' >> .tf_configure.bazelrc echo 'build --action_env TF_CONFIGURE_IOS="0"' >> .tf_configure.bazelrc %if %{have_cuda} echo 'build --action_env CUDA_TOOLKIT_PATH="/usr/local/cuda"' >> .tf_configure.bazelrc echo 'build --action_env TF_CUDA_COMPUTE_CAPABILITIES=%{gpu_target_arch}' >> .tf_configure.bazelrc %if %{have_cuda_gcc} %if (0%{?fedora} > 34) || (0%{?rhel} > 8) echo 'build --action_env GCC_HOST_COMPILER_PATH="%{_bindir}/cuda-gcc"' >> .tf_configure.bazelrc %endif %endif %if %{have_tensorrt} echo 'build --config=tensorrt' >> .tf_configure.bazelrc %endif echo 'build --config=cuda' >> .tf_configure.bazelrc %endif echo 'build --config=xla' >> .tf_configure.bazelrc echo 'build:xla --define with_xla_support=true' >> .tf_configure.bazelrc echo 'build:opt --define with_default_optimizations=true' >> .tf_configure.bazelrc echo 'build:opt --copt=-Wno-sign-compare --copt=-fPIC' >> .tf_configure.bazelrc echo 'build:opt --cxxopt=-Wno-sign-compare --cxxopt=-fPIC' >> .tf_configure.bazelrc %ifarch x86_64 echo 'build:opt --copt=-mtune=generic' >> .tf_configure.bazelrc echo 'build:opt --cxxopt=-mtune=generic' >> .tf_configure.bazelrc echo 'build:opt --host_copt=-mtune=generic' >> .tf_configure.bazelrc echo 'build:opt --host_cxxopt=-mtune=generic' >> .tf_configure.bazelrc %endif %ifarch ppc64le echo 'build:opt --define tflite_with_xnnpack=flase' >> .tf_configure.bazelrc echo 'build:opt --copt=-mcpu=power8 --copt=-mtune=power8' >> .tf_configure.bazelrc echo 'build:opt --cxxopt=-mcpu=power8 --cxxopt=-mtune=power8' >> .tf_configure.bazelrc echo 'build:opt --host_copt=-mcpu=power8 --host_copt=-mtune=power8' >> .tf_configure.bazelrc echo 'build:opt --host_cxxopt=-mcpu=power8 --host_cxxopt=-mtune=power8' >> .tf_configure.bazelrc %endif echo 'test --flaky_test_attempts=3' >> .tf_configure.bazelrc echo 'test --test_size_filters=small,medium' >> .tf_configure.bazelrc echo 'test:v1 --test_tag_filters=-benchmark-test,-no_oss,-gpu,-oss_serial' >> .tf_configure.bazelrc echo 'test:v1 --build_tag_filters=-benchmark-test,-no_oss,-gpu' >> .tf_configure.bazelrc echo 'test:v2 --test_tag_filters=-benchmark-test,-no_oss,-gpu,-oss_serial,-v1only' >> .tf_configure.bazelrc echo 'test:v2 --build_tag_filters=-benchmark-test,-no_oss,-gpu,-v1only' >> .tf_configure.bazelrc # system libs export LOCAL_LIBS="curl,zlib,gif,png,libjpeg_turbo,lmdb,icu,org_sqlite,cython,six_archive,org_sqlite,double_conversion,typing_extensions_archive,astor_archive,wrapt,astunparse_archive,opt_einsum_archive,absl_py,dill_archive,gast_archive" #export LOCAL_LIBS="$LOCAL_LIBS,llvm-project,flatbuffers,com_google_absl,com_googlesource_code_re2,snappy,com_github_grpc_grpc,com_google_protobuf" %if %{ext_flatbuf} export LOCAL_LIBS="$LOCAL_LIBS,flatbuffers" %endif %if %{ext_protbuf} export LOCAL_LIBS="$LOCAL_LIBS,com_google_protobuf" %endif %if %{ext_grpcdev} export LOCAL_LIBS="$LOCAL_LIBS,com_github_grpc_grpc" %endif %if ! (0%{?rhel} == 9) export LOCAL_LIBS="$LOCAL_LIBS,tblib_archive" %endif export TMP=/tmp export TF_NEED_AWS=0 export TF_SYSTEM_LIBS=$LOCAL_LIBS export TF_IGNORE_MAX_BAZEL_VERSION=1 export TEST_TMPDIR="%{_builddir}/%{name}" export LD_LIBRARY_PATH="/usr/local/cuda-%{vcu_maj}.%{vcu_min}/%{_lib}/" bazel build \ --config=opt \ --config=v2 \ --config=cuda \ --config=noaws \ --config=nohdfs \ --define=no_tensorflow_py_deps=true \ --action_env TF_SYSTEM_LIBS=$LOCAL_LIBS \ --subcommands \ --explain=build.log \ --show_result=2147483647 \ --local_ram_resources=32768 \ --jobs 16 \ --verbose_failures \ --incompatible_use_python_toolchains \ //tensorflow/tools/pip_package:build_pip_package bazel build \ --config=opt \ --config=v2 \ --config=cuda \ --config=noaws \ --config=nohdfs \ --define=no_tensorflow_py_deps=true \ --action_env TF_SYSTEM_LIBS=$LOCAL_LIBS \ --subcommands \ --explain=build-tflite.log \ --show_result=2147483647 \ --local_ram_resources=32768 \ --jobs 16 \ --verbose_failures \ //tensorflow/lite:libtensorflowlite.so bazel build \ --config=opt \ --config=v2 \ --config=cuda \ --config=noaws \ --config=nohdfs \ --define=no_tensorflow_py_deps=true \ --action_env TF_SYSTEM_LIBS=$LOCAL_LIBS \ --subcommands \ --explain=build-tflite_c.log \ --show_result=2147483647 \ --local_ram_resources=32768 \ --jobs 16 \ --verbose_failures \ //tensorflow/lite/c:libtensorflowlite_c.so popd %install pushd %{name} export PYTHON_BIN_PATH=%{python3} export LD_LIBRARY_PATH="/usr/local/cuda-%{vcu_maj}.%{vcu_min}/%{_lib}/" bash ./bazel-bin/tensorflow/tools/pip_package/build_pip_package %{buildroot}/%{python3_sitearch}/ unzip %{buildroot}/%{python3_sitearch}/*.whl -d %{buildroot}/%{python3_sitearch}/ rm -rf %{buildroot}/%{python3_sitearch}/*.whl rm -rf %{buildroot}/%{python3_sitearch}/*.data # remove weak depends sed -i '/Requires-Dist: /d' %{buildroot}/%{python3_sitearch}/*.dist-info/METADATA # fix chmod find %{buildroot}/%{python3_sitearch}/ -type f -exec chmod 644 {} \; # strip libraries find %{buildroot}/%{python3_sitearch}/ -name "*.so*" -exec strip {} \; find %{buildroot}/%{python3_sitearch}/ -name "*.so*" -exec chmod 755 {} \; mv -f %{buildroot}/%{python3_sitearch}/tensorflow/libtensorflow_framework.so.2 \ %{buildroot}/%{_libdir}/libtensorflow_framework.so.2 ln -sf %{_libdir}/libtensorflow_framework.so.2 \ %{buildroot}/%{python3_sitearch}/tensorflow/libtensorflow_framework.so.2 ln -sf %{_libdir}/libtensorflow_framework.so.2 \ %{buildroot}/%{_libdir}/libtensorflow_framework.so \ # tflite install -m755 bazel-bin/tensorflow/lite/libtensorflowlite.so %{buildroot}/%{_libdir}/ install -m755 bazel-bin/tensorflow/lite/c/libtensorflowlite_c.so %{buildroot}/%{_libdir}/ # include dirs mkdir -p %{buildroot}/%{_includedir} ln -sf %{python3_sitearch}/tensorflow/include/tensorflow \ %{buildroot}/%{_includedir}/tensorflow # tflite additional headers for f in `find tensorflow/lite/ -name '*.h'` do install -D -pm 644 $f %{buildroot}/%{python3_sitearch}/tensorflow/include/$f done # clean external includes for d in `ls %{buildroot}/%{python3_sitearch}/tensorflow/include/ | grep -v tensorflow` do rm -rf %{buildroot}/%{python3_sitearch}/tensorflow/include/$d done popd # cleanup bad ro build rights chmod +w -R %{_builddir}/%{name}/_bazel* %files %license %{name}/LICENSE %doc %{name}/README.md %doc %{name}/CONTRIBUTING.md %exclude %{_libdir}/libtensorflowlite.so %exclude %{_libdir}/libtensorflowlite_c.so %{_libdir}/*.so* %exclude %{python3_sitearch}/tensorflow/include %{python3_sitearch}/* %files tflite %license %{name}/LICENSE %{_libdir}/libtensorflowlite.so %{_libdir}/libtensorflowlite_c.so %files devel %license %{name}/LICENSE %{_includedir}/tensorflow %{python3_sitearch}/tensorflow/include %changelog * Wed Dec 04 2019 Balint Cristian - github upstream releases