代码拉取完成,页面将自动刷新
%global anolis_version 6
%global debug_package %{nil}
Name: pytorch
Version: 1.10.1
Release: %{anolis_version}%{?dist}
Summary: PyTorch Neural Network Package
License: BSD
# git clone no-recursive (avoid thirdparty)
URL: https://github.com/pytorch/pytorch
Source0: pytorch.tar.gz
Patch1: pytorch-C.patch
Patch2: pytorch-onednn.patch
BuildRequires: doxygen gcc-c++
BuildRequires: python3-typing-extensions python3-pyyaml python3-setuptools onnx-optimizer-devel
BuildRequires: xnnpack-devel sleef-devel onednn-devel nnpack-devel tbb-devel foxi-devel qnnpack-devel
BuildRequires: mesa-libGLU-devel ocl-icd-devel libuv-devel cpuinfo-devel gemmlowp-devel rdma-core-devel
BuildRequires: hiredis-devel snappy-devel openblas-devel libzstd-devel leveldb-devel lmdb-devel ideep-devel psimd-devel
BuildRequires: pybind11-devel >= 2.7.0 python3-devel peachpy-python3 python3-pybind11 python3-six python3-numpy >= 1:1.19.4 nnpack-devel fmt-devel
BuildRequires: gmp-devel mpfr-devel miniz-devel eigen3-devel >= 3.3.9 onnx-devel neon2sse-devel tensorpipe-devel fp16-devel fxdiv-devel
BuildRequires: zeromq-devel numactl-devel glog-devel gflags-devel openblas-openmp protobuf-devel protobuf-compiler pthreadpool-devel
BuildRequires: fftw-devel
BuildRequires: qt5-qtbase-gui qt5-qtbase qt5-qtbase-common
Requires: python3-numpy >= 1:1.19.4
%if 0%{?fedora} >= 30
BuildRequires: rocksdb-devel
%endif
%if 0%{?rhel}
BuildRequires: python3-dataclasses
%endif
%ifarch x86_64
BuildRequires: fbgemm-devel
%endif
%global have_cuda 0
%global have_tensorrt 0
%global vcu_maj 11
%global vcu_min 5
%global gpu_target_arch "3.5+PTX 6.1"
# % global gpu_target_arch "3.5+PTX;5.2;6.1;7.5;8.6"
# % undefine _hardened_build
# % undefine _annotated_build
# % undefine _strict_symbol_defs_build
%global _lto_cflags %{nil}
%global __cmake_in_source_build 1
%undefine _missing_build_ids_terminate_build
%bcond_without cuda
%if %{without cuda}
%global have_cuda 0
%endif
%if %{have_cuda}
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-nvprof-%{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
BuildRequires: gloo-devel
BuildRequires: magma-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
%description
PyTorch is a python package that provides two high-level
features for Torch.
%package devel
Summary: Development files for pytorch
Requires: %{name} = %{version}-%{release}
%description devel
This package contains development files for pythorch.
%package python3
Summary: Python files for pytorch
Provides: python%{python3_version}dist(torch) = %{version}
Requires: %{name} = %{version}-%{release}
%description python3
This package contains python files for pythorch.
%prep
%setup -q
%patch1 -p0 -b .python
%patch2 -p1 -b .dnnl
%build
# use pure external
# already all empty
#rm -rf third_party
%if %{have_cuda}
# external fbgemm dnnl qnnpack gloo
sed -i -e 's|torch_cpu PUBLIC c10|torch_cpu PUBLIC c10 dnnl qnnpack gloo gloo_cuda|' caffe2/CMakeLists.txt
%endif
# external pybind11
#sed -i -e 's|find_package(pybind11 CONFIG)|find_package(pybind11 CONFIG REQUIRED)|g' cmake/Dependencies.cmake
sed -i -e 's|USE_SYSTEM_BIND11|USE_SYSTEM_PYBIND11|g' cmake/Dependencies.cmake
# external mkl-dnn
rm -rf cmake/Modules/FindMKLDNN.cmake
echo 'set(DNNL_USE_NATIVE_ARCH ${USE_NATIVE_ARCH})' > cmake/public/mkldnn.cmake
echo 'set(CAFFE2_USE_MKLDNN ON)' >> cmake/public/mkldnn.cmake
echo 'find_package(DNNL REQUIRED)' >> cmake/public/mkldnn.cmake
echo 'set(MKLDNN_FOUND ON)' >> cmake/public/mkldnn.cmake
echo 'link_directories("/usr/lib64")' >> cmake/public/mkldnn.cmake
echo 'link_libraries("/usr/lib64/libdnnl.so.2")' >> cmake/public/mkldnn.cmake
sed -i -e '/Caffe2_PUBLIC_DEPENDENCY_LIBS caffe2::mkldnn/d' cmake/Dependencies.cmake
# external pthreadpool
rm -rf third_party/pthreadpool/*
touch third_party/pthreadpool/CMakeLists.txt
# openblas openmp first
sed -i -e 's|NAMES openblas|NAMES openblaso openblas|' cmake/Modules/FindOpenBLAS.cmake
# use external zstd
sed -i -e 's|USE_ZSTD|NOT_USE_ZSTD|g' cmake/Dependencies.cmake
sed -i -e 's|add_subdirectory(zstd)|list(APPEND Caffe2_PUBLIC_DEPENDENCY_LIBS zstd)|g' caffe2/share/contrib/CMakeLists.txt
# use external onnx
sed -i -e 's|Caffe2_DEPENDENCY_LIBS onnx_proto onnx|Caffe2_DEPENDENCY_LIBS onnx_proto onnx onnx_optimizer|' cmake/Dependencies.cmake
#sed -i -e 's|onnx_c2|onnx|' CMakeLists.txt
#sed -i -e 's|onnx_torch|onnx|' CMakeLists.txt
#sed -i -e 's|add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../third_party/onnx EXCLUDE_FROM_ALL)|find_package(ONNX REQUIRED)\nfind_package(ONNXOptimizer REQUIRED)|' cmake/Dependencies.cmake
#sed -i -e '/target_compile_options(onnx/d' cmake/Dependencies.cmake
# external tensorpipe
mkdir -p third_party/tensorpipe
echo '' >> third_party/tensorpipe/CMakeLists.txt
sed -i '/add_dependencies(tensorpipe_agent tensorpipe)/d' caffe2/CMakeLists.txt
# external nnpack
echo '' > cmake/External/nnpack.cmake
echo 'set(NNPACK_FOUND TRUE)' >> cmake/External/nnpack.cmake
# external cpuinfo
sed -i '/TARGET cpuinfo PROPERTY/d' cmake/Dependencies.cmake
# external fp16
sed -i '/APPEND Caffe2_DEPENDENCY_LIBS fp16/d' cmake/Dependencies.cmake
# external qnnpack
mkdir -p third_party/QNNPACK
echo '' >> third_party/QNNPACK/CMakeLists.txt
sed -i '/TARGET qnnpack PROPERTY/d' cmake/Dependencies.cmake
sed -i -e '/target_compile_options(qnnpack/d' cmake/Dependencies.cmake
# external psimd
mkdir -p third_party/psimd
echo '' >> third_party/psimd/CMakeLists.txt
sed -i '/pytorch_qnnpack PRIVATE psimd/d' aten/src/ATen/native/quantized/cpu/qnnpack/CMakeLists.txt
# external fxdiv
sed -i '/NOT TARGET fxdiv/,/endif/d' caffe2/CMakeLists.txt
#mkdir -p third_party/FXdiv
#echo '' > third_party/FXdiv/CMakeLists.txt
sed -i '/torch_cpu PRIVATE fxdiv/d' caffe2/CMakeLists.txt
sed -i '/pytorch_qnnpack PRIVATE fxdiv/d' aten/src/ATen/native/quantized/cpu/qnnpack/CMakeLists.txt
# external fbgemm
mkdir -p third_party/fbgemm
echo '' > third_party/fbgemm/CMakeLists.txt
sed -i '/(TARGET fbgemm/d' cmake/Dependencies.cmake
sed -i 's|caffe2_fakelowp_ops fbgemm cpuinfo|caffe2_fakelowp_ops|' caffe2/contrib/fakelowp/CMakeLists.txt
sed -i 's|caffe2_dnnlowp_avx2_ops fbgemm|caffe2_dnnlowp_avx2_ops|' caffe2/quantization/server/CMakeLists.txt
# external foxi
mkdir -p third_party/foxi
echo '' > third_party/foxi/CMakeLists.txt
# external gloo
#sed -i '/c10d gloo/d' torch/lib/c10d/CMakeLists.txt
# external fmt
mkdir -p third_party/fmt
echo 'find_package(fmt REQUIRED)' > third_party/fmt/CMakeLists.txt
echo 'add_library(libfmt INTERFACE)' >> third_party/fmt/CMakeLists.txt
echo 'add_library(fmt::fmt-header-only ALIAS libfmt)' >> third_party/fmt/CMakeLists.txt
echo 'target_link_libraries(libfmt INTERFACE fmt)' >> third_party/fmt/CMakeLists.txt
sed -i '/fmt-header-only PROPERTIES/d' cmake/Dependencies.cmake
# external miniz
#sed -i '/miniz.c/d' caffe2/serialize/CMakeLists.txt
# external tbb
#sed -i '/^if(TBB_BUILD/,/^endif()/d' aten/src/ATen/cpu/tbb/CMakeLists.txt
# external tensorrt
mkdir -p third_party/onnx-tensorrt
echo '' > third_party/onnx-tensorrt/CMakeLists.txt
sed -i '/nvonnxparser_static/d' cmake/Dependencies.cmake
sed -i 's|onnx_trt_library|nvonnxparser_static|g' cmake/Dependencies.cmake
# no cmake cuda locals
mv -f cmake/Modules_CUDA_fix/FindCUDNN.cmake cmake/Modules
rm -rf cmake/Modules_CUDA_fix
find . -type d -name "FindCUDA" -exec rm -rf {} \;
sed -i -e '/install/{:a;/COMPONENT/bb;N;ba;:b;/Modules_CUDA_fix/d;}' CMakeLists.txt
# disable AVX2
#sed -i -e 's|AVX2_FOUND|AVX2_NONE_FOUND|g' cmake/Codegen.cmake
# rocksdb shared
sed -i 's|RocksDB::rocksdb|RocksDB::rocksdb-shared|' modules/rocksdb/CMakeLists.txt
# remove export deps
sed -i '/install(EXPORT Caffe2Targets/,/dev)/d' CMakeLists.txt
mkdir build
pushd build
export ONNX_ML=0
export BUILD_SPLIT_CUDA=ON
export REL_WITH_DEB_INFO=1
export PYTHON_EXECUTABLE="%{__python3}"
export CFLAGS="%{optflags} -Wno-sign-compare -Wno-deprecated-declarations -Wno-nonnull -DEIGEN_HAS_CXX11_MATH=1 -fpermissive"
export CXXFLAGS=$CFLAGS
# -DUSE_NATIVE_ARCH=ON
export LD_LIBRARY_PATH="/usr/local/cuda-%{vcu_maj}.%{vcu_min}/%{_lib}/"
%cmake .. -Wno-dev \
-DCMAKE_SKIP_RPATH=ON \
-DCMAKE_VERBOSE_MAKEFILE=OFF \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_SKIP_RULE_DEPENDENCY=ON \
-DCMAKE_SUPPRESS_REGENERATION=ON \
-DUSE_CCACHE=OFF \
-DHAVE_SOVERSION=ON \
-DUSE_NATIVE_ARCH=OFF \
-DUSE_DISTRIBUTED=ON \
-DBUILD_DOCS=OFF \
-DBUILD_PYTHON=ON \
-DBUILD_CAFFE2=ON \
-DBUILD_BINARY=OFF \
-DBUILD_BENCHMARK=OFF \
-DBUILD_CUSTOM_PROTOBUF=OFF \
-DBUILDING_WITH_TORCH_LIBS=ON \
-DPYTHON_EXECUTABLE="%{__python3}" \
-DPYBIND11_PYTHON_VERSION="%{python3_version}" \
-DCAFFE2_LINK_LOCAL_PROTOBUF=OFF \
-DONNX_ML=OFF \
-DUSE_GLOG=ON \
-DUSE_GFLAGS=ON \
-DUSE_OPENMP=ON \
-DUSE_KINETO=OFF \
-DUSE_BREAKPAD=OFF \
-DUSE_SYSTEM_ONNX=ON \
-DUSE_SYSTEM_PYBIND11=ON \
-DUSE_SYSTEM_EIGEN_INSTALL=ON \
%if %{have_cuda}
-DUSE_SYSTEM_GLOO=ON \
-DUSE_GLOO=ON \
-DUSE_CUDA=ON \
-DUSE_CUDNN=ON \
-DUSE_NVRTC=ON \
-DUSE_CUPTI_SO=ON \
-DUSE_FAST_NVCC=ON \
-DUSE_SYSTEM_NCCL=ON \
-DCMAKE_CUDA_FLAGS="-fPIC" \
-DCUDA_PROPAGATE_HOST_FLAGS=OFF \
-DTORCH_CUDA_ARCH_LIST=%{gpu_target_arch} \
-DCMAKE_CUDA_COMPILER="/usr/local/cuda-%{vcu_maj}.%{vcu_min}/bin/nvcc" \
-DNCCL_INCLUDE_DIR="%{_includedir}/nccl" \
-DUSE_MAGMA=ON \
-DBUILD_SPLIT_CUDA=ON \
%if %{have_tensorrt}
-DUSE_TENSORRT=ON \
%else
-DUSE_TENSORRT=OFF \
%endif
%endif
-DBLAS="OpenBLAS" \
-DUSE_MPI=OFF \
-DUSE_OBSERVERS=OFF \
-DUSE_ASAN=OFF \
-DUSE_ROCM=OFF \
-DUSE_MKLDNN=ON \
-DUSE_NCCL=OFF \
-DUSE_GLOO=OFF \
-DUSE_CUDA=OFF \
%ifarch x86_64
-DUSE_FBGEMM=ON \
%else
-DUSE_FBGEMM=OFF \
%endif
-DUSE_NNPACK=ON \
-DUSE_QNNPACK=ON \
-DUSE_PYTORCH_QNNPACK=ON \
-DUSE_SYSTEM_FP16=ON \
-DUSE_SYSTEM_PSIMD=ON \
-DUSE_SYSTEM_SLEEF=ON \
-DUSE_SYSTEM_FXDIV=ON \
-DUSE_SYSTEM_XNNPACK=ON \
-DUSE_SYSTEM_CPUINFO=ON \
-DUSE_SYSTEM_PTHREADPOOL=ON \
-DUSE_TENSORPIPE=ON \
-DUSE_FAKELOWP=OFF \
-DUSE_OPENCL=OFF \
-DUSE_ZMQ=ON \
-DUSE_ZSTD=ON \
-DUSE_LMDB=ON \
-DUSE_REDIS=ON \
-DUSE_LEVELDB=ON \
%if 0%{?fedora} >= 30
-DUSE_ROCKSDB=ON \
%else
-DUSE_ROCKSDB=OFF \
%endif
-DUSE_FFMPEG=OFF \
-DUSE_OPENCV=OFF \
-DUSE_METAL=OFF \
-DUSE_TBB=OFF \
-DUSE_LLVM=OFF \
-DATEN_NO_TEST=ON
make %{?_smp_mflags}
popd
%install
rm -rf %{buildroot}
#
# install libraries
#
pushd build
export PYTHON_EXECUTABLE="%{__python3}"
make install DESTDIR=%{buildroot}
mkdir -p %{buildroot}%{_libdir}
find %{buildroot}/ -name "*.a" -type f -prune -exec rm -rf '{}' '+'
rm -rf %{buildroot}/usr/lib/python*
mv -f %{buildroot}/usr/lib/* %{buildroot}%{_libdir}/
popd
install -D -pm 755 build/lib/libnnapi_backend.so %{buildroot}/%{_libdir}/
mkdir -p %{buildroot}/%{python3_sitearch}/torch/bin
install -D -pm 644 build/lib/_C.so %{buildroot}/%{python3_sitearch}/torch/
install -D -pm 644 build/lib/_dl.so %{buildroot}/%{python3_sitearch}/torch/
#install -D -pm 644 aten/src/THC/THCDeviceUtils.cuh %{buildroot}/%{_includedir}/THC/
# symlinks
ln -sf %{_includedir} %{buildroot}/%{python3_sitearch}/torch/include
ln -sf %{_libdir} %{buildroot}/%{python3_sitearch}/torch/lib
ln -sf %{_bindir}/torch_shm_manager %{buildroot}/%{python3_sitearch}/torch/bin/torch_shm_manager
#
# install python bits
#
# caffe2
pushd build
for f in `find . -name '*.py' | grep -v experiments | grep -v third_party | grep -v _test.py | grep -v docs | grep -v examples`;
do
install -D -pm 644 $f %{buildroot}/%{python3_sitearch}/$f
done
popd
# torch
for f in `find ./torch/ -name '*.py'`;
do
install -D -pm 644 $f %{buildroot}/%{python3_sitearch}/$f
done
# version.py
cuver=$(/usr/local/cuda/bin/nvcc --version | grep release | cut -d',' -f2 | awk '{print $2}')
echo '__version__ = "%{version}"' > %{buildroot}/%{python3_sitearch}/torch/version.py
echo 'debug = False' >> %{buildroot}/%{python3_sitearch}/torch/version.py
echo "cuda = \"$cuver\"" >> %{buildroot}/%{python3_sitearch}/torch/version.py
echo 'hip = None' >> %{buildroot}/%{python3_sitearch}/torch/version.py
# remove junk
rm -rf %{buildroot}/%{_includedir}/clog.h
%files
#%doc README.md CONTRIBUTING.md
#%license LICENSE
%{_bindir}/*
%{_libdir}/libshm.so.*
%{_libdir}/libc10.so.*
%if %{have_cuda}
%{_libdir}/libc10_cuda.so
%endif
%{_libdir}/libtorch.so.*
%{_libdir}/libtorch_cpu.so.*
%if %{have_cuda}
%{_libdir}/libtorch_cuda.so
%endif
%{_libdir}/libtorch_global_deps.so.*
#%{_libdir}/libcaffe2_rocksdb.so
%{_libdir}/libcaffe2_observers.so.*
%if %{have_cuda}
%{_libdir}/libcaffe2_detectron_ops_gpu.so
%{_libdir}/libcaffe2_nvrtc.so
%{_libdir}/libtorch_cuda_cpp.so
%{_libdir}/libtorch_cuda_cu.so
%endif
%{_libdir}/libnnapi_backend.so
/usr/lib64/libcaffe2_detectron_ops.so*
%{_libdir}/libshm.so
%{_libdir}/libc10.so
%{_libdir}/libtorch.so
%{_libdir}/libtorch_cpu.so
%{_libdir}/libtorch_global_deps.so
%{_libdir}/libcaffe2_observers.so
%files devel
%exclude %{_includedir}/THCUNN/generic/THCUNN.h
%{_includedir}/*
%{_datadir}/*
%files python3
%{python3_sitearch}/*
%{_libdir}/libtorch_python.so*
%changelog
* Wed Jun 14 2023 forrest_ly <flin@linux.alibaba.com> - 1.10.1-6
- Rebuild for Anolis OS 8.8 to avoid opencv & protobuf conflict
* Tue Jun 7 2022 forrest_ly <flin@linux.alibaba.com> - 1.10.1-5
- Min adjust
* Wed Jun 1 2022 forrest_ly <flin@linux.alibaba.com> - 1.10.1-4
- Rebuild for Anolis OS 8.6
* Tue May 31 2022 forrest_ly <flin@linux.alibaba.com> - 1.10.1-3
- Fix deps numpy version
* Tue Jan 11 2022 Forrestly <fin@linux.alibaba.com> - 1.10.1-2
- Compat for Anolis OS 8 build
* Thu Jan 6 2022 Forrestly <fin@linux.alibaba.com> - 1.10.1-1
- Update to 10.0.1
* Fri Dec 31 2021 Forrestly <fin@linux.alibaba.com> - 1.10.0-1
- Disable cuda
- Compat for Anolis OS 8
* Sun Apr 07 2019 Balint Cristian <cristian.balint@gmail.com>
- github build
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。