diff --git a/FindEigen3.cmake.file b/FindEigen3.cmake.file new file mode 100644 index 00000000000..1613005426f --- /dev/null +++ b/FindEigen3.cmake.file @@ -0,0 +1,84 @@ +# - Try to find Eigen3 lib +# +# This module supports requiring a minimum version, e.g. you can do +# find_package(Eigen3 3.1.2) +# to require version 3.1.2 or newer of Eigen3. +# +# Once done this will define +# +# EIGEN3_FOUND - system has eigen lib with correct version +# EIGEN3_INCLUDE_DIR - the eigen include directory +# EIGEN3_VERSION - eigen version + +# Copyright (c) 2006, 2007 Montel Laurent, +# Copyright (c) 2008, 2009 Gael Guennebaud, +# Copyright (c) 2009 Benoit Jacob +# Redistribution and use is allowed according to the terms of the 2-clause BSD license. +# +# Modified by Andreas Schuh to add Eigen3_DIR/EIGEN3_DIR to the PATHS of +# the find_path command (instead of HINGS). Use further PATH_SUFFIXES. +# Also, removed the separate branches for whether or not EIGEN3_INCLUDE_DIR +# is set already. The find_path command will not repeat the search in +# this case anyway. + +if(NOT Eigen3_FIND_VERSION) + if(NOT Eigen3_FIND_VERSION_MAJOR) + set(Eigen3_FIND_VERSION_MAJOR 2) + endif(NOT Eigen3_FIND_VERSION_MAJOR) + if(NOT Eigen3_FIND_VERSION_MINOR) + set(Eigen3_FIND_VERSION_MINOR 91) + endif(NOT Eigen3_FIND_VERSION_MINOR) + if(NOT Eigen3_FIND_VERSION_PATCH) + set(Eigen3_FIND_VERSION_PATCH 0) + endif(NOT Eigen3_FIND_VERSION_PATCH) + + set(Eigen3_FIND_VERSION "${Eigen3_FIND_VERSION_MAJOR}.${Eigen3_FIND_VERSION_MINOR}.${Eigen3_FIND_VERSION_PATCH}") +endif(NOT Eigen3_FIND_VERSION) + +macro(_eigen3_check_version) + file(READ "${EIGEN3_INCLUDE_DIR}/Eigen/src/Core/util/Macros.h" _eigen3_version_header) + + string(REGEX MATCH "define[ \t]+EIGEN_WORLD_VERSION[ \t]+([0-9]+)" _eigen3_world_version_match "${_eigen3_version_header}") + set(EIGEN3_WORLD_VERSION "${CMAKE_MATCH_1}") + string(REGEX MATCH "define[ \t]+EIGEN_MAJOR_VERSION[ \t]+([0-9]+)" _eigen3_major_version_match "${_eigen3_version_header}") + set(EIGEN3_MAJOR_VERSION "${CMAKE_MATCH_1}") + string(REGEX MATCH "define[ \t]+EIGEN_MINOR_VERSION[ \t]+([0-9]+)" _eigen3_minor_version_match "${_eigen3_version_header}") + set(EIGEN3_MINOR_VERSION "${CMAKE_MATCH_1}") + + set(EIGEN3_VERSION ${EIGEN3_WORLD_VERSION}.${EIGEN3_MAJOR_VERSION}.${EIGEN3_MINOR_VERSION}) + if(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION}) + set(EIGEN3_VERSION_OK FALSE) + else(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION}) + set(EIGEN3_VERSION_OK TRUE) + endif(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION}) + + if(NOT EIGEN3_VERSION_OK) + message(STATUS "Eigen3 version ${EIGEN3_VERSION} found in ${EIGEN3_INCLUDE_DIR}, " + "but at least version ${Eigen3_FIND_VERSION} is required") + endif(NOT EIGEN3_VERSION_OK) +endmacro(_eigen3_check_version) + +find_path(EIGEN3_INCLUDE_DIR + NAMES + signature_of_eigen3_matrix_library + PATHS + ${Eigen3_DIR} + ${EIGEN3_DIR} + ${CMAKE_INSTALL_PREFIX} + ${KDE4_INCLUDE_DIR} + PATH_SUFFIXES + include + include/eigen3 + include/eigen + eigen3 + eigen +) + +if (EIGEN3_INCLUDE_DIR) + _eigen3_check_version() +endif () + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Eigen3 DEFAULT_MSG EIGEN3_INCLUDE_DIR EIGEN3_VERSION_OK) + +mark_as_advanced(EIGEN3_INCLUDE_DIR) diff --git a/FindFMT.cmake.file b/FindFMT.cmake.file new file mode 100644 index 00000000000..2fa7ce0a6e5 --- /dev/null +++ b/FindFMT.cmake.file @@ -0,0 +1,29 @@ +# Find FMT +# +# Find the FMT includes +# +# if you nee to add a custom library search path, do it via via CMAKE_PREFIX_PATH +# +# This module defines +# FMT_INCLUDE_DIRS, where to find header, etc. +# FMT_FOUND, If false, do not try to use FMT. + +# only look in default directories +find_path( + FMT_INCLUDE_DIR + NAMES fmt/core.h + DOC "FMT include dir" + HINTS ${FMT_ROOT}/include +) + +if (NOT FMT_INCLUDE_DIR) + MESSAGE(FATAL_ERROR "Error, FMT include dir not found. Did you set FMT_ROOT variable?") +endif() + +set(FMT_INCLUDE_DIRS ${FMT_INCLUDE_DIR}) + +# handle the QUIETLY and REQUIRED arguments and set FMT_FOUND to TRUE +# if all listed variables are TRUE, hide their existence from configuration view +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(FMT DEFAULT_MSG FMT_INCLUDE_DIR) +mark_as_advanced (FMT_FOUND FMT_INCLUDE_DIR) diff --git a/cmssw-tool-conf.spec b/cmssw-tool-conf.spec index 6dde42ba71f..a367e4a1747 100644 --- a/cmssw-tool-conf.spec +++ b/cmssw-tool-conf.spec @@ -175,6 +175,7 @@ Requires: oracle-fake Requires: xtensor Requires: xtl Requires: xgboost +Requires: pytorch ## INCLUDE cmssw-vectorization ## INCLUDE cmssw-drop-tools diff --git a/fxdiv.spec b/fxdiv.spec new file mode 100644 index 00000000000..1dcba858671 --- /dev/null +++ b/fxdiv.spec @@ -0,0 +1,14 @@ +### RPM external fxdiv 2020-04-17 + +%define commit b408327ac2a15ec3e43352421954f5b1967701d1 + +Source0: git+https://github.com/Maratyszcza/FXdiv.git?obj=master/%{commit}&export=%{n}-%{realversion}&output=/%{n}-%{realversion}.tgz + +%prep +%setup -n %{n}-%{realversion} + +%build + +%install +mkdir -p %{i}/include +cp -a include/fxdiv.h %{i}/include/ diff --git a/psimd.spec b/psimd.spec new file mode 100644 index 00000000000..2656a4b2903 --- /dev/null +++ b/psimd.spec @@ -0,0 +1,22 @@ +### RPM external psimd 2020-05-17 +%define commit 072586a71b55b7f8c584153d223e95687148a900 + +Source0: git+https://github.com/Maratyszcza/psimd.git?obj=master/%{commit}&export=%{n}-%{realversion}&output=/%{n}-%{realversion}.tgz + +BuildRequires: gmake cmake + +%prep +%setup -n %{n}-%{realversion} + +%build +cd %{_builddir} +rm -rf build +mkdir build && cd build + +cmake ../%{n}-%{realversion} \ + -DCMAKE_INSTALL_PREFIX=%{i} \ + -DCMAKE_BUILD_TYPE=Release + +%install +cd %{_builddir}/build +make install diff --git a/pytorch-ignore-different-cuda-include-dir.patch b/pytorch-ignore-different-cuda-include-dir.patch new file mode 100644 index 00000000000..69a374cf443 --- /dev/null +++ b/pytorch-ignore-different-cuda-include-dir.patch @@ -0,0 +1,16 @@ +--- pytorch-2.1.0/cmake/public/cuda.cmake.orig 2023-11-07 13:17:24.113086707 +0100 ++++ pytorch-2.1.0/cmake/public/cuda.cmake 2023-11-07 13:17:36.295966731 +0100 +@@ -60,13 +60,6 @@ + + cmake_policy(POP) + +-if(NOT CMAKE_CUDA_COMPILER_VERSION STREQUAL CUDAToolkit_VERSION OR +- NOT CUDA_INCLUDE_DIRS STREQUAL CUDAToolkit_INCLUDE_DIR) +- message(FATAL_ERROR "Found two conflicting CUDA installs:\n" +- "V${CMAKE_CUDA_COMPILER_VERSION} in '${CUDA_INCLUDE_DIRS}' and\n" +- "V${CUDAToolkit_VERSION} in '${CUDAToolkit_INCLUDE_DIR}'") +-endif() +- + if(NOT TARGET CUDA::nvToolsExt) + message(FATAL_ERROR "Failed to find nvToolsExt") + endif() diff --git a/pytorch-missing-braces.patch b/pytorch-missing-braces.patch new file mode 100644 index 00000000000..23c98888f14 --- /dev/null +++ b/pytorch-missing-braces.patch @@ -0,0 +1,21 @@ +diff --git a/torch/csrc/profiler/events.h b/torch/csrc/profiler/events.h +index a1a956f1327..a4e02c795d9 100644 +--- a/torch/csrc/profiler/events.h ++++ b/torch/csrc/profiler/events.h +@@ -11,7 +11,7 @@ namespace profiler { + using perf_counters_t = std::vector; + + /* Standard list of performance events independent of hardware or backend */ +-constexpr std::array ProfilerPerfEvents = { ++constexpr std::array ProfilerPerfEvents = {{ + /* + * Number of Processing Elelement (PE) cycles between two points of interest + * in time. This should correlate positively with wall-time. Measured in +@@ -25,6 +25,6 @@ constexpr std::array ProfilerPerfEvents = { + * (i.e. work). Across repeat executions, the number of instructions should + * be more or less invariant. Measured in uint64_t. PE can be non cpu. + */ +- "instructions"}; ++ "instructions" }}; + } // namespace profiler + } // namespace torch diff --git a/pytorch-system-fmt.patch b/pytorch-system-fmt.patch new file mode 100644 index 00000000000..1561c227728 --- /dev/null +++ b/pytorch-system-fmt.patch @@ -0,0 +1,57 @@ +diff --git a/c10/CMakeLists.txt b/c10/CMakeLists.txt +index feebad7cbb7..8a2ad840286 100644 +--- a/c10/CMakeLists.txt ++++ b/c10/CMakeLists.txt +@@ -87,6 +87,7 @@ endif() + if(${USE_GLOG}) + target_link_libraries(c10 PUBLIC glog::glog) + endif() ++find_package(fmt REQUIRED) + target_link_libraries(c10 PRIVATE fmt::fmt-header-only) + + find_package(Backtrace) +diff --git a/caffe2/CMakeLists.txt b/caffe2/CMakeLists.txt +index 74d0d557190..ff3e94b1c4b 100644 +--- a/caffe2/CMakeLists.txt ++++ b/caffe2/CMakeLists.txt +@@ -1363,6 +1363,8 @@ if($ENV{TH_BINARY_BUILD}) + endif() + endif() + ++find_package(fmt REQUIRED) ++ + target_link_libraries(torch_cpu PUBLIC c10) + target_link_libraries(torch_cpu PUBLIC ${Caffe2_PUBLIC_DEPENDENCY_LIBS}) + target_link_libraries(torch_cpu PRIVATE ${Caffe2_DEPENDENCY_LIBS}) +diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake +index c3abce52e4c..5e89d3eb43a 100644 +--- a/cmake/Dependencies.cmake ++++ b/cmake/Dependencies.cmake +@@ -1832,9 +1832,13 @@ endif() + # + # End ATen checks + # +-set(TEMP_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS}) +-set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libs" FORCE) +-add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/fmt) ++find_package(FMT) ++if(FMT_FOUND) ++ message(STATUS "Found system FMT at " ${FMT_INCLUDE_DIR}) ++else() ++ message(STATUS "Did not find system FMT. Using third party subdirectory.") ++ add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/fmt) ++endif() + + # Disable compiler feature checks for `fmt`. + # +@@ -1843,10 +1847,8 @@ add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/fmt) + # CMAKE_CXX_FLAGS in ways that break feature checks. Since we already know + # `fmt` is compatible with a superset of the compilers that PyTorch is, it + # shouldn't be too bad to just disable the checks. +-set_target_properties(fmt-header-only PROPERTIES INTERFACE_COMPILE_FEATURES "") + + list(APPEND Caffe2_DEPENDENCY_LIBS fmt::fmt-header-only) +-set(BUILD_SHARED_LIBS ${TEMP_BUILD_SHARED_LIBS} CACHE BOOL "Build shared libs" FORCE) + + # ---[ Kineto + # edge profiler depends on KinetoProfiler but it only does cpu diff --git a/pytorch.spec b/pytorch.spec new file mode 100644 index 00000000000..5d58c9c5d42 --- /dev/null +++ b/pytorch.spec @@ -0,0 +1,92 @@ +### RPM external pytorch 2.1.1 +## INCLUDE cuda-flags + +%define cuda_arch_float $(echo %{cuda_arch} | tr ' ' '\\n' | sed -E 's|([0-9])$|.\\1|' | tr '\\n' ' ') +%define tag v%{realversion} +%define branch release/2.1 + +Source: git+https://github.com/pytorch/pytorch.git?obj=%{branch}/%{tag}&export=%{n}-%{realversion}&submodules=1&output=/%{n}-%{realversion}.tgz +Source1: FindEigen3.cmake +Source2: FindFMT.cmake +Patch0: pytorch-ignore-different-cuda-include-dir +Patch1: pytorch-missing-braces +Patch2: pytorch-system-fmt + +BuildRequires: cmake ninja +Requires: eigen fxdiv numactl openmpi protobuf psimd python3 py3-PyYAML +Requires: cuda cudnn OpenBLAS zlib protobuf fmt py3-pybind11 + +%prep +%setup -n %{n}-%{realversion} +%patch0 -p1 +%patch1 -p1 +%patch2 -p1 + +%build +cp %{_sourcedir}/FindEigen3.cmake %{_sourcedir}/FindFMT.cmake cmake/Modules/ +rm -rf ../build && mkdir ../build && cd ../build + +USE_CUDA=OFF +%if "%{cmsos}" != "slc7_aarch64" +if [ "%{cuda_gcc_support}" = "true" ] ; then +USE_CUDA=ON +fi +%endif + +cmake ../%{n}-%{realversion} \ + -G Ninja \ + -DCMAKE_INSTALL_PREFIX=%{i} \ + -DCMAKE_INSTALL_LIBDIR=lib \ + -DBUILD_TEST=OFF \ + -DBUILD_BINARY=OFF \ + -DBUILD_PYTHON=OFF \ + -DUSE_CUDA=${USE_CUDA} \ + -DTORCH_CUDA_ARCH_LIST="%{cuda_arch_float}" \ + -DCUDNN_INCLUDE_DIR=${CUDNN_ROOT}/include \ + -DCUDNN_LIBRARY=${CUDNN_ROOT}/lib64/libcudnn.so \ + -DUSE_NCCL=OFF \ + -DUSE_FBGEMM=OFF \ + -DUSE_KINETO=OFF \ + -DUSE_MAGMA=OFF \ + -DUSE_METAL=OFF \ + -DUSE_MPS=OFF \ + -DUSE_NNPACK=OFF \ + -DUSE_QNNPACK=OFF \ + -DUSE_PYTORCH_QNNPACK=OFF \ + -DUSE_XNNPACK=OFF \ + -DUSE_NUMA=ON \ + -DNUMA_ROOT_DIR=${NUMACTL_ROOT} \ + -DUSE_NUMPY=OFF \ + -DUSE_OPENMP=ON \ + -DUSE_QNNPACK=OFF \ + -DUSE_VALGRIND=OFF \ + -DUSE_XNNPACK=OFF \ + -DUSE_MKLDNN=OFF \ + -DUSE_DISTRIBUTED=OFF \ + -DUSE_MPI=ON \ + -DUSE_GLOO=OFF \ + -DUSE_TENSORPIPE=OFF \ + -DONNX_ML=ON \ + -DBLAS=OpenBLAS \ + -DBUILD_CUSTOM_PROTOBUF=OFF \ + -DUSE_SYSTEM_EIGEN_INSTALL=ON \ + -DUSE_SYSTEM_PSIMD=ON \ + -DUSE_SYSTEM_FXDIV=ON \ + -DUSE_SYSTEM_PYBIND11=ON \ + -DUSE_SYSTEM_BENCHMARK=ON \ + -DCMAKE_PREFIX_PATH="%{cmake_prefix_path}" \ + -DPYTHON_EXECUTABLE=${PYTHON3_ROOT}/bin/python3 + +ninja -v %{makeprocesses} + +%install +cd ../build +ninja -v %{makeprocesses} install + +%post +%{relocateConfig}include/caffe2/core/macros.h +%{relocateConfig}share/cmake/ATen/ATenConfig.cmake + +# For ROCm, pre-build +# NOTICE: can't build with both cuda and rocm +# python @{_builddir}/tools/amd_build/build_amd.py diff --git a/scram-tools.file/tools/pytorch/pytorch-cuda.xml b/scram-tools.file/tools/pytorch/pytorch-cuda.xml new file mode 100644 index 00000000000..d727c3ca728 --- /dev/null +++ b/scram-tools.file/tools/pytorch/pytorch-cuda.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/scram-tools.file/tools/pytorch/pytorch.xml b/scram-tools.file/tools/pytorch/pytorch.xml new file mode 100644 index 00000000000..c9ba308c303 --- /dev/null +++ b/scram-tools.file/tools/pytorch/pytorch.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/scram-tools.file/tools/pytorch/torch-interface.xml b/scram-tools.file/tools/pytorch/torch-interface.xml new file mode 100644 index 00000000000..d99e98b49fc --- /dev/null +++ b/scram-tools.file/tools/pytorch/torch-interface.xml @@ -0,0 +1,10 @@ + + + + + + + + + +