diff --git a/pytorch-C.patch b/pytorch-C.patch index 26cc0296cad8362e5aae8f4bae9e832ac6e57ac5..007c19b8a340c8d27fa515a8571ea30c4d688f3d 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-caffe2_nvrtc-linkage.patch b/pytorch-caffe2_nvrtc-linkage.patch new file mode 100644 index 0000000000000000000000000000000000000000..8e3f7515eb211b058ad3731ed342d90241882e19 --- /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_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) diff --git a/pytorch-cmake-install-libdir.patch b/pytorch-cmake-install-libdir.patch new file mode 100644 index 0000000000000000000000000000000000000000..0db118b38f3d6614b0ff185e9a502a6e3c1826e3 --- /dev/null +++ b/pytorch-cmake-install-libdir.patch @@ -0,0 +1,84 @@ +--- 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) +--- 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 +--- 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-drop-no-as-needed.patch b/pytorch-drop-no-as-needed.patch new file mode 100644 index 0000000000000000000000000000000000000000..55f4f43d2c2b946e4480cded7e1eef66d6f6b260 --- /dev/null +++ b/pytorch-drop-no-as-needed.patch @@ -0,0 +1,26 @@ +--- 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) +--- 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() diff --git a/pytorch-drop-source-in-ptx-flag.patch b/pytorch-drop-source-in-ptx-flag.patch new file mode 100644 index 0000000000000000000000000000000000000000..49350f8b704fbb436828d18cc864d588fae6bdd8 --- /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-enable-install-message.patch b/pytorch-enable-install-message.patch new file mode 100644 index 0000000000000000000000000000000000000000..ce7b779f1d1d77ec74610ac98c22dbf03865a993 --- /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-fpermissive.patch b/pytorch-fpermissive.patch new file mode 100644 index 0000000000000000000000000000000000000000..db51420c857b448d20b840487167c4cb146197a8 --- /dev/null +++ b/pytorch-fpermissive.patch @@ -0,0 +1,21 @@ +--- 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 +--- 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 diff --git a/pytorch-install-nnapi_backend.patch b/pytorch-install-nnapi_backend.patch new file mode 100644 index 0000000000000000000000000000000000000000..81f6a54a21186f79200d91b763b6ef5ad15b7638 --- /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-link-python.patch b/pytorch-link-python.patch new file mode 100644 index 0000000000000000000000000000000000000000..8042f98c469cafc4c8b6f437ec3e26b6aecb3e03 --- /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-system-qnnpack.patch b/pytorch-system-qnnpack.patch new file mode 100644 index 0000000000000000000000000000000000000000..abc24d2967ce0e865f9362b8fd325caaa20b9773 --- /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-system-zstd.patch b/pytorch-system-zstd.patch new file mode 100644 index 0000000000000000000000000000000000000000..9dc4708dd36083b89bd04bcf71afdc3b2b3ffce5 --- /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 3fde7793df5b219295d787fd912e84e575000ffe..e9e6d8fb8ce5842b2c063fe296ad6b6cba71a6d3 100644 --- a/pytorch.spec +++ b/pytorch.spec @@ -18,13 +18,21 @@ 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 +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 +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 @@ -71,13 +79,7 @@ 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 +#global debug_package %{nil} %bcond_without cuda %if %{without cuda} @@ -145,7 +147,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 +155,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} -p1 # 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 @@ -185,44 +172,15 @@ 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 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 -%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 - -# 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 -#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 @@ -313,25 +271,11 @@ 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_BUILD_TYPE=RelWithDebInfo \ -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 \ -DUSE_CCACHE=OFF \ -DHAVE_SOVERSION=ON \ @@ -431,30 +375,17 @@ 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 +%cmake_install -# -# 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 %{_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/ @@ -468,7 +399,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 @@ -510,16 +441,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