From 53dbc56808ca39c0767be25b8f306510ed211bec Mon Sep 17 00:00:00 2001 From: Chunmei Xu Date: Tue, 18 Jul 2023 15:58:41 +0800 Subject: [PATCH 01/23] build with cuda support Signed-off-by: Chunmei Xu --- pytorch.spec | 58 +++++++--------------------------------------------- 1 file changed, 7 insertions(+), 51 deletions(-) diff --git a/pytorch.spec b/pytorch.spec index 3fde779..b9c45b5 100644 --- a/pytorch.spec +++ b/pytorch.spec @@ -18,11 +18,9 @@ License: BSD URL: https://pytorch.org -Source0: pytorch-v2.0.1.tar.gz +Source0: https://github.com/pytorch/pytorch/releases/download/v%{version}/pytorch-v%{version}.tar.gz Patch1: pytorch-C.patch -Patch2: pytorch-gcc11.patch -Patch3: pytorch-quant-cpp.patch Patch4: pytorch-xnnpack.patch Patch5: pytorch-cuda12.patch @@ -71,14 +69,6 @@ BuildRequires: kineto-devel %define gpu_target_arch "6.0 6.1 7.0 7.5 8.0 8.6" -%global _lto_cflags %{nil} -%global debug_package %{nil} -%global __cmake_in_source_build 1 -%undefine _hardened_build -%undefine _annotated_build -%undefine _find_debuginfo_dwz_opts -%undefine _missing_build_ids_terminate_build - %bcond_without cuda %if %{without cuda} %global have_cuda 0 @@ -145,7 +135,7 @@ This package contains development files for pythorch. %package python3 Summary: Python files for pytorch -Provides: python%{python3_version}dist(torch) = %{version} +Provides: python3dist(torch) = %{version} Requires: %{name} = %{version}-%{release} %description python3 @@ -153,25 +143,10 @@ This package contains python files for pythorch. %prep -%setup -n %{name}-v%{version} -%global _default_patch_fuzz 100 -%patch1 -p0 -b .python~ -# % patch2 -p1 -b .gcc11~ -# % patch3 -p1 -b .cpp~ -%patch4 -p1 -b .xnn~ -%patch5 -p1 -b .cu12~ - -# python version -sed -i -e 's|VERSION_LESS 3.10)|VERSION_LESS 3.6)|g' cmake/Dependencies.cmake -sed -i -e 's|PY_MAJOR_VERSION == 3|PY_MAJOR_VERSION == 3 \&\& PY_MINOR_VERSION > 6|' torch/csrc/dynamo/eval_frame.c - -# c++std 17 -sed -i 's|CMAKE_CXX_STANDARD 14|CMAKE_CXX_STANDARD 17|' CMakeLists.txt +%autosetup -n %{name}-v%{version} # external fbgemm qnnpack gloo sed -i -e 's|torch_cpu PUBLIC c10|torch_cpu PUBLIC c10 qnnpack gloo gloo_cuda |' caffe2/CMakeLists.txt -# external pybind11 -sed -i -e 's|USE_SYSTEM_BIND11|USE_SYSTEM_PYBIND11|g' cmake/Dependencies.cmake %if %{use_dnnl} # external mkl-dnn @@ -313,20 +288,8 @@ sed -i '1i #include "stdint.h"' torch/csrc/jit/passes/quantization/quantization_ %build -mkdir build -pushd build -export ONNX_ML=0 -export BUILD_SPLIT_CUDA=ON -export REL_WITH_DEB_INFO=1 -export TORCH_NVCC_FLAGS="-DCUDA_HAS_FP16" -export PYTHON_EXECUTABLE="%{__python3}" -%global build_ldflags %(echo "%{build_ldflags}" -Wl,-lstdc++) -%global optflags %(echo "%{optflags} -w -fpermissive -Wno-sign-compare -Wno-deprecated-declarations -Wno-nonnull -DEIGEN_HAS_CXX11_MATH=1" | sed 's|-g||') -# -DUSE_NATIVE_ARCH=ON -export LDFLAGS="-Wl,-lstdc++" -export CFLAGS="${CFLAGS} -fPIC" export LD_LIBRARY_PATH=/usr/local/cuda-%{vcu_maj}.%{vcu_min}/lib64 -%cmake .. -Wno-dev \ +%cmake -Wno-dev \ -DCMAKE_SKIP_RPATH=ON \ -DCMAKE_VERBOSE_MAKEFILE=OFF \ -DCMAKE_BUILD_TYPE=Release \ @@ -431,19 +394,11 @@ export LD_LIBRARY_PATH=/usr/local/cuda-%{vcu_maj}.%{vcu_min}/lib64 -DUSE_LLVM=OFF \ -DATEN_NO_TEST=ON -make %{?_smp_mflags} -popd +%cmake_build %install - -# -# install libraries -# - -pushd build -export PYTHON_EXECUTABLE="%{__python3}" -make install DESTDIR=%{buildroot} +%cmake_install mkdir -p %{buildroot}%{_libdir} find %{buildroot}/ -name "*.a" -type f -prune -exec rm -rf '{}' '+' @@ -510,6 +465,7 @@ rm -rf %{buildroot}/%{_builddir}/pytorch/nvfuser || true cp -r torch.egg-info %{buildroot}%{python3_sitearch}/ sed -i 's|[<=>].*||g' %{buildroot}%{python3_sitearch}/*.egg-info/requires.txt sed -i '/triton/d' %{buildroot}%{python3_sitearch}/*.egg-info/requires.txt +sed -i '/sympy/d' %{buildroot}%{python3_sitearch}/*.egg-info/requires.txt # strip elf set +x find %{buildroot} -type f -print | LC_ALL=C sort | -- Gitee From 274a0779c987d1db568d6a1505c64018456ab7f9 Mon Sep 17 00:00:00 2001 From: Funda Wang Date: Mon, 24 Jul 2023 22:15:34 +0800 Subject: [PATCH 02/23] use standard macro --- pytorch.spec | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pytorch.spec b/pytorch.spec index b9c45b5..1d64052 100644 --- a/pytorch.spec +++ b/pytorch.spec @@ -145,6 +145,14 @@ This package contains python files for pythorch. %prep %autosetup -n %{name}-v%{version} +# python version +sed -i -e 's|VERSION_LESS 3.10)|VERSION_LESS 3.6)|g' cmake/Dependencies.cmake +sed -i -e 's|PY_MAJOR_VERSION == 3|PY_MAJOR_VERSION == 3 \&\& PY_MINOR_VERSION > 6|' torch/csrc/dynamo/eval_frame.c + +# c++std 17 +sed -i 's|CMAKE_CXX_STANDARD 14|CMAKE_CXX_STANDARD 17|' CMakeLists.txt +>>>>>>> 6199ed8 (use standard macro) + # external fbgemm qnnpack gloo sed -i -e 's|torch_cpu PUBLIC c10|torch_cpu PUBLIC c10 qnnpack gloo gloo_cuda |' caffe2/CMakeLists.txt -- Gitee From 2398df6fdb869439145016aa54ac7a5e66087c66 Mon Sep 17 00:00:00 2001 From: Funda Wang Date: Mon, 24 Jul 2023 22:39:00 +0800 Subject: [PATCH 03/23] drop unused seds --- pytorch.spec | 8 -------- 1 file changed, 8 deletions(-) diff --git a/pytorch.spec b/pytorch.spec index 1d64052..b9c45b5 100644 --- a/pytorch.spec +++ b/pytorch.spec @@ -145,14 +145,6 @@ This package contains python files for pythorch. %prep %autosetup -n %{name}-v%{version} -# python version -sed -i -e 's|VERSION_LESS 3.10)|VERSION_LESS 3.6)|g' cmake/Dependencies.cmake -sed -i -e 's|PY_MAJOR_VERSION == 3|PY_MAJOR_VERSION == 3 \&\& PY_MINOR_VERSION > 6|' torch/csrc/dynamo/eval_frame.c - -# c++std 17 -sed -i 's|CMAKE_CXX_STANDARD 14|CMAKE_CXX_STANDARD 17|' CMakeLists.txt ->>>>>>> 6199ed8 (use standard macro) - # external fbgemm qnnpack gloo sed -i -e 's|torch_cpu PUBLIC c10|torch_cpu PUBLIC c10 qnnpack gloo gloo_cuda |' caffe2/CMakeLists.txt -- Gitee From c4c3b06aae9a9cac89d61cab6e30f783997081f9 Mon Sep 17 00:00:00 2001 From: Funda Wang Date: Thu, 27 Jul 2023 12:15:54 +0800 Subject: [PATCH 04/23] update patch --- pytorch-C.patch | 6 +++--- pytorch.spec | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pytorch-C.patch b/pytorch-C.patch index 26cc029..007c19b 100644 --- a/pytorch-C.patch +++ b/pytorch-C.patch @@ -1,6 +1,6 @@ ---- torch/CMakeLists.txt.python 2022-10-11 18:48:56.534889586 +0300 -+++ torch/CMakeLists.txt 2022-10-11 18:52:32.368263631 +0300 -@@ -279,6 +279,16 @@ +--- pytorch-v2.0.1/torch/CMakeLists.txt.orig 2023-07-27 12:13:45.560954800 +0800 ++++ pytorch-v2.0.1/torch/CMakeLists.txt 2023-07-27 12:14:07.181247700 +0800 +@@ -280,6 +280,16 @@ list(APPEND TORCH_PYTHON_COMPILE_DEFINITIONS USE_NCCL) endif() diff --git a/pytorch.spec b/pytorch.spec index b9c45b5..5767bbe 100644 --- a/pytorch.spec +++ b/pytorch.spec @@ -143,7 +143,7 @@ This package contains python files for pythorch. %prep -%autosetup -n %{name}-v%{version} +%autosetup -n %{name}-v%{version} -p1 # external fbgemm qnnpack gloo sed -i -e 's|torch_cpu PUBLIC c10|torch_cpu PUBLIC c10 qnnpack gloo gloo_cuda |' caffe2/CMakeLists.txt -- Gitee From a75cc341f6b48ab6fc65e1542c266eb44e8e8763 Mon Sep 17 00:00:00 2001 From: Funda Wang Date: Thu, 27 Jul 2023 12:40:24 +0800 Subject: [PATCH 05/23] add fpermissive to aten --- pytorch-fpermissive.patch | 11 +++++++++++ pytorch.spec | 1 + 2 files changed, 12 insertions(+) create mode 100644 pytorch-fpermissive.patch diff --git a/pytorch-fpermissive.patch b/pytorch-fpermissive.patch new file mode 100644 index 0000000..36be623 --- /dev/null +++ b/pytorch-fpermissive.patch @@ -0,0 +1,11 @@ +--- pytorch-v2.0.1/aten/src/ATen/CMakeLists.txt.orig 2023-07-27 12:38:39.551744400 +0800 ++++ pytorch-v2.0.1/aten/src/ATen/CMakeLists.txt 2023-07-27 12:39:04.049216700 +0800 +@@ -6,6 +6,8 @@ + string(APPEND CMAKE_C_FLAGS " -Wno-ignored-qualifiers") + string(APPEND CMAKE_CXX_FLAGS " -Wno-absolute-value") + string(APPEND CMAKE_C_FLAGS " -Wno-absolute-value") ++ string(APPEND CMAKE_CXX_FLAGS " -fpermissive") ++ string(APPEND CMAKE_C_FLAGS " -fpermissive") + endif(NOT MSVC) + + # Can be compiled standalone diff --git a/pytorch.spec b/pytorch.spec index 5767bbe..7a68993 100644 --- a/pytorch.spec +++ b/pytorch.spec @@ -23,6 +23,7 @@ Source0: https://github.com/pytorch/pytorch/releases/download/v%{version} Patch1: pytorch-C.patch Patch4: pytorch-xnnpack.patch Patch5: pytorch-cuda12.patch +Patch6: pytorch-fpermissive.patch BuildRequires: git doxygen python3-devel pybind11-devel BuildRequires: python3-typing-extensions python3-pyyaml python3-setuptools -- Gitee From 4c7240d635ec798be05dd4a25d76bbcf2a7596f9 Mon Sep 17 00:00:00 2001 From: Funda Wang Date: Thu, 27 Jul 2023 12:59:48 +0800 Subject: [PATCH 06/23] update patch --- pytorch-fpermissive.patch | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pytorch-fpermissive.patch b/pytorch-fpermissive.patch index 36be623..db51420 100644 --- a/pytorch-fpermissive.patch +++ b/pytorch-fpermissive.patch @@ -9,3 +9,13 @@ endif(NOT MSVC) # Can be compiled standalone +--- pytorch-v2.0.1/caffe2/CMakeLists.txt.orig 2023-07-27 12:59:02.256060200 +0800 ++++ pytorch-v2.0.1/caffe2/CMakeLists.txt 2023-07-27 12:58:17.570708500 +0800 +@@ -55,6 +55,7 @@ + set(__caffe2_CMAKE_POSITION_INDEPENDENT_CODE ${CMAKE_POSITION_INDEPENDENT_CODE}) + set(CMAKE_POSITION_INDEPENDENT_CODE ON) + add_subdirectory(../aten aten) ++ add_compile_options(-fpermissive) + set(CMAKE_POSITION_INDEPENDENT_CODE ${__caffe2_CMAKE_POSITION_INDEPENDENT_CODE}) + + # Generate the headers wrapped by our operator -- Gitee From 193988560a959ef1431a0b1230a0cad0d79bcfc0 Mon Sep 17 00:00:00 2001 From: Funda Wang Date: Thu, 27 Jul 2023 13:53:19 +0800 Subject: [PATCH 07/23] update libdir --- pytorch-cmake-install-libdir.patch | 22 ++++++++++++++++++++++ pytorch.spec | 4 +--- 2 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 pytorch-cmake-install-libdir.patch diff --git a/pytorch-cmake-install-libdir.patch b/pytorch-cmake-install-libdir.patch new file mode 100644 index 0000000..39e1a8f --- /dev/null +++ b/pytorch-cmake-install-libdir.patch @@ -0,0 +1,22 @@ +--- pytorch-v2.0.1/torch/CMakeLists.txt.orig 2023-07-27 13:49:26.417947700 +0800 ++++ pytorch-v2.0.1/torch/CMakeLists.txt 2023-07-27 13:49:50.246620800 +0800 +@@ -21,7 +21,7 @@ + set(TORCH_ROOT "${TORCH_SRC_DIR}/..") + + if(NOT TORCH_INSTALL_LIB_DIR) +- set(TORCH_INSTALL_LIB_DIR lib) ++ set(TORCH_INSTALL_LIB_DIR ${CMAKE_INSTALL_LIBDIR}) + endif() + + if(MSVC) +--- pytorch-v2.0.1/caffe2/CMakeLists.txt.orig 2023-07-27 13:50:02.831645200 +0800 ++++ pytorch-v2.0.1/caffe2/CMakeLists.txt 2023-07-27 13:50:58.182653500 +0800 +@@ -318,7 +318,7 @@ + endif() + + if(NOT TORCH_INSTALL_LIB_DIR) +- set(TORCH_INSTALL_LIB_DIR lib) ++ set(TORCH_INSTALL_LIB_DIR ${CMAKE_INSTALL_LIBDIR}) + endif() + + set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) diff --git a/pytorch.spec b/pytorch.spec index 7a68993..3dcece5 100644 --- a/pytorch.spec +++ b/pytorch.spec @@ -24,6 +24,7 @@ Patch1: pytorch-C.patch Patch4: pytorch-xnnpack.patch Patch5: pytorch-cuda12.patch Patch6: pytorch-fpermissive.patch +Patch7: pytorch-cmake-install-libdir.patch BuildRequires: git doxygen python3-devel pybind11-devel BuildRequires: python3-typing-extensions python3-pyyaml python3-setuptools @@ -401,11 +402,8 @@ export LD_LIBRARY_PATH=/usr/local/cuda-%{vcu_maj}.%{vcu_min}/lib64 %install %cmake_install -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 -- Gitee From 78419731c3ded6a6eaa492227088c48af22bf156 Mon Sep 17 00:00:00 2001 From: Funda Wang Date: Thu, 27 Jul 2023 14:07:57 +0800 Subject: [PATCH 08/23] more cmake-install-path patch --- pytorch-cmake-install-libdir.patch | 40 ++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/pytorch-cmake-install-libdir.patch b/pytorch-cmake-install-libdir.patch index 39e1a8f..f10b7ec 100644 --- a/pytorch-cmake-install-libdir.patch +++ b/pytorch-cmake-install-libdir.patch @@ -20,3 +20,43 @@ endif() set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) +--- pytorch-v2.0.1/c10/CMakeLists.txt.orig 2023-07-27 14:02:55.832015900 +0800 ++++ pytorch-v2.0.1/c10/CMakeLists.txt 2023-07-27 14:03:18.373138200 +0800 +@@ -113,7 +113,7 @@ + # Note: for now, we will put all export path into one single Caffe2Targets group + # to deal with the cmake deployment need. Inside the Caffe2Targets set, the + # individual libraries like libc10.so and libcaffe2.so are still self-contained. +-install(TARGETS c10 EXPORT Caffe2Targets DESTINATION lib) ++install(TARGETS c10 EXPORT Caffe2Targets DESTINATION ${CMAKE_INSTALL_LIBDIR}) + install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR} + DESTINATION include + FILES_MATCHING PATTERN "*.h") +--- pytorch-v2.0.1/c10/cuda/CMakeLists.txt.orig 2023-07-27 14:03:26.568153700 +0800 ++++ pytorch-v2.0.1/c10/cuda/CMakeLists.txt 2023-07-27 14:03:46.245078300 +0800 +@@ -68,7 +68,7 @@ + # Note: for now, we will put all export path into one single Caffe2Targets group + # to deal with the cmake deployment need. Inside the Caffe2Targets set, the + # individual libraries like libc10.so and libcaffe2.so are still self-contained. +-install(TARGETS c10_cuda EXPORT Caffe2Targets DESTINATION lib) ++install(TARGETS c10_cuda EXPORT Caffe2Targets DESTINATION ${CMAKE_INSTALL_LIBDIR}) + foreach(file ${C10_CUDA_HEADERS}) + get_filename_component( dir ${file} DIRECTORY ) + install( FILES ${file} DESTINATION include/c10/cuda/${dir} ) +@@ -77,5 +77,5 @@ + DESTINATION include/c10/cuda/impl) + + if(MSVC AND C10_CUDA_BUILD_SHARED_LIBS) +- install(FILES $ DESTINATION lib OPTIONAL) ++ install(FILES $ DESTINATION ${CMAKE_INSTALL_LIBDIR} OPTIONAL) + endif() +--- pytorch-v2.0.1/torch/lib/libshm/CMakeLists.txt.orig 2023-07-27 14:06:38.814966400 +0800 ++++ pytorch-v2.0.1/torch/lib/libshm/CMakeLists.txt 2023-07-27 14:06:54.816916400 +0800 +@@ -4,7 +4,7 @@ + set(TORCH_ROOT ${CMAKE_CURRENT_LIST_DIR}/../../../) + + if(NOT LIBSHM_INSTALL_LIB_SUBDIR) +- set(LIBSHM_INSTALL_LIB_SUBDIR "lib" CACHE PATH "libshm install library directory") ++ set(LIBSHM_INSTALL_LIB_SUBDIR ${CMAKE_INSTALL_LIBDIR} CACHE PATH "libshm install library directory") + endif() + + # Flags -- Gitee From 4318d2af0c0ac997af8b77ca2ae80164763f9dae Mon Sep 17 00:00:00 2001 From: Funda Wang Date: Thu, 27 Jul 2023 15:18:03 +0800 Subject: [PATCH 09/23] more fixes --- pytorch-install-nnapi_backend.patch | 10 ++++++++++ pytorch.spec | 7 ++----- 2 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 pytorch-install-nnapi_backend.patch diff --git a/pytorch-install-nnapi_backend.patch b/pytorch-install-nnapi_backend.patch new file mode 100644 index 0000000..81f6a54 --- /dev/null +++ b/pytorch-install-nnapi_backend.patch @@ -0,0 +1,10 @@ +--- pytorch-v2.0.1/torch/CMakeLists.txt.orig 2023-07-27 15:14:05.475111300 +0800 ++++ pytorch-v2.0.1/torch/CMakeLists.txt 2023-07-27 15:14:47.270226100 +0800 +@@ -419,6 +419,7 @@ + ) + # Pybind11 requires explicit linking of the torch_python library + target_link_libraries(nnapi_backend PRIVATE torch torch_python pybind::pybind11) ++ install(TARGETS nnapi_backend DESTINATION "${TORCH_INSTALL_LIB_DIR}") + endif() + + set(TORCH_PYTHON_COMPILE_OPTIONS ${TORCH_PYTHON_COMPILE_OPTIONS} PARENT_SCOPE) diff --git a/pytorch.spec b/pytorch.spec index 3dcece5..0d4a87a 100644 --- a/pytorch.spec +++ b/pytorch.spec @@ -25,6 +25,7 @@ Patch4: pytorch-xnnpack.patch Patch5: pytorch-cuda12.patch Patch6: pytorch-fpermissive.patch Patch7: pytorch-cmake-install-libdir.patch +Patch8: pytorch-install-nnapi_backend.patch BuildRequires: git doxygen python3-devel pybind11-devel BuildRequires: python3-typing-extensions python3-pyyaml python3-setuptools @@ -293,8 +294,6 @@ sed -i '1i #include "stdint.h"' torch/csrc/jit/passes/quantization/quantization_ export LD_LIBRARY_PATH=/usr/local/cuda-%{vcu_maj}.%{vcu_min}/lib64 %cmake -Wno-dev \ -DCMAKE_SKIP_RPATH=ON \ - -DCMAKE_VERBOSE_MAKEFILE=OFF \ - -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_NO_SYSTEM_FROM_IMPORTED=ON \ -DCMAKE_SKIP_RULE_DEPENDENCY=ON \ -DCMAKE_SUPPRESS_REGENERATION=ON \ @@ -404,7 +403,6 @@ export LD_LIBRARY_PATH=/usr/local/cuda-%{vcu_maj}.%{vcu_min}/lib64 find %{buildroot}/ -name "*.a" -type f -prune -exec rm -rf '{}' '+' rm -rf %{buildroot}/usr/lib/python* -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/ @@ -422,7 +420,7 @@ ln -sf %{_bindir}/torch_shm_manager %{buildroot}/%{python3_sitearch}/torch/bin/t # # caffe2 -pushd build +pushd %{_vpath_builddir} 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 @@ -464,7 +462,6 @@ rm -rf %{buildroot}/%{_builddir}/pytorch/nvfuser || true cp -r torch.egg-info %{buildroot}%{python3_sitearch}/ sed -i 's|[<=>].*||g' %{buildroot}%{python3_sitearch}/*.egg-info/requires.txt sed -i '/triton/d' %{buildroot}%{python3_sitearch}/*.egg-info/requires.txt -sed -i '/sympy/d' %{buildroot}%{python3_sitearch}/*.egg-info/requires.txt # strip elf set +x find %{buildroot} -type f -print | LC_ALL=C sort | -- Gitee From ffce1614a530621f981e9101ef8afe58ae1a09b0 Mon Sep 17 00:00:00 2001 From: Funda Wang Date: Thu, 27 Jul 2023 16:24:00 +0800 Subject: [PATCH 10/23] update --- pytorch.spec | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pytorch.spec b/pytorch.spec index 0d4a87a..f8c5b68 100644 --- a/pytorch.spec +++ b/pytorch.spec @@ -405,8 +405,7 @@ find %{buildroot}/ -name "*.a" -type f -prune -exec rm -rf '{}' '+' rm -rf %{buildroot}/usr/lib/python* 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 %{_vpath_builddir}/lib/_C.so %{buildroot}/%{python3_sitearch}/torch/ mkdir -p %{buildroot}/%{_includedir}/THC/ install -D -pm 644 aten/src/THC/THCDeviceUtils.cuh %{buildroot}/%{_includedir}/THC/ -- Gitee From a419631adbb1e62ef12a3ccafb99d590aba22f15 Mon Sep 17 00:00:00 2001 From: Funda Wang Date: Thu, 27 Jul 2023 17:19:12 +0800 Subject: [PATCH 11/23] more install patch --- pytorch-cmake-install-libdir.patch | 22 ++++++++++++++++++++++ pytorch.spec | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/pytorch-cmake-install-libdir.patch b/pytorch-cmake-install-libdir.patch index f10b7ec..0db118b 100644 --- a/pytorch-cmake-install-libdir.patch +++ b/pytorch-cmake-install-libdir.patch @@ -60,3 +60,25 @@ endif() # Flags +--- pytorch-v2.0.1/modules/observers/CMakeLists.txt.orig 2023-07-27 17:15:06.173840200 +0800 ++++ pytorch-v2.0.1/modules/observers/CMakeLists.txt 2023-07-27 17:16:00.196336800 +0800 +@@ -21,7 +21,7 @@ + target_link_libraries(caffe2_observers PUBLIC torch_library) + target_include_directories(caffe2_observers PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/..) + target_compile_options(caffe2_observers PRIVATE "-DCAFFE2_BUILD_OBSERVER_LIB") +-install(TARGETS caffe2_observers DESTINATION lib) ++install(TARGETS caffe2_observers DESTINATION ${CMAKE_INSTALL_LIBDIR}) + caffe2_interface_library(caffe2_observers caffe2_observers_library) + if(MSVC AND BUILD_SHARED_LIBS) + install(FILES $ DESTINATION lib OPTIONAL) +--- pytorch-v2.0.1/modules/detectron/CMakeLists.txt.orig 2023-07-27 17:17:05.890399900 +0800 ++++ pytorch-v2.0.1/modules/detectron/CMakeLists.txt 2023-07-27 17:17:22.790455600 +0800 +@@ -19,7 +19,7 @@ + if(USE_MKLDNN) + target_link_libraries(caffe2_detectron_ops_gpu PRIVATE caffe2::mkldnn) + endif() +- install(TARGETS caffe2_detectron_ops_gpu DESTINATION lib) ++ install(TARGETS caffe2_detectron_ops_gpu DESTINATION ${CMAKE_INSTALL_LIBDIR}) + if(MSVC) + install(FILES $ DESTINATION lib OPTIONAL) + endif() diff --git a/pytorch.spec b/pytorch.spec index f8c5b68..305bfe0 100644 --- a/pytorch.spec +++ b/pytorch.spec @@ -399,7 +399,7 @@ export LD_LIBRARY_PATH=/usr/local/cuda-%{vcu_maj}.%{vcu_min}/lib64 %install -%cmake_install +%cmake_install --verbose find %{buildroot}/ -name "*.a" -type f -prune -exec rm -rf '{}' '+' rm -rf %{buildroot}/usr/lib/python* -- Gitee From 2a88c42cd815d1ed96e8779158e027efec4220bc Mon Sep 17 00:00:00 2001 From: Funda Wang Date: Thu, 27 Jul 2023 18:09:27 +0800 Subject: [PATCH 12/23] disable debug --- pytorch.spec | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pytorch.spec b/pytorch.spec index 305bfe0..baefe6e 100644 --- a/pytorch.spec +++ b/pytorch.spec @@ -72,6 +72,8 @@ BuildRequires: kineto-devel %define gpu_target_arch "6.0 6.1 7.0 7.5 8.0 8.6" +%global debug_package %{nil} + %bcond_without cuda %if %{without cuda} %global have_cuda 0 -- Gitee From e6ac1a69c7c38dcff3153c0f1b6cf0425f1e6ac4 Mon Sep 17 00:00:00 2001 From: Funda Wang Date: Thu, 27 Jul 2023 19:28:03 +0800 Subject: [PATCH 13/23] fix linkage of python --- pytorch-drop-no-as-needed.patch | 15 +++++++++++++++ pytorch-link-python.patch | 20 ++++++++++++++++++++ pytorch.spec | 2 ++ 3 files changed, 37 insertions(+) create mode 100644 pytorch-drop-no-as-needed.patch create mode 100644 pytorch-link-python.patch diff --git a/pytorch-drop-no-as-needed.patch b/pytorch-drop-no-as-needed.patch new file mode 100644 index 0000000..736f096 --- /dev/null +++ b/pytorch-drop-no-as-needed.patch @@ -0,0 +1,15 @@ +--- pytorch-v2.0.1/CMakeLists.txt.orig 2023-07-27 19:12:57.286435000 +0800 ++++ pytorch-v2.0.1/CMakeLists.txt 2023-07-27 19:13:13.774530100 +0800 +@@ -459,12 +459,6 @@ + "Master flag to build Lite Interpreter with tracing build option" + OFF) + option(BUILD_EXECUTORCH "Master flag to build Executorch" ON) +-# This is a fix for a rare build issue on Ubuntu: +-# symbol lookup error: miniconda3/envs/pytorch-py3.7/lib/libmkl_intel_lp64.so: undefined symbol: mkl_blas_dsyrk +-# https://software.intel.com/en-us/articles/symbol-lookup-error-when-linking-intel-mkl-with-gcc-on-ubuntu +-if(LINUX) +- set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-as-needed") +-endif() + + if(MSVC) + set(CMAKE_NINJA_CMCLDEPS_RC OFF) diff --git a/pytorch-link-python.patch b/pytorch-link-python.patch new file mode 100644 index 0000000..8042f98 --- /dev/null +++ b/pytorch-link-python.patch @@ -0,0 +1,20 @@ +--- pytorch-v2.0.1/torch/CMakeLists.txt.orig 2023-07-27 19:16:45.085485000 +0800 ++++ pytorch-v2.0.1/torch/CMakeLists.txt 2023-07-27 19:25:38.035938900 +0800 +@@ -13,6 +13,8 @@ + return() + endif() + ++find_package(Python COMPONENTS Interpreter Development) ++ + if(USE_TBB) + include_directories(${TBB_INCLUDE_DIR}) + endif() +@@ -360,6 +362,8 @@ + + target_link_libraries(torch_python PRIVATE torch_library ${TORCH_PYTHON_LINK_LIBRARIES}) + ++target_link_libraries(torch_python PUBLIC ${Python_LIBRARIES}) ++ + target_compile_definitions(torch_python PRIVATE ${TORCH_PYTHON_COMPILE_DEFINITIONS}) + + target_compile_definitions(torch_python PUBLIC ${TORCH_PYTHON_PUBLIC_COMPILE_DEFINITIONS}) diff --git a/pytorch.spec b/pytorch.spec index baefe6e..33abe5d 100644 --- a/pytorch.spec +++ b/pytorch.spec @@ -26,6 +26,8 @@ Patch5: pytorch-cuda12.patch Patch6: pytorch-fpermissive.patch Patch7: pytorch-cmake-install-libdir.patch Patch8: pytorch-install-nnapi_backend.patch +Patch9: pytorch-drop-no-as-needed.patch +Patch10: pytorch-link-python.patch BuildRequires: git doxygen python3-devel pybind11-devel BuildRequires: python3-typing-extensions python3-pyyaml python3-setuptools -- Gitee From d440fb161fd0cf1e701b5ae8cbce76ec786acbda Mon Sep 17 00:00:00 2001 From: Funda Wang Date: Thu, 27 Jul 2023 19:57:49 +0800 Subject: [PATCH 14/23] use system zstd --- pytorch-system-zstd.patch | 27 +++++++++++++++++++++++++++ pytorch.spec | 5 +---- 2 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 pytorch-system-zstd.patch diff --git a/pytorch-system-zstd.patch b/pytorch-system-zstd.patch new file mode 100644 index 0000000..9dc4708 --- /dev/null +++ b/pytorch-system-zstd.patch @@ -0,0 +1,27 @@ +--- pytorch-v2.0.1/cmake/Dependencies.cmake.orig 2023-07-27 19:51:09.457995000 +0800 ++++ pytorch-v2.0.1/cmake/Dependencies.cmake 2023-07-27 19:51:19.545082900 +0800 +@@ -1517,13 +1517,6 @@ + endif() + endif() + +-if(USE_ZSTD) +- list(APPEND Caffe2_DEPENDENCY_LIBS libzstd_static) +- include_directories(SYSTEM ${CMAKE_CURRENT_LIST_DIR}/../third_party/zstd/lib) +- add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../third_party/zstd/build/cmake) +- set_property(TARGET libzstd_static PROPERTY POSITION_INDEPENDENT_CODE ON) +-endif() +- + # ---[ Onnx + if(CAFFE2_CMAKE_BUILDING_WITH_MAIN_REPO AND NOT INTERN_DISABLE_ONNX) + if(EXISTS "${CAFFE2_CUSTOM_PROTOC_EXECUTABLE}") +--- pytorch-v2.0.1/caffe2/share/contrib/CMakeLists.txt.orig 2023-07-27 19:51:35.256502500 +0800 ++++ pytorch-v2.0.1/caffe2/share/contrib/CMakeLists.txt 2023-07-27 19:52:00.174444700 +0800 +@@ -2,7 +2,7 @@ + add_subdirectory(nnpack) + endif() + if(USE_ZSTD) +- add_subdirectory(zstd) ++ list(APPEND Caffe2_PUBLIC_DEPENDENCY_LIBS zstd) + endif() + if(NOT MSVC) + add_subdirectory(depthwise) diff --git a/pytorch.spec b/pytorch.spec index 33abe5d..62cbd55 100644 --- a/pytorch.spec +++ b/pytorch.spec @@ -28,6 +28,7 @@ Patch7: pytorch-cmake-install-libdir.patch Patch8: pytorch-install-nnapi_backend.patch Patch9: pytorch-drop-no-as-needed.patch Patch10: pytorch-link-python.patch +Patch11: pytorch-system-zstd.patch BuildRequires: git doxygen python3-devel pybind11-devel BuildRequires: python3-typing-extensions python3-pyyaml python3-setuptools @@ -174,10 +175,6 @@ 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 %if %{ext_onnx} sed -i -e 's|Caffe2_DEPENDENCY_LIBS onnx_proto onnx|Caffe2_DEPENDENCY_LIBS onnx_proto onnx onnx_optimizer|' cmake/Dependencies.cmake -- Gitee From 8ae6fc4d4f95232a127a0dc4b831e0fe2e1bd378 Mon Sep 17 00:00:00 2001 From: Funda Wang Date: Thu, 27 Jul 2023 20:37:22 +0800 Subject: [PATCH 15/23] try fix linkage --- pytorch-caffe2_nvrtc-linkage.patch | 11 +++++++++++ pytorch.spec | 1 + 2 files changed, 12 insertions(+) create mode 100644 pytorch-caffe2_nvrtc-linkage.patch diff --git a/pytorch-caffe2_nvrtc-linkage.patch b/pytorch-caffe2_nvrtc-linkage.patch new file mode 100644 index 0000000..6ab2b9a --- /dev/null +++ b/pytorch-caffe2_nvrtc-linkage.patch @@ -0,0 +1,11 @@ +--- pytorch-v2.0.1/caffe2/CMakeLists.txt.orig 2023-07-27 20:35:58.760411400 +0800 ++++ pytorch-v2.0.1/caffe2/CMakeLists.txt 2023-07-27 20:36:16.115052300 +0800 +@@ -634,7 +634,7 @@ + set(DELAY_LOAD_FLAGS "") + endif() + +- target_link_libraries(caffe2_nvrtc ${CUDA_NVRTC} ${CUDA_CUDA_LIB} ${CUDA_NVRTC_LIB} ${DELAY_LOAD_FLAGS}) ++ target_link_libraries(caffe2_nvrtc ${CUDA_LIBRARIES} ${CUDA_NVRTC} ${CUDA_CUDA_LIB} ${CUDA_NVRTC_LIB} ${DELAY_LOAD_FLAGS}) + target_include_directories(caffe2_nvrtc PRIVATE ${CUDA_INCLUDE_DIRS}) + install(TARGETS caffe2_nvrtc DESTINATION "${TORCH_INSTALL_LIB_DIR}") + if(USE_NCCL) diff --git a/pytorch.spec b/pytorch.spec index 62cbd55..0b46fdd 100644 --- a/pytorch.spec +++ b/pytorch.spec @@ -29,6 +29,7 @@ Patch8: pytorch-install-nnapi_backend.patch Patch9: pytorch-drop-no-as-needed.patch Patch10: pytorch-link-python.patch Patch11: pytorch-system-zstd.patch +Patch12: pytorch-caffe2_nvrtc-linkage.patch BuildRequires: git doxygen python3-devel pybind11-devel BuildRequires: python3-typing-extensions python3-pyyaml python3-setuptools -- Gitee From 401fc01f7572f74cc4539823af7d2320a035b48b Mon Sep 17 00:00:00 2001 From: Funda Wang Date: Fri, 28 Jul 2023 09:47:24 +0800 Subject: [PATCH 16/23] try build with debuginfo --- pytorch.spec | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pytorch.spec b/pytorch.spec index 0b46fdd..8e06a39 100644 --- a/pytorch.spec +++ b/pytorch.spec @@ -76,7 +76,7 @@ BuildRequires: kineto-devel %define gpu_target_arch "6.0 6.1 7.0 7.5 8.0 8.6" -%global debug_package %{nil} +#global debug_package %{nil} %bcond_without cuda %if %{without cuda} @@ -295,6 +295,7 @@ sed -i '1i #include "stdint.h"' torch/csrc/jit/passes/quantization/quantization_ %build export LD_LIBRARY_PATH=/usr/local/cuda-%{vcu_maj}.%{vcu_min}/lib64 %cmake -Wno-dev \ + -DCMAKE_BUILD_TYPE=RelWithDebInfo \ -DCMAKE_SKIP_RPATH=ON \ -DCMAKE_NO_SYSTEM_FROM_IMPORTED=ON \ -DCMAKE_SKIP_RULE_DEPENDENCY=ON \ -- Gitee From 1eb00207f36d7990b09bfefd90e621e9b7f8452e Mon Sep 17 00:00:00 2001 From: Funda Wang Date: Fri, 28 Jul 2023 10:45:33 +0800 Subject: [PATCH 17/23] source-in-ptx causes coredump --- pytorch-caffe2_nvrtc-linkage.patch | 2 +- pytorch-drop-source-in-ptx-flag.patch | 13 +++++++++++++ pytorch.spec | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 pytorch-drop-source-in-ptx-flag.patch diff --git a/pytorch-caffe2_nvrtc-linkage.patch b/pytorch-caffe2_nvrtc-linkage.patch index 6ab2b9a..7f7459b 100644 --- a/pytorch-caffe2_nvrtc-linkage.patch +++ b/pytorch-caffe2_nvrtc-linkage.patch @@ -5,7 +5,7 @@ endif() - target_link_libraries(caffe2_nvrtc ${CUDA_NVRTC} ${CUDA_CUDA_LIB} ${CUDA_NVRTC_LIB} ${DELAY_LOAD_FLAGS}) -+ target_link_libraries(caffe2_nvrtc ${CUDA_LIBRARIES} ${CUDA_NVRTC} ${CUDA_CUDA_LIB} ${CUDA_NVRTC_LIB} ${DELAY_LOAD_FLAGS}) ++ target_link_libraries(caffe2_nvrtc ${CUDA_NVRTC} ${CUDA_NVRTC_LIB} ${CUDA_LIBRARIES} ${DELAY_LOAD_FLAGS}) target_include_directories(caffe2_nvrtc PRIVATE ${CUDA_INCLUDE_DIRS}) install(TARGETS caffe2_nvrtc DESTINATION "${TORCH_INSTALL_LIB_DIR}") if(USE_NCCL) diff --git a/pytorch-drop-source-in-ptx-flag.patch b/pytorch-drop-source-in-ptx-flag.patch new file mode 100644 index 0000000..49350f8 --- /dev/null +++ b/pytorch-drop-source-in-ptx-flag.patch @@ -0,0 +1,13 @@ +--- pytorch-v2.0.1/CMakeLists.txt.orig 2023-07-28 10:44:08.604485400 +0800 ++++ pytorch-v2.0.1/CMakeLists.txt 2023-07-28 10:44:23.260791300 +0800 +@@ -549,8 +549,8 @@ + string(APPEND CMAKE_CUDA_FLAGS " -Xfatbin -compress-all") + + if(NOT MSVC) +- string(APPEND CMAKE_CUDA_FLAGS_DEBUG " -g -lineinfo --source-in-ptx") +- string(APPEND CMAKE_CUDA_FLAGS_RELWITHDEBINFO " -g -lineinfo --source-in-ptx") ++ string(APPEND CMAKE_CUDA_FLAGS_DEBUG " -g -lineinfo") ++ string(APPEND CMAKE_CUDA_FLAGS_RELWITHDEBINFO " -g -lineinfo") + endif(NOT MSVC) + + # Set INTERN_BUILD_MOBILE for all mobile builds. Components that are not diff --git a/pytorch.spec b/pytorch.spec index 8e06a39..cfcfddf 100644 --- a/pytorch.spec +++ b/pytorch.spec @@ -30,6 +30,7 @@ Patch9: pytorch-drop-no-as-needed.patch Patch10: pytorch-link-python.patch Patch11: pytorch-system-zstd.patch Patch12: pytorch-caffe2_nvrtc-linkage.patch +Patch13: pytorch-drop-source-in-ptx-flag.patch BuildRequires: git doxygen python3-devel pybind11-devel BuildRequires: python3-typing-extensions python3-pyyaml python3-setuptools -- Gitee From 608c39873f8cc8cf3610814fdc99073dab3a3b2e Mon Sep 17 00:00:00 2001 From: Funda Wang Date: Fri, 28 Jul 2023 11:41:37 +0800 Subject: [PATCH 18/23] do not strip --- pytorch.spec | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/pytorch.spec b/pytorch.spec index cfcfddf..7144d5a 100644 --- a/pytorch.spec +++ b/pytorch.spec @@ -299,7 +299,6 @@ export LD_LIBRARY_PATH=/usr/local/cuda-%{vcu_maj}.%{vcu_min}/lib64 -DCMAKE_BUILD_TYPE=RelWithDebInfo \ -DCMAKE_SKIP_RPATH=ON \ -DCMAKE_NO_SYSTEM_FROM_IMPORTED=ON \ - -DCMAKE_SKIP_RULE_DEPENDENCY=ON \ -DCMAKE_SUPPRESS_REGENERATION=ON \ -DUSE_CCACHE=OFF \ -DHAVE_SOVERSION=ON \ @@ -465,16 +464,6 @@ rm -rf %{buildroot}/%{_builddir}/pytorch/nvfuser || true cp -r torch.egg-info %{buildroot}%{python3_sitearch}/ sed -i 's|[<=>].*||g' %{buildroot}%{python3_sitearch}/*.egg-info/requires.txt sed -i '/triton/d' %{buildroot}%{python3_sitearch}/*.egg-info/requires.txt -# strip elf -set +x -find %{buildroot} -type f -print | LC_ALL=C sort | - file -N -f - | sed -n -e 's/^\(.*\):[ \t]*.*ELF.*, not stripped.*/\1/p' | - xargs --no-run-if-empty stat -c '%h %D_%i %n' | - while read nlinks inum f; do - echo "Stripping: $f" - strip -s $f - done -set -x %files -- Gitee From 1364be0d5f362ecd1a8072dfbc11feb1e43e72ae Mon Sep 17 00:00:00 2001 From: Funda Wang Date: Fri, 28 Jul 2023 12:45:37 +0800 Subject: [PATCH 19/23] enable install message --- pytorch-enable-install-message.patch | 11 +++++++++++ pytorch.spec | 3 ++- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 pytorch-enable-install-message.patch diff --git a/pytorch-enable-install-message.patch b/pytorch-enable-install-message.patch new file mode 100644 index 0000000..ce7b779 --- /dev/null +++ b/pytorch-enable-install-message.patch @@ -0,0 +1,11 @@ +--- pytorch-v2.0.1/CMakeLists.txt.orig 2023-07-28 12:44:02.996407400 +0800 ++++ pytorch-v2.0.1/CMakeLists.txt 2023-07-28 12:44:09.486884700 +0800 +@@ -28,8 +28,6 @@ + set(LINUX FALSE) + endif() + +-set(CMAKE_INSTALL_MESSAGE NEVER) +- + # check and set CMAKE_CXX_STANDARD + string(FIND "${CMAKE_CXX_FLAGS}" "-std=c++" env_cxx_standard) + if(env_cxx_standard GREATER -1) diff --git a/pytorch.spec b/pytorch.spec index 7144d5a..bc50ea1 100644 --- a/pytorch.spec +++ b/pytorch.spec @@ -31,6 +31,7 @@ Patch10: pytorch-link-python.patch Patch11: pytorch-system-zstd.patch Patch12: pytorch-caffe2_nvrtc-linkage.patch Patch13: pytorch-drop-source-in-ptx-flag.patch +Patch14: pytorch-enable-install-message.patch BuildRequires: git doxygen python3-devel pybind11-devel BuildRequires: python3-typing-extensions python3-pyyaml python3-setuptools @@ -402,7 +403,7 @@ export LD_LIBRARY_PATH=/usr/local/cuda-%{vcu_maj}.%{vcu_min}/lib64 %install -%cmake_install --verbose +%cmake_install find %{buildroot}/ -name "*.a" -type f -prune -exec rm -rf '{}' '+' rm -rf %{buildroot}/usr/lib/python* -- Gitee From a5912402a912704d5c2f24f37b30ab77ae7197a5 Mon Sep 17 00:00:00 2001 From: Funda Wang Date: Fri, 28 Jul 2023 14:02:54 +0800 Subject: [PATCH 20/23] more linkage fix --- pytorch-caffe2_nvrtc-linkage.patch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytorch-caffe2_nvrtc-linkage.patch b/pytorch-caffe2_nvrtc-linkage.patch index 7f7459b..8e3f751 100644 --- a/pytorch-caffe2_nvrtc-linkage.patch +++ b/pytorch-caffe2_nvrtc-linkage.patch @@ -5,7 +5,7 @@ endif() - target_link_libraries(caffe2_nvrtc ${CUDA_NVRTC} ${CUDA_CUDA_LIB} ${CUDA_NVRTC_LIB} ${DELAY_LOAD_FLAGS}) -+ target_link_libraries(caffe2_nvrtc ${CUDA_NVRTC} ${CUDA_NVRTC_LIB} ${CUDA_LIBRARIES} ${DELAY_LOAD_FLAGS}) ++ target_link_libraries(caffe2_nvrtc ${CUDA_NVRTC} ${CUDA_NVRTC_LIB} ${CUDA_CUDA_LIB} ${CUDA_LIBRARIES} ${DELAY_LOAD_FLAGS}) target_include_directories(caffe2_nvrtc PRIVATE ${CUDA_INCLUDE_DIRS}) install(TARGETS caffe2_nvrtc DESTINATION "${TORCH_INSTALL_LIB_DIR}") if(USE_NCCL) -- Gitee From d6ef5cd418402a899782a09efca74e18be5a90b6 Mon Sep 17 00:00:00 2001 From: Funda Wang Date: Fri, 28 Jul 2023 16:23:29 +0800 Subject: [PATCH 21/23] use system qnnpack --- pytorch-system-qnnpack.patch | 63 ++++++++++++++++++++++++++++++++++++ pytorch.spec | 25 ++------------ 2 files changed, 66 insertions(+), 22 deletions(-) create mode 100644 pytorch-system-qnnpack.patch diff --git a/pytorch-system-qnnpack.patch b/pytorch-system-qnnpack.patch new file mode 100644 index 0000000..abc24d2 --- /dev/null +++ b/pytorch-system-qnnpack.patch @@ -0,0 +1,63 @@ +--- pytorch-v2.0.1/cmake/Dependencies.cmake.orig 2023-07-27 19:51:09.457995000 +0800 ++++ pytorch-v2.0.1/cmake/Dependencies.cmake 2023-07-28 16:21:21.881535600 +0800 +@@ -487,58 +487,8 @@ + + # ---[ QNNPACK + if(USE_QNNPACK) +- set(CAFFE2_THIRD_PARTY_ROOT "${PROJECT_SOURCE_DIR}/third_party") +- +- if(NOT DEFINED QNNPACK_SOURCE_DIR) +- set(QNNPACK_SOURCE_DIR "${CAFFE2_THIRD_PARTY_ROOT}/QNNPACK" CACHE STRING "QNNPACK source directory") +- endif() +- +- if(NOT TARGET qnnpack) +- if(NOT USE_SYSTEM_PTHREADPOOL AND USE_INTERNAL_PTHREADPOOL_IMPL) +- set(QNNPACK_CUSTOM_THREADPOOL ON CACHE BOOL "") +- endif() +- +- set(QNNPACK_BUILD_TESTS OFF CACHE BOOL "") +- set(QNNPACK_BUILD_BENCHMARKS OFF CACHE BOOL "") +- set(QNNPACK_LIBRARY_TYPE "static" CACHE STRING "") +- add_subdirectory( +- "${QNNPACK_SOURCE_DIR}" +- "${CONFU_DEPENDENCIES_BINARY_DIR}/QNNPACK") +- +- # TODO: See https://github.com/pytorch/pytorch/issues/56285 +- if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU") +- target_compile_options(qnnpack PRIVATE -Wno-deprecated-declarations) +- endif() +- +- # We build static versions of QNNPACK and pthreadpool but link +- # them into a shared library for Caffe2, so they need PIC. +- set_property(TARGET qnnpack PROPERTY POSITION_INDEPENDENT_CODE ON) +- set_property(TARGET cpuinfo PROPERTY POSITION_INDEPENDENT_CODE ON) +- +- if(QNNPACK_CUSTOM_THREADPOOL) +- target_compile_definitions( +- qnnpack PRIVATE +- pthreadpool_t=legacy_pthreadpool_t +- pthreadpool_function_1d_t=legacy_pthreadpool_function_1d_t +- pthreadpool_function_1d_tiled_t=legacy_pthreadpool_function_1d_tiled_t +- pthreadpool_function_2d_t=legacy_pthreadpool_function_2d_t +- pthreadpool_function_2d_tiled_t=legacy_pthreadpool_function_2d_tiled_t +- pthreadpool_function_3d_tiled_t=legacy_pthreadpool_function_3d_tiled_t +- pthreadpool_function_4d_tiled_t=legacy_pthreadpool_function_4d_tiled_t +- pthreadpool_create=legacy_pthreadpool_create +- pthreadpool_destroy=legacy_pthreadpool_destroy +- pthreadpool_get_threads_count=legacy_pthreadpool_get_threads_count +- pthreadpool_compute_1d=legacy_pthreadpool_compute_1d +- pthreadpool_parallelize_1d=legacy_pthreadpool_parallelize_1d +- pthreadpool_compute_1d_tiled=legacy_pthreadpool_compute_1d_tiled +- pthreadpool_compute_2d=legacy_pthreadpool_compute_2d +- pthreadpool_compute_2d_tiled=legacy_pthreadpool_compute_2d_tiled +- pthreadpool_compute_3d_tiled=legacy_pthreadpool_compute_3d_tiled +- pthreadpool_compute_4d_tiled=legacy_pthreadpool_compute_4d_tiled) +- endif() +- endif() +- +- list(APPEND Caffe2_DEPENDENCY_LIBS qnnpack) ++ find_library(QNNPACK_LIBRARY NAMES qnnpack) ++ list(APPEND Caffe2_DEPENDENCY_LIBS ${QNNPACK_LIBRARY}) + endif() + + # ---[ Caffe2 Int8 operators (enabled by USE_QNNPACK) depend on gemmlowp and neon2sse headers diff --git a/pytorch.spec b/pytorch.spec index bc50ea1..347a93f 100644 --- a/pytorch.spec +++ b/pytorch.spec @@ -32,6 +32,7 @@ Patch11: pytorch-system-zstd.patch Patch12: pytorch-caffe2_nvrtc-linkage.patch Patch13: pytorch-drop-source-in-ptx-flag.patch Patch14: pytorch-enable-install-message.patch +Patch15: pytorch-system-qnnpack.patch BuildRequires: git doxygen python3-devel pybind11-devel BuildRequires: python3-typing-extensions python3-pyyaml python3-setuptools @@ -171,40 +172,20 @@ echo 'add_library(caffe2::mkldnn ALIAS DNNL::dnnl)' >> cmake/public/mkldnn.cmake sed -i -e 's|torch_cpu PUBLIC c10|torch_cpu PUBLIC c10 dnnl|' caffe2/CMakeLists.txt %endif -# 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 onnx -%if %{ext_onnx} -sed -i -e 's|Caffe2_DEPENDENCY_LIBS onnx_proto onnx|Caffe2_DEPENDENCY_LIBS onnx_proto onnx onnx_optimizer|' cmake/Dependencies.cmake -%endif - -# external tensorpipe -mkdir -p third_party/tensorpipe -echo '' >> third_party/tensorpipe/CMakeLists.txt -sed -i '/add_dependencies(tensorpipe_agent tensorpipe)/d' caffe2/CMakeLists.txt - +%if 0 # external nnpack echo '' > cmake/External/nnpack.cmake echo 'set(NNPACK_FOUND TRUE)' >> cmake/External/nnpack.cmake - +%endif # 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 -#sed -i 's/QNNPACK_LIBRARY_TYPE \"static\"/QNNPACK_LIBRARY_TYPE \"shared\"/g' cmake/Dependencies.cmake - # external psimd mkdir -p third_party/psimd echo '' >> third_party/psimd/CMakeLists.txt -- Gitee From fdb0e56cbb4e67c97d8619ea200bf45c2d7e0654 Mon Sep 17 00:00:00 2001 From: Funda Wang Date: Fri, 28 Jul 2023 18:12:11 +0800 Subject: [PATCH 22/23] remove --- pytorch.spec | 5 ----- 1 file changed, 5 deletions(-) diff --git a/pytorch.spec b/pytorch.spec index 347a93f..e9e6d8f 100644 --- a/pytorch.spec +++ b/pytorch.spec @@ -175,11 +175,6 @@ sed -i -e 's|torch_cpu PUBLIC c10|torch_cpu PUBLIC c10 dnnl|' caffe2/CMakeLists. # openblas openmp first sed -i -e 's|NAMES openblas|NAMES openblaso openblas|' cmake/Modules/FindOpenBLAS.cmake -%if 0 -# external nnpack -echo '' > cmake/External/nnpack.cmake -echo 'set(NNPACK_FOUND TRUE)' >> cmake/External/nnpack.cmake -%endif # external cpuinfo sed -i '/TARGET cpuinfo PROPERTY/d' cmake/Dependencies.cmake -- Gitee From a00859963ec1162cf4ad98c8ca0432f46a4397fe Mon Sep 17 00:00:00 2001 From: Funda Wang Date: Fri, 28 Jul 2023 20:14:43 +0800 Subject: [PATCH 23/23] more drop --- pytorch-drop-no-as-needed.patch | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pytorch-drop-no-as-needed.patch b/pytorch-drop-no-as-needed.patch index 736f096..55f4f43 100644 --- a/pytorch-drop-no-as-needed.patch +++ b/pytorch-drop-no-as-needed.patch @@ -13,3 +13,14 @@ if(MSVC) set(CMAKE_NINJA_CMCLDEPS_RC OFF) +--- pytorch-v2.0.1/cmake/public/utils.cmake.orig 2023-07-28 20:13:23.001853000 +0800 ++++ pytorch-v2.0.1/cmake/public/utils.cmake 2023-07-28 20:13:48.974350400 +0800 +@@ -264,7 +264,7 @@ + elseif(${__src_target_type} STREQUAL "SHARED_LIBRARY") + if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") + target_link_libraries(${DST} INTERFACE +- "-Wl,--no-as-needed,\"$\" -Wl,--as-needed") ++ "-Wl,\"$\"") + else() + target_link_libraries(${DST} INTERFACE ${SRC}) + endif() -- Gitee