Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add recipe for pytorch (C++ interface only) #8388

Merged
merged 38 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
dd2f95c
Initial commit of py3-torch recipe
iarspider Mar 14, 2023
15e8919
Merge branch 'IB/CMSSW_13_1_X/master' into add-py3-torch
iarspider Mar 15, 2023
b1f0dca
Fix the recipe
iarspider Mar 15, 2023
0181b0c
Add py3-torch to python_tools
iarspider Mar 15, 2023
317acbd
Add relocation
iarspider Mar 16, 2023
b05c5d3
Remove pthreadpoool - only needed for nnpack or mobile
iarspider Mar 16, 2023
a164d27
Fix recipe
iarspider Mar 16, 2023
121ea50
Update requirements.txt
iarspider Mar 16, 2023
d3b06e8
Update torch.file
iarspider Mar 16, 2023
4bf963b
Changes from review
iarspider Mar 17, 2023
58e945e
Merge branch 'add-py3-torch' of github.com:cms-sw/cmsdist into add-py…
iarspider Mar 17, 2023
be3430f
Fix recipe
iarspider Mar 17, 2023
60cf195
Update torch.file
iarspider Mar 20, 2023
a39c221
Update torch.file
iarspider Mar 20, 2023
3a92bea
Create symlinks to lib and include
iarspider Mar 23, 2023
758ba7e
Add toolfiles
iarspider Mar 23, 2023
43bbdbb
Fix toolfile
iarspider Mar 23, 2023
afe2130
Update toolfiles again
iarspider Mar 23, 2023
0f79019
Update torch-interface.xml
iarspider Apr 4, 2023
89ae3c3
Update torch.xml
iarspider Apr 4, 2023
4b706d1
Update toolfiles
iarspider Apr 5, 2023
74f2a58
Merge branch 'IB/CMSSW_13_3_X/master' into add-py3-torch
smuzaffar Oct 21, 2023
b2688d3
Test without CUDA
iarspider Oct 23, 2023
a6562b7
Update pytorch to 2.1 (but still keep both python and C++ parts)
iarspider Nov 7, 2023
61d29b6
Add patch to ignore difference between CUDA and CUDAToolkit include dirs
iarspider Nov 7, 2023
350bb60
Build only C++ part of pytorch
Nov 14, 2023
795093c
Delete py3-torch-cpp-externsion-ppc64.patch
iarspider Nov 14, 2023
f95f7af
Delete pip/py3-torch-ignore-different-cuda-include-dir.patch
iarspider Nov 14, 2023
c1a644d
Update python_tools.spec
iarspider Nov 14, 2023
2b6a5ef
Update toolfiles
iarspider Nov 14, 2023
4c38b6a
Add missing file; add pytorch to cmssw-tool-conf
iarspider Nov 14, 2023
238e271
Add patch to ignore difference between CUDA and CUDAToolkit include dirs
iarspider Nov 7, 2023
dfb07d3
Add patch to fix missing-braces error
iarspider Nov 15, 2023
ee99c9a
Update toolfiles
iarspider Nov 15, 2023
099f60a
Make CUDA optional
iarspider Nov 16, 2023
f29deb0
Use external eigen and fmt
iarspider Nov 27, 2023
2040f9f
Fix relocation
iarspider Nov 28, 2023
cbd56e4
Cleanup pytorch.spec
iarspider Nov 28, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions fxdiv.spec
Original file line number Diff line number Diff line change
@@ -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/
1 change: 1 addition & 0 deletions pip/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ toml==0.10.2
tomli==2.0.1
tomli-w==1.0.0
tomlkit==0.11.4
torch==1.13.1
tornado==6.2
tqdm==4.64.1
traitlets==5.3.0
Expand Down
72 changes: 72 additions & 0 deletions pip/torch.file
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
## 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/1.13

%define source0 git+https://github.com/pytorch/pytorch.git?obj=%{branch}/%{tag}&export=%{n}-%{realversion}&submodules=1&output=/%{n}-%{realversion}.tgz
#Patch0: py3-torch-cpp-externsion-ppc64 - TODO: is it needed? 1st part doesn't apply

BuildRequires: cmake gmake
iarspider marked this conversation as resolved.
Show resolved Hide resolved
Requires: eigen fxdiv numactl openmpi protobuf psimd py3-astunparse py3-cffi py3-future py3-numpy py3-pip py3-protobuf py3-pybind11 py3-PyYAML py3-requests py3-setuptools py3-six py3-tqdm py3-typing-extensions py3-wheel python3 cuda cudnn OpenBLAS

%define PipPreBuildPy \
%if "%{?compiling_processes:set}" == "set" \
export MAX_JOBS=%compiling_processes \
%endif \
export COLORIZE_OUTPUT=OFF \
export BUILD_TEST=OFF \
export USE_CUDA=ON \
export TORCH_CUDA_ARCH_LIST="%{cuda_arch_float}" \
\
export CUDNN_INCLUDE_DIR=${CUDNN_ROOT}/include \
export CUDNN_LIBRARY=${CUDNN_ROOT}/lib64/libcudnn.so \
\
export USE_NCCL=OFF \
export USE_FBGEMM=OFF \
export USE_KINETO=OFF \
export USE_MAGMA=OFF \
export USE_METAL=OFF \
export USE_MPS=OFF \
export USE_BREAKPAD=OFF \
export USE_NNPACK=OFF \
export USE_QNNPACK=OFF \
export USE_PYTORCH_QNNPACK=OFF \
export USE_XNNPACK=OFF \
\
export USE_NUMA=ON \
export NUMA_ROOT_DIR=${NUMACTL_ROOT} \
\
export USE_NUMPY=ON \
export USE_OPENMP=ON \
export USE_QNNPACK=OFF \
export USE_VALGRIND=OFF \
export USE_XNNPACK=OFF \
export USE_MKLDNN=OFF \
export USE_DISTRIBUTED=OFF \
export USE_MPI=ON \
export USE_GLOO=OFF \
export USE_TENSORPIPE=OFF \
export ONNX_ML=ON \
\
export PYTORCH_BUILD_VERSION=%{realversion} \
export PYTORCH_BUILD_NUMBER=0 \
export BLAS=OpenBLAS \
export WITH_BLAS=open \
\
export BUILD_CUSTOM_PROTOBUF=OFF \
export USE_SYSTEM_EIGEN_INSTALL=ON \
export pybind11_DIR=${PY3_PYBIND11_ROOT}/lib/python%{cms_python3_major_minor_version}/site-packages/pybind11/share/cmake/pybind11 \
export pybind11_INCLUDE_DIR=${PY3_PYBIND11_ROOT}/lib/python%{cms_python3_major_minor_version}/site-packages/pybind11/include \
export USE_SYSTEM_PYBIND11=ON \
\
export USE_SYSTEM_PSIMD=ON \
export USE_SYSTEM_FXDIV=ON \
export USE_SYSTEM_BENCHMARK=ON \
export CMAKE_PREFIX_PATH="%{cmake_prefix_path}"

%define PipPrePost %{relocateConfig}lib/python%{cms_python3_major_minor_version}/site-packages/torch/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
22 changes: 22 additions & 0 deletions psimd.spec
Original file line number Diff line number Diff line change
@@ -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
75 changes: 75 additions & 0 deletions py3-torch-cpp-externsion-ppc64.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
diff --git a/torch/utils/cpp_extension.py b/torch/utils/cpp_extension.py
index aed4fd5004..9ebaf18652 100644
--- a/torch/utils/cpp_extension.py
+++ b/torch/utils/cpp_extension.py
@@ -53,7 +53,7 @@ CUDA_GCC_VERSIONS = {
'11.1': (MINIMUM_GCC_VERSION, (10, 0, 0)),
'11.2': (MINIMUM_GCC_VERSION, (10, 0, 0)),
'11.3': (MINIMUM_GCC_VERSION, (10, 0, 0)),
- '11.4': ((6, 0, 0), (10, 0, 0))
+ '11.4': ((6, 0, 0), (11, 2, 0))
}

CUDA_CLANG_VERSIONS = {
@@ -465,12 +465,17 @@ class BuildExtension(build_ext, object):
else:
original_compile = self.compiler._compile

- def append_std14_if_no_std_present(cflags) -> None:
+ def append_std14_if_no_std_present(cflags, with_cuda) -> None:
# NVCC does not allow multiple -std to be passed, so we avoid
# overriding the option if the user explicitly passed it.
+ if with_cuda:
+ std_val = 'c++14'
+ else:
+ std_val = 'gnu++14'
+
cpp_format_prefix = '/{}:' if self.compiler.compiler_type == 'msvc' else '-{}='
cpp_flag_prefix = cpp_format_prefix.format('std')
- cpp_flag = cpp_flag_prefix + 'c++14'
+ cpp_flag = cpp_flag_prefix + std_val
if not any(flag.startswith(cpp_flag_prefix) for flag in cflags):
cflags.append(cpp_flag)

@@ -511,11 +516,13 @@ class BuildExtension(build_ext, object):
cflags = COMMON_HIPCC_FLAGS + cflags + _get_rocm_arch_flags(cflags)
else:
cflags = unix_cuda_flags(cflags)
+ append_std14_if_no_std_present(cflags, True)
elif isinstance(cflags, dict):
cflags = cflags['cxx']
+ append_std14_if_no_std_present(cflags, False)
if IS_HIP_EXTENSION:
cflags = COMMON_HIP_FLAGS + cflags
- append_std14_if_no_std_present(cflags)
+ append_std14_if_no_std_present(cflags, False)

original_compile(obj, src, ext, cc_args, cflags, pp_opts)
finally:
@@ -564,7 +571,7 @@ class BuildExtension(build_ext, object):
post_cflags = list(extra_postargs)
if IS_HIP_EXTENSION:
post_cflags = COMMON_HIP_FLAGS + post_cflags
- append_std14_if_no_std_present(post_cflags)
+ append_std14_if_no_std_present(post_cflags, with_cuda)

cuda_post_cflags = None
cuda_cflags = None
@@ -579,7 +586,7 @@ class BuildExtension(build_ext, object):
cuda_post_cflags = COMMON_HIP_FLAGS + COMMON_HIPCC_FLAGS + cuda_post_cflags
else:
cuda_post_cflags = unix_cuda_flags(cuda_post_cflags)
- append_std14_if_no_std_present(cuda_post_cflags)
+ append_std14_if_no_std_present(cuda_post_cflags, with_cuda)
cuda_cflags = [shlex.quote(f) for f in cuda_cflags]
cuda_post_cflags = [shlex.quote(f) for f in cuda_post_cflags]

@@ -710,7 +717,7 @@ class BuildExtension(build_ext, object):
post_cflags = extra_postargs['cxx']
else:
post_cflags = list(extra_postargs)
- append_std14_if_no_std_present(post_cflags)
+ append_std14_if_no_std_present(post_cflags, with_cuda)

cuda_post_cflags = None
cuda_cflags = None
1 change: 1 addition & 0 deletions python_tools.spec
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Requires: py3-tensorflow
Requires: py3-cmsml
Requires: py3-law
Requires: py3-protobuf
Requires: py3-torch

Requires: py3-tables
Requires: py3-numexpr
Expand Down